diff --git a/assets/images/desktop/ui.xml b/assets/images/desktop/ui.xml index 9c6ad81a..79c6909a 100644 --- a/assets/images/desktop/ui.xml +++ b/assets/images/desktop/ui.xml @@ -23,5 +23,5 @@ - + \ No newline at end of file diff --git a/assets/images/desktop/ui/buttonHover.png b/assets/images/desktop/ui/buttonHover.png index 28f0f77d..a178e6c7 100644 Binary files a/assets/images/desktop/ui/buttonHover.png and b/assets/images/desktop/ui/buttonHover.png differ diff --git a/assets/images/desktop/ui/contextOption.png b/assets/images/desktop/ui/contextOption.png index 1e13277b..51864d45 100644 Binary files a/assets/images/desktop/ui/contextOption.png and b/assets/images/desktop/ui/contextOption.png differ diff --git a/buildnumber.txt b/buildnumber.txt index d7bda98e..6b71fd4e 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1713 \ No newline at end of file +1719 \ No newline at end of file diff --git a/source/funkin/desktop/DesktopMain.hx b/source/funkin/desktop/DesktopMain.hx index 93a61891..68fc4bd6 100644 --- a/source/funkin/desktop/DesktopMain.hx +++ b/source/funkin/desktop/DesktopMain.hx @@ -12,6 +12,7 @@ import flixel.FlxSprite; import flixel.FlxBasic; import flixel.FlxCamera; import flixel.math.FlxPoint; +import flixel.util.FlxDestroyUtil; import funkin.desktop.editors.*; import funkin.desktop.windows.*; import funkin.desktop.theme.Theme; @@ -29,12 +30,14 @@ class DesktopMain extends MusicBeatState { public static var theme:Theme = null; + public static var contextMenu:ContextMenu = null; + public static function init() { theme = Theme.loadFromAssets(Paths.getPath('images/desktop/ui.xml', TEXT, null)); mouseInput = new MouseInput(); FlxG.signals.preUpdate.add(function() { - mouseInput.set(FlxG.mouse.pressed, FlxG.mouse.justPressed, FlxG.mouse.justReleased); + updateMouseInput(); }); } @@ -62,8 +65,15 @@ class DesktopMain extends MusicBeatState { add(windows); } + private static function updateMouseInput() { + mouseInput.set(FlxG.mouse.pressed, FlxG.mouse.justPressed, FlxG.mouse.justReleased, FlxG.mouse.pressedRight, FlxG.mouse.justPressedRight, FlxG.mouse.justReleasedRight); + } + public override function update(elapsed:Float) { - mouseInput.set(FlxG.mouse.pressed, FlxG.mouse.justPressed, FlxG.mouse.justReleased); + updateMouseInput(); + + if (contextMenu != null) + contextMenu.update(elapsed); super.update(elapsed); @@ -85,6 +95,12 @@ class DesktopMain extends MusicBeatState { return windows.add(new Window(content)); } + public override function draw() { + super.draw(); + if (contextMenu != null) + contextMenu.draw(); + } + public function updateScreenRes() { // update wallpaper wallpaper.setUnstretchedGraphicSize(FlxG.width, FlxG.height); @@ -95,6 +111,8 @@ class DesktopMain extends MusicBeatState { public override function destroy() { super.destroy(); + contextMenu = FlxDestroyUtil.destroy(contextMenu); + FlxG.scaleMode = oldScaleMode; FlxG.mouse.useSystemCursor = FlxG.mouse.visible = false; @@ -124,19 +142,27 @@ class MouseInput { public var pressed:Bool = false; public var justPressed:Bool = false; public var justReleased:Bool = false; + public var pressedRight:Bool = false; + public var justPressedRight:Bool = false; + public var justReleasedRight:Bool = false; + public var screenPos:FlxPoint = null; private var __cancelled:Bool = false; public function cancel() { - pressed = justPressed = justReleased = false; + pressed = justPressed = justReleased = pressedRight = justPressedRight = justReleasedRight = false; __cancelled = true; } public function new() {} - public function set(pressed:Bool, justPressed:Bool, justReleased:Bool) { + public function set(pressed:Bool, justPressed:Bool, justReleased:Bool, pressedRight:Bool, justPressedRight:Bool, justReleasedRight:Bool) { this.pressed = pressed; this.justPressed = justPressed; this.justReleased = justReleased; + this.pressedRight = pressedRight; + this.justPressedRight = justPressedRight; + this.justReleasedRight = justReleasedRight; + this.screenPos = FlxG.mouse.getScreenPosition(FlxG.camera); this.__cancelled = false; } diff --git a/source/funkin/desktop/windows/ContextMenu.hx b/source/funkin/desktop/windows/ContextMenu.hx index d66fb7ef..8838e559 100644 --- a/source/funkin/desktop/windows/ContextMenu.hx +++ b/source/funkin/desktop/windows/ContextMenu.hx @@ -1,5 +1,7 @@ package funkin.desktop.windows; +import flixel.FlxCamera; +import flixel.util.FlxDestroyUtil; import flixel.FlxSprite; import funkin.desktop.sprites.*; import flixel.FlxObject; @@ -9,9 +11,16 @@ class ContextMenu extends WindowGroup { public var bg:SpliceSprite; public var texts:Array = []; public var selectionBGs:Array = []; + public var callback:Int->Void; + public var contextOptions:Array = []; + public var contextCamera:FlxCamera; public override function new(x:Float, y:Float, options:Array, callback:Int->Void) { super(); + this.callback = callback; + this.contextOptions = options; + + DesktopMain.contextMenu = FlxDestroyUtil.destroy(DesktopMain.contextMenu); var bgTheme = DesktopMain.theme.contextBackground; var optionTheme = DesktopMain.theme.contextOption; @@ -23,23 +32,67 @@ class ContextMenu extends WindowGroup { var w:Float = 80; for(k=>o in options) { var selectSpr = new FlxSprite(bgTheme.left, bgTheme.top + (k * optionTheme.height)); - selectSpr.loadGraphic(Paths.image(bgTheme.sprite)); + selectSpr.loadGraphic(Paths.image(optionTheme.sprite)); selectSpr.setGraphicSize(10, Std.int(optionTheme.height)); + selectSpr.visible = false; selectionBGs.push(selectSpr); add(selectSpr); var text = new WindowText(4, 4, 0, o.name); text.y = selectSpr.y + ((selectSpr.height - text.height) / 2); + text.applyFontSettings(bgTheme); texts.push(text); add(text); if (w < text.width) w = text.width; + + lastOption = selectSpr; + } + var ow = Std.int(w) + 20; + for(o in selectionBGs) { + o.setGraphicSize(ow, Std.int(optionTheme.height)); + o.updateHitbox(); + } + bg.resize(bgTheme.left + ow + bgTheme.right, lastOption.y + lastOption.height + bgTheme.bottom); + contextCamera = camera = new FlxCamera(Std.int(x), Std.int(y), Std.int(bg.width), Std.int(bg.height)); + contextCamera.pixelPerfectRender = true; + contextCamera.bgColor = 0; + FlxG.cameras.add(contextCamera, false); + + DesktopMain.contextMenu = this; + } + + public override function update(elapsed:Float) { + super.update(elapsed); + if (DesktopMain.mouseInput.overlaps(bg, camera)) { + for(i=>o in selectionBGs) { + var wasVisible = o.visible; + if (o.visible = DesktopMain.mouseInput.overlaps(o, camera)) { + if (DesktopMain.mouseInput.justReleased) { + // select option + if (contextOptions[i].callback != null) + contextOptions[i].callback(); + if (callback != null) + callback(i); + destroy(); + } + } + if (o.visible != wasVisible) { + texts[i].applyFontSettings(o.visible ? DesktopMain.theme.contextOption : DesktopMain.theme.contextBackground); + } + } + DesktopMain.mouseInput.cancel(); + } else { + if (DesktopMain.mouseInput.justPressed) { + destroy(); + } } } public override function destroy() { super.destroy(); - FlxG.cameras.remove(camera, true); + DesktopMain.contextMenu = null; + FlxG.cameras.remove(contextCamera, true); } } diff --git a/source/funkin/desktop/windows/WindowDragHitbox.hx b/source/funkin/desktop/windows/WindowDragHitbox.hx index 24344b75..c2d8a6e7 100644 --- a/source/funkin/desktop/windows/WindowDragHitbox.hx +++ b/source/funkin/desktop/windows/WindowDragHitbox.hx @@ -54,6 +54,18 @@ class WindowDragHitbox extends FlxObject { var screenPos = FlxG.mouse.getScreenPosition(FlxG.camera); offset = FlxPoint.get(parent.content.winX - screenPos.x, parent.content.winY - screenPos.y); dragging = true; + } else if (DesktopMain.mouseInput.justPressedRight) { + var input = DesktopMain.mouseInput; + new ContextMenu(input.screenPos.x, input.screenPos.y, [ + { + name: "Close", + callback: function() { + parent.close(); + } + } + ], function(i) { + trace(i); + }); } DesktopMain.mouseInput.cancel(); }