Add mod icons, finish GUI support through Cloth Config Lite
This commit is contained in:
@@ -52,6 +52,8 @@ allprojects {
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ loader_version=0.12.11
|
||||
#Fabric api
|
||||
fabric_version=0.44.0+1.18
|
||||
# Mod Properties
|
||||
mod_version=1.1.0
|
||||
mod_version=1.2.0
|
||||
maven_group=draylar
|
||||
archives_base_name=omega-config
|
||||
|
||||
modmenu_version=3.0.0
|
||||
modmenu_version=3.0.1
|
||||
|
||||
@@ -35,7 +35,7 @@ public class OmegaConfig {
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final Identifier CONFIG_SYNC_PACKET = new Identifier("omegaconfig", "sync");
|
||||
public static final Gson SYNC_ONLY_GSON = new GsonBuilder().addSerializationExclusionStrategy(new SyncableExclusionStrategy()).setPrettyPrinting().create();
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
@@ -162,7 +162,7 @@ public class OmegaConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Class<?>> flatten(Class<?>[] array) {
|
||||
public static List<Class<?>> flatten(Class<?>[] array) {
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
|
||||
for (Class<?> clazz : array) {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 225 B |
@@ -1,3 +1,12 @@
|
||||
repositories {
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":omega-config-base")
|
||||
|
||||
include "me.shedaniel.cloth:cloth-config-lite-fabric:2.0.6"
|
||||
modApi ("me.shedaniel.cloth:cloth-config-lite-fabric:2.0.6") {
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,63 @@
|
||||
package draylar.omegaconfiggui;
|
||||
|
||||
import draylar.omegaconfig.OmegaConfig;
|
||||
import draylar.omegaconfig.api.Config;
|
||||
import draylar.omegaconfiggui.api.screen.OmegaScreenFactory;
|
||||
import me.shedaniel.clothconfiglite.api.ConfigScreen;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class OmegaConfigGui {
|
||||
|
||||
/**
|
||||
* Registers a ModMenu configuration screen for the given {@link Config} instance.
|
||||
*
|
||||
* @param config registered config to create a ModMenu screen for
|
||||
* @param <T> config type
|
||||
* Returns a factory which provides new Cloth Config Lite {@link Screen} instances for the given {@link Config}.
|
||||
* @param config Omega Config instance to create the screen factory for
|
||||
* @return a factory which provides new Cloth Config Lite {@link Screen} instances for the given {@link Config}.
|
||||
*/
|
||||
public static <T extends Config> void registerConfigScreen(T config) {
|
||||
if(FabricLoader.getInstance().isModLoaded("modmenu")) {
|
||||
// ModMenuHelper.injectScreen(config, parent -> new OmegaConfigScreen<>(config, parent));
|
||||
public static OmegaScreenFactory<Screen> getConfigScreenFactory(Config config) {
|
||||
return parent -> {
|
||||
try {
|
||||
Config defaultConfig = config.getClass().getDeclaredConstructor().newInstance();
|
||||
ConfigScreen screen = ConfigScreen.create(new LiteralText(config.getName()), parent);
|
||||
|
||||
// Fields
|
||||
for (Field field : config.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
screen.add(new LiteralText(field.getName()), field.get(config), () -> {
|
||||
try {
|
||||
return field.get(defaultConfig);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0.0d;
|
||||
}, newValue -> {
|
||||
try {
|
||||
field.set(config, newValue);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
config.save();
|
||||
});
|
||||
} catch (IllegalAccessException | IllegalArgumentException exception) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
return screen.get();
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||
OmegaConfig.LOGGER.error(String.format("Configuration class for mod %s must have a no-argument constructor for retrieving default values.", config.getModid()));
|
||||
}
|
||||
|
||||
// todo: is this a bad idea
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
-142
@@ -1,142 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import draylar.omegaconfig.api.Config;
|
||||
import draylar.omegaconfiggui.api.screen.widget.LabelWidget;
|
||||
import draylar.omegaconfiggui.api.screen.widget.TypeWidgets;
|
||||
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Pair;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class OmegaConfigScreen<T extends Config> extends Screen {
|
||||
|
||||
private static final List<Class<?>> validClasses = Arrays.asList(Double.class, String.class, Boolean.class);
|
||||
private final T config;
|
||||
private final Screen parent;
|
||||
private final Map<Field, Pair<WidgetSupplier<Object, ClickableWidget>, ClickableWidget>> fieldWidgets = new HashMap<>();
|
||||
|
||||
public OmegaConfigScreen(T config, Screen parent) {
|
||||
super(new LiteralText(""));
|
||||
this.config = config;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
try {
|
||||
// add label & button for each config entry
|
||||
// TODO: SUB-CLASS SUPPORT
|
||||
List<Field> collect = Arrays.stream(config.getClass().getDeclaredFields()).filter(field -> validClasses.contains(TypeWidgets.unbox(field.getType()))).collect(Collectors.toList());
|
||||
int over = 0;
|
||||
|
||||
for (Field field : collect) {
|
||||
Class<?> unbox = TypeWidgets.unbox(field.getType());
|
||||
|
||||
// label
|
||||
addDrawable(new LabelWidget(150, 15 + height / 6 + 20 * over, new LiteralText(field.getName())));
|
||||
|
||||
// get value
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(config);
|
||||
|
||||
// button / interact
|
||||
ClickableWidget button;
|
||||
WidgetSupplier<Object, ClickableWidget> widgetSupplier = (WidgetSupplier<Object, ClickableWidget>) TypeWidgets.get(unbox);
|
||||
if (widgetSupplier != null) {
|
||||
button = widgetSupplier.create(this, 250, 5 + height / 6 + 25 * over, 100, 20, new LiteralText(field.getName()), value);
|
||||
} else {
|
||||
button = new TextFieldWidget(client.textRenderer, 250, 5 + height / 6 + 25 * over, 100, 20, new LiteralText(field.getName()));
|
||||
}
|
||||
|
||||
fieldWidgets.put(field, new Pair<>(widgetSupplier, button));
|
||||
|
||||
addSelectableChild(button);
|
||||
|
||||
over++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// save and exit
|
||||
ButtonWidget exit = new ButtonWidget(width - 60, height - 30, 50, 20, new LiteralText("Exit"), widget -> onClose());
|
||||
ButtonWidget save = new ButtonWidget(10, height - 30, 50, 20, new LiteralText("Save"), widget -> {
|
||||
fieldWidgets.forEach((field, pair) -> {
|
||||
try {
|
||||
field.set(config, pair.getLeft().get(pair.getRight()));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
config.save();
|
||||
});
|
||||
addSelectableChild(save);
|
||||
addSelectableChild(exit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
renderBackground(matrices);
|
||||
|
||||
//TODO make this work. for Drawables (children) it works in parent method
|
||||
/*
|
||||
for (ClickableWidget button : this.) {
|
||||
button.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
for (Element element : this.children) {
|
||||
if (element instanceof Drawable && !buttons.contains(element)) {
|
||||
((Drawable) element).render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
client.setScreen(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(MatrixStack matrices) {
|
||||
// TODO: option for transparent BG
|
||||
// this.fillGradient(matrices, 0, 0, this.width, this.height, -1072689136, -804253680);
|
||||
renderCustomBackgroundTexture(0, 64, 64, 64, 0, 0, this.height, this.width);
|
||||
renderCustomBackgroundTexture(0, 32, 32, 32, 0, this.height / 8, this.height / 8 * 6, this.width);
|
||||
textRenderer.draw(matrices, config.getName(), width / 2f - textRenderer.getWidth(config.getName()) / 2f, 10, 0xffffff);
|
||||
}
|
||||
|
||||
public void renderCustomBackgroundTexture(int vOffset, int r, int g, int b, int x, int y, int height, int width) {
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||
this.client.getTextureManager().bindTexture(OPTIONS_BACKGROUND_TEXTURE);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
|
||||
bufferBuilder.vertex(x, height + y, 0.0D).texture(0.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
|
||||
bufferBuilder.vertex(width + x, height + y, 0.0D).texture((float) width / 32.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
|
||||
bufferBuilder.vertex(width + x, y, 0.0D).texture((float) width / 32.0F, (float) vOffset).color(r, g, b, 255).next();
|
||||
bufferBuilder.vertex(x, y, 0.0D).texture(0.0F, (float) vOffset).color(r, g, b, 255).next();
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen;
|
||||
|
||||
import draylar.omegaconfig.api.Config;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public interface OmegaConfigScreenSupplier<T extends Config> {
|
||||
OmegaConfigScreen<T> get(Screen parent);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package draylar.omegaconfiggui.api.screen;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import draylar.omegaconfig.api.Config;
|
||||
import draylar.omegaconfiggui.OmegaConfigGui;
|
||||
import draylar.omegaconfiggui.mixin.modmenu.ModMenuAccessor;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class OmegaModMenu {
|
||||
|
||||
private static final Map<Config, ConfigScreenFactory<Screen>> REGISTERED_CONFIGURATIONS = new HashMap<>();
|
||||
public static boolean modMenuInitialized = false;
|
||||
|
||||
/**
|
||||
* Registers a ModMenu configuration screen for the given {@link Config} instance.
|
||||
*
|
||||
* @param config registered config to create a ModMenu screen for
|
||||
* @param <T> config type
|
||||
*/
|
||||
public static <T extends Config> void registerConfigScreen(T config) {
|
||||
if(FabricLoader.getInstance().isModLoaded("modmenu")) {
|
||||
OmegaScreenFactory<Screen> factory = OmegaConfigGui.getConfigScreenFactory(config);
|
||||
|
||||
if(modMenuInitialized) {
|
||||
OmegaModMenu.injectScreen(config, factory::get);
|
||||
} else {
|
||||
addConfiguration(config, factory::get);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Config> void injectScreen(T config, ConfigScreenFactory<Screen> factory) {
|
||||
// they will suspect nothing
|
||||
ModMenuAccessor.setConfigScreenFactories(
|
||||
new ImmutableMap.Builder<String, ConfigScreenFactory<?>>()
|
||||
.putAll(ModMenuAccessor.getConfigScreenFactories())
|
||||
.put(config.getModid(), factory)
|
||||
.build());
|
||||
}
|
||||
|
||||
public static Map<Config, ConfigScreenFactory<Screen>> getRegisteredConfigurations() {
|
||||
return REGISTERED_CONFIGURATIONS;
|
||||
}
|
||||
|
||||
public static void addConfiguration(Config config, ConfigScreenFactory<Screen> screen) {
|
||||
REGISTERED_CONFIGURATIONS.put(config, screen);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -2,9 +2,9 @@ package draylar.omegaconfiggui.api.screen;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModMenuHelper {
|
||||
|
||||
|
||||
public interface OmegaScreenFactory<T extends Screen> {
|
||||
T get(Screen parent);
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget;
|
||||
|
||||
import draylar.omegaconfiggui.mixin.ClickableWidgetInvoker;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class BaseTextFieldWidget extends TextFieldWidget {
|
||||
|
||||
protected final Screen parent;
|
||||
|
||||
public BaseTextFieldWidget(Screen parent, TextRenderer textRenderer, int x, int y, int width, int height, Text text) {
|
||||
super(textRenderer, x, y, width, height, text);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextFieldFocused(boolean focused) {
|
||||
// unfocus all others
|
||||
parent.children().forEach(element -> {
|
||||
if (element instanceof ClickableWidget) {
|
||||
((ClickableWidgetInvoker) element).callSetFocused(false);
|
||||
}
|
||||
});
|
||||
|
||||
super.setFocused(focused);
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class DoubleFieldWidget extends BaseTextFieldWidget {
|
||||
|
||||
public DoubleFieldWidget(Screen parent, TextRenderer textRenderer, int x, int y, int width, int height, Text text) {
|
||||
super(parent, textRenderer, x, y, width, height, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(String string) {
|
||||
try {
|
||||
if (!string.equals(".") || getText().contains(".")) {
|
||||
Double.parseDouble(string);
|
||||
}
|
||||
super.write(string);
|
||||
|
||||
} catch (NumberFormatException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class LabelWidget extends DrawableHelper implements Drawable, Element {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final Text message;
|
||||
|
||||
public LabelWidget(int x, int y, Text message) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
drawTextWithShadow(matrices, MinecraftClient.getInstance().textRenderer, message, x, y, 0xffffff);
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget;
|
||||
|
||||
import draylar.omegaconfiggui.api.screen.widget.supplier.BooleanWidgetSupplier;
|
||||
import draylar.omegaconfiggui.api.screen.widget.supplier.DoubleWidgetSupplier;
|
||||
import draylar.omegaconfiggui.api.screen.widget.supplier.StringWidgetSupplier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TypeWidgets {
|
||||
|
||||
public static final Map<Class<?>, WidgetSupplier<?, ?>> CLASS_WIDGETS = new HashMap<>();
|
||||
public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_BOXED = new HashMap<>();
|
||||
|
||||
static {
|
||||
CLASS_WIDGETS.put(Double.class, new DoubleWidgetSupplier());
|
||||
CLASS_WIDGETS.put(Boolean.class, new BooleanWidgetSupplier());
|
||||
CLASS_WIDGETS.put(String.class, new StringWidgetSupplier());
|
||||
|
||||
// primitive -> boxed
|
||||
PRIMITIVE_TO_BOXED.put(boolean.class, Boolean.class);
|
||||
PRIMITIVE_TO_BOXED.put(byte.class, Byte.class);
|
||||
PRIMITIVE_TO_BOXED.put(char.class, Character.class);
|
||||
PRIMITIVE_TO_BOXED.put(double.class, Double.class);
|
||||
PRIMITIVE_TO_BOXED.put(float.class, Float.class);
|
||||
PRIMITIVE_TO_BOXED.put(int.class, Integer.class);
|
||||
PRIMITIVE_TO_BOXED.put(long.class, Long.class);
|
||||
PRIMITIVE_TO_BOXED.put(short.class, Short.class);
|
||||
PRIMITIVE_TO_BOXED.put(void.class, Void.class);
|
||||
}
|
||||
|
||||
private TypeWidgets() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> WidgetSupplier<T, ?> get(Class<T> typeClass) {
|
||||
return (WidgetSupplier<T, ?>) CLASS_WIDGETS.get(unbox(typeClass));
|
||||
}
|
||||
|
||||
public static Class<?> unbox(Class<?> c) {
|
||||
return PRIMITIVE_TO_BOXED.getOrDefault(c, c);
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
public interface WidgetSupplier<T, A extends ClickableWidget> {
|
||||
ClickableWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, T value);
|
||||
|
||||
T get(A widget);
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget.supplier;
|
||||
|
||||
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.CheckboxWidget;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
public class BooleanWidgetSupplier implements WidgetSupplier<Boolean, CheckboxWidget> {
|
||||
|
||||
@Override
|
||||
public CheckboxWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, Boolean value) {
|
||||
return new CheckboxWidget(x, y, 20, 20, new LiteralText(""), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean get(CheckboxWidget widget) {
|
||||
return widget.isChecked();
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget.supplier;
|
||||
|
||||
import draylar.omegaconfiggui.api.screen.widget.DoubleFieldWidget;
|
||||
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
public class DoubleWidgetSupplier implements WidgetSupplier<Double, DoubleFieldWidget> {
|
||||
|
||||
@Override
|
||||
public DoubleFieldWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, Double value) {
|
||||
LiteralText text = new LiteralText(String.valueOf(value));
|
||||
DoubleFieldWidget widget = new DoubleFieldWidget(parent, MinecraftClient.getInstance().textRenderer, x, y, width, height, text);
|
||||
widget.setText(text.asString());
|
||||
return widget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double get(DoubleFieldWidget widget) {
|
||||
String message = widget.getText();
|
||||
|
||||
// if it is just a . or empty, return 0
|
||||
if (message.equals(".") || message.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// trim potential trailing .
|
||||
if (message.indexOf(".") == message.length()) {
|
||||
message = message.substring(0, message.length() - 1);
|
||||
}
|
||||
|
||||
return Double.parseDouble(message);
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget.supplier;
|
||||
|
||||
import draylar.omegaconfiggui.api.screen.widget.BaseTextFieldWidget;
|
||||
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
public class StringWidgetSupplier implements WidgetSupplier<String, TextFieldWidget> {
|
||||
|
||||
@Override
|
||||
public TextFieldWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, String value) {
|
||||
LiteralText text = new LiteralText(value);
|
||||
TextFieldWidget textField = new BaseTextFieldWidget(parent, MinecraftClient.getInstance().textRenderer, x, y, width, height, text);
|
||||
textField.setText(value);
|
||||
return textField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(TextFieldWidget widget) {
|
||||
return widget.getText();
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package draylar.omegaconfiggui.mixin;
|
||||
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(ClickableWidget.class)
|
||||
public interface ClickableWidgetInvoker {
|
||||
@Invoker
|
||||
void callSetFocused(boolean focused);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package draylar.omegaconfiggui.mixin;
|
||||
|
||||
import com.terraformersmc.modmenu.ModMenu;
|
||||
import draylar.omegaconfiggui.api.screen.OmegaModMenu;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Mixin(ModMenu.class)
|
||||
public class ModMenuMixin {
|
||||
|
||||
@Inject(method = "onInitializeClient", at = @At("RETURN"), remap = false)
|
||||
private void addOmegaConfigurationScreens(CallbackInfo ci) {
|
||||
OmegaModMenu.modMenuInitialized = true;
|
||||
|
||||
// Add loaded configuration screens to mod menu.
|
||||
OmegaModMenu.getRegisteredConfigurations().forEach(OmegaModMenu::injectScreen);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package draylar.omegaconfiggui.mixin;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class OmegaConfigMixinPlugin implements IMixinConfigPlugin {
|
||||
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if(targetClassName.contains("ModMenu")) {
|
||||
return FabricLoader.getInstance().isModLoaded("modmenu");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package draylar.omegaconfiggui.mixin.modmenu;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.terraformersmc.modmenu.ModMenu;
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Mixin(ModMenu.class)
|
||||
public interface ModMenuAccessor {
|
||||
|
||||
@Accessor
|
||||
static ImmutableMap<String, ConfigScreenFactory<?>> getConfigScreenFactories() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Accessor
|
||||
static void setConfigScreenFactories(ImmutableMap<String, ConfigScreenFactory<?>> factories) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 225 B |
@@ -2,7 +2,7 @@
|
||||
"schemaVersion": 1,
|
||||
"id": "omega-config-gui",
|
||||
"version": "${version}",
|
||||
"name": "OmegaConfigGui",
|
||||
"name": "Omega Config GUI",
|
||||
"description": "GUI support for Omega Config.",
|
||||
"authors": [
|
||||
"Draylar"
|
||||
@@ -21,6 +21,9 @@
|
||||
"fabricloader": "*",
|
||||
"fabric": "*",
|
||||
"minecraft": "*"
|
||||
},
|
||||
"recommends": {
|
||||
"modmenu": "3.0.1"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "draylar.omegaconfiggui.mixin",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins": [
|
||||
"ClickableWidgetInvoker"
|
||||
],
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"plugin": "draylar.omegaconfiggui.mixin.OmegaConfigMixinPlugin",
|
||||
"client": [
|
||||
"modmenu.ModMenuAccessor",
|
||||
"ModMenuMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package draylar.omegatest;
|
||||
|
||||
import draylar.omegaconfiggui.OmegaConfigGui;
|
||||
import draylar.omegaconfiggui.api.screen.OmegaModMenu;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@@ -10,7 +10,7 @@ public class OmegaTestClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
OmegaConfigGui.registerConfigScreen(OmegaTestMain.CONFIG);
|
||||
OmegaModMenu.registerConfigScreen(OmegaTestMain.CONFIG);
|
||||
|
||||
HudRenderCallback.EVENT.register((stack, delta) -> {
|
||||
MinecraftClient.getInstance().textRenderer.draw(stack, new LiteralText(String.valueOf(OmegaTestMain.CONFIG.v)), 15, 15, 0xffffff);
|
||||
|
||||
Reference in New Issue
Block a user