mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- New constructed match setup improvements:
* changing the avatar in match setup or avatar preferences will now update each other to reflect the change to the preferences
This commit is contained in:
@@ -42,7 +42,11 @@ public enum CSubmenuConstructed implements ICDoc, IMenuProvider {
|
|||||||
MenuUtil.setMenuProvider(this);
|
MenuUtil.setMenuProvider(this);
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override public void run() { view.getBtnStart().requestFocusInWindow(); }
|
@Override public void run() {
|
||||||
|
view.refreshAvatarFromPrefs(0);
|
||||||
|
view.refreshAvatarFromPrefs(1);
|
||||||
|
view.getBtnStart().requestFocusInWindow();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ import com.google.common.base.Function;
|
|||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.gui.deckchooser.FDeckChooser;
|
|
||||||
import forge.gui.deckchooser.DecksComboBox.DeckType;
|
import forge.gui.deckchooser.DecksComboBox.DeckType;
|
||||||
|
import forge.gui.deckchooser.FDeckChooser;
|
||||||
import forge.gui.framework.DragCell;
|
import forge.gui.framework.DragCell;
|
||||||
import forge.gui.framework.DragTab;
|
import forge.gui.framework.DragTab;
|
||||||
import forge.gui.framework.EDocID;
|
import forge.gui.framework.EDocID;
|
||||||
@@ -104,7 +104,6 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
private final List<FTextField> playerNameBtnList = new ArrayList<FTextField>(8);
|
private final List<FTextField> playerNameBtnList = new ArrayList<FTextField>(8);
|
||||||
private final List<String> playerNames = new ArrayList<String>(8);
|
private final List<String> playerNames = new ArrayList<String>(8);
|
||||||
private final List<JRadioButton> playerTypeRadios = new ArrayList<JRadioButton>(8);
|
private final List<JRadioButton> playerTypeRadios = new ArrayList<JRadioButton>(8);
|
||||||
private final String[] avatarPrefs = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
|
||||||
private final List<FLabel> avatarList = new ArrayList<FLabel>(8);
|
private final List<FLabel> avatarList = new ArrayList<FLabel>(8);
|
||||||
private final TreeMap<Integer, Integer> usedAvatars = new TreeMap<Integer, Integer>();
|
private final TreeMap<Integer, Integer> usedAvatars = new TreeMap<Integer, Integer>();
|
||||||
|
|
||||||
@@ -196,8 +195,9 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
// Avatar
|
// Avatar
|
||||||
final FLabel avatar = new FLabel.Builder().opaque(true).hoverable(true)
|
final FLabel avatar = new FLabel.Builder().opaque(true).hoverable(true)
|
||||||
.iconScaleFactor(0.99f).iconInBackground(true).build();
|
.iconScaleFactor(0.99f).iconInBackground(true).build();
|
||||||
if (playerIndex < avatarPrefs.length) {
|
String[] currentPrefs = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||||
int avatarIndex = Integer.parseInt(avatarPrefs[playerIndex]);
|
if (playerIndex < currentPrefs.length) {
|
||||||
|
int avatarIndex = Integer.parseInt(currentPrefs[playerIndex]);
|
||||||
avatar.setIcon(FSkin.getAvatars().get(avatarIndex));
|
avatar.setIcon(FSkin.getAvatars().get(avatarIndex));
|
||||||
usedAvatars.put(playerIndex, avatarIndex);
|
usedAvatars.put(playerIndex, avatarIndex);
|
||||||
} else {
|
} else {
|
||||||
@@ -319,6 +319,19 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
playerNameBtnList.get(0).setText(name);
|
playerNameBtnList.get(0).setText(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshAvatarFromPrefs(int playerIndex) {
|
||||||
|
FLabel avatar = avatarList.get(playerIndex);
|
||||||
|
String[] currentPrefs = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||||
|
if (playerIndex < currentPrefs.length) {
|
||||||
|
int avatarIndex = Integer.parseInt(currentPrefs[playerIndex]);
|
||||||
|
avatar.setIcon(FSkin.getAvatars().get(avatarIndex));
|
||||||
|
avatar.repaintSelf();
|
||||||
|
usedAvatars.put(playerIndex, avatarIndex);
|
||||||
|
} else {
|
||||||
|
setRandomAvatar(avatar, playerIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Applies a random avatar, avoiding avatars already used.
|
/** Applies a random avatar, avoiding avatars already used.
|
||||||
* @param playerIndex */
|
* @param playerIndex */
|
||||||
private void setRandomAvatar(FLabel avatar, int playerIndex) {
|
private void setRandomAvatar(FLabel avatar, int playerIndex) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import javax.swing.SwingUtilities;
|
|||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
|
import forge.gui.home.sanctioned.VSubmenuConstructed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the avatars submenu in the home UI.
|
* Controls the avatars submenu in the home UI.
|
||||||
@@ -11,6 +12,8 @@ import forge.gui.framework.ICDoc;
|
|||||||
public enum CSubmenuAvatars implements ICDoc {
|
public enum CSubmenuAvatars implements ICDoc {
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
|
private final VSubmenuAvatars view = VSubmenuAvatars.SINGLETON_INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
}
|
}
|
||||||
@@ -18,7 +21,10 @@ public enum CSubmenuAvatars implements ICDoc {
|
|||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override public void run() { VSubmenuAvatars.SINGLETON_INSTANCE.focusHuman(); }
|
@Override public void run() {
|
||||||
|
view.refreshAvatarFromPrefs(0);
|
||||||
|
view.refreshAvatarFromPrefs(1);
|
||||||
|
view.focusHuman(); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,14 @@ public enum VSubmenuAvatars implements IVSubmenu<CSubmenuAvatars> {
|
|||||||
return lbl;
|
return lbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshAvatarFromPrefs(int playerIndex) {
|
||||||
|
FLabel avatar = playerIndex == 0 ? lblAvatarHuman : lblAvatarAI;
|
||||||
|
String[] currentPrefs = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||||
|
int avatarIndex = Integer.parseInt(currentPrefs[playerIndex]);
|
||||||
|
avatar.setIcon(FSkin.getAvatars().get(avatarIndex));
|
||||||
|
avatar.repaintSelf();
|
||||||
|
}
|
||||||
|
|
||||||
//========== Overridden from IVDoc
|
//========== Overridden from IVDoc
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
Reference in New Issue
Block a user