Java Code Examples for com.badlogic.gdx.scenes.scene2d.ui.Label#setTouchable()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Label#setTouchable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuScreen.java    From Unlucky with MIT License 5 votes vote down vote up
public MenuScreen(final Unlucky game, final ResourceManager rm) {
    super(game, rm);

    menuStyle = new Label.LabelStyle(rm.pixel10, new Color(79 / 255.f, 79 / 255.f, 117 / 255.f, 1));

    // one for each letter
    titleMoves = new Moving[7];
    letters = new Image[7];
    for (int i = 0; i < 7; i++) {
        titleMoves[i] = new Moving(new Vector2(), new Vector2(), 0);
        letters[i] = new Image(rm.title[i]);
        stage.addActor(letters[i]);
    }

    handlePlayButton();
    handleOptionButtons();

    battleLabel = new Label("Battle", menuStyle);
    battleLabel.setSize(80, 40);
    battleLabel.setFontScale(1.5f);
    battleLabel.setTouchable(Touchable.disabled);
    battleLabel.setAlignment(Align.center);
    battleLabel.setPosition(60, 35);

    stage.addActor(battleLabel);

    createCreditsScreen();

    // menu music
    rm.menuTheme.setLooping(true);
    rm.menuTheme.play();
}
 
Example 2
Source File: BattleScene.java    From Unlucky with MIT License 4 votes vote down vote up
public BattleScene(GameScreen gameScreen, TileMap tileMap, Player player, Battle battle,
                   BattleUIHandler uiHandler, Stage stage, ResourceManager rm) {
    super(gameScreen, tileMap, player, battle, uiHandler, rm);

    this.stage = stage;

    BitmapFont font = rm.pixel10;
    Label.LabelStyle ls = new Label.LabelStyle(font, new Color(255, 255, 255, 255));

    weakest = new Label.LabelStyle(font, new Color(200 / 255.f, 200 / 255.f, 200 / 255.f, 1));
    weaker = new Label.LabelStyle(font, new Color(0, 225 / 255.f, 0, 1));
    same = new Label.LabelStyle(font, new Color(1, 1, 1, 1));
    stronger = new Label.LabelStyle(font, new Color(1, 175 / 255.f, 0, 1));
    strongest = new Label.LabelStyle(font, new Color(225 / 255.f, 0, 0, 1));

    // create player hud
    playerHud = new MovingImageUI(rm.playerhpbar145x40, new Vector2(-72, 100), new Vector2(0, 100), 100.f, 72, 20);
    playerHpBar = new HealthBar(player, stage, shapeRenderer, 48, 4, new Vector2(), new Color(0, 225 / 255.f, 0, 1));
    playerHudLabel = new Label("", ls);
    playerHudLabel.setFontScale(0.5f);
    playerHudLabel.setSize(49, 6);
    playerHudLabel.setTouchable(Touchable.disabled);

    // create enemy hud
    enemyHud = new MovingImageUI(rm.enemyhpbar145x40, new Vector2(200, 100), new Vector2(128, 100), 100.f, 72, 20);
    enemyHpBar = new HealthBar(null, stage, shapeRenderer, 48, 4, new Vector2(), new Color(225 / 255.f, 0, 0, 1));
    enemyHudLabel = new Label("", ls);
    enemyHudLabel.setFontScale(0.5f);
    enemyHudLabel.setSize(49, 6);
    enemyHudLabel.setTouchable(Touchable.disabled);

    // create player sprite
    playerSprite = new Moving(PLAYER_ORIGIN, new Vector2(35, 50), 75.f);
    // create enemy sprite
    enemySprite = new Moving(ENEMY_ORIGIN, new Vector2(120, 50), 75.f);

    // create animations
    attackAnims = new AnimationManager[3];
    for (int i = 0; i < 3; i++) {
        attackAnims[i] = new AnimationManager(rm.battleAttacks64x64, 3, i, 1 / 6f);
    }
    healAnim = new AnimationManager(rm.battleHeal96x96, 3, 0, 1 / 5f);

    factory = new ParticleFactory((OrthographicCamera) stage.getCamera(), rm);

    stage.addActor(playerHud);
    stage.addActor(playerHudLabel);
    stage.addActor(enemyHud);
    stage.addActor(enemyHudLabel);
}
 
Example 3
Source File: BattleEventHandler.java    From Unlucky with MIT License 4 votes vote down vote up
public BattleEventHandler(GameScreen gameScreen, TileMap tileMap, Player player, Battle battle,
                          BattleUIHandler uiHandler, Stage stage, final ResourceManager rm) {
    super(gameScreen, tileMap, player, battle, uiHandler, rm);

    this.stage = stage;

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(175, 26);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleBattleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}
 
Example 4
Source File: LevelUpScreen.java    From Unlucky with MIT License 4 votes vote down vote up
public LevelUpScreen(GameScreen gameScreen, TileMap tileMap, Player player, ResourceManager rm) {
    super(gameScreen, tileMap, player, rm);

    // create bg
    ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
    style.imageUp = new TextureRegionDrawable(rm.levelupscreen400x240);
    ui = new ImageButton(style);
    ui.setSize(200, 120);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);
    stage.addActor(ui);

    handleClick();

    // create animation
    levelUpAnim = new AnimationManager(rm.levelUp96x96, 4, 0, 1 / 4f);

    // create labels
    BitmapFont font = rm.pixel10;
    Label.LabelStyle titleFont = new Label.LabelStyle(font, new Color(0, 205 / 255.f, 20 / 255.f, 1));
    Label.LabelStyle stdWhite = new Label.LabelStyle(font, new Color(1, 1, 1, 1));
    Label.LabelStyle yellow = new Label.LabelStyle(font, new Color(1, 212 / 255.f, 0, 1));
    Label.LabelStyle blue = new Label.LabelStyle(font, new Color(0, 190 / 255.f, 1, 1));

    title = new Label("LEVEL UP!", titleFont);
    title.setSize(200, 20);
    title.setPosition(0, 95);
    title.setFontScale(2.5f);
    title.setAlignment(Align.center);
    title.setTouchable(Touchable.disabled);
    stage.addActor(title);

    levelDesc = new Label("You reached level 1", stdWhite);
    levelDesc.setSize(200, 20);
    levelDesc.setPosition(0, 80);
    levelDesc.setAlignment(Align.center);
    levelDesc.setTouchable(Touchable.disabled);
    stage.addActor(levelDesc);

    statsDescs = new Label[statNames.length];
    stats = new Label[statNames.length];
    increases = new Label[statNames.length];

    for (int i = 0; i < statNames.length; i++) {
        statsDescs[i] = new Label(statNames[i], stdWhite);
        statsDescs[i].setSize(10, 10);
        statsDescs[i].setFontScale(1.3f / 2);
        statsDescs[i].setPosition(100, 17 + (i * 12));
        statsDescs[i].setAlignment(Align.left);
        statsDescs[i].setTouchable(Touchable.disabled);
        stage.addActor(statsDescs[i]);

        stats[i] = new Label("1330", blue);
        stats[i].setSize(10, 10);
        stats[i].setFontScale(1.3f / 2);
        stats[i].setPosition(140, 17 + (i * 12));
        stats[i].setAlignment(Align.left);
        stats[i].setTouchable(Touchable.disabled);
        stage.addActor(stats[i]);

        increases[i] = new Label("+20", yellow);
        increases[i].setSize(10, 10);
        increases[i].setFontScale(1.3f / 2);
        increases[i].setPosition(170, 17 + (i * 12));
        increases[i].setAlignment(Align.left);
        increases[i].setTouchable(Touchable.disabled);
        stage.addActor(increases[i]);
    }

    clickToContinue = new Label("Click to continue", stdWhite);
    clickToContinue.setSize(200, 10);
    clickToContinue.setFontScale(0.5f);
    clickToContinue.setPosition(0, 2);
    clickToContinue.setAlignment(Align.center);
    clickToContinue.setTouchable(Touchable.disabled);
    stage.addActor(clickToContinue);
}
 
Example 5
Source File: DialogScreen.java    From Unlucky with MIT License 4 votes vote down vote up
public DialogScreen(GameScreen gameScreen, TileMap tileMap, Player player, final ResourceManager rm) {
    super(gameScreen, tileMap, player, rm);

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(350 / 2, 52 / 2);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}
 
Example 6
Source File: SettingsScreen.java    From Unlucky with MIT License 4 votes vote down vote up
public SettingsScreen(final Unlucky game, final ResourceManager rm) {
    super(game, rm);

    // exit button
    stage.addActor(exitButton);
    exitButton.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            if (!game.player.settings.muteSfx) rm.buttonclick0.play(game.player.settings.sfxVolume);
            if (inGame) {
                game.gameScreen.resetGame = false;
                setFadeScreen(game.gameScreen);
                game.gameScreen.hud.settingsDialog.show(game.gameScreen.hud.getStage());
            }
            else {
                game.menuScreen.transitionIn = 2;
                setSlideScreen(game.menuScreen, false);
            }
        }
    });

    // create title label
    banner = new Image(rm.skin, "default-slider");
    banner.setPosition(8, 102);
    banner.setSize(164, 12);
    stage.addActor(banner);

    bannerLabel = new Label("SETTINGS", rm.skin);
    bannerLabel.setStyle(new Label.LabelStyle(rm.pixel10, new Color(1, 212 / 255.f, 0, 1)));
    bannerLabel.setSize(50, 12);
    bannerLabel.setTouchable(Touchable.disabled);
    bannerLabel.setPosition(14, 102);
    bannerLabel.setAlignment(Align.left);
    stage.addActor(bannerLabel);

    bg = new Image(rm.skin, "default-slider");
    bg.setPosition(8, 8);
    bg.setSize(184, 88);
    stage.addActor(bg);

    white = new Label.LabelStyle(rm.pixel10, Color.WHITE);
    description = new Label("SOUND                                 MISC",
        new Label.LabelStyle(rm.pixel10, new Color(1, 212 / 255.f, 0, 1)));
    description.setFontScale(0.75f);
    description.setTouchable(Touchable.disabled);
    description.setPosition(14, 85);
    stage.addActor(description);

    // create settings labels
    settingLabels = new Label[7];
    String[] settingStrs = new String[] {
        "MUSIC VOLUME", "SFX VOLUME", "MUTE MUSIC:", "MUTE SFX:",
        "SHOW ENEMY LEVELS:", "WEATHER ANIMATIONS:", "SHOW FPS:"
    };
    for (int i = 0; i < 7; i++) {
        settingLabels[i] = new Label(settingStrs[i], white);
        settingLabels[i].setTouchable(Touchable.disabled);
        settingLabels[i].setFontScale(0.5f);
        stage.addActor(settingLabels[i]);
    }
    for (int i = 0; i < 2; i++) settingLabels[i].setPosition(14, 76 - i * 24);
    for (int i = 2; i < 4; i++) settingLabels[i].setPosition(14, 26 - (i - 2) * 14);
    for (int i = 4; i < 7; i++) settingLabels[i].setPosition(111, 72 - (i - 4) * 16);

    createSliders();
    createCheckboxes();
}