mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- New constructed match setup fixes:
* starting a game without preferences set no longer causes issues with avatars or name. * avatars are assigned avatars randomly (except for p1 and p2 who uses their preferences) * right clicking an avatar assigns a new random avatar
This commit is contained in:
@@ -371,6 +371,19 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a clean name from the state that can be used for labels. */
|
||||||
|
public final String getStateForLabel() {
|
||||||
|
String deckType = decksComboBox.getDeckType().toString();
|
||||||
|
String state = deckType;
|
||||||
|
final JList<String> lst = getLstDecks();
|
||||||
|
state += ": ";
|
||||||
|
for (String value : lst.getSelectedValuesList()) {
|
||||||
|
state += value + ", ";
|
||||||
|
}
|
||||||
|
state = state.substring(0, state.length() - 2);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
private void restoreSavedState() {
|
private void restoreSavedState() {
|
||||||
if (stateSetting != null) {
|
if (stateSetting != null) {
|
||||||
String savedState = prefs.getPref(stateSetting);
|
String savedState = prefs.getPref(stateSetting);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import forge.game.GameType;
|
|||||||
import forge.game.player.RegisteredPlayer;
|
import forge.game.player.RegisteredPlayer;
|
||||||
import forge.gui.deckchooser.DecksComboBox.DeckType;
|
import forge.gui.deckchooser.DecksComboBox.DeckType;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
|
import forge.gui.home.settings.GamePlayerUtil;
|
||||||
import forge.gui.menus.IMenuProvider;
|
import forge.gui.menus.IMenuProvider;
|
||||||
import forge.gui.menus.MenuUtil;
|
import forge.gui.menus.MenuUtil;
|
||||||
import forge.gui.toolbox.FOptionPane;
|
import forge.gui.toolbox.FOptionPane;
|
||||||
@@ -31,24 +32,6 @@ public enum CSubmenuConstructed implements ICDoc, IMenuProvider {
|
|||||||
/** */
|
/** */
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
protected enum GamePlayers {
|
|
||||||
HUMAN_VS_AI ("Human v Computer"),
|
|
||||||
AI_VS_AI ("Computer v Computer"),
|
|
||||||
HUMAN_VS_HUMAN ("Human v Human");
|
|
||||||
private String value;
|
|
||||||
private GamePlayers(String value) { this.value = value; }
|
|
||||||
@Override
|
|
||||||
public String toString() { return value; }
|
|
||||||
public static GamePlayers fromString(String value){
|
|
||||||
for (final GamePlayers t : GamePlayers.values()) {
|
|
||||||
if (t.toString().equalsIgnoreCase(value)) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("No Enum specified for this string");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final VSubmenuConstructed view = VSubmenuConstructed.SINGLETON_INSTANCE;
|
private final VSubmenuConstructed view = VSubmenuConstructed.SINGLETON_INSTANCE;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -95,10 +78,10 @@ public enum CSubmenuConstructed implements ICDoc, IMenuProvider {
|
|||||||
private void startGame(final GameType gameType) {
|
private void startGame(final GameType gameType) {
|
||||||
for (final int i : view.getParticipants()) {
|
for (final int i : view.getParticipants()) {
|
||||||
if (view.getDeckChooser(i).getPlayer() == null) {
|
if (view.getDeckChooser(i).getPlayer() == null) {
|
||||||
FOptionPane.showMessageDialog("Please specify a deck for each player first.");
|
FOptionPane.showMessageDialog("Please specify a deck for " + view.getPlayerName(i));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} // Is it even possible anymore? I think current implementation assigns decks automatically.
|
||||||
|
|
||||||
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) {
|
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) {
|
||||||
for (final int i : view.getParticipants()) {
|
for (final int i : view.getParticipants()) {
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ import javax.swing.JCheckBox;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JRadioButton;
|
import javax.swing.JRadioButton;
|
||||||
|
|
||||||
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.gui.deckchooser.FDeckChooser;
|
import forge.gui.deckchooser.FDeckChooser;
|
||||||
@@ -46,6 +47,7 @@ import forge.gui.toolbox.FSkin;
|
|||||||
import forge.gui.toolbox.FTextField;
|
import forge.gui.toolbox.FTextField;
|
||||||
import forge.properties.ForgePreferences;
|
import forge.properties.ForgePreferences;
|
||||||
import forge.properties.ForgePreferences.FPref;
|
import forge.properties.ForgePreferences.FPref;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assembles Swing components of constructed submenu singleton.
|
* Assembles Swing components of constructed submenu singleton.
|
||||||
@@ -164,7 +166,6 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
buildDeckPanel(i);
|
buildDeckPanel(i);
|
||||||
}
|
}
|
||||||
populateDeckPanel(playerWithFocus, true);
|
populateDeckPanel(playerWithFocus, true);
|
||||||
updateDeckSelectorLabels();
|
|
||||||
constructedFrame.add(decksFrame, "grow, push");
|
constructedFrame.add(decksFrame, "grow, push");
|
||||||
constructedFrame.setOpaque(false);
|
constructedFrame.setOpaque(false);
|
||||||
|
|
||||||
@@ -188,10 +189,10 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
int avatarIndex = Integer.parseInt(avatarPrefs[playerIndex]);
|
int avatarIndex = Integer.parseInt(avatarPrefs[playerIndex]);
|
||||||
avatar.setIcon(FSkin.getAvatars().get(avatarIndex));
|
avatar.setIcon(FSkin.getAvatars().get(avatarIndex));
|
||||||
} else {
|
} else {
|
||||||
avatar.setIcon(FSkin.getAvatars().get(playerIndex));
|
setRandomAvatar(avatar);
|
||||||
}
|
}
|
||||||
changeAvatarFocus();
|
changeAvatarFocus();
|
||||||
avatar.setToolTipText("Change this avatar");
|
avatar.setToolTipText("L-click: Select avatar. R-click: Randomize avatar.");
|
||||||
avatar.addFocusListener(avatarFocusListener);
|
avatar.addFocusListener(avatarFocusListener);
|
||||||
avatar.addMouseListener(avatarMouseListener);
|
avatar.addMouseListener(avatarMouseListener);
|
||||||
avatarList.add(avatar);
|
avatarList.add(avatar);
|
||||||
@@ -202,6 +203,9 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
String name;
|
String name;
|
||||||
if (playerIndex == 0) {
|
if (playerIndex == 0) {
|
||||||
name = Singletons.getModel().getPreferences().getPref(FPref.PLAYER_NAME);
|
name = Singletons.getModel().getPreferences().getPref(FPref.PLAYER_NAME);
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
name = "Human";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
name = "Player " + (playerIndex + 1);
|
name = "Player " + (playerIndex + 1);
|
||||||
}
|
}
|
||||||
@@ -236,7 +240,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
playerTypeRadios.add(tmpAI);
|
playerTypeRadios.add(tmpAI);
|
||||||
|
|
||||||
// Deck selector button
|
// Deck selector button
|
||||||
FLabel deckBtn = new FLabel.ButtonBuilder().text("Select a deck" + playerIndex).build();
|
FLabel deckBtn = new FLabel.ButtonBuilder().text("Select a deck").build();
|
||||||
deckBtn.addFocusListener(deckLblFocusListener);
|
deckBtn.addFocusListener(deckLblFocusListener);
|
||||||
deckBtn.addMouseListener(deckLblMouseListener);
|
deckBtn.addMouseListener(deckLblMouseListener);
|
||||||
playerPanel.add(deckBtn, "height 30px, gapy 5px, growx, wrap, span 3 1");
|
playerPanel.add(deckBtn, "height 30px, gapy 5px, growx, wrap, span 3 1");
|
||||||
@@ -280,30 +284,34 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
refreshPanels(true, false);
|
refreshPanels(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDeckSelectorLabels() {
|
public void updatePlayerName(int playerIndex) {
|
||||||
String title = "Current deck: ";
|
String name = prefs.getPref(FPref.PLAYER_NAME);
|
||||||
for (int index = 0; index < deckSelectorBtns.size(); index++) {
|
playerNameBtnList.get(0).setGhostText(name);
|
||||||
|
playerNameBtnList.get(0).setText(name);
|
||||||
|
}
|
||||||
|
|
||||||
ForgePreferences p = Singletons.getModel().getPreferences();
|
private void setRandomAvatar(FLabel avatar) {
|
||||||
switch (index) {
|
int random = MyRandom.getRandom().nextInt(FSkin.getAvatars().size());
|
||||||
case 0: { title = p.getPref(FPref.CONSTRUCTED_P1_DECK_STATE); break; }
|
avatar.setIcon(FSkin.getAvatars().get(random));
|
||||||
case 1: { title = p.getPref(FPref.CONSTRUCTED_P2_DECK_STATE); break; }
|
avatar.repaintSelf();
|
||||||
case 2: { title = p.getPref(FPref.CONSTRUCTED_P3_DECK_STATE); break; }
|
}
|
||||||
case 3: { title = p.getPref(FPref.CONSTRUCTED_P4_DECK_STATE); break; }
|
|
||||||
case 4: { title = p.getPref(FPref.CONSTRUCTED_P5_DECK_STATE); break; }
|
|
||||||
case 5: { title = p.getPref(FPref.CONSTRUCTED_P6_DECK_STATE); break; }
|
|
||||||
case 6: { title = p.getPref(FPref.CONSTRUCTED_P7_DECK_STATE); break; }
|
|
||||||
case 7: { title = p.getPref(FPref.CONSTRUCTED_P8_DECK_STATE); break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
title = title.replace(";", " -> ");
|
public void updateDeckSelectorLabels() {
|
||||||
final FLabel lbl = deckSelectorBtns.get(index);
|
for (int i = 0; i < deckChoosers.size(); i++) {
|
||||||
if (!StringUtils.isBlank(title) && !lbl.getText().matches(title)) {
|
updateDeckSelectorLabel(i);
|
||||||
lbl.setText(title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateDeckSelectorLabel(int playerIndex) {
|
||||||
|
final FLabel lbl = deckSelectorBtns.get(playerIndex);
|
||||||
|
String title = deckChoosers.get(playerIndex).getStateForLabel();
|
||||||
|
title = title.replace(";", " -> ");
|
||||||
|
|
||||||
|
if (!StringUtils.isBlank(title) && !lbl.getText().matches(title)) {
|
||||||
|
lbl.setText(title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void buildDeckPanel(final int playerIndex) {
|
private void buildDeckPanel(final int playerIndex) {
|
||||||
String sectionConstraints = "insets 8";
|
String sectionConstraints = "insets 8";
|
||||||
|
|
||||||
@@ -373,11 +381,11 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
for(FDeckChooser fdc : deckChoosers) {
|
for(FDeckChooser fdc : deckChoosers) {
|
||||||
fdc.populate();
|
fdc.populate();
|
||||||
}
|
}
|
||||||
|
updateDeckSelectorLabels();
|
||||||
|
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(constructedFrame, "gap 20px 20px 20px 0px, push, grow");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(constructedFrame, "gap 20px 20px 20px 0px, push, grow");
|
||||||
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlStart, "gap 0 0 3.5%! 3.5%!, ax center");
|
VHomeUI.SINGLETON_INSTANCE.getPnlDisplay().add(pnlStart, "gap 0 0 3.5%! 3.5%!, ax center");
|
||||||
|
|
||||||
|
|
||||||
if (container.isShowing()) {
|
if (container.isShowing()) {
|
||||||
container.validate();
|
container.validate();
|
||||||
container.repaint();
|
container.repaint();
|
||||||
@@ -558,7 +566,13 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
FLabel avatar = (FLabel)e.getSource();
|
FLabel avatar = (FLabel)e.getSource();
|
||||||
changePlayerFocus(avatarList.indexOf(avatar));
|
int playerIndex = avatarList.indexOf(avatar);
|
||||||
|
|
||||||
|
if (e.getButton() == 3) {
|
||||||
|
setRandomAvatar(avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
changePlayerFocus(playerIndex);
|
||||||
avatar.grabFocus(); // TODO: Replace this with avatar selection which will actually gain focus instead
|
avatar.grabFocus(); // TODO: Replace this with avatar selection which will actually gain focus instead
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,6 +664,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
public void focusGained(FocusEvent e) {
|
public void focusGained(FocusEvent e) {
|
||||||
int deckLblID = deckSelectorBtns.indexOf((FLabel)e.getSource());
|
int deckLblID = deckSelectorBtns.indexOf((FLabel)e.getSource());
|
||||||
changePlayerFocus(deckLblID);
|
changePlayerFocus(deckLblID);
|
||||||
|
updateDeckSelectorLabel(deckLblID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ public final class GamePlayerUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void showThankYouPrompt(String playerName) {
|
private static void showThankYouPrompt(String playerName) {
|
||||||
FOptionPane.showMessageDialog("Thank you, " + playerName + ". " +
|
FOptionPane.showMessageDialog("Thank you, " + playerName + ". "
|
||||||
"You will not be prompted again but you can change\nyour name at any time using the \"Player Name\" setting in Preferences.\n\n");
|
+ "You will not be prompted again but you can change\n"
|
||||||
|
+ "your name at any time using the \"Player Name\" setting in Preferences\n"
|
||||||
|
+ "or via the constructed match setup screen\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPlayerNameUsingFirstTimePrompt() {
|
private static String getPlayerNameUsingFirstTimePrompt() {
|
||||||
|
|||||||
Reference in New Issue
Block a user