aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java24
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java17
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java12
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/client/MouseInputHandler.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java37
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/PressableWidgetAccessor.java15
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/SliderWidgetAccessor.java25
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java6
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java33
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java33
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java13
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java9
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java12
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.pngbin0 -> 3228 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.pngbin0 -> 2107 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.pngbin0 -> 3233 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_dark.png (renamed from src/main/resources/assets/libgui/textures/widget/panel_dark.png)bin1644 -> 1644 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_light.png (renamed from src/main/resources/assets/libgui/textures/widget/panel_light.png)bin650 -> 650 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_light.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.pngbin0 -> 748 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png.mcmeta15
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.pngbin0 -> 748 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png.mcmeta15
-rw-r--r--src/main/resources/assets/libgui/textures/widget/dark_widgets.pngbin5798 -> 0 bytes
-rw-r--r--src/main/resources/fabric.mod.json6
-rw-r--r--src/main/resources/mixins.libgui.json4
32 files changed, 248 insertions, 90 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java
index f3df523..52bd317 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java
@@ -10,6 +10,7 @@ import io.github.cottonmc.cotton.gui.widget.data.Texture;
import juuxel.libninepatch.NinePatch;
import juuxel.libninepatch.TextureRegion;
+import java.util.Objects;
import java.util.function.Consumer;
/**
@@ -31,8 +32,8 @@ public interface BackgroundPainter {
/**
* The {@code VANILLA} background painter draws a vanilla-like GUI panel using nine-patch textures.
*
- * <p>This background painter uses {@code libgui:textures/widget/panel_light.png} as the light texture and
- * {@code libgui:textures/widget/panel_dark.png} as the dark texture.
+ * <p>This background painter uses {@code libgui:textures/gui/sprites/widget/panel_light.png} as the light texture and
+ * {@code libgui:textures/gui/sprites/widget/panel_dark.png} as the dark texture.
*
* <p>This background painter is the default painter for root panels.
* * You can override {@link io.github.cottonmc.cotton.gui.GuiDescription#addPainters()} to customize the painter yourself.
@@ -40,8 +41,8 @@ public interface BackgroundPainter {
* @since 1.5.0
*/
public static BackgroundPainter VANILLA = createLightDarkVariants(
- createNinePatch(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/panel_light.png")),
- createNinePatch(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/panel_dark.png"))
+ createGuiSprite(new Identifier(LibGuiCommon.MOD_ID, "widget/panel_light")),
+ createGuiSprite(new Identifier(LibGuiCommon.MOD_ID, "widget/panel_dark"))
);
/**
@@ -158,4 +159,19 @@ public interface BackgroundPainter {
else light.paintBackground(context, left, top, panel);
};
}
+
+ /**
+ * Creates a background painter that uses a texture from the GUI atlas.
+ *
+ * <p>This method can be used to draw tiled or nine-slice GUI sprites from resource packs
+ * as a simpler and more data-driven alternative to {@link #createNinePatch(Identifier)}.
+ *
+ * @param texture the texture ID
+ * @return a new background painter that uses a GUI sprite
+ * @since 9.0.0
+ */
+ static BackgroundPainter createGuiSprite(Identifier texture) {
+ Objects.requireNonNull(texture, "Texture cannot be null");
+ return (context, left, top, panel) -> context.drawGuiTexture(texture, left, top, panel.getWidth(), panel.getHeight());
+ }
}
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 2b7bb0c..a0c04be 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
@@ -204,8 +204,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
new file mode 100644
index 0000000..437de7c
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_dark.png
Binary files differ
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
new file mode 100644
index 0000000..83e5146
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_disabled_dark.png
Binary files differ
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
new file mode 100644
index 0000000..59f0561
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/button_highlighted_dark.png
Binary files differ
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/widget/panel_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_dark.png
index c4e643f..c4e643f 100644
--- a/src/main/resources/assets/libgui/textures/widget/panel_dark.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_dark.png.mcmeta
new file mode 100644
index 0000000..0f75440
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_dark.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 4
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/panel_light.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_light.png
index 8bb50a8..8bb50a8 100644
--- a/src/main/resources/assets/libgui/textures/widget/panel_light.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_light.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_light.png.mcmeta
new file mode 100644
index 0000000..0f75440
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/panel_light.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 4
+ }
+ }
+}
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
new file mode 100644
index 0000000..f843714
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_dark.png
Binary files differ
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
new file mode 100644
index 0000000..dff8794
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/slider_handle_highlighted_dark.png
Binary files differ
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
deleted file mode 100644
index 8482d76..0000000
--- a/src/main/resources/assets/libgui/textures/widget/dark_widgets.png
+++ /dev/null
Binary files differ
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": {