diff --git a/src/main/java/org/betterx/bclib/BCLib.java b/src/main/java/org/betterx/bclib/BCLib.java index 0c1e40d0..5f07700e 100644 --- a/src/main/java/org/betterx/bclib/BCLib.java +++ b/src/main/java/org/betterx/bclib/BCLib.java @@ -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); - } + VersionChecker.registerMod(MOD_ID); + if (false && isDevEnvironment()) { BCLBiome theYellow = BCLBiomeBuilder diff --git a/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java b/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java index 4e0b94f8..44bf419b 100644 --- a/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java @@ -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 void addRow(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription option) { if (ConfigKeeper.BooleanEntry.class.isAssignableFrom(option.token.type)) { addCheckbox(grid, config, (ConfigTokenDescription) option); + } else if (ConfigKeeper.FloatEntry.class.isAssignableFrom(option.token.type)) { + addFloat(grid, config, (ConfigTokenDescription) option); } grid.addSpacer(2); } + protected void addFloat(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription option) { + if (option.topPadding > 0) { + grid.addSpacer(option.topPadding); + } + HorizontalStack row = grid.addRow(); + if (option.leftPadding > 0) { + row.addSpacer(option.leftPadding); + } + Range 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 option) { if (option.topPadding > 0) { diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java index 0964fc65..04cc6777 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java @@ -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()) diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java index 76363263..fa44493c 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java @@ -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 -> { diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java index 57a4eaf2..88fe8c8a 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java @@ -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")) - .setColor(ColorUtil.GRAY); + 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); + } } diff --git a/src/main/java/org/betterx/bclib/config/ClientConfig.java b/src/main/java/org/betterx/bclib/config/ClientConfig.java index 2f021e76..fb298fdb 100644 --- a/src/main/java/org/betterx/bclib/config/ClientConfig.java +++ b/src/main/java/org/betterx/bclib/config/ClientConfig.java @@ -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 DID_SHOW_WELCOME = ConfigToken.Boolean( + false, + "didShowWelcome", + "version" + ); + @ConfigUI(topPadding = 12) + public static final ConfigToken CHECK_VERSIONS = ConfigToken.Boolean( + true, + "check", + "version" + ); + @ConfigUI(leftPadding = 8) + public static final ConfigToken SHOW_UPDATE_INFO = ConfigToken.Boolean( + true, + "showUpdateInfo", + "ui" + ); public static final ConfigToken SUPPRESS_EXPERIMENTAL_DIALOG = ConfigToken.Boolean( false, "suppressExperimentalDialogOnLoad", "ui" ); + + @ConfigUI(hide = true) + public static final ConfigToken NO_DONOR = ConfigToken.Boolean( + false, + "iAmNotTheDonorType", + "ui" + ); + + @ConfigUI(topPadding = 12) public static final ConfigToken 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 DEBUG_HASHES = ConfigToken.Boolean( false, "debugHashes", AutoSync.SYNC_CATEGORY ); - @ConfigUI(leftPadding = 8) + @ConfigUI(topPadding = 12) public static final ConfigToken CUSTOM_FOG_RENDERING = ConfigToken.Boolean( true, "customFogRendering", "rendering" ); @ConfigUI(leftPadding = 8) - public static final ConfigToken NETHER_THICK_FOG = ConfigToken.Boolean( + public static final ConfigToken NETHER_THICK_FOG = DependendConfigToken.Boolean( true, "netherThickFog", - "rendering" + "rendering", + (config) -> config.get(CUSTOM_FOG_RENDERING) ); - public static final ConfigToken FOG_DENSITY = ConfigToken.Float( + @ConfigUI(leftPadding = 8, minValue = 0, maxValue = 2) + public static final ConfigToken FOG_DENSITY = DependendConfigToken.Float( 1.0f, "FogDensity", - "rendering" + "rendering", + (config) -> config.get(CUSTOM_FOG_RENDERING) ); - public static final ConfigToken SHOW_UPDATE_INFO = ConfigToken.Boolean( - true, - "showUpdateInfo", - "ui" - ); - - @ConfigUI(leftPadding = 8) - public static final ConfigToken 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); + } } diff --git a/src/main/java/org/betterx/bclib/config/Config.java b/src/main/java/org/betterx/bclib/config/Config.java index 56a9a465..45223139 100644 --- a/src/main/java/org/betterx/bclib/config/Config.java +++ b/src/main/java/org/betterx/bclib/config/Config.java @@ -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; diff --git a/src/main/java/org/betterx/bclib/config/ConfigKeeper.java b/src/main/java/org/betterx/bclib/config/ConfigKeeper.java index c4fc171e..6571b1f7 100644 --- a/src/main/java/org/betterx/bclib/config/ConfigKeeper.java +++ b/src/main/java/org/betterx/bclib/config/ConfigKeeper.java @@ -57,11 +57,17 @@ public final class ConfigKeeper { } private static Pair> find(JsonObject json, Pair key) { + String kk = key.first + key.second; for (var entry : json.entrySet()) { final Pair 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 otherKey = ConfigKey.realKey(entry.getKey()); +// if (otherKey.first.equals(key.first)) return new Pair<>(entry.getValue(), otherKey); +// } + return null; } diff --git a/src/main/java/org/betterx/bclib/config/ConfigUI.java b/src/main/java/org/betterx/bclib/config/ConfigUI.java index 2e7942c7..d2fc94ff 100644 --- a/src/main/java/org/betterx/bclib/config/ConfigUI.java +++ b/src/main/java/org/betterx/bclib/config/ConfigUI.java @@ -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; } diff --git a/src/main/java/org/betterx/bclib/config/MainConfig.java b/src/main/java/org/betterx/bclib/config/MainConfig.java index 70c74eb5..3bb49fd5 100644 --- a/src/main/java/org/betterx/bclib/config/MainConfig.java +++ b/src/main/java/org/betterx/bclib/config/MainConfig.java @@ -19,21 +19,6 @@ public class MainConfig extends NamedPathConfig { ); - @ConfigUI(hide = true) - public static final ConfigToken DID_SHOW_WELCOME = ConfigToken.Boolean( - false, - "did_show_welcome", - "version" - ); - - public static final ConfigToken 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); - } } diff --git a/src/main/java/org/betterx/bclib/config/NamedPathConfig.java b/src/main/java/org/betterx/bclib/config/NamedPathConfig.java index f8e35b0d..d90859fa 100644 --- a/src/main/java/org/betterx/bclib/config/NamedPathConfig.java +++ b/src/main/java/org/betterx/bclib/config/NamedPathConfig.java @@ -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 defaultValue, + String entry, + String path, + Predicate dependenciesTrue + ) { + return new DependendConfigToken( + ConfigKeeper.FloatEntry.class, + defaultValue, + entry, + path, + dependenciesTrue + ); + } } public static class ConfigToken extends ConfigKey { diff --git a/src/main/java/org/betterx/bclib/networking/VersionChecker.java b/src/main/java/org/betterx/bclib/networking/VersionChecker.java index 43652a65..d79dc967 100644 --- a/src/main/java/org/betterx/bclib/networking/VersionChecker.java +++ b/src/main/java/org/betterx/bclib/networking/VersionChecker.java @@ -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(); } diff --git a/src/main/java/org/betterx/bclib/networking/VersionCheckerClient.java b/src/main/java/org/betterx/bclib/networking/VersionCheckerClient.java index 553a300d..f6baae73 100644 --- a/src/main/java/org/betterx/bclib/networking/VersionCheckerClient.java +++ b/src/main/java/org/betterx/bclib/networking/VersionCheckerClient.java @@ -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()) { diff --git a/src/main/resources/assets/bclib/lang/de_de.json b/src/main/resources/assets/bclib/lang/de_de.json index edf2b490..cea9f3bc 100644 --- a/src/main/resources/assets/bclib/lang/de_de.json +++ b/src/main/resources/assets/bclib/lang/de_de.json @@ -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" } \ No newline at end of file diff --git a/src/main/resources/assets/bclib/lang/en_us.json b/src/main/resources/assets/bclib/lang/en_us.json index 1688594d..5553ec6e 100644 --- a/src/main/resources/assets/bclib/lang/en_us.json +++ b/src/main/resources/assets/bclib/lang/en_us.json @@ -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" } \ No newline at end of file