Allow clicking anywhere inside player panel to select it

Distinguish selected player better using semi-transparent overlay for other panels
This commit is contained in:
drdev
2014-01-17 05:55:30 +00:00
parent dd044c30e6
commit ba59dfb01c
2 changed files with 43 additions and 54 deletions

View File

@@ -1,10 +1,11 @@
package forge.gui.home.sanctioned; package forge.gui.home.sanctioned;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
@@ -45,6 +46,7 @@ import forge.gui.toolbox.FPanel;
import forge.gui.toolbox.FRadioButton; import forge.gui.toolbox.FRadioButton;
import forge.gui.toolbox.FScrollPanel; import forge.gui.toolbox.FScrollPanel;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
import forge.gui.toolbox.FSkin.SkinColor;
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;
@@ -60,7 +62,8 @@ import forge.util.NameGenerator;
*/ */
public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> { public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private final static ForgePreferences prefs = Singletons.getModel().getPreferences(); private static final ForgePreferences prefs = Singletons.getModel().getPreferences();
private static final SkinColor unfocusedPlayerOverlay = FSkin.getColor(FSkin.Colors.CLR_OVERLAY).alphaColor(120);
// Fields used with interface IVDoc // Fields used with interface IVDoc
private DragCell parentCell; private DragCell parentCell;
@@ -70,6 +73,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
private final LblHeader lblTitle = new LblHeader("Sanctioned Format: Constructed"); private final LblHeader lblTitle = new LblHeader("Sanctioned Format: Constructed");
private int activePlayersNum = 2; private int activePlayersNum = 2;
private int playerWithFocus = 0; // index of the player that currently has focus private int playerWithFocus = 0; // index of the player that currently has focus
private PlayerPanel playerPanelWithFocus;
private final FCheckBox cbSingletons = new FCheckBox("Singleton Mode"); private final FCheckBox cbSingletons = new FCheckBox("Singleton Mode");
private final FCheckBox cbArtifacts = new FCheckBox("Remove Artifacts"); private final FCheckBox cbArtifacts = new FCheckBox("Remove Artifacts");
@@ -93,7 +97,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
private final JPanel playersFrame = new JPanel(new MigLayout("insets 0, gap 0 5, wrap, hidemode 3")); private final JPanel playersFrame = new JPanel(new MigLayout("insets 0, gap 0 5, wrap, hidemode 3"));
private final FScrollPanel playersScroll = new FScrollPanel(new MigLayout("insets 0, gap 0, wrap, hidemode 3"), private final FScrollPanel playersScroll = new FScrollPanel(new MigLayout("insets 0, gap 0, wrap, hidemode 3"),
true, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); true, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
private final List<FPanel> playerPanelList = new ArrayList<FPanel>(8); private final List<PlayerPanel> playerPanelList = new ArrayList<PlayerPanel>(8);
private final List<FPanel> activePlayerPanelList = new ArrayList<FPanel>(8); private final List<FPanel> activePlayerPanelList = new ArrayList<FPanel>(8);
private final List<FPanel> inactivePlayerPanelList = new ArrayList<FPanel>(6); private final List<FPanel> inactivePlayerPanelList = new ArrayList<FPanel>(6);
private final List<FTextField> playerNameBtnList = new ArrayList<FTextField>(8); private final List<FTextField> playerNameBtnList = new ArrayList<FTextField>(8);
@@ -160,6 +164,8 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
} }
} }
playerPanelWithFocus = playerPanelList.get(0);
playersFrame.setOpaque(false); playersFrame.setOpaque(false);
playersFrame.add(playersScroll, "grow, push"); playersFrame.add(playersScroll, "grow, push");
@@ -195,7 +201,13 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
} }
private FPanel buildPlayerPanel(final int playerIndex) { private FPanel buildPlayerPanel(final int playerIndex) {
FPanel playerPanel = new FPanel(); PlayerPanel playerPanel = new PlayerPanel();
playerPanel.addMouseListener(new FMouseAdapter() {
@Override
public void onLeftClick(MouseEvent e) {
avatarList.get(playerPanelList.indexOf((FPanel)e.getSource())).requestFocusInWindow();
}
});
playerPanel.setLayout(new MigLayout("insets 10px, gap 5px")); playerPanel.setLayout(new MigLayout("insets 10px, gap 5px"));
// Add a button to players 3+ to remove them from the setup // Add a button to players 3+ to remove them from the setup
@@ -256,11 +268,11 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
FRadioButton tmpHuman = new FRadioButton(); FRadioButton tmpHuman = new FRadioButton();
tmpHuman.setText("Human"); tmpHuman.setText("Human");
tmpHuman.setSelected(playerIndex == 0); tmpHuman.setSelected(playerIndex == 0);
tmpHuman.addFocusListener(radioFocusListener); tmpHuman.addMouseListener(radioMouseAdapter);
FRadioButton tmpAI = new FRadioButton(); FRadioButton tmpAI = new FRadioButton();
tmpAI.setText("AI"); tmpAI.setText("AI");
tmpAI.setSelected(playerIndex != 0); tmpAI.setSelected(playerIndex != 0);
tmpAI.addFocusListener(radioFocusListener); tmpAI.addMouseListener(radioMouseAdapter);
tempBtnGroup.add(tmpHuman); tempBtnGroup.add(tmpHuman);
tempBtnGroup.add(tmpAI); tempBtnGroup.add(tmpAI);
playerTypeRadios.add(tmpHuman); playerTypeRadios.add(tmpHuman);
@@ -271,11 +283,10 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
// Deck selector button // Deck selector button
final FLabel deckBtn = new FLabel.ButtonBuilder().text("Select a deck").build(); final FLabel deckBtn = new FLabel.ButtonBuilder().text("Select a deck").build();
deckBtn.addFocusListener(deckLblFocusListener);
deckBtn.setCommand(new Runnable() { deckBtn.setCommand(new Runnable() {
@Override @Override
public void run() { public void run() {
changePlayerFocus(deckSelectorBtns.indexOf(deckBtn)); avatarList.get(deckSelectorBtns.indexOf(deckBtn)).requestFocusInWindow();
} }
}); });
playerPanel.add(newLabel("Deck:"), "height 30px, gapx rel"); playerPanel.add(newLabel("Deck:"), "height 30px, gapx rel");
@@ -508,22 +519,25 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
} }
} }
@SuppressWarnings("serial")
private class PlayerPanel extends FPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (playerPanelWithFocus != this) {
FSkin.setGraphicsColor(g, unfocusedPlayerOverlay);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
}
}
private void changePlayerFocus(int newFocusOwner) { private void changePlayerFocus(int newFocusOwner) {
if (newFocusOwner != playerWithFocus) { if (newFocusOwner != playerWithFocus) {
playerWithFocus = newFocusOwner; playerWithFocus = newFocusOwner;
FPanel playerPanel = playerPanelList.get(playerWithFocus); playerPanelWithFocus = playerPanelList.get(playerWithFocus);
//TODO (Marc) Style the actual panel for more visible indication of player with focus:
/*for (FPanel itrPanel : playerPanelList) {
if (itrPanel == playerPanel) {
// Make panel less opaque
} else {
// restore default panel opacity
}
}*/
changeAvatarFocus(); changeAvatarFocus();
playersScroll.getViewport().scrollRectToVisible(playerPanel.getBounds()); playersScroll.getViewport().scrollRectToVisible(playerPanelWithFocus.getBounds());
populateDeckPanel(false); populateDeckPanel(false);
refreshPanels(true, true); refreshPanels(true, true);
@@ -620,17 +634,12 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
}; };
/** Listens to avatar buttons and gives the appropriate player focus. */ /** Listens to avatar buttons and gives the appropriate player focus. */
private FocusListener avatarFocusListener = new FocusListener() { private FocusAdapter avatarFocusListener = new FocusAdapter() {
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
int avatarOwnerID = avatarList.indexOf((FLabel)e.getSource()); int avatarOwnerID = avatarList.indexOf((FLabel)e.getSource());
changePlayerFocus(avatarOwnerID); changePlayerFocus(avatarOwnerID);
} }
@Override
public void focusLost(FocusEvent e) {
}
}; };
private FMouseAdapter avatarMouseListener = new FMouseAdapter() { private FMouseAdapter avatarMouseListener = new FMouseAdapter() {
@@ -670,7 +679,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
/** Listens to name text fields and gives the appropriate player focus. /** Listens to name text fields and gives the appropriate player focus.
* Also saves the name preference when leaving player one's text field. */ * Also saves the name preference when leaving player one's text field. */
private FocusListener nameFocusListener = new FocusListener() { private FocusAdapter nameFocusListener = new FocusAdapter() {
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
FTextField nField = (FTextField)e.getSource(); FTextField nField = (FTextField)e.getSource();
@@ -692,33 +701,12 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
} }
}; };
/** Listens to name player type radio buttons and gives the appropriate player focus. */ private FMouseAdapter radioMouseAdapter = new FMouseAdapter() {
private FocusListener radioFocusListener = new FocusListener() {
@Override @Override
public void focusGained(FocusEvent e) { public void onLeftClick(MouseEvent e) {
int radioID = playerTypeRadios.indexOf((FRadioButton)e.getSource()); int radioID = playerTypeRadios.indexOf((FRadioButton)e.getSource());
int radioOwnerID = (int) Math.floor(radioID/2); int radioOwnerID = (int) Math.floor(radioID / 2);
changePlayerFocus(radioOwnerID); avatarList.get(radioOwnerID).requestFocusInWindow();
}
@Override
public void focusLost(FocusEvent e) {
}
};
/** Listens to deck select buttons and gives the appropriate player focus. */
private FocusListener deckLblFocusListener = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
int deckLblID = deckSelectorBtns.indexOf((FLabel)e.getSource());
changePlayerFocus(deckLblID);
updateDeckSelectorLabel(deckLblID);
}
@Override
public void focusLost(FocusEvent e) {
} }
}; };

View File

@@ -19,5 +19,6 @@ public class FRadioButton extends SkinnedRadioButton {
this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
this.setFont(FSkin.getFont(14)); this.setFont(FSkin.getFont(14));
this.setOpaque(false); this.setOpaque(false);
this.setFocusable(false);
} }
} }