Search in sources :

Example 1 with BallotOption

use of de.gg.game.model.votes.BallotOption 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)

Example 2 with BallotOption

use of de.gg.game.model.votes.BallotOption in project ProjektGG by eskalon.

the class CharacterBehaviour method getElectionVoteOption.

@SuppressWarnings("unchecked")
private static int getElectionVoteOption(short characterId, ElectionBallot matter, GameSession session) {
    Map<Integer, Integer> options = new HashMap<>();
    for (BallotOption vo : matter.getOptions()) {
        int tmp = 0;
        short voteOptionCharId = (short) vo.getValue();
        tmp += getOpinionOfAnotherCharacter(voteOptionCharId, characterId, session);
        if (characterId == voteOptionCharId)
            tmp = 125;
        options.put(vo.getValue(), tmp);
    }
    options = CollectionUtils.sortByValue(options);
    return ((Entry<Integer, Integer>) options.entrySet().toArray()[0]).getKey();
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) BallotOption(de.gg.game.model.votes.BallotOption)

Aggregations

BallotOption (de.gg.game.model.votes.BallotOption)2 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 CharacterComponent (de.gg.game.ui.components.CharacterComponent)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1