27
27
import com .badlogic .gdx .scenes .scene2d .utils .ChangeListener ;
28
28
import com .badlogic .gdx .utils .Array ;
29
29
import com .bladecoder .engine .actions .Param ;
30
+ import com .bladecoder .engine .loader .XMLConstants ;
30
31
import com .bladecoder .engineeditor .ui .components .CellRenderer ;
31
32
import com .bladecoder .engineeditor .ui .components .EditElementDialog ;
32
33
import com .bladecoder .engineeditor .ui .components .ElementList ;
@@ -38,12 +39,27 @@ public class ActionList extends ElementList {
38
39
39
40
private ImageButton upBtn ;
40
41
private ImageButton downBtn ;
42
+
43
+ private ImageButton disableBtn ;
41
44
42
45
public ActionList (Skin skin ) {
43
46
super (skin , true );
44
47
this .skin = skin ;
45
48
46
49
setCellRenderer (listCellRenderer );
50
+
51
+ disableBtn = new ImageButton (skin );
52
+ toolbar .addToolBarButton (disableBtn , "ic_eye" , "Enable/Disable" ,
53
+ "Enable/Disable" );
54
+
55
+ disableBtn .setDisabled (false );
56
+
57
+ disableBtn .addListener (new ChangeListener () {
58
+ @ Override
59
+ public void changed (ChangeEvent event , Actor actor ) {
60
+ toggleEnabled ();
61
+ }
62
+ });
47
63
48
64
upBtn = new ImageButton (skin );
49
65
downBtn = new ImageButton (skin );
@@ -59,6 +75,7 @@ public void changed(ChangeEvent event, Actor actor) {
59
75
int pos = list .getSelectedIndex ();
60
76
61
77
toolbar .disableEdit (pos == -1 );
78
+ disableBtn .setDisabled (pos == -1 );
62
79
upBtn .setDisabled (pos == -1 || pos == 0 );
63
80
downBtn .setDisabled (pos == -1
64
81
|| pos == list .getItems ().size - 1 );
@@ -80,6 +97,26 @@ public void changed(ChangeEvent event, Actor actor) {
80
97
}
81
98
});
82
99
}
100
+
101
+ private void toggleEnabled () {
102
+
103
+ Element e = list .getSelected ();
104
+
105
+ // CONTROL ACTIONS CAN'T BE DISABLED
106
+ if (e == null || !e .getAttribute ("endType" ).isEmpty ())
107
+ return ;
108
+
109
+ String value = e .getAttribute (XMLConstants .ACTION_ENABLED_ATTR );
110
+
111
+ if (value .isEmpty () || value .equals (XMLConstants .TRUE_VALUE ))
112
+ value = XMLConstants .FALSE_VALUE ;
113
+ else
114
+ value = XMLConstants .TRUE_VALUE ;
115
+
116
+ e .setAttribute (XMLConstants .ACTION_ENABLED_ATTR , value );
117
+ doc .setModified (e );
118
+ }
119
+
83
120
84
121
@ Override
85
122
protected EditElementDialog getEditElementDialogInstance (Element e ) {
@@ -138,13 +175,13 @@ public void changed(ChangeEvent event, Actor actor) {
138
175
doc .setModified (e );
139
176
140
177
if (!editedElement .getAttribute ("endType" ).isEmpty ()
141
- && !editedElement .getAttribute ("action_name" ).equals (
142
- e .getAttribute ("action_name" ))) {
178
+ && !editedElement .getAttribute (XMLConstants . ACTION_NAME_ATTR ).equals (
179
+ e .getAttribute (XMLConstants . ACTION_NAME_ATTR ))) {
143
180
int pos = list .getSelectedIndex ();
144
181
145
182
if (editedElement .getAttribute ("endType" ).equals ("else" )) {
146
183
while (!list .getItems ().get (pos )
147
- .getAttribute ("action_name" ).equals ("Else" ))
184
+ .getAttribute (XMLConstants . ACTION_NAME_ATTR ).equals ("Else" ))
148
185
pos ++;
149
186
150
187
Element e2 = list .getItems ().removeIndex (pos );
@@ -153,10 +190,10 @@ public void changed(ChangeEvent event, Actor actor) {
153
190
while (!list
154
191
.getItems ()
155
192
.get (pos )
156
- .getAttribute ("action_name" )
193
+ .getAttribute (XMLConstants . ACTION_NAME_ATTR )
157
194
.equals ("End"
158
195
+ editedElement
159
- .getAttribute ("action_name" )))
196
+ .getAttribute (XMLConstants . ACTION_NAME_ATTR )))
160
197
pos ++;
161
198
162
199
e2 = list .getItems ().removeIndex (pos );
@@ -166,10 +203,10 @@ public void changed(ChangeEvent event, Actor actor) {
166
203
while (!list
167
204
.getItems ()
168
205
.get (pos )
169
- .getAttribute ("action_name" )
206
+ .getAttribute (XMLConstants . ACTION_NAME_ATTR )
170
207
.equals ("End"
171
208
+ editedElement
172
- .getAttribute ("action_name" )))
209
+ .getAttribute (XMLConstants . ACTION_NAME_ATTR )))
173
210
pos ++;
174
211
175
212
Element e2 = list .getItems ().removeIndex (pos );
@@ -194,13 +231,13 @@ private void insertEndAction(Element e) {
194
231
195
232
if (e .getAttribute ("endType" ).equals ("else" )) {
196
233
Element elseEl = doc .createElement ((Element ) parent , "action" );
197
- elseEl .setAttribute ("action_name" , "Else" );
234
+ elseEl .setAttribute (XMLConstants . ACTION_NAME_ATTR , "Else" );
198
235
elseEl .setAttribute ("class" , END_ACTION );
199
236
elseEl .setAttribute ("endType" , "else" );
200
237
201
238
Element endEl = doc .createElement ((Element ) parent , "action" );
202
- endEl .setAttribute ("action_name" ,
203
- "End" + e .getAttribute ("action_name" ));
239
+ endEl .setAttribute (XMLConstants . ACTION_NAME_ATTR ,
240
+ "End" + e .getAttribute (XMLConstants . ACTION_NAME_ATTR ));
204
241
endEl .setAttribute ("class" , END_ACTION );
205
242
endEl .setAttribute ("endType" , "if" );
206
243
@@ -211,8 +248,8 @@ private void insertEndAction(Element e) {
211
248
parent .insertBefore (endEl , e2 );
212
249
} else {
213
250
Element endEl = doc .createElement ((Element ) parent , "action" );
214
- endEl .setAttribute ("action_name" ,
215
- "End" + e .getAttribute ("action_name" ));
251
+ endEl .setAttribute (XMLConstants . ACTION_NAME_ATTR ,
252
+ "End" + e .getAttribute (XMLConstants . ACTION_NAME_ATTR ));
216
253
endEl .setAttribute ("class" , END_ACTION );
217
254
endEl .setAttribute ("endType" , e .getAttribute ("endType" ));
218
255
@@ -256,23 +293,23 @@ protected void delete() {
256
293
super .delete ();
257
294
258
295
if (e .getAttribute ("endType" ).equals ("else" )) {
259
- while (!list .getItems ().get (pos ).getAttribute ("action_name" )
296
+ while (!list .getItems ().get (pos ).getAttribute (XMLConstants . ACTION_NAME_ATTR )
260
297
.equals ("Else" ))
261
298
pos ++;
262
299
263
300
Element e2 = list .getItems ().removeIndex (pos );
264
301
doc .deleteElement (e2 );
265
302
266
- while (!list .getItems ().get (pos ).getAttribute ("action_name" )
267
- .equals ("End" + e .getAttribute ("action_name" )))
303
+ while (!list .getItems ().get (pos ).getAttribute (XMLConstants . ACTION_NAME_ATTR )
304
+ .equals ("End" + e .getAttribute (XMLConstants . ACTION_NAME_ATTR )))
268
305
pos ++;
269
306
270
307
e2 = list .getItems ().removeIndex (pos );
271
308
doc .deleteElement (e2 );
272
309
} else if (!e .getAttribute ("endType" ).isEmpty ()) {
273
310
274
- while (!list .getItems ().get (pos ).getAttribute ("action_name" )
275
- .equals ("End" + e .getAttribute ("action_name" )))
311
+ while (!list .getItems ().get (pos ).getAttribute (XMLConstants . ACTION_NAME_ATTR )
312
+ .equals ("End" + e .getAttribute (XMLConstants . ACTION_NAME_ATTR )))
276
313
pos ++;
277
314
278
315
Element e2 = list .getItems ().removeIndex (pos );
@@ -344,15 +381,39 @@ private void down() {
344
381
345
382
@ Override
346
383
protected String getCellTitle (Element e ) {
347
- String id = e .getAttribute ("action_name" ).isEmpty () ? e
348
- .getAttribute ("class" ) : e .getAttribute ("action_name" );
384
+ String id = e .getAttribute (XMLConstants . ACTION_NAME_ATTR ).isEmpty () ? e
385
+ .getAttribute ("class" ) : e .getAttribute (XMLConstants . ACTION_NAME_ATTR );
349
386
350
387
String actor = e .getAttribute ("actor" );
351
- boolean animationAction = e .getAttribute ("action_name" ).equals (
388
+ boolean animationAction = e .getAttribute (XMLConstants . ACTION_NAME_ATTR ).equals (
352
389
"Animation" );
353
390
boolean controlAction = !e .getAttribute ("endType" ).isEmpty ();
391
+
392
+ boolean enabled = e .getAttribute (XMLConstants .ACTION_ENABLED_ATTR ).isEmpty () || e .getAttribute (XMLConstants .ACTION_ENABLED_ATTR ).equals (XMLConstants .TRUE_VALUE );
393
+
394
+ if (!enabled && !controlAction ) {
395
+ if (!actor .isEmpty () && !animationAction ) {
396
+ String [] s = Param .parseString2 (actor );
397
+
398
+ if (s [0 ] != null )
399
+ id = MessageFormat .format ("[GRAY]{0} {1}.{2}[]" , s [0 ],
400
+ s [1 ], id );
401
+ else
402
+ id = MessageFormat .format ("[GRAY]{0}.{1}[]" , actor , id );
403
+ } else if (animationAction ) {
404
+ String a = e .getAttribute ("animation" );
405
+ String [] s = Param .parseString2 (a );
406
+
407
+ if (s [0 ] != null )
408
+ id = MessageFormat .format ("[GRAY]{0}.{1} {2}[]" , s [0 ], id ,
409
+ s [1 ]);
410
+ else
411
+ id = MessageFormat .format ("[GRAY]{0} {1}[]" , id , a );
412
+ } else {
413
+ id = MessageFormat .format ("[GRAY]{0}[]" , id );
414
+ }
354
415
355
- if (!actor .isEmpty () && !animationAction && !controlAction ) {
416
+ } else if (!actor .isEmpty () && !animationAction && !controlAction ) {
356
417
String [] s = Param .parseString2 (actor );
357
418
358
419
if (s [0 ] != null )
@@ -397,9 +458,10 @@ protected String getCellSubTitle(Element e) {
397
458
398
459
if (name .equals ("endType" )
399
460
|| name .equals ("actor" )
400
- || name .equals ("class" )
401
- || name .equals ("action_name" )
402
- || (e .getAttribute ("action_name" ).equals ("Animation" ) && name
461
+ || name .equals (XMLConstants .CLASS_ATTR )
462
+ || name .equals (XMLConstants .ACTION_NAME_ATTR )
463
+ || name .equals (XMLConstants .ACTION_ENABLED_ATTR )
464
+ || (e .getAttribute (XMLConstants .ACTION_NAME_ATTR ).equals ("Animation" ) && name
403
465
.equals ("animation" )))
404
466
continue ;
405
467
0 commit comments