From 7d6da4eecae4d96bc085c4ad12b9ef9e131aa68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linnea=20Gr=C3=A4f?= Date: Tue, 26 Dec 2023 02:10:07 +0100 Subject: [PATCH] Add initial support for a component based editor --- .../moulberry/moulconfig/common/IMinecraft.kt | 4 + .../moulconfig/common/RenderContext.java | 4 + .../moulconfig/gui/GuiComponent.java | 8 +- .../moulconfig/gui/GuiImmediateContext.kt | 10 ++ .../gui/component/ArrayComponent.java | 24 +++- .../gui/component/ButtonComponent.kt | 14 +- .../gui/component/CenterComponent.java | 8 +- .../gui/component/CollapsibleComponent.kt | 16 +-- .../gui/component/ColumnComponent.java | 23 +++- .../gui/component/HoverComponent.kt | 4 +- .../gui/component/IndirectComponent.kt | 8 +- .../gui/component/PanelComponent.java | 18 ++- .../gui/component/RowComponent.java | 22 +++- .../gui/component/ScaleComponent.kt | 8 +- .../gui/component/ScrollPanelComponent.java | 12 +- .../gui/component/SliderComponent.kt | 4 +- .../gui/component/SwitchComponent.java | 6 +- .../gui/component/TextFieldComponent.kt | 47 ++++--- .../moulconfig/observer/GetSetter.java | 46 +++++++ .../moulconfig/observer/Property.java | 47 ++++--- .../moulconfig/observer/PropertyImpl.java | 25 ++++ .../moulconfig/observer/PropertyUpgraded.java | 21 +++ ...apperNew.java => GuiComponentWrapper.java} | 4 +- .../gui/editors/ComponentEditor.java | 76 +++++++++++ .../gui/editors/GuiOptionEditorBoolean.java | 122 +++++++++++++----- .../moulconfig/internal/ForgeMinecraft.kt | 24 +++- .../moulconfig/processor/ProcessedOption.java | 15 +++ .../moulconfig/test/MoulConfigTest.java | 4 +- .../moulconfig/test/TestCategory.java | 2 +- .../moulconfig/platform/ModernMinecraft.kt | 9 ++ 30 files changed, 501 insertions(+), 134 deletions(-) create mode 100644 common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyImpl.java create mode 100644 common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyUpgraded.java rename legacy/src/main/java/io/github/moulberry/moulconfig/gui/{GuiScreenElementWrapperNew.java => GuiComponentWrapper.java} (96%) create mode 100644 legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/ComponentEditor.java diff --git a/common/src/main/java/io/github/moulberry/moulconfig/common/IMinecraft.kt b/common/src/main/java/io/github/moulberry/moulconfig/common/IMinecraft.kt index 64ad20a3c..74956b9ea 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/common/IMinecraft.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/common/IMinecraft.kt @@ -13,9 +13,13 @@ interface IMinecraft { fun loadResourceLocation(resourceLocation: MyResourceLocation): InputStream fun getLogger(label: String): MCLogger + val mouseX: Int + val mouseY: Int val isDevelopmentEnvironment: Boolean val defaultFontRenderer: IFontRenderer val keyboardConstants: IKeyboardConstants + val scaledWidth: Int + val scaledHeight: Int companion object { @JvmField diff --git a/common/src/main/java/io/github/moulberry/moulconfig/common/RenderContext.java b/common/src/main/java/io/github/moulberry/moulconfig/common/RenderContext.java index 37ff0bc0f..f1d250281 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/common/RenderContext.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/common/RenderContext.java @@ -122,4 +122,8 @@ default void drawDarkRect(int x, int y, int width, int height) { void refreshScissor(); void disableScissor(); + + default IMinecraft getMinecraft() { + return IMinecraft.instance; + } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiComponent.java index 8c5dc3773..6ed254ee3 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiComponent.java @@ -121,8 +121,10 @@ public T foldChildren(T initial, @NotNull BiFunction<@NotNull GuiComponent, * Called by the parent renderer. * * @param context the context in which this + * @return {@code true} if this event was handled, {@code false} if this event should be handled by another element */ - public void mouseEvent(@NotNull MouseEvent mouseEvent,@NotNull GuiImmediateContext context) { + public boolean mouseEvent(@NotNull MouseEvent mouseEvent,@NotNull GuiImmediateContext context) { + return false; } /** @@ -130,8 +132,10 @@ public void mouseEvent(@NotNull MouseEvent mouseEvent,@NotNull GuiImmediateConte *

N.B.: this method is called regardless of whether this element is focused or not.

* * @param context the context in which this + * @return {@code true} if this event was handled, {@code false} if this event should be handled by another element */ - public void keyboardEvent(@NotNull KeyboardEvent event,@NotNull GuiImmediateContext context) { + public boolean keyboardEvent(@NotNull KeyboardEvent event,@NotNull GuiImmediateContext context) { + return false; } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiImmediateContext.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiImmediateContext.kt index a6f33f415..1d4062d74 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiImmediateContext.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/GuiImmediateContext.kt @@ -126,6 +126,16 @@ data class GuiImmediateContext( ) } + /** + * Construct a new context, which has not been translated, but possible smaller if the arguments demand so. + * + * @param maxWidth max width of the new context. this argument will be ignored if it is larger than the current width + * @param maxHeight max height of the new context. this argument will be ignored if it is larger than the current height + */ + fun limitSize(maxWidth: Int, maxHeight: Int): GuiImmediateContext { + return translated(0, 0, minOf(width, maxWidth), minOf(height, maxHeight)) + } + fun scaled(scale: Float): GuiImmediateContext { return GuiImmediateContext( renderContext, diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ArrayComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ArrayComponent.java index f928b12fc..05d261819 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ArrayComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ArrayComponent.java @@ -84,14 +84,26 @@ public void render(GuiImmediateContext context) { } @Override - public void mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { - foldWithContext(context, (guiComponent, guiImmediateContext) -> - guiComponent.mouseEvent(mouseEvent, guiImmediateContext)); + public boolean mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { + // TODO: early return + boolean[] wasHandled = new boolean[1]; + foldWithContext(context, (guiComponent, guiImmediateContext) -> { + if (guiComponent.mouseEvent(mouseEvent, guiImmediateContext)) { + wasHandled[0] = true; + } + }); + return wasHandled[0]; } @Override - public void keyboardEvent(KeyboardEvent keyboardEvent, GuiImmediateContext context) { - foldWithContext(context, (guiComponent, guiImmediateContext) -> - guiComponent.keyboardEvent(keyboardEvent, guiImmediateContext)); + public boolean keyboardEvent(KeyboardEvent keyboardEvent, GuiImmediateContext context) { + // TODO: early return + boolean[] wasHandled = new boolean[1]; + foldWithContext(context, (guiComponent, guiImmediateContext) -> { + if (guiComponent.keyboardEvent(keyboardEvent, guiImmediateContext)) { + wasHandled[0] = true; + } + }); + return wasHandled[0]; } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ButtonComponent.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ButtonComponent.kt index 1d51db838..deeac9b9f 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ButtonComponent.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ButtonComponent.kt @@ -8,18 +8,24 @@ import io.github.moulberry.moulconfig.gui.MouseEvent import io.github.moulberry.moulconfig.gui.MouseEvent.Click class ButtonComponent(element: GuiComponent, insets: Int, val onClick: Runnable) : PanelComponent(element, insets) { - override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext) { + override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean { if (context.isHovered && mouseEvent is Click) { val (mouseButton, mouseState) = mouseEvent - if (mouseState && mouseButton == 0) onClick.run() + if (mouseState && mouseButton == 0) { + onClick.run() + return true + } } + return false } - override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext) { + override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean { if (isFocused && event is KeyboardEvent.KeyPressed && event.pressed && event.keycode == KeyboardConstants.enter ) { onClick.run() - } else super.keyboardEvent(event, context) + return true + } + return false } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CenterComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CenterComponent.java index 4d3eba26a..36288cb2f 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CenterComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CenterComponent.java @@ -79,12 +79,12 @@ public void render(GuiImmediateContext context) { } @Override - public void keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { - child.keyboardEvent(event, getChildContext(context)); + public boolean keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { + return child.keyboardEvent(event, getChildContext(context)); } @Override - public void mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { - child.mouseEvent(mouseEvent, getChildContext(context)); + public boolean mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { + return child.mouseEvent(mouseEvent, getChildContext(context)); } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CollapsibleComponent.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CollapsibleComponent.kt index c1bde1bc0..688f9d9bb 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CollapsibleComponent.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/CollapsibleComponent.kt @@ -72,7 +72,7 @@ class CollapsibleComponent( } } - override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext) { + override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean { val barHeight = maxOf(title.get().height, fr.height) if (mouseEvent is MouseEvent.Click && context.translated( @@ -84,33 +84,31 @@ class CollapsibleComponent( ) { if (mouseEvent.mouseState) collapsedState.set(!collapsedState.get()) - return + return true } - title.get().mouseEvent( + return title.get().mouseEvent( mouseEvent, context.translated( iconWidth, 0, context.width - iconWidth, barHeight ) - ) - body.get().mouseEvent( + ) || body.get().mouseEvent( mouseEvent, context.translated(0, barHeight, context.width, context.height - barHeight) ) } - override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext) { + override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean { val barHeight = maxOf(title.get().height, fr.height) - title.get().keyboardEvent( + return title.get().keyboardEvent( event, context.translated( iconWidth, 0, context.width - iconWidth, barHeight ) - ) - body.get().keyboardEvent( + ) || body.get().keyboardEvent( event, context.translated(0, barHeight, context.width, context.height - barHeight) ) } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ColumnComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ColumnComponent.java index f64f53a37..3d3bc6a75 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ColumnComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ColumnComponent.java @@ -83,13 +83,26 @@ public void render(GuiImmediateContext context) { } @Override - public void mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { - foldWithContext(context, (component, context1) -> component.mouseEvent(mouseEvent, context1)); + public boolean mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { + // TODO: early return + boolean[] wasHandled = new boolean[1]; + foldWithContext(context, (guiComponent, guiImmediateContext) -> { + if (guiComponent.mouseEvent(mouseEvent, guiImmediateContext)) { + wasHandled[0] = true; + } + }); + return wasHandled[0]; } @Override - public void keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { - foldWithContext(context, (guiComponent, guiImmediateContext) -> - guiComponent.keyboardEvent(event, guiImmediateContext)); + public boolean keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { + // TODO: early return + boolean[] wasHandled = new boolean[1]; + foldWithContext(context, (guiComponent, guiImmediateContext) -> { + if (guiComponent.keyboardEvent(event, guiImmediateContext)) { + wasHandled[0] = true; + } + }); + return wasHandled[0]; } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/HoverComponent.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/HoverComponent.kt index c73219b88..2a440c80f 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/HoverComponent.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/HoverComponent.kt @@ -31,11 +31,11 @@ class HoverComponent( } - override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext) { + override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean { return child.mouseEvent(mouseEvent, context) } - override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext) { + override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean { return child.keyboardEvent(event, context) } } \ No newline at end of file diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/IndirectComponent.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/IndirectComponent.kt index 325449b80..28e673bff 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/IndirectComponent.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/IndirectComponent.kt @@ -22,12 +22,12 @@ open class IndirectComponent( component.get().render(context) } - override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext) { - component.get().keyboardEvent(event, context) + override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean { + return component.get().keyboardEvent(event, context) } - override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext) { - component.get().mouseEvent(mouseEvent, context) + override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean { + return component.get().mouseEvent(mouseEvent, context) } override fun foldChildren(initial: T, visitor: BiFunction): T { diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/PanelComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/PanelComponent.java index da4f5e85d..8d7467cf5 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/PanelComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/PanelComponent.java @@ -24,12 +24,14 @@ import io.github.moulberry.moulconfig.gui.GuiImmediateContext; import io.github.moulberry.moulconfig.gui.KeyboardEvent; import io.github.moulberry.moulconfig.gui.MouseEvent; +import lombok.Getter; import java.util.function.BiFunction; /** * Renders an element with a floating rect. */ +@Getter public class PanelComponent extends GuiComponent { private final GuiComponent element; private final int insets; @@ -57,35 +59,31 @@ public int getWidth() { return element.getWidth() + insets * 2; } - public int getInsets() { - return insets; - } - @Override public int getHeight() { return element.getHeight() + insets * 2 + 2; } - GuiImmediateContext getChildContext(GuiImmediateContext context) { + protected GuiImmediateContext getChildContext(GuiImmediateContext context) { return context.translated(insets, insets, element.getWidth(), element.getHeight()); } @Override public void render(GuiImmediateContext context) { context.getRenderContext().pushMatrix(); - context.getRenderContext().drawDarkRect(0, 0, getWidth(), getHeight() - 2); + context.getRenderContext().drawDarkRect(0, 0, context.getWidth(), context.getHeight() - 2); context.getRenderContext().translate(insets, insets, 0); element.render(getChildContext(context)); context.getRenderContext().popMatrix(); } @Override - public void keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { - element.keyboardEvent(event, getChildContext(context)); + public boolean keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { + return element.keyboardEvent(event, getChildContext(context)); } @Override - public void mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { - element.mouseEvent(mouseEvent, getChildContext(context)); + public boolean mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { + return element.mouseEvent(mouseEvent, getChildContext(context)); } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/RowComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/RowComponent.java index c790e1ce5..576ace44b 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/RowComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/RowComponent.java @@ -83,13 +83,27 @@ public void render(GuiImmediateContext context) { } @Override - public void mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { - foldWithContext(context, (guiComponent, guiImmediateContext) -> guiComponent.mouseEvent(mouseEvent, guiImmediateContext)); + public boolean mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { + // TODO: early return + boolean[] wasHandled = new boolean[1]; + foldWithContext(context, (guiComponent, guiImmediateContext) -> { + if (guiComponent.mouseEvent(mouseEvent, guiImmediateContext)) { + wasHandled[0] = true; + } + }); + return wasHandled[0]; } @Override - public void keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { - foldWithContext(context, (guiComponent, guiImmediateContext) -> guiComponent.keyboardEvent(event, guiImmediateContext)); + public boolean keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { + // TODO: early return + boolean[] wasHandled = new boolean[1]; + foldWithContext(context, (guiComponent, guiImmediateContext) -> { + if (guiComponent.keyboardEvent(event, guiImmediateContext)) { + wasHandled[0] = true; + } + }); + return wasHandled[0]; } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScaleComponent.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScaleComponent.kt index 37b210b21..ca84592eb 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScaleComponent.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScaleComponent.kt @@ -31,11 +31,11 @@ class ScaleComponent( context.renderContext.popMatrix() } - override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext) { - child.keyboardEvent(event, context.scaled(scaleFactor.get())) + override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean { + return child.keyboardEvent(event, context.scaled(scaleFactor.get())) } - override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext) { - super.mouseEvent(mouseEvent, context.scaled(scaleFactor.get())) + override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean { + return child.mouseEvent(mouseEvent, context.scaled(scaleFactor.get())) } } \ No newline at end of file diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScrollPanelComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScrollPanelComponent.java index a7ba0a59d..ff0a21828 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScrollPanelComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/ScrollPanelComponent.java @@ -45,15 +45,19 @@ public void render(GuiImmediateContext context) { } @Override - public void keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { - child.keyboardEvent(event, context.translatedNonRendering(0, -scrollOffset, width, height)); + public boolean keyboardEvent(KeyboardEvent event, GuiImmediateContext context) { + return child.keyboardEvent(event, context.translatedNonRendering(0, -scrollOffset, width, height)); } @Override - public void mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { + public boolean mouseEvent(MouseEvent mouseEvent, GuiImmediateContext context) { + if (child.mouseEvent(mouseEvent, context.translatedNonRendering(0, -scrollOffset, width, height))) { + return true; + } if (context.isHovered() && mouseEvent instanceof MouseEvent.Scroll) { scrollOffset = (int) Math.max(0, Math.min(scrollOffset - (((MouseEvent.Scroll) mouseEvent).getDWheel()), child.getHeight() - height)); + return true; } - child.mouseEvent(mouseEvent, context.translatedNonRendering(0, -scrollOffset, width, height)); + return false; } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SliderComponent.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SliderComponent.kt index 9ba73ac68..f8180dce7 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SliderComponent.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SliderComponent.kt @@ -65,13 +65,15 @@ open class SliderComponent( value.set(v) } - override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext) { + override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean { if (!context.renderContext.isMouseButtonDown(0)) clicked = false if (context.isHovered && mouseEvent is MouseEvent.Click && mouseEvent.mouseState && mouseEvent.mouseButton == 0) { clicked = true } if (clicked) { setValueFromContext(context) + return true } + return false } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SwitchComponent.java b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SwitchComponent.java index 229be2aa0..b8feee5b7 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SwitchComponent.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/SwitchComponent.java @@ -90,12 +90,14 @@ public void render(GuiImmediateContext context) { } @Override - public void mouseEvent(MouseEvent event, GuiImmediateContext context) { + public boolean mouseEvent(MouseEvent event, GuiImmediateContext context) { super.mouseEvent(event, context); - if (!(event instanceof MouseEvent.Click)) return; + if (!(event instanceof MouseEvent.Click)) return false; var click = (MouseEvent.Click) event; if (context.isHovered() && click.getMouseButton() == 0 && click.getMouseState()) { value.set(!value.get()); + return true; } + return false; } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/TextFieldComponent.kt b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/TextFieldComponent.kt index ec5718648..2478d266f 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/gui/component/TextFieldComponent.kt +++ b/common/src/main/java/io/github/moulberry/moulconfig/gui/component/TextFieldComponent.kt @@ -116,19 +116,19 @@ open class TextFieldComponent( context.renderContext.drawColoredRect(1f, 1f, (width - 1).toFloat(), (height - 1).toFloat(), BACKGROUND_COLOR) } - override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext) { - if (!editable.get()) return - if (!isFocused) return + override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean { + if (!editable.get()) return false + if (!isFocused) return false if (event is KeyboardEvent.KeyPressed && event.pressed) { - when (event.keycode) { + return when (event.keycode) { KeyboardConstants.left -> { onDirectionalKey(context, -1) - return + return true } KeyboardConstants.right -> { onDirectionalKey(context, 1) - return + return true } KeyboardConstants.home, KeyboardConstants.up -> { @@ -139,7 +139,7 @@ open class TextFieldComponent( } cursor = 0 scrollCursorIntoView() - return + return true } KeyboardConstants.down, KeyboardConstants.end -> { @@ -150,49 +150,61 @@ open class TextFieldComponent( } cursor = text.get().length scrollCursorIntoView() - return + return true } KeyboardConstants.backSpace -> { if (selection == -1) selection = skipCharacters(context.renderContext.isCtrlDown, -1) writeText("") - return + return true } KeyboardConstants.delete -> { if (selection == -1) selection = skipCharacters(context.renderContext.isCtrlDown, 1) writeText("") - return + return true } KeyboardConstants.keyC -> if (context.renderContext.isCtrlDown) { ClipboardUtils.copyToClipboard(getSelection()) - return + return true + } else { + return false } KeyboardConstants.keyX -> if (context.renderContext.isCtrlDown) { ClipboardUtils.copyToClipboard(getSelection()) writeText("") - return + return true + } else { + return false } KeyboardConstants.keyV -> if (context.renderContext.isCtrlDown) { writeText(ClipboardUtils.getClipboardContent()) - return + return true + } else { + return false } KeyboardConstants.keyA -> if (context.renderContext.isCtrlDown) { cursor = text.get().length selection = 0 scrollCursorIntoView() - return + return true + } else { + return false } + else -> return false } } else if (event is KeyboardEvent.CharTyped) { val it = event.char if (it >= ' ' && it != '§' && it.code != 127) writeText(it + "") + return true + } else { + return false } } @@ -203,14 +215,15 @@ open class TextFieldComponent( return safeSubString(text.get(), l, r) } - override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext) { + override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean { super.mouseEvent(mouseEvent, context) if (context.isHovered && mouseEvent is Click) { - val (mouseButton, mouseState) = mouseEvent - if (mouseState && mouseButton == 0) { + if (mouseEvent.mouseState && mouseEvent.mouseButton == 0) { requestFocus() + return true } } + return false } private fun safeSubString(str: String, startIndex: Int): String { diff --git a/common/src/main/java/io/github/moulberry/moulconfig/observer/GetSetter.java b/common/src/main/java/io/github/moulberry/moulconfig/observer/GetSetter.java index 0b46996c3..65a474f32 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/observer/GetSetter.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/observer/GetSetter.java @@ -20,6 +20,15 @@ package io.github.moulberry.moulconfig.observer; +import io.github.moulberry.moulconfig.internal.Warnings; +import lombok.SneakyThrows; +import lombok.var; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.function.Consumer; import java.util.function.Supplier; @@ -89,5 +98,42 @@ public void set(T newValue) { } }; } + + /** + * Create a {@link GetSetter} backed by a field… This {@link GetSetter} will update to and poll from the underlying field without any buffer. + * + * @param owner the instance on which to perform the lookup. should be null for static fields + * @param field the field to read from and write to + * @return a field backed {@link GetSetter} + */ + @SneakyThrows + static GetSetter ofField(@Nullable Object owner, @NotNull Field field) { + field.setAccessible(true); + if ((owner == null) != (Modifier.isStatic(field.getModifiers()))) { + Warnings.warn("Field instance (" + owner + ") is mismatched with field " + field); + } + var lookup = MethodHandles.publicLookup(); + var getter = lookup.unreflectGetter(field); + var setter = lookup.unreflectSetter(field); + if (owner != null) { + getter = getter.bindTo(owner); + setter = setter.bindTo(owner); + } + var finalGetter = getter; + var finalSetter = setter; + return new GetSetter() { + @SneakyThrows + @Override + public Object get() { + return (Object) finalGetter.invoke(); + } + + @SneakyThrows + @Override + public void set(Object newValue) { + finalSetter.invoke(newValue); + } + }; + } } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/observer/Property.java b/common/src/main/java/io/github/moulberry/moulconfig/observer/Property.java index 7d23d97b7..104944647 100644 --- a/common/src/main/java/io/github/moulberry/moulconfig/observer/Property.java +++ b/common/src/main/java/io/github/moulberry/moulconfig/observer/Property.java @@ -20,8 +20,6 @@ package io.github.moulberry.moulconfig.observer; -import com.google.gson.annotations.Expose; - /** * A property is a variable which is modifiable and can have those mutations observed. * When serializing a property to Json you can use {@link PropertyTypeAdapterFactory} to automatically @@ -31,15 +29,9 @@ * * @param the type of value this Property can hold. */ -public class Property extends BaseObservable implements GetSetter { - /** - * The internal storage of this property - */ - @Expose - T value; +public abstract class Property extends BaseObservable implements GetSetter { - private Property(T value) { - this.value = value; + Property() { } /** @@ -50,26 +42,39 @@ private Property(T value) { * @return a newly constructed property */ public static Property of(T value) { - return new Property<>(value); + return new PropertyImpl<>(value); } - @Override - public T get() { - return value; + /** + * Upgrades a {@link GetSetter} so that access through the returned {@link Property} will notify observers, with state still managed in the old {@link GetSetter}. + * N.B.: Changes to the provided {@link GetSetter} directly will only cause you to get notified if you already had a {@link Property}. If you want to not receive + * those updates, use {@link #wrap} + * + * @param getSetter the old get setter which will hold state + */ + public static Property upgrade(GetSetter getSetter) { + if (getSetter instanceof Property) + return (Property) getSetter; + return wrap(getSetter); + } + + /** + * Upgrades a {@link GetSetter} so that access through the returned {@link Property} will notify observers, with state still managed in the old {@link GetSetter}. + * N.B.: Changes to the provided {@link GetSetter} directly will never cause you to get notified. If you want to receive updates from the provided {@link GetSetter} + * if it already is a {@link Property}, use {@link #upgrade} + * + * @param getSetter the old get setter which will hold state + */ + public static Property wrap(GetSetter getSetter) { + return new PropertyUpgraded<>(getSetter); } /** * Explicitly notify observers about state changes that are internal to the stored value. */ public void notifyObservers() { + T value = get(); notifyObservers(value, value); } - @Override - public void set(T newValue) { - T oldValue = this.value; - this.value = newValue; - notifyObservers(oldValue, newValue); - } - } diff --git a/common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyImpl.java b/common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyImpl.java new file mode 100644 index 000000000..540be9e79 --- /dev/null +++ b/common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyImpl.java @@ -0,0 +1,25 @@ +package io.github.moulberry.moulconfig.observer; + +import com.google.gson.annotations.Expose; + +class PropertyImpl extends Property { + @Expose + T value; + + PropertyImpl(T value) { + this.value = value; + } + + @Override + public T get() { + return value; + } + + @Override + public void set(T newValue) { + T oldValue = this.value; + this.value = newValue; + notifyObservers(oldValue, newValue); + } + +} diff --git a/common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyUpgraded.java b/common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyUpgraded.java new file mode 100644 index 000000000..c271aa030 --- /dev/null +++ b/common/src/main/java/io/github/moulberry/moulconfig/observer/PropertyUpgraded.java @@ -0,0 +1,21 @@ +package io.github.moulberry.moulconfig.observer; + +class PropertyUpgraded extends Property { + private final GetSetter getSetter; + + public PropertyUpgraded(GetSetter getSetter) { + this.getSetter = getSetter; + } + + @Override + public void set(T newValue) { + T old = get(); + getSetter.set(newValue); + notifyObservers(old, get()); + } + + @Override + public T get() { + return getSetter.get(); + } +} diff --git a/legacy/src/main/java/io/github/moulberry/moulconfig/gui/GuiScreenElementWrapperNew.java b/legacy/src/main/java/io/github/moulberry/moulconfig/gui/GuiComponentWrapper.java similarity index 96% rename from legacy/src/main/java/io/github/moulberry/moulconfig/gui/GuiScreenElementWrapperNew.java rename to legacy/src/main/java/io/github/moulberry/moulconfig/gui/GuiComponentWrapper.java index 8063bddfb..f0d99240a 100644 --- a/legacy/src/main/java/io/github/moulberry/moulconfig/gui/GuiScreenElementWrapperNew.java +++ b/legacy/src/main/java/io/github/moulberry/moulconfig/gui/GuiComponentWrapper.java @@ -31,11 +31,11 @@ import java.io.IOException; @ToString -public class GuiScreenElementWrapperNew extends GuiScreen { +public class GuiComponentWrapper extends GuiScreen { @NonNull public GuiContext context; - public GuiScreenElementWrapperNew(@NotNull GuiContext context) { + public GuiComponentWrapper(@NotNull GuiContext context) { this.context = context; context.setCloseRequestHandler(this::requestClose); } diff --git a/legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/ComponentEditor.java b/legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/ComponentEditor.java new file mode 100644 index 000000000..404bb6b4d --- /dev/null +++ b/legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/ComponentEditor.java @@ -0,0 +1,76 @@ +package io.github.moulberry.moulconfig.gui.editors; + +import io.github.moulberry.moulconfig.common.IMinecraft; +import io.github.moulberry.moulconfig.gui.GuiComponent; +import io.github.moulberry.moulconfig.gui.GuiImmediateContext; +import io.github.moulberry.moulconfig.gui.GuiOptionEditor; +import io.github.moulberry.moulconfig.gui.MouseEvent; +import io.github.moulberry.moulconfig.internal.ForgeRenderContext; +import io.github.moulberry.moulconfig.processor.ProcessedOption; +import lombok.var; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.input.Mouse; + +public abstract class ComponentEditor extends GuiOptionEditor { + protected ComponentEditor(ProcessedOption option) { + super(option); + } + + public abstract @NotNull GuiComponent getDelegate(); + + public @Nullable GuiComponent getOverlayDelegate() { + return null; + } + + public GuiImmediateContext getImmContext( + int x, int y, int width, int height + ) { + IMinecraft instance = IMinecraft.instance; + return new GuiImmediateContext( + new ForgeRenderContext(), + x, y, + width, height, + instance.getMouseX() - x, + instance.getMouseY() - y, + instance.getMouseX(), + instance.getMouseY() + ); + } + + @Override + public int getHeight() { + return Math.max(getDelegate().getHeight(), super.getHeight()); + } + + @Override + public final boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + return getDelegate().mouseEvent(new MouseEvent.Click(Mouse.getEventButton(), Mouse.getEventButtonState()), getImmContext(x, y, width, getHeight())); + } + + @Override + public final boolean keyboardInput() { + return false; // TODO: handle keyboard input here + } + + @Override + public final void render(int x, int y, int width) { + var context = getImmContext(x, y, width, getHeight()); + context.getRenderContext().pushMatrix(); + context.getRenderContext().translate(context.getRenderOffsetX(), context.getRenderOffsetY(), 0); + getDelegate().render(context); + context.getRenderContext().popMatrix(); + } + + @Override + public final boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { + if (getOverlayDelegate() == null) return false; + return getOverlayDelegate().mouseEvent(new MouseEvent.Click(Mouse.getEventButton(), Mouse.getEventButtonState()), getImmContext(x, y, width, getOverlayDelegate().getHeight())); + } + + @Override + public final void renderOverlay(int x, int y, int width) { + if (getOverlayDelegate() == null) return; + getOverlayDelegate().render(getImmContext(x, y, width, getOverlayDelegate().getHeight())); + } +} diff --git a/legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/GuiOptionEditorBoolean.java b/legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/GuiOptionEditorBoolean.java index 878a4df11..b2b8746f1 100644 --- a/legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/GuiOptionEditorBoolean.java +++ b/legacy/src/main/java/io/github/moulberry/moulconfig/gui/editors/GuiOptionEditorBoolean.java @@ -21,15 +21,23 @@ package io.github.moulberry.moulconfig.gui.editors; import io.github.moulberry.moulconfig.Config; -import io.github.moulberry.moulconfig.gui.GuiOptionEditor; -import io.github.moulberry.moulconfig.gui.elements.GuiElementBoolean; +import io.github.moulberry.moulconfig.common.IMinecraft; +import io.github.moulberry.moulconfig.gui.GuiComponent; +import io.github.moulberry.moulconfig.gui.GuiImmediateContext; +import io.github.moulberry.moulconfig.gui.component.CenterComponent; +import io.github.moulberry.moulconfig.gui.component.PanelComponent; +import io.github.moulberry.moulconfig.gui.component.SwitchComponent; +import io.github.moulberry.moulconfig.observer.GetSetter; +import io.github.moulberry.moulconfig.observer.Property; import io.github.moulberry.moulconfig.processor.ProcessedOption; +import lombok.var; +import org.jetbrains.annotations.NotNull; -public class GuiOptionEditorBoolean extends GuiOptionEditor { +import java.util.List; - private final GuiElementBoolean bool; - private final Config config; - private final int runnableId; +public class GuiOptionEditorBoolean extends ComponentEditor { + + private final GuiComponent bool; public GuiOptionEditorBoolean( ProcessedOption option, @@ -37,37 +45,93 @@ public GuiOptionEditorBoolean( Config config ) { super(option); - this.config = config; - this.runnableId = runnableId; - bool = new GuiElementBoolean(0, 0, () -> (Boolean) option.get(), 10, (value) -> onUpdate(option, value)); + var prop = Property.upgrade((GetSetter) option.intoProperty()); + prop.whenChanged((oldValue, newValue) -> config.executeRunnable(runnableId)); + bool = wrapComponent(new CenterComponent(new SwitchComponent(prop, 200))); } - @Override - public void render(int x, int y, int width) { - super.render(x, y, width); - int height = getHeight(); + private class EditorComponentWrapper extends PanelComponent { + public EditorComponentWrapper(GuiComponent component) { + super(component); + } + + @Override + public int getWidth() { + return super.getWidth() + 150; + } + + @Override + public int getHeight() { + var fr = IMinecraft.instance.getDefaultFontRenderer(); + return Math.max(45, fr.splitText(option.desc, 250 * 2 / 3 - 10).size() * (fr.getHeight() + 1) + 10); + } + + @Override + protected GuiImmediateContext getChildContext(GuiImmediateContext context) { + return context.translated(5, 13, context.getWidth() / 3 - 10, context.getHeight() - 13); + } + + @Override + public void render(@NotNull GuiImmediateContext context) { + context.getRenderContext().drawDarkRect(0, 0, context.getWidth(), context.getHeight() - 2); + + renderTitle(context); - bool.x = x + width / 6 - 24; - bool.y = y + height - 7 - 14; - bool.render(); + renderDescription(context); + + renderElement(context); + } + + private void renderElement(@NotNull GuiImmediateContext context) { + context.getRenderContext().pushMatrix(); + context.getRenderContext().translate(5, 13, 0); + this.getElement().render(getChildContext(context)); + context.getRenderContext().popMatrix(); + } + + private void renderTitle(@NotNull GuiImmediateContext context) { + int width = context.getWidth(); + var minecraft = context.getRenderContext().getMinecraft(); + var fr = minecraft.getDefaultFontRenderer(); + context.getRenderContext().drawStringCenteredScaledMaxWidth( + option.name, fr, width / 6, 13, true, width / 3 - 10, 0xc0c0c0 + ); + } + + private void renderDescription(@NotNull GuiImmediateContext context) { + int width = context.getWidth(); + var minecraft = context.getRenderContext().getMinecraft(); + var fr = minecraft.getDefaultFontRenderer(); + float scale = 1; + List lines; + while (true) { + lines = fr.splitText(option.desc, (int) (width * 2 / 3 / scale - 10)); + if (lines.size() * scale * (fr.getHeight() + 1) + 10 < context.getHeight()) + break; + scale -= 1 / 8f; + if (scale < 1 / 16f) break; + } + context.getRenderContext().pushMatrix(); + context.getRenderContext().translate(5 + width / 3, 5, 0); + context.getRenderContext().scale(scale, scale, 1); + context.getRenderContext().translate(0, ((context.getHeight() - 10) - (fr.getHeight() + 1) * (lines.size() - 1) * scale) / 2F, 0); + for (String line : lines) { + context.getRenderContext().drawString(fr, line, 0, 0, 0xc0c0c0, false); + context.getRenderContext().translate(0, fr.getHeight() + 1, 0); + } + context.getRenderContext().popMatrix(); + } } - @Override - public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - int height = getHeight(); - bool.x = x + width / 6 - 24; - bool.y = y + height - 7 - 14; - return bool.mouseInput(mouseX, mouseY); + protected GuiComponent wrapComponent(GuiComponent component) { + return new EditorComponentWrapper( + new CenterComponent(component) + ); } @Override - public boolean keyboardInput() { - return false; + public @NotNull GuiComponent getDelegate() { + return bool; } - private void onUpdate(ProcessedOption option, boolean value) { - if (option.set(value)) { - config.executeRunnable(runnableId); - } - } } diff --git a/legacy/src/main/java/io/github/moulberry/moulconfig/internal/ForgeMinecraft.kt b/legacy/src/main/java/io/github/moulberry/moulconfig/internal/ForgeMinecraft.kt index a2dc082a1..1ac91a81a 100644 --- a/legacy/src/main/java/io/github/moulberry/moulconfig/internal/ForgeMinecraft.kt +++ b/legacy/src/main/java/io/github/moulberry/moulconfig/internal/ForgeMinecraft.kt @@ -5,11 +5,12 @@ import io.github.moulberry.moulconfig.common.IKeyboardConstants import io.github.moulberry.moulconfig.common.IMinecraft import io.github.moulberry.moulconfig.common.MyResourceLocation import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ScaledResolution import net.minecraft.launchwrapper.Launch import net.minecraft.util.ResourceLocation import org.apache.logging.log4j.LogManager +import org.lwjgl.input.Mouse import java.io.InputStream -import kotlin.math.log class ForgeMinecraft : IMinecraft { override fun bindTexture(resourceLocation: MyResourceLocation) { @@ -42,6 +43,27 @@ class ForgeMinecraft : IMinecraft { override val isDevelopmentEnvironment: Boolean get() = Launch.blackboard.get("fml.deobfuscatedEnvironment") as Boolean + override val scaledWidth + get(): Int = ScaledResolution(Minecraft.getMinecraft()).scaledWidth + + override val scaledHeight: Int + get() = ScaledResolution(Minecraft.getMinecraft()).scaledHeight + + override val mouseX: Int + get() { + val width = scaledWidth + val mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth + return mouseX + + } + + override val mouseY: Int + get() { + val height = scaledHeight + val mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1 + return mouseY + } + companion object { @JvmStatic fun fromMyResourceLocation(resourceLocation: MyResourceLocation): ResourceLocation { diff --git a/legacy/src/main/java/io/github/moulberry/moulconfig/processor/ProcessedOption.java b/legacy/src/main/java/io/github/moulberry/moulconfig/processor/ProcessedOption.java index 7a5da73b1..a1ff95934 100644 --- a/legacy/src/main/java/io/github/moulberry/moulconfig/processor/ProcessedOption.java +++ b/legacy/src/main/java/io/github/moulberry/moulconfig/processor/ProcessedOption.java @@ -23,6 +23,7 @@ import io.github.moulberry.moulconfig.Config; import io.github.moulberry.moulconfig.gui.GuiOptionEditor; +import io.github.moulberry.moulconfig.observer.GetSetter; import io.github.moulberry.moulconfig.observer.Property; import java.lang.reflect.Field; @@ -65,6 +66,20 @@ public Object get() { } } + public GetSetter intoProperty() { + return new GetSetter() { + @Override + public Object get() { + return ProcessedOption.this.get(); + } + + @Override + public void set(Object newValue) { + ProcessedOption.this.set(newValue); + } + }; + } + public Type getType() { if (isProperty) { return ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; diff --git a/legacy/src/main/java/io/github/moulberry/moulconfig/test/MoulConfigTest.java b/legacy/src/main/java/io/github/moulberry/moulconfig/test/MoulConfigTest.java index 1688f9a37..710917a8d 100644 --- a/legacy/src/main/java/io/github/moulberry/moulconfig/test/MoulConfigTest.java +++ b/legacy/src/main/java/io/github/moulberry/moulconfig/test/MoulConfigTest.java @@ -135,7 +135,7 @@ public void processCommand(ICommandSender sender, String[] args) { if (args.length > 0 && "gui".equals(args[0])) { screenToOpen = new MoulGuiOverlayEditor(testConfigMoulConfigProcessor); } else if (args.length > 0 && "testgui".equals(args[0])) { - screenToOpen = new GuiScreenElementWrapperNew(new GuiContext( + screenToOpen = new GuiComponentWrapper(new GuiContext( new CenterComponent(new PanelComponent( new ColumnComponent( new TextComponent("Label", 80), @@ -147,7 +147,7 @@ public void processCommand(ICommandSender sender, String[] args) { var xmlUniverse = XMLUniverse.getDefaultUniverse(); var gui = xmlUniverse.load(new ObjectBound(), Minecraft.getMinecraft().getResourceManager() .getResource(new ResourceLocation("moulconfig:test.xml")).getInputStream()); - screenToOpen = new GuiScreenElementWrapperNew(new GuiContext(gui)); + screenToOpen = new GuiComponentWrapper(new GuiContext(gui)); } else { screenToOpen = new GuiScreenElementWrapper(new MoulConfigEditor<>(testConfigMoulConfigProcessor)); } diff --git a/legacy/src/main/java/io/github/moulberry/moulconfig/test/TestCategory.java b/legacy/src/main/java/io/github/moulberry/moulconfig/test/TestCategory.java index 03be9cc42..677a47e3b 100644 --- a/legacy/src/main/java/io/github/moulberry/moulconfig/test/TestCategory.java +++ b/legacy/src/main/java/io/github/moulberry/moulconfig/test/TestCategory.java @@ -74,7 +74,7 @@ public String getName() { @Expose public Property text2 = Property.of("Text 2"); - @ConfigOption(name = "Boolean test", desc = "Toggle test") + @ConfigOption(name = "Boolean test", desc = "Ut iste voluptatibus qui fugiat maxime. Praesentium incidunt beatae voluptas voluptatem repudiandae. Et qui sed ea. Dolorem sit aspernatur assumenda optio sunt dolorum nemo. Quo eaque id minima enim consequatur excepturi blanditiis autem. Quae porro saepe doloribus iure optio nam quae et.") @ConfigEditorBoolean @Expose public boolean bool = true; diff --git a/modern/src/main/kotlin/io/github/notenoughupdates/moulconfig/platform/ModernMinecraft.kt b/modern/src/main/kotlin/io/github/notenoughupdates/moulconfig/platform/ModernMinecraft.kt index 00f11be15..79723dfd3 100644 --- a/modern/src/main/kotlin/io/github/notenoughupdates/moulconfig/platform/ModernMinecraft.kt +++ b/modern/src/main/kotlin/io/github/notenoughupdates/moulconfig/platform/ModernMinecraft.kt @@ -57,6 +57,11 @@ class ModernMinecraft : IMinecraft { } } + override val mouseX: Int + get() = TODO("Not yet implemented") + override val mouseY: Int + get() = TODO("Not yet implemented") + override fun loadResourceLocation(resourceLocation: MyResourceLocation): InputStream { return MinecraftClient.getInstance().resourceManager.getResource(fromMyResourceLocation(resourceLocation)) .get().inputStream @@ -66,4 +71,8 @@ class ModernMinecraft : IMinecraft { get() = ModernFontRenderer(MinecraftClient.getInstance().textRenderer) override val keyboardConstants: IKeyboardConstants get() = ModernKeyboardConstants + override val scaledWidth: Int + get() = TODO("Not yet implemented") + override val scaledHeight: Int + get() = TODO("Not yet implemented") } \ No newline at end of file