Search in sources :

Example 1 with TablePlayerPanel

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);
}
Also used : TablePlayerPanel(mage.client.table.TablePlayerPanel)

Example 2 with TablePlayerPanel

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();
}
Also used : MageComponents(mage.client.components.MageComponents) SkillLevel(mage.constants.SkillLevel) MageFrame(mage.client.MageFrame) TableView(mage.view.TableView) TablePlayerPanel(mage.client.table.TablePlayerPanel) RangeOfInfluence(mage.constants.RangeOfInfluence) DeckImporter(mage.cards.decks.importer.DeckImporter) MultiplayerAttackOption(mage.constants.MultiplayerAttackOption) IOException(java.io.IOException) UUID(java.util.UUID) PlayerType(mage.players.PlayerType) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) List(java.util.List) Event(mage.client.util.Event) IgnoreList(mage.client.util.IgnoreList) Listener(mage.client.util.Listener) MatchOptions(mage.game.match.MatchOptions) MulliganType(mage.game.mulligan.MulliganType) GameTypeView(mage.view.GameTypeView) SessionHandler(mage.client.SessionHandler) MatchTimeLimit(mage.constants.MatchTimeLimit) javax.swing(javax.swing) TablePlayerPanel(mage.client.table.TablePlayerPanel) PlayerType(mage.players.PlayerType) Event(mage.client.util.Event)

Example 3 with TablePlayerPanel

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();
}
Also used : TablePlayerPanel(mage.client.table.TablePlayerPanel)

Example 4 with TablePlayerPanel

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;
}
Also used : TablePlayerPanel(mage.client.table.TablePlayerPanel) MatchOptions(mage.game.match.MatchOptions) IOException(java.io.IOException)

Example 5 with TablePlayerPanel

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;
}
Also used : TablePlayerPanel(mage.client.table.TablePlayerPanel) MatchOptions(mage.game.match.MatchOptions) GameTypeView(mage.view.GameTypeView)

Aggregations

TablePlayerPanel (mage.client.table.TablePlayerPanel)6 MatchOptions (mage.game.match.MatchOptions)3 IOException (java.io.IOException)2 GameTypeView (mage.view.GameTypeView)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 javax.swing (javax.swing)1 DeckImporter (mage.cards.decks.importer.DeckImporter)1 MageFrame (mage.client.MageFrame)1 SessionHandler (mage.client.SessionHandler)1 MageComponents (mage.client.components.MageComponents)1 Event (mage.client.util.Event)1 IgnoreList (mage.client.util.IgnoreList)1 Listener (mage.client.util.Listener)1 MatchTimeLimit (mage.constants.MatchTimeLimit)1 MultiplayerAttackOption (mage.constants.MultiplayerAttackOption)1 RangeOfInfluence (mage.constants.RangeOfInfluence)1 SkillLevel (mage.constants.SkillLevel)1