Port to java 16 and MC 1.17
This commit is contained in:
@@ -12,11 +12,12 @@ 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
|
||||
*
|
||||
* @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")) {
|
||||
if (FabricLoader.getInstance().isModLoaded("modmenu")) {
|
||||
ModMenuHelper.injectScreen(config, parent -> new OmegaConfigScreen<>(config, parent));
|
||||
}
|
||||
}
|
||||
|
||||
+22
-21
@@ -5,19 +5,16 @@ 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.MinecraftClient;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
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.Identifier;
|
||||
import net.minecraft.util.Pair;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -32,7 +29,7 @@ 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, AbstractButtonWidget>, AbstractButtonWidget>> fieldWidgets = new HashMap<>();
|
||||
private final Map<Field, Pair<WidgetSupplier<Object, ClickableWidget>, ClickableWidget>> fieldWidgets = new HashMap<>();
|
||||
|
||||
public OmegaConfigScreen(T config, Screen parent) {
|
||||
super(new LiteralText(""));
|
||||
@@ -54,24 +51,24 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
||||
Class<?> unbox = TypeWidgets.unbox(field.getType());
|
||||
|
||||
// label
|
||||
addChild(new LabelWidget(150, 15 + height / 6 + 20 * over, new LiteralText(field.getName())));
|
||||
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
|
||||
AbstractButtonWidget button;
|
||||
WidgetSupplier<Object, AbstractButtonWidget> widgetSupplier = (WidgetSupplier<Object, AbstractButtonWidget>) TypeWidgets.get(unbox);
|
||||
if(widgetSupplier != null) {
|
||||
button = widgetSupplier.create(this,250, 5 + height / 6 + 25 * over, 100, 20, new LiteralText(field.getName()), value);
|
||||
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));
|
||||
|
||||
addButton(button);
|
||||
addSelectableChild(button);
|
||||
|
||||
over++;
|
||||
}
|
||||
@@ -92,15 +89,17 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
||||
|
||||
config.save();
|
||||
});
|
||||
addButton(save);
|
||||
addButton(exit);
|
||||
addSelectableChild(save);
|
||||
addSelectableChild(exit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
renderBackground(matrices);
|
||||
|
||||
for (AbstractButtonWidget button : this.buttons) {
|
||||
//TODO make this work. for Drawables (children) it works in parent method
|
||||
/*
|
||||
for (ClickableWidget button : this.) {
|
||||
button.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
@@ -109,6 +108,8 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
||||
((Drawable) element).render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,13 +130,13 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||
this.client.getTextureManager().bindTexture(OPTIONS_BACKGROUND_TEXTURE);
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
bufferBuilder.begin(7, 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();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget;
|
||||
|
||||
import draylar.omegaconfiggui.mixin.AbstractButtonWidgetAccessor;
|
||||
import draylar.omegaconfiggui.mixin.ClickableWidgetInvoker;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
@@ -20,8 +20,8 @@ public class BaseTextFieldWidget extends TextFieldWidget {
|
||||
public void setTextFieldFocused(boolean focused) {
|
||||
// unfocus all others
|
||||
parent.children().forEach(element -> {
|
||||
if(element instanceof AbstractButtonWidget) {
|
||||
((AbstractButtonWidgetAccessor) element).callSetFocused(false);
|
||||
if (element instanceof ClickableWidget) {
|
||||
((ClickableWidgetInvoker) element).callSetFocused(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+3
-5
@@ -13,14 +13,12 @@ public class DoubleFieldWidget extends BaseTextFieldWidget {
|
||||
@Override
|
||||
public void write(String string) {
|
||||
try {
|
||||
if(string.equals(".") && !getText().contains(".")) {
|
||||
super.write(string);
|
||||
} else {
|
||||
if (!string.equals(".") || getText().contains(".")) {
|
||||
Double.parseDouble(string);
|
||||
super.write(string);
|
||||
}
|
||||
super.write(string);
|
||||
|
||||
} catch(NumberFormatException ignored) {
|
||||
} catch (NumberFormatException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -30,6 +30,10 @@ public class TypeWidgets {
|
||||
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));
|
||||
@@ -38,8 +42,4 @@ public class TypeWidgets {
|
||||
public static Class<?> unbox(Class<?> c) {
|
||||
return PRIMITIVE_TO_BOXED.getOrDefault(c, c);
|
||||
}
|
||||
|
||||
private TypeWidgets() {
|
||||
// NO-OP
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,10 +1,11 @@
|
||||
package draylar.omegaconfiggui.api.screen.widget;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
public interface WidgetSupplier<T, A extends AbstractButtonWidget> {
|
||||
AbstractButtonWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, T value);
|
||||
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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,12 +21,12 @@ public class DoubleWidgetSupplier implements WidgetSupplier<Double, DoubleFieldW
|
||||
String message = widget.getText();
|
||||
|
||||
// if it is just a . or empty, return 0
|
||||
if(message.equals(".") || message.isEmpty()) {
|
||||
if (message.equals(".") || message.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// trim potential trailing .
|
||||
if(message.indexOf(".") == message.length()) {
|
||||
if (message.indexOf(".") == message.length()) {
|
||||
message = message.substring(0, message.length() - 1);
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -4,7 +4,6 @@ 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.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package draylar.omegaconfiggui.mixin;
|
||||
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(AbstractButtonWidget.class)
|
||||
public interface AbstractButtonWidgetAccessor {
|
||||
@Mixin(ClickableWidget.class)
|
||||
public interface ClickableWidgetInvoker {
|
||||
@Invoker
|
||||
void callSetFocused(boolean focused);
|
||||
}
|
||||
Reference in New Issue
Block a user