diff --git a/src/main/java/dev/lambdaurora/lambdynlights/config/LightSourceSettingEntry.java b/src/main/java/dev/lambdaurora/lambdynlights/config/LightSourceSettingEntry.java index 72d3da04..50447923 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/config/LightSourceSettingEntry.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/config/LightSourceSettingEntry.java @@ -11,10 +11,8 @@ import com.electronwill.nightconfig.core.Config; import dev.lambdaurora.spruceui.SpruceTexts; -import dev.lambdaurora.spruceui.option.SpruceBooleanOption; import dev.lambdaurora.spruceui.option.SpruceOption; import dev.lambdaurora.spruceui.option.SpruceToggleBooleanOption; -import net.minecraft.TextFormatting; import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; @@ -33,7 +31,7 @@ public LightSourceSettingEntry(String key, boolean defaultValue, @Nullable Confi @Override protected SpruceOption buildOption(@Nullable Text tooltip) { return new Option( - this.getOptionKey(), + this.key(), this::get, this::set, tooltip @@ -42,12 +40,20 @@ protected SpruceOption buildOption(@Nullable Text tooltip) { public static final class Option extends SpruceToggleBooleanOption { public Option(String key, Supplier getter, Consumer setter, @Nullable Text tooltip) { - super(key, getter, setter, tooltip); + super(key, getter, setter, tooltip, false); } @Override public Text getDisplayText() { - return Text.empty(); + boolean value = this.get(); + Text toggleText = SpruceTexts.getToggleText(value); + + return this.getDisplayText(toggleText); + } + + @Override + public Text getDisplayText(Text value) { + return Text.translatable("spruceui.options.generic", this.getPrefix(), value); } } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/gui/LightSourceListWidget.java b/src/main/java/dev/lambdaurora/lambdynlights/gui/LightSourceListWidget.java index e306d8bd..0ed912fe 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/gui/LightSourceListWidget.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/gui/LightSourceListWidget.java @@ -11,6 +11,7 @@ import dev.lambdaurora.lambdynlights.accessor.DynamicLightHandlerHolder; import dev.lambdaurora.spruceui.Position; +import dev.lambdaurora.spruceui.SpruceTexts; import dev.lambdaurora.spruceui.background.Background; import dev.lambdaurora.spruceui.background.EmptyBackground; import dev.lambdaurora.spruceui.background.SimpleColorBackground; @@ -23,6 +24,7 @@ import dev.lambdaurora.spruceui.widget.container.SpruceEntryListWidget; import dev.lambdaurora.spruceui.widget.container.SpruceParentWidget; import dev.lambdaurora.spruceui.widget.text.SpruceTextFieldWidget; +import dev.yumi.commons.TriState; import net.minecraft.TextFormatting; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.narration.NarratedElementType; @@ -54,10 +56,7 @@ public LightSourceListWidget(Position position, int width, int height, SpruceTex } var list = Stream.of(input.split(" ")) - .map(part -> part.startsWith("@") - ? Text.literal(part + " ").withStyle(TextFormatting.AQUA) - : Text.literal(part + " ") - ) + .map(this::stylizeFilterPart) .map(Text::getVisualOrderText) .toList(); return FormattedCharSequence.fromList(list); @@ -81,6 +80,24 @@ private void update(@Nullable String filter) { } } + private TriState evaluateValueFilter(String filter) { + if (filter.isBlank()) { + return TriState.DEFAULT; + } + + if (filter.equalsIgnoreCase(SpruceTexts.OPTIONS_ON.getString())) { + return TriState.TRUE; + } else if (filter.equalsIgnoreCase(SpruceTexts.OPTIONS_OFF.getString())) { + return TriState.FALSE; + } + + return switch (filter) { + case "true", "1", "on" -> TriState.TRUE; + case "false", "0", "off" -> TriState.FALSE; + default -> TriState.DEFAULT; + }; + } + private boolean checkFilter(LightSourceEntry entry, @NotNull List filter) { var name = entry.option.lambdynlights$getName().getString().toLowerCase(); @@ -91,6 +108,16 @@ private boolean checkFilter(LightSourceEntry entry, @NotNull List filter return false; } + continue; + } else if (part.startsWith("$")) { + var valueFilter = this.evaluateValueFilter(part.substring(1)); + + if (valueFilter == TriState.DEFAULT) continue; + + if (entry.option.lambdynlights$getSetting().get() != valueFilter.toBoolean()) { + return false; + } + continue; } @@ -102,6 +129,20 @@ private boolean checkFilter(LightSourceEntry entry, @NotNull List filter return true; } + private Text stylizeFilterPart(String filter) { + if (filter.startsWith("@")) { + return Text.literal(filter + " ").withStyle(TextFormatting.AQUA); + } else if (filter.startsWith("$")) { + var valueFilter = this.evaluateValueFilter(filter.substring(1)); + return Text.literal(filter + " ").withStyle(switch (valueFilter) { + case TriState.TRUE, TriState.FALSE -> TextFormatting.GOLD; + default -> TextFormatting.RED; + }); + } else { + return Text.literal(filter + " "); + } + } + /** * Adds a single option entry. The option will use all the width available. * diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityTypeMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityTypeMixin.java index cd8611f8..3884a792 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityTypeMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityTypeMixin.java @@ -28,6 +28,8 @@ public abstract class EntityTypeMixin implements DynamicLightH @Shadow public abstract Text getDescription(); + @Shadow public abstract String getDescriptionId(); + @Unique private DynamicLightHandler lambdynlights$lightHandler; @Unique @@ -52,9 +54,9 @@ public abstract class EntityTypeMixin implements DynamicLightH return null; } - this.lambdynlights$setting = new LightSourceSettingEntry("light_sources.settings.entities." - + id.namespace() + '.' + id.path().replace('/', '.'), - true, null, null); + this.lambdynlights$setting = new LightSourceSettingEntry(this.getDescriptionId(), + true, null, null + ); LambDynLights.get().config.load(this.lambdynlights$setting); }