mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
disclose and enforce DEV_MODE state in network play
Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>
This commit is contained in:
@@ -98,6 +98,10 @@ public class PlayerPanel extends FPanel {
|
||||
private final FLabel vgdSelectorBtn = new FLabel.ButtonBuilder().text("Select a Vanguard avatar").build();
|
||||
private final FLabel vgdLabel;
|
||||
|
||||
private FCheckBox chkDevMode;
|
||||
|
||||
private boolean allowNetworking;
|
||||
|
||||
private final VLobby lobby;
|
||||
public PlayerPanel(final VLobby lobby, final boolean allowNetworking, final int index, final LobbySlot slot, final boolean mayEdit, final boolean mayControl) {
|
||||
super();
|
||||
@@ -106,6 +110,7 @@ public class PlayerPanel extends FPanel {
|
||||
this.index = index;
|
||||
this.mayEdit = mayEdit;
|
||||
this.mayControl = mayControl;
|
||||
this.allowNetworking = allowNetworking;
|
||||
|
||||
this.deckLabel = lobby.newLabel("Deck:");
|
||||
this.scmLabel = lobby.newLabel("Scheme deck:");
|
||||
@@ -179,6 +184,11 @@ public class PlayerPanel extends FPanel {
|
||||
}
|
||||
});
|
||||
|
||||
if (isNetworkHost()) {
|
||||
createDevModeButton();
|
||||
this.add(chkDevMode);
|
||||
}
|
||||
|
||||
this.type = slot == null ? LobbySlotType.LOCAL : slot.getType();
|
||||
this.setPlayerName(slot == null ? "" : slot.getName());
|
||||
this.setAvatarIndex(slot == null ? 0 : slot.getAvatarIndex());
|
||||
@@ -186,6 +196,10 @@ public class PlayerPanel extends FPanel {
|
||||
update();
|
||||
}
|
||||
|
||||
boolean isNetworkHost() {
|
||||
return this.allowNetworking && this.index == 0;
|
||||
}
|
||||
|
||||
void update() {
|
||||
avatarLabel.setEnabled(mayEdit);
|
||||
avatarLabel.setIcon(FSkin.getAvatars().get(Integer.valueOf(type == LobbySlotType.OPEN ? -1 : avatarIndex)));
|
||||
@@ -200,6 +214,10 @@ public class PlayerPanel extends FPanel {
|
||||
chkReady.setVisible(type == LobbySlotType.LOCAL || type == LobbySlotType.REMOTE);
|
||||
chkReady.setEnabled(mayEdit);
|
||||
|
||||
if (chkDevMode != null) {
|
||||
chkDevMode.setEnabled(mayEdit);
|
||||
}
|
||||
|
||||
closeBtn.setVisible(mayRemove);
|
||||
|
||||
if (mayRemove) {
|
||||
@@ -585,6 +603,23 @@ public class PlayerPanel extends FPanel {
|
||||
});
|
||||
}
|
||||
|
||||
private void createDevModeButton() {
|
||||
chkDevMode = new FCheckBox("Dev Mode");
|
||||
|
||||
chkDevMode.addActionListener(new ActionListener() {
|
||||
@Override public final void actionPerformed(final ActionEvent e) {
|
||||
final boolean toggle = chkDevMode.isSelected();
|
||||
prefs.setPref(FPref.DEV_MODE_ENABLED, String.valueOf(toggle));
|
||||
ForgePreferences.DEV_MODE = toggle;
|
||||
|
||||
// ensure that preferences panel reflects the change
|
||||
prefs.save();
|
||||
|
||||
lobby.setDevMode(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
*/
|
||||
@@ -747,6 +782,15 @@ public class PlayerPanel extends FPanel {
|
||||
chkReady.setSelected(isReady);
|
||||
}
|
||||
|
||||
public boolean isDevMode() {
|
||||
return chkDevMode != null && chkDevMode.isSelected();
|
||||
}
|
||||
public void setIsDevMode(final boolean isDevMode) {
|
||||
if (chkDevMode != null) {
|
||||
chkDevMode.setSelected(isDevMode);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMayEdit(final boolean mayEdit) {
|
||||
this.mayEdit = mayEdit;
|
||||
}
|
||||
|
||||
@@ -275,6 +275,7 @@ public class VLobby implements ILobbyView {
|
||||
commanderDeckChooser.restoreSavedState();
|
||||
tinyLeaderDeckChooser.restoreSavedState();
|
||||
if (i == 0) {
|
||||
slot.setIsDevMode(prefs.getPrefBoolean(FPref.DEV_MODE_ENABLED));
|
||||
changePlayerFocus(0);
|
||||
}
|
||||
isNewPanel = true;
|
||||
@@ -286,6 +287,7 @@ public class VLobby implements ILobbyView {
|
||||
panel.setAvatarIndex(slot.getAvatarIndex());
|
||||
panel.setTeam(slot.getTeam());
|
||||
panel.setIsReady(slot.isReady());
|
||||
panel.setIsDevMode(slot.isDevMode());
|
||||
panel.setIsArchenemy(slot.isArchenemy());
|
||||
panel.setUseAiSimulation(slot.getAiOptions().contains(AIOption.USE_SIMULATION));
|
||||
panel.setMayEdit(lobby.mayEdit(i));
|
||||
@@ -331,6 +333,15 @@ public class VLobby implements ILobbyView {
|
||||
firePlayerChangeListener(index);
|
||||
changePlayerFocus(index);
|
||||
}
|
||||
void setDevMode(final int index) {
|
||||
// clear ready for everyone
|
||||
for (int i = 0; i < activePlayersNum; i++) {
|
||||
final PlayerPanel panel = playerPanels.get(i);
|
||||
panel.setIsReady(false);
|
||||
firePlayerChangeListener(i);
|
||||
}
|
||||
changePlayerFocus(index);
|
||||
}
|
||||
void firePlayerChangeListener(final int index) {
|
||||
if (playerChangeListener != null) {
|
||||
playerChangeListener.update(index, getSlot(index));
|
||||
@@ -361,7 +372,7 @@ public class VLobby implements ILobbyView {
|
||||
|
||||
private UpdateLobbyPlayerEvent getSlot(final int index) {
|
||||
final PlayerPanel panel = playerPanels.get(index);
|
||||
return UpdateLobbyPlayerEvent.create(panel.getType(), panel.getPlayerName(), panel.getAvatarIndex(), panel.getTeam(), panel.isArchenemy(), panel.isReady(), panel.getAiOptions());
|
||||
return UpdateLobbyPlayerEvent.create(panel.getType(), panel.getPlayerName(), panel.getAvatarIndex(), panel.getTeam(), panel.isArchenemy(), panel.isReady(), panel.isDevMode(), panel.getAiOptions());
|
||||
}
|
||||
|
||||
/** Builds the actual deck panel layouts for each player.
|
||||
|
||||
@@ -8,6 +8,7 @@ import forge.game.GameLogEntryType;
|
||||
import forge.gui.framework.FScreen;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.model.FModel;
|
||||
import forge.net.server.FServerManager;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.ForgePreferences;
|
||||
@@ -63,6 +64,11 @@ public enum CSubmenuPreferences implements ICDoc {
|
||||
@Override
|
||||
public void itemStateChanged(final ItemEvent arg0) {
|
||||
if (updating) { return; }
|
||||
// prevent changing DEV_MODE while network game running
|
||||
if (FServerManager.getInstance().isMatchActive()) {
|
||||
System.out.println("Can't change DEV_MODE while a network match is in progress!");
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean toggle = view.getCbDevMode().isSelected();
|
||||
prefs.setPref(FPref.DEV_MODE_ENABLED, String.valueOf(toggle));
|
||||
|
||||
Reference in New Issue
Block a user