mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Fix many issues with the recent GUI and lobby refactorings.
- Fix closing screen of AI vs AI and multiplayer games - Fix developer mode toggle boxes starting out in wrong state - Fix storm count not displaying - Fix deck selection when changing game variants - Fix deck selection when returning to lobby after visiting a game - Fix too many player panels appearing in games after a previous multiplayer game
This commit is contained in:
@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import forge.game.GameView;
|
||||
import forge.game.card.CardUtil;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.card.CardView.CardStateView;
|
||||
@@ -201,7 +202,7 @@ public class CardDetailUtil {
|
||||
return id.isEmpty() ? id : "[" + id + "]";
|
||||
}
|
||||
|
||||
public static String composeCardText(final CardStateView state, final boolean canShow) {
|
||||
public static String composeCardText(final CardStateView state, final GameView gameView, final boolean canShow) {
|
||||
if (!canShow) { return ""; }
|
||||
|
||||
final CardView card = state.getCard();
|
||||
@@ -479,10 +480,7 @@ public class CardDetailUtil {
|
||||
}
|
||||
|
||||
//show current storm count for storm cards
|
||||
// TODO add Storm
|
||||
/*
|
||||
if (state.hasStorm()) {
|
||||
GameView gameView = HostedMatch.getGameView();
|
||||
if (gameView != null) {
|
||||
if (area.length() != 0) {
|
||||
area.append("\n\n");
|
||||
@@ -490,7 +488,6 @@ public class CardDetailUtil {
|
||||
area.append("Current Storm Count: " + gameView.getStormCount());
|
||||
}
|
||||
}
|
||||
*/
|
||||
return area.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package forge.interfaces;
|
||||
|
||||
public interface IUpdateable {
|
||||
void update();
|
||||
void update(boolean fullUpdate);
|
||||
}
|
||||
|
||||
@@ -158,40 +158,31 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
||||
}
|
||||
|
||||
/** Concede game, bring up WinLose UI. */
|
||||
public void concede() {
|
||||
final String userPrompt =
|
||||
"This will end the current game and you will not be able to resume.\n\n" +
|
||||
"Concede anyway?";
|
||||
if (hasLocalPlayers() && showConfirmDialog(userPrompt, "Concede Game?", "Concede", "Cancel")) {
|
||||
for (final IGameController c : getGameControllers()) {
|
||||
// Concede each player on this Gui
|
||||
c.concede();
|
||||
}
|
||||
/*
|
||||
if (humanCount == 0) { // no human? then all players surrender!
|
||||
for (Player p : game.getPlayers()) {
|
||||
p.concede();
|
||||
public boolean concede() {
|
||||
if (gameView.isGameOver()) {
|
||||
return true;
|
||||
}
|
||||
if (hasLocalPlayers()) {
|
||||
if (showConfirmDialog("This will concede the current game and you will lose.\n\nConcede anyway?", "Concede Game?", "Concede", "Cancel")) {
|
||||
for (final IGameController c : getGameControllers()) {
|
||||
// Concede each player on this Gui
|
||||
c.concede();
|
||||
}
|
||||
}
|
||||
else {
|
||||
getCurrentPlayer().concede();
|
||||
if (gameView.isGameOver()) {
|
||||
// Don't immediately close, wait for win/lose screen
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player priorityPlayer = game.getPhaseHandler().getPriorityPlayer();
|
||||
boolean humanHasPriority = priorityPlayer == null || priorityPlayer.getLobbyPlayer() instanceof LobbyPlayerHuman;
|
||||
|
||||
if (humanCount > 0 && humanHasPriority) {
|
||||
game.getAction().checkGameOverCondition();
|
||||
} else {
|
||||
if (showConfirmDialog("This will close this game and you will not be able to resume watching it.\n\nClose anyway?", "Close Game?", "Close", "Cancel")) {
|
||||
//if (playbackControl != null) {
|
||||
//playbackControl.onGameStopRequested();
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
game.isGameOver(); // this is synchronized method - it's used to make Game-0 thread see changes made here
|
||||
onGameOver(false); //release any waiting input, effectively passing priority
|
||||
}
|
||||
|
||||
if (playbackControl != null) {
|
||||
playbackControl.onGameStopRequested();
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class GameLobby {
|
||||
}
|
||||
public void setData(final GameLobbyData data) {
|
||||
this.data = data;
|
||||
updateView();
|
||||
updateView(true);
|
||||
}
|
||||
|
||||
public GameType getGameType() {
|
||||
@@ -73,7 +73,6 @@ public abstract class GameLobby {
|
||||
}
|
||||
public void setGameType(final GameType type) {
|
||||
data.currentGameMode = type;
|
||||
updateView();
|
||||
}
|
||||
|
||||
public boolean hasVariant(final GameType variant) {
|
||||
@@ -99,7 +98,8 @@ public abstract class GameLobby {
|
||||
final boolean triesToChangeArchenemy = event.getArchenemy() != null;
|
||||
final boolean archenemyRemoved = triesToChangeArchenemy && !event.getArchenemy().booleanValue();
|
||||
final boolean hasArchenemyChanged = triesToChangeArchenemy && slot.isArchenemy() != event.getArchenemy().booleanValue();
|
||||
slot.apply(event);
|
||||
|
||||
final boolean changed = slot.apply(event) || hasArchenemyChanged;
|
||||
|
||||
// Change archenemy teams
|
||||
if (hasVariant(GameType.Archenemy) && hasArchenemyChanged) {
|
||||
@@ -116,7 +116,10 @@ public abstract class GameLobby {
|
||||
otherSlot.setIsArchenemy(becomesArchenemy);
|
||||
}
|
||||
}
|
||||
updateView();
|
||||
|
||||
if (changed) {
|
||||
updateView(false);
|
||||
}
|
||||
}
|
||||
|
||||
public IGameController getController(final int index) {
|
||||
@@ -130,7 +133,8 @@ public abstract class GameLobby {
|
||||
public abstract boolean mayEdit(final int index);
|
||||
public abstract boolean mayControl(final int index);
|
||||
public abstract boolean mayRemove(final int index);
|
||||
public abstract IGuiGame getGui(final int index);
|
||||
protected abstract IGuiGame getGui(final int index);
|
||||
protected abstract void gameStarted();
|
||||
|
||||
public void addSlot() {
|
||||
final int newIndex = getNumberOfSlots();
|
||||
@@ -151,7 +155,7 @@ public abstract class GameLobby {
|
||||
slot.setIsArchenemy(true);
|
||||
lastArchenemy = 0;
|
||||
}
|
||||
updateView();
|
||||
updateView(false);
|
||||
}
|
||||
private String randomName() {
|
||||
final List<String> names = Lists.newArrayListWithCapacity(MAX_PLAYERS);
|
||||
@@ -189,7 +193,7 @@ public abstract class GameLobby {
|
||||
lastArchenemy--;
|
||||
}
|
||||
data.slots.remove(index);
|
||||
updateView();
|
||||
updateView(false);
|
||||
}
|
||||
|
||||
public void applyVariant(final GameType variant) {
|
||||
@@ -217,12 +221,13 @@ public abstract class GameLobby {
|
||||
break;
|
||||
case MomirBasic:
|
||||
data.appliedVariants.remove(GameType.Commander);
|
||||
data.appliedVariants.remove(GameType.TinyLeaders);
|
||||
data.appliedVariants.remove(GameType.Vanguard);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
updateView();
|
||||
updateView(true);
|
||||
}
|
||||
|
||||
public void removeVariant(final GameType variant) {
|
||||
@@ -230,7 +235,16 @@ public abstract class GameLobby {
|
||||
if (data.appliedVariants.isEmpty()) {
|
||||
data.appliedVariants.add(GameType.Constructed);
|
||||
}
|
||||
updateView();
|
||||
if (variant == data.currentGameMode) {
|
||||
if (hasVariant(GameType.Commander)) {
|
||||
data.currentGameMode = GameType.Commander;
|
||||
} else if (hasVariant(GameType.TinyLeaders)) {
|
||||
data.currentGameMode = GameType.TinyLeaders;
|
||||
} else {
|
||||
data.currentGameMode = GameType.Constructed;
|
||||
}
|
||||
}
|
||||
updateView(true);
|
||||
}
|
||||
|
||||
private boolean isEnoughTeams() {
|
||||
@@ -247,9 +261,9 @@ public abstract class GameLobby {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected final void updateView() {
|
||||
protected final void updateView(final boolean fullUpdate) {
|
||||
if (listener != null) {
|
||||
listener.update();
|
||||
listener.update(fullUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,6 +436,8 @@ public abstract class GameLobby {
|
||||
gameControllers.put(slot, (IGameController) p.getController());
|
||||
}
|
||||
}
|
||||
|
||||
gameStarted();
|
||||
}
|
||||
|
||||
public final static class GameLobbyData implements Serializable {
|
||||
|
||||
@@ -32,33 +32,42 @@ public final class LobbySlot implements Serializable {
|
||||
this.setAiOptions(aiOptions);
|
||||
}
|
||||
|
||||
void apply(final UpdateLobbyPlayerEvent data) {
|
||||
boolean apply(final UpdateLobbyPlayerEvent data) {
|
||||
boolean changed = false;
|
||||
if (data.getType() != null) {
|
||||
setType(data.getType());
|
||||
changed = true;
|
||||
}
|
||||
if (data.getName() != null) {
|
||||
setName(data.getName());
|
||||
changed = true;
|
||||
}
|
||||
if (data.getAvatarIndex() != -1) {
|
||||
setAvatarIndex(data.getAvatarIndex());
|
||||
changed = true;
|
||||
}
|
||||
if (data.getTeam() != -1) {
|
||||
setTeam(data.getTeam());
|
||||
changed = true;
|
||||
}
|
||||
if (data.getArchenemy() != null) {
|
||||
setIsArchenemy(data.getArchenemy().booleanValue());
|
||||
changed = true;
|
||||
}
|
||||
if (data.getReady() != null) {
|
||||
setIsReady(data.getReady().booleanValue());
|
||||
changed = true;
|
||||
}
|
||||
if (data.getAiOptions() != null) {
|
||||
setAiOptions(data.getAiOptions());
|
||||
changed = true;
|
||||
}
|
||||
if (data.getDeck() != null) {
|
||||
setDeck(data.getDeck());
|
||||
} else if (getDeck() != null && data.getSection() != null && data.getCards() != null) {
|
||||
getDeck().putSection(data.getSection(), data.getCards());
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public LobbySlotType getType() {
|
||||
|
||||
@@ -9,6 +9,7 @@ import forge.net.game.LobbySlotType;
|
||||
|
||||
public final class LocalLobby extends GameLobby {
|
||||
|
||||
private IGuiGame gui = null;
|
||||
public LocalLobby() {
|
||||
super(false);
|
||||
|
||||
@@ -38,7 +39,14 @@ public final class LocalLobby extends GameLobby {
|
||||
return index >= 2;
|
||||
}
|
||||
|
||||
@Override public IGuiGame getGui(final int index) {
|
||||
return GuiBase.getInterface().getNewGuiGame();
|
||||
@Override protected IGuiGame getGui(final int index) {
|
||||
if (gui == null) {
|
||||
gui = GuiBase.getInterface().getNewGuiGame();
|
||||
}
|
||||
return gui;
|
||||
}
|
||||
|
||||
@Override protected void gameStarted() {
|
||||
gui = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,10 @@ public final class ClientGameLobby extends GameLobby {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public IGuiGame getGui(final int index) {
|
||||
@Override protected IGuiGame getGui(final int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override protected void gameStarted() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ public final class ServerGameLobby extends GameLobby {
|
||||
slot.setType(LobbySlotType.REMOTE);
|
||||
slot.setName(name);
|
||||
slot.setAvatarIndex(avatarIndex);
|
||||
updateView();
|
||||
updateView(false);
|
||||
}
|
||||
public void disconnectPlayer(final int index) {
|
||||
final LobbySlot slot = getSlot(index);
|
||||
slot.setType(LobbySlotType.OPEN);
|
||||
slot.setName(StringUtils.EMPTY);
|
||||
updateView();
|
||||
updateView(false);
|
||||
}
|
||||
|
||||
@Override public boolean hasControl() {
|
||||
@@ -59,7 +59,11 @@ public final class ServerGameLobby extends GameLobby {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public IGuiGame getGui(final int index) {
|
||||
@Override protected IGuiGame getGui(final int index) {
|
||||
return FServerManager.getInstance().getGui(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void gameStarted() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user