Update to android to support 3/4 player games

This commit is contained in:
austinio7116
2018-03-14 23:05:07 +00:00
committed by maustin
parent b01f950a28
commit df61e5d9aa
3 changed files with 59 additions and 15 deletions

View File

@@ -43,7 +43,7 @@ import forge.util.Utils;
public abstract class LobbyScreen extends LaunchScreen implements ILobbyView { public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
private static final ForgePreferences prefs = FModel.getPreferences(); private static final ForgePreferences prefs = FModel.getPreferences();
private static final float PADDING = Utils.scale(5); private static final float PADDING = Utils.scale(5);
public static final int MAX_PLAYERS = 2; //8; //TODO: Support multiplayer public static final int MAX_PLAYERS = 4; //8; //TODO: Support multiplayer
private static final FSkinFont VARIANTS_FONT = FSkinFont.get(12); private static final FSkinFont VARIANTS_FONT = FSkinFont.get(12);
// General variables // General variables
@@ -84,8 +84,6 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
public LobbyScreen(String headerCaption, FPopupMenu menu, GameLobby lobby0) { public LobbyScreen(String headerCaption, FPopupMenu menu, GameLobby lobby0) {
super(headerCaption, menu); super(headerCaption, menu);
initLobby(lobby0);
btnStart.setEnabled(false); //disable start button until decks loaded btnStart.setEnabled(false); //disable start button until decks loaded
add(lblPlayers); add(lblPlayers);
@@ -99,13 +97,20 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
@Override @Override
public void handleEvent(FEvent e) { public void handleEvent(FEvent e) {
int numPlayers = getNumPlayers(); int numPlayers = getNumPlayers();
while(lobby.getNumberOfSlots()<getNumPlayers()){
lobby.addSlot();
}
for (int i = 0; i < MAX_PLAYERS; i++) { for (int i = 0; i < MAX_PLAYERS; i++) {
playerPanels.get(i).setVisible(i < numPlayers); if(i<playerPanels.size()) {
playerPanels.get(i).setVisible(i < numPlayers);
}
} }
playersScroll.revalidate(); playersScroll.revalidate();
} }
}); });
initLobby(lobby0);
add(lblVariants); add(lblVariants);
add(cbVariants); add(cbVariants);
cbVariants.setFont(VARIANTS_FONT); cbVariants.setFont(VARIANTS_FONT);
@@ -148,9 +153,13 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
public void run() { public void run() {
playerPanels.get(0).initialize(FPref.CONSTRUCTED_P1_DECK_STATE, FPref.COMMANDER_P1_DECK_STATE, FPref.TINY_LEADER_P1_DECK_STATE, DeckType.PRECONSTRUCTED_DECK); playerPanels.get(0).initialize(FPref.CONSTRUCTED_P1_DECK_STATE, FPref.COMMANDER_P1_DECK_STATE, FPref.TINY_LEADER_P1_DECK_STATE, DeckType.PRECONSTRUCTED_DECK);
playerPanels.get(1).initialize(FPref.CONSTRUCTED_P2_DECK_STATE, FPref.COMMANDER_P2_DECK_STATE, FPref.TINY_LEADER_P2_DECK_STATE, DeckType.COLOR_DECK); playerPanels.get(1).initialize(FPref.CONSTRUCTED_P2_DECK_STATE, FPref.COMMANDER_P2_DECK_STATE, FPref.TINY_LEADER_P2_DECK_STATE, DeckType.COLOR_DECK);
/*playerPanels.get(2).initialize(FPref.CONSTRUCTED_P3_DECK_STATE, DeckType.COLOR_DECK); if(getNumPlayers()>2) {
playerPanels.get(3).initialize(FPref.CONSTRUCTED_P4_DECK_STATE, DeckType.COLOR_DECK); playerPanels.get(2).initialize(FPref.CONSTRUCTED_P3_DECK_STATE, FPref.COMMANDER_P3_DECK_STATE, FPref.TINY_LEADER_P3_DECK_STATE, DeckType.COLOR_DECK);
playerPanels.get(4).initialize(FPref.CONSTRUCTED_P5_DECK_STATE, DeckType.COLOR_DECK); }
if(getNumPlayers()>3) {
playerPanels.get(3).initialize(FPref.CONSTRUCTED_P4_DECK_STATE, FPref.COMMANDER_P4_DECK_STATE, FPref.TINY_LEADER_P4_DECK_STATE, DeckType.COLOR_DECK);
}
/*playerPanels.get(4).initialize(FPref.CONSTRUCTED_P5_DECK_STATE, DeckType.COLOR_DECK);
playerPanels.get(5).initialize(FPref.CONSTRUCTED_P6_DECK_STATE, DeckType.COLOR_DECK); playerPanels.get(5).initialize(FPref.CONSTRUCTED_P6_DECK_STATE, DeckType.COLOR_DECK);
playerPanels.get(6).initialize(FPref.CONSTRUCTED_P7_DECK_STATE, DeckType.COLOR_DECK); playerPanels.get(6).initialize(FPref.CONSTRUCTED_P7_DECK_STATE, DeckType.COLOR_DECK);
playerPanels.get(7).initialize(FPref.CONSTRUCTED_P8_DECK_STATE, DeckType.COLOR_DECK);*/ //TODO: Support multiplayer and improve performance of loading this screen by using background thread playerPanels.get(7).initialize(FPref.CONSTRUCTED_P8_DECK_STATE, DeckType.COLOR_DECK);*/ //TODO: Support multiplayer and improve performance of loading this screen by using background thread
@@ -165,8 +174,8 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
}); });
//disable player count for now until multiplayer supported //disable player count for now until multiplayer supported
lblPlayers.setEnabled(false); lblPlayers.setEnabled(true);
cbPlayerCount.setEnabled(false); cbPlayerCount.setEnabled(true);
} }
public GameLobby getLobby() { public GameLobby getLobby() {
@@ -180,6 +189,9 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
btnStart.setEnabled(hasControl); btnStart.setEnabled(hasControl);
lblVariants.setEnabled(hasControl); lblVariants.setEnabled(hasControl);
cbVariants.setEnabled(hasControl); cbVariants.setEnabled(hasControl);
while(lobby.getNumberOfSlots()<getNumPlayers()){
lobby.addSlot();
}
} }
private void updateVariantSelection() { private void updateVariantSelection() {
@@ -447,7 +459,7 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
@Override @Override
public void update(final boolean fullUpdate) { public void update(final boolean fullUpdate) {
int playerCount = lobby.getNumberOfSlots(); int playerCount = lobby.getNumberOfSlots();
cbPlayerCount.setSelectedItem(playerCount); //cbPlayerCount.setSelectedItem(playerCount);
updateVariantSelection(); updateVariantSelection();
@@ -465,6 +477,12 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
} }
else { else {
panel = new PlayerPanel(this, allowNetworking, i, slot, lobby.mayEdit(i), lobby.hasControl()); panel = new PlayerPanel(this, allowNetworking, i, slot, lobby.mayEdit(i), lobby.hasControl());
if(i==2) {
panel.initialize(FPref.CONSTRUCTED_P3_DECK_STATE, FPref.COMMANDER_P3_DECK_STATE, FPref.TINY_LEADER_P3_DECK_STATE, DeckType.COLOR_DECK);
}
if(i==3) {
panel.initialize(FPref.CONSTRUCTED_P4_DECK_STATE, FPref.COMMANDER_P4_DECK_STATE, FPref.TINY_LEADER_P4_DECK_STATE, DeckType.COLOR_DECK);
}
playerPanels.add(panel); playerPanels.add(panel);
playersScroll.add(panel); playersScroll.add(panel);
isNewPanel = true; isNewPanel = true;

View File

@@ -70,7 +70,7 @@ public class MatchScreen extends FScreen {
private final VDevMenu devMenu; private final VDevMenu devMenu;
private final FieldScroller scroller; private final FieldScroller scroller;
private final VPrompt bottomPlayerPrompt, topPlayerPrompt; private final VPrompt bottomPlayerPrompt, topPlayerPrompt;
private VPlayerPanel bottomPlayerPanel, topPlayerPanel; private VPlayerPanel bottomPlayerPanel, bottomPlayerPanel2, topPlayerPanel, topPlayerPanel2;
private AbilityEffect activeEffect; private AbilityEffect activeEffect;
public MatchScreen(List<VPlayerPanel> playerPanels0) { public MatchScreen(List<VPlayerPanel> playerPanels0) {
@@ -84,6 +84,14 @@ public class MatchScreen extends FScreen {
bottomPlayerPanel = playerPanels0.get(0); bottomPlayerPanel = playerPanels0.get(0);
topPlayerPanel = playerPanels0.get(1); topPlayerPanel = playerPanels0.get(1);
topPlayerPanel.setFlipped(true); topPlayerPanel.setFlipped(true);
if(is3Player()||is4Player()){
topPlayerPanel2 = playerPanels0.get(2);
topPlayerPanel2.setFlipped(true);
}
if(is4Player()){
bottomPlayerPanel2 = playerPanels0.get(3);
}
bottomPlayerPrompt = add(new VPrompt("", "", bottomPlayerPrompt = add(new VPrompt("", "",
new FEventHandler() { new FEventHandler() {
@@ -154,6 +162,14 @@ public class MatchScreen extends FScreen {
} }
} }
private boolean is4Player(){
return playerPanels.keySet().size()==4;
}
private boolean is3Player(){
return playerPanels.keySet().size()==3;
}
private IGameController getGameController() { private IGameController getGameController() {
return MatchController.instance.getGameController(); return MatchController.instance.getGameController();
} }
@@ -547,9 +563,19 @@ public class MatchScreen extends FScreen {
topPlayerPanelHeight += VAvatar.HEIGHT; topPlayerPanelHeight += VAvatar.HEIGHT;
bottomPlayerPanelHeight += VAvatar.HEIGHT; bottomPlayerPanelHeight += VAvatar.HEIGHT;
} }
if(is4Player()){
topPlayerPanel.setBounds(0, 0, visibleWidth, topPlayerPanelHeight); topPlayerPanel.setBounds(0, 0, visibleWidth / 2f, topPlayerPanelHeight);
bottomPlayerPanel.setBounds(0, totalHeight - bottomPlayerPanelHeight, visibleWidth, bottomPlayerPanelHeight); bottomPlayerPanel.setBounds(0, totalHeight - bottomPlayerPanelHeight, visibleWidth / 2f, bottomPlayerPanelHeight);
topPlayerPanel2.setBounds(visibleWidth / 2f, 0, visibleWidth / 2f, topPlayerPanelHeight);
bottomPlayerPanel2.setBounds(visibleWidth / 2f, totalHeight - bottomPlayerPanelHeight, visibleWidth / 2f, bottomPlayerPanelHeight);
}else if(is3Player()){
topPlayerPanel.setBounds(0, 0, visibleWidth / 2f, topPlayerPanelHeight);
bottomPlayerPanel.setBounds(0, totalHeight - bottomPlayerPanelHeight, visibleWidth, bottomPlayerPanelHeight);
topPlayerPanel2.setBounds(visibleWidth / 2f, 0, visibleWidth / 2f, topPlayerPanelHeight);
}else{
topPlayerPanel.setBounds(0, 0, visibleWidth, topPlayerPanelHeight);
bottomPlayerPanel.setBounds(0, totalHeight - bottomPlayerPanelHeight, visibleWidth / 2f, bottomPlayerPanelHeight);
}
return new ScrollBounds(visibleWidth, totalHeight); return new ScrollBounds(visibleWidth, totalHeight);
} }

View File

@@ -177,7 +177,7 @@ public abstract class GameLobby implements IHasGameType {
slot.setIsArchenemy(true); slot.setIsArchenemy(true);
lastArchenemy = 0; lastArchenemy = 0;
} }
updateView(false); updateView(true);
} }
private String randomName() { private String randomName() {
final List<String> names = Lists.newArrayListWithCapacity(MAX_PLAYERS); final List<String> names = Lists.newArrayListWithCapacity(MAX_PLAYERS);