From 418089fdf68e82e8e59bc750bcf5445e495864e6 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Sat, 18 Mar 2023 01:28:13 +0100 Subject: [PATCH] new ui stuff --- assets/images/editors/ui/context-bg.png | Bin 0 -> 906 bytes assets/images/editors/ui/context-bg.xml | 15 ++++++++ assets/images/editors/ui/selection.png | Bin 0 -> 124 bytes assets/images/editors/ui/slider.png | Bin 0 -> 289 bytes buildnumber.txt | 2 +- source/funkin/editors/UIDebugState.hx | 31 +++++++++++++++ source/funkin/editors/ui/UIContextMenu.hx | 44 ++++++++++++++++++++++ source/funkin/editors/ui/UISprite.hx | 10 ++++- source/funkin/editors/ui/UIState.hx | 20 +++++++++- 9 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 assets/images/editors/ui/context-bg.png create mode 100644 assets/images/editors/ui/context-bg.xml create mode 100644 assets/images/editors/ui/selection.png create mode 100644 assets/images/editors/ui/slider.png create mode 100644 source/funkin/editors/ui/UIContextMenu.hx diff --git a/assets/images/editors/ui/context-bg.png b/assets/images/editors/ui/context-bg.png new file mode 100644 index 0000000000000000000000000000000000000000..3f070653fc9b5868e516c566947552c8a8b8c49a GIT binary patch literal 906 zcmV;519kj~P)pIJV``BRCwC$+iOTuQ2+<V3Q)$73M24H^Ud&bZR0vI$Z@{2}X#! z=sAD5pYG-IKfe$6e)>a%5Lg)@6x(}CM3D}xUGhB~w$#JUBidkUevPcdAJhbxF90<Nb6+ihSB8i&9S!yuS8|DyAJ8xCK< z1upJ9;7naCC#L0PReh4KUt78cAWWo4;k$A*ExJ!|$~;YX?@h@*{$3!J`JwMUMrCz# zdEpX(H#;~!Fxcpq1rS$5!IpZp}Uh+BMA}% z7MocEW8{|yJ~rvO)012KYyZEQ|0@K9_zuGYRVlik{*dlIwB(8^4iEqh0U!XV5L18@ z0zd)e69DW19-snD0j|yi|%t1u*5Tpu)?q1eT;tN5HJ`9!1xxQ(z*$Fz@7Ty&tFbXOiNXj zHp$rkcI|k2F*~5h-d}P!lF4$Ab2z)DLJya9=ks$k&*yFaF`u`yvz=;f?PxTa%yn-X g-q-#{?W>;u1Dr(w@(CjkfB*mh07*qoM6N<$g6s%`6#xJL literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..09297449408637e6d3c4f2c5dfd6d5adc8b8141a GIT binary patch literal 124 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5he4R}c>anMprD?o zi(^Q|t>ig#zus?bY)oWgu3XR{m~ntrA(?q58%vLrLDqp4j3Fim8XKG5@GxAtX=Au2 S@4g*SCxfS}pUXO@geCxii6pB4 literal 0 HcmV?d00001 diff --git a/assets/images/editors/ui/slider.png b/assets/images/editors/ui/slider.png new file mode 100644 index 0000000000000000000000000000000000000000..5cbaf9692789a610527f9528fe8fe0577486b943 GIT binary patch literal 289 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5he4R}c>anMpx|Xs z7srr_TgfR6OmcE^Y@D2&Y@(u~yEY?=`U!?^Gtw5g zUE>s1`@{4xJ1gq}*96^+%uL43++18Y8rc4_txR;e#&e0oNcJXMiFlL2356MoJq~Am zil3eN$$hEj;UQL@-WLoh6B-*CZ%mjnMa0dGpP!$3!Tj^gmOKu^k{yf=-jWT|nhv*o zJkZGezjLeXZ0!SV41bx;8blb37$ouzA7kiZ5|rqDu*5sfM9Rp?(q%W3uA*V^yeWy3 iQqt8*q&?1_V@SAsW$WDw`o2K#F?hQAxvX; + 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