mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
DeckChooser will notify of their selection change
This commit is contained in:
@@ -13,11 +13,16 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
@@ -61,6 +66,11 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
|
||||
private final ForgePreferences prefs = Singletons.getModel().getPreferences();
|
||||
private FPref stateSetting = null;
|
||||
|
||||
private Function<ImmutablePair<DeckType, List<String>>, Void> onDeckSelected;
|
||||
public void setChangeListener(Function<ImmutablePair<DeckType, List<String>>, Void> fn) {
|
||||
onDeckSelected = fn;
|
||||
}
|
||||
|
||||
private final MouseAdapter madDecklist = new MouseAdapter() {
|
||||
@Override
|
||||
@@ -72,6 +82,14 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final ListSelectionListener selChangeListener = new ListSelectionListener(){
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if( null != onDeckSelected )
|
||||
onDeckSelected.apply(ImmutablePair.of(selectedDeckType, getLstDecks().getSelectedValuesList()));
|
||||
}
|
||||
};
|
||||
|
||||
public FDeckChooser(final String titleText, boolean forAi, boolean canSwitchType) {
|
||||
setOpaque(false);
|
||||
@@ -103,6 +121,10 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
final String[] listData = new String[] {"Random 1", "Random 2", "Random 3", "Black", "Blue", "Green", "Red", "White"};
|
||||
lst.setListData(listData);
|
||||
lst.setName(DeckgenUtil.DeckTypes.COLORS.toString());
|
||||
|
||||
lst.removeListSelectionListener(selChangeListener);
|
||||
lst.addListSelectionListener(selChangeListener);
|
||||
|
||||
lst.removeMouseListener(madDecklist);
|
||||
lst.addMouseListener(madDecklist);
|
||||
|
||||
@@ -121,6 +143,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
final JList<String> lst = getLstDecks();
|
||||
lst.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
lst.removeListSelectionListener(selChangeListener);
|
||||
lst.addListSelectionListener(selChangeListener);
|
||||
|
||||
lst.removeMouseListener(madDecklist);
|
||||
lst.addMouseListener(madDecklist);
|
||||
|
||||
@@ -150,6 +175,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
|
||||
lst.setListData(listData.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
||||
lst.setName(DeckgenUtil.DeckTypes.CUSTOM.toString());
|
||||
|
||||
lst.removeListSelectionListener(selChangeListener);
|
||||
lst.addListSelectionListener(selChangeListener);
|
||||
lst.removeMouseListener(madDecklist);
|
||||
lst.addMouseListener(madDecklist);
|
||||
|
||||
@@ -182,6 +210,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
|
||||
lst.setListData(listData.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
||||
lst.setName(DeckgenUtil.DeckTypes.PRECON.toString());
|
||||
|
||||
lst.removeListSelectionListener(selChangeListener);
|
||||
lst.addListSelectionListener(selChangeListener);
|
||||
lst.removeMouseListener(madDecklist);
|
||||
lst.addMouseListener(madDecklist);
|
||||
|
||||
@@ -212,6 +243,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
|
||||
lst.setListData(listData.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
||||
lst.setName(DeckgenUtil.DeckTypes.QUESTEVENTS.toString());
|
||||
|
||||
lst.removeListSelectionListener(selChangeListener);
|
||||
lst.addListSelectionListener(selChangeListener);
|
||||
lst.removeMouseListener(madDecklist);
|
||||
lst.addMouseListener(madDecklist);
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ 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;
|
||||
|
||||
@@ -26,10 +26,14 @@ import javax.swing.JRadioButton;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckchooser.FDeckChooser;
|
||||
import forge.gui.deckchooser.DecksComboBox.DeckType;
|
||||
import forge.gui.framework.DragCell;
|
||||
import forge.gui.framework.DragTab;
|
||||
import forge.gui.framework.EDocID;
|
||||
@@ -48,6 +52,7 @@ import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FTextField;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.Lang;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
@@ -319,11 +324,23 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
||||
|
||||
FDeckChooser mainChooser = new FDeckChooser("Main deck:", isPlayerAI(playerIndex));
|
||||
mainChooser.initialize();
|
||||
mainChooser.setChangeListener(new Function<ImmutablePair<DeckType, List<String>>, Void>(){
|
||||
@Override public Void apply(ImmutablePair<DeckType, List<String>> selection) {
|
||||
VSubmenuConstructed.this.onDeckClicked(playerIndex, selection.left, selection.right);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
deckChoosers.add(mainChooser);
|
||||
mainDeckPanel.add(mainChooser, "grow, push, wrap");
|
||||
deckPanelListMain.add(mainDeckPanel);
|
||||
}
|
||||
|
||||
protected void onDeckClicked(int iPlayer, DeckType type, List<String> selectedLines) {
|
||||
// TODO Auto-generated method stub
|
||||
String text = type.toString() + ": " + Lang.joinHomogenous(selectedLines);
|
||||
deckSelectorBtns.get(iPlayer).setText(text);
|
||||
}
|
||||
|
||||
/** Populates the deck panel with the focused player's deck choices. */
|
||||
private void populateDeckPanel(final boolean firstBuild) {
|
||||
if (!firstBuild) { decksFrame.removeAll(); }
|
||||
|
||||
Reference in New Issue
Block a user