Fix "controls" when alternating human vs ai, then ai vs ai play on mobile forge,

update refreshfield, update targeting arrows on 3 to 4 players
(shows attacked player on 3/4 player match...)
This commit is contained in:
Anthony Calosa
2019-11-09 19:28:21 +08:00
parent 5ecde572c3
commit f239755249
8 changed files with 66 additions and 22 deletions

View File

@@ -45,6 +45,15 @@ public enum PhaseType {
} }
public final boolean phaseforUpdateField() {
boolean result =
((ALL_PHASES.indexOf(this) >= ALL_PHASES.indexOf(UNTAP)
&& ALL_PHASES.indexOf(this) < ALL_PHASES.indexOf(COMBAT_FIRST_STRIKE_DAMAGE))
|| (ALL_PHASES.indexOf(this) >= ALL_PHASES.indexOf(MAIN2)
&& ALL_PHASES.indexOf(this) < ALL_PHASES.indexOf(CLEANUP)));
return result;
}
public final boolean isAfter(final PhaseType phase) { public final boolean isAfter(final PhaseType phase) {
return ALL_PHASES.indexOf(this) > ALL_PHASES.indexOf(phase); return ALL_PHASES.indexOf(this) > ALL_PHASES.indexOf(phase);
} }

View File

@@ -125,6 +125,11 @@ public class MatchController extends AbstractGuiGame {
@Override @Override
public void refreshField() { public void refreshField() {
if(getGameView() == null)
return;
if(getGameView().getPhase() == null)
return;
if (getGameView().getPhase().phaseforUpdateField())
for (final VPlayerPanel pnl : view.getPlayerPanels().values()) for (final VPlayerPanel pnl : view.getPlayerPanels().values())
pnl.getField().update(); pnl.getField().update();
} }

View File

@@ -378,9 +378,10 @@ public class MatchScreen extends FScreen {
} }
//player //player
if (is4Player() || is3Player()) { if (is4Player() || is3Player()) {
int numplayers = is3Player() ? 3 : 4;
for (final PlayerView p : game.getPlayers()) { for (final PlayerView p : game.getPlayers()) {
if (combat.getAttackersOf(p).contains(attacker)) if (combat.getAttackersOf(p).contains(attacker))
TargetingOverlay.drawArrow(g, attacker, p); TargetingOverlay.drawArrow(g, attacker, p, numplayers);
} }
} }
} }

View File

@@ -79,9 +79,9 @@ public class TargetingOverlay {
CardAreaPanel.get(endCard).getTargetingArrowOrigin(), CardAreaPanel.get(endCard).getTargetingArrowOrigin(),
connects); connects);
} }
public static void drawArrow(Graphics g, CardView startCard, PlayerView targetPlayer) { public static void drawArrow(Graphics g, CardView startCard, PlayerView targetPlayer, int numplayers) {
drawArrow(g, CardAreaPanel.get(startCard).getTargetingArrowOrigin(), drawArrow(g, CardAreaPanel.get(startCard).getTargetingArrowOrigin(),
MatchController.getView().getPlayerPanel(targetPlayer).getAvatar().getTargetingArrowOrigin(), MatchController.getView().getPlayerPanel(targetPlayer).getAvatar().getTargetingArrowOrigin(numplayers),
ArcConnection.FoesAttacking); ArcConnection.FoesAttacking);
} }
public static void drawArrow(Graphics g, Vector2 start, CardView targetCard, ArcConnection connects) { public static void drawArrow(Graphics g, Vector2 start, CardView targetCard, ArcConnection connects) {

View File

@@ -45,10 +45,15 @@ public class VAvatar extends FDisplayObject {
} }
public Vector2 getTargetingArrowOrigin() { public Vector2 getTargetingArrowOrigin() {
return getTargetingArrowOrigin(2);
}
public Vector2 getTargetingArrowOrigin(int numplayers) {
Vector2 origin = new Vector2(screenPos.x, screenPos.y); Vector2 origin = new Vector2(screenPos.x, screenPos.y);
origin.x += WIDTH * 0.75f; float modx = numplayers > 2 ? 0.25f : 0.75f;
if (origin.y < MatchController.getView().getHeight() / 2) {
origin.x += WIDTH * modx;
if (origin.y < MatchController.getView().getHeight() / numplayers) {
origin.y += HEIGHT * 0.75f; //target bottom right corner if on top half of screen origin.y += HEIGHT * 0.75f; //target bottom right corner if on top half of screen
} }
else { else {

View File

@@ -96,10 +96,6 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
needPlayerControlUpdate = false; needPlayerControlUpdate = false;
matchController.updatePlayerControl(); matchController.updatePlayerControl();
} }
if (refreshFieldUpdate) {
refreshFieldUpdate = false;
matchController.refreshField();
}
synchronized (zonesUpdate) { synchronized (zonesUpdate) {
if (!zonesUpdate.isEmpty()) { if (!zonesUpdate.isEmpty()) {
// Copy to prevent concurrency issues // Copy to prevent concurrency issues
@@ -107,6 +103,10 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
zonesUpdate.clear(); zonesUpdate.clear();
} }
} }
if (refreshFieldUpdate) {
refreshFieldUpdate = false;
matchController.refreshField();
}
if (gameOver) { if (gameOver) {
gameOver = false; gameOver = false;
humanController.getInputQueue().onGameOver(true); // this will unlock any game threads waiting for inputs to complete humanController.getInputQueue().onGameOver(true); // this will unlock any game threads waiting for inputs to complete
@@ -338,6 +338,8 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override @Override
public Void visit(final GameEventCardChangeZone event) { public Void visit(final GameEventCardChangeZone event) {
if(event.to.getZoneType() == ZoneType.Battlefield)
refreshFieldUpdate = true;
//pfps the change to the zones have already been performed with add and remove calls //pfps the change to the zones have already been performed with add and remove calls
// this is only for playing a sound // this is only for playing a sound
// updateZone(event.from); // updateZone(event.from);

View File

@@ -9,6 +9,7 @@ import java.util.Set;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import forge.GuiBase;
import forge.util.Localizer; import forge.util.Localizer;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -59,6 +60,15 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
player = TrackableTypes.PlayerViewType.lookup(player); //ensure we use the correct player player = TrackableTypes.PlayerViewType.lookup(player); //ensure we use the correct player
if (hasLocalPlayers() && !isLocalPlayer(player)) { //add check if gameControllers is not empty if (hasLocalPlayers() && !isLocalPlayer(player)) { //add check if gameControllers is not empty
if(GuiBase.getInterface().isLibgdxPort()){//spectator is registered as localplayer bug on ai vs ai (after .
if (spectator != null){ //human vs ai game), then it loses "control" when you watch ai vs ai,
currentPlayer = null; //again, and vice versa, This is to prevent throwing error, lose control,
updateCurrentPlayer(null); //workaround fix on mayviewcards below is needed or it will bug the UI..
gameControllers.clear();
return;
}
}
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@@ -168,9 +178,23 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
if (!hasLocalPlayers()) { if (!hasLocalPlayers()) {
return true; //if not in game, card can be shown return true; //if not in game, card can be shown
} }
if(GuiBase.getInterface().isLibgdxPort()){
if(spectator!=null) { //workaround fix!! this is needed on above code or it will
gameControllers.remove(spectator); //bug the UI! remove spectator here since its must not be here...
return true;
}
try{
if (getGameController().mayLookAtAllCards()) { // when it bugged here, the game thinks the spectator (null)
return true; // is the humancontroller here (maybe because there is an existing game thread???)
}
} catch (NullPointerException e){
return true; // return true so it will work as normal
}
} else {
if (getGameController().mayLookAtAllCards()) { if (getGameController().mayLookAtAllCards()) {
return true; return true;
} }
}
return c.canBeShownToAny(getLocalPlayers()); return c.canBeShownToAny(getLocalPlayers());
} }
@@ -271,6 +295,7 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
if (showConfirmDialog(Localizer.getInstance().getMessage("lblCloseGameSpectator"), Localizer.getInstance().getMessage("lblCloseGame"), Localizer.getInstance().getMessage("lblClose"), Localizer.getInstance().getMessage("lblCancel"))) { if (showConfirmDialog(Localizer.getInstance().getMessage("lblCloseGameSpectator"), Localizer.getInstance().getMessage("lblCloseGame"), Localizer.getInstance().getMessage("lblClose"), Localizer.getInstance().getMessage("lblCancel"))) {
IGameController controller = spectator; IGameController controller = spectator;
spectator = null; //ensure we don't prompt again, including when calling nextGameDecision below spectator = null; //ensure we don't prompt again, including when calling nextGameDecision below
controller.selectButtonOk(); //pause
controller.nextGameDecision(NextGameDecision.QUIT); controller.nextGameDecision(NextGameDecision.QUIT);
} }
return false; //let logic above handle closing current screen return false; //let logic above handle closing current screen

View File

@@ -216,13 +216,7 @@ public class HostedMatch {
final IGuiGame gui = GuiBase.getInterface().getNewGuiGame(); final IGuiGame gui = GuiBase.getInterface().getNewGuiGame();
gui.setGameView(null); //clear the view so when the game restarts again, it updates correctly gui.setGameView(null); //clear the view so when the game restarts again, it updates correctly
gui.setGameView(gameView); gui.setGameView(gameView);
registerSpectator(gui, new WatchLocalGame(game, new LobbyPlayerHuman("Spectator"), gui));
final PlayerControllerHuman humanController = new WatchLocalGame(game, new LobbyPlayerHuman("Spectator"), gui);
game.subscribeToEvents(new FControlGameEventHandler(humanController));
humanControllers.add(humanController);
gui.setSpectator(humanController);
gui.openView(null);
} }
//prompt user for player one name if needed //prompt user for player one name if needed
@@ -276,9 +270,12 @@ public class HostedMatch {
public void registerSpectator(final IGuiGame gui) { public void registerSpectator(final IGuiGame gui) {
final PlayerControllerHuman humanController = new WatchLocalGame(game, null, gui); final PlayerControllerHuman humanController = new WatchLocalGame(game, null, gui);
registerSpectator(gui, humanController);
}
public void registerSpectator(final IGuiGame gui, final PlayerControllerHuman humanController) {
gui.setSpectator(humanController); gui.setSpectator(humanController);
gui.openView(null); gui.openView(null);
game.subscribeToEvents(new FControlGameEventHandler(humanController)); game.subscribeToEvents(new FControlGameEventHandler(humanController));
humanControllers.add(humanController); humanControllers.add(humanController);
} }