Search in sources :

Example 1 with EnumGameDirection

use of ultimate.karoapi4j.enums.EnumGameDirection in project KaroToolsCollection by ultimate.

the class RulesScreen method updateBeforeShow.

@Override
public void updateBeforeShow(GameSeries gameSeries, EnumNavigation direction) {
    this.removeAll();
    int minZzzInit = (gameSeries.getRules() != null ? gameSeries.getRules().getMinZzz() : 2);
    this.minZzzSpinner = new JSpinner(new SpinnerNumberModel(minZzzInit, 0, Integer.MAX_VALUE, 1));
    int maxZzzInit = (gameSeries.getRules() != null ? gameSeries.getRules().getMaxZzz() : 2);
    this.maxZzzSpinner = new JSpinner(new SpinnerNumberModel(maxZzzInit, 0, Integer.MAX_VALUE, 1));
    EnumGameTC crashingAllowedInit = (gameSeries.getRules() != null ? gameSeries.getRules().getCrashallowed() : EnumGameTC.forbidden);
    this.crashingAllowedCB = new JComboBox<>(new GenericEnumModel<EnumGameTC>(EnumGameTC.class, crashingAllowedInit, true));
    Boolean checkpointsActivatedInit = (gameSeries.getRules() != null ? gameSeries.getRules().getCps() : true);
    this.checkpointsActivatedCB = new JComboBox<>(new BooleanModel(checkpointsActivatedInit, true));
    EnumGameDirection directionInit = (gameSeries.getRules() != null ? gameSeries.getRules().getStartdirection() : EnumGameDirection.classic);
    this.directionCB = new JComboBox<>(new GenericEnumModel<EnumGameDirection>(EnumGameDirection.class, directionInit, true));
    boolean creatorGiveUpInit = gameSeries.isCreatorGiveUp();
    this.creatorGiveUpCB = new JComboBox<>(new BooleanModel(creatorGiveUpInit, false));
    this.creatorGiveUpCB.setEnabled(GameSeriesManager.getBooleanConfig(GameSeriesManager.CONFIG_ALLOW_CREATOR_GIVE_UP));
    boolean ignoreInvitableInit = gameSeries.isIgnoreInvitable();
    this.ignoreInvitableCB = new JComboBox<>(new BooleanModel(ignoreInvitableInit, false));
    this.ignoreInvitableCB.setEnabled(this.karoAPICache.getCurrentUser().isSuperCreator() || GameSeriesManager.getBooleanConfig(GameSeriesManager.CONFIG_ALLOW_IGNORE_INVITABLE));
    gbc.gridy = 0;
    if (!(gameSeries.getType() == EnumGameSeriesType.Balanced)) {
        gbc.gridx = 0;
        gbc.gridwidth = 1;
        this.add(new JLabel(Language.getString("screen.rules.minzzz", cellWidth)), gbc);
        gbc.gridx = 1;
        gbc.gridwidth = 1;
        this.add(this.minZzzSpinner, gbc);
        gbc.gridx = 2;
        gbc.gridwidth = 1;
        this.add(new JLabel(Language.getString("screen.rules.maxzzz", cellWidth)), gbc);
        gbc.gridx = 3;
        gbc.gridwidth = 1;
        this.add(this.maxZzzSpinner, gbc);
        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = 4;
        this.add(new JLabel(Language.getString("screen.rules.zzz.description", totalWidth)), gbc);
        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = 1;
        this.add(new JLabel(Language.getString("screen.rules.crashs", cellWidth)), gbc);
        gbc.gridx = 1;
        gbc.gridwidth = 3;
        this.add(this.crashingAllowedCB, gbc);
        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = 1;
        this.add(new JLabel(Language.getString("screen.rules.cps", cellWidth)), gbc);
        gbc.gridx = 1;
        gbc.gridwidth = 3;
        this.add(this.checkpointsActivatedCB, gbc);
        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = 1;
        this.add(new JLabel(Language.getString("screen.rules.direction", cellWidth)), gbc);
        gbc.gridx = 1;
        gbc.gridwidth = 3;
        this.add(this.directionCB, gbc);
    }
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    this.add(new JLabel(Language.getString("screen.rules.creatorgiveup", cellWidth)), gbc);
    gbc.gridx = 1;
    gbc.gridwidth = 3;
    this.add(this.creatorGiveUpCB, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 4;
    this.add(new JLabel(Language.getString("screen.rules.creatorgiveup.description", totalWidth)), gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    this.add(new JLabel(Language.getString("screen.rules.ignoreinvitable", cellWidth)), gbc);
    gbc.gridx = 1;
    gbc.gridwidth = 3;
    this.add(this.ignoreInvitableCB, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 4;
    this.add(new JLabel(Language.getString("screen.rules.ignoreinvitable.description", totalWidth)), gbc);
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) GenericEnumModel(ultimate.karomuskel.ui.components.GenericEnumModel) EnumGameDirection(ultimate.karoapi4j.enums.EnumGameDirection) EnumGameTC(ultimate.karoapi4j.enums.EnumGameTC) BooleanModel(ultimate.karomuskel.ui.components.BooleanModel) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel)

Example 2 with EnumGameDirection

use of ultimate.karoapi4j.enums.EnumGameDirection in project KaroToolsCollection by ultimate.

the class SummaryScreen method initTable.

private void initTable(final JTable table) {
    table.setRowHeight(20);
    TableColumn col;
    for (int i = 0; i < table.getColumnCount(); i++) {
        col = table.getColumnModel().getColumn(i);
        col.setPreferredWidth(this.model.getColumnWidth(i));
        if (table.getColumnClass(i).equals(Integer.class)) {
            col.setCellEditor(new SpinnerCellEditor(new SpinnerNumberModel(2, 0, Integer.MAX_VALUE, 1)));
        } else if (table.getColumnClass(i).equals(EnumGameTC.class)) {
            col.setCellEditor(new DefaultCellEditor(new JComboBox<Label<EnumGameTC>>(new GenericEnumModel<EnumGameTC>(EnumGameTC.class, EnumGameTC.free, false))));
        } else if (table.getColumnClass(i).equals(EnumGameDirection.class)) {
            col.setCellEditor(new DefaultCellEditor(new JComboBox<Label<EnumGameDirection>>(new GenericEnumModel<EnumGameDirection>(EnumGameDirection.class, EnumGameDirection.free, false))));
        } else if (table.getColumnClass(i).equals(Map.class)) {
            Map[] maps = karoAPICache.getMaps().toArray(new Map[0]);
            col.setCellEditor(new DefaultCellEditor(new JComboBox<Map>(new DefaultComboBoxModel<Map>(maps))));
        } else if (table.getColumnClass(i).equals(User.class)) {
            UserCellEditor editor = new UserCellEditor(this.gui, this.model, karoAPICache);
            col.setCellEditor(editor);
            col.setCellRenderer(editor);
        }
    }
    // Batch-Update-Support
    table.getTableHeader().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            int col = table.columnAtPoint(e.getPoint());
            if (// Title
            col == 0)
                batchUpdateString(col, Language.getString("screen.summary.table.name"), Language.getString("screen.summary.batchUpdate.note.name"));
            else if (// Map
            col == 1)
                batchUpdateSelection(col, Language.getString("screen.summary.table.map"), new DefaultComboBoxModel<Map>(karoAPICache.getMaps().toArray(new Map[0])));
            else if (// Players
            col == 2)
                batchUpdatePlayers(col, Language.getString("screen.summary.table.players"));
            else if (// ZZZ
            col == 3)
                batchUpdateInt(col, Language.getString("screen.summary.table.zzz"), new SpinnerNumberModel(2, 0, Integer.MAX_VALUE, 1));
            else if (// TC
            col == 4)
                batchUpdateSelection(col, Language.getString("screen.summary.table.crashs"), new GenericEnumModel<EnumGameTC>(EnumGameTC.class, EnumGameTC.free, false));
            else if (// CPs
            col == 5)
                batchUpdateBoolean(col, Language.getString("screen.summary.table.cps"));
            else if (// Direction
            col == 6)
                batchUpdateSelection(col, Language.getString("screen.summary.table.direction"), new GenericEnumModel<EnumGameDirection>(EnumGameDirection.class, EnumGameDirection.free, false));
            else if (// Create
            col == 7)
                batchUpdateBoolean(col, Language.getString("screen.summary.table.createstatus"));
            else if (// Leave
            col == 8)
                batchUpdateBoolean(col, Language.getString("screen.summary.table.leavestatus"));
        }
    });
    for (PlannedGame game : this.gameSeries.getGames()) {
        this.model.addRow(game);
    }
}
Also used : GenericEnumModel(ultimate.karomuskel.ui.components.GenericEnumModel) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) Label(ultimate.karomuskel.ui.Language.Label) JLabel(javax.swing.JLabel) MouseAdapter(java.awt.event.MouseAdapter) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TableColumn(javax.swing.table.TableColumn) UserCellEditor(ultimate.karomuskel.ui.components.UserCellEditor) DefaultCellEditor(javax.swing.DefaultCellEditor) SpinnerNumberModel(javax.swing.SpinnerNumberModel) EnumGameDirection(ultimate.karoapi4j.enums.EnumGameDirection) EnumGameTC(ultimate.karoapi4j.enums.EnumGameTC) PlannedGame(ultimate.karoapi4j.model.official.PlannedGame) SpinnerCellEditor(ultimate.karomuskel.ui.components.SpinnerCellEditor) Map(ultimate.karoapi4j.model.official.Map)

Example 3 with EnumGameDirection

use of ultimate.karoapi4j.enums.EnumGameDirection in project KaroToolsCollection by ultimate.

the class MapsAndRulesScreen method updateBeforeShow.

@Override
public void updateBeforeShow(GameSeries gameSeries, EnumNavigation direction) {
    this.gameSeries = gameSeries;
    int numberOfMapsTmp = (int) gameSeries.get(GameSeries.NUMBER_OF_MAPS);
    if (this.firstShow || numberOfMapsTmp != this.numberOfMaps) {
        this.numberOfMaps = numberOfMapsTmp;
        this.mapCBList = new LinkedList<>();
        this.gamesPerPlayerSpinnerList = new LinkedList<>();
        this.numberOfPlayersSpinnerList = new LinkedList<>();
        this.minZzzSpinnerList = new LinkedList<>();
        this.maxZzzSpinnerList = new LinkedList<>();
        this.numberOfGamesTFList = new LinkedList<>();
        this.crashingAllowedCBList = new LinkedList<>();
        this.checkpointsActivatedCBList = new LinkedList<>();
        this.directionCBList = new LinkedList<>();
        this.removeAll();
        JPanel contentPanel = new JPanel();
        JScrollPane contentSP = new JScrollPane(contentPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        this.add(contentSP);
        GridBagLayout layout = new GridBagLayout();
        contentPanel.setLayout(layout);
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        JLabel label;
        JComboBox<Map> mapCB;
        JSpinner gamesPerPlayerSpinner;
        JSpinner numberOfPlayersSpinner;
        JSpinner minZzzSpinner;
        JSpinner maxZzzSpinner;
        JTextField numberOfGamesTF;
        JComboBox<Label<EnumGameTC>> crashingAllowedCB;
        JComboBox<Label<Boolean>> checkpointsActivatedCB;
        JComboBox<Label<EnumGameDirection>> directionCB;
        Map map;
        Rules rules;
        int gamesPerPlayer;
        int numberOfPlayers;
        Integer maxZzz;
        Integer minZzz;
        EnumGameTC crashingAllowed;
        Boolean checkpointsActivated;
        EnumGameDirection startDirection;
        int maxGamesPerPlayer = GameSeriesManager.getIntConfig(gameSeries, GameSeries.CONF_MAX_GAMES_PER_PLAYER);
        for (int i = 0; i < this.numberOfMaps; i++) {
            final int j = i;
            // remove maps with only less then 3 players (since only races with creator + 2 others make sense)
            LinkedList<Map> maps = new LinkedList<Map>(karoAPICache.getMaps());
            maps.removeIf(m -> {
                return m.getPlayers() < 3;
            });
            if (gameSeries.getMapsByKey().containsKey("" + i) && gameSeries.getMapsByKey().get("" + i).size() > 0)
                map = gameSeries.getMapsByKey().get("" + i).get(0);
            else
                map = maps.getFirst();
            rules = gameSeries.getRulesByKey().get("" + i);
            if (rules != null) {
                checkpointsActivated = rules.getCps();
                crashingAllowed = rules.getCrashallowed();
                startDirection = rules.getStartdirection();
                maxZzz = rules.getMaxZzz();
                minZzz = rules.getMinZzz();
                numberOfPlayers = rules.getNumberOfPlayers();
                gamesPerPlayer = rules.getGamesPerPlayer();
            } else {
                checkpointsActivated = null;
                crashingAllowed = null;
                startDirection = null;
                maxZzz = null;
                minZzz = null;
                numberOfPlayers = map.getPlayers() - 1;
                gamesPerPlayer = numberOfPlayers;
            }
            gbc.gridy = rowsPerMap * i;
            label = new JLabel(Language.getString("screen.mapsAndRules.map") + (i + 1));
            gbc.gridx = 0;
            contentPanel.add(label, gbc);
            mapCB = new JComboBox<>();
            mapCB.setModel(new DefaultComboBoxModel<Map>(maps.toArray(new Map[0])));
            mapCB.setRenderer(new MapRenderer());
            mapCB.setSelectedItem(map);
            mapCB.addActionListener(this);
            mapCB.setActionCommand(ACTION_MAP_SELECT + i);
            gbc.gridwidth = 4;
            gbc.gridx = 1;
            contentPanel.add(mapCB, gbc);
            gbc.gridwidth = 1;
            gbc.gridy++;
            label = new JLabel(Language.getString("screen.mapsAndRules.gamesPerPlayer"));
            gbc.gridx = 1;
            contentPanel.add(label, gbc);
            gamesPerPlayerSpinner = new JSpinner(new SpinnerNumberModel(Math.min(gamesPerPlayer, maxGamesPerPlayer), 1, maxGamesPerPlayer, 1));
            gamesPerPlayerSpinner.addChangeListener(e -> {
                actionPerformed(new ActionEvent(e.getSource(), j, ACTION_RECALC_NUMBER_OF_GAMES + j));
            });
            gbc.gridx++;
            contentPanel.add(gamesPerPlayerSpinner, gbc);
            label = new JLabel(Language.getString("screen.mapsAndRules.numberOfPlayers"));
            gbc.gridx++;
            contentPanel.add(label, gbc);
            numberOfPlayersSpinner = new JSpinner(new SpinnerNumberModel(Math.min(gameSeries.getPlayers().size() + 1, numberOfPlayers), 2, Math.min(gameSeries.getPlayers().size() + 1, map.getPlayers() - 1), 1));
            numberOfPlayersSpinner.addChangeListener(e -> {
                actionPerformed(new ActionEvent(e.getSource(), j, ACTION_RECALC_NUMBER_OF_GAMES + j));
            });
            gbc.gridx++;
            contentPanel.add(numberOfPlayersSpinner, gbc);
            gbc.gridy++;
            label = new JLabel(Language.getString("screen.rules.crashs"));
            gbc.gridx = 1;
            contentPanel.add(label, gbc);
            crashingAllowedCB = new JComboBox<>(new GenericEnumModel<EnumGameTC>(EnumGameTC.class, crashingAllowed, true));
            gbc.gridx++;
            contentPanel.add(crashingAllowedCB, gbc);
            label = new JLabel(Language.getString("screen.settings.numberofgames"));
            gbc.gridx++;
            contentPanel.add(label, gbc);
            numberOfGamesTF = new JTextField();
            numberOfGamesTF.setEditable(false);
            numberOfGamesTF.setHorizontalAlignment(SwingConstants.RIGHT);
            gbc.gridx++;
            contentPanel.add(numberOfGamesTF, gbc);
            gbc.gridy++;
            label = new JLabel(Language.getString("screen.rules.minzzz"));
            gbc.gridx = 1;
            contentPanel.add(label, gbc);
            minZzzSpinner = new JSpinner(new SpinnerNumberModel((minZzz == null ? 2 : minZzz), 0, Integer.MAX_VALUE, 1));
            gbc.gridx++;
            contentPanel.add(minZzzSpinner, gbc);
            label = new JLabel(Language.getString("screen.rules.maxzzz"));
            gbc.gridx++;
            contentPanel.add(label, gbc);
            maxZzzSpinner = new JSpinner(new SpinnerNumberModel((maxZzz == null ? 2 : maxZzz), 0, Integer.MAX_VALUE, 1));
            gbc.gridx++;
            contentPanel.add(maxZzzSpinner, gbc);
            gbc.gridy++;
            label = new JLabel(Language.getString("screen.rules.cps"));
            gbc.gridx = 1;
            contentPanel.add(label, gbc);
            checkpointsActivatedCB = new JComboBox<>(new BooleanModel(checkpointsActivated, true));
            gbc.gridx++;
            contentPanel.add(checkpointsActivatedCB, gbc);
            label = new JLabel(Language.getString("screen.rules.direction"));
            gbc.gridx++;
            contentPanel.add(label, gbc);
            directionCB = new JComboBox<>(new GenericEnumModel<EnumGameDirection>(EnumGameDirection.class, startDirection, true));
            gbc.gridx++;
            contentPanel.add(directionCB, gbc);
            this.gamesPerPlayerSpinnerList.add(gamesPerPlayerSpinner);
            this.numberOfPlayersSpinnerList.add(numberOfPlayersSpinner);
            this.minZzzSpinnerList.add(minZzzSpinner);
            this.maxZzzSpinnerList.add(maxZzzSpinner);
            this.numberOfGamesTFList.add(numberOfGamesTF);
            this.crashingAllowedCBList.add(crashingAllowedCB);
            this.checkpointsActivatedCBList.add(checkpointsActivatedCB);
            this.directionCBList.add(directionCB);
            this.mapCBList.add(mapCB);
        }
    }
// TODO NAVIGATION preselect values from gameseries
}
Also used : JPanel(javax.swing.JPanel) GenericEnumModel(ultimate.karomuskel.ui.components.GenericEnumModel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) Label(ultimate.karomuskel.ui.Language.Label) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JScrollPane(javax.swing.JScrollPane) BooleanModel(ultimate.karomuskel.ui.components.BooleanModel) JLabel(javax.swing.JLabel) Rules(ultimate.karoapi4j.model.extended.Rules) LinkedList(java.util.LinkedList) EnumGameDirection(ultimate.karoapi4j.enums.EnumGameDirection) MapRenderer(ultimate.karomuskel.ui.components.MapRenderer) EnumGameTC(ultimate.karoapi4j.enums.EnumGameTC) JSpinner(javax.swing.JSpinner) Map(ultimate.karoapi4j.model.official.Map)

Example 4 with EnumGameDirection

use of ultimate.karoapi4j.enums.EnumGameDirection in project KaroToolsCollection by ultimate.

the class MapsAndRulesScreen method createRules.

@SuppressWarnings("unchecked")
private Rules createRules(int i) throws GameSeriesException {
    int gamesPerPlayer = (Integer) gamesPerPlayerSpinnerList.get(i).getValue();
    int numberOfPlayers = (Integer) numberOfPlayersSpinnerList.get(i).getValue();
    int minZzz = (Integer) minZzzSpinnerList.get(i).getValue();
    int maxZzz = (Integer) maxZzzSpinnerList.get(i).getValue();
    if (maxZzz < minZzz) {
        throw new GameSeriesException("screen.rules.invalidzzz");
    }
    EnumGameTC crashingAllowed = ((Label<EnumGameTC>) crashingAllowedCBList.get(i).getSelectedItem()).getValue();
    Boolean checkpointsActivated = ((Label<Boolean>) checkpointsActivatedCBList.get(i).getSelectedItem()).getValue();
    EnumGameDirection direction = ((Label<EnumGameDirection>) directionCBList.get(i).getSelectedItem()).getValue();
    return new Rules(minZzz, maxZzz, crashingAllowed, checkpointsActivated, direction, gamesPerPlayer, numberOfPlayers);
}
Also used : EnumGameDirection(ultimate.karoapi4j.enums.EnumGameDirection) EnumGameTC(ultimate.karoapi4j.enums.EnumGameTC) Label(ultimate.karomuskel.ui.Language.Label) JLabel(javax.swing.JLabel) GameSeriesException(ultimate.karoapi4j.exceptions.GameSeriesException) Rules(ultimate.karoapi4j.model.extended.Rules)

Example 5 with EnumGameDirection

use of ultimate.karoapi4j.enums.EnumGameDirection in project KaroToolsCollection by ultimate.

the class RulesScreen method createRules.

@SuppressWarnings("unchecked")
private Rules createRules() throws GameSeriesException {
    int minZzz = (Integer) minZzzSpinner.getValue();
    int maxZzz = (Integer) maxZzzSpinner.getValue();
    if (maxZzz < minZzz) {
        throw new GameSeriesException("screen.rules.invalidzzz");
    }
    EnumGameTC crashingAllowed = ((Label<EnumGameTC>) crashingAllowedCB.getSelectedItem()).getValue();
    Boolean checkpointsActivated = ((Label<Boolean>) checkpointsActivatedCB.getSelectedItem()).getValue();
    EnumGameDirection direction = ((Label<EnumGameDirection>) directionCB.getSelectedItem()).getValue();
    return new Rules(minZzz, maxZzz, crashingAllowed, checkpointsActivated, direction);
}
Also used : EnumGameDirection(ultimate.karoapi4j.enums.EnumGameDirection) EnumGameTC(ultimate.karoapi4j.enums.EnumGameTC) Label(ultimate.karomuskel.ui.Language.Label) JLabel(javax.swing.JLabel) GameSeriesException(ultimate.karoapi4j.exceptions.GameSeriesException) Rules(ultimate.karoapi4j.model.extended.Rules)

Aggregations

JLabel (javax.swing.JLabel)5 EnumGameDirection (ultimate.karoapi4j.enums.EnumGameDirection)5 EnumGameTC (ultimate.karoapi4j.enums.EnumGameTC)5 Label (ultimate.karomuskel.ui.Language.Label)4 SpinnerNumberModel (javax.swing.SpinnerNumberModel)3 Rules (ultimate.karoapi4j.model.extended.Rules)3 GenericEnumModel (ultimate.karomuskel.ui.components.GenericEnumModel)3 JSpinner (javax.swing.JSpinner)2 GameSeriesException (ultimate.karoapi4j.exceptions.GameSeriesException)2 Map (ultimate.karoapi4j.model.official.Map)2 BooleanModel (ultimate.karomuskel.ui.components.BooleanModel)2 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 LinkedList (java.util.LinkedList)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1