Skip to content

Commit 689eda7

Browse files
committed
alphabet editor stuff
i still need a way to add spritesheets
1 parent 9757b00 commit 689eda7

File tree

5 files changed

+227
-88
lines changed

5 files changed

+227
-88
lines changed

assets/languages/en/Editors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@
488488
<str id="newGlyph">New Glyph</str>
489489
<str id="editGlyph">Edit Glyph</str>
490490
<str id="deleteGlyph">Delete Glyph</str>
491+
<str id="deleteCurGlyph">Delete Current Glyph</str>
491492
</group>
492493

493494
<str id="topBar.offset">Offsets</str>

source/funkin/editors/alphabet/AlphabetEditor.hx

Lines changed: 105 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class AlphabetEditor extends UIState {
4343
public var queueReorder:Bool = false;
4444
public var componentList:UIButtonList<ComponentButton>;
4545

46+
public var glyphCreateWindow:UISliceSprite;
47+
public var glyphChar:UITextBox;
48+
public var confirmGlyph:UIButton;
49+
public var deleteGlyph:UIButton;
50+
4651
public var infoWindow:GlyphInfoWindow;
4752
public var curSelectedComponent:AlphabetComponent = null;
4853
public var curSelectedData:AlphabetLetterData = null;
@@ -83,37 +88,25 @@ class AlphabetEditor extends UIState {
8388
{
8489
label: translate("topBar.edit"),
8590
childs: [
86-
{
91+
// TODO: add redo and undo
92+
/*{
8793
label: translate("edit.undo"),
88-
// TODO: add undo
94+
onSelect: null
8995
},
9096
{
9197
label: translate("edit.redo"),
92-
// TODO: add redo
98+
onSelect: null
99+
},*/
100+
{
101+
label: translate("glyph.deleteCurGlyph"),
102+
93103
},
94104
{
95105
label: "Edit Main Data", // TODO: add translations
96106
onSelect: _edit_main
97107
}
98108
]
99109
},
100-
{
101-
label: translate("topBar.glyph"),
102-
childs: [
103-
{
104-
label: translate("glyph.newGlyph"),
105-
//onSelect: _glyph_new
106-
},
107-
{
108-
label: translate("glyph.editGlyph"),
109-
//onSelect: _glyph_edit
110-
},
111-
{
112-
label: translate("glyph.deleteGlyph"),
113-
//onSelect: _glyph_delete
114-
}
115-
]
116-
},
117110
{
118111
label: translate("topBar.view"),
119112
childs: [
@@ -188,6 +181,67 @@ class AlphabetEditor extends UIState {
188181
brokenWarning.color = 0xFFFF6969;
189182
add(brokenWarning);
190183

184+
glyphCreateWindow = new UISliceSprite(FlxG.width - 15, topMenuSpr.bHeight + 15, 200, 150, "editors/ui/context-bg");
185+
glyphCreateWindow.x -= glyphCreateWindow.bWidth;
186+
uiGroup.add(glyphCreateWindow);
187+
188+
glyphChar = new UITextBox(glyphCreateWindow.x + 15, glyphCreateWindow.y + 15, "", glyphCreateWindow.bWidth - 30);
189+
glyphCreateWindow.members.push(glyphChar);
190+
191+
confirmGlyph = new UIButton(glyphChar.x, glyphChar.y + glyphChar.bHeight + 15, translate("glyph.newGlyph"), function() {
192+
if (deleteGlyph.selectable) {
193+
curLetter = tape.manualLetters.indexOf(lastChar) + charsForDefault.length;
194+
changeLetter(0);
195+
} else {
196+
tape.manualLetters.push(lastChar);
197+
tape.text = "";
198+
for (def in charsForDefault)
199+
tape.text += def[Std.int(Math.floor(defaultTmr) % def.length)] + " ";
200+
tape.text += tape.manualLetters.join(" ");
201+
202+
for (i in 0...tape.fastGetData(lastChar).components.length) {
203+
var anim = bigLetter.text + i;
204+
bigLetter.animation.remove(anim);
205+
tape.animation.remove(anim);
206+
}
207+
208+
tape.letterData.set(lastChar, {
209+
isDefault: false,
210+
advance: Math.NaN,
211+
advanceEmpty: true,
212+
components: [],
213+
startIndex: 0
214+
});
215+
216+
curLetter = tape.manualLetters.length - 1 + charsForDefault.length;
217+
changeLetter(0);
218+
}
219+
}, glyphChar.bWidth);
220+
confirmGlyph.selectable = false;
221+
glyphCreateWindow.members.push(confirmGlyph);
222+
223+
deleteGlyph = new UIButton(glyphChar.x, confirmGlyph.y + confirmGlyph.bHeight + 5, translate("glyph.deleteGlyph"), function() {
224+
final charIdx = tape.manualLetters.indexOf(lastChar);
225+
226+
tape.manualLetters.splice(charIdx, 1);
227+
tape.text = "";
228+
for (def in charsForDefault)
229+
tape.text += def[Std.int(Math.floor(defaultTmr) % def.length)] + " ";
230+
tape.text += tape.manualLetters.join(" ");
231+
232+
for (i in 0...tape.fastGetData(lastChar).components.length) {
233+
var anim = bigLetter.text + i;
234+
bigLetter.animation.remove(anim);
235+
tape.animation.remove(anim);
236+
}
237+
tape.letterData.remove(lastChar);
238+
239+
changeLetter((curLetter >= charIdx + charsForDefault.length) ? -1 : 0);
240+
}, glyphChar.bWidth);
241+
deleteGlyph.color = FlxColor.RED;
242+
deleteGlyph.selectable = false;
243+
glyphCreateWindow.members.push(deleteGlyph);
244+
191245
infoWindow = new GlyphInfoWindow();
192246
uiGroup.add(infoWindow);
193247

@@ -208,7 +262,7 @@ class AlphabetEditor extends UIState {
208262

209263
scaleX: 1,
210264
scaleY: 1,
211-
265+
212266
flipX: false,
213267
flipY: false,
214268

@@ -247,8 +301,29 @@ class AlphabetEditor extends UIState {
247301
}
248302
}
249303

304+
var lastChar:String = "";
250305
public override function update(elapsed:Float) {
251306
super.update(elapsed);
307+
308+
if (glyphChar.label.text != lastChar) {
309+
if (glyphChar.label.text == "") {
310+
lastChar = "";
311+
confirmGlyph.selectable = false;
312+
deleteGlyph.selectable = false;
313+
confirmGlyph.field.text = translate("glyph.newGlyph");
314+
} else {
315+
glyphChar.label.text = lastChar = switch (tape.forceCase) {
316+
case UPPER: glyphChar.label.text.charAt(glyphChar.label.text.length - 1).toUpperCase();
317+
case LOWER: glyphChar.label.text.charAt(glyphChar.label.text.length - 1).toLowerCase();
318+
case NONE: glyphChar.label.text.charAt(glyphChar.label.text.length - 1);
319+
};
320+
321+
confirmGlyph.selectable = true;
322+
deleteGlyph.selectable = tape.manualLetters.contains(lastChar);
323+
confirmGlyph.field.text = translate(deleteGlyph.selectable ? "glyph.editGlyph" : "glyph.newGlyph");
324+
}
325+
}
326+
252327
if (queueReorder) {
253328
queueReorder = false;
254329
var outlines = [];
@@ -344,6 +419,7 @@ class AlphabetEditor extends UIState {
344419
curLetter = CoolUtil.positiveModuloInt(curLetter + inc, tape.manualLetters.length + charsForDefault.length);
345420
targetX = FlxG.width * 0.5 - tape.defaultAdvance * (0.5 + curLetter * 2);
346421
bigLetter.text = (curLetter < charsForDefault.length) ? charsForDefault[curLetter][0] : tape.manualLetters[curLetter - charsForDefault.length];
422+
glyphChar.label.text = bigLetter.text;
347423
bigLetter.updateHitbox();
348424
bigLetter.screenCenter();
349425

@@ -396,19 +472,25 @@ class AlphabetEditor extends UIState {
396472
changeLetter(1);
397473
}
398474

475+
function buildAlphabet() {
476+
var tempPrettyPrint = true;
477+
var xmlThingYea:String = "<!DOCTYPE codename-engine-alphabet-font>\n" + Printer.print(tape.buildXML(), tempPrettyPrint);
478+
return tempPrettyPrint ? xmlThingYea : xmlThingYea.replace("\n", "");
479+
}
480+
399481
function _file_save(_) {
400482
#if sys
401483
CoolUtil.safeSaveFile(
402484
'${Paths.getAssetsRoot()}/data/alphabet/${__typeface}.xml',
403-
""//alphabet.buildXML()
485+
buildAlphabet()
404486
);
405487
#else
406488
_file_saveas(_);
407489
#end
408490
}
409491

410492
function _file_saveas(_) {
411-
openSubState(new SaveSubstate(""/*alphabet.buildXML()*/, {
493+
openSubState(new SaveSubstate(buildAlphabet(), {
412494
defaultSaveFile: '${__typeface}.xml'
413495
}));
414496
}

source/funkin/editors/alphabet/AlphabetSelection.hx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,11 @@ class AlphabetIconOption extends TextOption {
4343
var spritesheet = null;
4444
for (node in xml.elements()) {
4545
if (node.nodeName == "spritesheet") {
46-
spritesheet = node.firstChild().nodeValue;
46+
spritesheet = node.firstChild().nodeValue.trim();
4747
break;
4848
}
4949
}
5050

51-
var useColorOffsets = xml.get("useColorOffsets").getDefault("false") == "true";
52-
53-
5451
// todo fix crash if invalid spritesheet;
5552

5653
iconSpr = new FlxSprite();
@@ -64,7 +61,7 @@ class AlphabetIconOption extends TextOption {
6461
}
6562
}
6663
iconSpr.frame = frameToUse;
67-
if (useColorOffsets) {
64+
if (xml.get("colorMode") == "offsets") {
6865
iconSpr.colorTransform.color = -1;
6966
}
7067
iconSpr.setPosition(90 - iconSpr.width - 20, (__text.height - iconSpr.height) / 2);

source/funkin/editors/alphabet/GlyphInfoWindow.hx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class GlyphInfoWindow extends UIWindow {
1010
public var scaleYBox:UINumericStepper;
1111
public var angleBox:UINumericStepper;
1212
public var colorModeDrop:UIDropDown;
13-
13+
1414
public var flipXBox:UICheckbox;
1515
public var flipYBox:UICheckbox;
1616

@@ -60,7 +60,7 @@ class GlyphInfoWindow extends UIWindow {
6060

6161
xBox = new UINumericStepper(prefixBox.x, prefixBox.y + prefixBox.bHeight + itemMargin + labelOffset, 0, 1, 2, null, null, 80);
6262
xBox.onChange = valueSet.bind(xBox, function(val) { // kinda dumb but blame cne ui
63-
compon.x = val;
63+
compon.x = -val;
6464
});
6565
members.push(xBox);
6666

@@ -121,7 +121,7 @@ class GlyphInfoWindow extends UIWindow {
121121
members.push(colorModeDrop);
122122
addLabelOn(colorModeDrop, "Color Mode");
123123

124-
outlineCheck = new UICheckbox(colorModeDrop.x + colorModeDrop.bWidth + itemMargin * 2, colorModeDrop.y + 4, "Use Outline?");
124+
outlineCheck = new UICheckbox(colorModeDrop.x + colorModeDrop.bWidth + itemMargin * 2, colorModeDrop.y + 10, "Use Outline?");
125125
outlineCheck.onChecked = function(val) {
126126
targetPercent = val ? 1 : 0;
127127

@@ -147,7 +147,7 @@ class GlyphInfoWindow extends UIWindow {
147147
angle: compon.angle,
148148
cos: compon.cos,
149149
sin: compon.sin,
150-
150+
151151
flipX: compon.flipX,
152152
flipY: compon.flipY,
153153

@@ -156,15 +156,17 @@ class GlyphInfoWindow extends UIWindow {
156156
};
157157

158158
data.components.insert(AlphabetEditor.instance.outlineIdx, newOutline);
159+
++AlphabetEditor.instance.outlineIdx;
159160
++data.startIndex;
160161
} else {
161162
compon.outIndex = null;
162163
data.components.splice(AlphabetEditor.instance.outlineIdx - 1, 1);
164+
--AlphabetEditor.instance.outlineIdx;
163165
--data.startIndex;
164166
}
165167
}
166168
members.push(outlineCheck);
167-
169+
168170
flipXBox = new UICheckbox(outlineCheck.x, outlineCheck.y - outlineCheck.height - 8, "Flip X?");
169171
flipXBox.onChecked = function(check:Bool) {
170172
compon.flipX = check;
@@ -254,7 +256,7 @@ class GlyphInfoWindow extends UIWindow {
254256
}
255257

256258
prefixBox.label.text = com.anim;
257-
xBox.value = com.x;
259+
xBox.value = -com.x;
258260
yBox.value = com.y;
259261
scaleXBox.value = com.scaleX;
260262
scaleYBox.value = com.scaleY;
@@ -276,12 +278,12 @@ class GlyphInfoWindow extends UIWindow {
276278
outlineYBox.value = out.y;
277279
targetPercent = 1;
278280
}
279-
280-
for (item in members) {
281-
if (item is UISprite)
282-
cast(item, UISprite).selectable = true;
283-
}
284-
colorModeDrop.dropButton.selectable = true;
281+
282+
for (item in [prefixBox, scaleXBox, scaleYBox, angleBox, flipXBox, flipYBox])
283+
item.selectable = true;
284+
for (item in [xBox, yBox, colorModeDrop, outlineCheck, outlineBox, outlineXBox, outlineYBox])
285+
item.selectable = !data.isDefault;
286+
colorModeDrop.dropButton.selectable = colorModeDrop.selectable;
285287
}
286288

287289
function valueSet(item:UINumericStepper, func:Dynamic, text:String) {

0 commit comments

Comments
 (0)