Make it so Last Activity column isn't cut off

Make it so double-clicking a gauntlet on the Load Gauntlet screen will launch it
Support renaming gauntlets
Support sorting gauntlets (and quests) case insensitive
This commit is contained in:
drdev
2014-08-07 23:33:46 +00:00
parent 04c2e30dbd
commit d571daeed0
6 changed files with 180 additions and 52 deletions

View File

@@ -64,10 +64,24 @@ public enum CSubmenuGauntletLoad implements ICDoc {
public void initialize() { public void initialize() {
view.getBtnStart().addActionListener(actStartGame); view.getBtnStart().addActionListener(actStartGame);
view.getGauntletLister().setCmdDelete(new UiCommand() { @Override view.getGauntletLister().setCmdDelete(new UiCommand() {
public void run() { enableStartButton(); } }); @Override
view.getGauntletLister().setCmdSelect(new UiCommand() { @Override public void run() {
public void run() { enableStartButton(); } }); enableStartButton();
}
});
view.getGauntletLister().setCmdSelect(new UiCommand() {
@Override
public void run() {
enableStartButton();
}
});
view.getGauntletLister().setCmdActivate(new UiCommand() {
@Override
public void run() {
startGame();
}
});
} }
private void updateData() { private void updateData() {
@@ -103,7 +117,7 @@ public enum CSubmenuGauntletLoad implements ICDoc {
if (userDeck == null) { return; } //prevent crash if user doesn't select a deck if (userDeck == null) { return; } //prevent crash if user doesn't select a deck
gd.setUserDeck(userDeck); gd.setUserDeck(userDeck);
GauntletIO.saveGauntlet(gd); GauntletIO.saveGauntlet(gd);
updateData(); //show deck in row view.getGauntletLister().refresh();
} }
// Start game // Start game
@@ -126,8 +140,8 @@ public enum CSubmenuGauntletLoad implements ICDoc {
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.gui.framework.ICDoc#getCommandOnSelect() * @see forge.gui.framework.ICDoc#getCommandOnSelect()
*/ */
@SuppressWarnings("serial")
@Override @Override
@SuppressWarnings("serial")
public UiCommand getCommandOnSelect() { public UiCommand getCommandOnSelect() {
return new UiCommand() { return new UiCommand() {
@Override @Override

View File

@@ -4,7 +4,9 @@ import forge.UiCommand;
import forge.assets.FSkinProp; import forge.assets.FSkinProp;
import forge.gauntlet.GauntletData; import forge.gauntlet.GauntletData;
import forge.gauntlet.GauntletIO; import forge.gauntlet.GauntletIO;
import forge.quest.QuestUtil;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FMouseAdapter;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.toolbox.FSkin; import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinIcon; import forge.toolbox.FSkin.SkinIcon;
@@ -16,7 +18,6 @@ import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import java.awt.*; import java.awt.*;
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;
@@ -30,12 +31,13 @@ import java.util.List;
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class QuickGauntletLister extends JPanel { public class QuickGauntletLister extends JPanel {
private SkinIcon icoDelete, icoDeleteOver; private SkinIcon icoDelete, icoDeleteOver, icoEdit, icoEditOver;
private RowPanel previousSelect; private RowPanel previousSelect;
private RowPanel[] rows; private RowPanel[] rows;
private UiCommand cmdRowSelect, cmdRowDelete; private UiCommand cmdRowSelect, cmdRowDelete, cmdRowActivate;
private final Color clrDefault; private final Color clrDefault;
private final FSkin.SkinColor clrHover, clrActive, clrBorders; private final FSkin.SkinColor clrHover, clrActive, clrBorders;
private List<GauntletData> gauntlets;
/** */ /** */
public QuickGauntletLister() { public QuickGauntletLister() {
@@ -51,18 +53,26 @@ public class QuickGauntletLister extends JPanel {
icoDelete = FSkin.getIcon(FSkinProp.ICO_DELETE); icoDelete = FSkin.getIcon(FSkinProp.ICO_DELETE);
icoDeleteOver = FSkin.getIcon(FSkinProp.ICO_DELETE_OVER); icoDeleteOver = FSkin.getIcon(FSkinProp.ICO_DELETE_OVER);
icoEdit = FSkin.getIcon(FSkinProp.ICO_EDIT);
icoEditOver = FSkin.getIcon(FSkinProp.ICO_EDIT_OVER);
} }
/** @param gd0 &emsp; {@link forge.gauntlet.GauntletData}[] */ /** @param gd0 &emsp; {@link forge.gauntlet.GauntletData}[] */
public void setGauntlets(List<GauntletData> gd0) { public void setGauntlets(List<GauntletData> gd0) {
gauntlets = gd0;
refresh();
}
public void refresh() {
this.removeAll(); this.removeAll();
List<RowPanel> tempRows = new ArrayList<RowPanel>(); List<RowPanel> tempRows = new ArrayList<RowPanel>();
List<GauntletData> sorted = new ArrayList<GauntletData>(); List<GauntletData> sorted = new ArrayList<GauntletData>();
for (GauntletData gd : gd0) { sorted.add(gd); } for (GauntletData gd : gauntlets) { sorted.add(gd); }
Collections.sort(sorted, new Comparator<GauntletData>() { Collections.sort(sorted, new Comparator<GauntletData>() {
@Override @Override
public int compare(final GauntletData x, final GauntletData y) { public int compare(final GauntletData x, final GauntletData y) {
return x.getName().compareTo(y.getName()); return x.getName().toLowerCase().compareTo(y.getName().toLowerCase());
} }
}); });
@@ -72,18 +82,16 @@ public class QuickGauntletLister extends JPanel {
final SkinnedPanel rowTitle = new SkinnedPanel(); final SkinnedPanel rowTitle = new SkinnedPanel();
rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); 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().build(),
"w 30px!, h 20px!, gap 1% 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Name").fontAlign(SwingConstants.LEFT).build(), rowTitle.add(new FLabel.Builder().text("Name").fontAlign(SwingConstants.LEFT).build(),
"w 49% - 175px!, h 20px!, gap 20px 0 5px 0"); "w 49% - 185px!, h 20px!, gap 64px 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Your Deck").fontAlign(SwingConstants.LEFT).build(), rowTitle.add(new FLabel.Builder().text("Your Deck").fontAlign(SwingConstants.LEFT).build(),
"w 49% - 175px!, h 20px!, gap 0 0 5px 0"); "w 49% - 185px!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Last Activity").fontAlign(SwingConstants.CENTER).build(), rowTitle.add(new FLabel.Builder().text("Last Activity").fontAlign(SwingConstants.LEFT).build(),
"w 100px!, h 20px!, gap 0 0 5px 0"); "w 140px!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Opponents").fontAlign(SwingConstants.CENTER).build(), rowTitle.add(new FLabel.Builder().text("Opponents").fontAlign(SwingConstants.RIGHT).build(),
"w 100px!, h 20px!, gap 0 0 5px 0"); "w 90px!, h 20px!, gap 0 0 5px 0");
rowTitle.add(new FLabel.Builder().text("Progress").fontAlign(SwingConstants.CENTER).build(), rowTitle.add(new FLabel.Builder().text("Progress").fontAlign(SwingConstants.RIGHT).build(),
"w 100px!, h 20px!, gap 0 0 5px 0"); "w 90px!, 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;
@@ -94,21 +102,21 @@ public class QuickGauntletLister extends JPanel {
row = new RowPanel(gd); row = new RowPanel(gd);
row.setToolTipText(name); row.setToolTipText(name);
row.add(new DeleteButton(row), row.add(new DeleteButton(row), "w 22px!, h 20px!, gap 5px 0 5px 0");
"w 30px!, h 20px!, gap 1% 0 5px 0"); row.add(new EditButton(row), "w 22px!, h 20px!, gap 5px 0 5px 0");
row.add(new FLabel.Builder().fontAlign(SwingConstants.LEFT).text(name).build(), row.add(new FLabel.Builder().fontAlign(SwingConstants.LEFT).text(name).build(),
"w 49% - 175px!, h 20px!, gap 20px 0 5px 0"); "w 49% - 185px!, h 20px!, gap 10px 0 5px 0");
row.add(new FLabel.Builder().text(gd.getUserDeck() == null ? "(none)" : gd.getUserDeck().getName()).fontAlign(SwingConstants.LEFT).build(), row.add(new FLabel.Builder().text(gd.getUserDeck() == null ? "(none)" : gd.getUserDeck().getName()).fontAlign(SwingConstants.LEFT).build(),
"w 49% - 175px!, h 20px!, gap 0 0 5px 0"); "w 49% - 185px!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel.Builder().text(gd.getTimestamp()).fontAlign(SwingConstants.CENTER).build(), row.add(new FLabel.Builder().text(gd.getTimestamp()).fontAlign(SwingConstants.LEFT).build(),
"w 100px!, h 20px!, gap 0 0 5px 0"); "w 140px!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel.Builder().text(String.valueOf(gd.getDecks().size())) row.add(new FLabel.Builder().text(String.valueOf(gd.getDecks().size()))
.fontAlign(SwingConstants.CENTER).build(), .fontAlign(SwingConstants.RIGHT).build(),
"w 100px!, h 20px!, gap 0 0 5px 0"); "w 90px!, h 20px!, gap 0 0 5px 0");
row.add(new FLabel.Builder().text(String.valueOf(Math.round( row.add(new FLabel.Builder().text(String.valueOf(Math.round(
((double) gd.getCompleted() / (double) gd.getDecks().size()) * 100)) + "%") ((double) gd.getCompleted() / (double) gd.getDecks().size()) * 100)) + "%")
.fontAlign(SwingConstants.CENTER).build(), .fontAlign(SwingConstants.RIGHT).build(),
"w 100px!, h 20px!, gap 0 0 5px 0"); "w 90px!, h 20px!, gap 0 0 5px 0");
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);
} }
@@ -138,33 +146,70 @@ public class QuickGauntletLister extends JPanel {
setContentAreaFilled(false); setContentAreaFilled(false);
setBorder((Border)null); setBorder((Border)null);
setBorderPainted(false); setBorderPainted(false);
setToolTipText("Delete this deck"); setToolTipText("Delete this gauntlet");
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) {
r0.setBackground(clrHover); 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) {
r0.setBackground(clrDefault); 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);
} }
}); });
} }
} }
private class EditButton extends SkinnedButton {
public EditButton(final RowPanel r0) {
super();
setRolloverEnabled(true);
setPressedIcon(icoEditOver);
setRolloverIcon(icoEditOver);
setIcon(icoEdit);
setOpaque(false);
setContentAreaFilled(false);
setBorder((Border)null);
setBorderPainted(false);
setToolTipText("Rename this gauntlet");
this.addMouseListener(new FMouseAdapter() {
@Override
public void onMouseEnter(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrHover);
r0.setOpaque(true);
}
}
@Override
public void onMouseExit(MouseEvent e) {
if (!r0.selected) {
r0.setBackground(clrDefault);
r0.setOpaque(false);
}
}
@Override
public void onLeftClick(MouseEvent e) {
renameGauntlet(r0.getGauntletData());
}
});
}
}
private class RowPanel extends SkinnedPanel { private class RowPanel extends SkinnedPanel {
private boolean selected = false; private boolean selected = false;
private boolean hovered = false;
private GauntletData gauntletData; private GauntletData gauntletData;
public RowPanel(GauntletData gd0) { public RowPanel(GauntletData gd0) {
@@ -175,32 +220,43 @@ public class QuickGauntletLister extends JPanel {
this.setBorder(new FSkin.MatteSkinBorder(0, 0, 1, 0, clrBorders)); this.setBorder(new FSkin.MatteSkinBorder(0, 0, 1, 0, clrBorders));
gauntletData = gd0; gauntletData = gd0;
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;
if (!RowPanel.this.selected) {
RowPanel.this.setBackground(clrHover); RowPanel.this.setBackground(clrHover);
RowPanel.this.setOpaque(true); RowPanel.this.setOpaque(true);
} }
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void onMouseExit(final MouseEvent e) {
if (!selected) { RowPanel.this.hovered = false;
if (!RowPanel.this.selected) {
RowPanel.this.setBackground(clrDefault); RowPanel.this.setBackground(clrDefault);
RowPanel.this.setOpaque(false); RowPanel.this.setOpaque(false);
} }
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void onLeftMouseDown(final MouseEvent e) {
if (e.getClickCount() == 1) {
selectHandler(RowPanel.this); selectHandler(RowPanel.this);
} }
else if (cmdRowActivate != null) {
cmdRowActivate.run();
}
}
}); });
} }
public void setSelected(boolean b0) { public void setSelected(final boolean b0) {
selected = b0; this.selected = b0;
setOpaque(b0); this.setOpaque(b0);
this.setBackground(b0 ? clrActive : clrHover); if (b0) { this.setBackground(clrActive); }
else if (this.hovered) { this.setBackground(clrHover); }
else { this.setBackground(clrDefault); }
} }
public boolean isSelected() { public boolean isSelected() {
@@ -254,6 +310,11 @@ public class QuickGauntletLister extends JPanel {
this.cmdRowDelete = c0; this.cmdRowDelete = c0;
} }
/** @param c0 &emsp; {@link forge.UiCommand} command executed on row activate. */
public void setCmdActivate(UiCommand c0) {
this.cmdRowActivate = c0;
}
private void selectHandler(RowPanel r0) { private void selectHandler(RowPanel r0) {
if (previousSelect != null) { if (previousSelect != null) {
previousSelect.setSelected(false); previousSelect.setSelected(false);
@@ -264,6 +325,39 @@ public class QuickGauntletLister extends JPanel {
if (cmdRowSelect != null) { cmdRowSelect.run(); } if (cmdRowSelect != null) { cmdRowSelect.run(); }
} }
private void renameGauntlet(GauntletData gauntlet) {
String gauntletName;
String oldGauntletName = gauntlet.getName();
while (true) {
gauntletName = FOptionPane.showInputDialog("Rename gauntlet to:", "Gauntlet Rename", null, oldGauntletName);
if (gauntletName == null) { return; }
gauntletName = QuestUtil.cleanString(gauntletName);
if (gauntletName.equals(oldGauntletName)) { return; } //quit if chose same name
if (gauntletName.isEmpty()) {
FOptionPane.showMessageDialog("Please specify a gauntlet name.");
continue;
}
boolean exists = false;
for (RowPanel r : rows) {
if (r.getGauntletData().getName().equalsIgnoreCase(gauntletName)) {
exists = true;
break;
}
}
if (exists) {
FOptionPane.showMessageDialog("A gauntlet already exists with that name. Please pick another gauntlet name.");
continue;
}
break;
}
gauntlet.rename(gauntletName);
refresh();
}
private void deleteFile(RowPanel r0) { private void deleteFile(RowPanel r0) {
final GauntletData gd = r0.getGauntletData(); final GauntletData gd = r0.getGauntletData();

View File

@@ -70,7 +70,7 @@ public class QuestFileLister extends JPanel {
Collections.sort(sorted, new Comparator<QuestData>() { Collections.sort(sorted, new Comparator<QuestData>() {
@Override @Override
public int compare(final QuestData x, final QuestData y) { public int compare(final QuestData x, final QuestData y) {
return x.getName().compareTo(y.getName()); return x.getName().toLowerCase().compareTo(y.getName().toLowerCase());
} }
}); });

View File

@@ -15,6 +15,9 @@ We have added a branch to our SVN for the new cards that are currently being scr
Add column to Load Gauntlet screen to display your deck for the gauntlet Add column to Load Gauntlet screen to display your deck for the gauntlet
Fix so your deck is saved with a gauntlet when starting a quick gauntlet Fix so your deck is saved with a gauntlet when starting a quick gauntlet
Instead of crashing, prompt user to select a deck if attempting to load a gauntlet that doesn't have one saved Instead of crashing, prompt user to select a deck if attempting to load a gauntlet that doesn't have one saved
Make it so Last Activity column isn't cut off
Make it so double-clicking a gauntlet on the Load Gauntlet screen will launch it
Support renaming gauntlets
--------- ---------
New Cards New Cards

View File

@@ -1,8 +1,10 @@
package forge.gauntlet; package forge.gauntlet;
import com.thoughtworks.xstream.annotations.XStreamOmitField; import com.thoughtworks.xstream.annotations.XStreamOmitField;
import forge.deck.Deck;
import forge.deck.Deck;
import forge.properties.ForgeConstants;
import java.io.File;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@@ -37,6 +39,21 @@ public final class GauntletData {
name = name0; name = name0;
} }
/**
* Rename this gauntlet.
*
* @param newName
* the new name to set
*/
public void rename(final String newName) {
File newpath = new File(ForgeConstants.GAUNTLET_DIR.userPrefLoc, newName + ".dat");
File oldpath = new File(ForgeConstants.GAUNTLET_DIR.userPrefLoc, this.name + ".dat");
oldpath.renameTo(newpath);
this.name = newName;
GauntletIO.saveGauntlet(this);
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@@ -161,7 +161,7 @@ public final class QuestData {
} }
/** /**
* Rename this quest the name. * Rename this quest.
* *
* @param newName * @param newName
* the new name to set * the new name to set