Search in sources :

Example 36 with InteractiveActor

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);
            }
        }
    }
}
Also used : Dialog(com.bladecoder.engine.model.Dialog) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb) SpriteActor(com.bladecoder.engine.model.SpriteActor) CharacterActor(com.bladecoder.engine.model.CharacterActor) TextRenderer(com.bladecoder.engine.model.TextRenderer)

Example 37 with InteractiveActor

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));
            }
        }
    }
}
Also used : Dialog(com.bladecoder.engine.model.Dialog) Verb(com.bladecoder.engine.model.Verb) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) CharacterActor(com.bladecoder.engine.model.CharacterActor) DialogOption(com.bladecoder.engine.model.DialogOption) TextRenderer(com.bladecoder.engine.model.TextRenderer)

Example 38 with InteractiveActor

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);
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor)

Example 39 with InteractiveActor

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));
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 40 with InteractiveActor

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);
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) Rectangle(com.badlogic.gdx.math.Rectangle) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Polygon(com.badlogic.gdx.math.Polygon) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Aggregations

InteractiveActor (com.bladecoder.engine.model.InteractiveActor)43 BaseActor (com.bladecoder.engine.model.BaseActor)25 Scene (com.bladecoder.engine.model.Scene)17 SpriteActor (com.bladecoder.engine.model.SpriteActor)16 Verb (com.bladecoder.engine.model.Verb)14 CharacterActor (com.bladecoder.engine.model.CharacterActor)13 Vector2 (com.badlogic.gdx.math.Vector2)11 Rectangle (com.badlogic.gdx.math.Rectangle)7 Polygon (com.badlogic.gdx.math.Polygon)6 Action (com.bladecoder.engine.actions.Action)6 AnchorActor (com.bladecoder.engine.model.AnchorActor)6 Dialog (com.bladecoder.engine.model.Dialog)6 World (com.bladecoder.engine.model.World)6 TextRenderer (com.bladecoder.engine.model.TextRenderer)5 Color (com.badlogic.gdx.graphics.Color)4 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)3