Save configs from ModMenu-Screen
This commit is contained in:
parent
092e0a39e8
commit
b369954c05
7 changed files with 68 additions and 24 deletions
|
@ -32,11 +32,13 @@ public class AutoSync {
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public static class ClientConfig extends NamedPathConfig{
|
public static class ClientConfig extends NamedPathConfig{
|
||||||
public static final ConfigToken.Bool DEBUG_HASHES = new Bool(true, SYNC_CATEGORY, "debugHashes");
|
public static final ConfigToken.Bool ENABLED = new Bool(true, "enabled", SYNC_CATEGORY);
|
||||||
public static final ConfigToken.Bool ENABLED = new Bool(true, SYNC_CATEGORY, "enabled");
|
public static final ConfigToken.Bool ACCEPT_CONFIGS = new Bool(true,"acceptConfigs", SYNC_CATEGORY);
|
||||||
public static final ConfigToken.Bool ACCEPT_CONFIGS = new Bool(true, "acceptConfigs", "enabled");
|
public static final ConfigToken.Bool ACCEPT_FILES = new Bool(true,"acceptFiles", SYNC_CATEGORY);
|
||||||
public static final ConfigToken.Bool ACCEPT_FILES = new Bool(true, "acceptFiles", "enabled");
|
public static final ConfigToken.Bool ACCEPT_MODS = new Bool(true,"acceptMods", SYNC_CATEGORY);
|
||||||
public static final ConfigToken.Bool ACCEPT_MODS = new Bool(true, "acceptMods", "enabled");
|
public static final ConfigToken.Bool SYNC_MOD_FOLDER = new Bool(false, "syncModFolder", SYNC_CATEGORY);
|
||||||
|
public static final ConfigToken.Bool DEBUG_HASHES = new Bool(true, "debugHashes", SYNC_CATEGORY);
|
||||||
|
|
||||||
|
|
||||||
public ClientConfig(){
|
public ClientConfig(){
|
||||||
super(BCLib.MOD_ID, "client", false);
|
super(BCLib.MOD_ID, "client", false);
|
||||||
|
@ -64,10 +66,10 @@ public class AutoSync {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ServerConfig extends NamedPathConfig {
|
public static class ServerConfig extends NamedPathConfig {
|
||||||
public static final ConfigToken.Bool ENABLED = new Bool(true, SYNC_CATEGORY, "enabled");
|
public static final ConfigToken.Bool ENABLED = new Bool(true, "enabled", SYNC_CATEGORY);
|
||||||
public static final ConfigToken.Bool OFFER_CONFIGS = new Bool(true, "offerConfigs", "enabled");
|
public static final ConfigToken.Bool OFFER_CONFIGS = new Bool(true,"offerConfigs", SYNC_CATEGORY);
|
||||||
public static final ConfigToken.Bool OFFER_FILES = new Bool(true, "offerFiles", "enabled");
|
public static final ConfigToken.Bool OFFER_FILES = new Bool(true,"offerFiles", SYNC_CATEGORY);
|
||||||
public static final ConfigToken.Bool OFFER_MODS = new Bool(true, "offerMods", "enabled");
|
public static final ConfigToken.Bool OFFER_MODS = new Bool(true,"offerMods", SYNC_CATEGORY);
|
||||||
|
|
||||||
|
|
||||||
public ServerConfig(){
|
public ServerConfig(){
|
||||||
|
|
|
@ -22,6 +22,7 @@ public abstract class Config {
|
||||||
protected final static Map<AutoSyncID, Config> autoSyncConfigs = new HashMap<>();
|
protected final static Map<AutoSyncID, Config> autoSyncConfigs = new HashMap<>();
|
||||||
protected final ConfigKeeper keeper;
|
protected final ConfigKeeper keeper;
|
||||||
protected final boolean autoSync;
|
protected final boolean autoSync;
|
||||||
|
public final String configID;
|
||||||
|
|
||||||
protected abstract void registerEntries();
|
protected abstract void registerEntries();
|
||||||
|
|
||||||
|
@ -34,12 +35,13 @@ public abstract class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Config(String modID, String group, boolean autoSync, boolean diffContent) {
|
protected Config(String modID, String group, boolean autoSync, boolean diffContent) {
|
||||||
|
configID = modID + "." + group;
|
||||||
this.keeper = new ConfigKeeper(modID, group);
|
this.keeper = new ConfigKeeper(modID, group);
|
||||||
this.registerEntries();
|
this.registerEntries();
|
||||||
this.autoSync = autoSync;
|
this.autoSync = autoSync;
|
||||||
|
|
||||||
if (autoSync) {
|
if (autoSync) {
|
||||||
final String uid = CONFIG_SYNC_PREFIX + modID + "_" + group;
|
final String uid = CONFIG_SYNC_PREFIX + configID;
|
||||||
final AutoSyncID aid = new AutoSyncID(BCLib.MOD_ID, uid);
|
final AutoSyncID aid = new AutoSyncID(BCLib.MOD_ID, uid);
|
||||||
if (diffContent)
|
if (diffContent)
|
||||||
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile(),this::compareForSync);
|
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile(),this::compareForSync);
|
||||||
|
@ -47,7 +49,7 @@ public abstract class Config {
|
||||||
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile());
|
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile());
|
||||||
|
|
||||||
autoSyncConfigs.put(aid, this);
|
autoSyncConfigs.put(aid, this);
|
||||||
BCLib.LOGGER.info("Added Config " + modID + "." + group + " to auto sync (" + (diffContent?"content diff":"file hash") + ")");
|
BCLib.LOGGER.info("Added Config " + configID + " to auto sync (" + (diffContent?"content diff":"file hash") + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@ package ru.bclib.config;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import ru.bclib.BCLib;
|
import ru.bclib.BCLib;
|
||||||
|
import ru.bclib.config.NamedPathConfig.ConfigToken.Bool;
|
||||||
|
import ru.bclib.config.NamedPathConfig.ConfigToken.Float;
|
||||||
|
import ru.bclib.config.NamedPathConfig.ConfigToken.Int;
|
||||||
|
import ru.bclib.config.NamedPathConfig.ConfigToken.Str;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -74,12 +78,19 @@ public class NamedPathConfig extends PathConfig{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void set(ConfigToken what, Object value) {
|
private void set(ConfigToken what, Object value) {
|
||||||
BCLib.LOGGER.error("Accessing " + what + " as general type is not supported.");
|
if (what instanceof Bool) set(what, (boolean)value);
|
||||||
|
else if (what instanceof Int) set(what, (int)value);
|
||||||
|
else if (what instanceof Float) set(what, (float)value);
|
||||||
|
else if (what instanceof Str) set(what, (String)value);
|
||||||
|
else BCLib.LOGGER.error("Accessing " + what + " as general type is not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object get(ConfigToken what){
|
private Object get(ConfigToken what){
|
||||||
BCLib.LOGGER.error("Accessing " + what + " as general type is not supported.");
|
if (what instanceof Bool) return get((Bool)what);
|
||||||
return null;
|
else if (what instanceof Int) return get((Int)what);
|
||||||
|
else if (what instanceof Float) return get((Float)what);
|
||||||
|
else if (what instanceof Str) return get((Str)what);
|
||||||
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(ConfigToken.Int what, int value) {
|
public void set(ConfigToken.Int what, int value) {
|
||||||
|
|
|
@ -31,13 +31,20 @@ public class GridCheckboxCell extends GridCell{
|
||||||
private boolean checked;
|
private boolean checked;
|
||||||
|
|
||||||
GridCheckboxCell(Component text, boolean checked, float alpha, double width, GridValueType widthType, double height) {
|
GridCheckboxCell(Component text, boolean checked, float alpha, double width, GridValueType widthType, double height) {
|
||||||
|
this(text, checked, alpha, width, widthType, height, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
GridCheckboxCell(Component text, boolean checked, float alpha, double width, GridValueType widthType, double height, Consumer<Boolean> onChange) {
|
||||||
super(width, height, widthType, null, null);
|
super(width, height, widthType, null, null);
|
||||||
|
|
||||||
this.componentPlacer = (transform) -> {
|
this.componentPlacer = (transform) -> {
|
||||||
Checkbox cb = new SignalingCheckBox(transform.left, transform.top, transform.width, transform.height,
|
Checkbox cb = new SignalingCheckBox(transform.left, transform.top, transform.width, transform.height,
|
||||||
text,
|
text,
|
||||||
checked,
|
checked,
|
||||||
(state)-> this.checked = state
|
(state)-> {
|
||||||
|
this.checked = state;
|
||||||
|
if (onChange!=null) onChange.accept(state);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
cb.setAlpha(alpha);
|
cb.setAlpha(alpha);
|
||||||
return cb;
|
return cb;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import ru.bclib.gui.gridlayout.GridLayout.VerticalAlignment;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
|
@ -86,6 +87,13 @@ public class GridRow extends GridContainer {
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GridCheckboxCell addCheckbox(Component text, boolean checked, Font font, Consumer<Boolean> onChange){
|
||||||
|
final int width = font.width(text.getVisualOrderText()) + 24 + 2 * 12;
|
||||||
|
|
||||||
|
GridCheckboxCell cell = new GridCheckboxCell(text, checked, 1.0f, width, widthType, 20, onChange);
|
||||||
|
this.cells.add(cell);
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
|
||||||
public GridCheckboxCell addCheckbox(Component text, boolean checked, int height) {
|
public GridCheckboxCell addCheckbox(Component text, boolean checked, int height) {
|
||||||
return addCheckbox(text, checked, 1.0f, height);
|
return addCheckbox(text, checked, 1.0f, height);
|
||||||
|
|
|
@ -19,12 +19,14 @@ public class MainScreen extends GridScreen{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TranslatableComponent getComponent(NamedPathConfig config, ConfigToken.Bool token, String type){
|
protected TranslatableComponent getComponent(NamedPathConfig config, ConfigToken.Bool token, String type){
|
||||||
String path = "";
|
StringBuilder path = new StringBuilder();
|
||||||
for (String p : token.getPath()){
|
for (String p : token.getPath()){
|
||||||
path += "." + p;
|
path.append(".")
|
||||||
|
.append(p);
|
||||||
|
|
||||||
}
|
}
|
||||||
return new TranslatableComponent(type + ".config." + path );
|
path.append(".").append(token.getEntry());
|
||||||
|
return new TranslatableComponent(type + ".config." + config.configID + path );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken token){
|
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken token){
|
||||||
|
@ -37,21 +39,26 @@ public class MainScreen extends GridScreen{
|
||||||
|
|
||||||
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken.Bool token){
|
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken.Bool token){
|
||||||
GridRow row = grid.addRow();
|
GridRow row = grid.addRow();
|
||||||
row.addCheckbox(getComponent(config, token, "title"), config.get(token), 20);
|
row.addCheckbox(getComponent(config, token, "title"), config.get(token), font, (state)-> config.set(token, state));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldCloseOnEsc() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initLayout() {
|
protected void initLayout() {
|
||||||
final int BUTTON_HEIGHT = 20;
|
final int BUTTON_HEIGHT = 20;
|
||||||
grid.addSpacerRow(20);
|
|
||||||
|
|
||||||
Configs.CLIENT_CONFIG.getAllOptions().forEach(o -> addRow(grid, Configs.CLIENT_CONFIG, o));
|
Configs.CLIENT_CONFIG.getAllOptions().forEach(o -> addRow(grid, Configs.CLIENT_CONFIG, o));
|
||||||
|
|
||||||
|
grid.addSpacerRow(15);
|
||||||
GridRow row = grid.addRow();
|
GridRow row = grid.addRow();
|
||||||
row.addFiller();
|
row.addFiller();
|
||||||
row.addButton(CommonComponents.GUI_BACK, BUTTON_HEIGHT, font, (button)->{
|
row.addButton(CommonComponents.GUI_DONE, BUTTON_HEIGHT, font, (button)->{
|
||||||
|
Configs.CLIENT_CONFIG.saveChanges();
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
row.addFiller();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,12 @@
|
||||||
"title.bclib.confirmrestart": "Restart Required",
|
"title.bclib.confirmrestart": "Restart Required",
|
||||||
"message.bclib.confirmrestart": "The requested content was synchronized. You need to restart Minecraft now.",
|
"message.bclib.confirmrestart": "The requested content was synchronized. You need to restart Minecraft now.",
|
||||||
"title.link.bclib.discord": "Discord",
|
"title.link.bclib.discord": "Discord",
|
||||||
"title.bclib.modmenu.main": "BCLib Settings"
|
"title.bclib.modmenu.main": "BCLib Settings",
|
||||||
|
|
||||||
|
"title.config.bclib.client.auto_sync.enabled": "Enable Auto-Sync",
|
||||||
|
"title.config.bclib.client.auto_sync.acceptConfigs": "Accept incoming Confog Files",
|
||||||
|
"title.config.bclib.client.auto_sync.acceptFiles": "Accept incoming Files",
|
||||||
|
"title.config.bclib.client.auto_sync.acceptMods": "Accept incoming Mods",
|
||||||
|
"title.config.bclib.client.auto_sync.syncModFolder": "Sync entire Mod-Folder from Server",
|
||||||
|
"title.config.bclib.client.auto_sync.debugHashes": "Print Debug-Hashes to Log"
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue