mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Add prompts to confirm buying and selling items in Spell Shop
This commit is contained in:
@@ -149,7 +149,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
|||||||
this.getBtnRemove().setEnabled(false);
|
this.getBtnRemove().setEnabled(false);
|
||||||
this.getBtnRemove4().setEnabled(false);
|
this.getBtnRemove4().setEnabled(false);
|
||||||
fullCatalogToggle.setText("Return to spell shop");
|
fullCatalogToggle.setText("Return to spell shop");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.getCatalogManager().setPool(cardsForSale);
|
this.getCatalogManager().setPool(cardsForSale);
|
||||||
this.getBtnAdd().setEnabled(true);
|
this.getBtnAdd().setEnabled(true);
|
||||||
this.getBtnRemove().setEnabled(true);
|
this.getBtnRemove().setEnabled(true);
|
||||||
@@ -286,6 +287,25 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final String getItemDisplayType(InventoryItem item) {
|
||||||
|
if (item instanceof PaperCard) {
|
||||||
|
return "Card";
|
||||||
|
}
|
||||||
|
if (item instanceof BoosterPack) {
|
||||||
|
return "Booster Pack";
|
||||||
|
}
|
||||||
|
if (item instanceof TournamentPack) {
|
||||||
|
return "Tournament Pack";
|
||||||
|
}
|
||||||
|
if (item instanceof FatPack) {
|
||||||
|
return "Fat Pack";
|
||||||
|
}
|
||||||
|
if (item instanceof PreconDeck) {
|
||||||
|
return "Preconstructed Deck";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
//=========== Overridden from ACEditorBase
|
//=========== Overridden from ACEditorBase
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -303,11 +323,21 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
|||||||
|
|
||||||
for (Entry<InventoryItem, Integer> itemEntry : items) {
|
for (Entry<InventoryItem, Integer> itemEntry : items) {
|
||||||
final InventoryItem item = itemEntry.getKey();
|
final InventoryItem item = itemEntry.getKey();
|
||||||
|
final String displayType = getItemDisplayType(item);
|
||||||
|
if (displayType == null) { continue; } //don't remove item from Catalog if unsupported type
|
||||||
|
|
||||||
final int qty = itemEntry.getValue();
|
final int qty = itemEntry.getValue();
|
||||||
final int value = this.getCardValue(item);
|
final int value = this.getCardValue(item);
|
||||||
|
final int totalCost = qty * value;
|
||||||
|
final String title = "Buy " + displayType;
|
||||||
|
final String promptSuffix = " credits to purchase " + (qty == 1 ? "'" : qty + " copies of '") + item.getName() + "'";
|
||||||
|
|
||||||
if (value > this.questData.getAssets().getCredits()) {
|
if (totalCost > this.questData.getAssets().getCredits()) {
|
||||||
FOptionPane.showMessageDialog("Not enough credits to purchase " + (qty == 1 ? "" : qty + " copies of ") + item.getName() + ".");
|
FOptionPane.showMessageDialog("Not enough" + promptSuffix + ".", title);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!FOptionPane.showConfirmDialog("Pay " + totalCost + promptSuffix + "?", title, "Buy", "Cancel")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,8 +403,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
|||||||
protected void onRemoveItems(Iterable<Entry<InventoryItem, Integer>> items, boolean toAlternate) {
|
protected void onRemoveItems(Iterable<Entry<InventoryItem, Integer>> items, boolean toAlternate) {
|
||||||
if (showingFullCatalog || toAlternate) { return; }
|
if (showingFullCatalog || toAlternate) { return; }
|
||||||
|
|
||||||
this.getCatalogManager().addItems(items);
|
List<Entry<InventoryItem, Integer>> itemsToRemove = new ArrayList<Entry<InventoryItem, Integer>>();
|
||||||
this.getDeckManager().removeItems(items);
|
|
||||||
|
|
||||||
for (Entry<InventoryItem, Integer> itemEntry : items) {
|
for (Entry<InventoryItem, Integer> itemEntry : items) {
|
||||||
final InventoryItem item = itemEntry.getKey();
|
final InventoryItem item = itemEntry.getKey();
|
||||||
@@ -382,10 +411,24 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
|||||||
final PaperCard card = (PaperCard) item;
|
final PaperCard card = (PaperCard) item;
|
||||||
final int qty = itemEntry.getValue();
|
final int qty = itemEntry.getValue();
|
||||||
final int price = Math.min((int) (this.multiplier * this.getCardValue(card)), this.questData.getCards().getSellPriceLimit());
|
final int price = Math.min((int) (this.multiplier * this.getCardValue(card)), this.questData.getCards().getSellPriceLimit());
|
||||||
|
final int totalReceived = price * qty;
|
||||||
|
|
||||||
|
if (!FOptionPane.showConfirmDialog("Sell " + (qty == 1 ? "'" : qty + " copies of '") +
|
||||||
|
item.getName() + "' for " + totalReceived + " credit" + (totalReceived != 1 ? "s" : "") + "?",
|
||||||
|
"Sell Card", "Sell", "Cancel")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
this.questData.getCards().sellCard(card, qty, price);
|
this.questData.getCards().sellCard(card, qty, price);
|
||||||
|
itemsToRemove.add(itemEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (itemsToRemove.isEmpty()) { return; }
|
||||||
|
|
||||||
|
this.getCatalogManager().addItems(itemsToRemove);
|
||||||
|
this.getDeckManager().removeItems(itemsToRemove);
|
||||||
|
|
||||||
this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits());
|
this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,10 +29,18 @@ public class FOptionPane extends FDialog {
|
|||||||
showMessageDialog(message, "Forge", INFORMATION_ICON);
|
showMessageDialog(message, "Forge", INFORMATION_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showMessageDialog(String message, String title) {
|
||||||
|
showMessageDialog(message, title, INFORMATION_ICON);
|
||||||
|
}
|
||||||
|
|
||||||
public static void showErrorMessageDialog(String message) {
|
public static void showErrorMessageDialog(String message) {
|
||||||
showMessageDialog(message, "Forge", ERROR_ICON);
|
showMessageDialog(message, "Forge", ERROR_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showErrorMessageDialog(String message, String title) {
|
||||||
|
showMessageDialog(message, title, ERROR_ICON);
|
||||||
|
}
|
||||||
|
|
||||||
public static void showMessageDialog(String message, String title, SkinImage icon) {
|
public static void showMessageDialog(String message, String title, SkinImage icon) {
|
||||||
showOptionDialog(message, title, icon, new String[] {"OK"}, 0);
|
showOptionDialog(message, title, icon, new String[] {"OK"}, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user