aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/config')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java21
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java9
2 files changed, 21 insertions, 9 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java
index 33f4950..57ae2c3 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java
@@ -3,12 +3,16 @@ package shcm.shsupercm.fabric.citresewn.config;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
+import net.fabricmc.loader.api.FabricLoader;
+import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
+import java.util.function.Function;
+
public class CITResewnConfigScreenFactory {
public static Screen create(Screen parent) {
CITResewnConfig currentConfig = CITResewnConfig.INSTANCE, defaultConfig = new CITResewnConfig();
@@ -32,6 +36,21 @@ public class CITResewnConfigScreenFactory {
.setDefaultValue(defaultConfig.enabled)
.build());
+ class CurrentScreen { Screen screen; boolean prevToggle = false; } final CurrentScreen currentScreen = new CurrentScreen();
+ category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.defaults.title"), false)
+ .setTooltip(new TranslatableText("config.citresewn.defaults.tooltip"))
+ .setYesNoTextSupplier((b) -> {
+ if (b != currentScreen.prevToggle) {
+ //noinspection unchecked
+ MinecraftClient.getInstance().setScreen((Screen) FabricLoader.getInstance().getEntrypoints("citresewn-defaults:config_screen", Function.class).stream().findAny().orElseThrow().apply(currentScreen.screen));
+
+ currentScreen.prevToggle = b;
+ }
+
+ return new TranslatableText("config.citresewn.configure");
+ })
+ .build());
+
category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.mute_errors.title"), currentConfig.mute_errors)
.setTooltip(new TranslatableText("config.citresewn.mute_errors.tooltip"))
.setSaveConsumer(newConfig -> currentConfig.mute_errors = newConfig)
@@ -70,6 +89,6 @@ public class CITResewnConfigScreenFactory {
.requireRestart()
.build());
- return builder.build();
+ return currentScreen.screen = builder.build();
}
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java
index cf6d9bd..378350a 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java
@@ -11,15 +11,8 @@ public class CITResewnModMenu implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
if (FabricLoader.getInstance().isModLoaded("cloth-config2"))
- return new ClothConfigOpenImpl().getModConfigScreenFactory();
+ return CITResewnConfigScreenFactory::create;
return parent -> new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("CIT Resewn"), Text.of("CIT Resewn requires Cloth Config to be able to show the config."));
}
-
- private static class ClothConfigOpenImpl implements ModMenuApi {
- @Override
- public ConfigScreenFactory<?> getModConfigScreenFactory() {
- return CITResewnConfigScreenFactory::create;
- }
- }
}