use of mage.client.table.TablePlayerPanel in project mage by magefree.
the class NewTableDialog method showDialog.
public void showDialog(UUID roomId) {
this.roomId = roomId;
if (!lastSessionId.equals(SessionHandler.getSessionId())) {
lastSessionId = SessionHandler.getSessionId();
this.player1Panel.setPlayerName(SessionHandler.getUserName());
cbGameType.setModel(new DefaultComboBoxModel(SessionHandler.getGameTypes().toArray()));
cbDeckType.setModel(new DefaultComboBoxModel(SessionHandler.getDeckTypes()));
selectLimitedByDefault();
cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values()));
cbRange.setModel(new DefaultComboBoxModel(RangeOfInfluence.values()));
cbAttackOption.setModel(new DefaultComboBoxModel(MultiplayerAttackOption.values()));
cbSkillLevel.setModel(new DefaultComboBoxModel(SkillLevel.values()));
cbMulligan.setModel(new DefaultComboBoxModel(MulliganType.values()));
// Update the existing player panels (neccessary if server was changes = new session)
int i = 2;
for (TablePlayerPanel tablePlayerPanel : players) {
tablePlayerPanel.init(i++, tablePlayerPanel.getPlayerType());
}
this.setModal(true);
setGameOptions();
this.setLocation(150, 100);
}
// auto-load last settings
onLoadSettings(0);
this.setVisible(true);
}
use of mage.client.table.TablePlayerPanel in project mage by magefree.
the class NewTableDialog method createPlayers.
private void createPlayers(int numPlayers) {
// add missing player panels
if (numPlayers > players.size()) {
while (players.size() != numPlayers) {
TablePlayerPanel playerPanel = new TablePlayerPanel();
PlayerType playerType = PlayerType.HUMAN;
if (prefPlayerTypes.size() >= players.size() && !players.isEmpty()) {
playerType = prefPlayerTypes.get(players.size() - 1);
}
playerPanel.init(players.size() + 2, playerType);
players.add(playerPanel);
playerPanel.addPlayerTypeEventListener((Listener<Event>) event -> drawPlayers());
}
} else // remove player panels no longer needed
if (numPlayers < players.size()) {
while (players.size() != numPlayers) {
players.remove(players.size() - 1);
}
}
drawPlayers();
}
use of mage.client.table.TablePlayerPanel in project mage by magefree.
the class NewTableDialog method drawPlayers.
private void drawPlayers() {
this.pnlOtherPlayers.removeAll();
for (TablePlayerPanel panel : players) {
this.pnlOtherPlayers.add(panel);
}
this.pack();
this.revalidate();
this.repaint();
}
use of mage.client.table.TablePlayerPanel in project mage by magefree.
the class NewTableDialog method btnOKActionPerformed.
// GEN-LAST:event_btnPreviousConfigurationActionPerformed
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_btnOKActionPerformed
MatchOptions options = getMatchOptions();
if (!checkMatchOptions(options)) {
return;
}
// save last used
onSaveSettings(0, options, this.player1Panel.getDeckFile());
// run
table = SessionHandler.createTable(roomId, options);
if (table == null) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
// join AI
for (TablePlayerPanel player : players) {
if (player.getPlayerType() != PlayerType.HUMAN) {
if (!player.joinTable(roomId, table.getTableId())) {
// error message must be send by the server
SessionHandler.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
// join itself
if (SessionHandler.joinTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), PlayerType.HUMAN, 1, DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true), this.txtPassword.getText())) {
// all fine, can close create dialog (join dialog will be opened after feedback from server)
this.hideDialog();
return;
}
} catch (ClassNotFoundException | IOException ex) {
handleError(ex);
}
// JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining table.", "Error", JOptionPane.ERROR_MESSAGE);
SessionHandler.removeTable(roomId, table.getTableId());
table = null;
}
use of mage.client.table.TablePlayerPanel in project mage by magefree.
the class NewTableDialog method getMatchOptions.
// GEN-LAST:event_menuLoadSettingsDefaultActionPerformed
private MatchOptions getMatchOptions() {
// current settings
GameTypeView gameType = (GameTypeView) cbGameType.getSelectedItem();
MatchOptions options = new MatchOptions(this.txtName.getText(), gameType.getName(), false, 2);
options.getPlayerTypes().add(PlayerType.HUMAN);
for (TablePlayerPanel player : players) {
options.getPlayerTypes().add(player.getPlayerType());
}
options.setDeckType((String) this.cbDeckType.getSelectedItem());
options.setLimited(false);
options.setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
options.setAttackOption((MultiplayerAttackOption) this.cbAttackOption.getSelectedItem());
options.setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
options.setRange((RangeOfInfluence) this.cbRange.getSelectedItem());
options.setWinsNeeded((Integer) this.spnNumWins.getValue());
options.setRollbackTurnsAllowed(chkRollbackTurnsAllowed.isSelected());
options.setSpectatorsAllowed(chkSpectatorsAllowed.isSelected());
options.setPlaneChase(chkPlaneChase.isSelected());
options.setRated(chkRated.isSelected());
options.setFreeMulligans((Integer) this.spnFreeMulligans.getValue());
options.setPassword(this.txtPassword.getText());
options.setQuitRatio((Integer) this.spnQuitRatio.getValue());
options.setMinimumRating((Integer) this.spnMinimumRating.getValue());
options.setEdhPowerLevel((Integer) this.spnEdhPowerLevel.getValue());
options.setMullgianType((MulliganType) this.cbMulligan.getSelectedItem());
String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
return options;
}
Aggregations