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:
Matthew Scott Krafczyk
2025-07-25 09:07:19 -05:00
committed by GitHub
parent 79845eff1d
commit ab2b06500b
11 changed files with 220 additions and 17 deletions

View File

@@ -0,0 +1,56 @@
package forge.model;
import java.util.function.BiConsumer;
import java.util.function.Function;
import forge.localinstance.properties.ForgePreferences;
/**
* Binds any GUI component to a Forge preference key
*/
public class FPrefsBinder<C, V> implements ModelBinder<ForgePreferences.FPref, C, V> {
private final ForgePreferences.FPref prefKey;
private final C component;
/** Extracts a value from the component */
private final Function<C, V> extractor;
/** Pushes a value back into the component */
private final BiConsumer<C, V> applier;
/** conversions between pref store value and component value */
private final Function<V, String> toString;
private final Function<String, V> fromString;
public FPrefsBinder(ForgePreferences.FPref prefKey,
C component,
Function<C, V> extractor,
BiConsumer<C, V> applier,
Function<V, String> toString,
Function<String, V> fromString) {
this.prefKey = prefKey;
this.component = component;
this.extractor = extractor;
this.applier = applier;
this.toString = toString;
this.fromString = fromString;
}
public void load() {
ForgePreferences prefs = FModel.getPreferences();
String prefValue = prefs.getPref(prefKey);
if (prefValue != null) {
V value = fromString.apply(prefValue);
applier.accept(component, value);
}
}
public void save() {
ForgePreferences prefs = FModel.getPreferences();
V value = extractor.apply(component);
String prefValue = toString.apply(value);
prefs.setPref(prefKey, prefValue);
prefs.save();
}
}

View File

@@ -0,0 +1,10 @@
package forge.model;
/**
* Binds any GUI component to a Forge preference key
*/
public interface ModelBinder<K, C, V> {
public void load();
public void save();
}