From 1b79827b2dafef528a749327bfeaf943e967f2e9 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 23 Mar 2019 06:54:17 +0400 Subject: [PATCH] * UI: added save/load/reset game settings for new table dialog; Fixed that edh power level don't saves; --- .../java/mage/client/dialog/MageDialog.java | 3 +- .../mage/client/dialog/NewTableDialog.form | 298 ++++++++---- .../mage/client/dialog/NewTableDialog.java | 451 +++++++++++------- .../mage/client/dialog/PreferencesDialog.java | 1 + 4 files changed, 491 insertions(+), 262 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java index 334422f1bbb..c4bae193bb7 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java @@ -129,7 +129,8 @@ public class MageDialog extends javax.swing.JInternalFrame { // need popup clicks and mouse wheel (for out of bound actions) if (!allowedEvent) { 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); allowedEvent = true; } diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form index d55885f2fe6..335cf6df01f 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form @@ -1,6 +1,79 @@
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -26,108 +99,114 @@ - - + - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + + + + + + + + - + - + - + - + - + + + + + + + - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -150,14 +229,12 @@ - + - - @@ -182,6 +259,7 @@ + @@ -191,18 +269,22 @@ + + + + @@ -223,21 +305,24 @@ - + - - + + + + + - + - + @@ -264,10 +349,6 @@ - - - - @@ -394,9 +475,6 @@ - - - @@ -431,7 +509,7 @@ - + @@ -495,9 +573,6 @@ - - - @@ -505,5 +580,28 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java index 938038aebbb..146931b50a3 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java @@ -66,12 +66,20 @@ public class NewTableDialog extends MageDialog { // //GEN-BEGIN: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(); txtName = new javax.swing.JTextField(); lblPassword = new javax.swing.JLabel(); txtPassword = new javax.swing.JTextField(); - btnPreviousConfiguration1 = new javax.swing.JButton(); - btnPreviousConfiguration2 = new javax.swing.JButton(); lbDeckType = new javax.swing.JLabel(); cbDeckType = new javax.swing.JComboBox(); lbTimeLimit = new javax.swing.JLabel(); @@ -111,6 +119,62 @@ public class NewTableDialog extends MageDialog { lblMinimumRating = new javax.swing.JLabel(); spnMinimumRating = new javax.swing.JSpinner(); 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"); @@ -175,12 +239,6 @@ public class NewTableDialog extends MageDialog { lblNumWins.setText("Wins:"); 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.setText("Player 1 (You)"); @@ -189,7 +247,7 @@ public class NewTableDialog extends MageDialog { pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1)); - btnOK.setText("OK"); + btnOK.setText("Create"); btnOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnOKActionPerformed(evt); @@ -217,14 +275,26 @@ public class NewTableDialog extends MageDialog { lblMinimumRating.setText("Minimum rating:"); lblMinimumRating.setToolTipText("Players with rating less than this value can't join this table"); - spnMinimumRating.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - spnMinimumRatingnumPlayersChanged(evt); + chkRated.setText("Rated game"); + chkRated.setToolTipText("Indicates if matche will be rated"); + + 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"); - chkRated.setToolTipText("Indicates if matche will be rated"); + btnSettingsSave.setText("Save..."); + 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()); getContentPane().setLayout(layout); @@ -234,91 +304,95 @@ public class NewTableDialog extends MageDialog { .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(btnOK) + .addComponent(jLabel3) .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(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(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lblName) - .addComponent(lbDeckType) - .addComponent(lblGameType)) - .addGap(6, 6, 6) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbTimeLimit) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cbTimeLimit, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lblPassword) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .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.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(cbDeckType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cbGameType, 0, 270, Short.MAX_VALUE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblName) + .addComponent(lbDeckType) + .addComponent(lblGameType)) + .addGap(6, 6, 6) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lbTimeLimit) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cbTimeLimit, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lblPassword) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(chkSpectatorsAllowed)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(cbDeckType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cbGameType, 0, 270, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(chkRollbackTurnsAllowed) + .addGroup(layout.createSequentialGroup() + .addComponent(chkRated) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lblMinimumRating) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spnMinimumRating, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lblQuitRatio) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spnQuitRatio, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lblEdhPowerLevel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spnEdhPowerLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))))) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblNumPlayers) + .addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(chkRollbackTurnsAllowed) - .addGroup(layout.createSequentialGroup() - .addComponent(chkRated) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lblMinimumRating) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spnMinimumRating, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lblQuitRatio) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spnQuitRatio, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lblEdhPowerLevel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spnEdhPowerLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))))) - .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lblNumPlayers) - .addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lblRange) - .addComponent(cbRange, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(8, 8, 8) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(cbAttackOption, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lblAttack)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(cbSkillLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lblSkillLevel)) - .addGap(4, 4, 4) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lblNumWins)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(cbMulligan, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lblMullgian)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(spnFreeMulligans, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblRange) + .addComponent(cbRange, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(8, 8, 8) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(cbAttackOption, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblAttack)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(chkPlaneChase)) - .addComponent(lblFreeMulligans)))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(cbSkillLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblSkillLevel)) + .addGap(4, 4, 4) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblNumWins)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(cbMulligan, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblMullgian)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(spnFreeMulligans, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(chkPlaneChase)) + .addComponent(lblFreeMulligans)))) + .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -339,9 +413,7 @@ public class NewTableDialog extends MageDialog { .addComponent(lbTimeLimit) .addComponent(lblPassword) .addComponent(txtPassword) - .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))) + .addComponent(chkSpectatorsAllowed))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .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) @@ -362,6 +434,7 @@ public class NewTableDialog extends MageDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(lblRange) + .addGap(0, 0, 0) .addComponent(cbRange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .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)) .addGroup(layout.createSequentialGroup() .addComponent(lblAttack) + .addGap(0, 0, 0) .addComponent(cbAttackOption, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(lblSkillLevel) + .addGap(0, 0, 0) .addComponent(cbSkillLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(lblNumWins) + .addGap(0, 0, 0) .addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(lblMullgian) + .addGap(0, 0, 0) .addComponent(cbMulligan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(lblFreeMulligans) @@ -394,19 +471,22 @@ public class NewTableDialog extends MageDialog { .addGap(16, 16, 16) .addComponent(jLabel2) .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) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(btnCancel) - .addComponent(btnOK)) - .addGap(0, 0, 0)) + .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .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.createSequentialGroup() .addGap(201, 201, 201) .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"); @@ -421,41 +501,19 @@ public class NewTableDialog extends MageDialog { }//GEN-LAST:event_btnCancelActionPerformed private void btnPreviousConfigurationActionPerformed(java.awt.event.ActionEvent evt, int i) {//GEN-FIRST:event_btnPreviousConfigurationActionPerformed - currentSettingVersion = i; - setGameSettingsFromPrefs(currentSettingVersion); }//GEN-LAST:event_btnPreviousConfigurationActionPerformed 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); - 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)); + + MatchOptions options = getMatchOptions(); if (!checkMatchOptions(options)) { return; } - saveGameSettingsToPrefs(options, this.player1Panel.getDeckFile()); + // 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); @@ -503,13 +561,68 @@ public class NewTableDialog extends MageDialog { createPlayers(numPlayers); }//GEN-LAST:event_numPlayersChanged - private void spnNumWinsnumPlayersChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnNumWinsnumPlayersChanged - // TODO add your handling code here: - }//GEN-LAST:event_spnNumWinsnumPlayersChanged + private void btnSettingsSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSettingsSaveMouseClicked + popupSaveSettings.show(evt.getComponent(), evt.getX(), evt.getY()); + }//GEN-LAST:event_btnSettingsSaveMouseClicked - private void spnMinimumRatingnumPlayersChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnMinimumRatingnumPlayersChanged - // TODO add your handling code here: - }//GEN-LAST:event_spnMinimumRatingnumPlayersChanged + private void btnSettingsLoadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSettingsLoadMouseClicked + popupLoadSettings.show(evt.getComponent(), evt.getX(), evt.getY()); + }//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 @@ -625,8 +738,7 @@ public class NewTableDialog extends MageDialog { private void handleError(Exception 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) { @@ -651,8 +763,10 @@ public class NewTableDialog extends MageDialog { setGameOptions(); this.setLocation(150, 100); } - currentSettingVersion = 0; - setGameSettingsFromPrefs(currentSettingVersion); + + // auto-load last settings + onLoadSettings(0); + this.setVisible(true); } @@ -674,27 +788,23 @@ public class NewTableDialog extends MageDialog { } } - /** - * set the table settings from java prefs - */ - int currentSettingVersion = 0; + private void onLoadSettings(int version) { - private void setGameSettingsFromPrefs(int version) { - currentSettingVersion = version; String versionStr = ""; - switch (currentSettingVersion) { + switch (version) { + case -1: + versionStr = "-1"; // default (empty) case 1: versionStr = "1"; - btnPreviousConfiguration1.requestFocus(); break; case 2: versionStr = "2"; - btnPreviousConfiguration2.requestFocus(); break; default: - btnPreviousConfiguration2.getParent().requestFocus(); + versionStr = ""; break; } + txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NAME + versionStr, "Game")); 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.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"))); } - /** - * Save the settings to java prefs to reload it next time the dialog will be - * created - * - * @param options - * @param deckFile - */ - private void saveGameSettingsToPrefs(MatchOptions options, String deckFile) { + private void onSaveSettings(int version) { + MatchOptions options = getMatchOptions(); + onSaveSettings(version, options, this.player1Panel.getDeckFile()); + } + + private void onSaveSettings(int version, MatchOptions options, String deckFile) { + String versionStr = ""; - if (currentSettingVersion == 1) { - versionStr = "1"; - } else if (currentSettingVersion == 2) { - versionStr = "2"; + 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_PASSWORD + versionStr, options.getPassword()); 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_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_EDH_POWER_LEVEL + versionStr, Integer.toString(options.getEdhPowerLevel())); + StringBuilder playerTypesString = new StringBuilder(); for (Object player : players) { if (playerTypesString.length() > 0) { @@ -806,8 +924,8 @@ public class NewTableDialog extends MageDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCancel; private javax.swing.JButton btnOK; - private javax.swing.JButton btnPreviousConfiguration1; - private javax.swing.JButton btnPreviousConfiguration2; + private javax.swing.JButton btnSettingsLoad; + private javax.swing.JButton btnSettingsSave; private javax.swing.JComboBox cbAttackOption; private javax.swing.JComboBox cbDeckType; private javax.swing.JComboBox cbGameType; @@ -821,6 +939,7 @@ public class NewTableDialog extends MageDialog { private javax.swing.JCheckBox chkSpectatorsAllowed; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JSeparator jSeparator3; @@ -839,8 +958,18 @@ public class NewTableDialog extends MageDialog { private javax.swing.JLabel lblQuitRatio; private javax.swing.JLabel lblRange; 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 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 spnFreeMulligans; private javax.swing.JSpinner spnMinimumRating; diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index 361a8d6b052..1717071b982 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -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_MINIMUM_RATING = "newTableMinimumRating"; 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 public static final String KEY_NEW_TOURNAMENT_NAME = "newTournamentName";