diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwBooleanEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwBooleanEntry.java index 29665a6793..449f7600f6 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwBooleanEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwBooleanEntry.java @@ -1,10 +1,14 @@ package com.simibubi.create.foundation.config.ui.compat.flywheel; +import java.util.function.Consumer; +import java.util.function.Supplier; + import com.simibubi.create.foundation.gui.AllIcons; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; import com.simibubi.create.foundation.gui.element.RenderElement; import com.simibubi.create.foundation.gui.widget.BoxWidget; + import io.github.fabricators_of_create.porting_lib.mixin.accessors.client.accessor.AbstractWidgetAccessor; import net.minecraft.client.gui.GuiGraphics; @@ -13,8 +17,8 @@ public class FlwBooleanEntry extends FlwValueEntry { RenderElement disabled; BoxWidget button; - public FlwBooleanEntry(Boolean option, String key) { - super(option, key); + public FlwBooleanEntry(Supplier getter, Consumer option, String key) { + super(getter, option, key); enabled = AllIcons.I_CONFIRM.asStencil() .withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2, height, width, Theme.p(Theme.Key.BUTTON_SUCCESS))) diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwEnumEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwEnumEntry.java deleted file mode 100644 index 2e3eba2cc1..0000000000 --- a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwEnumEntry.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.simibubi.create.foundation.config.ui.compat.flywheel; - -import com.simibubi.create.foundation.config.ui.ConfigScreen; -import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.Theme; -import com.simibubi.create.foundation.gui.UIRenderHelper; -import com.simibubi.create.foundation.gui.element.BoxElement; -import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; -import com.simibubi.create.foundation.gui.element.TextStencilElement; -import com.simibubi.create.foundation.gui.widget.BoxWidget; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; - -import java.util.Locale; - -public class FlwEnumEntry extends FlwValueEntry> { - - protected static final int cycleWidth = 34; - - protected TextStencilElement valueText; - protected BoxWidget cycleLeft; - protected BoxWidget cycleRight; - - public FlwEnumEntry(Enum option, String key) { - super(option, key); - - valueText = new TextStencilElement(Minecraft.getInstance().font, "YEP").centered(true, true); - valueText.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2, - height, width, Theme.p(Theme.Key.TEXT))); - - DelegatedStencilElement l = AllIcons.I_CONFIG_PREV.asStencil(); - cycleLeft = new BoxWidget(0, 0, cycleWidth + 8, 16) - .withCustomBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) - .showingElement(l) - .withCallback(() -> cycleValue(-1)); - l.withElementRenderer(BoxWidget.gradientFactory.apply(cycleLeft)); - - DelegatedStencilElement r = AllIcons.I_CONFIG_NEXT.asStencil(); - cycleRight = new BoxWidget(0, 0, cycleWidth + 8, 16) - .withCustomBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) - .showingElement(r) - .withCallback(() -> cycleValue(1)); - r.at(cycleWidth - 8, 0); - r.withElementRenderer(BoxWidget.gradientFactory.apply(cycleRight)); - - listeners.add(cycleLeft); - listeners.add(cycleRight); - - onReset(); - } - - protected void cycleValue(int direction) { - Enum e = getValue(); - Enum[] options = e.getDeclaringClass() - .getEnumConstants(); - e = options[Math.floorMod(e.ordinal() + direction, options.length)]; - setValue(e); - bumpCog(direction * 15f); - } - - @Override - public void setEditable(boolean b) { - super.setEditable(b); - cycleLeft.active = b; - cycleLeft.animateGradientFromState(); - cycleRight.active = b; - cycleRight.animateGradientFromState(); - } - - @Override - public void tick() { - super.tick(); - cycleLeft.tick(); - cycleRight.tick(); - } - - @Override - public void render(GuiGraphics graphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, - boolean p_230432_9_, float partialTicks) { - super.render(graphics, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks); - - cycleLeft.setX(x + getLabelWidth(width) + 4); - cycleLeft.setY(y + 10); - cycleLeft.render(graphics, mouseX, mouseY, partialTicks); - - valueText.at(cycleLeft.getX() + cycleWidth - 8, y + 10, 200) - .withBounds(width - getLabelWidth(width) - 2 * cycleWidth - resetWidth - 4, 16) - .render(graphics); - - cycleRight.setX(x + width - cycleWidth * 2 - resetWidth + 10); - cycleRight.setY(y + 10); - cycleRight.render(graphics, mouseX, mouseY, partialTicks); - - new BoxElement() - .withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) - .flatBorder(0x01_000000) - .withBounds(48, 6) - .at(cycleLeft.getX() + 22, cycleLeft.getY() + 5) - .render(graphics); - } - - @Override - public void onValueChange(Enum newValue) { - super.onValueChange(newValue); - valueText.withText(ConfigScreen.toHumanReadable(newValue.name().toLowerCase(Locale.ROOT))); - Minecraft.getInstance().levelRenderer.allChanged(); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java index f9f0905efa..53386246e1 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java @@ -1,6 +1,8 @@ package com.simibubi.create.foundation.config.ui.compat.flywheel; import java.util.Collections; +import java.util.function.Consumer; +import java.util.function.Supplier; import com.electronwill.nightconfig.core.UnmodifiableConfig; import com.simibubi.create.foundation.config.ui.ConfigHelper; @@ -143,23 +145,20 @@ protected void init() { addRenderableWidget(search); addConfigEntry(FabricFlwConfig.INSTANCE.backend, "backend"); - addConfigEntry(FabricFlwConfig.INSTANCE.limitUpdates, "limitUpdates"); + addConfigEntryBoolean(() -> FabricFlwConfig.INSTANCE.limitUpdates, v -> FabricFlwConfig.INSTANCE.limitUpdates = v, "limitUpdates"); addConfigEntry(FabricFlwConfig.INSTANCE.workerThreads, "workerThreads"); addConfigEntry(FabricFlwConfig.INSTANCE.backendConfig, "flw_backend"); - Collections.sort(list.children(), - (e, e2) -> { - int group = (e2 instanceof SubMenuEntry ? 1 : 0) - (e instanceof SubMenuEntry ? 1 : 0); - if (group == 0 && e instanceof ConfigScreenList.LabeledEntry && e2 instanceof ConfigScreenList.LabeledEntry) { - ConfigScreenList.LabeledEntry le = (ConfigScreenList.LabeledEntry) e; - ConfigScreenList.LabeledEntry le2 = (ConfigScreenList.LabeledEntry) e2; - return le.label.getComponent() - .getString() - .compareTo(le2.label.getComponent() - .getString()); - } - return group; - }); + list.children().sort((e, e2) -> { + int group = (e2 instanceof SubMenuEntry ? 1 : 0) - (e instanceof SubMenuEntry ? 1 : 0); + if (group == 0 && e instanceof ConfigScreenList.LabeledEntry le && e2 instanceof ConfigScreenList.LabeledEntry le2) { + return le.label.getComponent() + .getString() + .compareTo(le2.label.getComponent() + .getString()); + } + return group; + }); list.search(highlights.stream().findFirst().orElse("")); @@ -200,17 +199,11 @@ protected void init() { addRenderableWidget(serverLocked); } - private void addConfigEntry(T option, String key) { - ConfigScreenList.Entry entry = null; - if (option instanceof Boolean) { - entry = new FlwBooleanEntry((Boolean) option, key); - } else if (option instanceof Enum) { - entry = new FlwEnumEntry((Enum) option, key); - } - - if (entry == null) - entry = new ConfigScreenList.LabeledEntry("Impl missing - " + option.getClass().getSimpleName() + " " + toHumanReadable(key) + " : " + option); + private void addConfigEntryBoolean(Supplier getter, Consumer option, String key) { + addConfigEntry(new FlwBooleanEntry(getter, option, key), key); + } + private void addConfigEntry(ConfigScreenList.Entry entry, String key) { if (highlights.contains(key)) entry.annotations.put("highlight", ":)"); diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwValueEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwValueEntry.java index c59293f8cd..1cff22df8e 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwValueEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwValueEntry.java @@ -1,5 +1,14 @@ package com.simibubi.create.foundation.config.ui.compat.flywheel; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import org.jetbrains.annotations.NotNull; + import com.google.common.base.Predicates; import com.simibubi.create.foundation.config.ui.ConfigAnnotations; import com.simibubi.create.foundation.config.ui.ConfigHelper; @@ -11,28 +20,24 @@ import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.item.TooltipHelper.Palette; import com.simibubi.create.foundation.utility.Pair; + import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; public class FlwValueEntry extends ValueEntry { + protected Supplier getter; + protected Consumer option; - protected T option; - - public FlwValueEntry(T option, String key) { + public FlwValueEntry(Supplier getter, Consumer option, String key) { super(ConfigScreen.toHumanReadable(key)); + this.getter = getter; this.option = option; this.path = String.join(".", key); resetButton = new BoxWidget(0, 0, resetWidth - 12, 16) .showingElement(AllIcons.I_CONFIG_RESET.asStencil()) .withCallback(() -> { - setValue(option); + setValue(getter.get()); this.onReset(); }); resetButton.modifyElement(e -> ((DelegatedStencilElement) e).withElementRenderer(BoxWidget.gradientFactory.apply(resetButton))); @@ -73,14 +78,14 @@ public FlwValueEntry(T option, String key) { @Override public void setValue(@NotNull T value) { - option = value; + option.accept(value); onValueChange(value); } @NotNull @Override public T getValue() { - return option; + return getter.get(); } @Override