From de50b3eb290570136928d1a40570fd47ebd9bbf4 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Mon, 26 Dec 2022 15:37:59 +0100 Subject: [PATCH] i agree with gray --- buildnumber.txt | 2 +- source/funkin/desktop/DesktopMain.hx | 25 ++++++++ .../funkin/desktop/editors/CharacterEditor.hx | 23 ++++++-- source/funkin/desktop/import.hx | 3 +- source/funkin/desktop/sprites/Button.hx | 15 ++++- source/funkin/desktop/sprites/DropDown.hx | 1 + source/funkin/desktop/sprites/InputBox.hx | 57 +++++++++++++++++++ source/funkin/system/XMLUtil.hx | 25 ++++---- 8 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 source/funkin/desktop/sprites/InputBox.hx diff --git a/buildnumber.txt b/buildnumber.txt index d20a7de3..fe3b82ae 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1788 \ No newline at end of file +1791 \ No newline at end of file diff --git a/source/funkin/desktop/DesktopMain.hx b/source/funkin/desktop/DesktopMain.hx index 986159f2..619deeba 100644 --- a/source/funkin/desktop/DesktopMain.hx +++ b/source/funkin/desktop/DesktopMain.hx @@ -26,6 +26,8 @@ class DesktopMain extends MusicBeatState { public static var instance:DesktopMain; + public static var currentFocus:IDesktopFocusableObject; + public static var mouseInput:MouseInput; public static var theme:Theme = null; @@ -137,6 +139,24 @@ class DesktopMain extends MusicBeatState { for(e in win.windowCameras) FlxG.cameras.add(e.camera, false); } } + + public static function loseFocus(obj:IDesktopFocusableObject) { + if (currentFocus == obj) { + currentFocus.onFocusLost(); + currentFocus = null; + } + } + + public static function setFocus(obj:IDesktopFocusableObject) { + if (currentFocus == obj) return; + if (currentFocus != null) + currentFocus.onFocusLost(); + (currentFocus = obj).onFocus(); + } + + public static function hasFocus(obj:IDesktopFocusableObject) { + return currentFocus == obj; + } } class MouseInput { @@ -184,4 +204,9 @@ class MouseInput { return ((pos.x > rect.x) && (pos.x < rect.x + rect.width)) && ((pos.y > rect.y) && (pos.y < rect.y + rect.height)); } +} + +interface IDesktopFocusableObject { + public function onFocus():Void; + public function onFocusLost():Void; } \ No newline at end of file diff --git a/source/funkin/desktop/editors/CharacterEditor.hx b/source/funkin/desktop/editors/CharacterEditor.hx index 2475ae36..fdf944f8 100644 --- a/source/funkin/desktop/editors/CharacterEditor.hx +++ b/source/funkin/desktop/editors/CharacterEditor.hx @@ -6,6 +6,8 @@ import flixel.FlxObject; import flixel.FlxCamera; import flixel.FlxG; +using funkin.system.XMLUtil; + class CharacterEditor extends WindowContent { public function new(curCharacter:String) { super('Character Editor - Loading...', 0, 0, 1200, 600); @@ -17,7 +19,8 @@ class CharacterEditor extends WindowContent { public var camFollow:FlxObject; public var tabView:TabView; - public var animList:Array = []; + public var animList:Array = []; + public var animListNames:Array = []; /** * ANIMATION TAB @@ -57,6 +60,12 @@ class CharacterEditor extends WindowContent { add(camFollow); windowCamera.follow(camFollow, LOCKON, 999); + // loading animations from character + animList = []; + if (char.xml != null) + for(anim in char.xml.nodes.anim) + animList.push(anim.extractAnimFromXML()); + // interface setup setupTabView(); } @@ -66,9 +75,13 @@ class CharacterEditor extends WindowContent { tabView.updateAnchor(1, 0, [camHUD]); add(tabView); - animsDropDown = new DropDown(10, 10, [], function(id) { - char.playAnim(animList[id], true); + var labels:Array = []; + var label:WindowText = null; + labels.push(label = new WindowText(10, 10, 0, "Animations")); + animsDropDown = new DropDown(10, label.y + label.height, [], function(id) { + char.playAnim(animList[id].name, true); }); + labels.push(label = new WindowText(10, animsDropDown.y + animsDropDown.height + 10, 0, "Animation Name")); refreshAnims(); for(spr in [animsDropDown]) @@ -76,8 +89,8 @@ class CharacterEditor extends WindowContent { } public function refreshAnims() { - @:privateAccess animList = [for(k=>e in char.animation._animations) k]; - animsDropDown.options = animList; + animListNames = [for(e in animList) e.name]; + animsDropDown.options = animListNames; animsDropDown.onSelectionChange(0); } diff --git a/source/funkin/desktop/import.hx b/source/funkin/desktop/import.hx index 0d58811c..f5d0ee4e 100644 --- a/source/funkin/desktop/import.hx +++ b/source/funkin/desktop/import.hx @@ -1,2 +1,3 @@ using funkin.desktop.DesktopUtils; -using funkin.desktop.windows.ContextMenu; \ No newline at end of file +using funkin.desktop.windows.ContextMenu; +using funkin.desktop.DesktopMain; \ No newline at end of file diff --git a/source/funkin/desktop/sprites/Button.hx b/source/funkin/desktop/sprites/Button.hx index 52b19a05..ef42aa6c 100644 --- a/source/funkin/desktop/sprites/Button.hx +++ b/source/funkin/desktop/sprites/Button.hx @@ -1,5 +1,6 @@ package funkin.desktop.sprites; +import funkin.desktop.DesktopMain.IDesktopFocusableObject; import funkin.desktop.theme.Theme; import flixel.FlxObject; import flixel.addons.ui.FlxUIText; @@ -7,7 +8,9 @@ import flixel.FlxSprite; import flixel.math.FlxPoint; import funkin.desktop.windows.WindowGroup; -class Button extends FlxObject { +using funkin.desktop.DesktopMain; + +class Button extends FlxObject implements IDesktopFocusableObject { public var callback:Void->Void; public var disabled:Bool = false; @@ -62,8 +65,10 @@ class Button extends FlxObject { return; } - if (mouseInput.justPressed || mouseInput.pressed) + if (mouseInput.justPressed || mouseInput.pressed) { + this.setFocus(); frame = 2; + } else frame = 1; mouseInput.cancel(); @@ -84,6 +89,8 @@ class Button extends FlxObject { } public override function destroy() { + DesktopMain.loseFocus(this); + for(e in [normalSprite, hoverSprite, pressedSprite, disabledSprite]) e.destroy(); scrollFactor.put(); @@ -111,4 +118,8 @@ class Button extends FlxObject { label.y += (height - label.height) / 2; label.draw(); } + + + public function onFocus() {} + public function onFocusLost() {} } \ No newline at end of file diff --git a/source/funkin/desktop/sprites/DropDown.hx b/source/funkin/desktop/sprites/DropDown.hx index dbe09034..c8a4c7cd 100644 --- a/source/funkin/desktop/sprites/DropDown.hx +++ b/source/funkin/desktop/sprites/DropDown.hx @@ -12,6 +12,7 @@ class DropDown extends Button { super(x, y, "", onClick, normalButton, hoverButton, pressedButton, disabledButton); this.options = options; onSelectionChange(curId); + this.onChange = onChange; } public function onClick() { diff --git a/source/funkin/desktop/sprites/InputBox.hx b/source/funkin/desktop/sprites/InputBox.hx new file mode 100644 index 00000000..f1c7807f --- /dev/null +++ b/source/funkin/desktop/sprites/InputBox.hx @@ -0,0 +1,57 @@ +package funkin.desktop.sprites; + +import flixel.math.FlxMath; +import openfl.ui.Keyboard; +import openfl.events.KeyboardEvent; +import flixel.FlxG; +import lime.app.Application; + +class InputBox extends Button { + public var index:Int = 0; + + public function new(x:Float, y:Float, w:Float, t:String, onChange:Void->Void) { + super(x, y, t, function() { + setIndex(label.text.length); + }); + this.resize(w, height); + this.label.alignment = LEFT; + FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); + Application.current.window.onTextInput.add(onTextInput); + } + + private function onKeyDown(event:KeyboardEvent) { + if (!this.hasFocus()) return; + switch(event.keyCode) { + case Keyboard.CONTROL | Keyboard.SHIFT: + // nothing + case Keyboard.ESCAPE: + this.loseFocus(); + case Keyboard.LEFT: + changeIndex(-1); + case Keyboard.RIGHT: + changeIndex(1); + case Keyboard.ENTER | Keyboard.NUMPAD_ENTER: + onTextInput("\n"); + } + } + + private function onTextInput(input:String) { + if (!this.hasFocus()) return; + + + } + + public inline function changeIndex(change:Int) { + setIndex(Std.int(FlxMath.bound(index + change, 0, label.text.length))); + } + + public inline function setIndex(index:Int) { + this.index = index; + + } + + public override function destroy() { + super.destroy(); + + } +} \ No newline at end of file diff --git a/source/funkin/system/XMLUtil.hx b/source/funkin/system/XMLUtil.hx index e946b95b..336e757d 100644 --- a/source/funkin/system/XMLUtil.hx +++ b/source/funkin/system/XMLUtil.hx @@ -90,16 +90,7 @@ class XMLUtil { return spr; } - /** - * Adds an XML animation to `sprite`. - * @param sprite Destination sprite - * @param anim Animation (Must be a `anim` XML node) - */ - public static function addXMLAnimation(sprite:FlxSprite, anim:Access, loop:Bool = false):ErrorCode { - var animType:XMLAnimType = NONE; - if (sprite is XMLSprite) - animType = cast(sprite, XMLSprite).spriteAnimType; - + public static function extractAnimFromXML(anim:Access, animType:XMLAnimType = NONE, loop:Bool = false):AnimData { var animData:AnimData = { name: null, anim: null, @@ -127,6 +118,20 @@ class XMLUtil { } } + return animData; + } + /** + * Adds an XML animation to `sprite`. + * @param sprite Destination sprite + * @param anim Animation (Must be a `anim` XML node) + */ + public static function addXMLAnimation(sprite:FlxSprite, anim:Access, loop:Bool = false):ErrorCode { + var animType:XMLAnimType = NONE; + if (sprite is XMLSprite) + animType = cast(sprite, XMLSprite).spriteAnimType; + + var animData = extractAnimFromXML(anim, animType, loop); + if (animData.name != null && animData.anim != null) { if (animData.fps <= 0 #if web || animData.fps == null #end) animData.fps = 24;