aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-11-04 17:28:27 +0800
committershedaniel <daniel@shedaniel.me>2024-04-16 00:38:18 +0900
commitcc008ae5a925226f1bf913f8493e40c2600350aa (patch)
tree636e1eecd14e4f7beb19b4fffddd8f0af8601f90
parent5df24222706448060baaa77c19c0ed71d8a15961 (diff)
downloadRoughlyEnoughItems-cc008ae5a925226f1bf913f8493e40c2600350aa.tar.gz
RoughlyEnoughItems-cc008ae5a925226f1bf913f8493e40c2600350aa.tar.bz2
RoughlyEnoughItems-cc008ae5a925226f1bf913f8493e40c2600350aa.zip
Add saving functionality and finalising the config ui
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java14
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java49
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java12
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java7
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java2
7 files changed, 62 insertions, 28 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java
index 7f3b34f78..61f94a829 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java
@@ -37,7 +37,6 @@ import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonPrimitiv
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.api.DeserializationException;
import me.shedaniel.clothconfig2.api.Modifier;
import me.shedaniel.clothconfig2.api.ModifierKeyCode;
-import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.config.ConfigManager;
import me.shedaniel.rei.api.client.config.addon.ConfigAddonRegistry;
import me.shedaniel.rei.api.client.config.entry.EntryStackProvider;
@@ -46,15 +45,11 @@ import me.shedaniel.rei.api.client.entry.filtering.FilteringRuleType;
import me.shedaniel.rei.api.client.entry.filtering.FilteringRuleTypeRegistry;
import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
import me.shedaniel.rei.api.client.gui.config.CheatingMode;
-import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
-import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.config.addon.ConfigAddonRegistryImpl;
import me.shedaniel.rei.impl.client.config.collapsible.CollapsibleConfigManager;
import me.shedaniel.rei.impl.client.config.entries.ConfigAddonsEntry;
-import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen;
import me.shedaniel.rei.impl.common.InternalLogger;
import net.fabricmc.api.EnvType;
@@ -298,14 +293,7 @@ public class ConfigManagerImpl implements ConfigManager {
if (!addonRegistry.getAddons().isEmpty()) {
builder.getOrCreateCategory(Component.translatable("config.roughlyenoughitems.basics")).getEntries().add(0, new ConfigAddonsEntry(220));
}
- return builder.setSavingRunnable(() -> {
- saveConfig();
- EntryRegistry.getInstance().refilter();
- REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
- if (REIRuntimeImpl.getSearchField() != null) {
- ScreenOverlayImpl.getEntryListWidget().updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
- }
- }).build();
+ return null;
});
return provider.get();
} catch (Exception e) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java
index 3e24218f4..3ff6caf20 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java
@@ -34,27 +34,34 @@ import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
+import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
+import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.util.CollectionUtils;
+import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
import me.shedaniel.rei.impl.client.config.ConfigObjectImpl;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.config.components.ConfigCategoriesListWidget;
import me.shedaniel.rei.impl.client.gui.config.components.ConfigEntriesListWidget;
-import me.shedaniel.rei.impl.client.gui.config.options.*;
-import me.shedaniel.rei.impl.client.gui.credits.CreditsScreen;
+import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigCategories;
+import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
+import me.shedaniel.rei.impl.client.gui.config.options.OptionCategory;
+import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup;
import me.shedaniel.rei.impl.client.gui.modules.Menu;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.commons.lang3.mutable.MutableObject;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.BiConsumer;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
@@ -120,15 +127,15 @@ public class REIConfigScreen extends Screen implements ConfigAccess {
super.init();
this.widgets.clear();
this.widgets.add(Widgets.createLabel(new Point(width / 2, 12), this.title));
- int sideWidth = (int) (width / 4.2);
+ int sideWidth = (int) Math.round(width / 4.2);
boolean singlePane = width - 20 - sideWidth <= 330;
int singleSideWidth = 32 + 6 + 4;
- Widget[] list = {ConfigEntriesListWidget.create(this, new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups())};
+ Mutable<Widget> list = new MutableObject<>(createEntriesList(singlePane, singleSideWidth, sideWidth));
IntValue selectedCategory = new IntValue() {
@Override
- public void accept(int i) {
- REIConfigScreen.this.activeCategory = categories.get(i);
- list[0] = ConfigEntriesListWidget.create(REIConfigScreen.this, new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups());
+ public void accept(int index) {
+ REIConfigScreen.this.activeCategory = categories.get(index);
+ list.setValue(createEntriesList(singlePane, singleSideWidth, sideWidth));
}
@Override
@@ -141,7 +148,31 @@ public class REIConfigScreen extends Screen implements ConfigAccess {
} else {
this.widgets.add(ConfigCategoriesListWidget.createTiny(new Rectangle(8, 32, singleSideWidth - 4, height - 32 - 32), categories, selectedCategory));
}
- this.widgets.add(Widgets.delegate(() -> list[0]));
+ this.widgets.add(Widgets.delegate(list::getValue));
+ this.widgets.add(Widgets.createButton(new Rectangle(width / 2 - 150 - 10, height - 26, 150, 20), translatable("gui.cancel")).onClick(button -> {
+ Minecraft.getInstance().setScreen(this.parent);
+ }));
+ this.widgets.add(Widgets.createButton(new Rectangle(width / 2 + 10, height - 26, 150, 20), translatable("gui.done")).onClick(button -> {
+ for (OptionCategory optionCategory : this.categories) {
+ for (OptionGroup group : optionCategory.getGroups()) {
+ for (CompositeOption<?> option : group.getOptions()) {
+ ((BiConsumer<ConfigObjectImpl, Object>) option.getSave()).accept(ConfigManagerImpl.getInstance().getConfig(), this.get(option));
+ }
+ }
+ }
+
+ ConfigManagerImpl.getInstance().saveConfig();
+ EntryRegistry.getInstance().refilter();
+ REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
+ if (REIRuntimeImpl.getSearchField() != null) {
+ ScreenOverlayImpl.getEntryListWidget().updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
+ }
+ Minecraft.getInstance().setScreen(this.parent);
+ }));
+ }
+
+ private Widget createEntriesList(boolean singlePane, int singleSideWidth, int sideWidth) {
+ return ConfigEntriesListWidget.create(this, new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups());
}
public Map<CompositeOption<?>, ?> getDefaultOptions() {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java
index 9f65e2333..fb23b5956 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java
@@ -87,7 +87,7 @@ public interface AllREIConfigCategories {
FILTERING,
LIST,
DEBUG,
- FLAGS,
+ // FLAGS,
RESET
);
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
index a68311686..0cc924884 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java
@@ -103,7 +103,8 @@ public interface AllREIConfigOptions {
.enumOptions();
CompositeOption<ItemCheatingMode> CHEATS_AMOUNT = make("cheats.amount", i -> i.functionality.itemCheatingMode, (i, v) -> i.functionality.itemCheatingMode = v)
.enumOptions();
- CompositeOption<String> GIVE_COMMAND = make("cheats.give_command", i -> i.advanced.commands.giveCommand, (i, v) -> i.advanced.commands.giveCommand = v);
+ CompositeOption<String> GIVE_COMMAND = make("cheats.give_command", i -> i.advanced.commands.giveCommand, (i, v) -> i.advanced.commands.giveCommand = v)
+ .string();
CompositeOption<SearchFieldLocation> SEARCH_FIELD_LOCATION = make("layout.search_field_location", i -> i.appearance.layout.searchFieldLocation, (i, v) -> i.appearance.layout.searchFieldLocation = v)
.entry(OptionValueEntry.<SearchFieldLocation>enumOptions().overrideText(location -> {
if (Minecraft.getInstance().screen instanceof REIConfigScreen configScreen) {
@@ -156,9 +157,12 @@ public interface AllREIConfigOptions {
.enabledDisabled();
CompositeOption<FavoriteAddWidgetMode> NEW_FAVORITES_BUTTON_VISIBILITY = make("favorites.new_favorites_button_visibility", i -> i.advanced.layout.favoriteAddWidgetMode, (i, v) -> i.advanced.layout.favoriteAddWidgetMode = v)
.enumOptions();
- CompositeOption<String> GAME_MODE_COMMAND = make("favorites.game_mode_command", i -> i.advanced.commands.gamemodeCommand, (i, v) -> i.advanced.commands.gamemodeCommand = v);
- CompositeOption<String> TIME_COMMAND = make("favorites.time_command", i -> i.advanced.commands.timeCommand, (i, v) -> i.advanced.commands.timeCommand = v);
- CompositeOption<String> WEATHER_COMMAND = make("favorites.weather_command", i -> i.advanced.commands.weatherCommand, (i, v) -> i.advanced.commands.weatherCommand = v);
+ CompositeOption<String> GAME_MODE_COMMAND = make("favorites.game_mode_command", i -> i.advanced.commands.gamemodeCommand, (i, v) -> i.advanced.commands.gamemodeCommand = v)
+ .string();
+ CompositeOption<String> TIME_COMMAND = make("favorites.time_command", i -> i.advanced.commands.timeCommand, (i, v) -> i.advanced.commands.timeCommand = v)
+ .string();
+ CompositeOption<String> WEATHER_COMMAND = make("favorites.weather_command", i -> i.advanced.commands.weatherCommand, (i, v) -> i.advanced.commands.weatherCommand = v)
+ .string();
CompositeOption<Boolean> BATCHED_RENDERING = make("performance.batched_rendering", i -> i.advanced.miscellaneous.newFastEntryRendering, (i, v) -> i.advanced.miscellaneous.newFastEntryRendering = v)
.enabledDisabled();
CompositeOption<Boolean> CACHED_RENDERING = make("performance.cached_rendering", i -> i.advanced.miscellaneous.cachingFastEntryRendering, (i, v) -> i.advanced.miscellaneous.cachingFastEntryRendering = v)
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java
index 0057cadb0..fed950b48 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/CompositeOption.java
@@ -72,6 +72,10 @@ public class CompositeOption<T> {
return ((CompositeOption<ModifierKeyCode>) this).entry(OptionValueEntry.keybind());
}
+ public CompositeOption<String> string() {
+ return ((CompositeOption<String>) this).entry(OptionValueEntry.string());
+ }
+
public CompositeOption<T> enumOptions(T... entry) {
return this.entry(OptionValueEntry.enumOptions(entry));
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java
index 7102d6adc..d1ef77787 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java
@@ -142,6 +142,10 @@ public interface OptionValueEntry<T> {
return ModifierKeyCode::getLocalizedName;
}
+ static OptionValueEntry.String string() {
+ return ConfigUtils::literal;
+ }
+
interface Configurator<T> {
void configure(ConfigAccess access, CompositeOption<T> option, Runnable onClose);
}
@@ -166,4 +170,7 @@ public interface OptionValueEntry<T> {
};
}
}
+
+ interface String extends OptionValueEntry<java.lang.String> {
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java
index be3dccb55..eedba9509 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java
@@ -137,7 +137,7 @@ public abstract class EntryListWidget extends WidgetWithBounds implements Overla
int heightReduction = (int) Math.round(bounds.height * (1 - ConfigObject.getInstance().getVerticalEntriesBoundariesPercentage()));
bounds.y += (int) Math.round(heightReduction * ConfigObject.getInstance().getVerticalEntriesBoundariesAlignments());
bounds.height -= heightReduction;
- int maxHeight = (int) Math.ceil(entrySize() * ConfigObject.getInstance().getVerticalEntriesBoundariesAlignments() + entrySize() * 0.75);
+ int maxHeight = (int) Math.ceil(entrySize() * ConfigObject.getInstance().getVerticalEntriesBoundariesRows() + entrySize() * 0.75);
if (bounds.height > maxHeight) {
bounds.y += (int) Math.round((bounds.height - maxHeight) * ConfigObject.getInstance().getVerticalEntriesBoundariesAlignments());
bounds.height = maxHeight;