use of ultimate.karomuskel.ui.Language.Label in project KaroToolsCollection by ultimate.
the class SettingsScreen method applySettings.
@SuppressWarnings("unchecked")
@Override
public GameSeries applySettings(GameSeries gameSeries, EnumNavigation direction) throws GameSeriesException {
gameSeries.setTitle(titleTF.getText());
if (gameSeries.getTitle() == null || gameSeries.getTitle().isEmpty())
throw new GameSeriesException("screen.settings.notitle");
if (gameSeries.getType() == EnumGameSeriesType.Simple) {
gameSeries.set(GameSeries.NUMBER_OF_GAMES, (Integer) numberOfGamesSpinner.getValue());
gameSeries.set(GameSeries.MIN_PLAYERS_PER_GAME, (Integer) minPlayersPerGameSpinner.getValue());
gameSeries.set(GameSeries.MAX_PLAYERS_PER_GAME, (Integer) maxPlayersPerGameSpinner.getValue());
if ((int) gameSeries.get(GameSeries.MIN_PLAYERS_PER_GAME) > (int) gameSeries.get(GameSeries.MAX_PLAYERS_PER_GAME))
throw new GameSeriesException("screen.settings.minabovemax");
} else if (GameSeriesManager.isTeamBased(gameSeries)) {
gameSeries.set(GameSeries.NUMBER_OF_TEAMS, (Integer) numberOfTeamsSpinner.getValue());
gameSeries.set(GameSeries.MIN_PLAYERS_PER_TEAM, (Integer) minPlayersPerTeamSpinner.getValue());
gameSeries.set(GameSeries.MAX_PLAYERS_PER_TEAM, (Integer) maxPlayersPerTeamSpinner.getValue());
if ((int) gameSeries.get(GameSeries.MIN_PLAYERS_PER_TEAM) > (int) gameSeries.get(GameSeries.MAX_PLAYERS_PER_TEAM))
throw new GameSeriesException("screen.settings.minabovemax");
gameSeries.set(GameSeries.NUMBER_OF_GAMES_PER_PAIR, (Integer) numberOfGamesPerPairSpinner.getValue());
if (gameSeries.getType() == EnumGameSeriesType.AllCombinations) {
// always false for AllCombinations, required so we don't run into an error
gameSeries.set(GameSeries.USE_HOME_MAPS, false);
gameSeries.set(GameSeries.NUMBER_OF_TEAMS_PER_MATCH, (Integer) numberOfTeamsPerMatchSpinner.getValue());
} else {
if (gameSeries.getType() == EnumGameSeriesType.KO && (int) gameSeries.get(GameSeries.NUMBER_OF_GAMES_PER_PAIR) == 1)
// home maps do not make sense here
gameSeries.set(GameSeries.USE_HOME_MAPS, false);
else
gameSeries.set(GameSeries.USE_HOME_MAPS, ((Label<Boolean>) useHomeMapsCB.getSelectedItem()).getValue());
}
gameSeries.set(GameSeries.SHUFFLE_TEAMS, ((Label<Boolean>) shuffleTeamsCB.getSelectedItem()).getValue());
if (gameSeries.getType() == EnumGameSeriesType.KO) {
gameSeries.set(GameSeries.SMALL_FINAL, ((Label<Boolean>) smallFinalCB.getSelectedItem()).getValue());
gameSeries.set(GameSeries.CURRENT_ROUND, gameSeries.get(GameSeries.NUMBER_OF_TEAMS));
} else if (gameSeries.getType() == EnumGameSeriesType.League) {
if ((int) gameSeries.get(GameSeries.NUMBER_OF_TEAMS) % 2 == 1)
gameSeries.set(GameSeries.DUMMY_MATCHES, ((Label<Boolean>) dummyMatchesCB.getSelectedItem()).getValue());
else
gameSeries.set(GameSeries.DUMMY_MATCHES, false);
}
gameSeries.set(GameSeries.AUTO_NAME_TEAMS, ((Label<Boolean>) autoNameTeamsCB.getSelectedItem()).getValue());
gameSeries.set(GameSeries.USE_CREATOR_TEAM, !((Label<Boolean>) creatorTeamCB.getSelectedItem()).getValue());
gameSeries.set(GameSeries.ALLOW_MULTIPLE_TEAMS, ((Label<Boolean>) multipleTeamsCB.getSelectedItem()).getValue());
int numberOfGamesPerPair = (int) gameSeries.get(GameSeries.NUMBER_OF_GAMES_PER_PAIR);
boolean homeMaps = ((boolean) gameSeries.get(GameSeries.USE_HOME_MAPS)) && (numberOfGamesPerPair > 1);
boolean otherMaps = (numberOfGamesPerPair % 2 == 1) || (!homeMaps);
findScreen(s -> {
return s instanceof HomeMapsScreen;
}, EnumNavigation.next).setSkip(!homeMaps);
findScreen(s -> {
return s instanceof MapsScreen;
}, EnumNavigation.next).setSkip(!otherMaps);
if (gameSeries.getType() == EnumGameSeriesType.KO) {
int maxTeams = GameSeriesManager.getIntConfig(gameSeries, GameSeries.CONF_MAX_TEAMS);
int teams = (int) gameSeries.get(GameSeries.NUMBER_OF_TEAMS);
// skip the screens those who are too many for the number of teams
Screen cursor = findScreen(s -> {
return s instanceof KOWinnersScreen;
}, EnumNavigation.next);
while (cursor != null && !(cursor instanceof StartScreen)) {
// skip KO
cursor.setSkip(maxTeams > teams);
cursor = cursor.getNext();
// skip Summary
cursor.setSkip(maxTeams > teams);
cursor = cursor.getNext();
maxTeams /= 2;
}
}
} else if (gameSeries.getType() == EnumGameSeriesType.Balanced) {
gameSeries.set(GameSeries.NUMBER_OF_MAPS, (Integer) numberOfMapsSpinner.getValue());
} else if (gameSeries.getType() == EnumGameSeriesType.KLC) {
// set current round after player selection
}
return gameSeries;
}
use of ultimate.karomuskel.ui.Language.Label 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"));
}
});
if (this.gameSeries.getGames().get(this.key) != null)
for (PlannedGame game : this.gameSeries.getGames().get(this.key)) this.model.addRow(game);
}
use of ultimate.karomuskel.ui.Language.Label 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) {
// preselect values from gameseries
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);
int value = Math.min(gameSeries.getPlayers().size() + 1, numberOfPlayers);
int max = Math.min(gameSeries.getPlayers().size() + 1, map.getPlayers() - 1);
// usually value should not be > max; but with manipulation this can lead to an error, so handle it here
value = Math.min(value, max);
numberOfPlayersSpinner = new JSpinner(new SpinnerNumberModel(value, 2, max, 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);
actionPerformed(new ActionEvent(gamesPerPlayerSpinner, j, ACTION_RECALC_NUMBER_OF_GAMES + j));
}
}
this.firstShow = false;
}
use of ultimate.karomuskel.ui.Language.Label in project KaroToolsCollection by ultimate.
the class RulesScreen method applySettings.
@SuppressWarnings("unchecked")
@Override
public GameSeries applySettings(GameSeries gameSeries, EnumNavigation direction) throws GameSeriesException {
Rules rules = createRules();
gameSeries.setRules(rules);
boolean creatorGiveUp = ((Label<Boolean>) creatorGiveUpCB.getSelectedItem()).getValue();
gameSeries.setCreatorGiveUp(creatorGiveUp);
boolean ignoreInvitable = ((Label<Boolean>) ignoreInvitableCB.getSelectedItem()).getValue();
gameSeries.setIgnoreInvitable(ignoreInvitable);
return gameSeries;
}
use of ultimate.karomuskel.ui.Language.Label 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);
}
Aggregations