Show dialog based on wheel outcome

This commit is contained in:
drdev
2016-01-10 23:10:36 +00:00
parent 5be985af76
commit aa7217a666
12 changed files with 124 additions and 51 deletions

View File

@@ -6,7 +6,6 @@ import java.awt.Font;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
@@ -26,7 +25,6 @@ import forge.gui.SOverlayUtils;
import forge.interfaces.IWinLoseView;
import forge.item.PaperCard;
import forge.model.FModel;
import forge.planarconquest.ConquestReward;
import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FButton;
import forge.toolbox.FLabel;
@@ -285,19 +283,6 @@ public class ViewWinLose implements IWinLoseView<FButton> {
}
}
@Override
public void showConquestRewards(String title, List<ConquestReward> rewards) {
//TODO: Make this nicer, for now just re-use showCards
List<PaperCard> cards = new ArrayList<PaperCard>();
for (int i = rewards.size() - 1; i >= 0; i--) { //loop backwards so mythics/rares go back to appearing first
ConquestReward reward = rewards.get(i);
if (!reward.isDuplicate()) {
cards.add(reward.getCard());
}
}
showCards(title, cards);
}
@Override
public void showMessage(String message, final String title, final FSkinProp icon) {
final SkinIcon icoTemp = FSkin.getIcon(icon).scale(0.5);

View File

@@ -32,7 +32,7 @@ public class GameEntityPicker extends TabPageScreen<GameEntityPicker> {
setHeight(FOptionPane.getMaxDisplayObjHeight());
optionPane = new FOptionPane(null, title, null, this,
optionPane = new FOptionPane(null, null, title, null, this,
isOptional ? ImmutableList.of("OK", "Cancel") : ImmutableList.of("OK"), 0, new Callback<Integer>() {
@Override
public void run(Integer result) {

View File

@@ -98,7 +98,7 @@ public class FDeckChooser extends FScreen {
container.add(deckChooser.lstDecks);
container.setHeight(FOptionPane.getMaxDisplayObjHeight());
deckChooser.optionPane = new FOptionPane(null, title, null, container, ImmutableList.of("OK", "Cancel"), 0, new Callback<Integer>() {
deckChooser.optionPane = new FOptionPane(null, null, title, null, container, ImmutableList.of("OK", "Cancel"), 0, new Callback<Integer>() {
@Override
public void run(Integer result) {
if (result == 0) {

View File

@@ -20,8 +20,6 @@ import forge.interfaces.IWinLoseView;
import forge.item.PaperCard;
import forge.menu.FMagnifyView;
import forge.model.FModel;
import forge.planarconquest.ConquestReward;
import forge.screens.planarconquest.ConquestRewardDialog;
import forge.toolbox.FButton;
import forge.toolbox.FContainer;
import forge.toolbox.FDisplayObject;
@@ -236,11 +234,6 @@ public class ViewWinLose extends FOverlay implements IWinLoseView<FButton> {
SGuiChoose.reveal(title, cards);
}
@Override
public void showConquestRewards(String title, List<ConquestReward> rewards) {
ConquestRewardDialog.show(title, rewards);
}
@Override
public void showMessage(String message, String title, FSkinProp icon) {
SOptionPane.showMessageDialog(message, title, icon);

View File

@@ -73,7 +73,7 @@ public class ConquestAEtherScreen extends FScreen {
PaperCard card = Aggregates.random(lstAEther.getFilteredItems()).getKey();
lstAEther.removeItem(card, 1);
ConquestRewardDialog.show("Card pulled from the AEther", card);
ConquestRewardDialog.show("Card pulled from the AEther", card, null);
model.spendAEtherShards(shardCost);
model.unlockCard(card);

View File

@@ -6,7 +6,7 @@ import forge.Graphics;
import forge.animation.ForgeAnimation;
import forge.assets.FSkinImage;
import forge.assets.FSkinTexture;
import forge.planarconquest.ConquestEvent.ConquestEventReward;
import forge.planarconquest.ConquestEvent.ChaosWheelOutcome;
import forge.toolbox.FOptionPane;
import forge.toolbox.FOverlay;
import forge.util.Aggregates;
@@ -15,15 +15,15 @@ import forge.util.PhysicsObject;
import forge.util.ThreadUtil;
public class ConquestChaosWheel extends FOverlay {
public static void spin(Callback<ConquestEventReward> callback0) {
public static void spin(Callback<ChaosWheelOutcome> callback0) {
ConquestChaosWheel wheel = new ConquestChaosWheel(callback0);
wheel.show();
}
private final WheelSpinAnimation animation = new WheelSpinAnimation();
private final Callback<ConquestEventReward> callback;
private final Callback<ChaosWheelOutcome> callback;
private ConquestChaosWheel(Callback<ConquestEventReward> callback0) {
private ConquestChaosWheel(Callback<ChaosWheelOutcome> callback0) {
callback = callback0;
}
@@ -85,7 +85,7 @@ public class ConquestChaosWheel extends FOverlay {
@Override
public void run() {
hide();
callback.run(ConquestEventReward.getReward(getWheelRotation()));
callback.run(ChaosWheelOutcome.getWheelOutcome(getWheelRotation()));
}
});
}

View File

@@ -11,21 +11,24 @@ import forge.Graphics;
import forge.animation.ForgeAnimation;
import forge.assets.FImage;
import forge.assets.FSkinColor;
import forge.assets.FSkinFont;
import forge.assets.FSkinImage;
import forge.card.CardDetailUtil;
import forge.card.CardRenderer;
import forge.card.CardDetailUtil.DetailColors;
import forge.model.FModel;
import forge.planarconquest.ConquestData;
import forge.planarconquest.ConquestEvent.ChaosWheelOutcome;
import forge.planarconquest.ConquestEvent.ConquestEventRecord;
import forge.planarconquest.ConquestEvent;
import forge.planarconquest.ConquestEvent.ConquestEventReward;
import forge.planarconquest.ConquestLocation;
import forge.planarconquest.ConquestPlane;
import forge.planarconquest.ConquestPlane.Region;
import forge.planarconquest.ConquestPreferences.CQPref;
import forge.planarconquest.ConquestPlaneData;
import forge.screens.FScreen;
import forge.toolbox.FDisplayObject;
import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane;
import forge.util.Callback;
import forge.util.Utils;
@@ -83,14 +86,95 @@ public class ConquestMultiverseScreen extends FScreen {
}
private void spinChaosWheel() {
ConquestChaosWheel.spin(new Callback<ConquestEventReward>() {
ConquestChaosWheel.spin(new Callback<ChaosWheelOutcome>() {
@Override
public void run(ConquestEventReward reward) {
System.out.println(reward);
public void run(ChaosWheelOutcome outcome) {
switch (outcome) {
case BOOSTER:
awardBooster(false);
break;
case DOUBLE_BOOSTER:
awardBooster(true);
break;
case SHARDS:
awardShards(FModel.getConquestPreferences().getPrefInt(CQPref.AETHER_WHEEL_SHARDS), false);
break;
case DOUBLE_SHARDS:
awardShards(2 * FModel.getConquestPreferences().getPrefInt(CQPref.AETHER_WHEEL_SHARDS), false);
break;
case PLANESWALK:
awardPlaneswalkCharge();
break;
case CHAOS:
triggerChaosTravel();
break;
}
}
});
}
private void awardBooster(final boolean bonusBooster) {
final int shardsBefore = model.getAEtherShards();
ConquestRewardDialog.show("Received Booster Pack" + (bonusBooster ? "\n(1 of 2)" : ""),
FModel.getConquest().awardBooster(), new Runnable() {
@Override
public void run() {
final Runnable alertShardsFromDuplicates = new Runnable() {
@Override
public void run() {
final int shardsReceived = model.getAEtherShards() - shardsBefore;
if (shardsReceived > 0) {
awardShards(shardsReceived, true);
}
}
};
if (bonusBooster) {
ConquestRewardDialog.show("Received Booster Pack\n(2 of 2)", FModel.getConquest().awardBooster(), alertShardsFromDuplicates);
}
else {
alertShardsFromDuplicates.run();
}
}
});
}
private static final FImage SHARD_IMAGE = new FImage() {
final float size = Forge.getScreenWidth() * 0.6f;
@Override
public float getWidth() {
return size;
}
@Override
public float getHeight() {
return size;
}
@Override
public void draw(Graphics g, float x, float y, float w, float h) {
FSkinImage.AETHER_SHARD.draw(g, x, y, w, h);
}
};
private void awardShards(int shards, boolean fromDuplicateCards) {
String message = "Received AEther Shards";
if (fromDuplicateCards) {
message += " for Duplicate Cards";
}
else { //if from duplicate cards, shards already added to model
model.rewardAEtherShards(shards);
}
FOptionPane.showMessageDialog(String.valueOf(shards), FSkinFont.get(32), message, SHARD_IMAGE);
}
private void awardPlaneswalkCharge() {
//TODO
FOptionPane.showMessageDialog(null, "Received Planeswalk Charge");
}
private void triggerChaosTravel() {
//TODO
FOptionPane.showMessageDialog(null, "Chaos Travel");
}
private class PlaneGrid extends FScrollPane {
private MoveAnimation activeMoveAnimation;
private BadgeAnimation activeBadgeAnimation;

View File

@@ -28,26 +28,28 @@ import forge.util.Utils;
public class ConquestRewardDialog extends FScrollPane {
private static final float PADDING = Utils.scale(5);
public static void show(String title, PaperCard card) {
public static void show(String title, PaperCard card, Runnable callback0) {
List<ConquestReward> rewards = new ArrayList<ConquestReward>(1);
rewards.add(new ConquestReward(card, 0));
show(title, rewards);
show(title, rewards, callback0);
}
public static void show(String title, Iterable<ConquestReward> rewards) {
ConquestRewardDialog revealer = new ConquestRewardDialog(title, rewards);
public static void show(String title, Iterable<ConquestReward> rewards, Runnable callback0) {
ConquestRewardDialog revealer = new ConquestRewardDialog(title, rewards, callback0);
revealer.dialog.show();
}
private final RevealDialog dialog;
private final List<CardRevealer> cardRevealers = new ArrayList<CardRevealer>();
private final CardRevealAnimation animation;
private final Runnable callback;
private int columnCount;
private float totalZoomAmount;
private CardRevealer focalCard;
private ConquestRewardDialog(String title, Iterable<ConquestReward> rewards) {
private ConquestRewardDialog(String title, Iterable<ConquestReward> rewards, Runnable callback0) {
dialog = new RevealDialog(title);
callback = callback0;
for (ConquestReward reward : rewards) {
cardRevealers.add(this.add(new CardRevealer(reward)));
@@ -167,6 +169,9 @@ public class ConquestRewardDialog extends FScrollPane {
@Override
public void handleEvent(FEvent e) {
hide();
if (callback != null) {
callback.run();
}
}
});
initButton(1, "Skip", new FEventHandler() {

View File

@@ -58,6 +58,10 @@ public class FOptionPane extends FDialog {
showOptionDialog(message, title, icon, ImmutableList.of("OK"), 0, null);
}
public static void showMessageDialog(final String message, FSkinFont messageFont, final String title, final FImage icon) {
showOptionDialog(message, messageFont, title, icon, ImmutableList.of("OK"), 0, null);
}
public static void showMessageDialog(final String message, final String title, final FImage icon, final Callback<Integer> callback) {
showOptionDialog(message, title, icon, ImmutableList.of("OK"), 0, callback);
}
@@ -93,7 +97,11 @@ public class FOptionPane extends FDialog {
}
public static void showOptionDialog(final String message, final String title, final FImage icon, final List<String> options, final int defaultOption, final Callback<Integer> callback) {
final FOptionPane optionPane = new FOptionPane(message, title, icon, null, options, defaultOption, callback);
showOptionDialog(message, null, title, icon, options, defaultOption, callback);
}
public static void showOptionDialog(final String message, final FSkinFont messageFont, final String title, final FImage icon, final List<String> options, final int defaultOption, final Callback<Integer> callback) {
final FOptionPane optionPane = new FOptionPane(message, messageFont, title, icon, null, options, defaultOption, callback);
optionPane.show();
}
@@ -143,7 +151,7 @@ public class FOptionPane extends FDialog {
icon = null;
}
final FOptionPane optionPane = new FOptionPane(message, title, icon, cardDisplay, options, defaultOption, callback);
final FOptionPane optionPane = new FOptionPane(message, null, title, icon, cardDisplay, options, defaultOption, callback);
optionPane.show();
}
@@ -181,7 +189,7 @@ public class FOptionPane extends FDialog {
container.add(inputField);
container.setHeight(inputField.getHeight() + padTop + PADDING);
final FOptionPane optionPane = new FOptionPane(message, title, null, container, ImmutableList.of("OK", "Cancel"), 0, new Callback<Integer>() {
final FOptionPane optionPane = new FOptionPane(message, null, title, null, container, ImmutableList.of("OK", "Cancel"), 0, new Callback<Integer>() {
@SuppressWarnings("unchecked")
@Override
public void run(final Integer result) {
@@ -224,7 +232,7 @@ public class FOptionPane extends FDialog {
private final int defaultOption;
private final boolean centerIcon;
public FOptionPane(final String message, final String title, final FImage icon, final FDisplayObject displayObj0, final List<String> options, final int defaultOption0, final Callback<Integer> callback0) {
public FOptionPane(final String message, final FSkinFont messageFont, final String title, final FImage icon, final FDisplayObject displayObj0, final List<String> options, final int defaultOption0, final Callback<Integer> callback0) {
super(title, options.size());
if (icon != null) {
@@ -241,7 +249,7 @@ public class FOptionPane extends FDialog {
if (message != null) {
prompt = add(new FTextArea(true, message));
prompt.setFont(FSkinFont.get(12));
prompt.setFont(messageFont != null ? messageFont : FSkinFont.get(12));
if (centerIcon || centerPrompt()) {
prompt.setAlignment(HAlignment.CENTER);
}

View File

@@ -142,7 +142,7 @@ public class ListChooser<T> extends FContainer {
updateHeight();
optionPane = new FOptionPane(null, title, null, this, options, 0, new Callback<Integer>() {
optionPane = new FOptionPane(null, null, title, null, this, options, 0, new Callback<Integer>() {
@Override
public void run(Integer result) {
called = false;

View File

@@ -4,7 +4,6 @@ import java.util.List;
import forge.assets.FSkinProp;
import forge.item.PaperCard;
import forge.planarconquest.ConquestReward;
public interface IWinLoseView<T extends IButton> {
T getBtnContinue();
@@ -14,6 +13,5 @@ public interface IWinLoseView<T extends IButton> {
void showRewards(Runnable runnable);
void showCards(String title, List<PaperCard> cards);
void showConquestRewards(String title, List<ConquestReward> rewards);
void showMessage(String message, String title, FSkinProp icon);
}

View File

@@ -123,7 +123,7 @@ public abstract class ConquestEvent {
}
}
public enum ConquestEventReward {
public enum ChaosWheelOutcome {
BOOSTER,
DOUBLE_BOOSTER,
SHARDS,
@@ -131,12 +131,12 @@ public abstract class ConquestEvent {
PLANESWALK,
CHAOS;
private static final ConquestEventReward[] wheelSpots = new ConquestEventReward[] {
private static final ChaosWheelOutcome[] wheelSpots = new ChaosWheelOutcome[] {
CHAOS, BOOSTER, SHARDS, DOUBLE_BOOSTER, PLANESWALK, BOOSTER, DOUBLE_SHARDS, BOOSTER
};
private static final float ANGLE_PER_SPOT = 360f / wheelSpots.length;
public static ConquestEventReward getReward(float wheelRotation) {
public static ChaosWheelOutcome getWheelOutcome(float wheelRotation) {
if (wheelRotation < 0) {
wheelRotation += 360f;
}