diff --git a/assets/images/editors/ui/button.png b/assets/images/editors/ui/button.png new file mode 100644 index 00000000..cdc0d1b4 Binary files /dev/null and b/assets/images/editors/ui/button.png differ diff --git a/assets/images/editors/ui/button.xml b/assets/images/editors/ui/button.xml new file mode 100644 index 00000000..e17db2e6 --- /dev/null +++ b/assets/images/editors/ui/button.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/images/editors/ui/inputbox.png b/assets/images/editors/ui/inputbox.png new file mode 100644 index 00000000..a81994a5 Binary files /dev/null and b/assets/images/editors/ui/inputbox.png differ 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) {