use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class I18NHandler method extractStrings.
public void extractStrings(String sceneid, BaseActor a) {
if (a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
// 1. DESC attribute
if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) != I18N.PREFIX) {
String key = genKey(sceneid, a.getId(), "desc");
String value = ia.getDesc();
ia.setDesc(key);
setTranslation(key, value);
}
// 2. ACTIONS
HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) extractStrings(sceneid, a.getId(), v);
// 3. DIALOGS
if (a instanceof CharacterActor) {
HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
if (dialogs != null)
for (Dialog d : dialogs.values()) extractStrings(sceneid, a.getId(), d);
}
// 4. Text for TextRenderer
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof TextRenderer) {
TextRenderer r = (TextRenderer) ((SpriteActor) a).getRenderer();
String v = r.getText();
if (v != null && !v.isEmpty() && v.charAt(0) != I18N.PREFIX) {
String key = genKey(sceneid, a.getId(), "text");
r.setText(key, r.getText());
setTranslation(key, v);
}
}
}
}
use of com.bladecoder.engine.model.InteractiveActor 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.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class InventoryUI method stopDragging.
private void stopDragging(int button) {
World.getInstance().getSceneCamera().getInputUnProject(sceneScreen.getViewport(), mousepos);
InteractiveActor targetActor = sceneScreen.getCurrentActor();
if (targetActor != null) {
if (targetActor != draggedActor)
use(targetActor, draggedActor);
else if (singleAction)
sceneScreen.runVerb(targetActor, "lookat", null);
else
sceneScreen.actorClick(targetActor, button);
}
draggedActor = null;
pointer.drag(null);
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class PieMenu method show.
public void show(InteractiveActor a, float x, float y) {
setVisible(true);
this.x = x;
this.y = y;
iActor = a;
// DRAW TARGET DESCRIPTION
desc = iActor.getDesc();
if (desc != null) {
if (desc.charAt(0) == I18N.PREFIX)
desc = I18N.getString(desc.substring(1));
layout.setText(font, desc);
}
Actor rightButton;
if (a.getVerb("talkto") != null) {
talktoButton.setVisible(true);
pickupButton.setVisible(false);
rightButton = talktoButton;
} else {
talktoButton.setVisible(false);
pickupButton.setVisible(true);
rightButton = pickupButton;
}
float margin = DPIUtils.getMarginSize();
// FITS TO SCREEN
if (x < lookatButton.getWidth() + margin)
this.x = lookatButton.getWidth() + margin;
else if (x > viewportWidth - lookatButton.getWidth() - margin)
this.x = viewportWidth - lookatButton.getWidth() - margin;
if (y < margin)
this.y = margin;
else if (y > viewportHeight - lookatButton.getHeight() - margin)
this.y = viewportHeight - lookatButton.getHeight() - margin;
// lookatButton.setPosition(this.x - lookatButton.getWidth() - margin / 2, this.y + margin);
lookatButton.setPosition(this.x - lookatButton.getWidth() / 2, this.y - lookatButton.getHeight() / 2);
lookatButton.addAction(Actions.moveTo(this.x - lookatButton.getWidth() - margin / 2, this.y + margin, .1f));
// rightButton.setPosition(this.x + margin / 2, this.y + margin);
rightButton.setPosition(this.x - lookatButton.getWidth() / 2, this.y - lookatButton.getHeight() / 2);
rightButton.addAction(Actions.moveTo(this.x + margin / 2, this.y + margin, .1f));
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class DefaultSceneScreen method drawHotspots.
private void drawHotspots(SpriteBatch batch) {
final World world = World.getInstance();
for (BaseActor a : world.getCurrentScene().getActors().values()) {
if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer())
continue;
InteractiveActor ia = (InteractiveActor) a;
if (!ia.canInteract())
continue;
Polygon p = a.getBBox();
if (p == null) {
EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId());
}
Rectangle r = a.getBBox().getBoundingRectangle();
unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0);
world.getSceneCamera().scene2screen(viewport, unprojectTmp);
if (!showDesc || ia.getDesc() == null) {
float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier();
if (ia.getVerb("leave") != null) {
TransformDrawable drawable = (TransformDrawable) getUI().getSkin().getDrawable("leave");
drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size / 2, size / 2, size, size, 1.0f, 1.0f, calcLeaveArrowRotation(ia));
} else {
Drawable drawable = getUI().getSkin().getDrawable("hotspot");
if (drawable != null)
drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size);
}
} else {
BitmapFont font = getUI().getSkin().getFont("desc");
String desc = ia.getDesc();
if (desc.charAt(0) == I18N.PREFIX)
desc = I18N.getString(desc.substring(1));
textLayout.setText(font, desc);
float textX = unprojectTmp.x - textLayout.width / 2;
float textY = unprojectTmp.y + textLayout.height;
RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK);
font.draw(batch, textLayout, textX, textY);
}
}
}
Aggregations