diff --git a/assets/images/editors/ui/context-bg.png b/assets/images/editors/ui/context-bg.png new file mode 100644 index 00000000..3f070653 Binary files /dev/null and b/assets/images/editors/ui/context-bg.png differ diff --git a/assets/images/editors/ui/context-bg.xml b/assets/images/editors/ui/context-bg.xml new file mode 100644 index 00000000..6eb3c21a --- /dev/null +++ b/assets/images/editors/ui/context-bg.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/images/editors/ui/selection.png b/assets/images/editors/ui/selection.png new file mode 100644 index 00000000..09297449 Binary files /dev/null and b/assets/images/editors/ui/selection.png differ diff --git a/assets/images/editors/ui/slider.png b/assets/images/editors/ui/slider.png new file mode 100644 index 00000000..5cbaf969 Binary files /dev/null and b/assets/images/editors/ui/slider.png differ diff --git a/buildnumber.txt b/buildnumber.txt index 9159750c..8263b02e 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -2559 \ No newline at end of file +2566 \ No newline at end of file diff --git a/source/funkin/editors/UIDebugState.hx b/source/funkin/editors/UIDebugState.hx index c048ead3..ccaeebf1 100644 --- a/source/funkin/editors/UIDebugState.hx +++ b/source/funkin/editors/UIDebugState.hx @@ -63,4 +63,35 @@ class UIDebugState extends UIState { ])); }, 130, 48)); } + + public override function update(elapsed:Float) { + super.update(elapsed); + if (FlxG.mouse.justReleasedRight) { + openContextMenu([ + { + label: "Test 1", + onSelect: function() { + + } + }, + { + label: "Test 2", + onSelect: function() { + + } + }, + { + label: "Test 3", + childs: [ + { + label: "Test 2", + onSelect: function() { + + } + } + ] + } + ]); + } + } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIContextMenu.hx b/source/funkin/editors/ui/UIContextMenu.hx new file mode 100644 index 00000000..3b5f56fc --- /dev/null +++ b/source/funkin/editors/ui/UIContextMenu.hx @@ -0,0 +1,44 @@ +package funkin.editors.ui; + +class UIContextMenu extends MusicBeatSubstate { + var options:Array; + var x:Float; + var y:Float; + var contextCam:FlxCamera; + + var bg:UISpliceSprite; + + public function new(options:Array, x:Float, y:Float) { + super(); + this.options = options.getDefault([]); + this.x = x; + this.y = y; + } + + public override function create() { + super.create(); + camera = contextCam = new FlxCamera(); + contextCam.bgColor = 0; + contextCam.alpha = 0; + FlxG.cameras.add(contextCam, false); + + bg = new UISpliceSprite(x, y, 100, 100, 'editors/ui/context-bg'); + add(bg); + } + + public override function update(elapsed:Float) { + if (FlxG.mouse.pressed && !bg.hoveredByChild) + close(); + + super.update(elapsed); + + contextCam.alpha = CoolUtil.fpsLerp(contextCam.alpha, 1, 0.25); + } +} + +typedef UIContextMenuOption = { + var label:String; + var ?icon:Int; + var ?onSelect:Void->Void; + var ?childs:Array; +} \ No newline at end of file diff --git a/source/funkin/editors/ui/UISprite.hx b/source/funkin/editors/ui/UISprite.hx index 0397343c..1654baa9 100644 --- a/source/funkin/editors/ui/UISprite.hx +++ b/source/funkin/editors/ui/UISprite.hx @@ -13,8 +13,11 @@ class UISprite extends FlxSprite { private var __oldDefCams:Array; - var hovered:Bool = false; - var pressed:Bool = false; + public var hovered:Bool = false; + public var hoveredByChild:Bool = false; + public var pressed:Bool = false; + + public var hoverCallback:Void->Void = null; public override function update(elapsed:Float) { super.update(elapsed); @@ -32,6 +35,7 @@ class UISprite extends FlxSprite { hovered = false; pressed = false; + hoveredByChild = false; } public override function draw() { @@ -72,5 +76,7 @@ class UISprite extends FlxSprite { hovered = true; if (FlxG.mouse.pressed) pressed = true; + if (hoverCallback != null) + hoverCallback(); } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index 999cce26..e83ff608 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -1,5 +1,6 @@ package funkin.editors.ui; +import funkin.editors.ui.UIContextMenu.UIContextMenuOption; import flixel.math.FlxPoint; import flixel.math.FlxRect; @@ -29,7 +30,8 @@ class UIState extends MusicBeatState { } public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) { - var pos = FlxG.mouse.getScreenPosition(camera); + FlxG.mouse.getScreenPosition(camera, __mousePos); + for(camera in spr.__lastDrawCameras) { __rect.x = rect.x; __rect.y = rect.y; @@ -39,7 +41,8 @@ class UIState extends MusicBeatState { __rect.x -= camera.scroll.x * spr.scrollFactor.x; __rect.y -= camera.scroll.y * spr.scrollFactor.y; - if (((pos.x > __rect.x) && (pos.x < __rect.x + rect.width)) && ((pos.y > __rect.y) && (pos.y < __rect.y + __rect.height))) { + if (((__mousePos.x > __rect.x) && (__mousePos.x < __rect.x + rect.width)) && ((__mousePos.y > __rect.y) && (__mousePos.y < __rect.y + __rect.height))) { + spr.hoveredByChild = true; this.buttonHandler = buttonHandler; return; } @@ -59,4 +62,17 @@ class UIState extends MusicBeatState { super.destroy(); __mousePos.put(); } + + public function openContextMenu(options:Array, ?x:Float, ?y:Float) { + var state = FlxG.state; + while(state.subState != null) + state = state.subState; + + state.persistentDraw = true; + state.persistentUpdate = true; + + + + openSubState(new UIContextMenu(options, x.getDefault(__mousePos.x), y.getDefault(__mousePos.y))); + } } \ No newline at end of file