use of com.bladecoder.engine.model.DialogOption in project bladecoder-adventure-engine by bladecoder.
the class SayDialogAction method run.
@Override
public boolean run(VerbRunner cb) {
World w = World.getInstance();
if (w.getCurrentDialog() == null || w.getCurrentDialog().getCurrentOption() == null) {
EngineLogger.debug("SayDialogAction WARNING: Current dialog doesn't found.");
return false;
}
setVerbCb(cb);
DialogOption o = w.getCurrentDialog().getCurrentOption();
String playerText = o.getText();
responseText = o.getResponseText();
responseVoiceId = o.getResponseVoiceId();
characterName = w.getCurrentDialog().getActor();
characterTurn = true;
previousAnim = null;
// If the player or the character is talking restore to 'stand' pose
restoreStandPose(w.getCurrentScene().getPlayer());
if (w.getCurrentScene().getActor(characterName, false) instanceof SpriteActor)
restoreStandPose((CharacterActor) w.getCurrentScene().getActor(characterName, false));
if (playerText != null) {
CharacterActor player = w.getCurrentScene().getPlayer();
Rectangle boundingRectangle = player.getBBox().getBoundingRectangle();
float x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
float y = boundingRectangle.getY() + boundingRectangle.getHeight();
w.getTextManager().addText(playerText, x, y, false, Text.Type.TALK, player.getTextColor(), null, player.getId(), o.getVoiceId(), this);
startTalkAnim(player);
} else {
resume();
}
return getWait();
}
use of com.bladecoder.engine.model.DialogOption in project bladecoder-adventure-engine by bladecoder.
the class ModelTools method extractDialogs.
public static final void extractDialogs() {
Map<String, Scene> scenes = World.getInstance().getScenes();
BufferedWriter writer = null;
try {
// create a temporary file
File dFile = new File(Ctx.project.getProjectPath() + "/" + "DIALOGS.md");
writer = new BufferedWriter(new FileWriter(dFile));
writer.write("# DIALOGS - " + (Ctx.project.getTitle() != null ? Ctx.project.getTitle().toUpperCase() : "") + "\n\n");
for (Scene scn : scenes.values()) {
Map<String, BaseActor> actors = scn.getActors();
writer.write("\n## SCENE: " + scn.getId() + "\n\n");
HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
// Process SayAction of TALK type
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
if (act instanceof SayAction) {
String type = ActionUtils.getStringValue(act, "type");
if ("TALK".equals(type)) {
String actor = ActionUtils.getStringValue(act, "actor").toUpperCase();
String rawText = ActionUtils.getStringValue(act, "text");
String text = Ctx.project.translate(rawText).replace("\\n\\n", "\n").replace("\\n", "\n");
writer.write(actor + ": " + text + "\n");
}
}
}
}
for (BaseActor a : actors.values()) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
verbs = ia.getVerbManager().getVerbs();
// Process SayAction of TALK type
for (Verb v : verbs.values()) {
ArrayList<Action> actions = v.getActions();
for (Action act : actions) {
if (act instanceof SayAction) {
String type = ActionUtils.getStringValue(act, "type");
if ("TALK".equals(type)) {
String actor = ActionUtils.getStringValue(act, "actor").toUpperCase();
String rawText = ActionUtils.getStringValue(act, "text");
String text = Ctx.project.translate(rawText).replace("\\n\\n", "\n").replace("\\n", "\n");
writer.write(actor + ": " + text + "\n");
}
}
}
}
}
if (a instanceof CharacterActor) {
CharacterActor ca = (CharacterActor) a;
HashMap<String, Dialog> dialogs = ca.getDialogs();
if (dialogs == null)
continue;
// Process SayAction of TALK type
for (Dialog d : dialogs.values()) {
ArrayList<DialogOption> options = d.getOptions();
if (options.size() > 0)
writer.write("\n**" + ca.getId().toUpperCase() + " - " + d.getId() + "**\n\n");
for (DialogOption o : options) {
String text = o.getText();
String response = o.getResponseText();
writer.write(scn.getPlayer().getId().toUpperCase() + ": " + Ctx.project.translate(text).replace("\\n\\n", "\n").replace("\\n", "\n") + "\n");
if (response != null)
writer.write(ca.getId().toUpperCase() + ": " + Ctx.project.translate(response).replace("\\n\\n", "\n").replace("\\n", "\n") + "\n\n");
}
}
}
}
}
} catch (Exception e) {
EditorLogger.printStackTrace(e);
} finally {
try {
// Close the writer regardless of what happens...
writer.close();
} catch (Exception e) {
}
}
}
use of com.bladecoder.engine.model.DialogOption in project bladecoder-adventure-engine by bladecoder.
the class I18NHandler method getUsedKeys.
private void getUsedKeys(Scene s, ArrayList<String> usedKeys) {
for (Verb v : s.getVerbManager().getVerbs().values()) getUsedKeys(v, usedKeys);
for (BaseActor a : s.getActors().values()) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) == I18N.PREFIX)
usedKeys.add(ia.getDesc().substring(1));
for (Verb v : ia.getVerbManager().getVerbs().values()) getUsedKeys(v, usedKeys);
if (a instanceof CharacterActor) {
CharacterActor ca = (CharacterActor) a;
if (ca.getDialogs() != null) {
for (Dialog d : ca.getDialogs().values()) {
for (DialogOption o : d.getOptions()) {
if (o.getText() != null && !o.getText().isEmpty() && o.getText().charAt(0) == I18N.PREFIX)
usedKeys.add(o.getText().substring(1));
if (o.getResponseText() != null && !o.getResponseText().isEmpty() && o.getResponseText().charAt(0) == I18N.PREFIX)
usedKeys.add(o.getResponseText().substring(1));
}
}
}
}
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof TextRenderer) {
TextRenderer r = (TextRenderer) ((SpriteActor) a).getRenderer();
String k = r.getText();
if (k != null && !k.isEmpty() && k.charAt(0) == I18N.PREFIX)
usedKeys.add(k.substring(1));
}
}
}
}
use of com.bladecoder.engine.model.DialogOption in project bladecoder-adventure-engine by bladecoder.
the class I18NHandler method extractStrings.
public void extractStrings(String sceneid, String actorid, Dialog d) {
ArrayList<DialogOption> options = d.getOptions();
for (int i = 0; i < options.size(); i++) {
DialogOption o = options.get(i);
extractStrings(sceneid, actorid, d.getId(), i, o);
}
}
Aggregations