mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +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;
|
||||
}
|
||||
|
||||
/** 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() {
|
||||
if (stateSetting != null) {
|
||||
String savedState = prefs.getPref(stateSetting);
|
||||
|
||||
@@ -14,6 +14,7 @@ import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.gui.deckchooser.DecksComboBox.DeckType;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.gui.home.settings.GamePlayerUtil;
|
||||
import forge.gui.menus.IMenuProvider;
|
||||
import forge.gui.menus.MenuUtil;
|
||||
import forge.gui.toolbox.FOptionPane;
|
||||
@@ -31,24 +32,6 @@ public enum CSubmenuConstructed implements ICDoc, IMenuProvider {
|
||||
/** */
|
||||
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;
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -95,10 +78,10 @@ public enum CSubmenuConstructed implements ICDoc, IMenuProvider {
|
||||
private void startGame(final GameType gameType) {
|
||||
for (final int i : view.getParticipants()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
} // Is it even possible anymore? I think current implementation assigns decks automatically.
|
||||
|
||||
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) {
|
||||
for (final int i : view.getParticipants()) {
|
||||
|
||||
@@ -22,9 +22,10 @@ import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Singletons;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckchooser.FDeckChooser;
|
||||
@@ -46,6 +47,7 @@ import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FTextField;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
* Assembles Swing components of constructed submenu singleton.
|
||||
@@ -164,7 +166,6 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
buildDeckPanel(i);
|
||||
}
|
||||
populateDeckPanel(playerWithFocus, true);
|
||||
updateDeckSelectorLabels();
|
||||
constructedFrame.add(decksFrame, "grow, push");
|
||||
constructedFrame.setOpaque(false);
|
||||
|
||||
@@ -188,10 +189,10 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
int avatarIndex = Integer.parseInt(avatarPrefs[playerIndex]);
|
||||
avatar.setIcon(FSkin.getAvatars().get(avatarIndex));
|
||||
} else {
|
||||
avatar.setIcon(FSkin.getAvatars().get(playerIndex));
|
||||
setRandomAvatar(avatar);
|
||||
}
|
||||
changeAvatarFocus();
|
||||
avatar.setToolTipText("Change this avatar");
|
||||
avatar.setToolTipText("L-click: Select avatar. R-click: Randomize avatar.");
|
||||
avatar.addFocusListener(avatarFocusListener);
|
||||
avatar.addMouseListener(avatarMouseListener);
|
||||
avatarList.add(avatar);
|
||||
@@ -202,6 +203,9 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
String name;
|
||||
if (playerIndex == 0) {
|
||||
name = Singletons.getModel().getPreferences().getPref(FPref.PLAYER_NAME);
|
||||
if (name.isEmpty()) {
|
||||
name = "Human";
|
||||
}
|
||||
} else {
|
||||
name = "Player " + (playerIndex + 1);
|
||||
}
|
||||
@@ -236,7 +240,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
playerTypeRadios.add(tmpAI);
|
||||
|
||||
// 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.addMouseListener(deckLblMouseListener);
|
||||
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);
|
||||
}
|
||||
|
||||
private void updateDeckSelectorLabels() {
|
||||
String title = "Current deck: ";
|
||||
for (int index = 0; index < deckSelectorBtns.size(); index++) {
|
||||
public void updatePlayerName(int playerIndex) {
|
||||
String name = prefs.getPref(FPref.PLAYER_NAME);
|
||||
playerNameBtnList.get(0).setGhostText(name);
|
||||
playerNameBtnList.get(0).setText(name);
|
||||
}
|
||||
|
||||
ForgePreferences p = Singletons.getModel().getPreferences();
|
||||
switch (index) {
|
||||
case 0: { title = p.getPref(FPref.CONSTRUCTED_P1_DECK_STATE); break; }
|
||||
case 1: { title = p.getPref(FPref.CONSTRUCTED_P2_DECK_STATE); break; }
|
||||
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; }
|
||||
}
|
||||
private void setRandomAvatar(FLabel avatar) {
|
||||
int random = MyRandom.getRandom().nextInt(FSkin.getAvatars().size());
|
||||
avatar.setIcon(FSkin.getAvatars().get(random));
|
||||
avatar.repaintSelf();
|
||||
}
|
||||
|
||||
title = title.replace(";", " -> ");
|
||||
final FLabel lbl = deckSelectorBtns.get(index);
|
||||
if (!StringUtils.isBlank(title) && !lbl.getText().matches(title)) {
|
||||
lbl.setText(title);
|
||||
}
|
||||
public void updateDeckSelectorLabels() {
|
||||
for (int i = 0; i < deckChoosers.size(); i++) {
|
||||
updateDeckSelectorLabel(i);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
String sectionConstraints = "insets 8";
|
||||
|
||||
@@ -373,11 +381,11 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
for(FDeckChooser fdc : deckChoosers) {
|
||||
fdc.populate();
|
||||
}
|
||||
updateDeckSelectorLabels();
|
||||
|
||||
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");
|
||||
|
||||
|
||||
if (container.isShowing()) {
|
||||
container.validate();
|
||||
container.repaint();
|
||||
@@ -558,7 +566,13 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -650,6 +664,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
public void focusGained(FocusEvent e) {
|
||||
int deckLblID = deckSelectorBtns.indexOf((FLabel)e.getSource());
|
||||
changePlayerFocus(deckLblID);
|
||||
updateDeckSelectorLabel(deckLblID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,8 +33,10 @@ public final class GamePlayerUtil {
|
||||
}
|
||||
|
||||
private static void showThankYouPrompt(String 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");
|
||||
FOptionPane.showMessageDialog("Thank you, " + playerName + ". "
|
||||
+ "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() {
|
||||
|
||||
Reference in New Issue
Block a user