diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2022-09-12 02:14:25 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2022-09-12 02:14:25 +0300 |
commit | 5759ee8ab8e43190ea2a688b5293d0f013ded1d0 (patch) | |
tree | ea9effddf4d229afa18f43a2bcc80c943c4d33b8 /src/main/java | |
parent | b8f57dd89cc36eaa62751546d10aade7fde7c977 (diff) | |
download | LibGui-5759ee8ab8e43190ea2a688b5293d0f013ded1d0.tar.gz LibGui-5759ee8ab8e43190ea2a688b5293d0f013ded1d0.tar.bz2 LibGui-5759ee8ab8e43190ea2a688b5293d0f013ded1d0.zip |
Make item slots paint a texture instead of coloured rectangles
Closes #128.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java | 35 | ||||
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java | 12 |
2 files changed, 27 insertions, 20 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 36c6c3a..654442c 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 @@ -44,6 +44,8 @@ public interface BackgroundPainter { /** * The {@code SLOT} background painter draws item slots or slot-like widgets. + * + * <p>For {@linkplain WItemSlot item slots}, this painter uses {@link WItemSlot#SLOT_TEXTURE libgui:textures/widget/item_slot.png}. */ public static BackgroundPainter SLOT = (matrices, left, top, panel) -> { if (!(panel instanceof WItemSlot)) { @@ -53,31 +55,24 @@ public interface BackgroundPainter { for(int x = 0; x < slot.getWidth()/18; ++x) { for(int y = 0; y < slot.getHeight()/18; ++y) { int index = x + y * (slot.getWidth() / 18); - int lo = 0xB8000000; - int bg = 0x4C000000; - //this will cause a slightly discolored bottom border on vanilla backgrounds but it's necessary for color support, it shouldn't be *too* visible unless you're looking for it - int hi = 0xB8FFFFFF; + float px = 1 / 64f; if (slot.isBigSlot()) { - ScreenDrawing.drawBeveledPanel(matrices, (x * 18) + left - 4, (y * 18) + top - 4, 26, 26, - lo, bg, hi); + int sx = (x * 18) + left - 4; + int sy = (y * 18) + top - 4; + ScreenDrawing.texturedRect(matrices, sx, sy, 26, 26, WItemSlot.SLOT_TEXTURE, + 18 * px, 0, 44 * px, 26 * px, 0xFF_FFFFFF); if (slot.getFocusedSlot() == index) { - int sx = (x * 18) + left - 4; - int sy = (y * 18) + top - 4; - ScreenDrawing.coloredRect(matrices, sx, sy, 26, 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(matrices, sx, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(matrices, sx + 26 - 1, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(matrices, sx + 1, sy + 26 - 1, 26 - 1, 1, 0xFF_FFFFA0); + ScreenDrawing.texturedRect(matrices, sx, sy, 26, 26, WItemSlot.SLOT_TEXTURE, + 18 * px, 26 * px, 44 * px, 52 * px, 0xFF_FFFFFF); } } else { - ScreenDrawing.drawBeveledPanel(matrices, (x * 18) + left, (y * 18) + top, 16+2, 16+2, - lo, bg, hi); + int sx = (x * 18) + left; + int sy = (y * 18) + top; + ScreenDrawing.texturedRect(matrices, sx, sy, 18, 18, WItemSlot.SLOT_TEXTURE, + 0, 0, 18 * px, 18 * px, 0xFF_FFFFFF); if (slot.getFocusedSlot() == index) { - int sx = (x * 18) + left; - int sy = (y * 18) + top; - ScreenDrawing.coloredRect(matrices, sx, sy, 18, 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(matrices, sx, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(matrices, sx + 18 - 1, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(matrices, sx + 1, sy + 18 - 1, 18 - 1, 1, 0xFF_FFFFA0); + ScreenDrawing.texturedRect(matrices, sx, sy, 18, 18, WItemSlot.SLOT_TEXTURE, + 0, 26 * px, 18 * px, 44 * px, 0xFF_FFFFFF); } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java index fd94100..0ec0869 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; +import io.github.cottonmc.cotton.gui.impl.LibGuiCommon; + import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -20,6 +22,9 @@ import io.github.cottonmc.cotton.gui.impl.VisualLogger; import io.github.cottonmc.cotton.gui.impl.client.NarrationMessages; import io.github.cottonmc.cotton.gui.widget.data.InputResult; import io.github.cottonmc.cotton.gui.widget.icon.Icon; + +import net.minecraft.util.Identifier; + import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -65,6 +70,13 @@ import java.util.function.Predicate; * </pre> */ public class WItemSlot extends WWidget { + /** + * The default texture of item slots and {@link BackgroundPainter#SLOT}. + * + * @since 6.2.0 + */ + public static final Identifier SLOT_TEXTURE = new Identifier(LibGuiCommon.MOD_ID, "textures/widget/item_slot.png"); + private static final VisualLogger LOGGER = new VisualLogger(WItemSlot.class); private final List<ValidatedSlot> peers = new ArrayList<>(); @Nullable |