Config Optimizations
This commit is contained in:
parent
9cb54346a2
commit
a7efcd25ba
15 changed files with 161 additions and 77 deletions
|
@ -80,9 +80,8 @@ public class BCLib implements ModInitializer {
|
|||
Configs.save();
|
||||
|
||||
WorldsTogether.FORCE_SERVER_TO_BETTERX_PRESET = Configs.SERVER_CONFIG.forceBetterXPreset();
|
||||
if (isClient()) {
|
||||
VersionChecker.registerMod(MOD_ID);
|
||||
}
|
||||
|
||||
|
||||
if (false && isDevEnvironment()) {
|
||||
BCLBiome theYellow = BCLBiomeBuilder
|
||||
|
|
|
@ -6,10 +6,7 @@ import org.betterx.bclib.config.Configs;
|
|||
import org.betterx.bclib.config.NamedPathConfig;
|
||||
import org.betterx.bclib.config.NamedPathConfig.ConfigTokenDescription;
|
||||
import org.betterx.bclib.config.NamedPathConfig.DependendConfigToken;
|
||||
import org.betterx.ui.layout.components.Checkbox;
|
||||
import org.betterx.ui.layout.components.HorizontalStack;
|
||||
import org.betterx.ui.layout.components.LayoutComponent;
|
||||
import org.betterx.ui.layout.components.VerticalStack;
|
||||
import org.betterx.ui.layout.components.*;
|
||||
import org.betterx.ui.vanilla.LayoutScreenWithIcon;
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
@ -43,11 +40,33 @@ public class MainScreen extends LayoutScreenWithIcon {
|
|||
protected <T> void addRow(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription<T> option) {
|
||||
if (ConfigKeeper.BooleanEntry.class.isAssignableFrom(option.token.type)) {
|
||||
addCheckbox(grid, config, (ConfigTokenDescription<Boolean>) option);
|
||||
} else if (ConfigKeeper.FloatEntry.class.isAssignableFrom(option.token.type)) {
|
||||
addFloat(grid, config, (ConfigTokenDescription<Float>) option);
|
||||
}
|
||||
|
||||
grid.addSpacer(2);
|
||||
}
|
||||
|
||||
protected void addFloat(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription<Float> option) {
|
||||
if (option.topPadding > 0) {
|
||||
grid.addSpacer(option.topPadding);
|
||||
}
|
||||
HorizontalStack row = grid.addRow();
|
||||
if (option.leftPadding > 0) {
|
||||
row.addSpacer(option.leftPadding);
|
||||
}
|
||||
Range<Float> cb = row.addRange(
|
||||
fixed(200), fit(),
|
||||
getComponent(config, option, "title"),
|
||||
option.minRange,
|
||||
option.maxRange,
|
||||
config.getRaw(option.token)
|
||||
).onChange(
|
||||
(caller, state) -> {
|
||||
config.set(option.token, state);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected void addCheckbox(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription<Boolean> option) {
|
||||
if (option.topPadding > 0) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.betterx.bclib.client.gui.screens;
|
|||
|
||||
import org.betterx.ui.layout.components.LayoutComponent;
|
||||
import org.betterx.ui.layout.components.VerticalStack;
|
||||
import org.betterx.ui.layout.values.Value;
|
||||
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -34,7 +35,7 @@ public class ConfirmRestartScreen extends BCLibLayoutScreen {
|
|||
protected LayoutComponent<?, ?> initContent() {
|
||||
VerticalStack grid = new VerticalStack(fill(), fill());
|
||||
grid.addFiller();
|
||||
grid.addMultilineText(fill(), fit(), this.description).centerHorizontal();
|
||||
grid.addMultilineText(Value.relative(0.9), fit(), this.description).centerHorizontal();
|
||||
grid.addSpacer(10);
|
||||
grid.addButton(fit(), fit(), CommonComponents.GUI_PROCEED)
|
||||
.onPress((button) -> listener.proceed())
|
||||
|
|
|
@ -80,14 +80,13 @@ public class UpdatesScreen extends BCLibLayoutScreen {
|
|||
|
||||
footer.addFiller();
|
||||
footer.addCheckbox(
|
||||
fit(),
|
||||
fit(),
|
||||
fit(), fit(),
|
||||
Component.translatable("Disable Check"),
|
||||
!Configs.MAIN_CONFIG.checkVersions()
|
||||
!Configs.CLIENT_CONFIG.checkVersions()
|
||||
)
|
||||
.onChange((cb, state) -> {
|
||||
Configs.MAIN_CONFIG.setCheckVersions(!state);
|
||||
Configs.MAIN_CONFIG.saveChanges();
|
||||
Configs.CLIENT_CONFIG.setCheckVersions(!state);
|
||||
Configs.CLIENT_CONFIG.saveChanges();
|
||||
});
|
||||
footer.addSpacer(4);
|
||||
footer.addButton(fit(), fit(), CommonComponents.GUI_DONE).onPress((bt -> {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.betterx.bclib.client.gui.screens;
|
||||
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.networking.VersionChecker;
|
||||
import org.betterx.ui.ColorUtil;
|
||||
import org.betterx.ui.layout.components.*;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -37,19 +40,35 @@ public class WelcomeScreen extends BCLibLayoutScreen {
|
|||
}
|
||||
|
||||
content.addHorizontalSeparator(48);
|
||||
content.addCheckbox(fit(), fit(), translatable("bclib.welcome.updater.title"), true)
|
||||
.onChange((cb, state) -> Configs.MAIN_CONFIG.setCheckVersions(state));
|
||||
Checkbox check = content.addCheckbox(
|
||||
fit(),
|
||||
fit(),
|
||||
translatable("bclib.welcome.updater.title"),
|
||||
Configs.CLIENT_CONFIG.checkVersions()
|
||||
)
|
||||
.onChange((cb, state) -> {
|
||||
Configs.CLIENT_CONFIG.setCheckVersions(state);
|
||||
});
|
||||
content.addSpacer(2);
|
||||
content.indent(24)
|
||||
.addMultilineText(fill(), fit(), translatable("bclib.welcome.updater.description"))
|
||||
HorizontalStack dscBox = content.indent(24);
|
||||
dscBox.addMultilineText(fill(), fit(), translatable("bclib.welcome.updater.description"))
|
||||
.setColor(ColorUtil.GRAY);
|
||||
dscBox.addSpacer(8);
|
||||
|
||||
content.addSpacer(16);
|
||||
content.addButton(fit(), fit(), CommonComponents.GUI_PROCEED).onPress((bt) -> {
|
||||
Configs.MAIN_CONFIG.setDidShowWelcomeScreen();
|
||||
Configs.CLIENT_CONFIG.setDidShowWelcomeScreen();
|
||||
Configs.CLIENT_CONFIG.setCheckVersions(check.isChecked());
|
||||
Configs.CLIENT_CONFIG.saveChanges();
|
||||
VersionChecker.startCheck(true);
|
||||
onClose();
|
||||
}).alignRight();
|
||||
|
||||
return VerticalScroll.create(fill(), fill(), content);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBackground(PoseStack poseStack, int i, int j, float f) {
|
||||
GuiComponent.fill(poseStack, 0, 0, width, height, 0xBD343444);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,40 @@ import org.betterx.bclib.BCLib;
|
|||
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSync;
|
||||
|
||||
public class ClientConfig extends NamedPathConfig {
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<Boolean> DID_SHOW_WELCOME = ConfigToken.Boolean(
|
||||
false,
|
||||
"didShowWelcome",
|
||||
"version"
|
||||
);
|
||||
@ConfigUI(topPadding = 12)
|
||||
public static final ConfigToken<Boolean> CHECK_VERSIONS = ConfigToken.Boolean(
|
||||
true,
|
||||
"check",
|
||||
"version"
|
||||
);
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> SHOW_UPDATE_INFO = ConfigToken.Boolean(
|
||||
true,
|
||||
"showUpdateInfo",
|
||||
"ui"
|
||||
);
|
||||
public static final ConfigToken<Boolean> SUPPRESS_EXPERIMENTAL_DIALOG = ConfigToken.Boolean(
|
||||
false,
|
||||
"suppressExperimentalDialogOnLoad",
|
||||
"ui"
|
||||
);
|
||||
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<Boolean> NO_DONOR = ConfigToken.Boolean(
|
||||
false,
|
||||
"iAmNotTheDonorType",
|
||||
"ui"
|
||||
);
|
||||
|
||||
|
||||
@ConfigUI(topPadding = 12)
|
||||
public static final ConfigToken<Boolean> ENABLED = ConfigToken.Boolean(true, "enabled", AutoSync.SYNC_CATEGORY);
|
||||
|
||||
|
@ -41,48 +69,38 @@ public class ClientConfig extends NamedPathConfig {
|
|||
true,
|
||||
"displayModInfo",
|
||||
AutoSync.SYNC_CATEGORY,
|
||||
(config) -> config.get(
|
||||
ENABLED)
|
||||
(config) -> config.get(ENABLED)
|
||||
);
|
||||
|
||||
@ConfigUI(topPadding = 12)
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> DEBUG_HASHES = ConfigToken.Boolean(
|
||||
false,
|
||||
"debugHashes",
|
||||
AutoSync.SYNC_CATEGORY
|
||||
);
|
||||
|
||||
@ConfigUI(leftPadding = 8)
|
||||
@ConfigUI(topPadding = 12)
|
||||
public static final ConfigToken<Boolean> CUSTOM_FOG_RENDERING = ConfigToken.Boolean(
|
||||
true,
|
||||
"customFogRendering",
|
||||
"rendering"
|
||||
);
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> NETHER_THICK_FOG = ConfigToken.Boolean(
|
||||
public static final ConfigToken<Boolean> NETHER_THICK_FOG = DependendConfigToken.Boolean(
|
||||
true,
|
||||
"netherThickFog",
|
||||
"rendering"
|
||||
"rendering",
|
||||
(config) -> config.get(CUSTOM_FOG_RENDERING)
|
||||
);
|
||||
|
||||
public static final ConfigToken<Float> FOG_DENSITY = ConfigToken.Float(
|
||||
@ConfigUI(leftPadding = 8, minValue = 0, maxValue = 2)
|
||||
public static final ConfigToken<Float> FOG_DENSITY = DependendConfigToken.Float(
|
||||
1.0f,
|
||||
"FogDensity",
|
||||
"rendering"
|
||||
"rendering",
|
||||
(config) -> config.get(CUSTOM_FOG_RENDERING)
|
||||
);
|
||||
|
||||
public static final ConfigToken<Boolean> SHOW_UPDATE_INFO = ConfigToken.Boolean(
|
||||
true,
|
||||
"showUpdateInfo",
|
||||
"ui"
|
||||
);
|
||||
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> NO_DONOR = ConfigToken.Boolean(
|
||||
false,
|
||||
"no_donor",
|
||||
"version"
|
||||
);
|
||||
|
||||
public ClientConfig() {
|
||||
super(BCLib.MOD_ID, "client", false);
|
||||
|
@ -135,4 +153,21 @@ public class ClientConfig extends NamedPathConfig {
|
|||
public float fogDensity() {
|
||||
return get(FOG_DENSITY);
|
||||
}
|
||||
|
||||
public boolean checkVersions() {
|
||||
return get(ClientConfig.CHECK_VERSIONS);
|
||||
}
|
||||
|
||||
|
||||
public void setCheckVersions(boolean newValue) {
|
||||
set(ClientConfig.CHECK_VERSIONS, newValue);
|
||||
}
|
||||
|
||||
public boolean didShowWelcomeScreen() {
|
||||
return get(ClientConfig.DID_SHOW_WELCOME);
|
||||
}
|
||||
|
||||
public void setDidShowWelcomeScreen() {
|
||||
set(ClientConfig.DID_SHOW_WELCOME, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,6 +198,7 @@ public abstract class Config {
|
|||
protected boolean setBoolean(ConfigKey key, boolean value) {
|
||||
try {
|
||||
ConfigKeeper.BooleanEntry entry = keeper.getEntry(key, ConfigKeeper.BooleanEntry.class);
|
||||
|
||||
if (entry == null) return false;
|
||||
entry.setValue(value);
|
||||
return true;
|
||||
|
|
|
@ -57,11 +57,17 @@ public final class ConfigKeeper {
|
|||
}
|
||||
|
||||
private static Pair<JsonElement, Pair<String, String>> find(JsonObject json, Pair<String, String> key) {
|
||||
String kk = key.first + key.second;
|
||||
for (var entry : json.entrySet()) {
|
||||
final Pair<String, String> otherKey = ConfigKey.realKey(entry.getKey());
|
||||
if (otherKey.first.equals(key.first)) return new Pair<>(entry.getValue(), otherKey);
|
||||
if (kk.equals(entry)) return new Pair<>(entry.getValue(), otherKey);
|
||||
}
|
||||
|
||||
// for (var entry : json.entrySet()) {
|
||||
// final Pair<String, String> otherKey = ConfigKey.realKey(entry.getKey());
|
||||
// if (otherKey.first.equals(key.first)) return new Pair<>(entry.getValue(), otherKey);
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,4 +22,14 @@ public @interface ConfigUI {
|
|||
* When a Widget is generated for this option, it will be indented by this Value
|
||||
*/
|
||||
int topPadding() default 0;
|
||||
|
||||
/**
|
||||
* When a Slider is generated, this will be the minimum Value
|
||||
*/
|
||||
int minValue() default 0;
|
||||
|
||||
/**
|
||||
* When a Slider is generated, this will be the maximu Value
|
||||
*/
|
||||
int maxValue() default 0;
|
||||
}
|
||||
|
|
|
@ -19,21 +19,6 @@ public class MainConfig extends NamedPathConfig {
|
|||
);
|
||||
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<Boolean> DID_SHOW_WELCOME = ConfigToken.Boolean(
|
||||
false,
|
||||
"did_show_welcome",
|
||||
"version"
|
||||
);
|
||||
|
||||
public static final ConfigToken<Boolean> CHECK_VERSIONS = DependendConfigToken.Boolean(
|
||||
true,
|
||||
"check",
|
||||
"version",
|
||||
(config) -> !config.get(DID_SHOW_WELCOME)
|
||||
);
|
||||
|
||||
|
||||
public MainConfig() {
|
||||
super(BCLib.MOD_ID, "main", true, true);
|
||||
}
|
||||
|
@ -45,21 +30,4 @@ public class MainConfig extends NamedPathConfig {
|
|||
public boolean repairBiomes() {
|
||||
return get(REPAIR_BIOMES);
|
||||
}
|
||||
|
||||
public boolean checkVersions() {
|
||||
return get(CHECK_VERSIONS);
|
||||
}
|
||||
|
||||
public boolean didShowWelcomeScreen() {
|
||||
return get(DID_SHOW_WELCOME);
|
||||
}
|
||||
|
||||
public void setDidShowWelcomeScreen() {
|
||||
set(DID_SHOW_WELCOME, true);
|
||||
}
|
||||
|
||||
|
||||
public void setCheckVersions(boolean newValue) {
|
||||
set(CHECK_VERSIONS, newValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ public class NamedPathConfig extends PathConfig {
|
|||
public final Boolean hidden;
|
||||
public final int leftPadding;
|
||||
public final int topPadding;
|
||||
public final int minRange;
|
||||
public final int maxRange;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ConfigTokenDescription(Field fl) throws IllegalAccessException {
|
||||
|
@ -28,10 +30,14 @@ public class NamedPathConfig extends PathConfig {
|
|||
this.hidden = ui.hide();
|
||||
leftPadding = ui.leftPadding();
|
||||
topPadding = ui.topPadding();
|
||||
minRange = ui.minValue();
|
||||
maxRange = ui.maxValue();
|
||||
} else {
|
||||
this.hidden = false;
|
||||
this.leftPadding = 0;
|
||||
topPadding = 0;
|
||||
minRange = 0;
|
||||
maxRange = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -101,6 +107,21 @@ public class NamedPathConfig extends PathConfig {
|
|||
dependenciesTrue
|
||||
);
|
||||
}
|
||||
|
||||
public static DependendConfigToken<Float> Float(
|
||||
float defaultValue,
|
||||
String entry,
|
||||
String path,
|
||||
Predicate<NamedPathConfig> dependenciesTrue
|
||||
) {
|
||||
return new DependendConfigToken<Float>(
|
||||
ConfigKeeper.FloatEntry.class,
|
||||
defaultValue,
|
||||
entry,
|
||||
path,
|
||||
dependenciesTrue
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigToken<T> extends ConfigKey {
|
||||
|
|
|
@ -57,8 +57,8 @@ public class VersionChecker implements Runnable {
|
|||
private static Thread versionChecker;
|
||||
|
||||
public static void startCheck(boolean isClient) {
|
||||
if (versionChecker == null) {
|
||||
if (Configs.MAIN_CONFIG.checkVersions()) {
|
||||
if (versionChecker == null && isClient) {
|
||||
if (Configs.CLIENT_CONFIG.checkVersions() && Configs.CLIENT_CONFIG.didShowWelcomeScreen()) {
|
||||
versionChecker = new Thread(isClient ? new VersionCheckerClient() : new VersionChecker());
|
||||
versionChecker.start();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import net.fabricmc.api.Environment;
|
|||
public class VersionCheckerClient extends VersionChecker {
|
||||
|
||||
public static void presentUpdateScreen(Screen parent) {
|
||||
if (!Configs.MAIN_CONFIG.didShowWelcomeScreen()) {
|
||||
if (!Configs.CLIENT_CONFIG.didShowWelcomeScreen()) {
|
||||
Minecraft.getInstance().setScreen(new WelcomeScreen(parent));
|
||||
|
||||
} else if (Configs.CLIENT_CONFIG.showUpdateInfo() && !VersionChecker.isEmpty()) {
|
||||
|
|
|
@ -76,5 +76,8 @@
|
|||
"bclib.welcome.description": "... und ein riesiges herzliches **Dankeschön** für das Herunterladen und Spielen unserer Mods. Wir hoffen, dass sie euch genauso viel Spaß machen wie uns.\n\nBevor wir anfangen, gibt es ein paar Dinge, die wir einrichten müssen, also lest bitte den folgenden langweiligen Teil weiter.",
|
||||
"bclib.welcome.donation": "Wenn Dir unsere Mods so gut gefallen, wie wir hoffen, dann denken Sie bitte über eine kleine Spende nach :)",
|
||||
"bclib.welcome.updater.description": "BCLib enthält eine einfache Versionsüberprüfung, die Dich benachrichtigen kann, wenn neue Updates unserer Mods verfügbar sind. Dazu müssen wir eine Ressource von einem unserer Webserver abrufen. Um die Anfrage zu bearbeiten versenden wir zusammen mit Deiner IP-Address (wir müssen ja wissen wohin die Antwort gehen soll) auch Deine Minecraft-Version (damit wir die richtige Mod-Version auswählen können). Die übertragenen Daten werden von uns niemals für andere Zwecke verwendet, verarbeitet oder weitergegeben, müssen aber aus rechtlichen Gründen für 4 Wochen in unseren Log-Dateien gespeichert werden.",
|
||||
"bclib.welcome.updater.title": "Versionsprüfung erlauben"
|
||||
"bclib.welcome.updater.title": "Versionsprüfung erlauben",
|
||||
"title.config.bclib.main.version.check": "Versionsprüfung erlauben",
|
||||
"title.config.bclib.client.ui.showUpdateInfo": "Anzeigen wenn neue Updates verfügabr sind",
|
||||
"title.config.bclib.client.rendering.FogDensity": "Nebeldichte"
|
||||
}
|
|
@ -76,5 +76,8 @@
|
|||
"bclib.welcome.description": "... and a huge hearty **thank you** for downloading and playing our mods. We hope you enjoy them as much as we do.\n\nBefore we start, there are a few things we need to set up, so please continue reading the following boring part.",
|
||||
"bclib.welcome.donation": "If you enjoy our Mods as much as we hope you do, please consider a small Donation :)",
|
||||
"bclib.welcome.updater.description": "BCLib includes a simple version checker that can notify you when new updates of our mods are available. To do this, we need to read a resource from one of our web servers. To process the request, together with your IP address (we need to know where to send the response) we also send your Minecraft version (so we can choose the right mod version). The transmitted data will never be used or processed by us for other purposes, but must be stored in our log files for 4 weeks for legal reasons.",
|
||||
"bclib.welcome.updater.title": "Enable Version Check"
|
||||
"bclib.welcome.updater.title": "Enable Version Check",
|
||||
"title.config.bclib.main.version.check": "Enable Version Check",
|
||||
"title.config.bclib.client.ui.showUpdateInfo": "Allow Update Reminder Screen",
|
||||
"title.config.bclib.client.rendering.FogDensity": "Fog Density"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue