Search in sources :

Example 86 with Texture

use of com.badlogic.gdx.graphics.Texture in project ultimate-java by pantinor.

the class SaveGame method renderZstats.

public void renderZstats(int showZstats, BitmapFont font, Batch batch, int SCREEN_HEIGHT) {
    if (zstatsBox == null) {
        Pixmap pixmap = new Pixmap(175, 490, Format.RGBA8888);
        pixmap.setColor(0f, 0f, 0f, 0.65f);
        pixmap.fillRectangle(0, 0, 175, 490);
        zstatsBox = new Texture(pixmap);
        pixmap.dispose();
    }
    batch.draw(zstatsBox, 5, SCREEN_HEIGHT - 5 - 490);
    int rx = 10;
    int ry = SCREEN_HEIGHT - 10;
    String[] pages = getZstats();
    if (showZstats >= STATS_PLAYER1 && showZstats <= STATS_PLAYER8) {
        // players
        String[] players = pages[0].split("\\~");
        for (int i = 0; i < players.length; i++) {
            String[] lines = players[i].split("\\|");
            if (i != showZstats - 1) {
                continue;
            }
            rx = 10;
            ry = SCREEN_HEIGHT - 10;
            font.draw(batch, "Player " + (i + 1), rx, ry);
            ry = ry - 18;
            for (int j = 0; j < lines.length; j++) {
                if (lines[j] == null || lines[j].length() < 1) {
                    continue;
                }
                font.draw(batch, lines[j], rx, ry);
                ry = ry - 18;
            }
        }
    } else if (showZstats == STATS_WEAPONS) {
        String[] lines = pages[1].split("\\|");
        font.draw(batch, "Weapons", rx, ry);
        ry = ry - 18;
        for (int j = 0; j < lines.length; j++) {
            if (lines[j] == null || lines[j].length() < 1) {
                continue;
            }
            font.draw(batch, lines[j], rx, ry);
            ry = ry - 18;
        }
    } else if (showZstats == STATS_ARMOR) {
        String[] lines = pages[2].split("\\|");
        font.draw(batch, "Armor", rx, ry);
        ry = ry - 18;
        for (int j = 0; j < lines.length; j++) {
            if (lines[j] == null || lines[j].length() < 1) {
                continue;
            }
            font.draw(batch, lines[j], rx, ry);
            ry = ry - 18;
        }
    } else if (showZstats == STATS_ITEMS) {
        String[] lines = pages[3].split("\\|");
        font.draw(batch, "Items", rx, ry);
        ry = ry - 18;
        for (int j = 0; j < lines.length; j++) {
            if (lines[j] == null || lines[j].length() < 1) {
                continue;
            }
            font.draw(batch, lines[j], rx, ry);
            ry = ry - 18;
        }
    } else if (showZstats == STATS_REAGENTS) {
        String[] lines = pages[4].split("\\|");
        font.draw(batch, "Reagents", rx, ry);
        ry = ry - 18;
        for (int j = 0; j < lines.length; j++) {
            if (lines[j] == null || lines[j].length() < 1) {
                continue;
            }
            font.draw(batch, lines[j], rx, ry);
            ry = ry - 18;
        }
    } else if (showZstats == STATS_SPELLS) {
        String[] lines = pages[5].split("\\|");
        font.draw(batch, "Spell Mixtures", rx, ry);
        ry = ry - 18;
        for (int j = 0; j < lines.length; j++) {
            if (lines[j] == null || lines[j].length() < 1) {
                continue;
            }
            font.draw(batch, lines[j], rx, ry);
            ry = ry - 18;
        }
    }
}
Also used : Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 87 with Texture

use of com.badlogic.gdx.graphics.Texture in project bladecoder-adventure-engine by bladecoder.

the class RectangleRenderer method makePixel.

private static Texture makePixel() {
    Texture _temp;
    Pixmap p = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    p.setColor(Color.WHITE);
    p.fillRectangle(0, 0, 1, 1);
    _temp = new Texture(p, true);
    p.dispose();
    return _temp;
}
Also used : Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 88 with Texture

use of com.badlogic.gdx.graphics.Texture 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 89 with Texture

use of com.badlogic.gdx.graphics.Texture in project bladecoder-adventure-engine by bladecoder.

the class CreditsScreen method retrieveAssets.

private void retrieveAssets() {
    style = ui.getSkin().get(CreditScreenStyle.class);
    final Locale locale = Locale.getDefault();
    String localeFilename = MessageFormat.format("{0}_{1}.txt", CREDITS_FILENAME, locale.getLanguage());
    if (!EngineAssetManager.getInstance().assetExists(localeFilename))
        localeFilename = MessageFormat.format("{0}.txt", CREDITS_FILENAME);
    BufferedReader reader = EngineAssetManager.getInstance().getAsset(localeFilename).reader(4096, "utf-8");
    try {
        String line;
        while ((line = reader.readLine()) != null) {
            credits.add(line);
        }
    } catch (Exception e) {
        EngineLogger.error(e.getMessage());
        ui.setCurrentScreen(Screens.MENU_SCREEN);
    }
    scrollY += style.titleFont.getLineHeight();
    // Load IMAGES
    for (String s : credits) {
        if (s.indexOf('#') != -1 && s.charAt(0) == 'i') {
            s = s.substring(2);
            Texture tex = new Texture(EngineAssetManager.getInstance().getResAsset("ui/" + s));
            tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
            images.put(s, tex);
        }
    }
}
Also used : Locale(java.util.Locale) BufferedReader(java.io.BufferedReader) Texture(com.badlogic.gdx.graphics.Texture)

Example 90 with Texture

use of com.badlogic.gdx.graphics.Texture in project bladecoder-adventure-engine by bladecoder.

the class LoadSaveScreen method getScreenshot.

private Image getScreenshot(String slot) {
    String filename = slot + World.GAMESTATE_EXT + ".png";
    FileHandle savedFile = null;
    if (EngineAssetManager.getInstance().getUserFile(filename).exists())
        savedFile = EngineAssetManager.getInstance().getUserFile(filename);
    else if (EngineAssetManager.getInstance().assetExists("tests/" + filename))
        savedFile = EngineAssetManager.getInstance().getAsset("tests/" + filename);
    else {
        Drawable d = ui.getSkin().getDrawable("black");
        return new Image(d);
    }
    Texture t = new Texture(savedFile);
    // add to the list for proper dispose when hide the screen
    textureList.add(t);
    return new Image(t);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)235 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)78 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)62 Pixmap (com.badlogic.gdx.graphics.Pixmap)56 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)35 Stage (com.badlogic.gdx.scenes.scene2d.Stage)35 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)26 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)21 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)17 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)16 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)16 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)14 Material (com.badlogic.gdx.graphics.g3d.Material)12 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)12 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)11 FileHandle (com.badlogic.gdx.files.FileHandle)10