Search in sources :

Example 1 with TournamentPlayerPanel

use of mage.client.table.TournamentPlayerPanel in project mage by magefree.

the class NewTournamentDialog method drawPlayers.

private void drawPlayers() {
    this.pnlOtherPlayers.removeAll();
    for (TournamentPlayerPanel panel : players) {
        this.pnlOtherPlayers.add(panel);
        panel.getPlayerType().addActionListener(evt -> {
            if (!automaticChange) {
                playerActionPerformed(evt);
            }
        });
    }
    this.pack();
    this.revalidate();
    this.repaint();
}
Also used : TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel)

Example 2 with TournamentPlayerPanel

use of mage.client.table.TournamentPlayerPanel in project mage by magefree.

the class NewTournamentDialog method playerActionPerformed.

private void playerActionPerformed(java.awt.event.ActionEvent evt) {
    boolean start = false;
    int selectedIndex = 0;
    automaticChange = true;
    for (TournamentPlayerPanel player : players) {
        if (!start) {
            if (evt.getSource().equals(player.getPlayerType())) {
                start = true;
                selectedIndex = player.getPlayerType().getSelectedIndex();
            }
        } else {
            player.getPlayerType().setSelectedIndex(selectedIndex);
        }
    }
    automaticChange = false;
}
Also used : TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel)

Example 3 with TournamentPlayerPanel

use of mage.client.table.TournamentPlayerPanel in project mage by magefree.

the class NewTournamentDialog method getTournamentOptions.

private TournamentOptions getTournamentOptions() {
    TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
    int numSeats = (Integer) this.spnNumSeats.getValue();
    TournamentOptions tOptions = new TournamentOptions(this.txtName.getText(), "", numSeats);
    tOptions.setTournamentType(tournamentType.getName());
    tOptions.setPassword(txtPassword.getText());
    tOptions.getPlayerTypes().add(PlayerType.HUMAN);
    tOptions.setWatchingAllowed(cbAllowSpectators.isSelected());
    tOptions.setPlaneChase(cbPlaneChase.isSelected());
    tOptions.setQuitRatio((Integer) spnQuitRatio.getValue());
    tOptions.setMinimumRating((Integer) spnMinimumRating.getValue());
    for (TournamentPlayerPanel player : players) {
        tOptions.getPlayerTypes().add((PlayerType) player.getPlayerType().getSelectedItem());
    }
    if (!tournamentType.isElimination()) {
        tOptions.setNumberRounds((Integer) spnNumRounds.getValue());
    }
    if (tournamentType.isDraft()) {
        DraftOptions options = new DraftOptions();
        options.setTiming((TimingOption) this.cbDraftTiming.getSelectedItem());
        tOptions.setLimitedOptions(options);
    }
    if (tOptions.getLimitedOptions() == null) {
        tOptions.setLimitedOptions(new LimitedOptions());
    }
    if (tournamentType.isLimited()) {
        tOptions.getLimitedOptions().setConstructionTime((Integer) this.spnConstructTime.getValue() * 60);
        tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
        tOptions.getLimitedOptions().setIsRichMan(tournamentType.isRichMan());
        tOptions.getLimitedOptions().setIsJumpstart(tournamentType.isJumpstart());
        if (tournamentType.isJumpstart()) {
            if (!(jumpstartPacksFilename.isEmpty())) {
                String jumpstartPacksData = "";
                try {
                    jumpstartPacksData = new String(Files.readAllBytes(Paths.get(jumpstartPacksFilename)));
                    if (jumpstartPacksData.length() > 300000) {
                        JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Chosen file too big", "Jumpstart Packs data is too long.  Please trim or choose another file.", JOptionPane.ERROR_MESSAGE);
                        jumpstartPacksData = "";
                    }
                } catch (IOException e2) {
                    JOptionPane.showMessageDialog(MageFrame.getDesktop(), e2.getMessage(), "Error loading Jumpstart Packs data", JOptionPane.ERROR_MESSAGE);
                }
                tOptions.getLimitedOptions().setJumpstartPacks(jumpstartPacksData);
            }
        }
        if (tournamentType.isCubeBooster()) {
            tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
            if (!(cubeFromDeckFilename.isEmpty())) {
                Deck cubeFromDeck = new Deck();
                try {
                    cubeFromDeck = Deck.load(DeckImporter.importDeckFromFile(cubeFromDeckFilename, true), true, true);
                } catch (GameException e1) {
                    JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
                }
                if (cubeFromDeck != null) {
                    cubeFromDeck.clearLayouts();
                    tOptions.getLimitedOptions().setCubeFromDeck(cubeFromDeck);
                }
            }
        } else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
            this.isRandom = tournamentType.isRandom();
            this.isRichMan = tournamentType.isRichMan();
            tOptions.getLimitedOptions().getSetCodes().clear();
            java.util.List<String> selected = randomPackSelector.getSelectedPacks();
            Collections.shuffle(selected);
            int maxPacks = 3 * (players.size() + 1);
            if (tournamentType.isRichMan()) {
                maxPacks = 36;
            }
            if (selected.size() > maxPacks) {
                StringBuilder infoString = new StringBuilder("More sets were selected than needed. ");
                infoString.append(maxPacks);
                infoString.append(" sets will be randomly chosen.");
                JOptionPane.showMessageDialog(MageFrame.getDesktop(), infoString, "Information", JOptionPane.INFORMATION_MESSAGE);
                tOptions.getLimitedOptions().getSetCodes().addAll(selected.subList(0, maxPacks));
            } else {
                tOptions.getLimitedOptions().getSetCodes().addAll(selected);
            }
        } else {
            for (JPanel panel : packPanels) {
                JComboBox combo = findComboInComponent(panel);
                if (combo != null) {
                    tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) combo.getSelectedItem()).getCode());
                } else {
                    logger.error("Can't find combo component in " + panel.toString());
                }
            }
        }
        tOptions.getMatchOptions().setDeckType("Limited");
        tOptions.getMatchOptions().setGameType("Two Player Duel");
        tOptions.getMatchOptions().setLimited(true);
    } else {
        tOptions.getLimitedOptions().setConstructionTime(0);
        tOptions.getLimitedOptions().setNumberBoosters(0);
        tOptions.getLimitedOptions().setDraftCube(null);
        tOptions.getLimitedOptions().setDraftCubeName("");
        tOptions.getMatchOptions().setDeckType((String) this.cbDeckType.getSelectedItem());
        tOptions.getMatchOptions().setGameType(((GameTypeView) this.cbGameType.getSelectedItem()).getName());
        tOptions.getMatchOptions().setLimited(false);
    }
    String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
    tOptions.getMatchOptions().setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
    tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
    tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
    tOptions.getMatchOptions().setWinsNeeded((Integer) this.spnNumWins.getValue());
    tOptions.getMatchOptions().setFreeMulligans((Integer) this.spnFreeMulligans.getValue());
    tOptions.getMatchOptions().setMullgianType((MulliganType) this.cbMulligan.getSelectedItem());
    tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
    tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
    tOptions.getMatchOptions().setRollbackTurnsAllowed(this.chkRollbackTurnsAllowed.isSelected());
    tOptions.getMatchOptions().setRated(this.chkRated.isSelected());
    return tOptions;
}
Also used : LimitedOptions(mage.game.tournament.LimitedOptions) Deck(mage.cards.decks.Deck) IOException(java.io.IOException) TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel) TournamentTypeView(mage.view.TournamentTypeView) TournamentOptions(mage.game.tournament.TournamentOptions) DraftOptions(mage.game.draft.DraftOptions) IgnoreList(mage.client.util.IgnoreList) ExpansionInfo(mage.cards.repository.ExpansionInfo) GameException(mage.game.GameException)

Example 4 with TournamentPlayerPanel

use of mage.client.table.TournamentPlayerPanel in project mage by magefree.

the class NewTournamentDialog method btnOkActionPerformed.

// GEN-LAST:event_cbTournamentTypeActionPerformed
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_btnOkActionPerformed
    // get settings
    TournamentOptions tOptions = getTournamentOptions();
    // CHECKS
    TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
    if (tournamentType.isRandom() || tournamentType.isRichMan()) {
        if (tOptions.getLimitedOptions().getSetCodes().isEmpty()) {
            JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Warning, you must select packs for the pool", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    if (tournamentType.isDraft() && tOptions.getLimitedOptions() instanceof DraftOptions) {
        DraftOptions draftOptions = (DraftOptions) tOptions.getLimitedOptions();
        if (draftOptions.getTiming() == TimingOption.NONE) {
            JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Warning, you must select draft timing option", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    // save last settings
    onSaveSettings(0, tOptions);
    // run
    table = SessionHandler.createTournamentTable(roomId, tOptions);
    if (table == null) {
        // message must be send by server!
        return;
    }
    // join AI
    for (TournamentPlayerPanel player : players) {
        if (player.getPlayerType().getSelectedItem() != PlayerType.HUMAN) {
            if (!player.joinTournamentTable(roomId, table.getTableId(), DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true))) {
                // error message must be send by sever
                SessionHandler.removeTable(roomId, table.getTableId());
                table = null;
                return;
            }
        }
    }
    // join itself
    if (SessionHandler.joinTournamentTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), PlayerType.HUMAN, 1, DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true), tOptions.getPassword())) {
        // all fine, can close create dialog (join dialog will be opened after feedback from server)
        this.hideDialog();
        return;
    }
    JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
    SessionHandler.removeTable(roomId, table.getTableId());
    table = null;
}
Also used : TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel) TournamentOptions(mage.game.tournament.TournamentOptions) TournamentTypeView(mage.view.TournamentTypeView) DraftOptions(mage.game.draft.DraftOptions)

Example 5 with TournamentPlayerPanel

use of mage.client.table.TournamentPlayerPanel in project mage by magefree.

the class NewTournamentDialog method createPlayers.

private void createPlayers(int numPlayers) {
    // add/remove player panels
    if (numPlayers > players.size()) {
        while (players.size() != numPlayers) {
            TournamentPlayerPanel playerPanel = new TournamentPlayerPanel();
            playerPanel.init(players.size() + 2);
            players.add(playerPanel);
        }
    } else if (numPlayers < players.size()) {
        while (players.size() != numPlayers) {
            players.remove(players.size() - 1);
        }
    }
    drawPlayers();
    setNumberOfSwissRoundsMin(numPlayers);
}
Also used : TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel)

Aggregations

TournamentPlayerPanel (mage.client.table.TournamentPlayerPanel)6 DraftOptions (mage.game.draft.DraftOptions)3 TournamentOptions (mage.game.tournament.TournamentOptions)3 TournamentTypeView (mage.view.TournamentTypeView)3 IOException (java.io.IOException)2 Deck (mage.cards.decks.Deck)2 ExpansionInfo (mage.cards.repository.ExpansionInfo)2 IgnoreList (mage.client.util.IgnoreList)2 GameException (mage.game.GameException)2 LimitedOptions (mage.game.tournament.LimitedOptions)2 java.awt (java.awt)1 File (java.io.File)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 javax.swing (javax.swing)1 DeckFileFilter (mage.cards.decks.DeckFileFilter)1 DeckImporter (mage.cards.decks.importer.DeckImporter)1 ExpansionRepository (mage.cards.repository.ExpansionRepository)1