* UI: added save/load/reset game settings for new table dialog;

Fixed that edh power level don't saves;
This commit is contained in:
Oleg Agafonov 2019-03-23 06:54:17 +04:00
parent 42658d5cff
commit 1b79827b2d
4 changed files with 491 additions and 262 deletions

View file

@ -129,7 +129,8 @@ public class MageDialog extends javax.swing.JInternalFrame {
// need popup clicks and mouse wheel (for out of bound actions) // need popup clicks and mouse wheel (for out of bound actions)
if (!allowedEvent) { if (!allowedEvent) {
popupComponent = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); // show root component (popups creates at root) popupComponent = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); // show root component (popups creates at root)
if (popupComponent != null && popupComponent.getClass().getName().contains("BasicComboPopup")) { if (popupComponent != null && (popupComponent.getClass().getName().contains("BasicComboPopup")
|| popupComponent.getClass().getName().contains("JMenuItem"))) {
popupEvent = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, popupComponent); popupEvent = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, popupComponent);
allowedEvent = true; allowedEvent = true;
} }

View file

@ -1,6 +1,79 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo"> <Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<NonVisualComponents>
<Container class="javax.swing.JPopupMenu" name="popupSaveSettings">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="menuSaveSettings1">
<Properties>
<Property name="text" type="java.lang.String" value="Save to config 1"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuSaveSettings1ActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="menuSaveSettings2">
<Properties>
<Property name="text" type="java.lang.String" value="Save to config 2"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuSaveSettings2ActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Container>
<Container class="javax.swing.JPopupMenu" name="popupLoadSettings">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="menuLoadSettingsLast">
<Properties>
<Property name="text" type="java.lang.String" value="Load from last time"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuLoadSettingsLastActionPerformed"/>
</Events>
</MenuItem>
<Component class="javax.swing.JPopupMenu$Separator" name="separator1">
</Component>
<MenuItem class="javax.swing.JMenuItem" name="menuLoadSettings1">
<Properties>
<Property name="text" type="java.lang.String" value="Load from config 1"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuLoadSettings1ActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="menuLoadSettings2">
<Properties>
<Property name="text" type="java.lang.String" value="Load from config 2"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuLoadSettings2ActionPerformed"/>
</Events>
</MenuItem>
<Component class="javax.swing.JPopupMenu$Separator" name="separator2">
</Component>
<MenuItem class="javax.swing.JMenuItem" name="menuLoadSettingsDefault">
<Properties>
<Property name="text" type="java.lang.String" value="Load default settings"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuLoadSettingsDefaultActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Container>
</NonVisualComponents>
<Properties> <Properties>
<Property name="title" type="java.lang.String" value="New Table"/> <Property name="title" type="java.lang.String" value="New Table"/>
</Properties> </Properties>
@ -26,15 +99,22 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0"> <Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<Component id="btnOK" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/> <Component id="btnSettingsLoad" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnSettingsSave" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="btnOK" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" pref="100" max="-2" attributes="0"/>
</Group> </Group>
<Component id="jSeparator2" alignment="1" max="32767" attributes="0"/> <Component id="jSeparator2" alignment="1" max="32767" attributes="0"/>
<Component id="player1Panel" alignment="0" pref="863" max="32767" attributes="0"/> <Component id="player1Panel" alignment="0" pref="863" max="32767" attributes="0"/>
<Component id="pnlOtherPlayers" alignment="1" max="32767" attributes="0"/> <Component id="pnlOtherPlayers" alignment="1" max="32767" attributes="0"/>
<Component id="jSeparator1" alignment="0" max="32767" attributes="0"/> <Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="lblName" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="lblName" alignment="0" min="-2" max="-2" attributes="0"/>
@ -55,10 +135,6 @@
<Component id="txtPassword" min="-2" pref="109" max="-2" attributes="0"/> <Component id="txtPassword" min="-2" pref="109" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="chkSpectatorsAllowed" min="-2" max="-2" attributes="0"/> <Component id="chkSpectatorsAllowed" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnPreviousConfiguration1" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnPreviousConfiguration2" min="-2" pref="50" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0"> <Group type="103" groupAlignment="1" max="-2" attributes="0">
@ -130,6 +206,9 @@
</Group> </Group>
</Group> </Group>
</Group> </Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0"> <Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
@ -150,14 +229,12 @@
<Component id="txtName" alignment="3" max="32767" attributes="0"/> <Component id="txtName" alignment="3" max="32767" attributes="0"/>
<Component id="lblName" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lblName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="103" alignment="0" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="cbTimeLimit" alignment="3" max="32767" attributes="0"/> <Component id="cbTimeLimit" alignment="3" max="32767" attributes="0"/>
<Component id="lbTimeLimit" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lbTimeLimit" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPassword" alignment="3" max="32767" attributes="0"/> <Component id="txtPassword" alignment="3" max="32767" attributes="0"/>
<Component id="chkSpectatorsAllowed" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="chkSpectatorsAllowed" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnPreviousConfiguration1" alignment="0" pref="26" max="32767" attributes="0"/>
<Component id="btnPreviousConfiguration2" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@ -182,6 +259,7 @@
<Group type="103" groupAlignment="1" attributes="0"> <Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="lblRange" min="-2" max="-2" attributes="0"/> <Component id="lblRange" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="cbRange" min="-2" max="-2" attributes="0"/> <Component id="cbRange" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" attributes="0"> <Group type="102" attributes="0">
@ -191,18 +269,22 @@
</Group> </Group>
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Component id="lblAttack" min="-2" max="-2" attributes="0"/> <Component id="lblAttack" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="cbAttackOption" min="-2" max="-2" attributes="0"/> <Component id="cbAttackOption" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Component id="lblSkillLevel" min="-2" max="-2" attributes="0"/> <Component id="lblSkillLevel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="cbSkillLevel" min="-2" max="-2" attributes="0"/> <Component id="cbSkillLevel" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Component id="lblNumWins" min="-2" max="-2" attributes="0"/> <Component id="lblNumWins" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="spnNumWins" min="-2" max="-2" attributes="0"/> <Component id="spnNumWins" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Component id="lblMullgian" min="-2" max="-2" attributes="0"/> <Component id="lblMullgian" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="cbMulligan" min="-2" max="-2" attributes="0"/> <Component id="cbMulligan" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" attributes="0"> <Group type="102" attributes="0">
@ -223,21 +305,24 @@
<EmptySpace min="-2" pref="16" max="-2" attributes="0"/> <EmptySpace min="-2" pref="16" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/> <Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="pnlOtherPlayers" pref="92" max="32767" attributes="0"/> <Component id="pnlOtherPlayers" pref="90" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/> <EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
<Component id="jSeparator1" min="-2" max="-2" attributes="0"/> <Component id="jSeparator1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCancel" alignment="3" min="-2" pref="30" max="-2" attributes="0"/>
<Component id="btnOK" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnOK" alignment="3" min="-2" pref="30" max="-2" attributes="0"/>
<Component id="btnSettingsLoad" alignment="3" min="-2" pref="30" max="-2" attributes="0"/>
<Component id="btnSettingsSave" alignment="3" min="-2" pref="30" max="-2" attributes="0"/>
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0"> <Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="201" max="-2" attributes="0"/> <EmptySpace min="-2" pref="201" max="-2" attributes="0"/>
<Component id="jSeparator3" min="-2" max="-2" attributes="0"/> <Component id="jSeparator3" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="169" max="32767" attributes="0"/> <EmptySpace pref="180" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</Group> </Group>
@ -264,10 +349,6 @@
</Component> </Component>
<Component class="javax.swing.JTextField" name="txtPassword"> <Component class="javax.swing.JTextField" name="txtPassword">
</Component> </Component>
<Component class="javax.swing.JButton" name="btnPreviousConfiguration1">
</Component>
<Component class="javax.swing.JButton" name="btnPreviousConfiguration2">
</Component>
<Component class="javax.swing.JLabel" name="lbDeckType"> <Component class="javax.swing.JLabel" name="lbDeckType">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Deck Type:"/> <Property name="text" type="java.lang.String" value="Deck Type:"/>
@ -394,9 +475,6 @@
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JSpinner" name="spnNumWins"> <Component class="javax.swing.JSpinner" name="spnNumWins">
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumWinsnumPlayersChanged"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JSeparator" name="jSeparator2"> <Component class="javax.swing.JSeparator" name="jSeparator2">
</Component> </Component>
@ -431,7 +509,7 @@
</Component> </Component>
<Component class="javax.swing.JButton" name="btnOK"> <Component class="javax.swing.JButton" name="btnOK">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="OK"/> <Property name="text" type="java.lang.String" value="Create"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOKActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOKActionPerformed"/>
@ -495,9 +573,6 @@
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JSpinner" name="spnMinimumRating"> <Component class="javax.swing.JSpinner" name="spnMinimumRating">
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnMinimumRatingnumPlayersChanged"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JCheckBox" name="chkRated"> <Component class="javax.swing.JCheckBox" name="chkRated">
<Properties> <Properties>
@ -505,5 +580,28 @@
<Property name="toolTipText" type="java.lang.String" value="Indicates if matche will be rated"/> <Property name="toolTipText" type="java.lang.String" value="Indicates if matche will be rated"/>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JButton" name="btnSettingsLoad">
<Properties>
<Property name="text" type="java.lang.String" value="Load..."/>
<Property name="toolTipText" type="java.lang.String" value="Load settings"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btnSettingsLoadMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnSettingsSave">
<Properties>
<Property name="text" type="java.lang.String" value="Save..."/>
<Property name="toolTipText" type="java.lang.String" value="Save settings"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="btnSettingsSaveMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="text" type="java.lang.String" value="Settings"/>
</Properties>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View file

@ -66,12 +66,20 @@ public class NewTableDialog extends MageDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
popupSaveSettings = new javax.swing.JPopupMenu();
menuSaveSettings1 = new javax.swing.JMenuItem();
menuSaveSettings2 = new javax.swing.JMenuItem();
popupLoadSettings = new javax.swing.JPopupMenu();
menuLoadSettingsLast = new javax.swing.JMenuItem();
separator1 = new javax.swing.JPopupMenu.Separator();
menuLoadSettings1 = new javax.swing.JMenuItem();
menuLoadSettings2 = new javax.swing.JMenuItem();
separator2 = new javax.swing.JPopupMenu.Separator();
menuLoadSettingsDefault = new javax.swing.JMenuItem();
lblName = new javax.swing.JLabel(); lblName = new javax.swing.JLabel();
txtName = new javax.swing.JTextField(); txtName = new javax.swing.JTextField();
lblPassword = new javax.swing.JLabel(); lblPassword = new javax.swing.JLabel();
txtPassword = new javax.swing.JTextField(); txtPassword = new javax.swing.JTextField();
btnPreviousConfiguration1 = new javax.swing.JButton();
btnPreviousConfiguration2 = new javax.swing.JButton();
lbDeckType = new javax.swing.JLabel(); lbDeckType = new javax.swing.JLabel();
cbDeckType = new javax.swing.JComboBox(); cbDeckType = new javax.swing.JComboBox();
lbTimeLimit = new javax.swing.JLabel(); lbTimeLimit = new javax.swing.JLabel();
@ -111,6 +119,62 @@ public class NewTableDialog extends MageDialog {
lblMinimumRating = new javax.swing.JLabel(); lblMinimumRating = new javax.swing.JLabel();
spnMinimumRating = new javax.swing.JSpinner(); spnMinimumRating = new javax.swing.JSpinner();
chkRated = new javax.swing.JCheckBox(); chkRated = new javax.swing.JCheckBox();
btnSettingsLoad = new javax.swing.JButton();
btnSettingsSave = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
menuSaveSettings1.setText("Save to config 1");
menuSaveSettings1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuSaveSettings1ActionPerformed(evt);
}
});
popupSaveSettings.add(menuSaveSettings1);
menuSaveSettings2.setText("Save to config 2");
menuSaveSettings2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuSaveSettings2ActionPerformed(evt);
}
});
popupSaveSettings.add(menuSaveSettings2);
menuLoadSettingsLast.setText("Load from last time");
menuLoadSettingsLast.setToolTipText("");
menuLoadSettingsLast.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuLoadSettingsLastActionPerformed(evt);
}
});
popupLoadSettings.add(menuLoadSettingsLast);
popupLoadSettings.add(separator1);
menuLoadSettings1.setText("Load from config 1");
menuLoadSettings1.setToolTipText("");
menuLoadSettings1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuLoadSettings1ActionPerformed(evt);
}
});
popupLoadSettings.add(menuLoadSettings1);
menuLoadSettings2.setText("Load from config 2");
menuLoadSettings2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuLoadSettings2ActionPerformed(evt);
}
});
popupLoadSettings.add(menuLoadSettings2);
popupLoadSettings.add(separator2);
menuLoadSettingsDefault.setText("Load default settings");
menuLoadSettingsDefault.setToolTipText("");
menuLoadSettingsDefault.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuLoadSettingsDefaultActionPerformed(evt);
}
});
popupLoadSettings.add(menuLoadSettingsDefault);
setTitle("New Table"); setTitle("New Table");
@ -175,12 +239,6 @@ public class NewTableDialog extends MageDialog {
lblNumWins.setText("Wins:"); lblNumWins.setText("Wins:");
lblNumWins.setToolTipText("How many games has a player to win to win the match."); lblNumWins.setToolTipText("How many games has a player to win to win the match.");
spnNumWins.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spnNumWinsnumPlayersChanged(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel1.setText("Player 1 (You)"); jLabel1.setText("Player 1 (You)");
@ -189,7 +247,7 @@ public class NewTableDialog extends MageDialog {
pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1)); pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1));
btnOK.setText("OK"); btnOK.setText("Create");
btnOK.addActionListener(new java.awt.event.ActionListener() { btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOKActionPerformed(evt); btnOKActionPerformed(evt);
@ -217,14 +275,26 @@ public class NewTableDialog extends MageDialog {
lblMinimumRating.setText("Minimum rating:"); lblMinimumRating.setText("Minimum rating:");
lblMinimumRating.setToolTipText("Players with rating less than this value can't join this table"); lblMinimumRating.setToolTipText("Players with rating less than this value can't join this table");
spnMinimumRating.addChangeListener(new javax.swing.event.ChangeListener() { chkRated.setText("Rated game");
public void stateChanged(javax.swing.event.ChangeEvent evt) { chkRated.setToolTipText("Indicates if matche will be rated");
spnMinimumRatingnumPlayersChanged(evt);
btnSettingsLoad.setText("Load...");
btnSettingsLoad.setToolTipText("Load settings");
btnSettingsLoad.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnSettingsLoadMouseClicked(evt);
} }
}); });
chkRated.setText("Rated game"); btnSettingsSave.setText("Save...");
chkRated.setToolTipText("Indicates if matche will be rated"); btnSettingsSave.setToolTipText("Save settings");
btnSettingsSave.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnSettingsSaveMouseClicked(evt);
}
});
jLabel3.setText("Settings");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
@ -234,14 +304,21 @@ public class NewTableDialog extends MageDialog {
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE) .addComponent(jLabel3)
.addComponent(btnOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)) .addComponent(btnSettingsLoad)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnSettingsSave)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jSeparator2) .addComponent(jSeparator2)
.addComponent(player1Panel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 863, Short.MAX_VALUE) .addComponent(player1Panel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 863, Short.MAX_VALUE)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblName) .addComponent(lblName)
@ -260,11 +337,7 @@ public class NewTableDialog extends MageDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkSpectatorsAllowed) .addComponent(chkSpectatorsAllowed))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPreviousConfiguration1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPreviousConfiguration2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cbDeckType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cbDeckType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@ -319,6 +392,7 @@ public class NewTableDialog extends MageDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkPlaneChase)) .addComponent(chkPlaneChase))
.addComponent(lblFreeMulligans)))) .addComponent(lblFreeMulligans))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap()) .addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
@ -339,9 +413,7 @@ public class NewTableDialog extends MageDialog {
.addComponent(lbTimeLimit) .addComponent(lbTimeLimit)
.addComponent(lblPassword) .addComponent(lblPassword)
.addComponent(txtPassword) .addComponent(txtPassword)
.addComponent(chkSpectatorsAllowed) .addComponent(chkSpectatorsAllowed)))
.addComponent(btnPreviousConfiguration1, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
.addComponent(btnPreviousConfiguration2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbDeckType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cbDeckType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -362,6 +434,7 @@ public class NewTableDialog extends MageDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblRange) .addComponent(lblRange)
.addGap(0, 0, 0)
.addComponent(cbRange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(cbRange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblNumPlayers) .addComponent(lblNumPlayers)
@ -369,15 +442,19 @@ public class NewTableDialog extends MageDialog {
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblAttack) .addComponent(lblAttack)
.addGap(0, 0, 0)
.addComponent(cbAttackOption, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(cbAttackOption, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblSkillLevel) .addComponent(lblSkillLevel)
.addGap(0, 0, 0)
.addComponent(cbSkillLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(cbSkillLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblNumWins) .addComponent(lblNumWins)
.addGap(0, 0, 0)
.addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblMullgian) .addComponent(lblMullgian)
.addGap(0, 0, 0)
.addComponent(cbMulligan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(cbMulligan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblFreeMulligans) .addComponent(lblFreeMulligans)
@ -394,19 +471,22 @@ public class NewTableDialog extends MageDialog {
.addGap(16, 16, 16) .addGap(16, 16, 16)
.addComponent(jLabel2) .addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE) .addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addGap(9, 9, 9) .addGap(9, 9, 9)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel) .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnOK)) .addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)) .addComponent(btnSettingsLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSettingsSave, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGap(201, 201, 201) .addGap(201, 201, 201)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(169, Short.MAX_VALUE))) .addContainerGap(180, Short.MAX_VALUE)))
); );
lblMullgian.getAccessibleContext().setAccessibleName("Mullgian"); lblMullgian.getAccessibleContext().setAccessibleName("Mullgian");
@ -421,41 +501,19 @@ public class NewTableDialog extends MageDialog {
}//GEN-LAST:event_btnCancelActionPerformed }//GEN-LAST:event_btnCancelActionPerformed
private void btnPreviousConfigurationActionPerformed(java.awt.event.ActionEvent evt, int i) {//GEN-FIRST:event_btnPreviousConfigurationActionPerformed private void btnPreviousConfigurationActionPerformed(java.awt.event.ActionEvent evt, int i) {//GEN-FIRST:event_btnPreviousConfigurationActionPerformed
currentSettingVersion = i;
setGameSettingsFromPrefs(currentSettingVersion);
}//GEN-LAST:event_btnPreviousConfigurationActionPerformed }//GEN-LAST:event_btnPreviousConfigurationActionPerformed
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
GameTypeView gameType = (GameTypeView) cbGameType.getSelectedItem();
MatchOptions options = new MatchOptions(this.txtName.getText(), gameType.getName(), false, 2); MatchOptions options = getMatchOptions();
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().orElseGet(() -> "");
options.setBannedUsers(IgnoreList.ignoreList(serverAddress));
if (!checkMatchOptions(options)) { if (!checkMatchOptions(options)) {
return; return;
} }
saveGameSettingsToPrefs(options, this.player1Panel.getDeckFile());
// save last used
onSaveSettings(0, options, this.player1Panel.getDeckFile());
// run
table = SessionHandler.createTable(roomId, options); table = SessionHandler.createTable(roomId, options);
if (table == null) { if (table == null) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE);
@ -503,13 +561,68 @@ public class NewTableDialog extends MageDialog {
createPlayers(numPlayers); createPlayers(numPlayers);
}//GEN-LAST:event_numPlayersChanged }//GEN-LAST:event_numPlayersChanged
private void spnNumWinsnumPlayersChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnNumWinsnumPlayersChanged private void btnSettingsSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSettingsSaveMouseClicked
// TODO add your handling code here: popupSaveSettings.show(evt.getComponent(), evt.getX(), evt.getY());
}//GEN-LAST:event_spnNumWinsnumPlayersChanged }//GEN-LAST:event_btnSettingsSaveMouseClicked
private void spnMinimumRatingnumPlayersChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnMinimumRatingnumPlayersChanged private void btnSettingsLoadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSettingsLoadMouseClicked
// TODO add your handling code here: popupLoadSettings.show(evt.getComponent(), evt.getX(), evt.getY());
}//GEN-LAST:event_spnMinimumRatingnumPlayersChanged }//GEN-LAST:event_btnSettingsLoadMouseClicked
private void menuSaveSettings2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSaveSettings2ActionPerformed
onSaveSettings(2);
}//GEN-LAST:event_menuSaveSettings2ActionPerformed
private void menuSaveSettings1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSaveSettings1ActionPerformed
onSaveSettings(1);
}//GEN-LAST:event_menuSaveSettings1ActionPerformed
private void menuLoadSettingsLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuLoadSettingsLastActionPerformed
onLoadSettings(0);
}//GEN-LAST:event_menuLoadSettingsLastActionPerformed
private void menuLoadSettings1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuLoadSettings1ActionPerformed
onLoadSettings(1);
}//GEN-LAST:event_menuLoadSettings1ActionPerformed
private void menuLoadSettings2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuLoadSettings2ActionPerformed
onLoadSettings(2);
}//GEN-LAST:event_menuLoadSettings2ActionPerformed
private void menuLoadSettingsDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuLoadSettingsDefaultActionPerformed
onLoadSettings(-1);
}//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().orElseGet(() -> "");
options.setBannedUsers(IgnoreList.ignoreList(serverAddress));
return options;
}
/** /**
* Checks about not valid game option combinations and shows an error * Checks about not valid game option combinations and shows an error
@ -625,8 +738,7 @@ public class NewTableDialog extends MageDialog {
private void handleError(Exception ex) { private void handleError(Exception ex) {
logger.fatal("Error loading deck", ex); logger.fatal("Error loading deck", ex);
//JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error loading deck.", "Error", JOptionPane.ERROR_MESSAGE); MageFrame.getInstance().showErrorDialog("Error loading deck", ex.getMessage());
MageFrame.getInstance().showErrorDialog("Error loading deck.", ex.getMessage());
} }
public void showDialog(UUID roomId) { public void showDialog(UUID roomId) {
@ -651,8 +763,10 @@ public class NewTableDialog extends MageDialog {
setGameOptions(); setGameOptions();
this.setLocation(150, 100); this.setLocation(150, 100);
} }
currentSettingVersion = 0;
setGameSettingsFromPrefs(currentSettingVersion); // auto-load last settings
onLoadSettings(0);
this.setVisible(true); this.setVisible(true);
} }
@ -674,27 +788,23 @@ public class NewTableDialog extends MageDialog {
} }
} }
/** private void onLoadSettings(int version) {
* set the table settings from java prefs
*/
int currentSettingVersion = 0;
private void setGameSettingsFromPrefs(int version) {
currentSettingVersion = version;
String versionStr = ""; String versionStr = "";
switch (currentSettingVersion) { switch (version) {
case -1:
versionStr = "-1"; // default (empty)
case 1: case 1:
versionStr = "1"; versionStr = "1";
btnPreviousConfiguration1.requestFocus();
break; break;
case 2: case 2:
versionStr = "2"; versionStr = "2";
btnPreviousConfiguration2.requestFocus();
break; break;
default: default:
btnPreviousConfiguration2.getParent().requestFocus(); versionStr = "";
break; break;
} }
txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NAME + versionStr, "Game")); txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NAME + versionStr, "Game"));
txtPassword.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD + versionStr, "")); txtPassword.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD + versionStr, ""));
@ -756,23 +866,29 @@ public class NewTableDialog extends MageDialog {
this.spnQuitRatio.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_QUIT_RATIO + versionStr, "100"))); this.spnQuitRatio.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_QUIT_RATIO + versionStr, "100")));
this.spnMinimumRating.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_MINIMUM_RATING + versionStr, "0"))); this.spnMinimumRating.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_MINIMUM_RATING + versionStr, "0")));
this.spnEdhPowerLevel.setValue(0); this.spnEdhPowerLevel.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_EDH_POWER_LEVEL + versionStr, "0")));
} }
/** private void onSaveSettings(int version) {
* Save the settings to java prefs to reload it next time the dialog will be MatchOptions options = getMatchOptions();
* created onSaveSettings(version, options, this.player1Panel.getDeckFile());
*
* @param options
* @param deckFile
*/
private void saveGameSettingsToPrefs(MatchOptions options, String deckFile) {
String versionStr = "";
if (currentSettingVersion == 1) {
versionStr = "1";
} else if (currentSettingVersion == 2) {
versionStr = "2";
} }
private void onSaveSettings(int version, MatchOptions options, String deckFile) {
String versionStr = "";
switch (version) {
case 1:
versionStr = "1";
break;
case 2:
versionStr = "2";
break;
default:
versionStr = "";
break;
}
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NAME + versionStr, options.getName()); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NAME + versionStr, options.getName());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD + versionStr, options.getPassword()); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD + versionStr, options.getPassword());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_DECK_TYPE + versionStr, options.getDeckType()); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_DECK_TYPE + versionStr, options.getDeckType());
@ -792,6 +908,8 @@ public class NewTableDialog extends MageDialog {
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PLANECHASE + versionStr, options.isPlaneChase() ? "Yes" : "No"); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PLANECHASE + versionStr, options.isPlaneChase() ? "Yes" : "No");
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_QUIT_RATIO + versionStr, Integer.toString(options.getQuitRatio())); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_QUIT_RATIO + versionStr, Integer.toString(options.getQuitRatio()));
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_MINIMUM_RATING + versionStr, Integer.toString(options.getMinimumRating())); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_MINIMUM_RATING + versionStr, Integer.toString(options.getMinimumRating()));
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_EDH_POWER_LEVEL + versionStr, Integer.toString(options.getEdhPowerLevel()));
StringBuilder playerTypesString = new StringBuilder(); StringBuilder playerTypesString = new StringBuilder();
for (Object player : players) { for (Object player : players) {
if (playerTypesString.length() > 0) { if (playerTypesString.length() > 0) {
@ -806,8 +924,8 @@ public class NewTableDialog extends MageDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel; private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOK; private javax.swing.JButton btnOK;
private javax.swing.JButton btnPreviousConfiguration1; private javax.swing.JButton btnSettingsLoad;
private javax.swing.JButton btnPreviousConfiguration2; private javax.swing.JButton btnSettingsSave;
private javax.swing.JComboBox cbAttackOption; private javax.swing.JComboBox cbAttackOption;
private javax.swing.JComboBox cbDeckType; private javax.swing.JComboBox cbDeckType;
private javax.swing.JComboBox cbGameType; private javax.swing.JComboBox cbGameType;
@ -821,6 +939,7 @@ public class NewTableDialog extends MageDialog {
private javax.swing.JCheckBox chkSpectatorsAllowed; private javax.swing.JCheckBox chkSpectatorsAllowed;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2; private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3; private javax.swing.JSeparator jSeparator3;
@ -839,8 +958,18 @@ public class NewTableDialog extends MageDialog {
private javax.swing.JLabel lblQuitRatio; private javax.swing.JLabel lblQuitRatio;
private javax.swing.JLabel lblRange; private javax.swing.JLabel lblRange;
private javax.swing.JLabel lblSkillLevel; private javax.swing.JLabel lblSkillLevel;
private javax.swing.JMenuItem menuLoadSettings1;
private javax.swing.JMenuItem menuLoadSettings2;
private javax.swing.JMenuItem menuLoadSettingsDefault;
private javax.swing.JMenuItem menuLoadSettingsLast;
private javax.swing.JMenuItem menuSaveSettings1;
private javax.swing.JMenuItem menuSaveSettings2;
private mage.client.table.NewPlayerPanel player1Panel; private mage.client.table.NewPlayerPanel player1Panel;
private javax.swing.JPanel pnlOtherPlayers; private javax.swing.JPanel pnlOtherPlayers;
private javax.swing.JPopupMenu popupLoadSettings;
private javax.swing.JPopupMenu popupSaveSettings;
private javax.swing.JPopupMenu.Separator separator1;
private javax.swing.JPopupMenu.Separator separator2;
private javax.swing.JSpinner spnEdhPowerLevel; private javax.swing.JSpinner spnEdhPowerLevel;
private javax.swing.JSpinner spnFreeMulligans; private javax.swing.JSpinner spnFreeMulligans;
private javax.swing.JSpinner spnMinimumRating; private javax.swing.JSpinner spnMinimumRating;

View file

@ -203,6 +203,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_NEW_TABLE_QUIT_RATIO = "newTableQuitRatio"; public static final String KEY_NEW_TABLE_QUIT_RATIO = "newTableQuitRatio";
public static final String KEY_NEW_TABLE_MINIMUM_RATING = "newTableMinimumRating"; public static final String KEY_NEW_TABLE_MINIMUM_RATING = "newTableMinimumRating";
public static final String KEY_NEW_TABLE_RATED = "newTableRated"; public static final String KEY_NEW_TABLE_RATED = "newTableRated";
public static final String KEY_NEW_TABLE_EDH_POWER_LEVEL = "newTableEdhPowerLevel";
// pref setting for new tournament dialog // pref setting for new tournament dialog
public static final String KEY_NEW_TOURNAMENT_NAME = "newTournamentName"; public static final String KEY_NEW_TOURNAMENT_NAME = "newTournamentName";