Search in sources :

Example 6 with World

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

the class RetroSceneScreen method sceneClick.

private void sceneClick(int button) {
    World w = World.getInstance();
    w.getSceneCamera().getInputUnProject(worldViewport, unprojectTmp);
    Scene s = w.getCurrentScene();
    if (currentActor != null) {
        if (EngineLogger.debugMode()) {
            EngineLogger.debug(currentActor.toString());
        }
        actorClick(currentActor, button);
    } else if (s.getPlayer() != null) {
        if (s.getPlayer().getVerb("goto") != null) {
            runVerb(s.getPlayer(), "goto", null);
        } else {
            Vector2 pos = new Vector2(unprojectTmp.x, unprojectTmp.y);
            if (recorder.isRecording()) {
                recorder.add(pos);
            }
            s.getPlayer().goTo(pos, null, false);
        }
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) World(com.bladecoder.engine.model.World) Scene(com.bladecoder.engine.model.Scene)

Example 7 with World

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

the class MenuScreen method show.

@Override
public void show() {
    stage = new Stage(new ScreenViewport());
    final Skin skin = ui.getSkin();
    final World world = World.getInstance();
    final MenuScreenStyle style = getStyle();
    final BitmapFont f = skin.get(style.textButtonStyle, TextButtonStyle.class).font;
    float buttonWidth = f.getCapHeight() * 15f;
    // Image background = new Image(style.background);
    Drawable bg = style.background;
    float scale = 1;
    if (bg == null && style.bgFile != null) {
        bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile));
        bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        scale = (float) bgTexFile.getHeight() / (float) stage.getViewport().getScreenHeight();
        int width = (int) (stage.getViewport().getScreenWidth() * scale);
        int x0 = (int) ((bgTexFile.getWidth() - width) / 2);
        bg = new TextureRegionDrawable(new TextureRegion(bgTexFile, x0, 0, width, bgTexFile.getHeight()));
    }
    menuButtonTable.clear();
    if (bg != null)
        menuButtonTable.setBackground(bg);
    menuButtonTable.addListener(new InputListener() {

        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
                if (world.getCurrentScene() != null)
                    ui.setCurrentScreen(Screens.SCENE_SCREEN);
            return true;
        }
    });
    menuButtonTable.align(getAlign());
    menuButtonTable.pad(DPIUtils.getMarginSize() * 2);
    menuButtonTable.defaults().pad(DPIUtils.getSpacing()).width(buttonWidth).align(getAlign());
    // menuButtonTable.debug();
    stage.setKeyboardFocus(menuButtonTable);
    if (style.showTitle && style.titleStyle != null) {
        Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin, style.titleStyle);
        title.setAlignment(getAlign());
        menuButtonTable.add(title).padBottom(DPIUtils.getMarginSize() * 2);
        menuButtonTable.row();
    }
    if (style.titleFile != null) {
        titleTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.titleFile));
        titleTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        Image img = new Image(titleTexFile);
        menuButtonTable.add(img).width((float) titleTexFile.getWidth() / scale).height((float) titleTexFile.getHeight() / scale).padBottom(DPIUtils.getMarginSize() * 2);
        menuButtonTable.row();
    }
    if (world.savedGameExists() || world.getCurrentScene() != null) {
        TextButton continueGame = new TextButton(I18N.getString("ui.continue"), skin, style.textButtonStyle);
        continueGame.getLabel().setAlignment(getAlign());
        continueGame.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                if (world.getCurrentScene() == null)
                    try {
                        world.load();
                    } catch (Exception e) {
                        Gdx.app.exit();
                    }
                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            }
        });
        menuButtonTable.add(continueGame);
        menuButtonTable.row();
    }
    TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle);
    newGame.getLabel().setAlignment(getAlign());
    newGame.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            if (world.savedGameExists()) {
                Dialog d = new Dialog("", skin) {

                    protected void result(Object object) {
                        if (((Boolean) object).booleanValue()) {
                            try {
                                world.newGame();
                                ui.setCurrentScreen(Screens.SCENE_SCREEN);
                            } catch (Exception e) {
                                EngineLogger.error("IN NEW GAME", e);
                                Gdx.app.exit();
                            }
                        }
                    }
                };
                d.pad(DPIUtils.getMarginSize());
                d.getButtonTable().padTop(DPIUtils.getMarginSize());
                d.getButtonTable().defaults().padLeft(DPIUtils.getMarginSize()).padRight(DPIUtils.getMarginSize());
                Label l = new Label(I18N.getString("ui.override"), ui.getSkin(), "ui-dialog");
                l.setWrap(true);
                l.setAlignment(Align.center);
                d.getContentTable().add(l).prefWidth(Gdx.graphics.getWidth() * .7f);
                d.button(I18N.getString("ui.yes"), true, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
                d.button(I18N.getString("ui.no"), false, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
                d.key(Keys.ENTER, true).key(Keys.ESCAPE, false);
                d.show(stage);
            } else {
                try {
                    world.newGame();
                    ui.setCurrentScreen(Screens.SCENE_SCREEN);
                } catch (Exception e) {
                    EngineLogger.error("IN NEW GAME", e);
                    Gdx.app.exit();
                }
            }
        }
    });
    menuButtonTable.add(newGame);
    menuButtonTable.row();
    TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle);
    loadGame.getLabel().setAlignment(getAlign());
    loadGame.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.LOAD_GAME_SCREEN);
        }
    });
    menuButtonTable.add(loadGame);
    menuButtonTable.row();
    TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle);
    quit.getLabel().setAlignment(getAlign());
    quit.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            Gdx.app.exit();
        }
    });
    menuButtonTable.add(quit);
    menuButtonTable.row();
    menuButtonTable.pack();
    stage.addActor(menuButtonTable);
    // BOTTOM-RIGHT BUTTON STACK
    credits = new Button(skin, "credits");
    credits.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.CREDIT_SCREEN);
        }
    });
    help = new Button(skin, "help");
    help.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.HELP_SCREEN);
        }
    });
    debug = new Button(skin, "debug");
    debug.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            DebugScreen debugScr = new DebugScreen();
            debugScr.setUI(ui);
            ui.setCurrentScreen(debugScr);
        }
    });
    iconStackTable.clear();
    iconStackTable.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(), DPIUtils.getPrefButtonSize());
    iconStackTable.pad(DPIUtils.getMarginSize() * 2);
    if (EngineLogger.debugMode() && world.getCurrentScene() != null) {
        iconStackTable.add(debug);
        iconStackTable.row();
    }
    iconStackTable.add(help);
    iconStackTable.row();
    iconStackTable.add(credits);
    iconStackTable.bottom().right();
    iconStackTable.setFillParent(true);
    iconStackTable.pack();
    stage.addActor(iconStackTable);
    Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
    version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
    version.addListener(new ClickListener() {

        int count = 0;

        long time = System.currentTimeMillis();

        public void clicked(InputEvent event, float x, float y) {
            if (System.currentTimeMillis() - time < 500) {
                count++;
            } else {
                count = 0;
            }
            time = System.currentTimeMillis();
            if (count == 4) {
                EngineLogger.toggle();
                if (World.getInstance().isDisposed())
                    return;
                if (EngineLogger.debugMode()) {
                    iconStackTable.row();
                    iconStackTable.add(debug);
                } else {
                    Cell<?> cell = iconStackTable.getCell(debug);
                    iconStackTable.removeActor(debug);
                    cell.reset();
                }
            }
        }
    });
    stage.addActor(version);
    debug.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            DebugScreen debugScr = new DebugScreen();
            debugScr.setUI(ui);
            ui.setCurrentScreen(debugScr);
        }
    });
    pointer = new Pointer(skin);
    stage.addActor(pointer);
    Gdx.input.setInputProcessor(stage);
    if (style.musicFile != null) {
        music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(style.musicFile));
        music.setLooping(true);
        music.play();
    }
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) World(com.bladecoder.engine.model.World) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 8 with World

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

the class SayDialogAction method resume.

@Override
public void resume() {
    World w = World.getInstance();
    BaseActor actor = w.getCurrentScene().getActor(characterName, false);
    if (characterTurn) {
        characterTurn = false;
        if (previousAnim != null) {
            SpriteActor player = World.getInstance().getCurrentScene().getPlayer();
            player.startAnimation(previousAnim, null);
        }
        if (responseText != null) {
            Rectangle boundingRectangle = actor.getBBox().getBoundingRectangle();
            float x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
            float y = boundingRectangle.getY() + boundingRectangle.getHeight();
            World.getInstance().getTextManager().addText(responseText, x, y, false, Text.Type.TALK, ((CharacterActor) actor).getTextColor(), null, actor.getId(), responseVoiceId, this);
            if (actor instanceof CharacterActor) {
                startTalkAnim((CharacterActor) actor);
            }
        } else {
            previousAnim = null;
            super.resume();
        }
    } else {
        if (actor instanceof SpriteActor && previousAnim != null) {
            ((SpriteActor) actor).startAnimation(previousAnim, null);
        }
        super.resume();
    }
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) World(com.bladecoder.engine.model.World) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 9 with World

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

the class DropItemAction method removeActor.

private void removeActor(Scene ts, BaseActor a) {
    final World w = World.getInstance();
    float scale = EngineAssetManager.getInstance().getScale();
    w.getInventory().removeItem(a.getId());
    if (ts != w.getCurrentScene() && w.getCachedScene(ts.getId()) == null && a instanceof Disposable)
        ((Disposable) a).dispose();
    ts.addActor(a);
    if (pos != null)
        a.setPosition(pos.x * scale, pos.y * scale);
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) World(com.bladecoder.engine.model.World)

Example 10 with World

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

the class MoveToSceneAction method run.

@Override
public boolean run(VerbRunner cb) {
    final Scene s = actor.getScene();
    final String actorId = actor.getActorId();
    final World w = World.getInstance();
    if (actorId == null) {
        // if called in a scene verb and no actor is specified, we do nothing
        EngineLogger.error(getClass() + ": No actor specified");
        return false;
    }
    InteractiveActor a = (InteractiveActor) s.getActor(actorId, false);
    s.removeActor(a);
    if (s == w.getCurrentScene() && a instanceof Disposable)
        ((Disposable) a).dispose();
    Scene ts = null;
    if (scene == null)
        ts = w.getCurrentScene();
    else
        ts = w.getScene(scene);
    // the scene is cached.
    if ((ts == w.getCurrentScene() || w.getCachedScene(ts.getId()) != null) && a instanceof AssetConsumer) {
        ((AssetConsumer) a).loadAssets();
        EngineAssetManager.getInstance().finishLoading();
        ((AssetConsumer) a).retrieveAssets();
    }
    ts.addActor(a);
    return false;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) AssetConsumer(com.bladecoder.engine.assets.AssetConsumer) Scene(com.bladecoder.engine.model.Scene) World(com.bladecoder.engine.model.World)

Aggregations

World (com.bladecoder.engine.model.World)20 BaseActor (com.bladecoder.engine.model.BaseActor)7 Rectangle (com.badlogic.gdx.math.Rectangle)6 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)6 Scene (com.bladecoder.engine.model.Scene)5 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)3 CharacterActor (com.bladecoder.engine.model.CharacterActor)3 SpriteActor (com.bladecoder.engine.model.SpriteActor)3 Color (com.badlogic.gdx.graphics.Color)2 Texture (com.badlogic.gdx.graphics.Texture)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Polygon (com.badlogic.gdx.math.Polygon)2 Vector2 (com.badlogic.gdx.math.Vector2)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Stage (com.badlogic.gdx.scenes.scene2d.Stage)2 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)2