mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Better Games In Match Selection (#8098)
* Add GamesInMatch combo box selection to booster draft page Also updated combo box default to be seeded with the stored preferences * Working comboboxes for desktop version * Working linked buttons on Mobile * Add binder classes for preferences and other Model components * Move to pref binders for mobile GUI
This commit is contained in:
committed by
GitHub
parent
79845eff1d
commit
ab2b06500b
@@ -51,6 +51,7 @@ import forge.toolbox.FScrollPane;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.Utils;
|
||||
import forge.util.GuiPrefBinders;
|
||||
|
||||
public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
|
||||
private static final ForgePreferences prefs = FModel.getPreferences();
|
||||
@@ -72,6 +73,8 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
|
||||
// Max games in a match frame and variables
|
||||
private final FLabel lblGamesInMatch = new FLabel.Builder().text(Forge.getLocalizer().getMessage("lblMatch") + ":").font(VARIANTS_FONT).build();
|
||||
private final FComboBox<String> cbGamesInMatch = new FComboBox<>();
|
||||
private final GuiPrefBinders.ComboBox cbGamesInMatchBinder =
|
||||
new GuiPrefBinders.ComboBox(FPref.UI_MATCHES_PER_GAME, cbGamesInMatch);
|
||||
|
||||
private final List<PlayerPanel> playerPanels = new ArrayList<>(MAX_PLAYERS);
|
||||
private final FScrollPane playersScroll = new FScrollPane() {
|
||||
@@ -133,8 +136,6 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
|
||||
cbGamesInMatch.addItem("1");
|
||||
cbGamesInMatch.addItem("3");
|
||||
cbGamesInMatch.addItem("5");
|
||||
cbGamesInMatch.setSelectedItem(FModel.getPreferences().getPref((FPref.UI_MATCHES_PER_GAME)));
|
||||
cbGamesInMatch.setChangedHandler(event -> FModel.getPreferences().setPref(FPref.UI_MATCHES_PER_GAME, cbGamesInMatch.getSelectedItem()));
|
||||
|
||||
add(lblVariants);
|
||||
add(cbVariants);
|
||||
@@ -588,6 +589,11 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivate() {
|
||||
cbGamesInMatchBinder.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(final boolean fullUpdate) {
|
||||
int playerCount = lobby.getNumberOfSlots();
|
||||
|
||||
@@ -20,6 +20,7 @@ import forge.gamemodes.match.HostedMatch;
|
||||
import forge.gui.FThreads;
|
||||
import forge.gui.GuiBase;
|
||||
import forge.gui.util.SGuiChoose;
|
||||
import forge.util.GuiPrefBinders;
|
||||
import forge.itemmanager.DeckManager;
|
||||
import forge.itemmanager.ItemManagerConfig;
|
||||
import forge.itemmanager.filters.ItemFilter;
|
||||
@@ -32,6 +33,7 @@ import forge.screens.home.LoadGameMenu;
|
||||
import forge.toolbox.FComboBox;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FOptionPane;
|
||||
import forge.util.Utils;
|
||||
|
||||
public class LoadDraftScreen extends LaunchScreen {
|
||||
private final DeckManager lstDecks = add(new DeckManager(GameType.Draft));
|
||||
@@ -44,6 +46,12 @@ public class LoadDraftScreen extends LaunchScreen {
|
||||
private final FLabel lblMode = add(new FLabel.Builder().text(Forge.getLocalizer().getMessage("lblMode")).font(GAME_MODE_FONT).build());
|
||||
private final FComboBox<String> cbMode = add(new FComboBox<>());
|
||||
|
||||
// Max games in a match frame and variables
|
||||
private final FLabel lblGamesInMatch = add(new FLabel.Builder().text(Forge.getLocalizer().getMessage("lblMatch") + ":").font(GAME_MODE_FONT).build());
|
||||
private final FComboBox<String> cbGamesInMatch = add(new FComboBox<>());
|
||||
private final GuiPrefBinders.ComboBox cbGamesInMatchBinder = new GuiPrefBinders.ComboBox(
|
||||
FPref.UI_MATCHES_PER_GAME, cbGamesInMatch);
|
||||
|
||||
public LoadDraftScreen() {
|
||||
super(null, LoadGameMenu.getMenu());
|
||||
|
||||
@@ -53,12 +61,18 @@ public class LoadDraftScreen extends LaunchScreen {
|
||||
|
||||
lstDecks.setup(ItemManagerConfig.DRAFT_DECKS);
|
||||
lstDecks.setItemActivateHandler(event -> editSelectedDeck());
|
||||
|
||||
cbGamesInMatch.setFont(GAME_MODE_FONT);
|
||||
cbGamesInMatch.addItem("1");
|
||||
cbGamesInMatch.addItem("3");
|
||||
cbGamesInMatch.addItem("5");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivate() {
|
||||
lstDecks.setPool(DeckProxy.getAllDraftDecks());
|
||||
lstDecks.setSelectedString(DeckPreferences.getDraftDeck());
|
||||
cbGamesInMatchBinder.load();
|
||||
}
|
||||
|
||||
private void editSelectedDeck() {
|
||||
@@ -78,8 +92,16 @@ public class LoadDraftScreen extends LaunchScreen {
|
||||
float listHeight = height - labelHeight - y - FDeckChooser.PADDING;
|
||||
float comboBoxHeight = cbMode.getHeight();
|
||||
|
||||
lblMode.setBounds(x, y, lblMode.getAutoSizeBounds().width + FDeckChooser.PADDING / 2, comboBoxHeight);
|
||||
cbMode.setBounds(x + lblMode.getWidth(), y, w - lblMode.getWidth(), comboBoxHeight);
|
||||
float x2 = x;
|
||||
float w1 = lblMode.getAutoSizeBounds().width;
|
||||
float w2 = lblGamesInMatch.getAutoSizeBounds().width;
|
||||
lblMode.setBounds(x2, y, w1 + FDeckChooser.PADDING / 2, comboBoxHeight);
|
||||
x2 += lblMode.getWidth();
|
||||
cbMode.setBounds(x2, y, w - x2 - w2 - Utils.AVG_FINGER_WIDTH, comboBoxHeight);
|
||||
x2 += cbMode.getWidth();
|
||||
lblGamesInMatch.setBounds(x2, y, w2 + FDeckChooser.PADDING / 2, comboBoxHeight);
|
||||
x2 += lblGamesInMatch.getWidth();
|
||||
cbGamesInMatch.setBounds(x2, y, Utils.AVG_FINGER_WIDTH, comboBoxHeight);
|
||||
y += comboBoxHeight + FDeckChooser.PADDING;
|
||||
lstDecks.setBounds(x, y, w, listHeight);
|
||||
y += listHeight + FDeckChooser.PADDING;
|
||||
|
||||
@@ -20,6 +20,7 @@ import forge.gamemodes.match.HostedMatch;
|
||||
import forge.gui.FThreads;
|
||||
import forge.gui.GuiBase;
|
||||
import forge.gui.util.SGuiChoose;
|
||||
import forge.util.GuiPrefBinders;
|
||||
import forge.itemmanager.DeckManager;
|
||||
import forge.itemmanager.ItemManagerConfig;
|
||||
import forge.itemmanager.filters.ItemFilter;
|
||||
@@ -32,6 +33,7 @@ import forge.screens.home.LoadGameMenu;
|
||||
import forge.toolbox.FComboBox;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FOptionPane;
|
||||
import forge.util.Utils;
|
||||
|
||||
public class LoadSealedScreen extends LaunchScreen {
|
||||
private final DeckManager lstDecks = add(new DeckManager(GameType.Draft));
|
||||
@@ -44,6 +46,12 @@ public class LoadSealedScreen extends LaunchScreen {
|
||||
private final FLabel lblMode = add(new FLabel.Builder().text(Forge.getLocalizer().getMessage("lblMode")).font(GAME_MODE_FONT).build());
|
||||
private final FComboBox<String> cbMode = add(new FComboBox<>());
|
||||
|
||||
// Max games in a match frame and variables
|
||||
private final FLabel lblGamesInMatch = add(new FLabel.Builder().text(Forge.getLocalizer().getMessage("lblMatch") + ":").font(GAME_MODE_FONT).build());
|
||||
private final FComboBox<String> cbGamesInMatch = add(new FComboBox<>());
|
||||
private final GuiPrefBinders.ComboBox cbGamesInMatchBinder = new GuiPrefBinders.ComboBox(
|
||||
FPref.UI_MATCHES_PER_GAME, cbGamesInMatch);
|
||||
|
||||
public LoadSealedScreen() {
|
||||
super(null, LoadGameMenu.getMenu());
|
||||
|
||||
@@ -53,12 +61,18 @@ public class LoadSealedScreen extends LaunchScreen {
|
||||
|
||||
lstDecks.setup(ItemManagerConfig.SEALED_DECKS);
|
||||
lstDecks.setItemActivateHandler(event -> editSelectedDeck());
|
||||
|
||||
cbGamesInMatch.setFont(GAME_MODE_FONT);
|
||||
cbGamesInMatch.addItem("1");
|
||||
cbGamesInMatch.addItem("3");
|
||||
cbGamesInMatch.addItem("5");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivate() {
|
||||
lstDecks.setPool(DeckProxy.getAllSealedDecks());
|
||||
lstDecks.setSelectedString(DeckPreferences.getSealedDeck());
|
||||
cbGamesInMatchBinder.load();
|
||||
}
|
||||
|
||||
private void editSelectedDeck() {
|
||||
@@ -78,8 +92,16 @@ public class LoadSealedScreen extends LaunchScreen {
|
||||
float listHeight = height - labelHeight - y - FDeckChooser.PADDING;
|
||||
float comboBoxHeight = cbMode.getHeight();
|
||||
|
||||
lblMode.setBounds(x, y, lblMode.getAutoSizeBounds().width + FDeckChooser.PADDING / 2, comboBoxHeight);
|
||||
cbMode.setBounds(x + lblMode.getWidth(), y, w - lblMode.getWidth(), comboBoxHeight);
|
||||
float x2 = x;
|
||||
float w1 = lblMode.getAutoSizeBounds().width;
|
||||
float w2 = lblGamesInMatch.getAutoSizeBounds().width;
|
||||
lblMode.setBounds(x2, y, w1 + FDeckChooser.PADDING / 2, comboBoxHeight);
|
||||
x2 += lblMode.getWidth();
|
||||
cbMode.setBounds(x2, y, w - x2 - w2 - Utils.AVG_FINGER_WIDTH, comboBoxHeight);
|
||||
x2 += cbMode.getWidth();
|
||||
lblGamesInMatch.setBounds(x2, y, w2 + FDeckChooser.PADDING / 2, comboBoxHeight);
|
||||
x2 += lblGamesInMatch.getWidth();
|
||||
cbGamesInMatch.setBounds(x2, y, Utils.AVG_FINGER_WIDTH, comboBoxHeight);
|
||||
y += comboBoxHeight + FDeckChooser.PADDING;
|
||||
lstDecks.setBounds(x, y, w, listHeight);
|
||||
y += listHeight + FDeckChooser.PADDING;
|
||||
|
||||
23
forge-gui-mobile/src/forge/util/GuiPrefBinders.java
Normal file
23
forge-gui-mobile/src/forge/util/GuiPrefBinders.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package forge.util;
|
||||
|
||||
import forge.toolbox.FComboBox;
|
||||
import forge.localinstance.properties.ForgePreferences;
|
||||
import forge.model.FPrefsBinder;
|
||||
|
||||
public class GuiPrefBinders {
|
||||
public static final class ComboBox extends FPrefsBinder<FComboBox<String>, String> {
|
||||
public ComboBox(ForgePreferences.FPref key, FComboBox<String> box) {
|
||||
super(
|
||||
key,
|
||||
box,
|
||||
b -> (String) b.getSelectedItem(),
|
||||
(b, s) -> b.setSelectedItem(s),
|
||||
s -> s,
|
||||
s -> s);
|
||||
|
||||
box.setChangedHandler(e -> {
|
||||
this.save();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user