mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Fixed some panel state bugs.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -6740,6 +6740,7 @@ src/forge/properties/Preferences.java svneol=native#text/plain
|
|||||||
src/forge/properties/SavePreferencesListener.java svneol=native#text/plain
|
src/forge/properties/SavePreferencesListener.java svneol=native#text/plain
|
||||||
src/forge/quest/Gui_QuestOptions.java svneol=native#text/plain
|
src/forge/quest/Gui_QuestOptions.java svneol=native#text/plain
|
||||||
src/forge/quest/Gui_Quest_Assignments.java svneol=native#text/plain
|
src/forge/quest/Gui_Quest_Assignments.java svneol=native#text/plain
|
||||||
|
src/forge/quest/QuestAbstractPanel.java svneol=native#text/plain
|
||||||
src/forge/quest/QuestFrame.java svneol=native#text/plain
|
src/forge/quest/QuestFrame.java svneol=native#text/plain
|
||||||
src/forge/quest/QuestMainPanel.java svneol=native#text/plain
|
src/forge/quest/QuestMainPanel.java svneol=native#text/plain
|
||||||
src/forge/quest/QuestOpponent.java svneol=native#text/plain
|
src/forge/quest/QuestOpponent.java svneol=native#text/plain
|
||||||
|
|||||||
7
src/forge/quest/QuestAbstractPanel.java
Normal file
7
src/forge/quest/QuestAbstractPanel.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package forge.quest;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public abstract class QuestAbstractPanel extends JPanel {
|
||||||
|
public abstract void refreshState();
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.CardLayout;
|
import java.awt.CardLayout;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.HeadlessException;
|
import java.awt.HeadlessException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class QuestFrame extends JFrame {
|
public class QuestFrame extends JFrame {
|
||||||
private static final long serialVersionUID = -2832625381531838412L;
|
private static final long serialVersionUID = -2832625381531838412L;
|
||||||
@@ -21,6 +23,8 @@ public class QuestFrame extends JFrame {
|
|||||||
public static final String MAIN_PANEL = "Main";
|
public static final String MAIN_PANEL = "Main";
|
||||||
public static final String BAZAAR_PANEL = "Bazaar";
|
public static final String BAZAAR_PANEL = "Bazaar";
|
||||||
|
|
||||||
|
Map<String, QuestAbstractPanel> subPanelMap = new HashMap<String, QuestAbstractPanel>();
|
||||||
|
|
||||||
public QuestFrame() throws HeadlessException {
|
public QuestFrame() throws HeadlessException {
|
||||||
this.setTitle("Quest Mode");
|
this.setTitle("Quest Mode");
|
||||||
|
|
||||||
@@ -28,8 +32,14 @@ public class QuestFrame extends JFrame {
|
|||||||
visiblePanel.setBorder(new EmptyBorder(2,2,2,2));
|
visiblePanel.setBorder(new EmptyBorder(2,2,2,2));
|
||||||
questLayout = new CardLayout();
|
questLayout = new CardLayout();
|
||||||
visiblePanel.setLayout(questLayout);
|
visiblePanel.setLayout(questLayout);
|
||||||
visiblePanel.add(new QuestMainPanel(this), MAIN_PANEL);
|
|
||||||
visiblePanel.add(new QuestBazaarPanel(this), BAZAAR_PANEL);
|
QuestAbstractPanel newPanel = new QuestMainPanel(this);
|
||||||
|
visiblePanel.add(newPanel, MAIN_PANEL);
|
||||||
|
subPanelMap.put(MAIN_PANEL, newPanel);
|
||||||
|
|
||||||
|
newPanel = new QuestBazaarPanel(this);
|
||||||
|
visiblePanel.add(newPanel, BAZAAR_PANEL);
|
||||||
|
subPanelMap.put(BAZAAR_PANEL, newPanel);
|
||||||
|
|
||||||
|
|
||||||
this.getContentPane().setLayout(new BorderLayout());
|
this.getContentPane().setLayout(new BorderLayout());
|
||||||
@@ -46,6 +56,7 @@ public class QuestFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void showPane(String paneName){
|
public void showPane(String paneName){
|
||||||
|
subPanelMap.get(paneName).refreshState();
|
||||||
questLayout.show(visiblePanel, paneName);
|
questLayout.show(visiblePanel, paneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
//presumes AllZone.QuestData is not null
|
//presumes AllZone.QuestData is not null
|
||||||
|
|
||||||
//AllZone.QuestData should be set by Gui_QuestOptions
|
//AllZone.QuestData should be set by Gui_QuestOptions
|
||||||
public class QuestMainPanel extends JPanel {
|
public class QuestMainPanel extends QuestAbstractPanel {
|
||||||
private QuestData questData;
|
private QuestData questData;
|
||||||
|
|
||||||
private QuestFrame mainFrame;
|
private QuestFrame mainFrame;
|
||||||
@@ -35,6 +35,7 @@ public class QuestMainPanel extends JPanel {
|
|||||||
JComboBox deckComboBox = new JComboBox();
|
JComboBox deckComboBox = new JComboBox();
|
||||||
|
|
||||||
JButton questButton = new JButton("Quest");
|
JButton questButton = new JButton("Quest");
|
||||||
|
JButton playButton = new JButton("Play");
|
||||||
|
|
||||||
QuestOpponent selectedOpponent = null;
|
QuestOpponent selectedOpponent = null;
|
||||||
|
|
||||||
@@ -143,7 +144,6 @@ public class QuestMainPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
questButton.addActionListener(new ActionListener() {
|
questButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
QuestMainPanel.this.showQuests();
|
QuestMainPanel.this.showQuests();
|
||||||
@@ -154,7 +154,6 @@ public class QuestMainPanel extends JPanel {
|
|||||||
questButton.setPreferredSize(new Dimension(0, 60));
|
questButton.setPreferredSize(new Dimension(0, 60));
|
||||||
|
|
||||||
|
|
||||||
JButton playButton = new JButton("Play");
|
|
||||||
playButton.addActionListener(new ActionListener() {
|
playButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
QuestMainPanel.this.launchGame();
|
QuestMainPanel.this.launchGame();
|
||||||
@@ -213,8 +212,6 @@ public class QuestMainPanel extends JPanel {
|
|||||||
opponent.addMouseListener(new OpponentAdapter(opponent));
|
opponent.addMouseListener(new OpponentAdapter(opponent));
|
||||||
|
|
||||||
GuiUtils.addGap(opponentPanel, 3);
|
GuiUtils.addGap(opponentPanel, 3);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
opponentPanel.setAlignmentX(LEFT_ALIGNMENT);
|
opponentPanel.setAlignmentX(LEFT_ALIGNMENT);
|
||||||
@@ -228,6 +225,13 @@ public class QuestMainPanel extends JPanel {
|
|||||||
JLabel deckLabel = new JLabel("Use Deck");
|
JLabel deckLabel = new JLabel("Use Deck");
|
||||||
deckPanel.add(deckLabel);
|
deckPanel.add(deckLabel);
|
||||||
GuiUtils.addGap(deckPanel);
|
GuiUtils.addGap(deckPanel);
|
||||||
|
|
||||||
|
this.deckComboBox.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
playButton.setEnabled(canGameBeLaunched());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
deckPanel.add(this.deckComboBox);
|
deckPanel.add(this.deckComboBox);
|
||||||
GuiUtils.addGap(deckPanel);
|
GuiUtils.addGap(deckPanel);
|
||||||
|
|
||||||
@@ -248,8 +252,32 @@ public class QuestMainPanel extends JPanel {
|
|||||||
if (questData.getMode().equals(QuestData.FANTASY)) {
|
if (questData.getMode().equals(QuestData.FANTASY)) {
|
||||||
JPanel petPanel = new JPanel();
|
JPanel petPanel = new JPanel();
|
||||||
petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS));
|
petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
|
this.petCheckBox.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (petCheckBox.isSelected()) {
|
||||||
|
questData.setSelectedPet((String) petComboBox.getSelectedItem());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
questData.setSelectedPet("");
|
||||||
|
}
|
||||||
|
|
||||||
|
petComboBox.setEnabled(petCheckBox.isSelected());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
petPanel.add(this.petCheckBox);
|
petPanel.add(this.petCheckBox);
|
||||||
GuiUtils.addGap(petPanel);
|
GuiUtils.addGap(petPanel);
|
||||||
|
this.petComboBox.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (petCheckBox.isSelected()) {
|
||||||
|
questData.setSelectedPet((String) petComboBox.getSelectedItem());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
questData.setSelectedPet("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
petPanel.add(this.petComboBox);
|
petPanel.add(this.petComboBox);
|
||||||
mainPanel.add(petPanel);
|
mainPanel.add(petPanel);
|
||||||
petPanel.setMaximumSize(petPanel.getPreferredSize());
|
petPanel.setMaximumSize(petPanel.getPreferredSize());
|
||||||
@@ -289,6 +317,8 @@ public class QuestMainPanel extends JPanel {
|
|||||||
|
|
||||||
questButton.setEnabled(shouldQuestsBeEnabled());
|
questButton.setEnabled(shouldQuestsBeEnabled());
|
||||||
|
|
||||||
|
playButton.setEnabled(canGameBeLaunched());
|
||||||
|
|
||||||
if (questData.getMode().equals(QuestData.FANTASY)) {
|
if (questData.getMode().equals(QuestData.FANTASY)) {
|
||||||
lifeLabel.setText("Starting Life: " + questData.getLife());
|
lifeLabel.setText("Starting Life: " + questData.getLife());
|
||||||
petComboBox.removeAllItems();
|
petComboBox.removeAllItems();
|
||||||
@@ -308,6 +338,15 @@ public class QuestMainPanel extends JPanel {
|
|||||||
petComboBox.setEnabled(false);
|
petComboBox.setEnabled(false);
|
||||||
petCheckBox.setEnabled(false);
|
petCheckBox.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (questData.getSelectedPet().equals("")) {
|
||||||
|
petCheckBox.setSelected(false);
|
||||||
|
petComboBox.setEnabled(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
petCheckBox.setSelected(true);
|
||||||
|
petComboBox.setSelectedItem(questData.getSelectedPet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,10 +444,15 @@ public class QuestMainPanel extends JPanel {
|
|||||||
AllZone.GameAction.newGame(human, computer);
|
AllZone.GameAction.newGame(human, computer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (petCheckBox.isSelected()) {
|
||||||
Object pet = petComboBox.getSelectedItem();
|
Object pet = petComboBox.getSelectedItem();
|
||||||
if (pet != null) {
|
if (!pet.equals("")) {
|
||||||
questData.setSelectedPet(pet.toString());
|
questData.setSelectedPet(pet.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
questData.setSelectedPet("");
|
||||||
|
}
|
||||||
|
|
||||||
CardList hCl = QuestUtil.getHumanPlantAndPet(questData);
|
CardList hCl = QuestUtil.getHumanPlantAndPet(questData);
|
||||||
int hLife = QuestUtil.getLife(questData);
|
int hLife = QuestUtil.getLife(questData);
|
||||||
@@ -425,7 +469,7 @@ public class QuestMainPanel extends JPanel {
|
|||||||
|
|
||||||
private String getSelectedOpponent() {
|
private String getSelectedOpponent() {
|
||||||
if (selectedOpponent == null) {
|
if (selectedOpponent == null) {
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectedOpponent.getName();
|
return selectedOpponent.getName();
|
||||||
@@ -471,7 +515,18 @@ public class QuestMainPanel extends JPanel {
|
|||||||
opponent.setSelected(true);
|
opponent.setSelected(true);
|
||||||
|
|
||||||
selectedOpponent = opponent;
|
selectedOpponent = opponent;
|
||||||
|
playButton.setEnabled(canGameBeLaunched());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean canGameBeLaunched() {
|
||||||
|
return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) ||
|
||||||
|
getSelectedOpponent() == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshState() {
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package forge.quest.bazaar;
|
package forge.quest.bazaar;
|
||||||
|
|
||||||
|
import forge.quest.QuestAbstractPanel;
|
||||||
import forge.quest.QuestFrame;
|
import forge.quest.QuestFrame;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -13,7 +14,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class QuestBazaarPanel extends JPanel{
|
public class QuestBazaarPanel extends QuestAbstractPanel{
|
||||||
private static final long serialVersionUID = 1418913010051869222L;
|
private static final long serialVersionUID = 1418913010051869222L;
|
||||||
|
|
||||||
QuestFrame mainFrame;
|
QuestFrame mainFrame;
|
||||||
@@ -124,4 +125,8 @@ public class QuestBazaarPanel extends JPanel{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshState() {
|
||||||
|
refreshLastInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user