Cleanup Quest and Deck lister display

Fix Quest renaming
This commit is contained in:
drdev
2013-12-28 22:28:59 +00:00
parent 8ceda2b07b
commit 40bfde20fa
6 changed files with 123 additions and 106 deletions

View File

@@ -51,7 +51,7 @@ public enum CSubmenuQuestData implements ICDoc {
private final Command cmdQuestSelect = new Command() { @Override private final Command cmdQuestSelect = new Command() { @Override
public void run() { changeQuest(); } }; public void run() { changeQuest(); } };
private final Command cmdQuestDelete = new Command() { @Override private final Command cmdQuestUpdate = new Command() { @Override
public void run() { update(); } }; public void run() { update(); } };
/* (non-Javadoc) /* (non-Javadoc)
@@ -139,7 +139,8 @@ public enum CSubmenuQuestData implements ICDoc {
} }
view.getLstQuests().setSelectCommand(cmdQuestSelect); view.getLstQuests().setSelectCommand(cmdQuestSelect);
view.getLstQuests().setDeleteCommand(cmdQuestDelete); view.getLstQuests().setDeleteCommand(cmdQuestUpdate);
view.getLstQuests().setEditCommand(cmdQuestUpdate);
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override public void run() { view.getBtnEmbark().requestFocusInWindow(); } @Override public void run() { view.getBtnEmbark().requestFocusInWindow(); }

View File

@@ -1,7 +1,6 @@
package forge.gui.home.quest; package forge.gui.home.quest;
import java.awt.Color; import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@@ -10,13 +9,13 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.Command; import forge.Command;
import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FLabel;
import forge.gui.toolbox.FMouseAdapter;
import forge.gui.toolbox.FOptionPane; import forge.gui.toolbox.FOptionPane;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
import forge.properties.NewConstants; import forge.properties.NewConstants;
@@ -83,11 +82,9 @@ public class QuestFileLister extends JPanel {
final JPanel rowTitle = new JPanel(); final JPanel rowTitle = new JPanel();
FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA));
rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0"); rowTitle.add(new FLabel.Builder().text("Name").fontAlign(SwingConstants.LEFT).build(), "w 85%-112px!, h 20px!, gaptop 5px, gapleft 48px");
rowTitle.add(new FLabel.Builder().text("Rename").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0"); rowTitle.add(new FLabel.Builder().text("Mode").fontAlign(SwingConstants.LEFT).build(), "w 15%!, h 20px!, gaptop 5px, gapleft 4px");
rowTitle.add(new FLabel.Builder().text("Name").fontAlign(SwingConstants.CENTER).build(), "w 40%!, h 20px!, gap 0 0 5px 0"); rowTitle.add(new FLabel.Builder().text("Record").fontAlign(SwingConstants.LEFT).build(), "w 60px!, h 20px!, gaptop 5px, gapleft 4px");
rowTitle.add(new FLabel.Builder().text("Mode").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Record").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0");
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%"); this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
RowPanel row; RowPanel row;
@@ -95,12 +92,12 @@ public class QuestFileLister extends JPanel {
for (QuestData qd : sorted) { for (QuestData qd : sorted) {
mode = qd.getMode().toString(); mode = qd.getMode().toString();
row = new RowPanel(qd); row = new RowPanel(qd);
row.add(new DeleteButton(row), "w 15%!, h 20px!, gap 0 0 5px 0"); row.add(new DeleteButton(row), "w 22px!, h 20px!, gaptop 5px");
row.add(new EditButton(row), "w 15%!, h 20px!, gaptop 5px"); row.add(new EditButton(row), "w 22px!, h 20px!, gaptop 5px");
row.add(new FLabel.Builder().text(qd.getName()).build(), "w 40%!, h 20px!, gap 0 0 5px 0"); row.add(new FLabel.Builder().text(qd.getName()).fontAlign(SwingConstants.LEFT).build(), "w 85%-112px!, h 20px!, gaptop 5px, gapleft 4px");
row.add(new FLabel.Builder().text(mode).fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0"); row.add(new FLabel.Builder().text(mode).fontAlign(SwingConstants.LEFT).build(), "w 15%!, h 20px!, gaptop 5px, gapleft 4px");
row.add(new FLabel.Builder().text(qd.getAchievements().getWin() + "/" + qd.getAchievements().getLost()) row.add(new FLabel.Builder().text(qd.getAchievements().getWin() + "/" + qd.getAchievements().getLost())
.fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0"); .fontAlign(SwingConstants.LEFT).build(), "w 60px!, h 20px!, gaptop 5px, gapleft 4px");
this.add(row, "w 98%!, h 30px!, gap 1% 0 0 0"); this.add(row, "w 98%!, h 30px!, gap 1% 0 0 0");
tempRows.add(row); tempRows.add(row);
} }
@@ -126,25 +123,25 @@ public class QuestFileLister extends JPanel {
setContentAreaFilled(false); setContentAreaFilled(false);
setBorder(null); setBorder(null);
setBorderPainted(false); setBorderPainted(false);
setToolTipText("Delete this deck"); setToolTipText("Delete this quest");
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new FMouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void onMouseEnter(MouseEvent e) {
if (!r0.selected) { if (!r0.selected) {
FSkin.get(r0).setBackground(clrHover); FSkin.get(r0).setBackground(clrHover);
r0.setOpaque(true); r0.setOpaque(true);
} }
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void onMouseExit(MouseEvent e) {
if (!r0.selected) { if (!r0.selected) {
FSkin.get(r0).setBackground(clrDefault); FSkin.get(r0).setBackground(clrDefault);
r0.setOpaque(false); r0.setOpaque(false);
} }
} }
@Override @Override
public void mouseClicked(MouseEvent e) { public void onLeftClick(MouseEvent e) {
deleteFile(r0); deleteFile(r0);
} }
}); });
@@ -165,24 +162,24 @@ public class QuestFileLister extends JPanel {
setBorderPainted(false); setBorderPainted(false);
setToolTipText("Rename this quest"); setToolTipText("Rename this quest");
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new FMouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void onMouseEnter(MouseEvent e) {
if (!r0.selected) { if (!r0.selected) {
FSkin.get(r0).setBackground(clrHover); FSkin.get(r0).setBackground(clrHover);
r0.setOpaque(true); r0.setOpaque(true);
} }
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void onMouseExit(MouseEvent e) {
if (!r0.selected) { if (!r0.selected) {
FSkin.get(r0).setBackground(clrDefault); FSkin.get(r0).setBackground(clrDefault);
r0.setOpaque(false); r0.setOpaque(false);
} }
} }
@Override @Override
public void mouseClicked(MouseEvent e) { public void onLeftClick(MouseEvent e) {
editFileName(r0.getQuestData().getName()); editQuest(r0.getQuestData());
} }
}); });
} }
@@ -190,6 +187,7 @@ public class QuestFileLister extends JPanel {
private class RowPanel extends JPanel { private class RowPanel extends JPanel {
private boolean selected = false; private boolean selected = false;
private boolean hovered = false;
private QuestData questData; private QuestData questData;
public RowPanel(QuestData qd0) { public RowPanel(QuestData qd0) {
@@ -200,32 +198,40 @@ public class QuestFileLister extends JPanel {
FSkin.get(this).setMatteBorder(0, 0, 1, 0, clrBorders); FSkin.get(this).setMatteBorder(0, 0, 1, 0, clrBorders);
questData = qd0; questData = qd0;
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new FMouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void onMouseEnter(final MouseEvent e) {
if (!selected) { RowPanel.this.hovered = true;
FSkin.get(((RowPanel) e.getSource())).setBackground(clrHover); if (!RowPanel.this.selected) {
FSkin.get(((RowPanel) e.getSource())).setBackground(QuestFileLister.this.clrHover);
((RowPanel) e.getSource()).setOpaque(true); ((RowPanel) e.getSource()).setOpaque(true);
} }
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void onMouseExit(final MouseEvent e) {
if (!selected) { RowPanel.this.hovered = false;
FSkin.get(((RowPanel) e.getSource())).setBackground(clrDefault); if (!RowPanel.this.selected) {
FSkin.get(((RowPanel) e.getSource())).setBackground(QuestFileLister.this.clrDefault);
((RowPanel) e.getSource()).setOpaque(false); ((RowPanel) e.getSource()).setOpaque(false);
} }
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void onLeftMouseDown(final MouseEvent e) {
selectHandler((RowPanel) e.getSource()); if (e.getClickCount() == 1) {
QuestFileLister.this.selectHandler((RowPanel) e.getSource());
}
} }
}); });
} }
public void setSelected(boolean b0) { public void setSelected(final boolean b0) {
selected = b0; this.selected = b0;
setOpaque(b0); this.setOpaque(b0);
FSkin.get(this).setBackground(b0 ? clrActive : clrHover); if (b0) { FSkin.get(this).setBackground(QuestFileLister.this.clrActive); }
else if (this.hovered) { FSkin.get(this).setBackground(QuestFileLister.this.clrHover); }
else { FSkin.get(this).setBackground(QuestFileLister.this.clrDefault); }
} }
public boolean isSelected() { public boolean isSelected() {
@@ -294,45 +300,46 @@ public class QuestFileLister extends JPanel {
if (cmdRowSelect != null) { cmdRowSelect.run(); } if (cmdRowSelect != null) { cmdRowSelect.run(); }
} }
private void editFileName(String s0) { private void editQuest(QuestData quest) {
final Object o = JOptionPane.showInputDialog(JOptionPane.getRootFrame(), String questName;
"Rename Quest to:", "Quest Rename", JOptionPane.OK_CANCEL_OPTION); String oldQuestName = quest.getName();
while (true) {
questName = FOptionPane.showInputDialog("Rename quest to:", "Quest Rename", null, oldQuestName);
if (questName == null) { return; }
if (o == null) { return; } questName = SSubmenuQuestUtil.cleanString(questName);
if (questName.equals(oldQuestName)) { return; } //quit if chose same name
final String questName = SSubmenuQuestUtil.cleanString(o.toString()); if (questName.isEmpty()) {
FOptionPane.showMessageDialog("Please specify a quest name.");
continue;
}
boolean exists = false; boolean exists = false;
for (RowPanel r : rows) { for (RowPanel r : rows) {
if (r.getQuestData().getName().equalsIgnoreCase(questName)) { if (r.getQuestData().getName().equalsIgnoreCase(questName)) {
exists = true; exists = true;
break; break;
} }
} }
if (exists) {
if (exists || questName.equals("")) { FOptionPane.showMessageDialog("A quest already exists with that name. Please pick another quest name.");
FOptionPane.showMessageDialog("Please pick another quest name, a quest already has that name."); continue;
return;
} }
else { break;
File newpath = new File(NewConstants.QUEST_SAVE_DIR, questName + ".dat");
File oldpath = new File(NewConstants.QUEST_SAVE_DIR, s0 + ".dat");
oldpath.renameTo(newpath);
} }
quest.rename(questName);
if (cmdRowEdit != null) { cmdRowEdit.run(); } if (cmdRowEdit != null) { cmdRowEdit.run(); }
} }
private void deleteFile(RowPanel r0) { private void deleteFile(RowPanel r0) {
final QuestData qd = r0.getQuestData(); final QuestData qd = r0.getQuestData();
final int n = JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), if (!FOptionPane.showConfirmDialog(
"Are you sure you want to delete \"" + qd.getName() "Are you sure you want to delete '" + qd.getName() + "'?",
+ "\" ?", "Delete Deck", JOptionPane.YES_NO_OPTION); "Delete Quest", "Delete", "Cancel")) {
if (n == JOptionPane.NO_OPTION) {
return; return;
} }

View File

@@ -28,7 +28,6 @@ import java.util.List;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
@@ -47,6 +46,7 @@ import forge.gui.framework.FScreen;
import forge.gui.framework.ILocalRepaint; import forge.gui.framework.ILocalRepaint;
import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FLabel;
import forge.gui.toolbox.FMouseAdapter; import forge.gui.toolbox.FMouseAdapter;
import forge.gui.toolbox.FOptionPane;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
import forge.gui.toolbox.FSkin.JLabelSkin; import forge.gui.toolbox.FSkin.JLabelSkin;
import forge.item.InventoryItem; import forge.item.InventoryItem;
@@ -124,20 +124,15 @@ public class DeckLister extends JPanel implements ILocalRepaint {
FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(),
"w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel.Builder().text("Edit")
.fontSize(14).fontAlign(SwingConstants.CENTER).build(),
"w 10%!, h 20px!, gaptop 5px");
rowTitle.add(new FLabel.Builder().text("Deck Name") rowTitle.add(new FLabel.Builder().text("Deck Name")
.fontSize(14).fontAlign(SwingConstants.CENTER).build(), .fontSize(14).fontAlign(SwingConstants.LEFT).build(),
"w 58%!, h 20px!, gaptop 5px"); "w 100%-128px!, h 20px!, gaptop 5px, gapleft 48px");
rowTitle.add(new FLabel.Builder().text("Main") rowTitle.add(new FLabel.Builder().text("Main")
.fontSize(14).fontAlign(SwingConstants.CENTER).build(), .fontSize(14).fontAlign(SwingConstants.LEFT).build(),
"w 10%!, h 20px!, gaptop 5px"); "w 36px!, h 20px!, gaptop 5px, gapleft 4px");
rowTitle.add(new FLabel.Builder().text("Side") rowTitle.add(new FLabel.Builder().text("Side")
.fontSize(14).fontAlign(SwingConstants.CENTER).build(), .fontSize(14).fontAlign(SwingConstants.LEFT).build(),
"w 10%!, h 20px!, gaptop 5px"); "w 36px!, h 20px!, gaptop 5px, gapleft 4px");
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%"); this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
RowPanel row; RowPanel row;
@@ -147,11 +142,11 @@ public class DeckLister extends JPanel implements ILocalRepaint {
} }
row = new RowPanel(d); row = new RowPanel(d);
row.add(new DeleteButton(row), "w 10%!, h 20px!, gaptop 5px"); row.add(new DeleteButton(row), "w 22px!, h 20px!, gaptop 5px");
row.add(new EditButton(row), "w 10%!, h 20px!, gaptop 5px"); row.add(new EditButton(row), "w 22px!, h 20px!, gaptop 5px");
row.add(new GenericLabel(d.getName()), "w 58%!, h 20px!, gaptop 5px"); row.add(new GenericLabel(d.getName()), "w 100%-128px!, h 20px!, gaptop 5px, gapleft 4px");
row.add(new MainLabel(String.valueOf(d.getMain().countAll())), "w 10%, h 20px!, gaptop 5px"); row.add(new MainLabel(String.valueOf(d.getMain().countAll())), "w 36px!, h 20px!, gaptop 5px, gapleft 4px");
row.add(new GenericLabel(d.has(DeckSection.Sideboard) ? String.valueOf(d.get(DeckSection.Sideboard).countAll()) : "none"), "w 10%!, h 20px!, gaptop 5px"); row.add(new GenericLabel(d.has(DeckSection.Sideboard) ? String.valueOf(d.get(DeckSection.Sideboard).countAll()) : "none"), "w 36px!, h 20px!, gaptop 5px, gapleft 4px");
this.add(row, "w 98%!, h 30px!, gapleft 1%"); this.add(row, "w 98%!, h 30px!, gapleft 1%");
tempRows.add(row); tempRows.add(row);
} }
@@ -353,7 +348,7 @@ public class DeckLister extends JPanel implements ILocalRepaint {
private class GenericLabel extends JLabel { private class GenericLabel extends JLabel {
public GenericLabel(final String txt0) { public GenericLabel(final String txt0) {
super(txt0); super(txt0);
this.setHorizontalAlignment(SwingConstants.CENTER); this.setHorizontalAlignment(SwingConstants.LEFT);
JLabelSkin<GenericLabel> skin = FSkin.get(this); JLabelSkin<GenericLabel> skin = FSkin.get(this);
skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
skin.setFont(FSkin.getBoldFont(12)); skin.setFont(FSkin.getBoldFont(12));
@@ -435,7 +430,6 @@ public class DeckLister extends JPanel implements ILocalRepaint {
} }
} }
private <T extends DeckBase> void editDeck(final Deck d0) { private <T extends DeckBase> void editDeck(final Deck d0) {
ACEditorBase<? extends InventoryItem, ? extends DeckBase> editorCtrl = null; ACEditorBase<? extends InventoryItem, ? extends DeckBase> editorCtrl = null;
FScreen screen = null; FScreen screen = null;
@@ -471,10 +465,9 @@ public class DeckLister extends JPanel implements ILocalRepaint {
private void deleteDeck(final RowPanel r0) { private void deleteDeck(final RowPanel r0) {
final Deck d0 = r0.getDeck(); final Deck d0 = r0.getDeck();
final int n = JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), "Are you sure you want to delete \"" + d0.getName() + "\" ?", if (!FOptionPane.showConfirmDialog(
"Delete Deck", JOptionPane.YES_NO_OPTION); "Are you sure you want to delete '" + d0.getName() + "'?",
"Delete Deck", "Delete", "Cancel")) {
if (n == JOptionPane.NO_OPTION) {
return; return;
} }
@@ -482,12 +475,15 @@ public class DeckLister extends JPanel implements ILocalRepaint {
if (this.gametype.equals(GameType.Draft)) { if (this.gametype.equals(GameType.Draft)) {
deckManager.getDraft().delete(d0.getName()); deckManager.getDraft().delete(d0.getName());
} else if (this.gametype.equals(GameType.Sealed)) { }
else if (this.gametype.equals(GameType.Sealed)) {
deckManager.getSealed().delete(d0.getName()); deckManager.getSealed().delete(d0.getName());
} else if (this.gametype.equals(GameType.Quest)) { }
else if (this.gametype.equals(GameType.Quest)) {
Singletons.getModel().getQuest().getMyDecks().delete(d0.getName()); Singletons.getModel().getQuest().getMyDecks().delete(d0.getName());
Singletons.getModel().getQuest().save(); Singletons.getModel().getQuest().save();
} else { }
else {
deckManager.getConstructed().delete(d0.getName()); deckManager.getConstructed().delete(d0.getName());
} }

View File

@@ -254,9 +254,10 @@ public class QuestController {
this.load(new QuestData(name, difficulty, mode, formatPrizes, allowSetUnlocks, startingWorld)); // pass awards and unlocks here this.load(new QuestData(name, difficulty, mode, formatPrizes, allowSetUnlocks, startingWorld)); // pass awards and unlocks here
if (null != startingCards) { if (startingCards != null) {
this.myCards.addDeck(startingCards); this.myCards.addDeck(startingCards);
} else { }
else {
Predicate<PaperCard> filter = Predicates.alwaysTrue(); Predicate<PaperCard> filter = Predicates.alwaysTrue();
if (formatStartingPool != null) { if (formatStartingPool != null) {
filter = formatStartingPool.getFilterPrinted(); filter = formatStartingPool.getFilterPrinted();
@@ -265,7 +266,6 @@ public class QuestController {
} }
this.getAssets().setCredits(Singletons.getModel().getQuestPreferences().getPrefInt(DifficultyPrefs.STARTING_CREDITS, difficulty)); this.getAssets().setCredits(Singletons.getModel().getQuestPreferences().getPrefInt(DifficultyPrefs.STARTING_CREDITS, difficulty));
} }
/** /**

View File

@@ -17,11 +17,13 @@
*/ */
package forge.quest.data; package forge.quest.data;
import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import forge.Singletons; import forge.Singletons;
import forge.game.GameFormat; import forge.game.GameFormat;
import forge.properties.NewConstants;
import forge.quest.QuestMode; import forge.quest.QuestMode;
import forge.quest.io.QuestDataIO; import forge.quest.io.QuestDataIO;
@@ -38,7 +40,6 @@ import forge.quest.io.QuestDataIO;
* @version $Id$ * @version $Id$
*/ */
public final class QuestData { public final class QuestData {
/** Holds the latest version of the Quest Data. */ /** Holds the latest version of the Quest Data. */
public static final int CURRENT_VERSION_NUMBER = 8; public static final int CURRENT_VERSION_NUMBER = 8;
@@ -49,7 +50,7 @@ public final class QuestData {
private int versionNumber = QuestData.CURRENT_VERSION_NUMBER; private int versionNumber = QuestData.CURRENT_VERSION_NUMBER;
private GameFormatQuest format; private GameFormatQuest format;
private final String name; private String name;
// Quest mode - there should be an enum :( // Quest mode - there should be an enum :(
/** The mode. */ /** The mode. */
@@ -64,7 +65,6 @@ public final class QuestData {
private final Map<Integer, String> petSlots = new HashMap<Integer, String>(); private final Map<Integer, String> petSlots = new HashMap<Integer, String>();
private boolean isCharmActive = false; private boolean isCharmActive = false;
/** /**
* Instantiates a new quest data. * Instantiates a new quest data.
* @param mode2 * @param mode2
@@ -80,18 +80,17 @@ public final class QuestData {
* @param startingWorld * @param startingWorld
* starting world * starting world
*/ */
public QuestData(String name2, int diff, QuestMode mode2, GameFormat userFormat, public QuestData(String name0, int diff, QuestMode mode0, GameFormat userFormat,
boolean allowSetUnlocks, final String startingWorld) { boolean allowSetUnlocks, final String startingWorld) {
this.name = name2; this.name = name0;
if (userFormat != null) { if (userFormat != null) {
this.format = new GameFormatQuest(userFormat, allowSetUnlocks); this.format = new GameFormatQuest(userFormat, allowSetUnlocks);
} }
this.mode = mode2; this.mode = mode0;
this.achievements = new QuestAchievements(diff); this.achievements = new QuestAchievements(diff);
this.assets = new QuestAssets(format); this.assets = new QuestAssets(format);
this.worldId = startingWorld; this.worldId = startingWorld;
} }
/** /**
@@ -158,6 +157,21 @@ public final class QuestData {
return this.name; return this.name;
} }
/**
* Rename this quest the name.
*
* @param newName
* the new name to set
*/
public void rename(final String newName) {
File newpath = new File(NewConstants.QUEST_SAVE_DIR, newName + ".dat");
File oldpath = new File(NewConstants.QUEST_SAVE_DIR, this.name + ".dat");
oldpath.renameTo(newpath);
this.name = newName;
QuestDataIO.saveData(this);
}
public QuestAssets getAssets() { public QuestAssets getAssets() {
return assets; return assets;
} }
@@ -200,5 +214,4 @@ public final class QuestData {
public void setCharmActive(boolean isCharmActive) { public void setCharmActive(boolean isCharmActive) {
this.isCharmActive = isCharmActive; this.isCharmActive = isCharmActive;
} }
} }

View File

@@ -145,7 +145,8 @@ public class QuestDataIO {
} }
return data; return data;
} catch (final Exception ex) { }
catch (final Exception ex) {
BugReporter.reportException(ex, "Error loading Quest Data"); BugReporter.reportException(ex, "Error loading Quest Data");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@@ -175,7 +176,6 @@ public class QuestDataIO {
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
private static void updateSaveFile(final QuestData newData, final String input, String filename) throws ParserConfigurationException, SAXException, IOException, IllegalAccessException, NoSuchFieldException { private static void updateSaveFile(final QuestData newData, final String input, String filename) throws ParserConfigurationException, SAXException, IOException, IllegalAccessException, NoSuchFieldException {
final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final InputSource is = new InputSource(); final InputSource is = new InputSource();
is.setCharacterStream(new StringReader(input)); is.setCharacterStream(new StringReader(input));
@@ -206,7 +206,6 @@ public class QuestDataIO {
QuestDataIO.setFinalField(QuestData.class, "isCharmActive", newData, false); QuestDataIO.setFinalField(QuestData.class, "isCharmActive", newData, false);
} }
final QuestAssets qS = newData.getAssets(); final QuestAssets qS = newData.getAssets();
final QuestAchievements qA = newData.getAchievements(); final QuestAchievements qA = newData.getAchievements();
@@ -376,7 +375,8 @@ public class QuestDataIO {
QuestDataIO.savePacked(f + ".dat", xStream, qd); QuestDataIO.savePacked(f + ".dat", xStream, qd);
// QuestDataIO.saveUnpacked(f + ".xml", xStream, qd); // QuestDataIO.saveUnpacked(f + ".xml", xStream, qd);
} catch (final Exception ex) { }
catch (final Exception ex) {
BugReporter.reportException(ex, "Error saving Quest Data."); BugReporter.reportException(ex, "Error saving Quest Data.");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }