New UI for bazaar.

Selling price added to interface and abstract for quest bazaar items.
Can now sell life back to the Alchemist.
This commit is contained in:
Doublestrike
2012-02-05 02:53:52 +00:00
parent 793a692f6e
commit b542329961
31 changed files with 663 additions and 518 deletions

View File

@@ -28,8 +28,8 @@ import javax.swing.JLayeredPane;
import javax.swing.WindowConstants;
import forge.control.KeyboardShortcuts.Shortcut;
import forge.quest.gui.bazaar.QuestBazaarPanel;
import forge.view.GuiTopLevel;
import forge.view.bazaar.BazaarTopLevel;
import forge.view.editor.EditorTopLevel;
import forge.view.home.HomeTopLevel;
import forge.view.match.MatchTopLevel;
@@ -52,7 +52,7 @@ public class FControl {
private MatchTopLevel match = null;
private EditorTopLevel editor = null;
private WindowAdapter waDefault, waConcede, waLeaveBazaar;
private QuestBazaarPanel bazaar;
private BazaarTopLevel bazaar;
/** */
public static final int HOME_SCREEN = 0;
@@ -156,7 +156,7 @@ public class FControl {
break;
case QUEST_BAZAAR:
this.bazaar = new QuestBazaarPanel(null);
this.bazaar = new BazaarTopLevel();
this.display.add(bazaar, JLayeredPane.DEFAULT_LAYER);
sizeChildren();
view.addWindowListener(waLeaveBazaar);
@@ -200,7 +200,7 @@ public class FControl {
*
* @return MatchTopLevel
*/
public QuestBazaarPanel getBazaarView() {
public BazaarTopLevel getBazaarView() {
return this.bazaar;
}

View File

@@ -0,0 +1,21 @@
package forge.control.bazaar;
import forge.view.bazaar.ViewStall;
/**
* TODO: Write javadoc for this type.
*
*/
public class ControlStall {
private final ViewStall view;
/** @param v0   {@link forge.view.bazaar.ViewStall} */
public ControlStall(ViewStall v0) {
this.view = v0;
}
/** @return {@link forge.view.bazaar.ViewStall} */
public ViewStall getView() {
return view;
}
}

View File

@@ -420,15 +420,21 @@ public final class QuestData {
}
/**
* Adds the life.
*
* @param n
* the n
* Adds n life to maximum.
* @param n   int
*/
public void addLife(final int n) {
this.life += n;
}
/**
* Removes n life from maximum.
* @param n   int
*/
public void removeLife(final int n) {
this.life -= n;
}
// Credits
/**
* Adds the credits.

View File

@@ -44,33 +44,31 @@ public class QuestStallManager {
private static Map<String, SortedSet<QuestStallPurchasable>> items;
/**
* <p>
* buildStalls.
* </p>
* Master method for assembling stall data: merchant...
*/
public static void buildStalls() {
final FSkin skin = Singletons.getView().getSkin();
QuestStallManager.stalls = new HashMap<String, QuestStallDefinition>();
QuestStallManager.stalls.put(QuestStallManager.ALCHEMIST, new QuestStallDefinition(QuestStallManager.ALCHEMIST,
"Alchemist", "The walls of this alchemist's stall are covered with shelves with potions, oils, "
"Orim, Samite Healer", "The walls of this alchemist's stall are covered with shelves with potions, oils, "
+ "powders, poultices and elixirs, each meticulously labeled.",
skin.getIcon(FSkin.QuestIcons.ICO_BOTTLES)));
QuestStallManager.stalls.put(QuestStallManager.BANKER, new QuestStallDefinition(QuestStallManager.BANKER,
"Banker", "A large book large enough to be seen from the outside rests on the Banker's desk.",
"Bank of Sarpadia", "A large book large enough to be seen from the outside rests on the Banker's desk.",
skin.getIcon(FSkin.QuestIcons.ICO_COIN)));
QuestStallManager.stalls.put(QuestStallManager.BOOKSTORE, new QuestStallDefinition(QuestStallManager.BOOKSTORE,
"Bookstore", "Tomes of different sizes are stacked in man-high towers.",
"Beleren's Books", "Tomes of different sizes are stacked in man-high towers.",
skin.getIcon(FSkin.QuestIcons.ICO_BOOK)));
QuestStallManager.stalls.put(QuestStallManager.GEAR, new QuestStallDefinition(QuestStallManager.GEAR,
"Adventuring Gear",
"The Rope and Axe",
"This adventurer's market has a tool for every need ... or so the plaque on the wall claims.",
skin.getIcon(FSkin.QuestIcons.ICO_GEAR)));
QuestStallManager.stalls.put(QuestStallManager.NURSERY, new QuestStallDefinition(QuestStallManager.NURSERY,
"Nursery", "The smells of the one hundred and one different plants forms a unique fragrance.",
"Force of Nature Nursery", "The smells of the one hundred and one different plants forms a unique fragrance.",
skin.getIcon(FSkin.QuestIcons.ICO_LEAF)));
QuestStallManager.stalls.put(QuestStallManager.PET_SHOP, new QuestStallDefinition(QuestStallManager.PET_SHOP,
"Pet Shop", "This large stall echoes with a multitude of animal noises.",
"The Hive", "This large menagerie echoes with a multitude of animal noises.",
skin.getIcon(FSkin.QuestIcons.ICO_FOX)));
}
@@ -110,9 +108,8 @@ public class QuestStallManager {
}
/**
* <p>
* buildItems.
* </p>
* Retrieves all creatures and items, iterates through them,
* and maps to appropriate merchant.
*/
public static void buildItems() {
final SortedSet<QuestStallPurchasable> itemSet = new TreeSet<QuestStallPurchasable>();
@@ -133,18 +130,13 @@ public class QuestStallManager {
}
/**
* <p>
* Getter for the field <code>items</code>.
* </p>
* Returns <i>purchasable</i> items available for a particular stall.
*
* @param stallName
* a {@link java.lang.String} object.
* @return a {@link java.util.List} object.
* @param stallName &emsp; {@link java.lang.String}
* @return {@link java.util.List}.
*/
public static List<QuestStallPurchasable> getItems(final String stallName) {
if (QuestStallManager.items == null) {
QuestStallManager.buildItems();
}
QuestStallManager.buildItems();
final List<QuestStallPurchasable> ret = new ArrayList<QuestStallPurchasable>();

View File

@@ -58,9 +58,18 @@ public interface QuestStallPurchasable extends Comparable<Object> {
* getPrice.
* </p>
*
* @return the cost of the item in credits
* @return the buying cost of the item in credits
*/
int getPrice();
int getBuyingPrice();
/**
* <p>
* getPrice.
* </p>
*
* @return the selling cost of the item in credits
*/
int getSellingPrice();
/**
* Returns if the item is available for purchase;.

View File

@@ -115,6 +115,7 @@ public class QuestInventory {
private static Set<QuestItemAbstract> getAllItems() {
final SortedSet<QuestItemAbstract> set = new TreeSet<QuestItemAbstract>();
set.add(new QuestItemPoundFlesh());
set.add(new QuestItemElixir());
set.add(new QuestItemEstates());
set.add(new QuestItemLuckyCoin());

View File

@@ -186,15 +186,13 @@ public abstract class QuestItemAbstract implements QuestStallPurchasable {
@Override
public abstract ImageIcon getIcon();
/**
* <p>
* getPrice.
* </p>
*
* @return a int.
*/
/** @return a int. */
@Override
public abstract int getPrice();
public abstract int getBuyingPrice();
/** @return a int. */
@Override
public abstract int getSellingPrice();
/** {@inheritDoc} */
@Override

View File

@@ -44,7 +44,9 @@ public class QuestItemElixir extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final String getPurchaseDescription() {
return "Gives +1 to maximum life<br>Current Life: " + AllZone.getQuestData().getLife();
return "A salty sweet smell rises from the vials bubbling behind the counter.\n"
+ "\nEffect: Gives +1 to maximum life."
+ "\nFine Print: Loses effectiveness after 15 uses.";
}
/** {@inheritDoc} */
@@ -55,20 +57,32 @@ public class QuestItemElixir extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final int getPrice() {
public final int getBuyingPrice() {
if (this.getLevel() < 5) {
return 250;
} else if (this.getLevel() < 10) {
return 500;
} else {
} else if (this.getLevel() <= this.getMaxLevel()) {
return 750;
} else {
return 0;
}
}
/** {@inheritDoc} */
@Override
public final int getSellingPrice() {
return 0;
}
/** {@inheritDoc} */
@Override
public final void onPurchase() {
AllZone.getQuestData().addLife(1);
super.onPurchase();
if (this.getLevel() <= this.getMaxLevel()) {
AllZone.getQuestData().addLife(1);
}
}
}

View File

@@ -44,8 +44,10 @@ public class QuestItemEstates extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final String getPurchaseDescription() {
return String.format("Gives a bonus of <b>%d%%</b> to match winnings.<br>"
+ "Improves sell percentage by <b>%.2f%%</b>.", (10 + (this.getLevel() * 5)),
return String.format("Land owners have a strong voice in community matters.\n"
+ "\nEffect: Gives a bonus of %d%% to match winnings."
+ "\nEffect: Improves sell percentage by %.2f%%.",
(10 + (this.getLevel() * 5)),
(1 + (this.getLevel() * 0.75)));
}
@@ -57,7 +59,7 @@ public class QuestItemEstates extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final int getPrice() {
public final int getBuyingPrice() {
if (this.getLevel() == 0) {
return 500;
} else if (this.getLevel() == 1) {
@@ -67,4 +69,9 @@ public class QuestItemEstates extends QuestItemAbstract {
}
}
/** {@inheritDoc} */
@Override
public final int getSellingPrice() {
return 0;
}
}

View File

@@ -44,8 +44,8 @@ public class QuestItemLuckyCoin extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final String getPurchaseDescription() {
return "This coin is believed to give good luck to its owner.<br>"
+ "Improves the chance of getting a random <br>rare after each match by <b>15%</b>.";
return "This coin is believed to give good luck to its owner.\n"
+ "\nEffect: Improves the chance of getting a random rare after each match by 15%.";
}
/** {@inheritDoc} */
@@ -56,8 +56,13 @@ public class QuestItemLuckyCoin extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final int getPrice() {
public final int getBuyingPrice() {
return 2000;
}
/** {@inheritDoc} */
@Override
public final int getSellingPrice() {
return 0;
}
}

View File

@@ -50,8 +50,8 @@ public class QuestItemMap extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final String getPurchaseDescription() {
return "These ancient charts should facilitate navigation during your travels significantly.<br>"
+ "<em>Effect: </em>Quest assignments become available more frequently.";
return "These ancient charts should facilitate navigation during your travels significantly.\n"
+ "\nEffect: Quest assignments become available more frequently.";
}
/** {@inheritDoc} */
@@ -62,7 +62,13 @@ public class QuestItemMap extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final int getPrice() {
public final int getBuyingPrice() {
return 2000;
}
/** {@inheritDoc} */
@Override
public final int getSellingPrice() {
return 0;
}
}

View File

@@ -0,0 +1,86 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.quest.data.item;
import javax.swing.ImageIcon;
import forge.AllZone;
import forge.Singletons;
import forge.quest.data.bazaar.QuestStallManager;
import forge.view.toolbox.FSkin;
/**
* This item has special coding.
*
* @author Forge
* @version $Id: QuestItemElixir.java 13728 2012-02-01 11:13:34Z moomarc $
*/
public class QuestItemPoundFlesh extends QuestItemAbstract {
/**
* <p>
* Constructor for QuestItemElixir.
* </p>
*/
QuestItemPoundFlesh() {
super("Pound of Flesh", QuestStallManager.ALCHEMIST, 29);
}
/** {@inheritDoc} */
@Override
public final String getPurchaseDescription() {
return "The Alchemist welcomes contributions to his famous Elixer.\n"
+ "But beware, you may build an immunity to its effects...\n"
+ "\nEffect: Alchemist gives you " + getSellingPrice() + " credits."
+ "\nEffect: Reduces maximum life by 1.";
}
/** {@inheritDoc} */
@Override
public final ImageIcon getIcon() {
return Singletons.getView().getSkin().getIcon(FSkin.QuestIcons.ICO_BREW);
}
/** {@inheritDoc} */
@Override
public final int getBuyingPrice() {
return 0;
}
/** {@inheritDoc} */
public final int getSellingPrice() {
if (AllZone.getQuestData().getLife() < 2) {
return 0;
} else if (this.getLevel() < 5) {
return 250;
} else if (this.getLevel() < 10) {
return 500;
} else {
return 750;
}
}
/** {@inheritDoc} */
@Override
public final void onPurchase() {
if (AllZone.getQuestData().getLife() > 1) {
super.onPurchase();
AllZone.getQuestData().removeLife(1);
}
}
}

View File

@@ -50,10 +50,16 @@ public class QuestItemSleight extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final int getPrice() {
public final int getBuyingPrice() {
return 2000;
}
/** {@inheritDoc} */
@Override
public final int getSellingPrice() {
return 0;
}
/** {@inheritDoc} */
@Override
public final String getPurchaseName() {
@@ -63,7 +69,7 @@ public class QuestItemSleight extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final String getPurchaseDescription() {
return "These volumes explain how to perform the most difficult of sleights.<br>"
+ "<em>Effect: </em>Your first mulligan is <b>free</b>";
return "These volumes explain how to perform the most difficult of sleights.\n"
+ "\nEffect: Your first mulligan is free.";
}
}

View File

@@ -55,10 +55,10 @@ public class QuestItemZeppelin extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final String getPurchaseDescription() {
return "This extremely comfortable airship allows for more efficient and safe travel<br>to faraway destinations. <br>"
+ "<em>Effect: </em>Quest assignments become available more frequently<br>"
+ "<em>Effect: </em>Adds +3 to max life during quest games.<br>"
+ "<em>Effect: </em>Allows travel to far places, allowing you to see a new set of opponents";
return "This extremely comfortable airship allows for more efficient and safe travelto faraway destinations.\n"
+ "\nEffect: Quest assignments become available more frequently."
+ "\nEffect: Adds +3 to max life during quest games."
+ "\nEffect: Allows travel to far places, allowing you to see a new set of opponents,";
}
/** {@inheritDoc} */
@@ -69,10 +69,16 @@ public class QuestItemZeppelin extends QuestItemAbstract {
/** {@inheritDoc} */
@Override
public final int getPrice() {
public final int getBuyingPrice() {
return 5000;
}
/** {@inheritDoc} */
@Override
public final int getSellingPrice() {
return 0;
}
/** {@inheritDoc} */
@Override
public final boolean isAvailableForPurchase() {

View File

@@ -67,10 +67,16 @@ public abstract class QuestPetAbstract implements QuestStallPurchasable {
* @return a int.
*/
@Override
public final int getPrice() {
public final int getBuyingPrice() {
return this.getAllUpgradePrices()[this.level];
}
/** {@inheritDoc} */
@Override
public final int getSellingPrice() {
return 0;
}
/**
* <p>
* getAllUpgradeDescriptions.
@@ -215,8 +221,8 @@ public abstract class QuestPetAbstract implements QuestStallPurchasable {
*/
@Override
public final String getPurchaseDescription() {
return "<em>" + this.getDescription() + "</em><br>" + this.getUpgradeDescription()
+ "<br><br><u>Current stats:</u> " + this.getStats() + "<br><u>Upgraded stats:</u> "
return this.getDescription()
+ "\n\nCurrent stats: " + this.getStats() + "\nUpgraded stats: "
+ this.getUpgradedStats();
}

View File

@@ -110,7 +110,7 @@ public class QuestPetBird extends QuestPetAbstract {
public final ImageIcon[] getAllIcons() {
final String address = ForgeProps.getFile(NewConstants.IMAGE_TOKEN).getAbsolutePath() + File.separator;
return new ImageIcon[] { null,
return new ImageIcon[] {
new ImageIcon(address + "w_0_1_bird_pet.jpg"),
new ImageIcon(address + "w_1_1_bird_pet.jpg"),
new ImageIcon(address + "w_2_1_bird_pet.jpg"),

View File

@@ -106,7 +106,7 @@ public class QuestPetCrocodile extends QuestPetAbstract {
public final ImageIcon[] getAllIcons() {
final String address = ForgeProps.getFile(NewConstants.IMAGE_TOKEN).getAbsolutePath() + File.separator;
return new ImageIcon[] { null,
return new ImageIcon[] {
new ImageIcon(address + "b_1_1_crocodile_pet.jpg"),
new ImageIcon(address + "b_2_1_crocodile_pet.jpg"),
new ImageIcon(address + "b_3_1_crocodile_pet.jpg"),

View File

@@ -122,7 +122,7 @@ public class QuestPetHound extends QuestPetAbstract {
public final ImageIcon[] getAllIcons() {
final String address = ForgeProps.getFile(NewConstants.IMAGE_TOKEN).getAbsolutePath() + File.separator;
return new ImageIcon[] { null,
return new ImageIcon[] {
new ImageIcon(address + "r_1_1_hound_pet.jpg"),
new ImageIcon(address + "r_1_1_hound_pet_haste.jpg"),
new ImageIcon(address + "r_2_1_hound_pet.jpg"),

View File

@@ -125,7 +125,7 @@ public class QuestPetPlant extends QuestPetAbstract {
*/
public QuestPetPlant() {
super("Plant", "Start each of your battles with this lush, verdant plant on your side."
+ "Excellent at blocking the nastiest of critters!", 6);
+ "\nExcellent at blocking the nastiest of critters!", 6);
}
/** {@inheritDoc} */
@@ -155,8 +155,7 @@ public class QuestPetPlant extends QuestPetAbstract {
@Override
public final ImageIcon[] getAllIcons() {
final String address = ForgeProps.getFile(NewConstants.IMAGE_TOKEN).getAbsolutePath() + File.separator;
return new ImageIcon[] { null,
return new ImageIcon[] {
new ImageIcon(address + "g_0_1_plant_wall.jpg"),
new ImageIcon(address + "g_0_2_plant_wall.jpg"),
new ImageIcon(address + "g_0_3_plant_wall.jpg"),

View File

@@ -107,7 +107,7 @@ public class QuestPetWolf extends QuestPetAbstract {
public final ImageIcon[] getAllIcons() {
final String address = ForgeProps.getFile(NewConstants.IMAGE_TOKEN).getAbsolutePath() + File.separator;
return new ImageIcon[] { null,
return new ImageIcon[] {
new ImageIcon(address + "g_1_1_wolf_pet.jpg"),
new ImageIcon(address + "g_1_2_wolf_pet.jpg"),
new ImageIcon(address + "g_2_2_wolf_pet.jpg"),

View File

@@ -30,7 +30,6 @@ import javax.swing.border.EmptyBorder;
import forge.AllZone;
import forge.gui.GuiUtils;
import forge.quest.gui.bazaar.QuestBazaarPanel;
/**
* <p>
@@ -79,7 +78,7 @@ public class QuestFrame extends JFrame {
this.visiblePanel.add(newPanel, QuestFrame.MAIN_PANEL);
this.subPanelMap.put(QuestFrame.MAIN_PANEL, newPanel);
newPanel = new QuestBazaarPanel(this);
newPanel = null; //new QuestBazaarPanel(this);
this.visiblePanel.add(newPanel, QuestFrame.BAZAAR_PANEL);
this.subPanelMap.put(QuestFrame.BAZAAR_PANEL, newPanel);

View File

@@ -1,174 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.quest.gui.bazaar;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import forge.AllZone;
import forge.gui.GuiUtils;
import forge.gui.MultiLineLabel;
import forge.quest.data.bazaar.QuestStallPurchasable;
/**
* <p>
* QuestBazaarItem class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class QuestBazaarItem {
/** The item. */
private final QuestStallPurchasable item;
/**
* <p>
* Constructor for QuestBazaarItem.
* </p>
*
* @param purchasable
* a {@link forge.quest.data.bazaar.QuestStallPurchasable}
* object.
*/
protected QuestBazaarItem(final QuestStallPurchasable purchasable) {
this.item = purchasable;
}
/**
* Invoked by the Bazaar UI when the item is purchased. The credits of the
* item should not be deducted here.
*/
public final void purchaseItem() {
this.item.onPurchase();
}
/**
* <p>
* getItemPanel.
* </p>
*
* @return a {@link javax.swing.JPanel} object.
*/
protected final JPanel getItemPanel() {
ImageIcon icon = this.item.getIcon();
if (icon == null) {
// The original size was only 40 x 40 pixels.
// Increased the size to give added pixels for more detail.
icon = GuiUtils.getEmptyIcon(80, 80);
}
// The original size was only 40 x 40 pixels.
// Increased the size to give added pixels for more detail.
final ImageIcon resizedImage = GuiUtils.getResizedIcon(icon, 80, 80);
final JLabel iconLabel = new JLabel(resizedImage);
iconLabel.setBorder(new LineBorder(Color.BLACK));
final JPanel iconPanel = new JPanel(new BorderLayout());
iconPanel.add(iconLabel, BorderLayout.NORTH);
final JLabel nameLabel = new JLabel(this.item.getPurchaseName());
nameLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14));
final JLabel descriptionLabel = new MultiLineLabel("<html>" + this.item.getPurchaseDescription() + "</html>");
descriptionLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
final JLabel priceLabel = new JLabel("<html><b>Cost:</b> " + this.item.getPrice() + " credits</html>");
priceLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
final JButton purchaseButton = new JButton("Buy");
purchaseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
AllZone.getQuestData().subtractCredits(QuestBazaarItem.this.item.getPrice());
QuestBazaarItem.this.purchaseItem();
AllZone.getQuestData().saveData();
QuestBazaarPanel.refreshLastInstance();
}
});
if (AllZone.getQuestData().getCredits() < this.item.getPrice()) {
purchaseButton.setEnabled(false);
}
final JPanel itemPanel = new JPanel() {
private static final long serialVersionUID = -5182857296365949682L;
@Override
public Dimension getPreferredSize() {
final Dimension realSize = super.getPreferredSize();
realSize.width = 100;
return realSize;
}
};
final GridBagLayout layout = new GridBagLayout();
itemPanel.setLayout(layout);
final GridBagConstraints constraints = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0);
constraints.gridheight = GridBagConstraints.REMAINDER;
layout.setConstraints(iconLabel, constraints);
itemPanel.add(iconLabel);
constraints.gridheight = 1;
constraints.gridx = 1;
constraints.weightx = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(nameLabel, constraints);
itemPanel.add(nameLabel);
constraints.gridy = 1;
layout.setConstraints(descriptionLabel, constraints);
itemPanel.add(descriptionLabel);
constraints.gridy = 2;
layout.setConstraints(priceLabel, constraints);
itemPanel.add(priceLabel);
constraints.gridy = 2;
constraints.gridx = 2;
constraints.fill = GridBagConstraints.NONE;
constraints.gridheight = 1;
constraints.weightx = 0;
layout.setConstraints(purchaseButton, constraints);
itemPanel.add(purchaseButton);
itemPanel.setBorder(new CompoundBorder(new LineBorder(Color.BLACK, 1), new EmptyBorder(5, 5, 5, 5)));
itemPanel.setMinimumSize(new Dimension(0, 0));
return itemPanel;
}
}

View File

@@ -1,3 +1,8 @@
package forge.quest.gui.bazaar;
import forge.quest.gui.QuestAbstractPanel;
import forge.quest.gui.QuestFrame;
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
@@ -14,7 +19,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
package forge.quest.gui.bazaar;
import java.awt.BorderLayout;
@@ -47,35 +52,44 @@ import forge.view.GuiTopLevel;
* @version $Id$
*/
public class QuestBazaarPanel extends QuestAbstractPanel {
/** Constant <code>serialVersionUID=1418913010051869222L</code>. */
/**
* TODO: Write javadoc for Constructor.
* @param mainFrame
*/
protected QuestBazaarPanel(QuestFrame mainFrame) {
super(mainFrame);
// TODO Auto-generated constructor stub
throw new net.slightlymagic.braids.util.NotImplementedError();
}
@Override
public void refreshState() {
// TODO Auto-generated method stub
throw new net.slightlymagic.braids.util.NotImplementedError();
}
/*
/** Constant <code>serialVersionUID=1418913010051869222L</code>. *
private static final long serialVersionUID = 1418913010051869222L;
/** Constant <code>stallList</code>. */
/** Constant <code>stallList</code>. *
private static List<QuestBazaarStall> stallList = new ArrayList<QuestBazaarStall>();
/** The button panel. */
/** The button panel. *
private final JPanel buttonPanel = new JPanel(new BorderLayout());
/** The button panel main. */
/** The button panel main. *
private final JPanel buttonPanelMain = new JPanel();
/** The stall panel. */
/** The stall panel. *
private final JPanel stallPanel = new JPanel();
/** The selected stall. */
/** The selected stall. *
private JToggleButton selectedStall = null;
/** The stall layout. */
/** The stall layout. *
private final CardLayout stallLayout = new CardLayout();
/**
* <p>
* Constructor for QuestBazaarPanel.
* </p>
*
* @param mainFrame
* a {@link forge.quest.gui.QuestFrame} object.
*/
public QuestBazaarPanel(final QuestFrame mainFrame) {
super(mainFrame);
this.setLayout(new BorderLayout());
@@ -165,23 +179,27 @@ public class QuestBazaarPanel extends QuestAbstractPanel {
*
* @param source
* a {@link java.lang.String} object.
*/
*
private void showStall(final String source) {
this.stallLayout.show(this.stallPanel, source);
}
/**
* Slightly hackish, but should work.
*/
*
static void refreshLastInstance() {
for (final QuestBazaarStall stall : QuestBazaarPanel.stallList) {
stall.updateItems();
}
}
/** {@inheritDoc} */
/** {@inheritDoc} *
@Override
public final void refreshState() {
QuestBazaarPanel.refreshLastInstance();
}
} */
/* (non-Javadoc)
* @see forge.quest.gui.QuestAbstractPanel#refreshState()
*/
}

View File

@@ -1,247 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.quest.gui.bazaar;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import forge.AllZone;
import forge.quest.data.QuestData;
import forge.quest.data.bazaar.QuestStallDefinition;
import forge.quest.data.bazaar.QuestStallManager;
import forge.quest.data.bazaar.QuestStallPurchasable;
/**
* <p>
* QuestBazaarStall class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class QuestBazaarStall extends JPanel {
/** Constant <code>serialVersionUID=-4147745071116906043L</code>. */
private static final long serialVersionUID = -4147745071116906043L;
/** The name. */
private final String name;
/** The stall name. */
private final String stallName;
/** The fluff. */
private final String fluff;
/** The icon. */
private final ImageIcon icon;
private final JLabel creditLabel = new JLabel();
private final JPanel inventoryPanel = new JPanel();
/** The quest data. */
private final QuestData questData = AllZone.getQuestData();
/**
* <p>
* Constructor for QuestBazaarStall.
* </p>
*
* @param definition
* a {@link forge.quest.data.bazaar.QuestStallDefinition} object.
*/
protected QuestBazaarStall(final QuestStallDefinition definition) {
this.fluff = definition.getFluff();
this.icon = definition.getIcon();
this.stallName = definition.getDisplayName();
this.name = definition.getName();
this.initUI();
}
/**
* <p>
* initUI.
* </p>
*/
private void initUI() {
this.removeAll();
JLabel stallNameLabel;
final GridBagLayout layout = new GridBagLayout();
this.setLayout(layout);
stallNameLabel = new JLabel(this.stallName);
stallNameLabel.setFont(new Font("sserif", Font.BOLD, 22));
stallNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
this.creditLabel.setText("Credits: " + this.questData.getCredits());
this.creditLabel.setFont(new Font("sserif", 0, 14));
final JTextArea fluffArea = new JTextArea(this.fluff);
fluffArea.setFont(new Font("sserif", Font.ITALIC, 14));
fluffArea.setLineWrap(true);
fluffArea.setWrapStyleWord(true);
fluffArea.setOpaque(false);
fluffArea.setEditable(false);
fluffArea.setFocusable(false);
fluffArea.setPreferredSize(new Dimension(fluffArea.getPreferredSize().width, 40));
final GridBagConstraints constraints = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER,
GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0);
layout.setConstraints(stallNameLabel, constraints);
this.add(stallNameLabel);
constraints.gridy = 1;
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(fluffArea, constraints);
this.add(fluffArea);
constraints.gridy = 2;
layout.setConstraints(this.creditLabel, constraints);
this.add(this.creditLabel);
constraints.gridy = 3;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(10, 5, 10, 5);
constraints.weighty = 1;
constraints.weightx = GridBagConstraints.REMAINDER;
this.populateInventory(this.populateItems());
final JScrollPane scrollPane = new JScrollPane(this.inventoryPanel);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
layout.setConstraints(scrollPane, constraints);
this.add(scrollPane);
this.setBorder(new EmptyBorder(0, 5, 0, 0));
}
/**
* <p>
* populateInventory.
* </p>
*
* @param stallItems
* a {@link java.util.List} object.
*/
private void populateInventory(final java.util.List<QuestBazaarItem> stallItems) {
this.inventoryPanel.removeAll();
final GridBagLayout innerLayout = new GridBagLayout();
this.inventoryPanel.setLayout(innerLayout);
final GridBagConstraints innerConstraints = new GridBagConstraints(0, 0, 1, 1, 1, 0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0);
final JLabel purchaseLabel = new JLabel();
if (stallItems.size() == 0) {
purchaseLabel.setText("The merchant does not have anything useful for sale");
this.inventoryPanel.add(purchaseLabel);
innerConstraints.gridy++;
} else {
innerConstraints.insets = new Insets(5, 20, 5, 5);
for (final QuestBazaarItem item : stallItems) {
final JPanel itemPanel = item.getItemPanel();
innerLayout.setConstraints(itemPanel, innerConstraints);
this.inventoryPanel.add(itemPanel);
innerConstraints.gridy++;
}
}
innerConstraints.weighty = 1;
final JLabel fillLabel = new JLabel();
innerLayout.setConstraints(fillLabel, innerConstraints);
this.inventoryPanel.add(fillLabel);
}
/**
* <p>
* populateItems.
* </p>
*
* @return a {@link java.util.List} object.
*/
protected java.util.List<QuestBazaarItem> populateItems() {
final java.util.List<QuestBazaarItem> ret = new ArrayList<QuestBazaarItem>();
final java.util.List<QuestStallPurchasable> purchasables = QuestStallManager.getItems(this.name);
for (final QuestStallPurchasable purchasable : purchasables) {
ret.add(new QuestBazaarItem(purchasable));
}
return ret;
}
/**
* <p>
* getStallIcon.
* </p>
*
* @return a {@link javax.swing.ImageIcon} object.
*/
public ImageIcon getStallIcon() {
return this.icon;
}
/**
* <p>
* Getter for the field <code>stallName</code>.
* </p>
*
* @return a {@link java.lang.String} object.
*/
public String getStallName() {
return this.stallName;
}
/**
* <p>
* updateItems.
* </p>
*/
public void updateItems() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
QuestBazaarStall.this.populateInventory(QuestBazaarStall.this.populateItems());
QuestBazaarStall.this.creditLabel.setText("Credits: " + QuestBazaarStall.this.questData.getCredits());
QuestBazaarStall.this.inventoryPanel.invalidate();
QuestBazaarStall.this.inventoryPanel.repaint();
}
});
}
}

View File

@@ -0,0 +1,94 @@
package forge.view.bazaar;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
import forge.Command;
import forge.Singletons;
import forge.quest.data.bazaar.QuestStallManager;
import forge.view.toolbox.FLabel;
import forge.view.toolbox.FPanel;
import forge.view.toolbox.FSkin;
/** Lays out containers and borders for resizeable layout and
* instantiates top-level controller for bazaar UI. */
@SuppressWarnings("serial")
public class BazaarTopLevel extends FPanel {
private final FSkin skin;
private final JPanel pnlAllStalls;
private final ViewStall pnlSingleStall;
private FLabel previousSelected;
/** Lays out containers and borders for resizeable layout and
* instantiates top-level controller for bazaar UI. */
public BazaarTopLevel() {
super();
// Final inits
this.skin = Singletons.getView().getSkin();
this.pnlAllStalls = new JPanel();
this.pnlSingleStall = new ViewStall(this);
// Component styling
this.setBGTexture(skin.getIcon(FSkin.Backgrounds.BG_TEXTURE));
this.setLayout(new MigLayout("insets 0, gap 0"));
pnlAllStalls.setOpaque(false);
pnlAllStalls.setLayout(new MigLayout("insets 0, gap 0, wrap, align center"));
// Layout
this.add(pnlAllStalls, "w 25%!, h 100%!");
this.add(pnlSingleStall, "w 75%!, h 100%!");
// Populate all stalls, and select first one.
populateStalls();
((FLabel) pnlAllStalls.getComponent(0)).setSelected(true);
previousSelected = ((FLabel) pnlAllStalls.getComponent(0));
showStall(QuestStallManager.getStallNames().get(0));
}
private void populateStalls() {
for (final String s : QuestStallManager.getStallNames()) {
final FLabel lbl = new FLabel(s + " ", SwingConstants.RIGHT);
lbl.setIcon(QuestStallManager.getStall(s).getIcon());
lbl.setIconInBackground(true);
lbl.setFontScaleFactor(0.3);
lbl.setOpaque(true);
lbl.setHoverable(true);
lbl.setSelectable(true);
pnlAllStalls.add(lbl, "h 80px!, w 90%!, gap 0 0 10px 10px");
lbl.setCommand(new Command() {
@Override
public void execute() {
if (previousSelected != null) { previousSelected.setSelected(false); }
previousSelected = lbl;
showStall(s);
}
});
}
}
private void showStall(final String s0) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pnlSingleStall.setStall(QuestStallManager.getStall(s0));
pnlSingleStall.updateStall();
}
});
}
/** */
public void refreshLastInstance() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pnlSingleStall.updateStall();
}
});
}
}

View File

@@ -0,0 +1,96 @@
package forge.view.bazaar;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
import forge.AllZone;
import forge.Singletons;
import forge.quest.data.bazaar.QuestStallPurchasable;
import forge.view.GuiTopLevel;
import forge.view.toolbox.FLabel;
import forge.view.toolbox.FRoundedPanel;
import forge.view.toolbox.FSkin;
import forge.view.toolbox.FTextArea;
import forge.view.toolbox.SubButton;
/** An update-able panel instance representing a single item. */
@SuppressWarnings("serial")
public class ViewItem extends FRoundedPanel {
private final FLabel lblIcon, lblName, lblPrice;
private final FTextArea tarDesc;
private final SubButton btnPurchase;
private QuestStallPurchasable item;
/** An update-able panel instance representing a single item. */
public ViewItem() {
// Final inits
lblIcon = new FLabel();
lblName = new FLabel();
lblPrice = new FLabel();
tarDesc = new FTextArea();
btnPurchase = new SubButton("Buy");
// Component styling
this.setBackground(Singletons.getView().getSkin().getColor(FSkin.Colors.CLR_THEME).darker().darker());
this.lblName.setFontStyle(Font.BOLD);
this.lblPrice.setFontStyle(Font.BOLD);
this.lblPrice.setFontScaleFactor(0.8);
this.lblIcon.setIconInBackground(true);
this.lblIcon.setIconScaleFactor(1);
// Layout
this.setLayout(new MigLayout("insets 0, gap 0"));
this.add(lblIcon, "w 100px!, h n:90%:100px, ay center, span 1 3, gap 5px 5px 5px 5px");
this.add(lblName, "pushx, w 60%!, h 22px!, gap 0 0 5px 5px");
this.add(btnPurchase, "w 80px!, h 80px!, ay center, span 1 3, gap 0 15px 0 0, wrap");
this.add(tarDesc, "w 60%!, gap 0 0 0 10px, wrap");
this.add(lblPrice, "w 60%!, h 20px!, gap 0 0 0 5px");
btnPurchase.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
AllZone.getQuestData().subtractCredits(getItem().getBuyingPrice());
AllZone.getQuestData().addCredits(getItem().getSellingPrice());
getItem().onPurchase();
AllZone.getQuestData().saveData();
((GuiTopLevel) AllZone.getDisplay()).getController().getBazaarView().refreshLastInstance();
}
});
}
/** @param i0 &emsp; {@link forge.quest.data.bazaar.QuestStallPurchasable} */
public void setItem(QuestStallPurchasable i0) {
this.item = i0;
}
/** @return {@link forge.quest.data.bazaar.QuestStallPurchasable} */
public QuestStallPurchasable getItem() {
return this.item;
}
/** Updates this panel with current item stats. */
public void update() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
lblIcon.setIcon(getItem().getIcon());
lblName.setText(getItem().getPurchaseName());
lblPrice.setText("Cost: " + String.valueOf(getItem().getBuyingPrice()) + " credits");
tarDesc.setText(getItem().getPurchaseDescription());
if (AllZone.getQuestData().getCredits() < getItem().getBuyingPrice()) {
btnPurchase.setEnabled(false);
}
revalidate();
repaint();
}
});
}
}

View File

@@ -0,0 +1,180 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.view.bazaar;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import net.miginfocom.swing.MigLayout;
import forge.AllZone;
import forge.Singletons;
import forge.control.bazaar.ControlStall;
import forge.quest.data.bazaar.QuestStallDefinition;
import forge.quest.data.bazaar.QuestStallManager;
import forge.quest.data.bazaar.QuestStallPurchasable;
import forge.view.toolbox.FLabel;
import forge.view.toolbox.FScrollPane;
import forge.view.toolbox.FSkin;
/**
* <p>
* ViewStall class.
* </p>
*
* @author Forge
* @version $Id$
*/
@SuppressWarnings("serial")
public class ViewStall extends JPanel {
private final FSkin skin;
private final FLabel lblStallName, lblEmpty, lblStats;
private final JTextPane tpnFluff;
private final JPanel pnlInventory;
private final FScrollPane scrInventory;
private final ControlStall control;
private final BazaarTopLevel parentView;
private List<ViewItem> lstItemPanels;
private QuestStallDefinition stall;
/** @param v0 {@link forge.view.bazaar.BazaarTopLevel} */
protected ViewStall(final BazaarTopLevel v0) {
// Final/component inits
this.skin = Singletons.getView().getSkin();
this.lblStallName = new FLabel("", SwingConstants.CENTER);
this.lblEmpty = new FLabel("The merchant does not have anything useful for sale.", SwingConstants.CENTER);
this.lblStats = new FLabel();
this.tpnFluff = new JTextPane();
this.pnlInventory = new JPanel();
this.scrInventory = new FScrollPane(pnlInventory);
this.control = new ControlStall(this);
this.parentView = v0;
this.lstItemPanels = new ArrayList<ViewItem>();
// Component styling
this.setOpaque(false);
tpnFluff.setOpaque(false);
tpnFluff.setForeground(skin.getColor(FSkin.Colors.CLR_TEXT));
tpnFluff.setFont(skin.getItalicFont(15));
tpnFluff.setFocusable(false);
tpnFluff.setEditable(false);
tpnFluff.setBorder(null);
StyledDocument doc = tpnFluff.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
pnlInventory.setOpaque(false);
scrInventory.setBorder(null);
scrInventory.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrInventory.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
lblStats.setHorizontalAlignment(SwingConstants.CENTER);
lblStats.setFontScaleFactor(0.9);
// Layout
this.setLayout(new MigLayout("insets 0, gap 0, wrap, ay center"));
this.add(lblStallName, "w 90%!, h 40px!, gap 5% 0 10px 0");
this.add(tpnFluff, "w 90%!, h 20px!, gap 5% 0 10px 40px");
this.add(lblStats, "w 90%!, h 18px!, gap 5% 0 0 10px");
this.add(scrInventory, "w 95%!, h 70%!");
pnlInventory.setLayout(new MigLayout("insets 0, gap 0, wrap, alignx center, hidemode 3"));
pnlInventory.add(lblEmpty, "w 90%!, h 30px!, gap 5% 0 50px 50px");
}
/** @return {@link forge.view.toolbox.FLabel} */
public FLabel getLblStallName() {
return lblStallName;
}
/** @return {@link javax.swing.JTextPane} */
public JTextPane getTpnFluff() {
return tpnFluff;
}
/** @return {@link forge.view.toolbox.FLabel} */
public FLabel getLblStats() {
return lblStats;
}
/** @return {@link forge.view.toolbox.FScrollPane} */
public FScrollPane getScrInventory() {
return scrInventory;
}
/** @return {@link forge.control.bazaar.ControlStall} */
public ControlStall getController() {
return control;
}
/** @param q0 &emsp; {@link forge.quest.data.bazaar.QuestStallDefinition} */
public void setStall(QuestStallDefinition q0) {
this.stall = q0;
}
/**
* Updates/hides pre-existing panels with new inventory list,
* and creates new panels if necessary.
*/
public void updateStall() {
this.lblStats.setText(
"Credits: " + AllZone.getQuestData().getCredits()
+ " Life: " + AllZone.getQuestData().getLife());
final List<QuestStallPurchasable> items =
QuestStallManager.getItems(stall.getName());
lblStallName.setText(stall.getDisplayName());
tpnFluff.setText(stall.getFluff());
// Hide all components
for (Component i : this.pnlInventory.getComponents()) { i.setVisible(false); }
// No items available to purchase?
if (items.size() == 0) { lblEmpty.setVisible(true); return; }
for (int i = 0; i < items.size(); i++) {
// Add panel instances to match length of list, if necessary
if (this.lstItemPanels.size() == i) {
final ViewItem pnlItem = new ViewItem();
lstItemPanels.add(i, pnlItem);
pnlInventory.add(pnlItem, "w 90%!, gap 5% 0 0 10px");
}
lstItemPanels.get(i).setItem(items.get(i));
lstItemPanels.get(i).update();
lstItemPanels.get(i).setVisible(true);
}
}
/** @return {@link forge.view.bazaar.BazaarTopLevel} */
public BazaarTopLevel getParentView() {
return this.parentView;
}
}

View File

@@ -155,7 +155,8 @@ public class FLabel extends JLabel {
@Override
public void mouseClicked(MouseEvent e) {
if (!selectable) { return; }
selected = (selected ? false : true); repaint();
if (selected) { setSelected(false); }
else { setSelected(true); }
cmdClick.execute();
}
};
@@ -173,6 +174,12 @@ public class FLabel extends JLabel {
this.selectable = b0;
}
/** @param b0 &emsp; boolean */
public void setSelected(boolean b0) {
this.selected = b0;
repaint();
}
/** @param d0 &emsp; Scale factor for font size relative to label height, percent.
* If your font is "blowing up", try setting an explicity height/width for this label. */
public void setFontScaleFactor(final double d0) {
@@ -225,7 +232,7 @@ public class FLabel extends JLabel {
@Override
public void setIcon(final Icon i0) {
if (i0 == null) { return; }
if (i0 == null) { this.img = null; return; }
// Will need image (not icon) for scaled and non-scaled.
if (iconInBackground) { this.img = ((ImageIcon) i0).getImage(); }
// Will need image if not in background, but scaled.
@@ -245,6 +252,11 @@ public class FLabel extends JLabel {
this.cmdClick = c0;
}
/** @return {@link forge.Command} on click */
public Command getCommand() {
return this.cmdClick;
}
@Override
public void setOpaque(final boolean b0) {
// Must be overridden to allow drawing order of background, icon, string
@@ -267,6 +279,7 @@ public class FLabel extends JLabel {
g2d.setColor(clrActive);
g2d.fillRect(0, 0, w, h);
}
// Hover
if (hoverable && hovered && !selected) {
g2d.setColor(clrHover);

View File

@@ -229,6 +229,7 @@ public class FSkin {
ICO_MAP (new int[] {320, 560, 80, 80}), /** */
ICO_NOTES (new int[] {400, 560, 80, 80}), /** */
ICO_HEART (new int[] {480, 560, 80, 80}), /** */
ICO_BREW (new int[] {560, 560, 80, 80}), /** */
ICO_MINUS (new int[] {560, 640, 80, 80}), /** */
ICO_PLUS (new int[] {480, 640, 80, 80});