Add some delays to the end day process and make it so commanders selected in order

This commit is contained in:
drdev
2014-12-08 03:47:20 +00:00
parent 3c2dffe1c4
commit 1888d201e3
3 changed files with 45 additions and 10 deletions

View File

@@ -86,7 +86,27 @@ public class CommandCenterScreen extends FScreen implements IVCommandCenter {
public void updateCurrentDay() { public void updateCurrentDay() {
lblCurrentPlane.setText("Plane - " + model.getCurrentPlane().getName()); lblCurrentPlane.setText("Plane - " + model.getCurrentPlane().getName());
btnEndDay.setText("End Day " + model.getDay()); btnEndDay.setText("End Day " + model.getDay());
regionDisplay.onRegionChanged(); //simulate region change when day changes to ensure everything is updated
commanderRow.selectedIndex = 0; //select first commander at the beginning of each day
ConquestCommander commander = commanderRow.panels[0].commander;
if (commander != null && commander.getDeployedRegion() != null) {
model.setCurrentRegion(commander.getDeployedRegion());
}
regionDisplay.onRegionChanged(); //simulate region change when day changes to ensure everything is updated, even if region didn't change
}
@Override
public boolean setSelectedCommander(ConquestCommander commander) {
int newIndex = model.getCurrentPlaneData().getCommanders().indexOf(commander);
boolean changed = commanderRow.selectedIndex != newIndex;
commanderRow.selectedIndex = newIndex;
if (commander.getDeployedRegion() != null) {
if (model.setCurrentRegion(commander.getDeployedRegion())) {
regionDisplay.onRegionChanged();
changed = true; //if region changed, always return true
}
}
return changed;
} }
@Override @Override
@@ -267,11 +287,11 @@ public class CommandCenterScreen extends FScreen implements IVCommandCenter {
if (model.setCurrentRegion(commander.getDeployedRegion())) { if (model.setCurrentRegion(commander.getDeployedRegion())) {
regionDisplay.onRegionChanged(); regionDisplay.onRegionChanged();
} }
else if (commander.getCurrentDayAction() != ConquestAction.Undeploy) { else if (commander.getCurrentDayAction() == null) {
//if already on commander's region, change action to undeploy //if already on commander's region, change action to undeploy if no action currently set
commander.setCurrentDayAction(ConquestAction.Undeploy); commander.setCurrentDayAction(ConquestAction.Undeploy);
} }
else { else if (commander.getCurrentDayAction() == ConquestAction.Undeploy) {
commander.setCurrentDayAction(null); commander.setCurrentDayAction(null);
} }
} }

View File

@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.FThreads; import forge.FThreads;
import forge.LobbyPlayer; import forge.LobbyPlayer;
import forge.card.CardRarity; import forge.card.CardRarity;
@@ -122,6 +123,15 @@ public class ConquestController {
} }
//perform all commander actions //perform all commander actions
for (ConquestCommander commander : commanders) { for (ConquestCommander commander : commanders) {
if (commandCenter.setSelectedCommander(commander)) {
try {
//sleep if selection changed so user can see it take effect
Thread.sleep(500);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
switch (commander.getCurrentDayAction()) { switch (commander.getCurrentDayAction()) {
case Attack1: case Attack1:
playGame(commander, 0, false, commandCenter); playGame(commander, 0, false, commandCenter);
@@ -136,10 +146,10 @@ public class ConquestController {
playGame(commander, Aggregates.randomInt(0, 2), true, commandCenter); //defend against random opponent playGame(commander, Aggregates.randomInt(0, 2), true, commandCenter); //defend against random opponent
break; break;
case Recruit: case Recruit:
if (!recruit(commander)) { return; } recruit(commander);
break; break;
case Study: case Study:
if (!study(commander)) { return; } study(commander);
break; break;
case Undeploy: case Undeploy:
model.getCurrentPlaneData().getRegionData(commander.getDeployedRegion()).setDeployedCommander(null); model.getCurrentPlaneData().getRegionData(commander.getDeployedRegion()).setDeployedCommander(null);
@@ -147,15 +157,19 @@ public class ConquestController {
default: //remaining actions don't need to do anything more default: //remaining actions don't need to do anything more
break; break;
} }
commander.setCurrentDayAction(null);
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
e.printStackTrace();
}
} }
//increment day and reset actions, then update UI for new day //update UI for new day
FThreads.invokeInEdtLater(new Runnable() { FThreads.invokeInEdtLater(new Runnable() {
@Override @Override
public void run() { public void run() {
model.incrementDay(); model.incrementDay();
for (ConquestCommander commander : commanders) {
commander.setCurrentDayAction(null);
}
commandCenter.updateCurrentDay(); commandCenter.updateCurrentDay();
} }
}); });

View File

@@ -4,5 +4,6 @@ import forge.planarconquest.ConquestController.GameRunner;
public interface IVCommandCenter { public interface IVCommandCenter {
void updateCurrentDay(); void updateCurrentDay();
boolean setSelectedCommander(ConquestCommander commander);
void startGame(final GameRunner gameRunner); void startGame(final GameRunner gameRunner);
} }