From 62d9dd1df1b96deab7a8305ceddaeefb38775cc4 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:46:30 +0100 Subject: [PATCH] fix button --- assets/images/editors/ui/button.png | Bin 0 -> 848 bytes assets/images/editors/ui/button.xml | 33 +++++++ assets/images/editors/ui/inputbox.png | Bin 0 -> 3693 bytes assets/images/editors/ui/inputbox.xml | 33 +++++++ buildnumber.txt | 2 +- source/funkin/editors/UIDebugState.hx | 3 + source/funkin/editors/ui/UIButton.hx | 122 +++++++++++++++++++++++++ source/funkin/editors/ui/UICheckbox.hx | 15 ++- source/funkin/editors/ui/UISprite.hx | 10 +- source/funkin/editors/ui/UIState.hx | 1 - 10 files changed, 207 insertions(+), 12 deletions(-) create mode 100644 assets/images/editors/ui/button.png create mode 100644 assets/images/editors/ui/button.xml create mode 100644 assets/images/editors/ui/inputbox.png create mode 100644 assets/images/editors/ui/inputbox.xml create mode 100644 source/funkin/editors/ui/UIButton.hx diff --git a/assets/images/editors/ui/button.png b/assets/images/editors/ui/button.png new file mode 100644 index 0000000000000000000000000000000000000000..cdc0d1b48449bd2b21e65258356bae5026b2fc50 GIT binary patch literal 848 zcmV-W1F!svP)pI0!c(cRCwC$*-K~>K^Oqwe|M8=^V%fPYD2Hq2NW-!y!GBDw#8F> z(1WemA_zf4l0yqgP%nZs!Q`g2Ac(Df+;i)xXCL({No^&`CL2TE&ZCdyxI0tm5(fsd zOZb`n_-EMtf1%xO10M79^Yn+#kxV9q&TBysnBt*z86uv50Wn@M7~E$G7>mV5P7v|p zN?)1Q2liXS*&eCdb-mF2bQH7cKSXaDICPnesVW5(-5Or=u5ir0yV$J$~V&_?J&b3y zTES+sfhdZa;KA(qNE=S^=58!uBfH&yFZ9d;actbE~_vngqSjr&8 zEcjmEA=i;e1e{JMnR-T{P#`lL4jTmU1t-8)XMi~SSO9Sro*&>3PJq`b;8x%m(4iBs zNCCYsdlfK90k7x;{Cxr#GYFu%&j-*pLIJl!doaKVc!U5aqDBGy$qDeZ_AcN>-@>!AvpYN@S`Y7P%C+G~cGoFD6a5`ZSz|0pufS!BDfRFi{fz$7d z0=U5maFPOke6)++0f$L7Mr%C~k3Z!D$dwPlm$*%?1A)Nld!W{OARfhH5lW>JEH5t` z1MtJcG&nB1Ky(b^M{B#C4##v?tE|6Mt@ ac>e&HwWJrq6qNY@0000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/images/editors/ui/inputbox.png b/assets/images/editors/ui/inputbox.png new file mode 100644 index 0000000000000000000000000000000000000000..a81994a5b88ff929ea08b8d34008a87663355524 GIT binary patch literal 3693 zcmV-z4wCVSP)pTA4x<(RCwCOnt4zZS02ZIP0tL>$stPQ5MfY25i|%SkPr%8bu~(q zO^nGVyY6nRRJq2p+{!;&)c#||^1!l8C0J#xZW7l`h>ok4x*APf2p(v-!k{t)hC@6e z40AC|&+L1zyJvcu88TdJQ?I(2>6&l%@AH1gJ1Do?4Z@?fwUss+jahoVzNEXm8@E^( z$6>WvdkPB+Po<@$>Eh$#>rzrun33*pJq)zbayLug+ECKn+f~y2q;q`wj)9)S1&dFm zCC}5vt5WJx{uDBz{tL4f(eJ*zWv*q=RMKa8yr!qWGj2Tk7W+WYLhZ|6DP@||$Ey!D zUellV(Wis}YHDhhpEz-%GA=GIEIK+GVq;?g84W^0LdN_69UUFe+1W|j)2C1E>({Se zotc?=-rv17A9pN2arRhcTvT#cv^oZ2BNHKhN-~5{<(Y_|-qYxq8XyNh_tS*E~u)iVhRchN{Wh#&I<3nTCQJl`_3I*MnVpqG(82R z5dcy(fJ6llBEe6}wO|f6+gwfnrx{>q0JT1Vu17|wYPrZ16y{=>~;aRsT-Z85*bWU#egbI15#QB5BfTZ zetcBYir*b7zTg2+UthoM3_5aha%inq3o4b07##}=5Apv2-(M8g@c$Tw*=)uk4jLO9 znf(0xRe5=N=kWLSe}A&<%*9h@a#CKQwTUU9n#CHO;*C!6`awW&V?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f-6yo6RM9y?$KV!((G(yHV4nr>EroYW}IA#5{oX?>CK4|GD_?*y(Y)^rU&ZX|~yQiR)lQ{Y5V>qyPB& zpXZt^{Uy$!p*4C#)3~;$$Hv5WMMXq^tx;-ppByi5`tIgsAN~IU00ZqZcgfjO00000 LNkvXXu0mjfsC}as literal 0 HcmV?d00001 diff --git a/assets/images/editors/ui/inputbox.xml b/assets/images/editors/ui/inputbox.xml new file mode 100644 index 00000000..03d5daf6 --- /dev/null +++ b/assets/images/editors/ui/inputbox.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/buildnumber.txt b/buildnumber.txt index ac037cdb..0805bfe8 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -2508 \ No newline at end of file +2514 \ No newline at end of file diff --git a/source/funkin/editors/UIDebugState.hx b/source/funkin/editors/UIDebugState.hx index 9aba4f09..b29ca0d1 100644 --- a/source/funkin/editors/UIDebugState.hx +++ b/source/funkin/editors/UIDebugState.hx @@ -13,5 +13,8 @@ class UIDebugState extends UIState { add(new UICheckbox(10, 10, "Test unchecked", false)); add(new UICheckbox(10, 40, "Test checked", true)); + add(new UIButton(10, 70, "Test button", function() { + trace("Hello, World!"); + }, 120, 20)); } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIButton.hx b/source/funkin/editors/ui/UIButton.hx new file mode 100644 index 00000000..69b09f0d --- /dev/null +++ b/source/funkin/editors/ui/UIButton.hx @@ -0,0 +1,122 @@ +package funkin.editors.ui; + +import flixel.graphics.frames.FlxFrame; + +class UIButton extends UISprite { + public var bWidth:Int = 120; + public var bHeight:Int = 20; + public var callback:Void->Void = null; + + public function resize(w:Int, h:Int) { + bWidth = w; + bHeight = h; + } + + public override function new(x:Float, y:Float, t:String, callback:Void->Void, w:Float = 120, h:Float = 20) { + super(x, y); + frames = CoolUtil.loadFrames(Paths.image('editors/ui/button')); + this.callback = callback; + } + + public override function updateButton() { + __rect.x = x; + __rect.y = y; + __rect.width = bWidth; + __rect.height = bHeight; + UIState.state.updateRectButtonHandler(this, __rect, onHovered); + } + + public override function onHovered() { + super.onHovered(); + if (FlxG.mouse.justReleased && callback != null) + callback(); + } + + public override function draw() { + var x:Float = this.x; + var y:Float = this.y; + var offset:Int = hovered ? (pressed ? 18 : 9) : 0; + + var topleft:FlxFrame = frames.frames[offset]; + var top:FlxFrame = frames.frames[offset + 1]; + var topright:FlxFrame = frames.frames[offset + 2]; + var middleleft:FlxFrame = frames.frames[offset + 3]; + var middle:FlxFrame = frames.frames[offset + 4]; + var middleright:FlxFrame = frames.frames[offset + 5]; + var bottomleft:FlxFrame = frames.frames[offset + 6]; + var bottom:FlxFrame = frames.frames[offset + 7]; + var bottomright:FlxFrame = frames.frames[offset + 8]; + + @:privateAccess { + // TOP LEFT + frame = topleft; + setPosition(x, y); + __setSize(topleft.frame.width, topleft.frame.height); + super.draw(); + + // TOP + frame = top; + setPosition(x + topleft.frame.width, y); + __setSize(bWidth - topleft.frame.width - topright.frame.width, top.frame.height); + super.draw(); + + // TOP RIGHT + frame = topright; + setPosition(x + bWidth - topright.frame.width, y); + __setSize(topright.frame.width, topright.frame.height); + super.draw(); + + // MIDDLE LEFT + frame = middleleft; + setPosition(x, y + top.frame.height); + __setSize(middleleft.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height); + super.draw(); + + // MIDDLE + frame = middle; + setPosition(x + topleft.frame.width, y + top.frame.height); + __setSize(bWidth - middleleft.frame.width - middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height); + super.draw(); + + // MIDDLE RIGHT + frame = middleright; + setPosition(x + bWidth - topright.frame.width, y + top.frame.height); + __setSize(middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height); + super.draw(); + + // BOTTOM LEFT + frame = bottomleft; + setPosition(x, y + bHeight - bottom.frame.height); + __setSize(bottomleft.frame.width, bottomleft.frame.height); + super.draw(); + + // BOTTOM + frame = bottom; + setPosition(x + bottomleft.frame.width, y + bHeight - bottom.frame.height); + __setSize(bWidth - bottomleft.frame.width - bottomright.frame.width, bottom.frame.height); + super.draw(); + + // BOTTOM RIGHT + frame = bottomright; + setPosition(x + bWidth - bottomright.frame.width, y + bHeight - bottom.frame.height); + __setSize(bottomright.frame.width, bottomright.frame.height); + super.draw(); + } + + + setPosition(x, y); + } + + private function __setSize(Width:Float, Height:Float) { + var newScaleX:Float = Width / frameWidth; + var newScaleY:Float = Height / frameHeight; + scale.set(newScaleX, newScaleY); + + if (Width <= 0) + scale.x = newScaleY; + else if (Height <= 0) + scale.y = newScaleX; + + updateHitbox(); + } +} \ No newline at end of file diff --git a/source/funkin/editors/ui/UICheckbox.hx b/source/funkin/editors/ui/UICheckbox.hx index 894450b5..2eff17f1 100644 --- a/source/funkin/editors/ui/UICheckbox.hx +++ b/source/funkin/editors/ui/UICheckbox.hx @@ -3,13 +3,12 @@ package funkin.editors.ui; import funkin.ui.FunkinText; class UICheckbox extends UISprite { + public var checked:Bool = false; + public var onChecked:Bool->Void = null; + public var field:FunkinText; public var check:FlxSprite; - public var checked:Bool = false; - - var hovered:Bool = false; - var pressed:Bool = false; public function new(x:Float, y:Float, text:String, checked:Bool = false, w:Int = 0) { super(x, y); loadGraphic(Paths.image('editors/ui/checkbox'), true, 20, 20); @@ -29,8 +28,6 @@ class UICheckbox extends UISprite { public override function update(elapsed:Float) { // ANIMATION HANDLING animation.play(hovered ? (pressed ? "pressed" : "hover") : "normal"); - hovered = false; - pressed = false; // CHECKMARK HANDLING check.alpha = checked ? 1 : 0; @@ -56,9 +53,7 @@ class UICheckbox extends UISprite { } public override function onHovered() { - hovered = true; - if (FlxG.mouse.pressed) - pressed = true; + super.onHovered(); if (FlxG.mouse.justReleased) { // clicked checked = !checked; @@ -66,6 +61,8 @@ class UICheckbox extends UISprite { if (Options.editorSFX) CoolUtil.playMenuSFX(checked ? CHECKED : UNCHECKED, 0.5); + if (onChecked != null) + onChecked(checked); } } diff --git a/source/funkin/editors/ui/UISprite.hx b/source/funkin/editors/ui/UISprite.hx index 3a3220b6..7cf51330 100644 --- a/source/funkin/editors/ui/UISprite.hx +++ b/source/funkin/editors/ui/UISprite.hx @@ -12,6 +12,9 @@ class UISprite extends FlxSprite { private var __oldDefCams:Array; + var hovered:Bool = false; + var pressed:Bool = false; + public override function update(elapsed:Float) { super.update(elapsed); updateButton(); @@ -25,6 +28,9 @@ class UISprite extends FlxSprite { FlxCamera._defaultCameras = __oldDefCams; } + + hovered = false; + pressed = false; } public override function draw() { @@ -56,6 +62,8 @@ class UISprite extends FlxSprite { * Called whenever the sprite is being hovered by the mouse. */ public function onHovered() { - + hovered = true; + if (FlxG.mouse.pressed) + pressed = true; } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index 6b133134..ffb1112f 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -28,7 +28,6 @@ class UIState extends MusicBeatState { updateRectButtonHandler(spr, spr.__rect, buttonHandler); } - public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) { var pos = FlxG.mouse.getScreenPosition(camera); for(camera in spr.__lastDrawCameras) {