Example usage for com.badlogic.gdx.scenes.scene2d.ui Skin getDrawable

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Skin getDrawable

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Skin getDrawable.

Prototype

public Drawable getDrawable(String name) 

Source Link

Document

Returns a registered drawable.

Usage

From source file:com.badlogic.gdx.tests.LetterBoxTest3.java

License:Apache License

public void create() {
    stage = new Stage(0, 0, false);
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);/*w  w w .  j ava  2  s.  c  o  m*/

    root = new Table();
    stage.addActor(root);
    root.setSize(300, 200);
    root.setBackground(skin.getDrawable("default-pane"));
    root.debug().defaults().space(6);
    root.add(new TextButton("Button 1", skin));
    root.add(new TextButton("Button 2", skin));
    root.add(new TextButton("Button 3", skin));
}

From source file:com.badlogic.gdx.tests.ViewportTest1.java

License:Apache License

public void create() {
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));

    label = new Label("", skin);

    Table root = new Table(skin);
    root.setFillParent(true);//from w  w  w .  j ava2 s .  c  o m
    root.setBackground(skin.getDrawable("default-pane"));
    root.debug().defaults().space(6);
    root.add(new TextButton("Button 1", skin));
    root.add(new TextButton("Button 2", skin)).row();
    root.add("Press spacebar to change the viewport:").colspan(2).row();
    root.add(label).colspan(2);
    stage.addActor(root);

    viewports = getViewports(stage.getCamera());
    names = getViewportNames();

    stage.setViewport(viewports.first());
    label.setText(names.first());

    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
                label.setText(names.get(index));
                Viewport viewport = viewports.get(index);
                stage.setViewport(viewport);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    }, stage));
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createLevelAndHealthLayer() {
    Stage stage = new Stage(new StretchViewport(486, 864));
    Skin skin = new Skin();
    Table table = new Table();
    table.top().pad(10);//from  ww w.j av  a2 s.c om

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
            Gdx.files.internal("ui/fonts/Century Gothic Bold.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 40;
    parameter.borderColor = Color.BLACK;
    parameter.borderWidth = 3;
    BitmapFont font = generator.generateFont(parameter);
    generator.dispose();
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    skin.add("star", new Texture("ui/icons/star.png"));
    skin.add("shield", new Texture("ui/icons/shield.png"));
    skin.add("brick", new Texture("ui/icons/brick.png"));
    skin.add("swipe128", new Texture("ui/icons/swipe128.png"));

    float padding = 10;
    Image icon = new Image(skin.getDrawable("star"));
    if (Global.debugLevelUp) {
        icon.addListener(new ClickListener() {
            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                if (Engine.systemManager.has(LevelProgressionSystem.class)) {
                    for (Entity entity : Engine.systemManager.get(LevelProgressionSystem.class).entities) {
                        Engine.garbageManager.markForDeletion(entity);
                    }
                }
                super.touchUp(event, x, y, pointer, button);
            }
        });
    }
    table.add(icon).pad(padding);
    Label levelLabel = new Label("", labelStyle);
    table.add(levelLabel).pad(padding);
    icon = new Image(skin.getDrawable("shield"));
    table.add(icon).pad(padding);
    Label healthLabel = new Label("", labelStyle);
    table.add(healthLabel).pad(padding);
    icon = new Image(skin.getDrawable("brick"));
    table.add(icon).pad(padding);
    Label brickLabel = new Label("", labelStyle);
    table.add(brickLabel).pad(padding);

    table.row();

    // swipe
    if (Engine.systemManager.has(LevelProgressionSystem.class)) {
        if (Engine.systemManager.get(LevelProgressionSystem.class).level < 5) {
            icon = new Image(skin.getDrawable("swipe128"));
            table.add(icon).padTop(350).colspan(6);
            Global.swipeIcon = icon;

        }
    }

    //        table.setDebug(true);
    table.setFillParent(true);
    stage.addActor(table);

    Global.LEVEL_LABEL = levelLabel;
    Global.HEALTH_LABEL = healthLabel;
    Global.BRICK_LABEL = brickLabel;

    if (Engine.systemManager.has(LevelProgressionSystem.class)) {
        Global.LEVEL_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).level);
        Global.HEALTH_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).health);
        Global.BRICK_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).nrOfBricks);
    }

    Engine.inputManager.add(stage);
    return new Layer("topLayer", stage, table);
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createScoreLayer() {
    Stage stage = new Stage();
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    font.scale(2);/*from w  w w.  j a  v a  2 s  .co m*/
    Button button;

    Skin skin = new Skin();
    skin.add("bluebox", new Texture("textures/bluebox.jpg"));
    skin.add("greenbox", new Texture("textures/greenbox.jpg"));
    skin.add("redbox", new Texture("textures/redbox2.jpg"));

    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("redbox"),
            skin.getDrawable("greenbox"), skin.getDrawable("bluebox"), font);

    button = new ImageTextButton("0", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    table.add(button).pad(5).center();

    table.pack();
    table.setPosition(Gdx.graphics.getWidth() / 2 - table.getWidth() / 2,
            Gdx.graphics.getHeight() - table.getHeight());
    stage.addActor(table);

    Global.scoreButton = button;
    return new Layer("scoreLayer", stage);
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createFireLayer() {
    Stage stage = new Stage(new StretchViewport(640, 480));
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    Button button;/*from w  w w  .  j  av  a 2 s  .  c o  m*/

    Skin skin = new Skin();
    skin.add("bluebox", new Texture("textures/bluebox.jpg"));
    skin.add("greenbox", new Texture("textures/greenbox.jpg"));
    skin.add("redbox", new Texture("textures/redbox.jpg"));

    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("redbox"),
            skin.getDrawable("greenbox"), skin.getDrawable("bluebox"), font);

    button = new ImageTextButton("Fire", style);
    button.setHeight(50);
    button.setWidth(50);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new InputListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.input.getInputProcessor().keyDown(Keys.SPACE);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.input.getInputProcessor().keyUp(Keys.SPACE);
        }

    });
    table.add(button).pad(50).center();

    table.pack();
    table.setPosition(640 - table.getWidth(), 0);
    stage.addActor(table);

    Engine.inputManager.add(stage);
    return new Layer("fireLayer", stage);
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createJoystickLayer() {
    Stage stage = new Stage(new StretchViewport(1280, 720));
    Table table = new Table();
    MyListener listener = new MyListener();
    BitmapFont font = new BitmapFont();
    Button button;/*from  w ww. j a  v  a  2  s  .c om*/

    Skin skin = new Skin();
    skin.add("cirlce", new Texture("textures/circle.png"));
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("cirlce"),
            skin.getDrawable("cirlce"), skin.getDrawable("cirlce"), font);

    button = new ImageTextButton("Move", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new MoveListener());
    table.add(button).pad(50).expandX().left();

    button = new ImageTextButton("Fire", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(listener);
    table.add(button).pad(50).bottom().right();

    table.setDebug(true);
    table.setFillParent(true);
    table.bottom().left();
    stage.addActor(table);

    Engine.inputManager.add(stage);
    return new Layer("joystickLayer", stage);
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createJoystickControlLayer() {
    Stage stage = new Stage(new StretchViewport(1280, 720));
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    Button button;/*from  w  ww .j  av a 2 s  .  co m*/

    Skin skin = new Skin();
    skin.add("cirlce", new Texture("textures/circle.png"));
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("cirlce"),
            skin.getDrawable("cirlce"), skin.getDrawable("cirlce"), font);

    button = new ImageTextButton("Debug Options", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            Engine.game.setScreen(Engine.screens.get("debug"));
            return false;
        }
    });
    table.add(button).pad(50).padLeft(100).expandX().left();
    table.row();

    button = new ImageTextButton("L Boost", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(true, false, true));
    table.add(button).pad(50).padLeft(100).expandX().left();

    button = new ImageTextButton("R Boost", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(false, true, true));
    table.add(button).pad(50).padRight(100).bottom().right();
    table.row();

    button = new ImageTextButton("Left", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(true, false, false));
    table.add(button).pad(50).padLeft(100).expandX().left();

    button = new ImageTextButton("Right", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(false, true, false));
    table.add(button).pad(50).padRight(100).bottom().right();

    //        table.setDebug(true);
    table.setFillParent(true);
    table.bottom().left();
    stage.addActor(table);

    if (Engine.systemManager.has(OrbitCameraSystem.class)
            && Engine.systemManager.get(OrbitCameraSystem.class).mouseListener) {
        InputProcessor tmp = Engine.systemManager.get(OrbitCameraSystem.class).orbitCameraController;
        Engine.inputManager.remove(tmp);
        Engine.inputManager.add(stage);
        Engine.inputManager.add(tmp);
    } else {
        Engine.inputManager.add(stage);
    }

    return new Layer("controlLayer", stage);
}

From source file:com.bladecoder.engine.ui.LoadSaveScreen.java

License:Apache License

/**
 * Creates a button to represent one slot
 *
 * @param slot/*from  ww  w. ja v  a 2  s.c  om*/
 * @return The button to use for one slot
 */
private Button getSlotButton(String slot) {
    final Skin skin = ui.getSkin();
    final Button button = new Button(new ButtonStyle());
    final ButtonStyle style = button.getStyle();
    style.up = style.down = skin.getDrawable("black");

    String textLabel = I18N.getString("ui.newSlot");
    button.setSize(slotWidth, slotHeight);

    if (slotExists(slot)) {
        button.add(getScreenshot(slot)).maxSize(slotWidth * .95f, slotHeight * .95f);

        try {
            long l = Long.parseLong(slot);

            Date d = new Date(l);
            textLabel = (new SimpleDateFormat()).format(d);
        } catch (Exception e) {
            textLabel = slot;
        }

        button.addListener(loadClickListener);
    } else {
        Image fg = new Image(skin.getDrawable("plus"));
        button.add(fg).maxSize(slotHeight / 2, slotHeight / 2);

        button.addListener(saveClickListener);
    }

    button.row();

    Label label = new Label(textLabel, skin);
    label.setAlignment(Align.center);

    button.add(label).fillX();

    button.setName(slot);
    return button;
}

From source file:com.bladecoder.engineeditor.scneditor.ScnWidget.java

License:Apache License

public ScnWidget(Skin skin) {
    bigFont = skin.get("big-font", BitmapFont.class);
    defaultFont = skin.get("default-font", BitmapFont.class);

    setSize(150, 150);/*ww w . j  a v a2 s  .  com*/

    tile = new TiledDrawable(Ctx.assetManager.getIcon("transparent-light"));
    background = skin.getDrawable("background");

    faRenderer.setViewport(getWidth(), getHeight());

    setLayoutEnabled(true);

    addListener(inputListner);

    Ctx.project.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent e) {
            EditorLogger.debug("ScnWidget Listener: " + e.getPropertyName());

            if (e.getPropertyName().equals(Project.NOTIFY_SCENE_SELECTED)) {
                if (!projectLoadedFlag)
                    setSelectedScene(Ctx.project.getSelectedScene());
            } else if (e.getPropertyName().equals(Project.NOTIFY_ACTOR_SELECTED)) {
                if (!projectLoadedFlag)
                    setSelectedActor(Ctx.project.getSelectedActor());
            } else if (e.getPropertyName().equals(Project.NOTIFY_ANIM_SELECTED)) {
                if (!projectLoadedFlag && Ctx.project.getSelectedFA() != null)
                    setSelectedFA(Ctx.project.getSelectedFA());
            } else if (e.getPropertyName().equals(Project.NOTIFY_PROJECT_LOADED)) {
                projectLoadedFlag = true;
            } else if (e.getPropertyName().equals("scene")) {
                setSelectedScene(Ctx.project.getSelectedScene());
                setSelectedActor(Ctx.project.getSelectedActor());
            } else if (e.getPropertyName().equals("init_animation")) {
                if (!inScene)
                    setSelectedFA(null);
            }
        }
    });
}

From source file:com.bladecoder.engineeditor.scneditor.ToolsWindow.java

License:Apache License

public ToolsWindow(Skin skin, ScnWidget sw) {

    scnWidget = sw;/*  www .  j  a v a 2s .c  o m*/

    Table table = new Table(skin);
    button1 = new TextButton("PUSHME", skin);
    button1.setDisabled(true);

    table.top();
    table.add(new Label("Tools", skin, "big")).center();

    Drawable drawable = skin.getDrawable("trans");
    setBackground(drawable);
    table.row();
    table.add(button1).expandX().fill();
    setActor(table);

    button1.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {

            //            event.cancel();
        }

    });

    prefSize(200, 200);
    setSize(200, 200);
}