Skip to content

Commit

Permalink
Merge Fixes V
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 22, 2024
1 parent 5691a35 commit 5448055
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,8 +17,8 @@ public class FlwBooleanEntry extends FlwValueEntry<Boolean> {
RenderElement disabled;
BoxWidget button;

public FlwBooleanEntry(Boolean option, String key) {
super(option, key);
public FlwBooleanEntry(Supplier<Boolean> getter, Consumer<Boolean> 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)))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(""));

Expand Down Expand Up @@ -200,17 +199,11 @@ protected void init() {
addRenderableWidget(serverLocked);
}

private <T> 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<Boolean> getter, Consumer<Boolean> 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", ":)");

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T> extends ValueEntry<T> {
protected Supplier<T> getter;
protected Consumer<T> option;

protected T option;

public FlwValueEntry(T option, String key) {
public FlwValueEntry(Supplier<T> getter, Consumer<T> 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)));
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5448055

Please sign in to comment.