49
49
- Additionaly {link} has a Confirmation functionality which presents the user
50
50
with a question in a popup or a new menu before triggering an action
51
51
52
- - You can enable a Confirmation to a link by setting the optional field like this:]
53
- | ?fs=Are you sure?:Yes:No | or by :
54
- | ?pop=Sure?:Yes:No |
52
+ - You can enable a Confirmation to a link by setting the optional field like this:
53
+ ` | ?fs=Are you sure?:Yes:No |`
54
+ ` | ?pop=Sure?:Yes:No |`
55
55
56
- Notice it is one string with = and : used as a separators " ?askid=QUESTION:YES:NO"
56
+ Notice it is one string with = and : used as a separators ` ?askid=QUESTION:YES:NO`
57
57
`?fs` means that the question will be presented as a new menu page (autogenerated)
58
- and `?pop` will open a small popup over the item and ask (good for short things)
58
+ `?pop` will open a small popup over the item and ask (good for short things)
59
59
60
- ! :TIP: You can skip the question in the "?pop" style by ommiting the question.
61
- e.g. | ?pop=:Yes:No |
60
+ - You can * skip the question* by entering an empty string , like so
61
+ ` ?pop=:Yes:No` , notice the `=:`
62
62
63
- ! : Supports \n newlines in the ASK string, and it will generate multiple labels
64
- e.g. | ?fs=First Line\nSecond Line?:yes:no
63
+ - * Supports* `\n` newlines in the ASK string, and it will generate multiple labels
64
+ e.g. ` ?fs=First Line\nSecond Line?:yes:no`
65
65
> will produce two labels for the question.
66
66
> This is for cases where the question does not fit the screen
67
67
148
148
149
149
>> {label}
150
150
Creates a text element on the menu that is not selectable. Cursor will jump past it
151
-
151
+ - the `ID` field is *optional*
152
152
examples >>>>>>>>>>>>>>>>>>>>
153
153
154
154
"Advanced Options | label " ; Note that I didn't put an ID
155
155
"Advanced Options | label | id_lbl " ; But if you want, you can declare one
156
156
"Advanced Options | label | id_lbl |U" ; Make this label Unselectable. The Cursor will JUMP over it
157
-
158
157
-------------------------------------------------------------
159
158
160
159
=== For more usage examples, check <MPageData.hx> and <FlxMenu.hx>
161
160
162
161
***********************************************************************/
163
162
package djFlixel .ui .menu ;
164
163
165
- import flixel . input . actions . FlxActionInput . FlxInputDevice ;
164
+ import haxe . Exception ;
166
165
import haxe .EnumTools ;
167
166
168
167
enum MItemType {
@@ -224,46 +223,58 @@ class MItemData
224
223
225
224
/**
226
225
Creates a new Item Data from an encoded String
226
+ Encoded String Example: "New Game | link | ng+ | optionA | optionB "
227
227
@param str Encoded String. Check <MItemData.hx> header comments for more info on formatting
228
228
**/
229
229
public function new (str : String )
230
230
{
231
- parse (str );
231
+ try { parse (str ); }
232
+ catch (e : String ) {
233
+ var m = ' Error Parsing line\n " ${str }" \n :: ${e }' ;
234
+ throw new Exception (m );
235
+ }
232
236
}// ---------------------------------------------------;
233
237
238
+ // @throws <string> errors
234
239
function parse (S : String )
235
240
{
236
- // Split " A | B | | | C |" into ['A','B','C']
237
- var F = S .split (' |' ).map ((i )-> StringTools .trim (i )).filter ((i )-> i .length > 0 );
238
- /**
239
- F[0] = Label
240
- F[1] = Type
241
- F[2] = ID
242
- **/
243
-
244
- // Get : Label, ItemType, ItemID - which are required for all ItemTypes -
241
+ /* DEVNOTE:
242
+ - The string should be in this format
243
+ LABEL | TYPE | ID | <optional A> | <optional B>
244
+ - The string may end with a `|` it will be ignored
245
+ - The first two fields are mandatory (label does not need the third ID field)
246
+ */
247
+
248
+ var F = S .split (' |' ).map ((i )-> StringTools .trim (i ));
249
+
250
+ if (F .length < 2 ) throw " Insufficient fields" ;
251
+
252
+ // Allowing empty Labels, I am just going to warn
245
253
label = F .shift ();
246
- if (label == null ) throw ' MenuItem Must have a Label ' ;
247
-
254
+ if (label == " " ) trace ( ' Warning: Empty label for " ${ S } " ' ) ;
255
+
248
256
try {
249
257
type = EnumTools .createByName (MItemType , F .shift ());
250
- } catch (_ ) throw ' Wrong MenuItemType at " $label " Typo?' ;
258
+ } catch (_ )
259
+ throw ' Undefined TYPE, typo?' ;
251
260
252
261
ID = F .shift ();
253
- if (ID == null && type != MItemType .label ) throw ' ItemData " $label " must have an ID' ;
262
+ if ( (ID == null || ID == " " ) && type != MItemType .label )
263
+ throw ' No ID defined' ;
254
264
255
- // -- Must be called after types have finished getting mandatory fields
265
+ // Processes all optional fields one by one in a custom function
266
+ // func(key,value)
256
267
function feed (fn : String -> String -> Void )
257
268
{
258
269
for (i in F )
259
270
{
260
- // Check for universal parameters:
261
- // Currently : { |D| , |U| , |AF| }
262
-
263
-
271
+ // Handle strings ending with an |
272
+ if (i == " " ) continue ;
273
+
274
+ // Check for universal options first ::
275
+
264
276
// |AF| , for autofocusing
265
- if (i == " AF" )
266
- {
277
+ if (i == " AF" ) {
267
278
P .autofocus = true ;
268
279
continue ;
269
280
}
@@ -283,15 +294,15 @@ class MItemData
283
294
// All other Fields must be in this format "KEY=VALUE"
284
295
var KV = i .split (' =' );
285
296
if (KV .length != 2 ){
286
- throw ' Illegal MenuItem Parameter for $ ID ' ;
297
+ throw ' Illegal Parameter for " ${ i } " ' ;
287
298
}
288
299
289
300
// |I=Information Text| for attaching some text to the item
290
301
if (KV [0 ] == " I" ) {
291
302
info = KV [1 ];
292
303
continue ;
293
304
}
294
-
305
+
295
306
// Pass everything else to type specific code
296
307
fn (KV [0 ], KV [1 ]);
297
308
}
@@ -317,14 +328,13 @@ class MItemData
317
328
if (k == " fs" ) P .ltype = 3 ;
318
329
P .ask = v .split (" :" );
319
330
if (P .ask .length != 3 )
320
- throw ' Improper Ask Format. "Question:Yes:No" - Skip the Question with ":Yes:No" ' ;
331
+ throw ' Improper Ask Format' ;
321
332
}
322
333
});
323
334
324
-
325
335
326
336
case range :
327
- if (F [0 ] == null ) throw ' Range Item $ ID needs a range ' ;
337
+ if (F [0 ] == null ) throw ' Must define a Range ' ;
328
338
var _n = F .shift ().split (' ,' );
329
339
P .c = 0.0 ; // I need it to be Float so I can increment with a float later
330
340
P .step = 1 ;
@@ -346,7 +356,7 @@ class MItemData
346
356
}
347
357
348
358
case list :
349
- if (F [0 ] == null ) throw ' List Item $ ID needs a list ' ;
359
+ if (F [0 ] == null ) throw ' Must define a List ' ;
350
360
P .c = 0 ;
351
361
P .loop = false ;
352
362
P .list = F .shift ().split (' ,' );
0 commit comments