mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Flesh out logic necessary to start and update game state
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -16094,6 +16094,7 @@ forge-m-base/src/forge/screens/match/input/InputSynchronized.java -text
|
||||
forge-m-base/src/forge/screens/match/input/InputSyncronizedBase.java -text
|
||||
forge-m-base/src/forge/screens/match/views/VAvatar.java -text
|
||||
forge-m-base/src/forge/screens/match/views/VField.java -text
|
||||
forge-m-base/src/forge/screens/match/views/VGameDetails.java -text
|
||||
forge-m-base/src/forge/screens/match/views/VLog.java -text
|
||||
forge-m-base/src/forge/screens/match/views/VPhaseIndicator.java -text
|
||||
forge-m-base/src/forge/screens/match/views/VPlayerPanel.java -text
|
||||
|
||||
@@ -3,9 +3,8 @@ package forge.screens;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Forge;
|
||||
import forge.screens.FScreen;
|
||||
import forge.screens.match.MatchScreen;
|
||||
import forge.screens.match.FControl;
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinImage;
|
||||
import forge.game.GameRules;
|
||||
@@ -91,7 +90,7 @@ public abstract class LaunchScreen extends FScreen {
|
||||
rules.setManaBurn(false); //Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||
rules.canCloneUseTargetsImage = false; //Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
|
||||
|
||||
Forge.openScreen(new MatchScreen(new Match(rules, launchParams.players)));
|
||||
FControl.startGame(new Match(rules, launchParams.players));
|
||||
}
|
||||
|
||||
creatingMatch = false;
|
||||
|
||||
@@ -22,6 +22,7 @@ import forge.game.player.Player;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.model.FModel;
|
||||
import forge.net.FServer;
|
||||
import forge.screens.match.events.IUiEventVisitor;
|
||||
import forge.screens.match.events.UiEvent;
|
||||
import forge.screens.match.events.UiEventAttackerDeclared;
|
||||
@@ -39,7 +40,10 @@ public class FControl {
|
||||
private static InputQueue inputQueue;
|
||||
private static List<Player> sortedPlayers;
|
||||
private static final EventBus uiEvents;
|
||||
private static MatchUiEventVisitor visitor = new MatchUiEventVisitor();
|
||||
private static boolean gameHasHumanPlayer;
|
||||
private static final MatchUiEventVisitor visitor = new MatchUiEventVisitor();
|
||||
private static final FControlGameEventHandler fcVisitor = new FControlGameEventHandler();
|
||||
private static final FControlGamePlayback playbackControl = new FControlGamePlayback();
|
||||
|
||||
static {
|
||||
uiEvents = new EventBus("ui events");
|
||||
@@ -47,9 +51,8 @@ public class FControl {
|
||||
uiEvents.register(visitor);
|
||||
}
|
||||
|
||||
public static void startGame(final Match match, final MatchScreen view0) {
|
||||
public static void startGame(final Match match) {
|
||||
game = match.createGame();
|
||||
view = view0;
|
||||
|
||||
/*if (game.getRules().getGameType() == GameType.Quest) {
|
||||
QuestController qc = Singletons.getModel().getQuest();
|
||||
@@ -68,6 +71,25 @@ public class FControl {
|
||||
// The UI controls should use these game data as models
|
||||
initMatch(game.getRegisteredPlayers(), humanLobbyPlayer);
|
||||
|
||||
FModel.getPreferences().actuateMatchPreferences();
|
||||
view.getPrompt().getInputProxy().setGame(game);
|
||||
|
||||
// Listen to DuelOutcome event to show ViewWinLose
|
||||
game.subscribeToEvents(fcVisitor);
|
||||
|
||||
// Add playback controls to match if needed
|
||||
gameHasHumanPlayer = false;
|
||||
for (Player p : game.getPlayers()) {
|
||||
if (p.getController().getLobbyPlayer() == FServer.getLobby().getGuiPlayer()) {
|
||||
gameHasHumanPlayer = true;
|
||||
}
|
||||
}
|
||||
if (!gameHasHumanPlayer) {
|
||||
game.subscribeToEvents(playbackControl);
|
||||
}
|
||||
|
||||
Forge.openScreen(view);
|
||||
|
||||
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
|
||||
// Game is set on pause while gui player takes decisions
|
||||
/*game.getAction().invoke(new Runnable() {
|
||||
@@ -104,10 +126,6 @@ public class FControl {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private static int getPlayerIndex(Player player) {
|
||||
return sortedPlayers.indexOf(player);
|
||||
}
|
||||
|
||||
public static void endCurrentGame() {
|
||||
if (game == null) { return; }
|
||||
|
||||
@@ -116,60 +134,27 @@ public class FControl {
|
||||
}
|
||||
|
||||
public static void initMatch(final List<Player> players, LobbyPlayer localPlayer) {
|
||||
// TODO fix for use with multiplayer
|
||||
|
||||
final String[] indices = FModel.getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||
|
||||
// Instantiate all required field slots (user at 0)
|
||||
sortedPlayers = shiftPlayersPlaceLocalFirst(players, localPlayer);
|
||||
|
||||
/*final List<VField> fields = new ArrayList<VField>();
|
||||
final List<VCommand> commands = new ArrayList<VCommand>();
|
||||
List<VPlayerPanel> playerPanels = new ArrayList<VPlayerPanel>();
|
||||
|
||||
int i = 0;
|
||||
int avatarIndex = 0;
|
||||
for (Player p : sortedPlayers) {
|
||||
// A field must be initialized after it's instantiated, to update player info.
|
||||
// No player, no init.
|
||||
VField f = new VField(EDocID.Fields[i], p, localPlayer);
|
||||
VCommand c = new VCommand(EDocID.Commands[i], p);
|
||||
fields.add(f);
|
||||
commands.add(c);
|
||||
|
||||
//setAvatar(f, new ImageIcon(FSkin.getAvatars().get()));
|
||||
setAvatar(f, getPlayerAvatar(p, Integer.parseInt(indices[i > 2 ? 1 : 0])));
|
||||
f.getLayoutControl().initialize();
|
||||
c.getLayoutControl().initialize();
|
||||
i++;
|
||||
}
|
||||
|
||||
// Replace old instances
|
||||
view.setCommandViews(commands);
|
||||
view.setFieldViews(fields);
|
||||
|
||||
VPlayers.SINGLETON_INSTANCE.init(players);*/
|
||||
|
||||
initHandViews(localPlayer);
|
||||
}
|
||||
|
||||
public static void initHandViews(LobbyPlayer localPlayer) {
|
||||
/*final List<VHand> hands = new ArrayList<VHand>();
|
||||
|
||||
int i = 0;
|
||||
for (Player p : sortedPlayers) {
|
||||
if (p.getLobbyPlayer() == localPlayer) {
|
||||
VHand newHand = new VHand(EDocID.Hands[i], p);
|
||||
newHand.getLayoutControl().initialize();
|
||||
hands.add(newHand);
|
||||
if (i < indices.length) {
|
||||
avatarIndex = Integer.parseInt(indices[i]);
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
localPlayer.setAvatarIndex(avatarIndex);
|
||||
playerPanels.add(new VPlayerPanel(p, localPlayer));
|
||||
}
|
||||
|
||||
if (hands.isEmpty()) { // add empty hand for matches without human
|
||||
VHand newHand = new VHand(EDocID.Hands[0], null);
|
||||
newHand.getLayoutControl().initialize();
|
||||
hands.add(newHand);
|
||||
}
|
||||
view.setHandViews(hands);*/
|
||||
view = new MatchScreen(playerPanels);
|
||||
|
||||
view.getGameDetails().init(players);
|
||||
}
|
||||
|
||||
private static List<Player> shiftPlayersPlaceLocalFirst(final List<Player> players, LobbyPlayer localPlayer) {
|
||||
@@ -189,7 +174,7 @@ public class FControl {
|
||||
}
|
||||
|
||||
public static void resetAllPhaseButtons() {
|
||||
for (final VPlayerPanel panel : view.getPlayerPanels()) {
|
||||
for (final VPlayerPanel panel : view.getPlayerPanels().values()) {
|
||||
panel.getPhaseIndicator().resetPhaseButtons();
|
||||
}
|
||||
}
|
||||
@@ -199,8 +184,7 @@ public class FControl {
|
||||
}
|
||||
|
||||
public static VPlayerPanel getPlayerPanel(Player p) {
|
||||
int idx = getPlayerIndex(p);
|
||||
return idx < 0 ? null : view.getPlayerPanels().get(idx);
|
||||
return view.getPlayerPanels().get(p);
|
||||
}
|
||||
|
||||
public static boolean mayShowCard(Card c) {
|
||||
@@ -257,27 +241,11 @@ public class FControl {
|
||||
|
||||
public static void updateZones(List<Pair<Player, ZoneType>> zonesToUpdate) {
|
||||
//System.out.println("updateZones " + zonesToUpdate);
|
||||
/*for (Pair<Player, ZoneType> kv : zonesToUpdate) {
|
||||
for (Pair<Player, ZoneType> kv : zonesToUpdate) {
|
||||
Player owner = kv.getKey();
|
||||
ZoneType zt = kv.getValue();
|
||||
|
||||
if (zt == ZoneType.Command)
|
||||
getCommandFor(owner).getTabletop().setupPlayZone();
|
||||
else if (zt == ZoneType.Hand) {
|
||||
VHand vHand = getHandFor(owner);
|
||||
if (null != vHand)
|
||||
vHand.getLayoutControl().updateHand();
|
||||
getFieldViewFor(owner).getDetailsPanel().updateZones();
|
||||
}
|
||||
else if (zt == ZoneType.Battlefield) {
|
||||
getFieldViewFor(owner).getTabletop().setupPlayZone();
|
||||
} else if (zt == ZoneType.Ante) {
|
||||
CAntes.SINGLETON_INSTANCE.update();
|
||||
}
|
||||
else {
|
||||
getFieldViewFor(owner).getDetailsPanel().updateZones();
|
||||
}
|
||||
}*/
|
||||
getPlayerPanel(owner).updateZone(zt);
|
||||
}
|
||||
}
|
||||
|
||||
// Player's mana pool changes
|
||||
@@ -289,9 +257,9 @@ public class FControl {
|
||||
|
||||
// Player's lives and poison counters
|
||||
public static void updateLives(List<Player> livesUpdate) {
|
||||
/*for (Player p : livesUpdate) {
|
||||
getFieldViewFor(p).updateDetails();
|
||||
}*/
|
||||
for (Player p : livesUpdate) {
|
||||
getPlayerPanel(p).updateLife();
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateCards(Set<Card> cardsToUpdate) {
|
||||
@@ -303,8 +271,7 @@ public class FControl {
|
||||
public static void updateSingleCard(Card c) {
|
||||
Zone zone = c.getZone();
|
||||
if (zone != null && zone.getZoneType() == ZoneType.Battlefield) {
|
||||
/*PlayArea pa = getFieldViewFor(zone.getPlayer()).getTabletop();
|
||||
pa.updateSingleCard(c);*/
|
||||
getPlayerPanel(zone.getPlayer()).getField().updateSingleCard(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +108,8 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
}
|
||||
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() {
|
||||
FControl.initHandViews(FServer.getLobby().getGuiPlayer());
|
||||
/*SLayoutIO.loadLayout(null);
|
||||
/*FControl.initHandViews(FServer.getLobby().getGuiPlayer());
|
||||
SLayoutIO.loadLayout(null);
|
||||
VMatchUI.SINGLETON_INSTANCE.populate();
|
||||
for (VHand h : VMatchUI.SINGLETON_INSTANCE.getHands()) {
|
||||
h.getLayoutControl().updateHand();
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package forge.screens.match;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.screens.FScreen;
|
||||
import forge.screens.match.views.VAvatar;
|
||||
import forge.screens.match.views.VGameDetails;
|
||||
import forge.screens.match.views.VLog;
|
||||
import forge.screens.match.views.VPlayerPanel;
|
||||
import forge.screens.match.views.VPrompt;
|
||||
import forge.screens.match.views.VStack;
|
||||
@@ -11,39 +15,39 @@ import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinTexture;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.game.Match;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
public class MatchScreen extends FScreen {
|
||||
public static FSkinColor BORDER_COLOR = FSkinColor.get(Colors.CLR_BORDERS);
|
||||
|
||||
private final Match match;
|
||||
private final List<VPlayerPanel> playerPanels;
|
||||
//private final VLog log;
|
||||
private final Map<Player, VPlayerPanel> playerPanels = new HashMap<Player, VPlayerPanel>();
|
||||
private final VLog log;
|
||||
private final VStack stack;
|
||||
private final VPrompt prompt;
|
||||
private final VGameDetails gameDetails;
|
||||
|
||||
private VPlayerPanel bottomPlayerPanel, topPlayerPanel;
|
||||
|
||||
public MatchScreen(Match match0) {
|
||||
public MatchScreen(List<VPlayerPanel> playerPanels0) {
|
||||
super(true, "Game", true);
|
||||
match = match0;
|
||||
|
||||
playerPanels = new ArrayList<VPlayerPanel>();
|
||||
for (RegisteredPlayer player : match.getPlayers()) {
|
||||
playerPanels.add(add(new VPlayerPanel(player)));
|
||||
for (VPlayerPanel playerPanel : playerPanels0) {
|
||||
playerPanels.put(playerPanel.getPlayer(), add(playerPanel));
|
||||
}
|
||||
bottomPlayerPanel = playerPanels.get(0);
|
||||
topPlayerPanel = playerPanels.get(1);
|
||||
bottomPlayerPanel = playerPanels0.get(0);
|
||||
topPlayerPanel = playerPanels0.get(1);
|
||||
topPlayerPanel.setFlipped(true);
|
||||
bottomPlayerPanel.setSelectedZone(ZoneType.Hand);
|
||||
|
||||
//log = add(new VLog());
|
||||
stack = add(new VStack());
|
||||
prompt = add(new VPrompt());
|
||||
|
||||
FControl.startGame(match0, this);
|
||||
log = add(new VLog());
|
||||
stack = add(new VStack());
|
||||
gameDetails = add(new VGameDetails());
|
||||
log.setVisible(false);
|
||||
stack.setVisible(false);
|
||||
gameDetails.setVisible(false);
|
||||
}
|
||||
|
||||
public VPrompt getPrompt() {
|
||||
@@ -54,7 +58,23 @@ public class MatchScreen extends FScreen {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public List<VPlayerPanel> getPlayerPanels() {
|
||||
public VLog getLog() {
|
||||
return log;
|
||||
}
|
||||
|
||||
public VGameDetails getGameDetails() {
|
||||
return gameDetails;
|
||||
}
|
||||
|
||||
public VPlayerPanel getTopPlayerPanel() {
|
||||
return topPlayerPanel;
|
||||
}
|
||||
|
||||
public VPlayerPanel getBottomPlayerPanel() {
|
||||
return bottomPlayerPanel;
|
||||
}
|
||||
|
||||
public Map<Player, VPlayerPanel> getPlayerPanels() {
|
||||
return playerPanels;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import forge.model.FModel;
|
||||
import forge.toolbox.FCardPanel;
|
||||
import forge.toolbox.FDisplayObject;
|
||||
import forge.toolbox.FScrollPane;
|
||||
@@ -17,19 +16,6 @@ public class VField extends FScrollPane {
|
||||
private final List<FCardPanel> otherPermanents = new ArrayList<FCardPanel>();
|
||||
|
||||
public VField() {
|
||||
Card creature = Card.getCardForUi(FModel.getMagicDb().getCommonCards().getCard("Llanowar Elves"));
|
||||
Card land = Card.getCardForUi(FModel.getMagicDb().getCommonCards().getCard("Forest"));
|
||||
Card artifact = Card.getCardForUi(FModel.getMagicDb().getCommonCards().getCard("Coat of Arms"));
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
creatures.add(add(new FCardPanel(creature)));
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
lands.add(add(new FCardPanel(land)));
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
otherPermanents.add(add(new FCardPanel(artifact)));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFlipped() {
|
||||
@@ -39,6 +25,14 @@ public class VField extends FScrollPane {
|
||||
flipped = flipped0;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
public void updateSingleCard(Card card) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
float x = 0;
|
||||
|
||||
98
forge-m-base/src/forge/screens/match/views/VGameDetails.java
Normal file
98
forge-m-base/src/forge/screens/match/views/VGameDetails.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package forge.screens.match.views;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.GameType;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardFactoryUtil;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.model.FModel;
|
||||
import forge.toolbox.FContainer;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.utils.ForgePreferences.FPref;
|
||||
|
||||
public class VGameDetails extends FContainer {
|
||||
private Map<Player, InfoLabel[]> infoLabels;
|
||||
private InfoLabel stormLabel;
|
||||
|
||||
public void init(final Iterable<Player> players) {
|
||||
clear();
|
||||
infoLabels = new HashMap<Player, InfoLabel[]>();
|
||||
for (final Player p : players) {
|
||||
// Create and store labels detailing various non-critical player info.
|
||||
final InfoLabel name = add(new InfoLabel());
|
||||
final InfoLabel life = add(new InfoLabel());
|
||||
final InfoLabel hand = add(new InfoLabel());
|
||||
final InfoLabel draw = add(new InfoLabel());
|
||||
final InfoLabel prevention = add(new InfoLabel());
|
||||
final InfoLabel keywords = add(new InfoLabel());
|
||||
final InfoLabel antes = add(new InfoLabel());
|
||||
final InfoLabel cmd = add(new InfoLabel());
|
||||
infoLabels.put(p, new InfoLabel[] { name, life, hand, draw, prevention, keywords, antes, cmd });
|
||||
|
||||
name.setText(p.getName());
|
||||
}
|
||||
|
||||
stormLabel = add(new InfoLabel());
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (!isVisible()) { return; } //No need to update if this panel isn't showing
|
||||
|
||||
for (Entry<Player, InfoLabel[]> rr : infoLabels.entrySet()) {
|
||||
Player p0 = rr.getKey();
|
||||
final InfoLabel[] temp = rr.getValue();
|
||||
temp[1].setText("Life: " + String.valueOf(p0.getLife()) + " | Poison counters: "
|
||||
+ String.valueOf(p0.getPoisonCounters()));
|
||||
temp[2].setText("Maximum hand size: " + String.valueOf(p0.getMaxHandSize()));
|
||||
temp[3].setText("Cards drawn this turn: " + String.valueOf(p0.getNumDrawnThisTurn()));
|
||||
temp[4].setText("Damage Prevention: " + String.valueOf(p0.getPreventNextDamageTotalShields()));
|
||||
if (!p0.getKeywords().isEmpty()) {
|
||||
temp[5].setText(p0.getKeywords().toString());
|
||||
}
|
||||
else {
|
||||
temp[5].setText("");
|
||||
}
|
||||
if (FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE)) {
|
||||
List<Card> list = p0.getCardsIn(ZoneType.Ante);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Ante'd: ");
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
sb.append(list.get(i));
|
||||
if (i < (list.size() - 1)) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
temp[6].setText(sb.toString());
|
||||
}
|
||||
if (p0.getGame().getRules().getGameType() == GameType.Commander) {
|
||||
temp[7].setText(CardFactoryUtil.getCommanderInfo(p0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param game */
|
||||
public void updateStormLabel(Game game) {
|
||||
if (!isVisible()) { return; } //No need to update if this panel isn't showing
|
||||
|
||||
stormLabel.setText("Storm count: " + game.getStack().getCardsCastThisTurn().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private class InfoLabel extends FLabel {
|
||||
private InfoLabel() {
|
||||
super(new FLabel.Builder());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package forge.screens.match.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
@@ -10,7 +12,8 @@ import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinImage;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.screens.match.FControl;
|
||||
import forge.screens.match.MatchScreen;
|
||||
@@ -23,31 +26,42 @@ public class VPlayerPanel extends FContainer {
|
||||
private static final FSkinColor INFO_FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
private static final FSkinColor ZONE_BACK_COLOR = FSkinColor.get(Colors.CLR_INACTIVE).alphaColor(0.5f);
|
||||
|
||||
private final RegisteredPlayer player;
|
||||
private final Player player;
|
||||
private final LobbyPlayer localPlayer;
|
||||
private final VPhaseIndicator phaseIndicator;
|
||||
private final VField field;
|
||||
private final VAvatar avatar;
|
||||
private final List<InfoLabel> infoLabels = new ArrayList<InfoLabel>();
|
||||
private final List<VZoneDisplay> zones = new ArrayList<VZoneDisplay>();
|
||||
private final LifeLabel lblLife;
|
||||
private final List<ZoneInfoTab> zoneTabs = new ArrayList<ZoneInfoTab>();
|
||||
private final Map<ZoneType, VZoneDisplay> zoneDisplays = new HashMap<ZoneType, VZoneDisplay>();
|
||||
private VZoneDisplay selectedZone;
|
||||
|
||||
public VPlayerPanel(RegisteredPlayer player0) {
|
||||
public VPlayerPanel(Player player0, LobbyPlayer localPlayer0) {
|
||||
player = player0;
|
||||
localPlayer = localPlayer0;
|
||||
phaseIndicator = add(new VPhaseIndicator());
|
||||
field = add(new VField());
|
||||
avatar = add(new VAvatar(player.getPlayer().getAvatarIndex()));
|
||||
infoLabels.add(add(new LifeLabel()));
|
||||
avatar = add(new VAvatar(localPlayer.getAvatarIndex()));
|
||||
lblLife = add(new LifeLabel());
|
||||
addZoneDisplay(ZoneType.Hand, FSkinImage.HAND);
|
||||
addZoneDisplay(ZoneType.Graveyard, FSkinImage.GRAVEYARD);
|
||||
addZoneDisplay(ZoneType.Library, FSkinImage.LIBRARY);
|
||||
addZoneDisplay(ZoneType.Exile, FSkinImage.EXILE);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public LobbyPlayer getLocalPlayer() {
|
||||
return localPlayer;
|
||||
}
|
||||
|
||||
public void addZoneDisplay(ZoneType zoneType, FSkinImage tabIcon) {
|
||||
VZoneDisplay zone = add(new VZoneDisplay(zoneType));
|
||||
zone.setVisible(false);
|
||||
zones.add(zone);
|
||||
infoLabels.add(add(new ZoneInfoTab(tabIcon, zone)));
|
||||
zoneDisplays.put(zoneType, zone);
|
||||
zoneTabs.add(add(new ZoneInfoTab(tabIcon, zone)));
|
||||
}
|
||||
|
||||
public ZoneType getSelectedZone() {
|
||||
@@ -72,12 +86,9 @@ public class VPlayerPanel extends FContainer {
|
||||
selectedZone = null;
|
||||
}
|
||||
else {
|
||||
for (VZoneDisplay zone : zones) {
|
||||
if (zone.getZoneType() == zoneType) {
|
||||
selectedZone = zone;
|
||||
selectedZone.setVisible(true);
|
||||
break;
|
||||
}
|
||||
selectedZone = zoneDisplays.get(zoneType);
|
||||
if (selectedZone != null) {
|
||||
selectedZone.setVisible(true);
|
||||
}
|
||||
}
|
||||
if (FControl.getView() != null) { //must revalidate entire screen so panel heights updated
|
||||
@@ -104,6 +115,24 @@ public class VPlayerPanel extends FContainer {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void updateLife() {
|
||||
lblLife.update();
|
||||
}
|
||||
|
||||
public void updateZone(ZoneType zoneType) {
|
||||
if (zoneType == ZoneType.Battlefield) {
|
||||
field.update();
|
||||
}
|
||||
else {
|
||||
for (ZoneInfoTab tab : zoneTabs) {
|
||||
if (tab.zoneToOpen.getZoneType() == zoneType) {
|
||||
tab.update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
//layout for bottom panel by default
|
||||
@@ -115,7 +144,7 @@ public class VPlayerPanel extends FContainer {
|
||||
y = height - VAvatar.HEIGHT;
|
||||
zoneHeight = y / 3;
|
||||
y -= zoneHeight;
|
||||
for (VZoneDisplay zone : zones) {
|
||||
for (VZoneDisplay zone : zoneDisplays.values()) {
|
||||
zone.setBounds(0, y, width, zoneHeight);
|
||||
}
|
||||
}
|
||||
@@ -125,12 +154,13 @@ public class VPlayerPanel extends FContainer {
|
||||
|
||||
y = height - VAvatar.HEIGHT;
|
||||
avatar.setPosition(0, y);
|
||||
float infoLabelWidth;
|
||||
|
||||
float infoLabelHeight = VAvatar.HEIGHT - VPhaseIndicator.HEIGHT;
|
||||
for (InfoLabel infoLabel : infoLabels) {
|
||||
infoLabelWidth = infoLabel.getPreferredWidth();
|
||||
infoLabel.setBounds(x, y, infoLabelWidth, infoLabelHeight);
|
||||
x += infoLabelWidth;
|
||||
lblLife.setBounds(x, y, lblLife.getWidth(), infoLabelHeight);
|
||||
x += lblLife.getWidth();
|
||||
for (ZoneInfoTab tab : zoneTabs) {
|
||||
tab.setBounds(x, y, tab.getWidth(), infoLabelHeight);
|
||||
x += tab.getWidth();
|
||||
}
|
||||
|
||||
field.setBounds(0, 0, width, y - zoneHeight);
|
||||
@@ -148,13 +178,11 @@ public class VPlayerPanel extends FContainer {
|
||||
float w = getWidth();
|
||||
g.fillRect(ZONE_BACK_COLOR, 0, selectedZone.getTop(), w, selectedZone.getHeight());
|
||||
|
||||
InfoLabel selectedZoneTab = null;;
|
||||
for (InfoLabel label : infoLabels) {
|
||||
if (label instanceof ZoneInfoTab) {
|
||||
if (((ZoneInfoTab)label).zoneToOpen == selectedZone) {
|
||||
selectedZoneTab = label;
|
||||
break;
|
||||
}
|
||||
ZoneInfoTab selectedZoneTab = null;
|
||||
for (ZoneInfoTab tab : zoneTabs) {
|
||||
if (tab.zoneToOpen == selectedZone) {
|
||||
selectedZoneTab = tab;
|
||||
break;
|
||||
}
|
||||
}
|
||||
float y = isFlipped() ? selectedZone.getTop() + 1 : selectedZone.getBottom();
|
||||
@@ -168,35 +196,32 @@ public class VPlayerPanel extends FContainer {
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class InfoLabel extends FDisplayObject {
|
||||
protected String value;
|
||||
public abstract float getPreferredWidth();
|
||||
}
|
||||
|
||||
private class LifeLabel extends InfoLabel {
|
||||
private class LifeLabel extends FDisplayObject {
|
||||
private String life = "20";
|
||||
|
||||
private LifeLabel() {
|
||||
value = "20";
|
||||
setWidth(VAvatar.HEIGHT * 2f / 3f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPreferredWidth() {
|
||||
return VAvatar.HEIGHT * 2f / 3f;
|
||||
private void update() {
|
||||
life = String.valueOf(player.getLife());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
g.drawText(value, LIFE_FONT, INFO_FORE_COLOR, 0, 0, getWidth(), getHeight(), false, HAlignment.CENTER, true);
|
||||
g.drawText(life, LIFE_FONT, INFO_FORE_COLOR, 0, 0, getWidth(), getHeight(), false, HAlignment.CENTER, true);
|
||||
}
|
||||
}
|
||||
|
||||
private class ZoneInfoTab extends InfoLabel {
|
||||
private class ZoneInfoTab extends FDisplayObject {
|
||||
private String value = "0";
|
||||
private final FSkinImage icon;
|
||||
private final VZoneDisplay zoneToOpen;
|
||||
|
||||
private ZoneInfoTab(FSkinImage icon0, VZoneDisplay zoneToOpen0) {
|
||||
icon = icon0;
|
||||
zoneToOpen = zoneToOpen0;
|
||||
value = "99";
|
||||
setWidth(VAvatar.HEIGHT * 1.05f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,9 +235,9 @@ public class VPlayerPanel extends FContainer {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPreferredWidth() {
|
||||
return VAvatar.HEIGHT * 1.05f;
|
||||
private void update() {
|
||||
zoneToOpen.update();
|
||||
value = String.valueOf(zoneToOpen.getCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,9 +3,7 @@ package forge.screens.match.views;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.model.FModel;
|
||||
import forge.toolbox.FCardPanel;
|
||||
import forge.toolbox.FScrollPane;
|
||||
|
||||
@@ -15,18 +13,20 @@ public class VZoneDisplay extends FScrollPane {
|
||||
|
||||
public VZoneDisplay(ZoneType zoneType0) {
|
||||
zoneType = zoneType0;
|
||||
|
||||
Card card = Card.getCardForUi(FModel.getMagicDb().getCommonCards().getCard("Forest"));
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
cards.add(add(new FCardPanel(card)));
|
||||
}
|
||||
}
|
||||
|
||||
public ZoneType getZoneType() {
|
||||
return zoneType;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return 99; //TODO
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
float x = 0;
|
||||
|
||||
@@ -19,6 +19,9 @@ package forge.utils;
|
||||
|
||||
import forge.ai.AiProfileUtil;
|
||||
import forge.game.GameLogEntryType;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.screens.match.FControl;
|
||||
import forge.screens.match.views.VPhaseIndicator;
|
||||
|
||||
public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
|
||||
/**
|
||||
@@ -135,4 +138,73 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
|
||||
protected String getPrefDefault(FPref key) {
|
||||
return key.getDefault();
|
||||
}
|
||||
|
||||
public void writeMatchPreferences() {
|
||||
VPhaseIndicator fvAi = FControl.getView().getTopPlayerPanel().getPhaseIndicator();
|
||||
this.setPref(FPref.PHASE_AI_UPKEEP, String.valueOf(fvAi.getLabel(PhaseType.UPKEEP).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_DRAW, String.valueOf(fvAi.getLabel(PhaseType.DRAW).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_MAIN1, String.valueOf(fvAi.getLabel(PhaseType.MAIN1).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_BEGINCOMBAT, String.valueOf(fvAi.getLabel(PhaseType.COMBAT_BEGIN).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_DECLAREATTACKERS, String.valueOf(fvAi.getLabel(PhaseType.COMBAT_DECLARE_ATTACKERS).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_DECLAREBLOCKERS, String.valueOf(fvAi.getLabel(PhaseType.COMBAT_DECLARE_BLOCKERS).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_FIRSTSTRIKE, String.valueOf(fvAi.getLabel(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_COMBATDAMAGE, String.valueOf(fvAi.getLabel(PhaseType.COMBAT_DAMAGE).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_ENDCOMBAT, String.valueOf(fvAi.getLabel(PhaseType.COMBAT_END).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_MAIN2, String.valueOf(fvAi.getLabel(PhaseType.MAIN2).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_EOT, String.valueOf(fvAi.getLabel(PhaseType.END_OF_TURN).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_AI_CLEANUP, String.valueOf(fvAi.getLabel(PhaseType.CLEANUP).getStopAtPhase()));
|
||||
|
||||
VPhaseIndicator fvHuman = FControl.getView().getBottomPlayerPanel().getPhaseIndicator();
|
||||
this.setPref(FPref.PHASE_HUMAN_UPKEEP, String.valueOf(fvHuman.getLabel(PhaseType.UPKEEP).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_DRAW, String.valueOf(fvHuman.getLabel(PhaseType.DRAW).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_MAIN1, String.valueOf(fvHuman.getLabel(PhaseType.MAIN1).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_BEGINCOMBAT, String.valueOf(fvHuman.getLabel(PhaseType.COMBAT_BEGIN).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_DECLAREATTACKERS, String.valueOf(fvHuman.getLabel(PhaseType.COMBAT_DECLARE_ATTACKERS).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_DECLAREBLOCKERS, String.valueOf(fvHuman.getLabel(PhaseType.COMBAT_DECLARE_BLOCKERS).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_FIRSTSTRIKE, String.valueOf(fvHuman.getLabel(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_COMBATDAMAGE, String.valueOf(fvHuman.getLabel(PhaseType.COMBAT_DAMAGE).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_ENDCOMBAT, String.valueOf(fvHuman.getLabel(PhaseType.COMBAT_END).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_MAIN2, String.valueOf(fvHuman.getLabel(PhaseType.MAIN2).getStopAtPhase()));
|
||||
this.setPref(FPref.PHASE_HUMAN_EOT, fvHuman.getLabel(PhaseType.END_OF_TURN).getStopAtPhase());
|
||||
this.setPref(FPref.PHASE_HUMAN_CLEANUP, fvHuman.getLabel(PhaseType.CLEANUP).getStopAtPhase());
|
||||
|
||||
/*final VDev v = VDev.SINGLETON_INSTANCE;
|
||||
|
||||
// this.setPref(FPref.DEV_MILLING_LOSS, v.getLblMilling().getEnabled());
|
||||
this.setPref(FPref.DEV_UNLIMITED_LAND, v.getLblUnlimitedLands().getEnabled());*/
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Needs to be reworked for efficiency with rest of prefs saves in
|
||||
* codebase.
|
||||
*/
|
||||
public void actuateMatchPreferences() {
|
||||
VPhaseIndicator fvAi = FControl.getView().getTopPlayerPanel().getPhaseIndicator();
|
||||
fvAi.getLabel(PhaseType.UPKEEP).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_UPKEEP));
|
||||
fvAi.getLabel(PhaseType.DRAW).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_DRAW));
|
||||
fvAi.getLabel(PhaseType.MAIN1).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_MAIN1));
|
||||
fvAi.getLabel(PhaseType.COMBAT_BEGIN).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_BEGINCOMBAT));
|
||||
fvAi.getLabel(PhaseType.COMBAT_DECLARE_ATTACKERS).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_DECLAREATTACKERS));
|
||||
fvAi.getLabel(PhaseType.COMBAT_DECLARE_BLOCKERS).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_DECLAREBLOCKERS));
|
||||
fvAi.getLabel(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_FIRSTSTRIKE));
|
||||
fvAi.getLabel(PhaseType.COMBAT_DAMAGE).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_COMBATDAMAGE));
|
||||
fvAi.getLabel(PhaseType.COMBAT_END).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_ENDCOMBAT));
|
||||
fvAi.getLabel(PhaseType.MAIN2).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_MAIN2));
|
||||
fvAi.getLabel(PhaseType.END_OF_TURN).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_EOT));
|
||||
fvAi.getLabel(PhaseType.CLEANUP).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_AI_CLEANUP));
|
||||
|
||||
VPhaseIndicator fvHuman = FControl.getView().getBottomPlayerPanel().getPhaseIndicator();
|
||||
fvHuman.getLabel(PhaseType.UPKEEP).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_UPKEEP));
|
||||
fvHuman.getLabel(PhaseType.DRAW).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_DRAW));
|
||||
fvHuman.getLabel(PhaseType.MAIN1).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_MAIN1));
|
||||
fvHuman.getLabel(PhaseType.COMBAT_BEGIN).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_BEGINCOMBAT));
|
||||
fvHuman.getLabel(PhaseType.COMBAT_DECLARE_ATTACKERS).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_DECLAREATTACKERS));
|
||||
fvHuman.getLabel(PhaseType.COMBAT_DECLARE_BLOCKERS).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_DECLAREBLOCKERS));
|
||||
fvHuman.getLabel(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_FIRSTSTRIKE));
|
||||
fvHuman.getLabel(PhaseType.COMBAT_DAMAGE).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_COMBATDAMAGE));
|
||||
fvHuman.getLabel(PhaseType.COMBAT_END).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_ENDCOMBAT));
|
||||
fvHuman.getLabel(PhaseType.MAIN2).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_MAIN2));
|
||||
fvHuman.getLabel(PhaseType.END_OF_TURN).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_EOT));
|
||||
fvHuman.getLabel(PhaseType.CLEANUP).setStopAtPhase(this.getPrefBoolean(FPref.PHASE_HUMAN_CLEANUP));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user