Search in sources :

Example 6 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class ModelTools method checkI18NMissingKeys.

public static final void checkI18NMissingKeys() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    Map<String, Scene> scenes = World.getInstance().getScenes();
    for (Scene scn : scenes.values()) {
        Map<String, BaseActor> actors = scn.getActors();
        // SCENE VERBS
        HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
        for (Verb v : verbs.values()) {
            ArrayList<Action> actions = v.getActions();
            for (Action act : actions) {
                String[] params = ActionUtils.getFieldNames(act);
                for (String p : params) {
                    String val = ActionUtils.getStringValue(act, p);
                    if (val != null && !val.isEmpty() && val.charAt(0) == I18N.PREFIX) {
                        String trans = Ctx.project.translate(val);
                        if (trans == val) {
                            EditorLogger.error("Key not found: " + val);
                        }
                    }
                }
            }
        }
        for (BaseActor a : actors.values()) {
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                // DESC
                if (ia.getDesc() != null && !ia.getDesc().isEmpty() && ia.getDesc().charAt(0) == I18N.PREFIX) {
                    String trans = Ctx.project.translate(ia.getDesc());
                    if (trans == ia.getDesc()) {
                        EditorLogger.error("Key not found: " + ia.getDesc());
                    }
                }
                // ACTOR VERBS
                verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    ArrayList<Action> actions = v.getActions();
                    for (Action act : actions) {
                        String[] params = ActionUtils.getFieldNames(act);
                        for (String p : params) {
                            String val = ActionUtils.getStringValue(act, p);
                            if (val != null && !val.isEmpty() && val.charAt(0) == I18N.PREFIX) {
                                String trans = Ctx.project.translate(val);
                                if (trans == val) {
                                    EditorLogger.error("Key not found: " + val);
                                }
                            }
                        }
                    }
                }
            }
            // DIALOGS
            if (a instanceof CharacterActor) {
                HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
                if (dialogs != null) {
                    for (Dialog d : dialogs.values()) {
                        ArrayList<DialogOption> options = d.getOptions();
                        for (DialogOption o : options) {
                            if (o.getText() != null && !o.getText().isEmpty() && o.getText().charAt(0) == I18N.PREFIX) {
                                String trans = Ctx.project.translate(o.getText());
                                if (trans == o.getText()) {
                                    EditorLogger.error("Key not found: " + o.getText());
                                }
                            }
                            if (o.getResponseText() != null && !o.getResponseText().isEmpty() && o.getResponseText().charAt(0) == I18N.PREFIX) {
                                String trans = Ctx.project.translate(o.getResponseText());
                                if (trans == o.getResponseText()) {
                                    EditorLogger.error("Key not found: " + o.getResponseText());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LookAtAction(com.bladecoder.engine.actions.LookAtAction) SayAction(com.bladecoder.engine.actions.SayAction) SetCutmodeAction(com.bladecoder.engine.actions.SetCutmodeAction) Action(com.bladecoder.engine.actions.Action) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor) Dialog(com.bladecoder.engine.model.Dialog) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor) DialogOption(com.bladecoder.engine.model.DialogOption)

Example 7 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class EditVerbDialog method inputsToModel.

@Override
protected void inputsToModel(boolean create) {
    if (create) {
        e = new Verb();
    } else {
        HashMap<String, Verb> verbs = parent.getVerbs();
        verbs.remove(e.getHashKey());
    }
    e.setId(id.getText());
    e.setState(state.getText());
    e.setTarget(target.getText());
    e.setIcon(icon.getText());
    parent.addVerb(e);
    // TODO UNDO OP
    // UndoOp undoOp = new UndoAddElement(doc, e);
    // Ctx.project.getUndoStack().add(undoOp);
    Ctx.project.setModified();
}
Also used : Verb(com.bladecoder.engine.model.Verb)

Example 8 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class ActionList method edit.

@Override
protected void edit() {
    Action e = list.getSelected();
    if (e == null || e instanceof EndAction || e instanceof DisableActionAction)
        return;
    editedElement = (Action) ElementUtils.cloneElement(e);
    EditModelDialog<Verb, Action> dialog = getEditElementDialogInstance(e);
    dialog.show(getStage());
    dialog.setListener(new ChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Action e = ((EditModelDialog<Verb, Action>) actor).getElement();
            int pos = list.getSelectedIndex();
            list.getItems().set(pos, e);
            parent.getActions().set(pos, e);
            Ctx.project.setModified();
            if (isControlAction(editedElement)) {
                if (!editedElement.getClass().getName().equals(e.getClass().getName())) {
                    deleteControlAction(pos, (AbstractControlAction) editedElement);
                    if (isControlAction(e)) {
                        insertEndAction(pos + 1, getOrCreateControlActionId((AbstractControlAction) e));
                        if (e instanceof AbstractIfAction)
                            insertEndAction(pos + 2, getOrCreateControlActionId((AbstractControlAction) e));
                    }
                } else {
                    // insert previous caId
                    try {
                        ActionUtils.setParam(e, CONTROL_ACTION_ID_ATTR, getOrCreateControlActionId((AbstractControlAction) editedElement));
                    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
                        EditorLogger.error(e1.getMessage());
                    }
                }
            }
        }
    });
}
Also used : AbstractControlAction(com.bladecoder.engine.actions.AbstractControlAction) UndoDeleteAction(com.bladecoder.engineeditor.undo.UndoDeleteAction) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction) CommentAction(com.bladecoder.engine.actions.CommentAction) EndAction(com.bladecoder.engine.actions.EndAction) Action(com.bladecoder.engine.actions.Action) AbstractControlAction(com.bladecoder.engine.actions.AbstractControlAction) DisableActionAction(com.bladecoder.engine.actions.DisableActionAction) DisableActionAction(com.bladecoder.engine.actions.DisableActionAction) PropertyChangeEvent(java.beans.PropertyChangeEvent) EndAction(com.bladecoder.engine.actions.EndAction) Verb(com.bladecoder.engine.model.Verb) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction)

Example 9 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class ActionList method create.

@Override
protected void create() {
    EditModelDialog<Verb, Action> dialog = getEditElementDialogInstance(null);
    dialog.show(getStage());
    dialog.setListener(new ChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            int pos = list.getSelectedIndex() + 1;
            Action e = ((EditModelDialog<Verb, Action>) actor).getElement();
            list.getItems().insert(pos, e);
            parent.getActions().add(pos, e);
            list.getSelection().choose(list.getItems().get(pos));
            if (isControlAction(e)) {
                insertEndAction(pos + 1, getOrCreateControlActionId((AbstractControlAction) e));
                if (e instanceof AbstractIfAction)
                    insertEndAction(pos + 2, getOrCreateControlActionId((AbstractControlAction) e));
            }
            list.invalidateHierarchy();
        }
    });
}
Also used : AbstractControlAction(com.bladecoder.engine.actions.AbstractControlAction) UndoDeleteAction(com.bladecoder.engineeditor.undo.UndoDeleteAction) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction) CommentAction(com.bladecoder.engine.actions.CommentAction) EndAction(com.bladecoder.engine.actions.EndAction) Action(com.bladecoder.engine.actions.Action) AbstractControlAction(com.bladecoder.engine.actions.AbstractControlAction) DisableActionAction(com.bladecoder.engine.actions.DisableActionAction) PropertyChangeEvent(java.beans.PropertyChangeEvent) Verb(com.bladecoder.engine.model.Verb) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) AbstractIfAction(com.bladecoder.engine.actions.AbstractIfAction)

Example 10 with Verb

use of com.bladecoder.engine.model.Verb in project bladecoder-adventure-engine by bladecoder.

the class EditActorDialog method inputsToModel.

@Override
protected void inputsToModel(boolean create) {
    String type = typePanel.getText();
    boolean typeChanged = false;
    BaseActor oldElement = e;
    String oldId = null;
    boolean isPlayer = false;
    if (!create) {
        typeChanged = (type.equals(CHARACTER_TYPE_STR) && !(e instanceof CharacterActor)) || (type.equals(SPRITE_TYPE_STR) && (!(e instanceof SpriteActor) || e instanceof CharacterActor)) || (type.equals(BACKGROUND_TYPE_STR) && (!(e instanceof InteractiveActor) || e instanceof SpriteActor)) || (type.equals(OBSTACLE_TYPE_STR) && !(e instanceof ObstacleActor)) || (type.equals(ANCHOR_TYPE_STR) && !(e instanceof AnchorActor));
        isPlayer = parent.getPlayer() == e;
        // remove to allow id, zindex and layer change
        parent.removeActor(e);
        oldId = e.getId();
    }
    if (create || typeChanged) {
        if (type.equals(BACKGROUND_TYPE_STR)) {
            e = new InteractiveActor();
        } else if (type.equals(SPRITE_TYPE_STR)) {
            e = new SpriteActor();
        } else if (type.equals(CHARACTER_TYPE_STR)) {
            e = new CharacterActor();
        } else if (type.equals(OBSTACLE_TYPE_STR)) {
            e = new ObstacleActor();
        } else if (type.equals(ANCHOR_TYPE_STR)) {
            e = new AnchorActor();
        }
        if (!(e instanceof SpriteActor) && !(e instanceof AnchorActor)) {
            Polygon bbox = e.getBBox();
            bbox.setVertices(new float[8]);
            float[] verts = bbox.getVertices();
            verts[0] = -DEFAULT_DIM / 2;
            verts[1] = 0f;
            verts[2] = -DEFAULT_DIM / 2;
            verts[3] = DEFAULT_DIM;
            verts[4] = DEFAULT_DIM / 2;
            verts[5] = DEFAULT_DIM;
            verts[6] = DEFAULT_DIM / 2;
            verts[7] = 0f;
            bbox.dirty();
        }
    }
    if (typeChanged) {
        if (oldElement instanceof InteractiveActor && e instanceof InteractiveActor) {
            HashMap<String, Verb> verbs = ((InteractiveActor) e).getVerbManager().getVerbs();
            HashMap<String, Verb> oldVerbs = ((InteractiveActor) oldElement).getVerbManager().getVerbs();
            for (String k : oldVerbs.keySet()) {
                Verb v = oldVerbs.get(k);
                verbs.put(k, v);
            }
        }
        if (oldElement instanceof SpriteActor && e instanceof SpriteActor) {
            ((SpriteActor) e).setRenderer(((SpriteActor) oldElement).getRenderer());
        }
    }
    e.setId(ElementUtils.getCheckedId(id.getText(), parent.getActors().keySet().toArray(new String[0])));
    e.setVisible(Boolean.parseBoolean(visible.getText()));
    Vector2 p = Param.parseVector2(pos.getText());
    e.setPosition(p.x, p.y);
    if (e instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) e;
        ia.setLayer(layer.getText());
        ia.setInteraction(Boolean.parseBoolean(interaction.getText()));
        Vector2 rp = Param.parseVector2(refPoint.getText());
        ia.setRefPoint(rp.x, rp.y);
        String key = ia.getDesc();
        if (key == null || key.isEmpty() || key.charAt(0) != I18N.PREFIX || !e.getId().equals(oldId))
            key = Ctx.project.getI18N().genKey(parent.getId(), e.getId(), "desc");
        Ctx.project.getI18N().setTranslation(key, desc.getText());
        if (desc.getText() != null)
            ia.setDesc(key);
        else
            ia.setDesc(null);
        ia.setState(state.getText());
        ia.setZIndex(Float.parseFloat(zIndex.getText()));
        if (e instanceof SpriteActor) {
            SpriteActor sa = (SpriteActor) e;
            String rendererType = renderer.getText();
            if (Project.ATLAS_RENDERER_STRING.equals(rendererType)) {
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof AtlasRenderer))
                    sa.setRenderer(new AtlasRenderer());
            } else if (Project.IMAGE_RENDERER_STRING.equals(rendererType)) {
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof ImageRenderer))
                    sa.setRenderer(new ImageRenderer());
            } else if (Project.S3D_RENDERER_STRING.equals(rendererType)) {
                Sprite3DRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof Sprite3DRenderer)) {
                    r = new Sprite3DRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (Sprite3DRenderer) sa.getRenderer();
                }
                r.setCameraFOV(Float.parseFloat(fov.getText()));
                r.setCameraName(cameraName.getText());
                r.setSpriteSize(Param.parseVector2(spriteSize.getText()));
            } else if (Project.PARTICLE_RENDERER_STRING.equals(rendererType)) {
                ParticleRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof ParticleRenderer)) {
                    r = new ParticleRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (ParticleRenderer) sa.getRenderer();
                }
                r.setParticleName(particleName.getText());
                r.setAtlasName(particleAtlas.getText());
            } else if (Project.TEXT_RENDERER_STRING.equals(rendererType)) {
                TextRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof TextRenderer)) {
                    r = new TextRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (TextRenderer) sa.getRenderer();
                }
                key = text.getText();
                if (key == null || key.isEmpty() || key.charAt(0) != I18N.PREFIX || !e.getId().equals(oldId))
                    key = Ctx.project.getI18N().genKey(parent.getId(), e.getId(), "text");
                Ctx.project.getI18N().setTranslation(key, text.getText());
                if (text.getText() != null)
                    r.setText(key, text.getText());
                else
                    r.setText(null, null);
                r.setFontSize(Integer.parseInt(size.getText()));
                r.setFontName(font.getText());
                r.setAlign(AlignUtils.getAlign(textAlign.getText()));
                r.setBorderWidth(Integer.parseInt(borderWidth.getText()));
                r.setBorderColor(Param.parseColor(borderColor.getText()));
                r.setBorderStraight(Boolean.parseBoolean(borderStraight.getText()));
                r.setShadowOffsetX(Integer.parseInt(shadowOffsetX.getText()));
                r.setShadowOffsetY(Integer.parseInt(shadowOffsetY.getText()));
                r.setShadowColor(Param.parseColor(shadowColor.getText()));
                // dispose to force reload the text attributes
                sa.dispose();
            } else if (Project.SPINE_RENDERER_STRING.equals(rendererType)) {
                SpineRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof SpineRenderer)) {
                    r = new SpineRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (SpineRenderer) sa.getRenderer();
                }
                r.setSkin(spineSkin.getText());
            }
            boolean bbfr = Boolean.parseBoolean(bboxFromRenderer.getText());
            if (bbfr != sa.isBboxFromRenderer())
                sa.setBboxFromRenderer(bbfr);
            sa.setFakeDepth(Boolean.parseBoolean(fakeDepth.getText()));
            sa.setScale(Float.parseFloat(scale.getText()));
            sa.setRot(Float.parseFloat(rot.getText()));
            sa.getRenderer().setOrgAlign(AlignUtils.getAlign(orgAlign.getText()));
            sa.setTint(Param.parseColor(tint.getText()));
            if (e instanceof CharacterActor) {
                CharacterActor ca = (CharacterActor) e;
                ca.setWalkingSpeed(Float.parseFloat(walkingSpeed.getText()));
                ca.setTextColor(Param.parseColor(textColor.getText()));
                ca.setTextStyle(textStyle.getText());
            }
        }
    }
    parent.addActor(e);
    if (isPlayer && !typeChanged)
        parent.setPlayer((CharacterActor) e);
    if (e instanceof InteractiveActor) {
        SceneLayer l = parent.getLayer(((InteractiveActor) e).getLayer());
        l.orderByZIndex();
    }
    if (e instanceof SpriteActor)
        ((SpriteActor) e).retrieveAssets();
    // TODO UNDO OP
    // UndoOp undoOp = new UndoAddElement(doc, e);
    // Ctx.project.getUndoStack().add(undoOp);
    Ctx.project.setModified();
}
Also used : AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) SceneLayer(com.bladecoder.engine.model.SceneLayer) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) ParticleRenderer(com.bladecoder.engine.model.ParticleRenderer) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) CharacterActor(com.bladecoder.engine.model.CharacterActor) AnchorActor(com.bladecoder.engine.model.AnchorActor) ImageRenderer(com.bladecoder.engine.model.ImageRenderer) ObstacleActor(com.bladecoder.engine.model.ObstacleActor) Vector2(com.badlogic.gdx.math.Vector2) Verb(com.bladecoder.engine.model.Verb) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Polygon(com.badlogic.gdx.math.Polygon) TextRenderer(com.bladecoder.engine.model.TextRenderer)

Aggregations

Verb (com.bladecoder.engine.model.Verb)26 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)14 Scene (com.bladecoder.engine.model.Scene)9 Action (com.bladecoder.engine.actions.Action)8 BaseActor (com.bladecoder.engine.model.BaseActor)8 CharacterActor (com.bladecoder.engine.model.CharacterActor)7 Dialog (com.bladecoder.engine.model.Dialog)6 SpriteActor (com.bladecoder.engine.model.SpriteActor)5 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 TextRenderer (com.bladecoder.engine.model.TextRenderer)4 UndoDeleteVerb (com.bladecoder.engineeditor.undo.UndoDeleteVerb)4 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 AbstractControlAction (com.bladecoder.engine.actions.AbstractControlAction)2 AbstractIfAction (com.bladecoder.engine.actions.AbstractIfAction)2 CommentAction (com.bladecoder.engine.actions.CommentAction)2 DisableActionAction (com.bladecoder.engine.actions.DisableActionAction)2