i agree with gray
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
1788
|
||||
1791
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<String> = [];
|
||||
public var animList:Array<AnimData> = [];
|
||||
public var animListNames:Array<String> = [];
|
||||
|
||||
/**
|
||||
* 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<WindowText> = [];
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
using funkin.desktop.DesktopUtils;
|
||||
using funkin.desktop.windows.ContextMenu;
|
||||
using funkin.desktop.windows.ContextMenu;
|
||||
using funkin.desktop.DesktopMain;
|
||||
@@ -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() {}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user