diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 13:59:24 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 13:59:24 +0300 |
commit | 2a05170b93d9522cc9d54d954a783dd6a7f01c1c (patch) | |
tree | 397c08ae1fcb273502a16c4b21cb6dc7bf454cd6 | |
parent | 5c66af7bd411c7caa3f2e4cc4f754066fe37eae3 (diff) | |
download | LibGui-2a05170b93d9522cc9d54d954a783dd6a7f01c1c.tar.gz LibGui-2a05170b93d9522cc9d54d954a783dd6a7f01c1c.tar.bz2 LibGui-2a05170b93d9522cc9d54d954a783dd6a7f01c1c.zip |
Initial port to 1.20.2
30 files changed, 214 insertions, 91 deletions
diff --git a/CREDITS.txt b/CREDITS.txt index a8bfbd8..439466e 100644 --- a/CREDITS.txt +++ b/CREDITS.txt @@ -1 +1 @@ -- Dark-mode button textures (dark_widgets.png) are adapted from Roughly Enough Items by shedaniel, licensed under MIT +- Dark-mode button textures (button*_dark.png) are adapted from Roughly Enough Items by shedaniel, licensed under MIT diff --git a/gradle.properties b/gradle.properties index 949a79a..bea13b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20.1 - yarn_mappings=1.20.1+build.10 - loader_version=0.14.21 + minecraft_version=1.20.2-pre2 + yarn_mappings=1.20.2-pre2+build.3 + loader_version=0.14.22 # Mod Properties mod_version = 8.0.2 @@ -13,7 +13,7 @@ org.gradle.jvmargs=-Xmx1G archives_base_name = LibGui # Dependencies - fabric_version=0.86.1+1.20.1 + fabric_version=0.88.3+1.20.2 jankson_version=6.0.0+j1.2.3 modmenu_version=7.0.1 libninepatch_version=1.2.0 diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java index 877528c..071bb39 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -123,10 +123,13 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { } } - private void paint(DrawContext context, int mouseX, int mouseY) { - renderBackground(context); + private void paint(DrawContext context, int mouseX, int mouseY, float delta) { + renderBackground(context, mouseX, mouseY, delta); if (description!=null) { + context.getMatrices().push(); + context.getMatrices().translate(0f, 0f, 0.01f); + WPanel root = description.getRootPanel(); if (root!=null) { GL11.glEnable(GL11.GL_SCISSOR_TEST); @@ -140,12 +143,14 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { int width = description.getRootPanel().getWidth(); ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - 2 * titleX, description.getTitleColor()); } + + context.getMatrices().pop(); } } @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - paint(context, mouseX, mouseY); + paint(context, mouseX, mouseY, partialTicks); super.render(context, mouseX, mouseY, partialTicks); @@ -207,12 +212,12 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - super.mouseScrolled(mouseX, mouseY, amount); + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); int containerX = (int)mouseX-left; int containerY = (int)mouseY-top; - mouseInputHandler.onMouseScroll(containerX, containerY, amount); + mouseInputHandler.onMouseScroll(containerX, containerY, horizontalAmount, verticalAmount); return true; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java index b1ed4ce..3d807e0 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -223,12 +223,12 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - super.mouseScrolled(mouseX, mouseY, amount); + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); int containerX = (int)mouseX-x; int containerY = (int)mouseY-y; - mouseInputHandler.onMouseScroll(containerX, containerY, amount); + mouseInputHandler.onMouseScroll(containerX, containerY, horizontalAmount, verticalAmount); return true; } @@ -275,8 +275,8 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl @Override protected void drawBackground(DrawContext context, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. - private void paint(DrawContext context, int mouseX, int mouseY) { - renderBackground(context); + private void paint(DrawContext context, int mouseX, int mouseY, float delta) { + renderBackground(context, mouseX, mouseY, delta); if (description!=null) { WPanel root = description.getRootPanel(); @@ -292,7 +292,7 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - paint(context, mouseX, mouseY); + paint(context, mouseX, mouseY, partialTicks); super.render(context, mouseX, mouseY, partialTicks); DiffuseLighting.disableGuiDepthLighting(); //Needed because super.render leaves dirty state diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/MouseInputHandler.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/MouseInputHandler.java index 0814e16..15aa875 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/MouseInputHandler.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/MouseInputHandler.java @@ -85,10 +85,10 @@ public final class MouseInputHandler<S extends Screen & CottonScreenImpl> { } } - public void onMouseScroll(int containerX, int containerY, double amount) { + public void onMouseScroll(int containerX, int containerY, double horizontalAmount, double verticalAmount) { runTree( screen.getDescription().getRootPanel().hit(containerX, containerY), - widget -> widget.onMouseScroll(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), amount) + widget -> widget.onMouseScroll(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), horizontalAmount, verticalAmount) ); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java new file mode 100644 index 0000000..86a2630 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java @@ -0,0 +1,37 @@ +package io.github.cottonmc.cotton.gui.impl.client; + +import io.github.cottonmc.cotton.gui.impl.mixin.client.SliderWidgetAccessor; + +import net.minecraft.client.gui.screen.ButtonTextures; +import net.minecraft.util.Identifier; + +import io.github.cottonmc.cotton.gui.impl.LibGuiCommon; +import io.github.cottonmc.cotton.gui.impl.mixin.client.PressableWidgetAccessor; + +public final class WidgetTextures { + private static final ButtonTextures LIGHT_LABELED_SLIDER_HANDLE = new ButtonTextures( + SliderWidgetAccessor.libgui$getHandleTexture(), + SliderWidgetAccessor.libgui$getHandleHighlightedTexture() + ); + private static final ButtonTextures DARK_LABELED_SLIDER_HANDLE = new ButtonTextures( + id("widget/slider_handle_dark"), + id("widget/slider_handle_highlighted_dark") + ); + private static final ButtonTextures DARK_BUTTON = new ButtonTextures( + id("widget/button_dark"), + id("widget/button_disabled_dark"), + id("widget/button_highlighted_dark") + ); + + public static ButtonTextures getButtonTextures(boolean dark) { + return dark ? DARK_BUTTON : PressableWidgetAccessor.libgui$getTextures(); + } + + public static ButtonTextures getLabeledSliderHandleTextures(boolean dark) { + return dark ? DARK_LABELED_SLIDER_HANDLE : LIGHT_LABELED_SLIDER_HANDLE; + } + + private static Identifier id(String path) { + return new Identifier(LibGuiCommon.MOD_ID, path); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/PressableWidgetAccessor.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/PressableWidgetAccessor.java new file mode 100644 index 0000000..b984af1 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/PressableWidgetAccessor.java @@ -0,0 +1,15 @@ +package io.github.cottonmc.cotton.gui.impl.mixin.client; + +import net.minecraft.client.gui.screen.ButtonTextures; +import net.minecraft.client.gui.widget.PressableWidget; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(PressableWidget.class) +public interface PressableWidgetAccessor { + @Accessor("TEXTURES") + static ButtonTextures libgui$getTextures() { + throw new AssertionError(); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/SliderWidgetAccessor.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/SliderWidgetAccessor.java new file mode 100644 index 0000000..ce9ea1a --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/SliderWidgetAccessor.java @@ -0,0 +1,25 @@ +package io.github.cottonmc.cotton.gui.impl.mixin.client; + +import net.minecraft.client.gui.widget.SliderWidget; +import net.minecraft.util.Identifier; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(SliderWidget.class) +public interface SliderWidgetAccessor { + @Accessor("TEXTURE") + static Identifier libgui$getTexture() { + throw new AssertionError(); + } + + @Accessor("HANDLE_TEXTURE") + static Identifier libgui$getHandleTexture() { + throw new AssertionError(); + } + + @Accessor("HANDLE_HIGHLIGHTED_TEXTURE") + static Identifier libgui$getHandleHighlightedTexture() { + throw new AssertionError(); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java index 945c121..3621233 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java @@ -183,13 +183,13 @@ public abstract class WAbstractSlider extends WWidget { @Environment(EnvType.CLIENT) @Override - public InputResult onMouseScroll(int x, int y, double amount) { + public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) { if (direction == Direction.LEFT || direction == Direction.DOWN) { - amount = -amount; + verticalAmount = -verticalAmount; } int previous = value; - value = MathHelper.clamp(value + (int) Math.signum(amount) * MathHelper.ceil(valueToCoordRatio * Math.abs(amount) * 2), min, max); + value = MathHelper.clamp(value + (int) Math.signum(verticalAmount) * MathHelper.ceil(valueToCoordRatio * Math.abs(verticalAmount) * 2), min, max); if (previous != value) { onValueChanged(value); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java index 1230905..5367483 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java @@ -4,23 +4,23 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ButtonTextures; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; -import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.impl.client.NarrationMessages; +import io.github.cottonmc.cotton.gui.impl.client.WidgetTextures; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; import io.github.cottonmc.cotton.gui.widget.data.InputResult; import io.github.cottonmc.cotton.gui.widget.icon.Icon; import org.jetbrains.annotations.Nullable; public class WButton extends WWidget { - private static final Identifier DARK_WIDGETS_LOCATION = new Identifier("libgui", "textures/widget/dark_widgets.png"); private static final int BUTTON_HEIGHT = 20; private static final int ICON_SPACING = 2; @@ -89,27 +89,9 @@ public class WButton extends WWidget { @Environment(EnvType.CLIENT) @Override public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { - boolean hovered = (mouseX>=0 && mouseY>=0 && mouseX<getWidth() && mouseY<getHeight()); - int state = 1; //1=regular. 2=hovered. 0=disabled. - if (!enabled) { - state = 0; - } else if (hovered || isFocused()) { - state = 2; - } - - float px = 1/256f; - float buttonLeft = 0 * px; - float buttonTop = (46 + (state*20)) * px; - int halfWidth = getWidth()/2; - if (halfWidth>198) halfWidth=198; - float buttonWidth = halfWidth*px; - float buttonHeight = 20*px; - - float buttonEndLeft = (200-(getWidth()/2)) * px; - - Identifier texture = getTexture(this); - ScreenDrawing.texturedRect(context, x, y, getWidth()/2, 20, texture, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF); - ScreenDrawing.texturedRect(context, x+(getWidth()/2), y, getWidth()/2, 20, texture, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF); + boolean hovered = isWithinBounds(mouseX, mouseY); + ButtonTextures textures = WidgetTextures.getButtonTextures(shouldRenderInDarkMode()); + context.drawGuiTexture(textures.get(enabled, hovered || isFocused()), x, y, getWidth(), getHeight()); if (icon != null) { icon.paint(context, x+ICON_SPACING, y+(BUTTON_HEIGHT-iconSize)/2, iconSize); @@ -266,9 +248,4 @@ public class WButton extends WWidget { } } } - - @Environment(EnvType.CLIENT) - static Identifier getTexture(WWidget widget) { - return widget.shouldRenderInDarkMode() ? DARK_WIDGETS_LOCATION : ClickableWidget.WIDGETS_TEXTURE; - } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java index d8cca29..467a634 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java @@ -1,5 +1,8 @@ package io.github.cottonmc.cotton.gui.widget; +import io.github.cottonmc.cotton.gui.impl.client.WidgetTextures; +import io.github.cottonmc.cotton.gui.impl.mixin.client.SliderWidgetAccessor; + import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.DrawContext; @@ -175,22 +178,17 @@ public class WLabeledSlider extends WAbstractSlider { matrices.translate(0, height, 0); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(270)); } - drawButton(context, 0, 0, 0, aWidth); + context.drawGuiTexture(SliderWidgetAccessor.libgui$getTexture(), 0, 0, aWidth, aHeight); - // 1: regular, 2: hovered, 0: disabled/dragging int thumbX = Math.round(coordToValueRatio * (value - min)); int thumbY = 0; int thumbWidth = getThumbWidth(); int thumbHeight = aHeight; boolean hovering = rotMouseX >= thumbX && rotMouseX <= thumbX + thumbWidth && rotMouseY >= thumbY && rotMouseY <= thumbY + thumbHeight; - int thumbState = dragging || hovering ? 2 : 1; - - drawButton(context, thumbX, thumbY, thumbState, thumbWidth); - if (thumbState == 1 && isFocused()) { - float px = 1 / 32f; - ScreenDrawing.texturedRect(context, thumbX, thumbY, thumbWidth, thumbHeight, WSlider.LIGHT_TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); - } + var thumbTextures = WidgetTextures.getLabeledSliderHandleTextures(shouldRenderInDarkMode()); + var thumbTexture = thumbTextures.get(true, dragging || hovering); + context.drawGuiTexture(thumbTexture, thumbX, thumbY, thumbWidth, thumbHeight); if (label != null) { int color = isMouseInsideBounds(mouseX, mouseY) ? 0xFFFFA0 : 0xE0E0E0; @@ -199,23 +197,6 @@ public class WLabeledSlider extends WAbstractSlider { matrices.pop(); } - // state = 1: regular, 2: hovered, 0: disabled/dragging - @Environment(EnvType.CLIENT) - private void drawButton(DrawContext context, int x, int y, int state, int width) { - float px = 1 / 256f; - float buttonLeft = 0 * px; - float buttonTop = (46 + (state * 20)) * px; - int halfWidth = width / 2; - if (halfWidth > 198) halfWidth = 198; - float buttonWidth = halfWidth * px; - float buttonHeight = 20 * px; - float buttonEndLeft = (200 - halfWidth) * px; - - Identifier texture = WButton.getTexture(this); - ScreenDrawing.texturedRect(context, x, y, halfWidth, 20, texture, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF); - ScreenDrawing.texturedRect(context, x + halfWidth, y, halfWidth, 20, texture, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); - } - @Environment(EnvType.CLIENT) @Override public void addNarrations(NarrationMessageBuilder builder) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index 06db362..9b0bc58 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java @@ -226,8 +226,8 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { } @Override - public InputResult onMouseScroll(int x, int y, double amount) { - return scrollBar.onMouseScroll(0, 0, amount); + public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) { + return scrollBar.onMouseScroll(0, 0, horizontalAmount, verticalAmount); } /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index 0846d68..0c1af59 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -228,8 +228,8 @@ public class WScrollBar extends WWidget { @Environment(EnvType.CLIENT) @Override - public InputResult onMouseScroll(int x, int y, double amount) { - setValue(getValue() + (int) -amount * SCROLLING_SPEED); + public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) { + setValue(getValue() + (int) (horizontalAmount - verticalAmount) * SCROLLING_SPEED); return InputResult.PROCESSED; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java index facac1b..620adc8 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java @@ -143,12 +143,19 @@ public class WScrollPanel extends WClippedPanel { } @Override - public InputResult onMouseScroll(int x, int y, double amount) { + public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) { + var horizontalResult = InputResult.IGNORED; + var verticalResult = InputResult.IGNORED; + + if (hasHorizontalScrollbar()) { + horizontalResult = horizontalScrollBar.onMouseScroll(x, y, horizontalAmount, 0); + } + if (hasVerticalScrollbar()) { - return verticalScrollBar.onMouseScroll(0, 0, amount); + verticalResult = verticalScrollBar.onMouseScroll(0, 0, 0, verticalAmount); } - return InputResult.IGNORED; + return horizontalResult.or(verticalResult); } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index 1486928..e8c3908 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -212,13 +212,14 @@ public class WWidget { /** * Notifies this widget that the mouse has been scrolled inside its bounds. * - * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) - * @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget) - * @param amount The scrolled amount. Positive values are up and negative values are down. + * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) + * @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget) + * @param horizontalAmount The scrolled horizontal amount. Positive values are right and negative values are left. + * @param verticalAmount The scrolled vertical amount. Positive values are up and negative values are down. * @return {@link InputResult#PROCESSED} if the event is handled, {@link InputResult#IGNORED} otherwise. */ @Environment(EnvType.CLIENT) - public InputResult onMouseScroll(int x, int y, double amount) { + public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) { return InputResult.IGNORED; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java index 4fed438..479977e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java @@ -11,6 +11,18 @@ public enum InputResult { IGNORED; /** + * Combines this input result with another. + * The combination is {@link #PROCESSED} is at least one of the inputs is. + * + * @param other the other input result + * @return the combined input result + * @since 9.0.0 + */ + public InputResult or(InputResult other) { + return this == IGNORED && other == IGNORED ? IGNORED : PROCESSED; + } + + /** * Gets the corresponding input result for a {@code processed} boolean. * * @param processed whether an input event was processed diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png Binary files differnew file mode 100644 index 0000000..437de7c --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png.mcmeta new file mode 100644 index 0000000..bcf5fc2 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png.mcmeta @@ -0,0 +1,10 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 200, + "height": 20, + "border": 3 + } + } +} diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png Binary files differnew file mode 100644 index 0000000..83e5146 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png.mcmeta new file mode 100644 index 0000000..bcf5fc2 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png.mcmeta @@ -0,0 +1,10 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 200, + "height": 20, + "border": 3 + } + } +} diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png Binary files differnew file mode 100644 index 0000000..59f0561 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png.mcmeta new file mode 100644 index 0000000..bcf5fc2 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png.mcmeta @@ -0,0 +1,10 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 200, + "height": 20, + "border": 3 + } + } +} diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png Binary files differnew file mode 100644 index 0000000..f843714 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png.mcmeta new file mode 100644 index 0000000..dab004a --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png.mcmeta @@ -0,0 +1,15 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 8, + "height": 20, + "border": { + "left": 2, + "top": 2, + "right": 2, + "bottom": 3 + } + } + } +} diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png Binary files differnew file mode 100644 index 0000000..dff8794 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png.mcmeta new file mode 100644 index 0000000..dab004a --- /dev/null +++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png.mcmeta @@ -0,0 +1,15 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 8, + "height": 20, + "border": { + "left": 2, + "top": 2, + "right": 2, + "bottom": 3 + } + } + } +} diff --git a/src/main/resources/assets/libgui/textures/widget/dark_widgets.png b/src/main/resources/assets/libgui/textures/widget/dark_widgets.png Binary files differdeleted file mode 100644 index 8482d76..0000000 --- a/src/main/resources/assets/libgui/textures/widget/dark_widgets.png +++ /dev/null diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9a59c86..bbd2386 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -25,12 +25,12 @@ "mixins": ["mixins.libgui.json"], "depends": { "java": ">=17", - "fabricloader": ">=0.14.21", + "fabricloader": ">=0.14.22", "fabric-api-base": ">=0.4.4", "fabric-lifecycle-events-v1": "^2.0.2", - "fabric-networking-api-v1": "^1.0.21", + "fabric-networking-api-v1": "^3.0.5", "fabric-rendering-v1": "^3.0.6", - "minecraft": ">=1.20-rc.1", + "minecraft": ">=1.20.2-beta.2", "jankson": "^6.0.0", "libninepatch": "^1.2.0" }, diff --git a/src/main/resources/mixins.libgui.json b/src/main/resources/mixins.libgui.json index 6698d08..d72e129 100644 --- a/src/main/resources/mixins.libgui.json +++ b/src/main/resources/mixins.libgui.json @@ -7,7 +7,9 @@ "client": [ "client.MinecraftClientMixin", - "client.ScreenAccessor" + "client.PressableWidgetAccessor", + "client.ScreenAccessor", + "client.SliderWidgetAccessor" ], "injectors": { diff --git a/src/testMod/java/io/github/cottonmc/test/client/DarkModeTestGui.java b/src/testMod/java/io/github/cottonmc/test/client/DarkModeTestGui.java index 2caea5c..f9012d7 100644 --- a/src/testMod/java/io/github/cottonmc/test/client/DarkModeTestGui.java +++ b/src/testMod/java/io/github/cottonmc/test/client/DarkModeTestGui.java @@ -28,6 +28,7 @@ public final class DarkModeTestGui extends LightweightGuiDescription { root.add(new WButton(Text.literal("Button B")), 0, 1, 3, 1); root.add(new WText(Text.literal("Text")), 0, 2, 3, 1); root.add(new WLabeledSlider(1, 100, Text.literal("Slider A")), 3, 0, 3, 1); + root.add(new WLabeledSlider(1, 100, Axis.VERTICAL, Text.literal("Slider B")), 6, 0, 1, 3); root.add(new WSlider(1, 100, Axis.HORIZONTAL), 3, 1, 3, 1); root.add(new WLabel(Text.literal("Label")), 3, 2, 3, 1); root.add(new WScrollBar(Axis.HORIZONTAL), 0, 3, 3, 1); |