diff --git a/src/main/java/com/plusls/MasaGadget/config/Configs.java b/src/main/java/com/plusls/MasaGadget/config/Configs.java index ca950dbf..53029c06 100644 --- a/src/main/java/com/plusls/MasaGadget/config/Configs.java +++ b/src/main/java/com/plusls/MasaGadget/config/Configs.java @@ -48,10 +48,11 @@ public static void loadFromFile() { ConfigUtils.readConfigBase(root, "malilib", Malilib.OPTIONS); try { JsonObject obj = Objects.requireNonNull(JsonUtils.getNestedObject(root, "malilib", true)); - JsonObject favoriteObj = Objects.requireNonNull(JsonUtils.getNestedObject(obj, "favorite", true)); + JsonObject favoriteObj = Objects.requireNonNull(JsonUtils.getNestedObject(obj, "favorites", true)); for (Map.Entry favoriteEntry : favoriteObj.entrySet()) { Malilib.FAVORITES.put(favoriteEntry.getKey(), favoriteEntry.getValue().getAsBoolean()); } + Malilib.favoritesFilter = JsonUtils.getBooleanOrDefault(obj, "favoritesFilter", false); } catch (ClassCastException | IllegalStateException ignored) { } @@ -81,7 +82,8 @@ public static void saveToFile() { favoriteObj.add(favoriteEntry.getKey(), new JsonPrimitive(true)); } } - obj.add("favorite", favoriteObj); + obj.add("favorites", favoriteObj); + obj.add("favoritesFilter", new JsonPrimitive(Malilib.favoritesFilter)); ConfigUtils.writeConfigBase(root, "minihud", Minihud.OPTIONS); ConfigUtils.writeConfigBase(root, "tweakeroo", Tweakeroo.OPTIONS); root.add("configVersion", new JsonPrimitive(CONFIG_VERSION)); @@ -187,7 +189,7 @@ public static class Malilib { SHOW_ORIGINAL_CONFIG_NAME ); public static final List GUI_OPTIONS = new LinkedList<>(OPTIONS); - public static boolean favorites; + public static boolean favoritesFilter; static { GUI_OPTIONS.removeIf(iConfigBase -> iConfigBase == FAST_SWITCH_MASA_CONFIG_GUI && !ModInfo.isModLoaded(ModInfo.MODMENU_MOD_ID)); diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java index 0885a393..909eade3 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java @@ -1,7 +1,6 @@ package com.plusls.MasaGadget.mixin.malilib.favorites; import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.gui.GuiConfigs; import com.plusls.MasaGadget.gui.MasaGadgetIcons; import com.plusls.MasaGadget.gui.WidgetIconToggleButton; import fi.dy.masa.malilib.gui.GuiConfigsBase; @@ -21,14 +20,16 @@ @Mixin(value = GuiConfigsBase.class, remap = false) public abstract class MixinGuiConfigBase extends GuiListBase implements IKeybindConfigGui { private final WidgetIconToggleButton favoritesButton = new WidgetIconToggleButton(GuiUtils.getScaledWindowWidth() - 175, 13, - MasaGadgetIcons.FAVORITE, Configs.Malilib.favorites, + MasaGadgetIcons.FAVORITE, Configs.Malilib.favoritesFilter, status -> { - Configs.Malilib.favorites = status; + Configs.Malilib.favoritesFilter = status; WidgetListConfigOptions widgetListConfigOptions = this.getListWidget(); if (widgetListConfigOptions != null) { widgetListConfigOptions.getScrollbar().setValue(0); widgetListConfigOptions.refreshEntries(); } + Configs.saveToFile(); + Configs.loadFromFile(); }, status -> status ? I18n.translate("masa_gadget_mod.message.showAllOptions") : I18n.translate("masa_gadget_mod.message.showFavorite"), widgetIconToggleButton -> Configs.Malilib.FAVORITES_SUPPORT.getBooleanValue()); @@ -43,7 +44,7 @@ public void postInitGui(CallbackInfo ci) { } @Dynamic - @Inject(method = "resize", at = @At(value = "HEAD")) + @Inject(method = "resize", at = @At(value = "RETURN")) public void favoritesResize(MinecraftClient mc, int width, int height, CallbackInfo callbackInfo) { favoritesButton.setX(GuiUtils.getScaledWindowWidth() - 175); } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetListConfigOptions.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetListConfigOptions.java index b7a3fe06..c379fb43 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetListConfigOptions.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetListConfigOptions.java @@ -24,7 +24,7 @@ public MixinWidgetListConfigOptions(int x, int y, int width, int height, int con @Inject(method = "getEntryStringsForFilter*", at = @At(value = "HEAD"), cancellable = true) private void filterFavorites(GuiConfigsBase.ConfigOptionWrapper entry, CallbackInfoReturnable> cir) { - if (Configs.Malilib.FAVORITES_SUPPORT.getBooleanValue() && Configs.Malilib.favorites) { + if (Configs.Malilib.FAVORITES_SUPPORT.getBooleanValue() && Configs.Malilib.favoritesFilter) { IConfigBase config = entry.getConfig(); if (config == null || !Configs.Malilib.FAVORITES.getOrDefault(config.getName(), false)) { cir.setReturnValue(ImmutableList.of("")); @@ -34,7 +34,7 @@ private void filterFavorites(GuiConfigsBase.ConfigOptionWrapper entry, CallbackI @Override protected void addNonFilteredContents(Collection placements) { - if (Configs.Malilib.FAVORITES_SUPPORT.getBooleanValue() && Configs.Malilib.favorites) { + if (Configs.Malilib.FAVORITES_SUPPORT.getBooleanValue() && Configs.Malilib.favoritesFilter) { for (GuiConfigsBase.ConfigOptionWrapper configWrapper : placements) { IConfigBase config = configWrapper.getConfig(); if (config != null && Configs.Malilib.FAVORITES.getOrDefault(config.getName(), false)) {