mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Fixed stall refresh issue.
This commit is contained in:
@@ -9,28 +9,31 @@ import javax.swing.*;
|
|||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public abstract class QuestAbstractBazaarStall extends JPanel implements NewConstants{
|
public abstract class QuestAbstractBazaarStall extends JPanel implements NewConstants {
|
||||||
private static final long serialVersionUID = -4147745071116906043L;
|
private static final long serialVersionUID = -4147745071116906043L;
|
||||||
String stallName;
|
String stallName;
|
||||||
String fluff;
|
String fluff;
|
||||||
ImageIcon icon;
|
ImageIcon icon;
|
||||||
|
|
||||||
|
|
||||||
|
private JPanel inventoryPanel = new JPanel();
|
||||||
|
|
||||||
private JPanel inventoryPanel;
|
protected QuestData questData = AllZone.QuestData;
|
||||||
|
|
||||||
protected QuestData questData = AllZone.QuestData;
|
|
||||||
|
|
||||||
protected QuestAbstractBazaarStall(String stallName, String iconName, String fluff) {
|
protected QuestAbstractBazaarStall(String stallName, String iconName, String fluff) {
|
||||||
this.fluff = fluff;
|
this.fluff = fluff;
|
||||||
this.icon = GuiUtils.getIconFromFile(iconName);
|
this.icon = GuiUtils.getIconFromFile(iconName);
|
||||||
this.stallName = stallName;
|
this.stallName = stallName;
|
||||||
|
|
||||||
|
initUI();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initUI() {
|
||||||
JLabel stallNameLabel;
|
JLabel stallNameLabel;
|
||||||
JLabel creditLabel;
|
JLabel creditLabel;
|
||||||
|
|
||||||
|
|
||||||
GridBagLayout layout = new GridBagLayout();
|
GridBagLayout layout = new GridBagLayout();
|
||||||
this.setLayout(layout);
|
this.setLayout(layout);
|
||||||
|
|
||||||
stallNameLabel = new JLabel(stallName);
|
stallNameLabel = new JLabel(stallName);
|
||||||
@@ -48,91 +51,106 @@ public abstract class QuestAbstractBazaarStall extends JPanel implements NewCons
|
|||||||
fluffArea.setEditable(false);
|
fluffArea.setEditable(false);
|
||||||
fluffArea.setFocusable(false);
|
fluffArea.setFocusable(false);
|
||||||
|
|
||||||
GridBagConstraints constraints = new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(2,2,2,2), 0,0);
|
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);
|
layout.setConstraints(stallNameLabel, constraints);
|
||||||
this.add(stallNameLabel);
|
this.add(stallNameLabel);
|
||||||
|
|
||||||
constraints.gridy=1;
|
constraints.gridy = 1;
|
||||||
constraints.anchor = GridBagConstraints.WEST;
|
constraints.anchor = GridBagConstraints.WEST;
|
||||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||||
layout.setConstraints(fluffArea, constraints);
|
layout.setConstraints(fluffArea, constraints);
|
||||||
this.add(fluffArea);
|
this.add(fluffArea);
|
||||||
|
|
||||||
constraints.gridy=2;
|
constraints.gridy = 2;
|
||||||
layout.setConstraints(creditLabel, constraints);
|
layout.setConstraints(creditLabel, constraints);
|
||||||
this.add(creditLabel);
|
this.add(creditLabel);
|
||||||
|
|
||||||
java.util.List<QuestAbstractBazaarItem> stallItems = populateItems();
|
java.util.List<QuestAbstractBazaarItem> stallItems = populateItems();
|
||||||
|
|
||||||
if (stallItems == null || stallItems.size() == 0){
|
if (stallItems == null || stallItems.size() == 0) {
|
||||||
//TODO: Get stall-specific fluff in here.
|
//TODO: Get stall-specific fluff in here.
|
||||||
constraints.gridy=3;
|
constraints.gridy = 3;
|
||||||
constraints.anchor=GridBagConstraints.NORTHWEST;
|
constraints.anchor = GridBagConstraints.NORTHWEST;
|
||||||
constraints.fill=GridBagConstraints.BOTH;
|
constraints.fill = GridBagConstraints.BOTH;
|
||||||
|
|
||||||
JLabel noSaleLabel = new JLabel("This stall does not offer anything useful for purchase.");
|
JLabel noSaleLabel = new JLabel("This stall does not offer anything useful for purchase.");
|
||||||
layout.setConstraints(noSaleLabel,constraints);
|
layout.setConstraints(noSaleLabel, constraints);
|
||||||
this.add(noSaleLabel);
|
this.add(noSaleLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else {
|
||||||
constraints.gridy++;
|
constraints.gridy=3;
|
||||||
constraints.insets = new Insets(10,5,10,5);
|
constraints.insets = new Insets(10, 5, 10, 5);
|
||||||
JLabel saleLabel = new JLabel("The following items are for sale:");
|
JLabel saleLabel = new JLabel("The following items are for sale:");
|
||||||
|
|
||||||
layout.setConstraints(saleLabel,constraints);
|
layout.setConstraints(saleLabel, constraints);
|
||||||
this.add(saleLabel);
|
this.add(saleLabel);
|
||||||
|
|
||||||
constraints.insets = new Insets(10,5,10,5);
|
constraints.insets = new Insets(10, 5, 10, 5);
|
||||||
|
|
||||||
constraints.anchor=GridBagConstraints.NORTHWEST;
|
constraints.anchor = GridBagConstraints.NORTHWEST;
|
||||||
constraints.fill=GridBagConstraints.HORIZONTAL;
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||||
constraints.weighty = 1;
|
constraints.weighty = 1;
|
||||||
constraints.weightx = GridBagConstraints.REMAINDER;
|
constraints.weightx = GridBagConstraints.REMAINDER;
|
||||||
constraints.fill = GridBagConstraints.BOTH;
|
constraints.fill = GridBagConstraints.BOTH;
|
||||||
constraints.gridy++;
|
constraints.gridy++;
|
||||||
|
|
||||||
|
|
||||||
inventoryPanel = new JPanel();
|
|
||||||
|
|
||||||
populateInventory(stallItems);
|
populateInventory(stallItems);
|
||||||
|
|
||||||
inventoryPanel.setBorder(new LineBorder(Color.ORANGE,2));
|
inventoryPanel.setBorder(new LineBorder(Color.ORANGE, 2));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(inventoryPanel);
|
JScrollPane scrollPane = new JScrollPane(inventoryPanel);
|
||||||
layout.setConstraints(scrollPane,constraints);
|
layout.setConstraints(scrollPane, constraints);
|
||||||
this.add(scrollPane);
|
this.add(scrollPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateInventory(java.util.List<QuestAbstractBazaarItem> stallItems) {
|
private void populateInventory(java.util.List<QuestAbstractBazaarItem> stallItems) {
|
||||||
|
inventoryPanel = new JPanel();
|
||||||
GridBagLayout innerLayout = new GridBagLayout();
|
GridBagLayout innerLayout = new GridBagLayout();
|
||||||
inventoryPanel.setLayout(innerLayout);
|
inventoryPanel.setLayout(innerLayout);
|
||||||
GridBagConstraints innerConstraints =
|
GridBagConstraints innerConstraints =
|
||||||
new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL,new Insets(2,2,2,2), 0, 0);
|
new GridBagConstraints(0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
GridBagConstraints.NORTHWEST,
|
||||||
|
GridBagConstraints.HORIZONTAL,
|
||||||
|
new Insets(2, 2, 2, 2),
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
|
||||||
for (QuestAbstractBazaarItem item : stallItems) {
|
for (QuestAbstractBazaarItem item : stallItems) {
|
||||||
JPanel itemPanel = item.getItemPanel();
|
JPanel itemPanel = item.getItemPanel();
|
||||||
|
|
||||||
innerLayout.setConstraints(itemPanel,innerConstraints);
|
innerLayout.setConstraints(itemPanel, innerConstraints);
|
||||||
inventoryPanel.add(itemPanel);
|
inventoryPanel.add(itemPanel);
|
||||||
innerConstraints.gridy++;
|
innerConstraints.gridy++;
|
||||||
}
|
}
|
||||||
|
|
||||||
innerConstraints.weighty=1;
|
innerConstraints.weighty = 1;
|
||||||
JLabel fillLabel = new JLabel();
|
JLabel fillLabel = new JLabel();
|
||||||
|
|
||||||
innerLayout.setConstraints(fillLabel,innerConstraints);
|
innerLayout.setConstraints(fillLabel, innerConstraints);
|
||||||
inventoryPanel.add(fillLabel);
|
inventoryPanel.add(fillLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract java.util.List<QuestAbstractBazaarItem> populateItems();
|
protected abstract java.util.List<QuestAbstractBazaarItem> populateItems();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ImageIcon getStallIcon() {
|
public ImageIcon getStallIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
@@ -142,7 +160,7 @@ public abstract class QuestAbstractBazaarStall extends JPanel implements NewCons
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateItems() {
|
public void updateItems() {
|
||||||
this.inventoryPanel.removeAll();
|
this.removeAll();
|
||||||
this.populateInventory(populateItems());
|
this.initUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user