From a7c51d072e57060b189e925ac7de49ab24a95cf8 Mon Sep 17 00:00:00 2001 From: Yoshman29 Date: Mon, 24 Oct 2022 01:23:00 +0200 Subject: [PATCH] buttons (broken) --- assets/images/desktop/ui.xml | 8 +- assets/images/desktop/ui/button.png | Bin 0 -> 686 bytes assets/images/desktop/ui/buttonDisabled.png | Bin 0 -> 266 bytes assets/images/desktop/ui/buttonHover.png | Bin 0 -> 818 bytes assets/images/desktop/ui/buttonPressed.png | Bin 0 -> 689 bytes buildnumber.txt | 2 +- source/funkin/desktop/editors/HelloWorld.hx | 7 + source/funkin/desktop/sprites/Button.hx | 96 +++++++++++++ source/funkin/desktop/sprites/SpliceSprite.hx | 126 ++++++++++++++++++ source/funkin/desktop/theme/Theme.hx | 11 ++ source/funkin/desktop/windows/Window.hx | 31 ++--- .../funkin/desktop/windows/WindowContent.hx | 2 +- source/funkin/desktop/windows/WindowGroup.hx | 7 + source/funkin/system/CoolUtil.hx | 5 + 14 files changed, 273 insertions(+), 22 deletions(-) create mode 100644 assets/images/desktop/ui/button.png create mode 100644 assets/images/desktop/ui/buttonDisabled.png create mode 100644 assets/images/desktop/ui/buttonHover.png create mode 100644 assets/images/desktop/ui/buttonPressed.png create mode 100644 source/funkin/desktop/sprites/Button.hx create mode 100644 source/funkin/desktop/sprites/SpliceSprite.hx diff --git a/assets/images/desktop/ui.xml b/assets/images/desktop/ui.xml index 4b2aac16..26b05830 100644 --- a/assets/images/desktop/ui.xml +++ b/assets/images/desktop/ui.xml @@ -1,8 +1,12 @@ - - + + + + + + \ No newline at end of file diff --git a/assets/images/desktop/ui/button.png b/assets/images/desktop/ui/button.png new file mode 100644 index 0000000000000000000000000000000000000000..c4826c6a70d7b0c043d1d34441720aad03a6b2d0 GIT binary patch literal 686 zcmV;f0#W^mP)pHU`a$lRCwBBWME)m6B82?WMX3CU}IxrV!#0e1qJzG?Dy~Ae}u7r z{rdF}sQ2HWKYxC`diCl(BhWB$4-XG7HZ_OR-4~vyK78?sg@FVh!prv0!ARyA`-7vE zOP4O)z$hgpCF_;dvh(9l7R~G+YX*A*B~r{|xc1;BL&LmX47}`rug$ATGz1&SYL#(s zK~)qBsfIzoe};n>?lB~^E&uayO`Ra4goK3r3ze7$e-Cy*r2j({5p5h$!|$Iz7`Qx| z7&P8&(FMEknNrlFU;ElfG6?3n-@kqV@ec+8zb*!o9|z3f2L9O7OtOI>*ZukRli?T8 zg~CC73`XDfS-=hawyObdD@g|a1{(O|JA-J*ByliXsCgBc`Jo_-Pwu21-R@7+6W6 zfiqAI{J6D(3=3}4>fq7XbYBqz}uS1q_1K+GK z0vZP~kP(T*X&4ax`}+rMAjp*p@e3Gi7*04a3JD2GGnr>RT3r{wq%6V1@DJz>Mi68q zU?4DP{{8z4H0(FS?Pnht;(GS}bK$=i!^p$KBjSgC35N%FALSTA%?=I?g0VFKrS5} z9TgKGP*G7)6#xQOAOO~6D1HXX!Ps~1+_?>+Sy)(@flAqdwI$ovuV25kwzhTx0L-wN Uh9;rG-~a#s07*qoM6N<$f*I{EzW@LL literal 0 HcmV?d00001 diff --git a/assets/images/desktop/ui/buttonDisabled.png b/assets/images/desktop/ui/buttonDisabled.png new file mode 100644 index 0000000000000000000000000000000000000000..22fc15b6b69d49aa7d85a6d55e4bfcf789bce546 GIT binary patch literal 266 zcmeAS@N?(olHy`uVBq!ia0vp^B0wz8!3HF`W%CyUDb50q$YKTtzQZ8Qcszea3Q%y5 zr;B4q#jWI&1x5)ihE>(o>Jibeju;ymaZN}%aDV^*db_$`iNO^W6%uzGCM4dQx9z9X zAtjzWcWhL4zIc9Ko@agBzJwdQ{(d;}=+Psl4UOu3Z)?^sS)=8!D$(G>*Vp20)#ds1 z8#WY)vq)Eb`myf6)h;%X*1JpHlxavdm*xtmvebh7qd&&} z@sIo?LJFfuN(>@N%QVxW78ryEK^Y$$FBu8z8kF=&H|9u=u2S6?kK#ln>5$ zRu)kCsa?uDedJpd@OnIiga83H$OLu(qE$d2TZjbm*Vu3yY&jzfsPc3Y2LW?}ivnH^ z_g~P|EDz{z1w@*HsimTTU4BwC1i@T~ETDR(irvZEo>D1oCgn0%}H%N;_lE86$y9ElyD&1Pc4) z0f!Ef43hR~Hb*IJ8j^|ff$4O^**V}N=GSJ zx#uOT!1`xmf5L)wK&l%2d9Mp24;FYx7^;wjs51X|>uETkWOce61^^N_QpZ?XI=nxs&j5Iqz$x zFx4Zjttu}sw;6Wr>wGvkk@Y`!ioG~{uELT$=piNoHD-YPAIUJ78-&KBDh9V2azyJUM07*qoM6N<$f**u%K>z>% literal 0 HcmV?d00001 diff --git a/assets/images/desktop/ui/buttonPressed.png b/assets/images/desktop/ui/buttonPressed.png new file mode 100644 index 0000000000000000000000000000000000000000..ba4d4ba830f367b259db5398eaf56a21f442bd8e GIT binary patch literal 689 zcmV;i0#5yjP)pHV@X6oRCwBBWME)m6B82?WMX3CU}IxrV!#0e1qJzG?Dy~Ae}u7r z{rdF}sQ2HWKYxC`diCl(BhWB$4-XG7HZ_OR-4~vyK78?sg@FVh!prv0!ARyA`-7vE zOP4O)z$hgpCF_;dvh&f)51QfDaty}G!VHXzj6kJ~L>c(t^*4qYJ8v^citt{WSCeQ6 zHjvdS<6dL9K8u;EC<8MKD+3cVGt^N0;Q#;s42(=n3}^4WWhk3}^v}aJb%Kl%5)$$+ zRAL_7m=Vsv%Eku7>_7uq2pb4A>_3zVQY#%Xok8Qx7G1ClpD9H>x-}=7fsKuWfdyzN zFp!D%GSo;0sj$fmCO;0CAq<=iG>{!=AS)}-MkeBof`+$L_!I`CZ~H9Z2Hu<%2{n+7 zsPKci46GK2q{FAt*uWdJBFHw75p3XeGy`XbQ)Xbq3{(TJ&!EgenMe!+!zeUxCan#e z9>%~*fq}A77zTz?Xy7bV1Fy{p1?OW@4P;`1s9y2Uh5ud*BM%Rch(})6`Jca;WKw;M8SL~G8JLJE zZ5ScMjfbxpT9+JT;N$rJQvUCwsUTqve}8`uDeK_QZKob6kyEF5S*X4ZF%&*^4+ua8 za_Q*ksF(nOii(P=01&VO0TU$p-~c2CW8b-R=QfCDVF3mZD=Ry&wq*PI_3M|`*49n{ Xw%O}Void; + + public var disabled:Bool = false; + + public var frame:Int = 0; + + public var normalSprite:SpliceSprite; + public var hoverSprite:SpliceSprite; + public var pressedSprite:SpliceSprite; + public var disabledSprite:SpliceSprite; + + public var label:FlxUIText; + + public function new(x:Float, y:Float, text:String = "", callback:Void->Void) { + super(); + this.x = x; + this.y = y; + this.width = 75; + this.height = 24; + this.callback = callback; + + var normalButton = DesktopMain.theme.normalButton; + var hoverButton = DesktopMain.theme.hoverButton; + var pressedButton = DesktopMain.theme.pressedButton; + var disabledButton = DesktopMain.theme.disabledButton; + + normalSprite = new SpliceSprite(normalButton.sprite, x, y, 75, 24, normalButton.left, normalButton.top, normalButton.bottom, normalButton.right); + hoverSprite = new SpliceSprite(hoverButton.sprite, x, y, 75, 24, hoverButton.left, hoverButton.top, hoverButton.bottom, hoverButton.right); + pressedSprite = new SpliceSprite(pressedButton.sprite, x, y, 75, 24, pressedButton.left, pressedButton.top, pressedButton.bottom, pressedButton.right); + disabledSprite = new SpliceSprite(disabledButton.sprite, x, y, 75, 24, disabledButton.left, disabledButton.top, disabledButton.bottom, disabledButton.right); + + label = new FlxUIText(0, 0, 75, text); + } + + public override function update(elapsed:Float) { + super.update(elapsed); + var mouseInput = DesktopMain.instance.mouseInput; + if (mouseInput.overlaps(normalSprite, camera)) { + if (mouseInput.justReleased) { + callback(); + return; + } + + if (mouseInput.justPressed || mouseInput.pressed) + frame = 2; + else + frame = 1; + mouseInput.cancel(); + } else + frame = 0; + + if (disabled) frame = 3; + + for(e in [normalSprite, hoverSprite, pressedSprite, disabledSprite]) + e.update(elapsed); + } + + public override function destroy() { + for(e in [normalSprite, hoverSprite, pressedSprite, disabledSprite]) + e.destroy(); + scrollFactor.put(); + super.destroy(); + } + + public function resize(width:Float, height:Float) { + this.width = width; + this.height = height; + normalSprite.resize(width, height); + label.fieldWidth = width; + } + public override function draw() { + super.draw(); + var spr = switch(frame) { + case 1: hoverSprite; + case 2: pressedSprite; + case 3: disabledSprite; + default: normalSprite; + }; + spr.resize(width, height); + for(sprite in [spr, label]) { + sprite.cameras = cameras; + sprite.setPosition(x, y); + sprite.scrollFactor.set(scrollFactor.x, scrollFactor.y); + sprite.draw(); + } + } +} \ No newline at end of file diff --git a/source/funkin/desktop/sprites/SpliceSprite.hx b/source/funkin/desktop/sprites/SpliceSprite.hx new file mode 100644 index 00000000..401e721c --- /dev/null +++ b/source/funkin/desktop/sprites/SpliceSprite.hx @@ -0,0 +1,126 @@ +package funkin.desktop.sprites; + +import openfl.display.BitmapData; +import openfl.geom.Rectangle; +import openfl.geom.Point; +import flixel.FlxObject; +import flixel.FlxSprite; +import flixel.system.FlxAssets.FlxGraphicAsset; + +class SpliceSprite extends FlxObject { + public var topLeft:FlxSprite = new FlxSprite(); + public var left:FlxSprite = new FlxSprite(); + public var bottomLeft:FlxSprite = new FlxSprite(); + public var bottom:FlxSprite = new FlxSprite(); + public var bottomRight:FlxSprite = new FlxSprite(); + public var right:FlxSprite = new FlxSprite(); + public var topRight:FlxSprite = new FlxSprite(); + public var top:FlxSprite = new FlxSprite(); + + public var __internalSprite:FlxSprite; + public var slice:Array = [0, 0, 0, 0]; + + public function new(spr:FlxGraphicAsset, x:Float, y:Float, width:Float, height:Float, left:Float = 5, top:Float = 5, bottom:Float = 5, right:Float = 5) { + super(); + this.x = x; + this.y = y; + this.width = width; + this.height = height; + + __internalSprite = new FlxSprite(0, 0, spr); + + slice = [Std.int(left), Std.int(bottom), Std.int(top), Std.int(right)]; + // for(e in [topLeft, left, bottomLeft, bottom, bottomRight, right, topRight, top]) { + // e.loadGraphic(spr); + // } + updateRects(); + } + + public function updateRects() { + var parts = [topLeft, left, bottomLeft, bottom, bottomRight, right, topRight, top]; + var _left:Int = slice[0]; + var _down:Int = slice[1]; + var _up:Int = slice[2]; + var _right:Int = slice[3]; + var _height:Int = __internalSprite.frameHeight; + var _width:Int = __internalSprite.frameWidth; + + topLeft.pixels = new BitmapData(_left, _up, true, 0); + left.pixels = new BitmapData(_left, _height - _up - _down, true, 0); + bottomLeft.pixels = new BitmapData(_left, _down, true, 0); + bottom.pixels = new BitmapData(_width - _left - _right, _down, true, 0); + bottomRight.pixels = new BitmapData(_right, _down, true, 0); + right.pixels = new BitmapData(_right, _height - _up - _down, true, 0); + topRight.pixels = new BitmapData(_right, _up, true, 0); + top.pixels = new BitmapData(_width - _left - _right, _up, true, 0); + + + for(e in parts) e.pixels.lock(); + + var pos = new Point(0, 0); + topLeft.pixels.copyPixels(__internalSprite.pixels, new Rectangle(0, 0, _left, _up), pos); + left.pixels.copyPixels(__internalSprite.pixels, new Rectangle(0, _up, _left, _height - _up - _down), pos); + bottomLeft.pixels.copyPixels(__internalSprite.pixels, new Rectangle(0, _height - _down, _left, _down), pos); + bottom.pixels.copyPixels(__internalSprite.pixels, new Rectangle(_left, _height - _down, _width - _left - _right, _down), pos); + bottomRight.pixels.copyPixels(__internalSprite.pixels, new Rectangle(_width - _right, _height - _down, _right, _down), pos); + right.pixels.copyPixels(__internalSprite.pixels, new Rectangle(_width - _right, _up, _right, _height - _down - _up), pos); + topRight.pixels.copyPixels(__internalSprite.pixels, new Rectangle(_width - _right, 0, _right, _up), pos); + top.pixels.copyPixels(__internalSprite.pixels, new Rectangle(_left, 0, _width - _left - _right, _up), pos); + + for(e in parts) e.pixels.unlock(); + } + + public override function destroy() { + for(e in [topLeft, left, bottomLeft, bottom, bottomRight, right, topRight, top, __internalSprite]) + e.destroy(); + super.destroy(); + } + + public function resize(width:Float, height:Float) { + this.width = width; + this.height = height; + } + + public override function draw() { + if (!visible) return; + super.draw(); + var parts = [topLeft, left, bottomLeft, bottom, bottomRight, right, topRight, top]; + + var _left:Int = slice[0]; + var _down:Int = slice[1]; + var _up:Int = slice[2]; + var _right:Int = slice[3]; + + // left + topLeft.setPosition(x, y); + left.setPosition(x, y + _up); + left.setSpriteSize(_left, height - _up - _down); + bottomLeft.setPosition(x, y + height - _down); + + // top + top.setPosition(x + _left, y); + top.setSpriteSize(width - _left - _right, _up); + + // bottom + bottom.setPosition(x + _left, y + height - _down); + bottom.setSpriteSize(width - _left - _right, _down); + + // right + topRight.setPosition(x + (width - _right), y); + right.setPosition(x + (width - _right), y + _up); + right.setSpriteSize(_right, height - _up - _down); + bottomRight.setPosition(x + (width - _right), y + height - _down); + + for(e in parts) { + e.cameras = cameras; + e.scrollFactor.set(scrollFactor.x, scrollFactor.y); + e.draw(); + } + } + + public override function update(elapsed:Float) { + super.update(elapsed); + for(e in [topLeft, left, bottomLeft, bottom, bottomRight, right, topRight, top]) + e.update(elapsed); + } +} \ No newline at end of file diff --git a/source/funkin/desktop/theme/Theme.hx b/source/funkin/desktop/theme/Theme.hx index db41c401..da66dd2f 100644 --- a/source/funkin/desktop/theme/Theme.hx +++ b/source/funkin/desktop/theme/Theme.hx @@ -23,10 +23,21 @@ class Theme { return new Theme(content); } + /** + * CAPTION + */ public var captionActive:ThemeData = new ThemeData(); public var captionInactive:ThemeData = new ThemeData(); public var captionButtons:ThemeData = new ThemeData(); + /** + * BUTTON + */ + public var normalButton:ThemeData = new ThemeData(); + public var hoverButton:ThemeData = new ThemeData(); + public var pressedButton:ThemeData = new ThemeData(); + public var disabledButton:ThemeData = new ThemeData(); + public function new(content:String) { try { var access = new Access(Xml.parse(content).firstElement()); diff --git a/source/funkin/desktop/windows/Window.hx b/source/funkin/desktop/windows/Window.hx index 9e301d4c..7c28363b 100644 --- a/source/funkin/desktop/windows/Window.hx +++ b/source/funkin/desktop/windows/Window.hx @@ -13,6 +13,7 @@ import flixel.FlxG; import flixel.tweens.FlxTween; import flixel.tweens.FlxEase; import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; +import funkin.desktop.sprites.*; typedef WindowCam = { @@ -22,8 +23,8 @@ typedef WindowCam = { var height:Int; } class Window extends FlxTypedGroup { - public var windowFrame:FlxUI9SliceSprite; - public var windowInactiveFrame:FlxUI9SliceSprite; + public var windowFrame:SpliceSprite; + public var windowInactiveFrame:SpliceSprite; public var captionButtons:FlxTypedSpriteGroup; public var windowWidth:Int = 0; @@ -56,22 +57,16 @@ class Window extends FlxTypedGroup { } public function new(content:WindowContent) { super(); - windowFrame = new FlxUI9SliceSprite(0, 0, - Paths.image(DesktopMain.theme.captionActive.sprite), - new Rectangle(10, 10), [ - Std.int(DesktopMain.theme.captionActive.left), - Std.int(DesktopMain.theme.captionActive.top), - Std.int(DesktopMain.theme.captionActive.right), - Std.int(DesktopMain.theme.captionActive.bottom) - ]); - windowInactiveFrame = new FlxUI9SliceSprite(0, 0, - Paths.image(DesktopMain.theme.captionInactive.sprite), - new Rectangle(10, 10), [ - Std.int(DesktopMain.theme.captionInactive.left), - Std.int(DesktopMain.theme.captionInactive.top), - Std.int(DesktopMain.theme.captionInactive.right), - Std.int(DesktopMain.theme.captionInactive.bottom) - ]); + windowFrame = new SpliceSprite(Paths.image(DesktopMain.theme.captionActive.sprite), 0, 0, 10, 10, + Std.int(DesktopMain.theme.captionActive.left), + Std.int(DesktopMain.theme.captionActive.top), + Std.int(DesktopMain.theme.captionActive.right), + Std.int(DesktopMain.theme.captionActive.bottom)); + windowInactiveFrame = new SpliceSprite(Paths.image(DesktopMain.theme.captionInactive.sprite), 0, 0, 10, 10, + Std.int(DesktopMain.theme.captionInactive.left), + Std.int(DesktopMain.theme.captionInactive.top), + Std.int(DesktopMain.theme.captionInactive.right), + Std.int(DesktopMain.theme.captionInactive.bottom)); add(windowFrame); add(windowInactiveFrame); diff --git a/source/funkin/desktop/windows/WindowContent.hx b/source/funkin/desktop/windows/WindowContent.hx index eb9bb041..fb448aab 100644 --- a/source/funkin/desktop/windows/WindowContent.hx +++ b/source/funkin/desktop/windows/WindowContent.hx @@ -5,7 +5,7 @@ import flixel.FlxSprite; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.FlxCamera; -class WindowContent extends FlxTypedGroup { +class WindowContent extends WindowGroup { public var winX(default, set):Float = 0; public var winY(default, set):Float = 0; public var title(default, set):String = "Window"; diff --git a/source/funkin/desktop/windows/WindowGroup.hx b/source/funkin/desktop/windows/WindowGroup.hx index d7f84cba..eea068c2 100644 --- a/source/funkin/desktop/windows/WindowGroup.hx +++ b/source/funkin/desktop/windows/WindowGroup.hx @@ -2,11 +2,16 @@ package funkin.desktop.windows; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.FlxBasic; +import flixel.FlxCamera; class WindowGroup extends FlxTypedGroup { public override function update(elapsed:Float) { // update them backwards, so that the top most window gets the priority var i = length; + + @:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras; + @:privateAccess if (cameras != null) FlxCamera._defaultCameras = cameras; + while(i > 0) { i--; var window = members[i]; @@ -14,5 +19,7 @@ class WindowGroup extends FlxTypedGroup { continue; window.update(elapsed); } + + @:privateAccess FlxCamera._defaultCameras = oldDefaultCameras; } } \ No newline at end of file diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index 9d431a88..035b96ff 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -189,6 +189,11 @@ class CoolUtil } } + public static function setSpriteSize(sprite:FlxSprite, width:Float, height:Float) { + sprite.scale.set(width / sprite.frameWidth, height / sprite.frameHeight); + sprite.updateHitbox(); + } + /** * Returns last member of array */