Skip to content

Commit d7874d1

Browse files
committed
Fix EditActionDialog for custom actions.
1 parent 89948b0 commit d7874d1

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/EditActionDialog.java

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
2424
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
2525
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
26+
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener;
2627
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
27-
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener;
2828
import com.bladecoder.engine.actions.Action;
2929
import com.bladecoder.engine.actions.ActionFactory;
3030
import com.bladecoder.engine.actions.Param;
@@ -73,12 +73,19 @@ public void changed(ChangeEvent event, Actor actor) {
7373
}
7474
});
7575

76-
((TextField) classPanel.getField()).addListener(new FocusListener() {
77-
@Override
78-
public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
79-
if (!event.isFocused())
80-
setAction();
81-
}
76+
// ((TextField) classPanel.getField()).addListener(new FocusListener() {
77+
// @Override
78+
// public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
79+
// if (!event.isFocused())
80+
// setAction();
81+
// }
82+
// });
83+
84+
((TextField) classPanel.getField()).setTextFieldListener(new TextFieldListener() {
85+
@Override
86+
public void keyTyped(TextField textField, char key) {
87+
setAction();
88+
}
8289
});
8390

8491
if (e != null) {
@@ -113,8 +120,17 @@ private void setAction() {
113120

114121
if (id.equals(CUSTOM_ACTION_STR)) {
115122
addInputPanel(classPanel);
116-
if (classPanel != null && !classPanel.getText().trim().isEmpty())
123+
if (classPanel != null && classPanel.getText() != null && !classPanel.getText().trim().isEmpty())
117124
tmp = ActionFactory.createByClass(classPanel.getText(), null);
125+
126+
if(tmp == null) {
127+
classPanel.setError(true);
128+
} else {
129+
classPanel.setError(false);
130+
}
131+
132+
getStage().setKeyboardFocus(classPanel.getField());
133+
118134
setInfo(CUSTOM_INFO);
119135
} else {
120136
tmp = ActionFactory.create(id, null);
@@ -145,6 +161,8 @@ private void setAction() {
145161
i[j].getCell(i[j].getField()).fillX();
146162
}
147163
}
164+
} else {
165+
i = new InputPanel[0];
148166
}
149167

150168
// ((ScrollPane)(getContentTable().getCells().get(1).getActor())).setWidget(getCenterPanel());
@@ -183,11 +201,13 @@ protected void inputsToModel(boolean create) {
183201
}
184202

185203
ActionUtils.setParam(e, i[j].getTitle(), v);
186-
Ctx.project.setModified();
204+
187205
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
188206
EditorLogger.error(e.getMessage());
189207
}
190208
}
209+
210+
Ctx.project.setModified();
191211
}
192212

193213
@Override
@@ -208,4 +228,17 @@ protected void modelToInputs() {
208228
}
209229
}
210230
}
231+
232+
@Override
233+
protected boolean validateFields() {
234+
235+
String id = actionPanel.getText();
236+
237+
if (id.equals(CUSTOM_ACTION_STR) && e == null) {
238+
if(ActionFactory.createByClass(classPanel.getText(), null) == null)
239+
return false;
240+
}
241+
242+
return super.validateFields();
243+
}
211244
}

blade-engine/src/com/bladecoder/engine/model/Verb.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class Verb implements VerbRunner, Serializable {
3535
public static final String GOTO_VERB = "goto";
3636
public static final String TEST_VERB = "test";
3737
public static final String INIT_VERB = "init";
38+
public static final String INIT_NEW_GAME_VERB = "initNewGame";
39+
public static final String INIT_SAVED_GAME_VERB = "initSavedGame";
3840

3941
private String id;
4042
private String state;

blade-engine/src/com/bladecoder/engine/model/World.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ public void update(float delta) {
234234
initGame = false;
235235

236236
// Call world init verbs. Check for SAVED_GAME_VERSION property to know if new or loaded game.
237-
if(customProperties.get(WorldProperties.SAVED_GAME_VERSION.toString()) == null && verbs.getVerb("initNewGame", null, null) != null)
238-
verbs.runVerb("initNewGame", null, null);
239-
else if(customProperties.get(WorldProperties.SAVED_GAME_VERSION.toString()) != null && verbs.getVerb("initSavedGame", null, null) != null)
240-
verbs.runVerb("initSavedGame", null, null);
237+
if(customProperties.get(WorldProperties.SAVED_GAME_VERSION.toString()) == null && verbs.getVerb(Verb.INIT_NEW_GAME_VERB, null, null) != null)
238+
verbs.runVerb(Verb.INIT_NEW_GAME_VERB, null, null);
239+
else if(customProperties.get(WorldProperties.SAVED_GAME_VERSION.toString()) != null && verbs.getVerb(Verb.INIT_SAVED_GAME_VERB, null, null) != null)
240+
verbs.runVerb(Verb.INIT_SAVED_GAME_VERB, null, null);
241241

242242
// If in test mode run 'test' verb
243-
if (testScene != null && testScene.equals(currentScene.getId()) && currentScene.getVerb("test") != null)
244-
currentScene.runVerb("test");
243+
if (testScene != null && testScene.equals(currentScene.getId()) && currentScene.getVerb(Verb.TEST_VERB) != null)
244+
currentScene.runVerb(Verb.TEST_VERB);
245245
}
246246

247247
// call 'init' verb only when arrives from setCurrentScene and not

0 commit comments

Comments
 (0)