Support determining reward based on wheel rotation

This commit is contained in:
drdev
2016-01-10 21:43:39 +00:00
parent f0e6bdb306
commit 611688c9bc
3 changed files with 45 additions and 5 deletions

View File

@@ -6,21 +6,25 @@ import forge.Graphics;
import forge.animation.ForgeAnimation;
import forge.assets.FSkinImage;
import forge.assets.FSkinTexture;
import forge.planarconquest.ConquestEvent.ConquestEventReward;
import forge.toolbox.FOptionPane;
import forge.toolbox.FOverlay;
import forge.util.Aggregates;
import forge.util.Callback;
import forge.util.PhysicsObject;
import forge.util.ThreadUtil;
public class ConquestChaosWheel extends FOverlay {
public static void spin() {
ConquestChaosWheel wheel = new ConquestChaosWheel();
public static void spin(Callback<ConquestEventReward> callback0) {
ConquestChaosWheel wheel = new ConquestChaosWheel(callback0);
wheel.show();
}
private final WheelSpinAnimation animation = new WheelSpinAnimation();
private final Callback<ConquestEventReward> callback;
private ConquestChaosWheel() {
private ConquestChaosWheel(Callback<ConquestEventReward> callback0) {
callback = callback0;
}
@Override
@@ -81,8 +85,14 @@ public class ConquestChaosWheel extends FOverlay {
@Override
public void run() {
hide();
callback.run(ConquestEventReward.getReward(getWheelRotation()));
}
});
}
}
@Override
public boolean keyDown(int keyCode) {
return true; //suppress key pressing while this overlay is open
}
}

View File

@@ -19,6 +19,7 @@ import forge.model.FModel;
import forge.planarconquest.ConquestData;
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;
@@ -82,7 +83,12 @@ public class ConquestMultiverseScreen extends FScreen {
}
private void spinChaosWheel() {
ConquestChaosWheel.spin();
ConquestChaosWheel.spin(new Callback<ConquestEventReward>() {
@Override
public void run(ConquestEventReward reward) {
System.out.println(reward);
}
});
}
private class PlaneGrid extends FScrollPane {
@@ -403,7 +409,9 @@ public class ConquestMultiverseScreen extends FScreen {
@Override
protected void onEnd(boolean endingAll) {
activeBadgeAnimation = null;
spinChaosWheel(); //spin Chaos Wheel after badge positioned
if (!endingAll) {
spinChaosWheel(); //spin Chaos Wheel after badge positioned
}
}
}
}

View File

@@ -122,4 +122,26 @@ public abstract class ConquestEvent {
return -1;
}
}
public enum ConquestEventReward {
BOOSTER,
DOUBLE_BOOSTER,
SHARDS,
DOUBLE_SHARDS,
PLANESWALK,
CHAOS;
private static final ConquestEventReward[] wheelSpots = new ConquestEventReward[] {
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) {
if (wheelRotation < 0) {
wheelRotation += 360f;
}
int spot = (int)(wheelRotation / ANGLE_PER_SPOT);
return wheelSpots[spot];
}
}
}