mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Created Quest panel.
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -6779,7 +6779,8 @@ src/forge/quest/bazaar/QuestNurseryStall.java svneol=native#text/plain
|
||||
src/forge/quest/bazaar/QuestPetStall.java svneol=native#text/plain
|
||||
src/forge/quest/main/QuestMainPanel.java svneol=native#text/plain
|
||||
src/forge/quest/main/QuestOpponent.java svneol=native#text/plain
|
||||
src/forge/quest/quests/Gui_Quest_Assignments.java svneol=native#text/plain
|
||||
src/forge/quest/quests/QuestQuestsPanel.java svneol=native#text/plain
|
||||
src/forge/quest/quests/QuestQuestsReader.java svneol=native#text/plain
|
||||
src/org/jdesktop/beans/AbstractBean.java svneol=native#text/plain
|
||||
src/org/jdesktop/swingworker/AccumulativeRunnable.java -text svneol=native#text/plain
|
||||
src/org/jdesktop/swingworker/SwingPropertyChangeSupport.java -text svneol=native#text/plain
|
||||
|
||||
@@ -3,5 +3,11 @@ package forge.quest;
|
||||
import javax.swing.*;
|
||||
|
||||
public abstract class QuestAbstractPanel extends JPanel {
|
||||
public QuestFrame mainFrame;
|
||||
|
||||
protected QuestAbstractPanel(QuestFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
}
|
||||
|
||||
public abstract void refreshState();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import forge.QuestData;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.quest.bazaar.QuestBazaarPanel;
|
||||
import forge.quest.main.QuestMainPanel;
|
||||
import forge.quest.quests.QuestQuestsPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@@ -24,6 +25,7 @@ public class QuestFrame extends JFrame {
|
||||
|
||||
public static final String MAIN_PANEL = "Main";
|
||||
public static final String BAZAAR_PANEL = "Bazaar";
|
||||
private static final String QUESTS_PANEL = "Quests";
|
||||
|
||||
Map<String, QuestAbstractPanel> subPanelMap = new HashMap<String, QuestAbstractPanel>();
|
||||
|
||||
@@ -43,6 +45,10 @@ public class QuestFrame extends JFrame {
|
||||
visiblePanel.add(newPanel, BAZAAR_PANEL);
|
||||
subPanelMap.put(BAZAAR_PANEL, newPanel);
|
||||
|
||||
newPanel = new QuestQuestsPanel(this);
|
||||
visiblePanel.add(newPanel, QUESTS_PANEL);
|
||||
subPanelMap.put(QUESTS_PANEL, newPanel);
|
||||
|
||||
|
||||
this.getContentPane().setLayout(new BorderLayout());
|
||||
this.getContentPane().add(visiblePanel, BorderLayout.CENTER);
|
||||
@@ -61,11 +67,27 @@ public class QuestFrame extends JFrame {
|
||||
|
||||
|
||||
|
||||
public void showPane(String paneName){
|
||||
private void showPane(String paneName){
|
||||
subPanelMap.get(paneName).refreshState();
|
||||
questLayout.show(visiblePanel, paneName);
|
||||
}
|
||||
|
||||
public void showMainPane(){
|
||||
showPane(MAIN_PANEL);
|
||||
}
|
||||
|
||||
public void showBazaarPane(){
|
||||
showPane(BAZAAR_PANEL);
|
||||
}
|
||||
|
||||
public void showQuestsPane(forge.Deck deck){
|
||||
QuestQuestsPanel questsPanel = (QuestQuestsPanel) subPanelMap.get(QUESTS_PANEL);
|
||||
questsPanel.setDeck(deck);
|
||||
|
||||
showPane(QUESTS_PANEL);
|
||||
}
|
||||
|
||||
|
||||
public void returnToMainMenu() {
|
||||
QuestData.saveData(AllZone.QuestData);
|
||||
(new Gui_NewGame()).setVisible(true) ;
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.List;
|
||||
public class QuestBazaarPanel extends QuestAbstractPanel{
|
||||
private static final long serialVersionUID = 1418913010051869222L;
|
||||
|
||||
QuestFrame mainFrame;
|
||||
static List<QuestAbstractBazaarStall> stallList = new ArrayList<QuestAbstractBazaarStall>();
|
||||
|
||||
JPanel buttonPanel = new JPanel(new BorderLayout());
|
||||
@@ -30,7 +29,7 @@ public class QuestBazaarPanel extends QuestAbstractPanel{
|
||||
CardLayout stallLayout = new CardLayout();
|
||||
|
||||
public QuestBazaarPanel(QuestFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
super(mainFrame);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
stallList = new ArrayList<QuestAbstractBazaarStall>();
|
||||
@@ -100,7 +99,7 @@ public class QuestBazaarPanel extends QuestAbstractPanel{
|
||||
quitButton.setSize(max);
|
||||
quitButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
QuestBazaarPanel.this.mainFrame.showPane(QuestFrame.MAIN_PANEL);
|
||||
QuestBazaarPanel.this.mainFrame.showMainPane();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import forge.*;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.quest.QuestAbstractPanel;
|
||||
import forge.quest.QuestFrame;
|
||||
import forge.quest.quests.Gui_Quest_Assignments;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
@@ -27,8 +26,6 @@ import java.util.List;
|
||||
public class QuestMainPanel extends QuestAbstractPanel {
|
||||
private QuestData questData;
|
||||
|
||||
private QuestFrame mainFrame;
|
||||
|
||||
JLabel creditsLabel = new JLabel();
|
||||
JLabel lifeLabel = new JLabel();
|
||||
JLabel statsLabel = new JLabel();
|
||||
@@ -52,8 +49,8 @@ public class QuestMainPanel extends QuestAbstractPanel {
|
||||
private static final String NO_DECKS_AVAILABLE = "No decks available";
|
||||
|
||||
public QuestMainPanel(QuestFrame mainFrame) {
|
||||
super(mainFrame);
|
||||
questData = AllZone.QuestData;
|
||||
this.mainFrame = mainFrame;
|
||||
|
||||
initUI();
|
||||
}
|
||||
@@ -388,7 +385,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
|
||||
}//deck editor button
|
||||
|
||||
void showBazaar() {
|
||||
mainFrame.showPane(QuestFrame.BAZAAR_PANEL);
|
||||
mainFrame.showBazaarPane();
|
||||
}
|
||||
|
||||
void showCardShop() {
|
||||
@@ -495,9 +492,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
|
||||
questData.setSelectedPet(pet.toString());
|
||||
}
|
||||
|
||||
forge.quest.quests.Gui_Quest_Assignments g = new Gui_Quest_Assignments(human);
|
||||
g.setVisible(true);
|
||||
mainFrame.dispose();
|
||||
mainFrame.showQuestsPane(human);
|
||||
}
|
||||
|
||||
class OpponentAdapter extends MouseAdapter {
|
||||
|
||||
@@ -2,22 +2,22 @@ package forge.quest.quests;
|
||||
|
||||
import forge.*;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.QuestAbstractPanel;
|
||||
import forge.quest.QuestFrame;
|
||||
import forge.quest.main.QuestMainPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class Gui_Quest_Assignments extends JFrame implements NewConstants{
|
||||
public class QuestQuestsPanel extends QuestAbstractPanel{
|
||||
|
||||
private static final long serialVersionUID = 2409591658245091210L;
|
||||
|
||||
@@ -32,32 +32,17 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{
|
||||
|
||||
private Deck hDeck;
|
||||
|
||||
private ReadQuest_Assignment read;
|
||||
private QuestQuestsReader read;
|
||||
|
||||
public Gui_Quest_Assignments(Deck humanDeck) {
|
||||
public QuestQuestsPanel(QuestFrame mainFrame) {
|
||||
super(mainFrame);
|
||||
try {
|
||||
jbInit();
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
hDeck = humanDeck;
|
||||
|
||||
setup();
|
||||
|
||||
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
setSize(1024, 768);
|
||||
this.setResizable(false);
|
||||
Dimension screen = getToolkit().getScreenSize();
|
||||
Rectangle bounds = getBounds();
|
||||
bounds.width = 1024;
|
||||
bounds.height = 768;
|
||||
bounds.x = (screen.width - bounds.width) / 2;
|
||||
bounds.y = (screen.height - bounds.height) / 2;
|
||||
setBounds(bounds);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//only do this ONCE:
|
||||
@@ -77,7 +62,7 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{
|
||||
}
|
||||
});
|
||||
|
||||
read = new ReadQuest_Assignment(ForgeProps.getFile(QUEST.QUESTS), questData);
|
||||
read = new QuestQuestsReader(ForgeProps.getFile(NewConstants.QUEST.QUESTS), questData);
|
||||
read.run();
|
||||
|
||||
ArrayList<Quest_Assignment> questsToDisplay = new ArrayList<Quest_Assignment>();
|
||||
@@ -172,12 +157,11 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{
|
||||
|
||||
buttonGroup.add(radio);
|
||||
|
||||
this.getContentPane().add(radio);
|
||||
this.getContentPane().add(description);
|
||||
this.getContentPane().add(difficulty);
|
||||
this.getContentPane().add(repeatable);
|
||||
this.getContentPane().add(reward);
|
||||
//this.getContentPane().add(iconLabel);
|
||||
this.add(radio);
|
||||
this.add(description);
|
||||
this.add(difficulty);
|
||||
this.add(repeatable);
|
||||
this.add(reward);
|
||||
|
||||
y+=80;
|
||||
}//for
|
||||
@@ -190,9 +174,9 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{
|
||||
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
titleLabel.setText("Quests");
|
||||
titleLabel.setBounds(new Rectangle(400, 5, 300, 60));
|
||||
ImageIcon icon = getIcon("MapIcon.png");
|
||||
ImageIcon icon = GuiUtils.getIconFromFile("MapIcon.png");
|
||||
titleLabel.setIcon(icon);
|
||||
this.getContentPane().setLayout(null);
|
||||
this.setLayout(null);
|
||||
|
||||
//String fileName = "LeafIconSmall.png";
|
||||
//ImageIcon icon = getIcon(fileName);
|
||||
@@ -203,15 +187,15 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{
|
||||
quitButton.setText("Quit");
|
||||
quitButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
quitButton_actionPerformed();
|
||||
mainFrame.showMainPane();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//jPanel2.add(quitButton, null);
|
||||
this.getContentPane().add(startQuestButton, null);
|
||||
this.getContentPane().add(titleLabel, null);
|
||||
this.getContentPane().add(quitButton,null);
|
||||
this.add(startQuestButton, null);
|
||||
this.add(titleLabel, null);
|
||||
this.add(quitButton,null);
|
||||
}
|
||||
|
||||
void startQuestButton_actionPerformed(ActionEvent e) throws Exception {
|
||||
@@ -259,22 +243,15 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{
|
||||
selectedQuest.getComputerLife(), selectedQuest);
|
||||
|
||||
AllZone.Display.setVisible(true);
|
||||
dispose();
|
||||
}
|
||||
|
||||
private ImageIcon getIcon(String fileName)
|
||||
{
|
||||
File base = ForgeProps.getFile(IMAGE_ICON);
|
||||
File file = new File(base, fileName);
|
||||
ImageIcon icon = new ImageIcon(file.toString());
|
||||
return icon;
|
||||
}
|
||||
|
||||
void quitButton_actionPerformed() {
|
||||
dispose();
|
||||
new QuestFrame();
|
||||
|
||||
mainFrame.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
}
|
||||
|
||||
public void setDeck(Deck deck) {
|
||||
this.hDeck = deck;
|
||||
}
|
||||
}
|
||||
|
||||
197
src/forge/quest/quests/QuestQuestsReader.java
Normal file
197
src/forge/quest/quests/QuestQuestsReader.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package forge.quest.quests;
|
||||
|
||||
import forge.QuestData;
|
||||
import forge.QuestUtil;
|
||||
import forge.Quest_Assignment;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class QuestQuestsReader implements Runnable, NewConstants {
|
||||
private BufferedReader in;
|
||||
private ArrayList<Quest_Assignment> allQuests = new ArrayList<Quest_Assignment>();
|
||||
|
||||
private int totalWins;
|
||||
private ArrayList<Integer> completedQuests = new ArrayList<Integer>();
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
try {
|
||||
QuestQuestsReader read = new QuestQuestsReader(ForgeProps.getFile(QUEST.QUESTS), null);
|
||||
|
||||
javax.swing.SwingUtilities.invokeAndWait(read);
|
||||
// read.run();
|
||||
|
||||
Quest_Assignment qa[] = new Quest_Assignment[read.allQuests.size()];
|
||||
read.allQuests.toArray(qa);
|
||||
for(int i = 0; i < qa.length; i++) {
|
||||
System.out.println(qa[i].getId());
|
||||
System.out.println(qa[i].getName());
|
||||
System.out.println(qa[i].getDesc());
|
||||
System.out.println(qa[i].getDifficulty());
|
||||
System.out.println(qa[i].isRepeatable());
|
||||
System.out.println(qa[i].getRequiredNumberWins());
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
System.out.println("Error reading file " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Quest_Assignment> getQuests() {
|
||||
return new ArrayList<Quest_Assignment>(allQuests);
|
||||
}
|
||||
|
||||
public ArrayList<Quest_Assignment> getQuestsByIds(ArrayList<Integer> availableQuestIds) {
|
||||
ArrayList<Quest_Assignment> quests = new ArrayList<Quest_Assignment>();
|
||||
|
||||
for(Quest_Assignment qa:allQuests)
|
||||
{
|
||||
if (availableQuestIds.contains(qa.getId()))
|
||||
quests.add(qa);
|
||||
}
|
||||
|
||||
return quests;
|
||||
}
|
||||
|
||||
public Quest_Assignment getQuestById(int i)
|
||||
{
|
||||
for(Quest_Assignment qa:allQuests)
|
||||
{
|
||||
if (qa.getId() == i)
|
||||
return qa;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
public Quest_Assignment getQuestById(int id) {
|
||||
return allQuests.get(id);
|
||||
}
|
||||
*/
|
||||
|
||||
public QuestQuestsReader(String filename, QuestData questData) {
|
||||
this(new File(filename), questData);
|
||||
}
|
||||
|
||||
public QuestQuestsReader(File file, QuestData questData) {
|
||||
|
||||
if (questData != null) {
|
||||
totalWins = questData.getWin();
|
||||
if (questData.getCompletedQuests() != null)
|
||||
completedQuests = questData.getCompletedQuests();
|
||||
else
|
||||
completedQuests = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
if(!file.exists())
|
||||
throw new RuntimeException("QuestQuestsReader : constructor error -- file not found -- filename is "
|
||||
+ file.getAbsolutePath());
|
||||
|
||||
//makes the checked exception, into an unchecked runtime exception
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(file));
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath());
|
||||
throw new RuntimeException("QuestQuestsReader : constructor error -- file not found -- filename is "
|
||||
+ file.getPath());
|
||||
}
|
||||
}//ReadCard()
|
||||
|
||||
/* id
|
||||
* name
|
||||
* desc
|
||||
* difficulty
|
||||
* repeatable
|
||||
* numberWinsRequired
|
||||
* cardReward
|
||||
* creditsReward
|
||||
*/
|
||||
|
||||
public void run() {
|
||||
Quest_Assignment qa;
|
||||
String s = readLine();
|
||||
ArrayList<Integer> ids = new ArrayList<Integer>();
|
||||
|
||||
while(!s.equals("End")) {
|
||||
qa = new Quest_Assignment();
|
||||
if(s.equals("")) throw new RuntimeException("QuestQuestsReader : run() reading error, id is blank");
|
||||
int id = Integer.parseInt(s);
|
||||
qa.setId(id);
|
||||
|
||||
s = readLine();
|
||||
qa.setName(s);
|
||||
|
||||
s = readLine();
|
||||
qa.setDesc(s);
|
||||
|
||||
|
||||
s = readLine();
|
||||
qa.setDifficulty(s);
|
||||
if (qa.getDifficulty().equals("Medium"))
|
||||
qa.setComputerLife(25);
|
||||
else if (qa.getDifficulty().equals("Hard"))
|
||||
qa.setComputerLife(30);
|
||||
else if (qa.getDifficulty().equals("Very Hard"))
|
||||
qa.setComputerLife(35);
|
||||
else if (qa.getDifficulty().equals("Expert"))
|
||||
qa.setComputerLife(50);
|
||||
else if (qa.getDifficulty().equals("Insane"))
|
||||
qa.setComputerLife(100);
|
||||
|
||||
s = readLine();
|
||||
if (s.equals("Repeatable"))
|
||||
qa.setRepeatable(true);
|
||||
else
|
||||
qa.setRepeatable(false);
|
||||
|
||||
s = readLine();
|
||||
int wins = Integer.valueOf(s);
|
||||
qa.setRequiredNumberWins(wins);
|
||||
|
||||
s = readLine();
|
||||
qa.setCardReward(s);
|
||||
|
||||
s = readLine();
|
||||
long reward = Long.parseLong(s.trim());
|
||||
qa.setCreditsReward(reward);
|
||||
|
||||
s = readLine();
|
||||
qa.setIconName(s);
|
||||
|
||||
//s = readLine();
|
||||
s = readLine();
|
||||
|
||||
if(ids.contains(qa.getId())) {
|
||||
System.out.println("QuestQuestsReader:run() error - duplicate card name: " + qa.getId());
|
||||
throw new RuntimeException("QuestQuestsReader:run() error - duplicate card name: " + qa.getId());
|
||||
}
|
||||
|
||||
ids.add(qa.getId());
|
||||
if (qa.getRequiredNumberWins() <= totalWins && !completedQuests.contains(qa.getId()) ) {
|
||||
QuestUtil.setupQuest(qa);
|
||||
allQuests.add(qa);
|
||||
}
|
||||
|
||||
//id:
|
||||
s = readLine();
|
||||
}
|
||||
}//run()
|
||||
|
||||
private String readLine() {
|
||||
//makes the checked exception, into an unchecked runtime exception
|
||||
try {
|
||||
String s = in.readLine();
|
||||
if(s != null) s = s.trim();
|
||||
return s;
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("QuestQuestsReader: readLine(Quest_Assignment) error");
|
||||
}
|
||||
}//readLine(Quest_Assignment)
|
||||
}
|
||||
Reference in New Issue
Block a user