From 086c265ef76911ded02b1c2acb029322dda17357 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:24:09 -0700 Subject: [PATCH] cancel button on the create strum thing --- source/funkin/editors/charter/Charter.hx | 7 +-- .../charter/CharterStrumlineAddButton.hx | 50 ------------------ .../charter/CharterStrumlineExtraButton.hx | 52 +++++++++++++++++++ .../editors/charter/CharterStrumlineScreen.hx | 13 +++-- 4 files changed, 62 insertions(+), 60 deletions(-) delete mode 100644 source/funkin/editors/charter/CharterStrumlineAddButton.hx create mode 100644 source/funkin/editors/charter/CharterStrumlineExtraButton.hx diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 88351491..424385bf 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -54,7 +54,7 @@ class Charter extends UIState { public var topLimit:FlxSprite; public var strumlineInfoBG:FlxSprite; - public var strumlineAddButton:CharterStrumlineAddButton; + public var strumlineAddButton:CharterStrumlineExtraButton; public var hitsound:FlxSound; public var metronome:FlxSound; @@ -388,7 +388,8 @@ class Charter extends UIState { strumlineInfoBG.y = 23; strumlineInfoBG.scrollFactor.set(); - strumlineAddButton = new CharterStrumlineAddButton(); + strumlineAddButton = new CharterStrumlineExtraButton("editors/charter/add-strumline", "Add New"); + strumlineAddButton.onClick = createStrumWithUI; strumlineAddButton.cameras = [charterCamera]; strumlineInfoBG.cameras = [charterCamera]; @@ -752,7 +753,7 @@ class Charter extends UIState { public function createStrumWithUI() { FlxG.state.openSubState(new CharterStrumlineScreen(strumLines.members.length, null, (_) -> { - createStrumline(strumLines.members.length, _); + if (_ != null) createStrumline(strumLines.members.length, _); })); } diff --git a/source/funkin/editors/charter/CharterStrumlineAddButton.hx b/source/funkin/editors/charter/CharterStrumlineAddButton.hx deleted file mode 100644 index 21271b63..00000000 --- a/source/funkin/editors/charter/CharterStrumlineAddButton.hx +++ /dev/null @@ -1,50 +0,0 @@ -package funkin.editors.charter; - -import flixel.math.FlxPoint; - -class CharterStrumlineAddButton extends UISprite { - public var addButton:UISprite; - public var addText:UIText; - - public override function new(?x:Float, ?y:Float) { - super(); - - scrollFactor.set(1, 0); - alpha = 0; - - addButton = new UISprite(); - addButton.loadGraphic(Paths.image("editors/charter/add-strumline")); - addButton.scale.set(0.75,0.75); - addButton.updateHitbox(); - addButton.antialiasing = false; - members.push(addButton); - - addText = new UIText(0,0, 160, "Add New"); - addText.alignment = CENTER; - members.push(addText); - } - - var addButtonScale:FlxPoint = FlxPoint.get(0,0); - - public override function update(elapsed:Float) { - addButton.follow(this, ((40 * 4) - addButton.width) / 2, 18); - addText.follow(this, 0, 84); - - super.update(elapsed); - - addButton.__rect.x = addButton.x; - addButton.__rect.y = addButton.y; - addButton.__rect.width = addButton.width; - addButton.__rect.height = addButton.height; - if(UIState.state.isOverlapping(addButton, addButton.__rect)) { - addButtonScale.set(0.85, 0.85); - if (FlxG.mouse.justReleased) Charter.instance.createStrumWithUI(); - } - else addButtonScale.set(0.75, 0.75); - - addButton.scale.set( - FlxMath.lerp(addButton.scale.x, addButtonScale.x, 1/6), - FlxMath.lerp(addButton.scale.y, addButtonScale.y, 1/6) - ); - } -} \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterStrumlineExtraButton.hx b/source/funkin/editors/charter/CharterStrumlineExtraButton.hx new file mode 100644 index 00000000..b1fc7ad3 --- /dev/null +++ b/source/funkin/editors/charter/CharterStrumlineExtraButton.hx @@ -0,0 +1,52 @@ +package funkin.editors.charter; + +import flixel.math.FlxPoint; + +class CharterStrumlineExtraButton extends UISprite { + public var button:UISprite; + public var text:UIText; + + public var onClick:Void->Void; + + public override function new(imagePath:String, text:String) { + super(); + + scrollFactor.set(1, 0); + alpha = 0; + + button = new UISprite(); + button.loadGraphic(Paths.image(imagePath)); + button.scale.set(0.75,0.75); + button.updateHitbox(); + button.antialiasing = false; + members.push(button); + + this.text = new UIText(0,0, 160, text); + this.text.alignment = CENTER; + members.push(this.text); + } + + var buttonScale:FlxPoint = FlxPoint.get(0,0); + + public override function update(elapsed:Float) { + button.follow(this, ((40 * 4) - button.width) / 2, 18); + text.follow(this, 0, 84); + + super.update(elapsed); + + button.__rect.x = button.x; + button.__rect.y = button.y; + button.__rect.width = button.width; + button.__rect.height = button.height; + if(UIState.state.isOverlapping(button, button.__rect)) { + buttonScale.set(0.85, 0.85); + if (FlxG.mouse.justReleased && onClick != null) onClick(); + } + else buttonScale.set(0.75, 0.75); + + button.scale.set( + FlxMath.lerp(button.scale.x, buttonScale.x, 1/6), + FlxMath.lerp(button.scale.y, buttonScale.y, 1/6) + ); + } +} \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterStrumlineScreen.hx b/source/funkin/editors/charter/CharterStrumlineScreen.hx index 3751500f..3bf64618 100644 --- a/source/funkin/editors/charter/CharterStrumlineScreen.hx +++ b/source/funkin/editors/charter/CharterStrumlineScreen.hx @@ -100,13 +100,12 @@ class CharterStrumlineScreen extends UISubstateWindow { }, 125); add(saveButton); - if (!creatingStrumLine) { - closeButton = new UIButton(saveButton.x - 20, saveButton.y, "Close", function() { - close(); - }, 125); - add(closeButton); - closeButton.x -= closeButton.bWidth; - } + closeButton = new UIButton(saveButton.x - 20, saveButton.y, creatingStrumLine ? "Cancel" : "Close", function() { + if (creatingStrumLine) onSave(null); + close(); + }, 125); + add(closeButton); + closeButton.x -= closeButton.bWidth; } function updateCharacterIcons(characters:Array) {