@@ -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 }
0 commit comments