mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
keep player list in CMatchUI, extracted method to setup hand views.
This commit is contained in:
@@ -57,6 +57,8 @@ import forge.properties.ForgePreferences.FPref;
|
|||||||
public enum CMatchUI {
|
public enum CMatchUI {
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
|
private List<Player> sortedPlayers;
|
||||||
|
|
||||||
private ImageIcon getPlayerAvatar(final Player p, final int defaultIndex) {
|
private ImageIcon getPlayerAvatar(final Player p, final int defaultIndex) {
|
||||||
LobbyPlayer lp = p.getLobbyPlayer();
|
LobbyPlayer lp = p.getLobbyPlayer();
|
||||||
if (null != lp.getIconImageKey()) {
|
if (null != lp.getIconImageKey()) {
|
||||||
@@ -85,24 +87,12 @@ public enum CMatchUI {
|
|||||||
|
|
||||||
final String[] indices = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
final String[] indices = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||||
|
|
||||||
// Instantiate all required field slots (user at 0) <-- that's not guaranteed
|
// Instantiate all required field slots (user at 0)
|
||||||
|
sortedPlayers = shiftPlayersPlaceLocalFirst(players, localPlayer);
|
||||||
|
|
||||||
|
|
||||||
final List<VField> fields = new ArrayList<VField>();
|
final List<VField> fields = new ArrayList<VField>();
|
||||||
final List<VCommand> commands = new ArrayList<VCommand>();
|
final List<VCommand> commands = new ArrayList<VCommand>();
|
||||||
final List<VHand> hands = new ArrayList<VHand>();
|
|
||||||
|
|
||||||
// get an arranged list so that the first local player is at index 0
|
|
||||||
List<Player> sortedPlayers = Lists.newArrayList(players);
|
|
||||||
int ixFirstHuman = -1;
|
|
||||||
for(int i = 0; i < players.size(); i++) {
|
|
||||||
if( sortedPlayers.get(i).getLobbyPlayer() == localPlayer ) {
|
|
||||||
ixFirstHuman = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( ixFirstHuman > 0 ) {
|
|
||||||
sortedPlayers.add(0, sortedPlayers.remove(ixFirstHuman));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Player p : sortedPlayers) {
|
for (Player p : sortedPlayers) {
|
||||||
@@ -117,7 +107,23 @@ public enum CMatchUI {
|
|||||||
setAvatar(f, getPlayerAvatar(p, Integer.parseInt(indices[i > 2 ? 1 : 0])));
|
setAvatar(f, getPlayerAvatar(p, Integer.parseInt(indices[i > 2 ? 1 : 0])));
|
||||||
f.getLayoutControl().initialize();
|
f.getLayoutControl().initialize();
|
||||||
c.getLayoutControl().initialize();
|
c.getLayoutControl().initialize();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace old instances
|
||||||
|
VMatchUI.SINGLETON_INSTANCE.setCommandViews(commands);
|
||||||
|
VMatchUI.SINGLETON_INSTANCE.setFieldViews(fields);
|
||||||
|
|
||||||
|
VPlayers.SINGLETON_INSTANCE.init(players);
|
||||||
|
|
||||||
|
initHandViews(localPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initHandViews(LobbyPlayer localPlayer) {
|
||||||
|
final List<VHand> hands = new ArrayList<VHand>();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (Player p : sortedPlayers) {
|
||||||
if (p.getLobbyPlayer() == localPlayer) {
|
if (p.getLobbyPlayer() == localPlayer) {
|
||||||
VHand newHand = new VHand(EDocID.Hands[i], p);
|
VHand newHand = new VHand(EDocID.Hands[i], p);
|
||||||
newHand.getLayoutControl().initialize();
|
newHand.getLayoutControl().initialize();
|
||||||
@@ -131,14 +137,23 @@ public enum CMatchUI {
|
|||||||
newHand.getLayoutControl().initialize();
|
newHand.getLayoutControl().initialize();
|
||||||
hands.add(newHand);
|
hands.add(newHand);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace old instances
|
|
||||||
VMatchUI.SINGLETON_INSTANCE.setCommandViews(commands);
|
|
||||||
VMatchUI.SINGLETON_INSTANCE.setFieldViews(fields);
|
|
||||||
VMatchUI.SINGLETON_INSTANCE.setHandViews(hands);
|
VMatchUI.SINGLETON_INSTANCE.setHandViews(hands);
|
||||||
VMatchUI.SINGLETON_INSTANCE.setPlayers(sortedPlayers);
|
}
|
||||||
|
|
||||||
VPlayers.SINGLETON_INSTANCE.init(players);
|
private List<Player> shiftPlayersPlaceLocalFirst(final List<Player> players, LobbyPlayer localPlayer) {
|
||||||
|
// get an arranged list so that the first local player is at index 0
|
||||||
|
List<Player> sortedPlayers = Lists.newArrayList(players);
|
||||||
|
int ixFirstHuman = -1;
|
||||||
|
for(int i = 0; i < players.size(); i++) {
|
||||||
|
if( sortedPlayers.get(i).getLobbyPlayer() == localPlayer ) {
|
||||||
|
ixFirstHuman = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( ixFirstHuman > 0 ) {
|
||||||
|
sortedPlayers.add(0, sortedPlayers.remove(ixFirstHuman));
|
||||||
|
}
|
||||||
|
return sortedPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +174,7 @@ public enum CMatchUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VField getFieldViewFor(Player p) {
|
public VField getFieldViewFor(Player p) {
|
||||||
int idx = VMatchUI.SINGLETON_INSTANCE.getPlayerIndex(p);
|
int idx = getPlayerIndex(p);
|
||||||
return idx < 0 ? null : VMatchUI.SINGLETON_INSTANCE.getFieldViews().get(idx);
|
return idx < 0 ? null : VMatchUI.SINGLETON_INSTANCE.getFieldViews().get(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,4 +255,8 @@ public enum CMatchUI {
|
|||||||
CDetail.SINGLETON_INSTANCE.showCard(c);
|
CDetail.SINGLETON_INSTANCE.showCard(c);
|
||||||
CPicture.SINGLETON_INSTANCE.showCard(c);
|
CPicture.SINGLETON_INSTANCE.showCard(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getPlayerIndex(Player player) {
|
||||||
|
return sortedPlayers.indexOf(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.game.player.Player;
|
|
||||||
import forge.gui.framework.DragCell;
|
import forge.gui.framework.DragCell;
|
||||||
import forge.gui.framework.EDocID;
|
import forge.gui.framework.EDocID;
|
||||||
import forge.gui.framework.IVTopLevelUI;
|
import forge.gui.framework.IVTopLevelUI;
|
||||||
@@ -36,7 +35,6 @@ public enum VMatchUI implements IVTopLevelUI {
|
|||||||
private List<VCommand> lstCommands = new ArrayList<VCommand>();
|
private List<VCommand> lstCommands = new ArrayList<VCommand>();
|
||||||
private List<VField> lstFields = new ArrayList<VField>();
|
private List<VField> lstFields = new ArrayList<VField>();
|
||||||
private List<VHand> lstHands = new ArrayList<VHand>();
|
private List<VHand> lstHands = new ArrayList<VHand>();
|
||||||
private List<Player> lstPlayers = new ArrayList<Player>();
|
|
||||||
|
|
||||||
// Other instantiations
|
// Other instantiations
|
||||||
private final CMatchUI control = null;
|
private final CMatchUI control = null;
|
||||||
@@ -131,11 +129,6 @@ public enum VMatchUI implements IVTopLevelUI {
|
|||||||
this.lstFields = lst0;
|
this.lstFields = lst0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param lst0 List<VField> */
|
|
||||||
public void setPlayers(final List<Player> lst0) {
|
|
||||||
this.lstPlayers = lst0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return {@link java.util.List}<{@link forge.gui.match.nonsigleton.VHand}> */
|
/** @return {@link java.util.List}<{@link forge.gui.match.nonsigleton.VHand}> */
|
||||||
public List<VField> getFieldViews() {
|
public List<VField> getFieldViews() {
|
||||||
return lstFields;
|
return lstFields;
|
||||||
@@ -169,9 +162,4 @@ public enum VMatchUI implements IVTopLevelUI {
|
|||||||
public void setCommandViews(List<VCommand> lstCommands0) {
|
public void setCommandViews(List<VCommand> lstCommands0) {
|
||||||
this.lstCommands = lstCommands0;
|
this.lstCommands = lstCommands0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getPlayerIndex(Player player) {
|
|
||||||
return lstPlayers.indexOf(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import javax.swing.border.Border;
|
|||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
import javax.swing.border.MatteBorder;
|
import javax.swing.border.MatteBorder;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
@@ -126,12 +125,12 @@ public class VField implements IVDoc<CField> {
|
|||||||
if (playerOnwer != null) { tab.setText(playerOnwer.getName() + " Field"); }
|
if (playerOnwer != null) { tab.setText(playerOnwer.getName() + " Field"); }
|
||||||
else { tab.setText("NO PLAYER FOR " + docID.toString()); }
|
else { tab.setText("NO PLAYER FOR " + docID.toString()); }
|
||||||
|
|
||||||
manaLabels.add(ImmutablePair.of(getBuiltFLabel(FSkin.ManaImages.IMG_BLACK, "99", "Black mana"), MagicColor.BLACK));
|
manaLabels.add(Pair.of(getBuiltFLabel(FSkin.ManaImages.IMG_BLACK, "99", "Black mana"), MagicColor.BLACK));
|
||||||
manaLabels.add(ImmutablePair.of(getBuiltFLabel(FSkin.ManaImages.IMG_BLUE, "99", "Blue mana"), MagicColor.BLUE));
|
manaLabels.add(Pair.of(getBuiltFLabel(FSkin.ManaImages.IMG_BLUE, "99", "Blue mana"), MagicColor.BLUE));
|
||||||
manaLabels.add(ImmutablePair.of(getBuiltFLabel(FSkin.ManaImages.IMG_GREEN, "99", "Green mana"), MagicColor.GREEN));
|
manaLabels.add(Pair.of(getBuiltFLabel(FSkin.ManaImages.IMG_GREEN, "99", "Green mana"), MagicColor.GREEN));
|
||||||
manaLabels.add(ImmutablePair.of(getBuiltFLabel(FSkin.ManaImages.IMG_RED, "99", "Red mana"), MagicColor.RED));
|
manaLabels.add(Pair.of(getBuiltFLabel(FSkin.ManaImages.IMG_RED, "99", "Red mana"), MagicColor.RED));
|
||||||
manaLabels.add(ImmutablePair.of(getBuiltFLabel(FSkin.ManaImages.IMG_WHITE, "99", "White mana"), MagicColor.WHITE));
|
manaLabels.add(Pair.of(getBuiltFLabel(FSkin.ManaImages.IMG_WHITE, "99", "White mana"), MagicColor.WHITE));
|
||||||
manaLabels.add(ImmutablePair.of(getBuiltFLabel(FSkin.ManaImages.IMG_COLORLESS, "99", "Colorless mana"), (byte)0));
|
manaLabels.add(Pair.of(getBuiltFLabel(FSkin.ManaImages.IMG_COLORLESS, "99", "Colorless mana"), (byte)0));
|
||||||
|
|
||||||
// TODO player is hard-coded into tabletop...should be dynamic
|
// TODO player is hard-coded into tabletop...should be dynamic
|
||||||
// (haven't looked into it too deeply). Doublestrike 12-04-12
|
// (haven't looked into it too deeply). Doublestrike 12-04-12
|
||||||
|
|||||||
Reference in New Issue
Block a user