hi guys (component editing)
possibly some messy code but oh boy
This commit is contained in:
@@ -34,17 +34,22 @@ class AlphabetEditor extends UIState {
|
||||
inline function translate(id:String, ?args:Array<Dynamic>)
|
||||
return TU.translate("editor.alphabet." + id, args);
|
||||
|
||||
public var brokenWarning:UIText;
|
||||
public var tape:Alphabet;
|
||||
public var bigLetter:Alphabet;
|
||||
public var curLetter:Int = 0;
|
||||
public var targetX:Float = 0;
|
||||
|
||||
public var queueReorder:Bool = false;
|
||||
public var componentList:UIButtonList<ComponentButton>;
|
||||
|
||||
public var infoWindow:GlyphInfoWindow;
|
||||
public var curSelectedComponent:AlphabetComponent = null;
|
||||
public var curSelectedData:AlphabetLetterData = null;
|
||||
public var outlineIdx:Int = -1;
|
||||
|
||||
public var defaultTmr:Float = 0.0;
|
||||
public var charsForDefault:Array<String> = [];
|
||||
public var charsForDefault:Array<Array<String>> = [];
|
||||
|
||||
public override function create() {
|
||||
super.create();
|
||||
@@ -167,7 +172,7 @@ class AlphabetEditor extends UIState {
|
||||
tape.renderMode = MONOSPACE;
|
||||
add(tape);
|
||||
|
||||
bigLetter = new Alphabet(0, 0, charsForDefault[0], "<SKIP>");
|
||||
bigLetter = new Alphabet(0, 0, "", "<SKIP>");
|
||||
bigLetter.copyData(tape);
|
||||
bigLetter.alignment = CENTER;
|
||||
bigLetter.scale.set(4, 4);
|
||||
@@ -176,27 +181,46 @@ class AlphabetEditor extends UIState {
|
||||
bigLetter.screenCenter();
|
||||
add(bigLetter);
|
||||
|
||||
updateTape();
|
||||
tape.x = targetX;
|
||||
|
||||
var infoWindow = new GlyphInfoWindow();
|
||||
infoWindow.info.text = [
|
||||
//"Char: " + allChars.charAt(randomIndex),
|
||||
//"Anim Name: " + allChars.charAt(randomIndex) + " bold0",
|
||||
"X Offset: " + 0,
|
||||
"Y Offset: " + 0,
|
||||
"ScaleX: " + 1,
|
||||
"ScaleY: " + 1,
|
||||
"Angle: " + 0,
|
||||
].join('\n');
|
||||
brokenWarning = new UIText(0, 550, FlxG.width, "", 32);
|
||||
brokenWarning.alignment = CENTER;
|
||||
brokenWarning.color = 0xFFFF6969;
|
||||
add(brokenWarning);
|
||||
|
||||
infoWindow = new GlyphInfoWindow();
|
||||
uiGroup.add(infoWindow);
|
||||
|
||||
componentList = new UIButtonList<ComponentButton>(0, 720 - 170 - 30, 230, 170, "Components:", FlxPoint.get(230, 50), FlxPoint.get(0, 0), 0);
|
||||
componentList.dragCallback = (button, oldID, newID) -> {
|
||||
queueReorder = true; // not do it for every button reordered
|
||||
}
|
||||
componentList.addButton.callback = () -> {
|
||||
curSelectedComponent = {
|
||||
anim: "",
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
||||
shouldRotate: false,
|
||||
angle: 0,
|
||||
sin: 0,
|
||||
cos: 1,
|
||||
|
||||
scaleX: 1,
|
||||
scaleY: 1,
|
||||
|
||||
hasColorMode: false,
|
||||
colorMode: bigLetter.colorMode
|
||||
};
|
||||
curSelectedData.components.push(curSelectedComponent);
|
||||
var newButton = new ComponentButton(curSelectedComponent);
|
||||
componentList.add(newButton);
|
||||
newButton.ID = componentList.buttons.members.length - 1; // readjust it because UIButtonList doesnt generate the id properly
|
||||
findOutline();
|
||||
infoWindow.updateInfo();
|
||||
}
|
||||
|
||||
updateTape();
|
||||
uiGroup.add(componentList);
|
||||
|
||||
add(topMenuSpr);
|
||||
@@ -222,36 +246,65 @@ class AlphabetEditor extends UIState {
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
if (queueReorder) {
|
||||
queueReorder = false;
|
||||
var outlines = [];
|
||||
var newList = [];
|
||||
for (button in componentList.buttons.members) {
|
||||
var com = button.component;
|
||||
if (com.outIndex != null) {
|
||||
var out = curSelectedData.components[com.outIndex];
|
||||
out.refIndex = newList.length;
|
||||
com.outIndex = outlines.length;
|
||||
outlines.push(out);
|
||||
}
|
||||
newList.push(com);
|
||||
}
|
||||
curSelectedData.components = outlines.concat(newList);
|
||||
|
||||
if (true) {
|
||||
findOutline();
|
||||
for (i in 0...curSelectedData.components.length) {
|
||||
var anim = bigLetter.text + i;
|
||||
bigLetter.animation.remove(anim);
|
||||
tape.animation.remove(anim);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentFocus == null) {
|
||||
if(FlxG.keys.justPressed.ANY)
|
||||
UIUtil.processShortcuts(topMenu);
|
||||
|
||||
if(curSelectedComponent != null) {
|
||||
if(FlxG.keys.pressed.K) {
|
||||
curSelectedComponent.y -= 100 * elapsed;
|
||||
}
|
||||
if(FlxG.keys.pressed.I) {
|
||||
curSelectedComponent.y += 100 * elapsed;
|
||||
}
|
||||
if(FlxG.keys.pressed.L) {
|
||||
curSelectedComponent.x -= 100 * elapsed;
|
||||
}
|
||||
if(FlxG.keys.pressed.J) {
|
||||
curSelectedComponent.x += 100 * elapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(curSelectedComponent != null) {
|
||||
if(FlxG.keys.pressed.I) {
|
||||
curSelectedComponent.y -= 100 * elapsed;
|
||||
}
|
||||
if(FlxG.keys.pressed.K) {
|
||||
curSelectedComponent.y += 100 * elapsed;
|
||||
}
|
||||
if(FlxG.keys.pressed.J) {
|
||||
curSelectedComponent.x -= 100 * elapsed;
|
||||
}
|
||||
if(FlxG.keys.pressed.L) {
|
||||
curSelectedComponent.x += 100 * elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
var lastIdx = Math.floor(defaultTmr);
|
||||
defaultTmr += elapsed * 0.5;
|
||||
if (lastIdx != (lastIdx = Math.floor(defaultTmr)))
|
||||
tape.text = charsForDefault[Math.floor(defaultTmr)] + " " + tape.manualLetters.join(" ");
|
||||
if (lastIdx != (lastIdx = Math.floor(defaultTmr))) {
|
||||
tape.text = "";
|
||||
for (def in charsForDefault)
|
||||
tape.text += def[Std.int(lastIdx % def.length)] + " ";
|
||||
tape.text += tape.manualLetters.join(" ");
|
||||
}
|
||||
tape.x = lerp(tape.x, targetX, 0.25);
|
||||
}
|
||||
|
||||
function updateTape() {
|
||||
charsForDefault = [];
|
||||
charsForDefault = [[], [], []];
|
||||
|
||||
for (i in 33...127) {
|
||||
var letter = String.fromCharCode(i);
|
||||
if (tape.manualLetters.contains(letter)) continue;
|
||||
@@ -261,19 +314,76 @@ class AlphabetEditor extends UIState {
|
||||
if (tape.fastGetLetterAnim(letter, data, com, i) == null)
|
||||
continue;
|
||||
}
|
||||
charsForDefault.push(letter);
|
||||
|
||||
if (i >= 'A'.code && i <= 'Z'.code && tape.defaults[CaseMode.UPPER] != null)
|
||||
charsForDefault[CaseMode.UPPER].push(letter);
|
||||
else if (i >= 'a'.code && i <= 'z'.code && tape.defaults[CaseMode.LOWER] != null)
|
||||
charsForDefault[CaseMode.LOWER].push(letter);
|
||||
else if (tape.defaults[CaseMode.NONE] != null)
|
||||
charsForDefault[CaseMode.NONE].push(letter);
|
||||
}
|
||||
defaultTmr %= charsForDefault.length;
|
||||
tape.text = charsForDefault[Math.floor(defaultTmr)] + " " + tape.manualLetters.join(" ");
|
||||
|
||||
var i = charsForDefault.length - 1;
|
||||
while (i >= 0) {
|
||||
if (charsForDefault[i].length <= 0)
|
||||
charsForDefault.splice(i, 1);
|
||||
--i;
|
||||
}
|
||||
|
||||
tape.text = "";
|
||||
for (def in charsForDefault)
|
||||
tape.text += def[Math.floor(defaultTmr % def.length)] + " ";
|
||||
tape.text += tape.manualLetters.join(" ");
|
||||
changeLetter(0);
|
||||
}
|
||||
|
||||
function changeLetter(inc:Int) {
|
||||
curLetter = CoolUtil.positiveModuloInt(curLetter + inc, tape.manualLetters.length + 1);
|
||||
curLetter = CoolUtil.positiveModuloInt(curLetter + inc, tape.manualLetters.length + charsForDefault.length);
|
||||
targetX = FlxG.width * 0.5 - tape.defaultAdvance * (0.5 + curLetter * 2);
|
||||
bigLetter.text = (curLetter == 0) ? charsForDefault[0] : tape.manualLetters[curLetter - 1];
|
||||
bigLetter.text = (curLetter < charsForDefault.length) ? charsForDefault[curLetter][0] : tape.manualLetters[curLetter - charsForDefault.length];
|
||||
bigLetter.updateHitbox();
|
||||
bigLetter.screenCenter();
|
||||
|
||||
checkForFailed();
|
||||
|
||||
while (componentList.buttons.members.length > 0)
|
||||
componentList.remove(componentList.buttons.members[0]);
|
||||
for (i in curSelectedData.startIndex...curSelectedData.components.length) {
|
||||
var newButton = new ComponentButton(curSelectedData.components[i]);
|
||||
componentList.add(newButton);
|
||||
newButton.ID = componentList.buttons.members.length - 1; // readjust it because UIButtonList doesnt generate the id properly
|
||||
}
|
||||
curSelectedComponent = (curSelectedData.components.length > 0) ? curSelectedData.components[curSelectedData.startIndex] : null;
|
||||
findOutline();
|
||||
infoWindow.updateInfo();
|
||||
}
|
||||
|
||||
public function findOutline() {
|
||||
outlineIdx = -1;
|
||||
for (i in curSelectedData.startIndex...curSelectedData.components.length) {
|
||||
var com = curSelectedData.components[i];
|
||||
if (com.outIndex != null)
|
||||
outlineIdx = com.outIndex;
|
||||
if (com == curSelectedComponent)
|
||||
break;
|
||||
}
|
||||
++outlineIdx;
|
||||
}
|
||||
|
||||
public function checkForFailed() {
|
||||
bigLetter.failedLetters.remove(bigLetter.text);
|
||||
curSelectedData = bigLetter.fastGetData(bigLetter.text);
|
||||
brokenWarning.text = "";
|
||||
bigLetter.draw();
|
||||
if (!bigLetter.failedLetters.contains(bigLetter.text))
|
||||
return false;
|
||||
|
||||
for (i in 0...curSelectedData.components.length) {
|
||||
var com = curSelectedData.components[i];
|
||||
if (!bigLetter.animation.exists(bigLetter.text + Std.string(i)))
|
||||
brokenWarning.text += " Unable to find: " + com.anim + "\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function _tape_left(_) {
|
||||
@@ -331,32 +441,59 @@ class ComponentButton extends UIButton {
|
||||
public var selected:Bool = false;
|
||||
|
||||
public var deleteButton:UIButton;
|
||||
public var deleteIcon:FlxSprite;
|
||||
|
||||
public function new(component:AlphabetComponent) {
|
||||
super(0, 0, component.anim, function() {
|
||||
AlphabetEditor.instance.curSelectedComponent = component;
|
||||
AlphabetEditor.instance.findOutline();
|
||||
AlphabetEditor.instance.infoWindow.updateInfo();
|
||||
}, 230, 50);
|
||||
this.component = component;
|
||||
|
||||
deleteButton = new UIButton(bWidth - 32, 0, "Delete", function() {
|
||||
deleteButton = new UIButton(bWidth - 32 - 10, 0, "", function() {
|
||||
var data = AlphabetEditor.instance.curSelectedData;
|
||||
|
||||
var outlineDrop = (component.outIndex != null) ? 1 : 0;
|
||||
var componentIndex = data.components.indexOf(component);
|
||||
for (i in 0...data.components.length) {
|
||||
var nextCompon = data.components[i];
|
||||
var anim = AlphabetEditor.instance.bigLetter.text + i;
|
||||
AlphabetEditor.instance.bigLetter.animation.remove(anim);
|
||||
AlphabetEditor.instance.tape.animation.remove(anim);
|
||||
|
||||
if (i > componentIndex && nextCompon.outIndex != null) {
|
||||
--data.components[nextCompon.outIndex].refIndex;
|
||||
nextCompon.outIndex -= outlineDrop;
|
||||
}
|
||||
}
|
||||
|
||||
if (component.outIndex != null) {
|
||||
data.components.splice(component.outIndex, 1);
|
||||
--data.startIndex;
|
||||
}
|
||||
|
||||
data.components.remove(component);
|
||||
AlphabetEditor.instance.curSelectedComponent = (AlphabetEditor.instance.curSelectedComponent == component) ? null : AlphabetEditor.instance.curSelectedComponent;
|
||||
AlphabetEditor.instance.findOutline();
|
||||
AlphabetEditor.instance.infoWindow.updateInfo();
|
||||
|
||||
AlphabetEditor.instance.componentList.remove(this);
|
||||
}, 32);
|
||||
deleteButton.color = FlxColor.RED;
|
||||
deleteButton.autoAlpha = false;
|
||||
members.push(deleteButton);
|
||||
|
||||
deleteIcon = new FlxSprite(deleteButton.x + (15/2), deleteButton.y + 8).loadGraphic(Paths.image('editors/delete-button'));
|
||||
deleteIcon.antialiasing = false;
|
||||
members.push(deleteIcon);
|
||||
}
|
||||
}
|
||||
|
||||
class GlyphInfoWindow extends UIWindow {
|
||||
public var info:UIText;
|
||||
public function new() {
|
||||
var width = 230;
|
||||
var height = 170;
|
||||
var margin = 30;
|
||||
super(FlxG.width - width - margin, FlxG.height - height - margin, width, height, "Glyph Info");
|
||||
override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
|
||||
info = new UIText(x + 28, y + 46, 400, "");
|
||||
info.alignment = LEFT;
|
||||
members.push(info);
|
||||
deleteButton.y = y + 10;
|
||||
deleteIcon.x = deleteButton.x + (15/2);
|
||||
deleteIcon.y = deleteButton.y + 8;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user