diff --git a/source/funkin/editors/import.hx b/source/funkin/editors/import.hx new file mode 100644 index 00000000..a5cced1d --- /dev/null +++ b/source/funkin/editors/import.hx @@ -0,0 +1,3 @@ +package funkin.editors; + +using funkin.editors.ui.UIUtil; \ No newline at end of file diff --git a/source/funkin/editors/ui/UIButton.hx b/source/funkin/editors/ui/UIButton.hx index 69b09f0d..c389fd95 100644 --- a/source/funkin/editors/ui/UIButton.hx +++ b/source/funkin/editors/ui/UIButton.hx @@ -7,15 +7,19 @@ class UIButton extends UISprite { public var bHeight:Int = 20; public var callback:Void->Void = null; + public var field:UIText; + public function resize(w:Int, h:Int) { bWidth = w; bHeight = h; + field.fieldWidth = w; } - public override function new(x:Float, y:Float, t:String, callback:Void->Void, w:Float = 120, h:Float = 20) { + public override function new(x:Float, y:Float, text:String, callback:Void->Void, w:Float = 120, h:Float = 20) { super(x, y); frames = CoolUtil.loadFrames(Paths.image('editors/ui/button')); this.callback = callback; + members.push(field = new UIText(x, y, w, text)); } public override function updateButton() { @@ -33,6 +37,7 @@ class UIButton extends UISprite { } public override function draw() { + field.follow(this, 0, ((height - field.height) / 2)); var x:Float = this.x; var y:Float = this.y; var offset:Int = hovered ? (pressed ? 18 : 9) : 0; diff --git a/source/funkin/editors/ui/UICheckbox.hx b/source/funkin/editors/ui/UICheckbox.hx index 23bbd424..f268dbad 100644 --- a/source/funkin/editors/ui/UICheckbox.hx +++ b/source/funkin/editors/ui/UICheckbox.hx @@ -6,7 +6,7 @@ class UICheckbox extends UISprite { public var checked:Bool = false; public var onChecked:Bool->Void = null; - public var field:FunkinText; + public var field:UIText; public var check:FlxSprite; public function new(x:Float, y:Float, text:String, checked:Bool = false, w:Int = 0) { @@ -17,7 +17,7 @@ class UICheckbox extends UISprite { this.checked = checked; - field = new UIText(x, y, w, text, 14, false); + field = new UIText(x, y, w, text); check = new FlxSprite().loadGraphicFromSprite(this); check.animation.play("checkmark"); @@ -41,10 +41,8 @@ class UICheckbox extends UISprite { } public inline function updatePositions() { - check.cameras = field.cameras = cameras; - - field.setPosition(x + 25, y); - check.setPosition(x, y); + check.follow(this); + field.follow(this, 25, 0); } public override function draw() { diff --git a/source/funkin/editors/ui/UIText.hx b/source/funkin/editors/ui/UIText.hx index c508b7eb..960dc2cb 100644 --- a/source/funkin/editors/ui/UIText.hx +++ b/source/funkin/editors/ui/UIText.hx @@ -1,5 +1,7 @@ package funkin.editors.ui; +import funkin.ui.FunkinText; + class UIText extends FunkinText { // PUTTING THIS HERE IN CASE IMMA MAKE FUTURE CHANGES public function new(x, y, w, text, size:Int = 14) { diff --git a/source/funkin/editors/ui/UIUtil.hx b/source/funkin/editors/ui/UIUtil.hx new file mode 100644 index 00000000..6b749b05 --- /dev/null +++ b/source/funkin/editors/ui/UIUtil.hx @@ -0,0 +1,9 @@ +package funkin.editors.ui; + +class UIUtil { + public static inline function follow(spr:FlxSprite, target:FlxSprite, x:Float = 0, y:Float = 0) { + spr.cameras = target.cameras; + spr.setPosition(target.x + x, target.y + y); + spr.scrollFactor.set(target.scrollFactor.x, target.scrollFactor.y); + } +} \ No newline at end of file