Search in sources :

Example 1 with OffsettableImageTextButton

use of de.gg.engine.ui.components.OffsettableImageTextButton in project ProjektGG by eskalon.

the class GameBallotScreen method onNewBallot.

@Subscribe
private void onNewBallot(NewBallotEvent ev) {
    if (ev.getNewBallot() == null) {
        application.getScreenManager().pushScreen("map", "circle_open");
        return;
    }
    World world = application.getClient().getSession().getWorld();
    Player localPlayer = application.getClient().getLocalPlayer();
    optionTable.clear();
    voterTable.clear();
    buttons.clear();
    infoText.setText(ev.getNewBallot().getInfoText());
    // Display the voters
    voterTable.add(new Label(Lang.get("screen.vote.voters"), skin, "title")).padBottom(12).row();
    for (short s : ev.getNewBallot().getVoters()) {
        // PositionType posT = world.getCharacter(s).getPosition();
        boolean isLocalPlayer = s == application.getClient().getLocalPlayer().getCurrentlyPlayedCharacterId();
        voterTable.add(new CharacterComponent(skin, world.getCharacter(s), isLocalPlayer ? -1 : application.getClient().getOpinionOfOtherCharacter(s))).left().padBottom(25).row();
    }
    // Display the options (if the player can vote)
    if (ev.getNewBallot().getVoters().contains(localPlayer.getCurrentlyPlayedCharacterId())) {
        for (BallotOption option : ev.getNewBallot().getOptions()) {
            ImageTextButton button = new OffsettableImageTextButton(Lang.get(option), skin, 5);
            button.addListener(new ButtonClickListener(application.getSoundManager()) {

                @Override
                protected void onClick() {
                    application.getClient().getActionHandler().castVote(option.getValue());
                    for (Button b : buttons) {
                        b.setDisabled(true);
                        b.setTouchable(Touchable.disabled);
                    }
                }
            });
            buttons.add(button);
            if (option.isCharacter() && option.getValue() != application.getClient().getLocalPlayer().getCurrentlyPlayedCharacterId()) {
                // PositionType posT = world.getCharacters()
                // .get((short) option.getValue()).getPosition();
                optionTable.add(new CharacterComponent(skin, world.getCharacter((short) option.getValue()), application.getClient().getOpinionOfOtherCharacter((short) option.getValue()))).right().padBottom(8).row();
            }
            optionTable.add(button).right().padBottom(15).row();
        }
    }
}
Also used : Player(de.gg.game.model.entities.Player) OffsettableImageTextButton(de.gg.engine.ui.components.OffsettableImageTextButton) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) OffsettableImageTextButton(de.gg.engine.ui.components.OffsettableImageTextButton) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) ButtonClickListener(de.gg.game.input.ButtonClickListener) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) CharacterComponent(de.gg.game.ui.components.CharacterComponent) BallotOption(de.gg.game.model.votes.BallotOption) OffsettableImageTextButton(de.gg.engine.ui.components.OffsettableImageTextButton) World(de.gg.game.model.World) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Button (com.badlogic.gdx.scenes.scene2d.ui.Button)1 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Subscribe (com.google.common.eventbus.Subscribe)1 OffsettableImageTextButton (de.gg.engine.ui.components.OffsettableImageTextButton)1 ButtonClickListener (de.gg.game.input.ButtonClickListener)1 World (de.gg.game.model.World)1 Player (de.gg.game.model.entities.Player)1 BallotOption (de.gg.game.model.votes.BallotOption)1 CharacterComponent (de.gg.game.ui.components.CharacterComponent)1