Skip to content

Commit b332db9

Browse files
committed
Enable/Disabled actions
1 parent e1712b8 commit b332db9

File tree

4 files changed

+95
-29
lines changed

4 files changed

+95
-29
lines changed

adventure-composer/src/main/java/com/bladecoder/engineeditor/ui/ActionList.java

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
2828
import com.badlogic.gdx.utils.Array;
2929
import com.bladecoder.engine.actions.Param;
30+
import com.bladecoder.engine.loader.XMLConstants;
3031
import com.bladecoder.engineeditor.ui.components.CellRenderer;
3132
import com.bladecoder.engineeditor.ui.components.EditElementDialog;
3233
import com.bladecoder.engineeditor.ui.components.ElementList;
@@ -38,12 +39,27 @@ public class ActionList extends ElementList {
3839

3940
private ImageButton upBtn;
4041
private ImageButton downBtn;
42+
43+
private ImageButton disableBtn;
4144

4245
public ActionList(Skin skin) {
4346
super(skin, true);
4447
this.skin = skin;
4548

4649
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+
});
4763

4864
upBtn = new ImageButton(skin);
4965
downBtn = new ImageButton(skin);
@@ -59,6 +75,7 @@ public void changed(ChangeEvent event, Actor actor) {
5975
int pos = list.getSelectedIndex();
6076

6177
toolbar.disableEdit(pos == -1);
78+
disableBtn.setDisabled(pos == -1);
6279
upBtn.setDisabled(pos == -1 || pos == 0);
6380
downBtn.setDisabled(pos == -1
6481
|| pos == list.getItems().size - 1);
@@ -80,6 +97,26 @@ public void changed(ChangeEvent event, Actor actor) {
8097
}
8198
});
8299
}
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+
83120

84121
@Override
85122
protected EditElementDialog getEditElementDialogInstance(Element e) {
@@ -138,13 +175,13 @@ public void changed(ChangeEvent event, Actor actor) {
138175
doc.setModified(e);
139176

140177
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))) {
143180
int pos = list.getSelectedIndex();
144181

145182
if (editedElement.getAttribute("endType").equals("else")) {
146183
while (!list.getItems().get(pos)
147-
.getAttribute("action_name").equals("Else"))
184+
.getAttribute(XMLConstants.ACTION_NAME_ATTR).equals("Else"))
148185
pos++;
149186

150187
Element e2 = list.getItems().removeIndex(pos);
@@ -153,10 +190,10 @@ public void changed(ChangeEvent event, Actor actor) {
153190
while (!list
154191
.getItems()
155192
.get(pos)
156-
.getAttribute("action_name")
193+
.getAttribute(XMLConstants.ACTION_NAME_ATTR)
157194
.equals("End"
158195
+ editedElement
159-
.getAttribute("action_name")))
196+
.getAttribute(XMLConstants.ACTION_NAME_ATTR)))
160197
pos++;
161198

162199
e2 = list.getItems().removeIndex(pos);
@@ -166,10 +203,10 @@ public void changed(ChangeEvent event, Actor actor) {
166203
while (!list
167204
.getItems()
168205
.get(pos)
169-
.getAttribute("action_name")
206+
.getAttribute(XMLConstants.ACTION_NAME_ATTR)
170207
.equals("End"
171208
+ editedElement
172-
.getAttribute("action_name")))
209+
.getAttribute(XMLConstants.ACTION_NAME_ATTR)))
173210
pos++;
174211

175212
Element e2 = list.getItems().removeIndex(pos);
@@ -194,13 +231,13 @@ private void insertEndAction(Element e) {
194231

195232
if (e.getAttribute("endType").equals("else")) {
196233
Element elseEl = doc.createElement((Element) parent, "action");
197-
elseEl.setAttribute("action_name", "Else");
234+
elseEl.setAttribute(XMLConstants.ACTION_NAME_ATTR, "Else");
198235
elseEl.setAttribute("class", END_ACTION);
199236
elseEl.setAttribute("endType", "else");
200237

201238
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));
204241
endEl.setAttribute("class", END_ACTION);
205242
endEl.setAttribute("endType", "if");
206243

@@ -211,8 +248,8 @@ private void insertEndAction(Element e) {
211248
parent.insertBefore(endEl, e2);
212249
} else {
213250
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));
216253
endEl.setAttribute("class", END_ACTION);
217254
endEl.setAttribute("endType", e.getAttribute("endType"));
218255

@@ -256,23 +293,23 @@ protected void delete() {
256293
super.delete();
257294

258295
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)
260297
.equals("Else"))
261298
pos++;
262299

263300
Element e2 = list.getItems().removeIndex(pos);
264301
doc.deleteElement(e2);
265302

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)))
268305
pos++;
269306

270307
e2 = list.getItems().removeIndex(pos);
271308
doc.deleteElement(e2);
272309
} else if (!e.getAttribute("endType").isEmpty()) {
273310

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)))
276313
pos++;
277314

278315
Element e2 = list.getItems().removeIndex(pos);
@@ -344,15 +381,39 @@ private void down() {
344381

345382
@Override
346383
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);
349386

350387
String actor = e.getAttribute("actor");
351-
boolean animationAction = e.getAttribute("action_name").equals(
388+
boolean animationAction = e.getAttribute(XMLConstants.ACTION_NAME_ATTR).equals(
352389
"Animation");
353390
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+
}
354415

355-
if (!actor.isEmpty() && !animationAction && !controlAction) {
416+
} else if (!actor.isEmpty() && !animationAction && !controlAction) {
356417
String[] s = Param.parseString2(actor);
357418

358419
if (s[0] != null)
@@ -397,9 +458,10 @@ protected String getCellSubTitle(Element e) {
397458

398459
if (name.equals("endType")
399460
|| 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
403465
.equals("animation")))
404466
continue;
405467

adventure-composer/src/main/java/com/bladecoder/engineeditor/ui/LayerList.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ public class LayerList extends ElementList {
3636

3737
private ImageButton upBtn;
3838
private ImageButton downBtn;
39-
private ImageButton initBtn;
39+
private ImageButton visibilityBtn;
4040

4141
public LayerList(Skin skin) {
4242
super(skin, false);
4343

4444
list.setCellRenderer(listCellRenderer);
4545

46-
initBtn = new ImageButton(skin);
47-
toolbar.addToolBarButton(initBtn, "ic_eye", "Toggle Visibility",
46+
visibilityBtn = new ImageButton(skin);
47+
toolbar.addToolBarButton(visibilityBtn, "ic_eye", "Toggle Visibility",
4848
"Toggle Visibility");
4949

50-
initBtn.setDisabled(false);
50+
visibilityBtn.setDisabled(false);
5151

52-
initBtn.addListener(new ChangeListener() {
52+
visibilityBtn.addListener(new ChangeListener() {
5353
@Override
5454
public void changed(ChangeEvent event, Actor actor) {
5555
toggleVisibility();

blade-engine/src/com/bladecoder/engine/loader/ChapterXMLLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,9 @@ private void parseAction(Attributes atts, String actor) {
622622
actionClass = atts.getValue(attName);
623623
} else if (attName.equals(XMLConstants.ACTION_NAME_ATTR)) {
624624
actionName = atts.getValue(attName);
625+
} else if (attName.equals(XMLConstants.ACTION_ENABLED_ATTR)) {
626+
if(atts.getValue(attName).equals(XMLConstants.FALSE_VALUE))
627+
return;
625628
} else {
626629
String value = atts.getValue(attName);
627630

blade-engine/src/com/bladecoder/engine/loader/XMLConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public final class XMLConstants {
2222
public static final String ACTION_TAG = "action";
2323
public static final String CLASS_ATTR = "class";
2424
public static final String ACTION_NAME_ATTR = "action_name";
25+
public static final String ACTION_ENABLED_ATTR = "action_enabled";
2526

2627
public static final String ACTOR_TAG = "actor";
2728
public static final String TYPE_ATTR = "type";

0 commit comments

Comments
 (0)