From 0970a63dd16b9d5c714f87c68e3c5149436258bc Mon Sep 17 00:00:00 2001 From: lunarcleint Date: Tue, 4 Mar 2025 19:52:58 -0700 Subject: [PATCH] AUTOCOMPLETE FOR ANIMS!!! --- source/funkin/backend/utils/CoolUtil.hx | 7 +++++++ .../funkin/editors/character/CharacterAnimButton.hx | 4 ++-- .../funkin/editors/character/CharacterAnimsWindow.hx | 7 +++++++ .../editors/character/CharacterPropertiesWindow.hx | 1 + source/funkin/editors/ui/UIAutoCompleteTextBox.hx | 12 ++++-------- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/source/funkin/backend/utils/CoolUtil.hx b/source/funkin/backend/utils/CoolUtil.hx index 4033b63c..61dfa725 100644 --- a/source/funkin/backend/utils/CoolUtil.hx +++ b/source/funkin/backend/utils/CoolUtil.hx @@ -1184,6 +1184,13 @@ final class CoolUtil return animsList; } + public static function getAnimsListFromSprite(spr:FunkinSprite):Array { + if (spr.animateAtlas != null) { + return [for (symbol => timeline in spr.animateAtlas.anim.symbolDictionary) symbol]; + } else + return getAnimsListFromFrames(spr.frames); + } + // TODO: check this for bugs // Code from https://github.com/elnabo/equals/blob/master/src/equals/Equal.hx, (MIT License), but updated to work with haxe 4 public static function deepEqual (a:T, b:T) : Bool { diff --git a/source/funkin/editors/character/CharacterAnimButton.hx b/source/funkin/editors/character/CharacterAnimButton.hx index eb20767b..79eeb1e4 100644 --- a/source/funkin/editors/character/CharacterAnimButton.hx +++ b/source/funkin/editors/character/CharacterAnimButton.hx @@ -25,7 +25,7 @@ class CharacterAnimButton extends UIButton { public var animationDisplayBG:UISliceSprite; public var nameTextBox:UITextBox; - public var animTextBox:UITextBox; + public var animTextBox:UIAutoCompleteTextBox; public var positionXStepper:UINumericStepper; public var positionYStepper:UINumericStepper; public var fpsStepper:UINumericStepper; @@ -78,7 +78,7 @@ class CharacterAnimButton extends UIButton { foldableButtons.push(nameTextBox); addLabelOn(nameTextBox, "Name", 12); - animTextBox = new UITextBox(nameTextBox.x + 100, nameTextBox.y, animData.anim, 156, 22, false, true); + animTextBox = new UIAutoCompleteTextBox(nameTextBox.x + 100, nameTextBox.y, animData.anim, 156, 22, false, true); animTextBox.onChange = (newAnim:String) -> {this.changeAnim(newAnim);}; members.push(animTextBox); foldableButtons.push(animTextBox); diff --git a/source/funkin/editors/character/CharacterAnimsWindow.hx b/source/funkin/editors/character/CharacterAnimsWindow.hx index 2cb4f9c6..48980179 100644 --- a/source/funkin/editors/character/CharacterAnimsWindow.hx +++ b/source/funkin/editors/character/CharacterAnimsWindow.hx @@ -41,6 +41,8 @@ class CharacterAnimsWindow extends UIButtonList { for (anim in character.getAnimOrder()) addAnimation(character.animDatas.get(anim)); addButton.callback = generateAnimation; + + setAnimAutoComplete(CoolUtil.getAnimsListFromSprite(character)); } public var ghosts:Array = []; @@ -113,6 +115,11 @@ class CharacterAnimsWindow extends UIButtonList { } } + public inline function setAnimAutoComplete(anims:Array) { + for (button in buttons) + button.animTextBox.suggestItems = anims; + } + public function findValid():Null { for (button in buttons) if (button.valid) return button.anim; return null; diff --git a/source/funkin/editors/character/CharacterPropertiesWindow.hx b/source/funkin/editors/character/CharacterPropertiesWindow.hx index ed3eb5c0..991730b2 100644 --- a/source/funkin/editors/character/CharacterPropertiesWindow.hx +++ b/source/funkin/editors/character/CharacterPropertiesWindow.hx @@ -188,6 +188,7 @@ class CharacterPropertiesWindow extends UISliceSprite { for (anim in animsWindow.buttons) anim.checkValid(); // Re-add all animations CharacterEditor.instance.playAnimation(animsWindow.findValid().getDefault(animsWindow.buttons.members[0].anim)); + animsWindow.setAnimAutoComplete(CoolUtil.getAnimsListFromSprite(character)); } public function changeFlipX(newFlipX:Bool) @:privateAccess { diff --git a/source/funkin/editors/ui/UIAutoCompleteTextBox.hx b/source/funkin/editors/ui/UIAutoCompleteTextBox.hx index 60259c41..497fe383 100644 --- a/source/funkin/editors/ui/UIAutoCompleteTextBox.hx +++ b/source/funkin/editors/ui/UIAutoCompleteTextBox.hx @@ -9,10 +9,10 @@ class UIAutoCompleteTextBox extends UITextBox { public var suggestItems(default, set):Array = []; var suggestIndex = 0; - public function new(x:Float, y:Float, text:String = "", width:Int = 320, height:Int = 32, multiline:Bool = false) { - super(x, y, text, width, height, multiline); + public function new(x:Float, y:Float, text:String = "", width:Int = 320, height:Int = 32, multiline:Bool = false, small:Bool = false) { + super(x, y, text, width, height, multiline, small); - suggestionText = new UIText(0, 0, width, ""); + suggestionText = new UIText(0, 0, width, "", small ? 12 : 15); suggestionText.color = 0xFF888888; suggestionText.visible = false; members.insert(members.indexOf(label), suggestionText); @@ -20,11 +20,7 @@ class UIAutoCompleteTextBox extends UITextBox { public override function update(elapsed:Float) { super.update(elapsed); - - var selected = selectable && focused; - - suggestionText.exists = selected; - + suggestionText.exists = selectable && focused; suggestionText.follow(label, 0, 0); }