From ab75b7dafdcd147905f3d87c1e9c995aef39027c Mon Sep 17 00:00:00 2001 From: Falkreon Date: Fri, 30 Aug 2019 09:58:20 -0500 Subject: Update to 19w35a, rearrange ScreenDrawing, rename screens --- .../cotton/gui/client/ClientCottonScreen.java | 188 ----------------- .../cotton/gui/client/CottonClientScreen.java | 187 +++++++++++++++++ .../cotton/gui/client/CottonInventoryScreen.java | 224 +++++++++++++++++++++ .../cottonmc/cotton/gui/client/CottonScreen.java | 224 --------------------- .../cottonmc/cotton/gui/client/ScreenDrawing.java | 106 +++++----- .../cotton/gui/client/modmenu/ModMenuSupport.java | 4 +- .../cotton/gui/client/modmenu/WKirbSprite.java | 2 +- .../io/github/cottonmc/cotton/gui/widget/WBar.java | 20 +- .../github/cottonmc/cotton/gui/widget/WButton.java | 4 +- .../cottonmc/cotton/gui/widget/WLabeledSlider.java | 6 +- .../cottonmc/cotton/gui/widget/WScrollBar.java | 4 +- .../github/cottonmc/cotton/gui/widget/WSlider.java | 16 +- .../github/cottonmc/cotton/gui/widget/WSprite.java | 4 +- .../cottonmc/cotton/gui/widget/WTextField.java | 22 +- .../cottonmc/cotton/gui/widget/WToggleButton.java | 2 +- 15 files changed, 506 insertions(+), 507 deletions(-) delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/CottonScreen.java (limited to 'src/main/java') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java deleted file mode 100644 index 16921cf..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java +++ /dev/null @@ -1,188 +0,0 @@ -package io.github.cottonmc.cotton.gui.client; - -import io.github.cottonmc.cotton.gui.GuiDescription; -import io.github.cottonmc.cotton.gui.widget.WPanel; -import io.github.cottonmc.cotton.gui.widget.WWidget; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -public class ClientCottonScreen extends Screen { - protected GuiDescription description; - protected int left = 0; - protected int top = 0; - protected int containerWidth = 0; - protected int containerHeight = 0; - - protected WWidget lastResponder = null; - - public ClientCottonScreen(GuiDescription description) { - super(new LiteralText("")); - this.description = description; - } - - public ClientCottonScreen(Text title, GuiDescription description) { - super(title); - this.description = description; - } - - public GuiDescription getDescription() { - return description; - } - - - @Override - public void init(MinecraftClient client, int screenWidth, int screenHeight) { - - super.init(client, screenWidth, screenHeight); - - description.addPainters(); - reposition(screenWidth, screenHeight); - } - - public void reposition(int screenWidth, int screenHeight) { - if (description!=null) { - WPanel root = description.getRootPanel(); - if (root!=null) { - this.containerWidth = root.getWidth(); - this.containerHeight = root.getHeight(); - - this.left = (screenWidth - root.getWidth()) / 2; - this.top = (screenHeight - root.getHeight()) / 2; - } - } - } - - @Override - public void render(int mouseX, int mouseY, float partialTicks) { - renderBackground(mouseX, mouseY); - - super.render(mouseX, mouseY, partialTicks); - - if (description!=null) { - WPanel root = description.getRootPanel(); - if (root!=null) { - root.paintForeground(left, top, mouseX, mouseY); - } - } - } - - public void renderBackground(int mouseX, int mouseY) { - super.renderBackground(); - - if (description!=null) { - WPanel root = description.getRootPanel(); - if (root!=null) { - root.paintBackground(left, top, mouseX-left, mouseY-top); - } - } - - if (getTitle() != null) { - font.draw(getTitle().asFormattedString(), left, top, description.getTitleColor()); - } - } - - - @Override - public void tick() { - super.tick(); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { - if (description.getRootPanel()==null) return super.mouseClicked(mouseX, mouseY, mouseButton); - WWidget focus = description.getFocus(); - if (focus!=null) { - - int wx = focus.getAbsoluteX(); - int wy = focus.getAbsoluteY(); - - if (mouseX>=wx && mouseX=wy && mouseY=width || containerY>=height) return result; - if (lastResponder==null) { - lastResponder = description.getRootPanel().hit(containerX, containerY); - if (lastResponder!=null) lastResponder.onMouseDown(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); - } else { - //This is a drag instead - } - return result; - - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { - if (description.getRootPanel()==null) return super.mouseReleased(mouseX, mouseY, mouseButton); - boolean result = super.mouseReleased(mouseX, mouseY, mouseButton); - int containerX = (int)mouseX-left; - int containerY = (int)mouseY-top; - - if (lastResponder!=null) { - lastResponder.onMouseUp(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); - if (containerX>=0 && containerY>=0 && containerX=width || containerY>=height) return result; - description.getRootPanel().onMouseDrag(containerX, containerY, mouseButton); - } - return result; - } - - @Override - public boolean charTyped(char ch, int keyCode) { - if (description.getFocus()==null) return false; - description.getFocus().onCharTyped(ch); - return true; - } - - @Override - public boolean keyPressed(int ch, int keyCode, int modifiers) { - if (super.keyPressed(ch, keyCode, modifiers)) return true; - if (description.getFocus()==null) return false; - description.getFocus().onKeyPressed(ch, keyCode, modifiers); - return true; - } - - @Override - public boolean keyReleased(int ch, int keyCode, int modifiers) { - if (description.getFocus()==null) return false; - description.getFocus().onKeyReleased(ch, keyCode, modifiers); - return true; - } - - //@Override - //public Element getFocused() { - //return this; - //} -} 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 new file mode 100644 index 0000000..a1b95fa --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -0,0 +1,187 @@ +package io.github.cottonmc.cotton.gui.client; + +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.widget.WPanel; +import io.github.cottonmc.cotton.gui.widget.WWidget; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; + +public class CottonClientScreen extends Screen { + protected GuiDescription description; + protected int left = 0; + protected int top = 0; + protected int containerWidth = 0; + protected int containerHeight = 0; + + protected WWidget lastResponder = null; + + public CottonClientScreen(GuiDescription description) { + super(new LiteralText("")); + this.description = description; + } + + public CottonClientScreen(Text title, GuiDescription description) { + super(title); + this.description = description; + } + + public GuiDescription getDescription() { + return description; + } + + + @Override + public void init(MinecraftClient client, int screenWidth, int screenHeight) { + + super.init(client, screenWidth, screenHeight); + + description.addPainters(); + reposition(screenWidth, screenHeight); + } + + public void reposition(int screenWidth, int screenHeight) { + if (description!=null) { + WPanel root = description.getRootPanel(); + if (root!=null) { + this.containerWidth = root.getWidth(); + this.containerHeight = root.getHeight(); + + this.left = (screenWidth - root.getWidth()) / 2; + this.top = (screenHeight - root.getHeight()) / 2; + } + } + } + + @Override + public void render(int mouseX, int mouseY, float partialTicks) { + renderBackground(mouseX, mouseY); + + super.render(mouseX, mouseY, partialTicks); + + if (description!=null) { + WPanel root = description.getRootPanel(); + if (root!=null) { + root.paintForeground(left, top, mouseX, mouseY); + } + } + } + + public void renderBackground(int mouseX, int mouseY) { + super.renderBackground(); + + if (description!=null) { + WPanel root = description.getRootPanel(); + if (root!=null) { + root.paintBackground(left, top, mouseX-left, mouseY-top); + } + } + + if (getTitle() != null) { + font.draw(getTitle().asFormattedString(), left, top, description.getTitleColor()); + } + } + + + @Override + public void tick() { + super.tick(); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { + if (description.getRootPanel()==null) return super.mouseClicked(mouseX, mouseY, mouseButton); + WWidget focus = description.getFocus(); + if (focus!=null) { + + int wx = focus.getAbsoluteX(); + int wy = focus.getAbsoluteY(); + + if (mouseX>=wx && mouseX=wy && mouseY=width || containerY>=height) return result; + if (lastResponder==null) { + lastResponder = description.getRootPanel().hit(containerX, containerY); + if (lastResponder!=null) lastResponder.onMouseDown(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); + } else { + //This is a drag instead + } + return result; + + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { + if (description.getRootPanel()==null) return super.mouseReleased(mouseX, mouseY, mouseButton); + boolean result = super.mouseReleased(mouseX, mouseY, mouseButton); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + if (lastResponder!=null) { + lastResponder.onMouseUp(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); + if (containerX>=0 && containerY>=0 && containerX=width || containerY>=height) return result; + description.getRootPanel().onMouseDrag(containerX, containerY, mouseButton); + } + return result; + } + + @Override + public boolean charTyped(char ch, int keyCode) { + if (description.getFocus()==null) return false; + description.getFocus().onCharTyped(ch); + return true; + } + + @Override + public boolean keyPressed(int ch, int keyCode, int modifiers) { + if (super.keyPressed(ch, keyCode, modifiers)) return true; + if (description.getFocus()==null) return false; + description.getFocus().onKeyPressed(ch, keyCode, modifiers); + return true; + } + + @Override + public boolean keyReleased(int ch, int keyCode, int modifiers) { + if (description.getFocus()==null) return false; + description.getFocus().onKeyReleased(ch, keyCode, modifiers); + return true; + } + + //@Override + //public Element getFocused() { + //return this; + //} +} 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 new file mode 100644 index 0000000..0be2ecd --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -0,0 +1,224 @@ +package io.github.cottonmc.cotton.gui.client; + +import io.github.cottonmc.cotton.gui.CottonScreenController; +import io.github.cottonmc.cotton.gui.widget.WPanel; +import io.github.cottonmc.cotton.gui.widget.WWidget; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Nameable; + +public class CottonInventoryScreen extends AbstractContainerScreen { + protected CottonScreenController container; + public static final int PADDING = 8; + protected WWidget lastResponder = null; + protected WWidget focus = null; + + public CottonInventoryScreen(T container, PlayerEntity player) { + super(container, player.inventory, new LiteralText("")); + this.container = container; + width = 18*9; + height = 18*9; + this.containerWidth = 18*9; + this.containerHeight = 18*9; + } + + /* + * RENDERING NOTES: + * + * * "width" and "height" are the width and height of the overall screen + * * "containerWidth" and "containerHeight" are the width and height of the panel to render + * * "left" and "top" are *actually* self-explanatory + * * coordinates start at 0,0 at the topleft of the screen. + */ + + @Override + public void init(MinecraftClient minecraftClient_1, int screenWidth, int screenHeight) { + super.init(minecraftClient_1, screenWidth, screenHeight); + + container.addPainters(); + + reposition(); + } + + public void reposition() { + WPanel basePanel = container.getRootPanel(); + if (basePanel!=null) { + basePanel.validate(container); + + containerWidth = basePanel.getWidth(); + containerHeight = basePanel.getHeight(); + + //DEBUG + if (containerWidth<16) containerWidth=300; + if (containerHeight<16) containerHeight=300; + //if (left<0 || left>300) left = 10; + //if (top<0 || top>300) top = 10; + } + left = (width / 2) - (containerWidth / 2); + top = (height / 2) - (containerHeight / 2); + } + + @Override + public void onClose() { + super.onClose(); + } + + @Override + public boolean isPauseScreen() { + //...yeah, we're going to go ahead and override that. + return false; + } + + @Override + public boolean charTyped(char ch, int keyCode) { + if (container.getFocus()==null) return false; + container.getFocus().onCharTyped(ch); + return true; + } + + @Override + public boolean keyPressed(int ch, int keyCode, int modifiers) { + if (super.keyPressed(ch, keyCode, modifiers)) return true; + if (container.getFocus()==null) return false; + container.getFocus().onKeyPressed(ch, keyCode, modifiers); + return true; + } + + @Override + public boolean keyReleased(int ch, int keyCode, int modifiers) { + if (container.getFocus()==null) return false; + container.getFocus().onKeyReleased(ch, keyCode, modifiers); + return true; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { + boolean result = super.mouseClicked(mouseX, mouseY, mouseButton); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + if (containerX<0 || containerY<0 || containerX>=width || containerY>=height) return result; + if (lastResponder==null) { + lastResponder = container.doMouseDown(containerX, containerY, mouseButton); + } else { + //This is a drag instead + } + return result; + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { //Testing shows that STATE IS ACTUALLY BUTTON + boolean result = super.mouseReleased(mouseX, mouseY, mouseButton); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + if (lastResponder!=null) { + lastResponder.onMouseUp(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); + if (containerX>=0 && containerY>=0 && containerX=width || containerY>=height) return result; + container.doMouseDrag(containerX, containerY, mouseButton); + } + return result; + } + + //Zapping this method may fix some positioning bugs - but may cause some backgroundPainter bugs. Will need to monitor. + /* + @Override + public void resize(MinecraftClient minecraftClient_1, int int_1, int int_2) { + //super.onScaleChanged(minecraftClient_1, int_1, int_2); + this.width = int_1; + this.height = int_2; + reposition(); + }*/ + + /* + * SPECIAL FUNCTIONS: Where possible, we want to draw everything based on *actual GUI state and composition* rather + * than relying on pre-baked textures that the programmer then needs to carefully match up their GUI to. + */ + + private int multiplyColor(int color, float amount) { + int a = color & 0xFF000000; + float r = (color >> 16 & 255) / 255.0F; + float g = (color >> 8 & 255) / 255.0F; + float b = (color & 255) / 255.0F; + + r = Math.min(r*amount, 1.0f); + g = Math.min(g*amount, 1.0f); + b = Math.min(b*amount, 1.0f); + + int ir = (int)(r*255); + int ig = (int)(g*255); + int ib = (int)(b*255); + + return a | + (ir << 16) | + (ig << 8) | + ib; + } + + @Override + protected void drawBackground(float partialTicks, int mouseX, int mouseY) { + if (this.container==null) { + return; + } + WPanel root = this.container.getRootPanel(); + if (root==null) return; + + root.paintBackground(left, top, mouseX-left, mouseY-top); + + //TODO: Change this to a label that lives in the rootPanel instead? + if (container instanceof Nameable) { + Text name = ((Nameable)container).getDisplayName(); + font.draw(name.asFormattedString(), left, top, container.getTitleColor()); + } else if (getTitle() != null) { + font.draw(getTitle().asFormattedString(), left, top, container.getTitleColor()); + } + } + + @Override + protected void drawForeground(int mouseX, int mouseY) { + if (this.container==null) { + System.out.println("CONTAINER IS NULL."); + return; + } + + if (this.container.getRootPanel()!=null) { + this.container.getRootPanel().paintForeground(0, 0, mouseX-left, mouseY-top); + } + } + + @Override + public void render(int mouseX, int mouseY, float partialTicks) { + // Render the background shadow + this.renderBackground(); + + this.drawBackground(partialTicks, mouseX, mouseY); + + super.render(mouseX, mouseY, partialTicks); + drawMouseoverTooltip(mouseX, mouseY); + } + +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonScreen.java deleted file mode 100644 index bb9f665..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonScreen.java +++ /dev/null @@ -1,224 +0,0 @@ -package io.github.cottonmc.cotton.gui.client; - -import io.github.cottonmc.cotton.gui.CottonScreenController; -import io.github.cottonmc.cotton.gui.widget.WPanel; -import io.github.cottonmc.cotton.gui.widget.WWidget; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Nameable; - -public class CottonScreen extends AbstractContainerScreen { - protected CottonScreenController container; - public static final int PADDING = 8; - protected WWidget lastResponder = null; - protected WWidget focus = null; - - public CottonScreen(T container, PlayerEntity player) { - super(container, player.inventory, new LiteralText("")); - this.container = container; - width = 18*9; - height = 18*9; - this.containerWidth = 18*9; - this.containerHeight = 18*9; - } - - /* - * RENDERING NOTES: - * - * * "width" and "height" are the width and height of the overall screen - * * "containerWidth" and "containerHeight" are the width and height of the panel to render - * * "left" and "top" are *actually* self-explanatory - * * coordinates start at 0,0 at the topleft of the screen. - */ - - @Override - public void init(MinecraftClient minecraftClient_1, int screenWidth, int screenHeight) { - super.init(minecraftClient_1, screenWidth, screenHeight); - - container.addPainters(); - - reposition(); - } - - public void reposition() { - WPanel basePanel = container.getRootPanel(); - if (basePanel!=null) { - basePanel.validate(container); - - containerWidth = basePanel.getWidth(); - containerHeight = basePanel.getHeight(); - - //DEBUG - if (containerWidth<16) containerWidth=300; - if (containerHeight<16) containerHeight=300; - //if (left<0 || left>300) left = 10; - //if (top<0 || top>300) top = 10; - } - left = (width / 2) - (containerWidth / 2); - top = (height / 2) - (containerHeight / 2); - } - - @Override - public void onClose() { - super.onClose(); - } - - @Override - public boolean isPauseScreen() { - //...yeah, we're going to go ahead and override that. - return false; - } - - @Override - public boolean charTyped(char ch, int keyCode) { - if (container.getFocus()==null) return false; - container.getFocus().onCharTyped(ch); - return true; - } - - @Override - public boolean keyPressed(int ch, int keyCode, int modifiers) { - if (super.keyPressed(ch, keyCode, modifiers)) return true; - if (container.getFocus()==null) return false; - container.getFocus().onKeyPressed(ch, keyCode, modifiers); - return true; - } - - @Override - public boolean keyReleased(int ch, int keyCode, int modifiers) { - if (container.getFocus()==null) return false; - container.getFocus().onKeyReleased(ch, keyCode, modifiers); - return true; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { - boolean result = super.mouseClicked(mouseX, mouseY, mouseButton); - int containerX = (int)mouseX-left; - int containerY = (int)mouseY-top; - if (containerX<0 || containerY<0 || containerX>=width || containerY>=height) return result; - if (lastResponder==null) { - lastResponder = container.doMouseDown(containerX, containerY, mouseButton); - } else { - //This is a drag instead - } - return result; - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { //Testing shows that STATE IS ACTUALLY BUTTON - boolean result = super.mouseReleased(mouseX, mouseY, mouseButton); - int containerX = (int)mouseX-left; - int containerY = (int)mouseY-top; - - if (lastResponder!=null) { - lastResponder.onMouseUp(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); - if (containerX>=0 && containerY>=0 && containerX=width || containerY>=height) return result; - container.doMouseDrag(containerX, containerY, mouseButton); - } - return result; - } - - //Zapping this method may fix some positioning bugs - but may cause some backgroundPainter bugs. Will need to monitor. - /* - @Override - public void resize(MinecraftClient minecraftClient_1, int int_1, int int_2) { - //super.onScaleChanged(minecraftClient_1, int_1, int_2); - this.width = int_1; - this.height = int_2; - reposition(); - }*/ - - /* - * SPECIAL FUNCTIONS: Where possible, we want to draw everything based on *actual GUI state and composition* rather - * than relying on pre-baked textures that the programmer then needs to carefully match up their GUI to. - */ - - private int multiplyColor(int color, float amount) { - int a = color & 0xFF000000; - float r = (color >> 16 & 255) / 255.0F; - float g = (color >> 8 & 255) / 255.0F; - float b = (color & 255) / 255.0F; - - r = Math.min(r*amount, 1.0f); - g = Math.min(g*amount, 1.0f); - b = Math.min(b*amount, 1.0f); - - int ir = (int)(r*255); - int ig = (int)(g*255); - int ib = (int)(b*255); - - return a | - (ir << 16) | - (ig << 8) | - ib; - } - - @Override - protected void drawBackground(float partialTicks, int mouseX, int mouseY) { - if (this.container==null) { - return; - } - WPanel root = this.container.getRootPanel(); - if (root==null) return; - - root.paintBackground(left, top, mouseX-left, mouseY-top); - - //TODO: Change this to a label that lives in the rootPanel instead? - if (container instanceof Nameable) { - Text name = ((Nameable)container).getDisplayName(); - font.draw(name.asFormattedString(), left, top, container.getTitleColor()); - } else if (getTitle() != null) { - font.draw(getTitle().asFormattedString(), left, top, container.getTitleColor()); - } - } - - @Override - protected void drawForeground(int mouseX, int mouseY) { - if (this.container==null) { - System.out.println("CONTAINER IS NULL."); - return; - } - - if (this.container.getRootPanel()!=null) { - this.container.getRootPanel().paintForeground(0, 0, mouseX-left, mouseY-top); - } - } - - @Override - public void render(int mouseX, int mouseY, float partialTicks) { - // Render the background shadow - this.renderBackground(); - - this.drawBackground(partialTicks, mouseX, mouseY); - - super.render(mouseX, mouseY, partialTicks); - drawMouseoverTooltip(mouseX, mouseY); - } - -} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index b0c2b05..9c44e35 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java @@ -2,8 +2,10 @@ package io.github.cottonmc.cotton.gui.client; import org.lwjgl.opengl.GL11; -import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.class_4493.class_4534; +import net.minecraft.class_4493.class_4535; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.render.BufferBuilder; @@ -14,15 +16,11 @@ import net.minecraft.util.Identifier; public class ScreenDrawing { private ScreenDrawing() {} - public static void rect(Identifier texture, int left, int top, int width, int height, int color) { - rect(texture, left, top, width, height, 0, 0, 1, 1, color, 0); + public static void texturedRect(int left, int top, int width, int height, Identifier texture, int color) { + texturedRect(left, top, width, height, texture, 0, 0, 1, 1, color); } - - public static void rect(Identifier texture, int left, int top, int width, int height, float u1, float v1, float u2, float v2, int color) { - rect(texture, left, top, width, height, u1, v1, u2, v2, color, 0); - } - - public static void rect(Identifier texture, int left, int top, int width, int height, float u1, float v1, float u2, float v2, int color, int z) { + + public static void texturedRect(int left, int top, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color) { MinecraftClient.getInstance().getTextureManager().bindTexture(texture); //float scale = 0.00390625F; @@ -35,24 +33,24 @@ public class ScreenDrawing { float b = (color & 255) / 255.0F; Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBufferBuilder(); - GlStateManager.enableBlend(); + RenderSystem.enableBlend(); //GlStateManager.disableTexture2D(); - GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); - GlStateManager.color4f(r, g, b, 1.0f); + RenderSystem.blendFuncSeparate(class_4535.SRC_ALPHA, class_4534.ONE_MINUS_SRC_ALPHA, class_4535.ONE, class_4534.ZERO); + RenderSystem.color4f(r, g, b, 1.0f); buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_UV); //I thought GL_QUADS was deprecated but okay, sure. - buffer.vertex(left, top + height, z).texture(u1, v2).next(); - buffer.vertex(left + width, top + height, z).texture(u2, v2).next(); - buffer.vertex(left + width, top, z).texture(u2, v1).next(); - buffer.vertex(left, top, z).texture(u1, v1).next(); + buffer.vertex(left, top + height, 0).texture(u1, v2).next(); + buffer.vertex(left + width, top + height, 0).texture(u2, v2).next(); + buffer.vertex(left + width, top, 0).texture(u2, v1).next(); + buffer.vertex(left, top, 0).texture(u1, v1).next(); tessellator.draw(); //GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); + RenderSystem.disableBlend(); } /** * Draws an untextured rectangle of the specified RGB color. */ - public static void rect(int left, int top, int width, int height, int color) { + public static void coloredRect(int left, int top, int width, int height, int color) { if (width <= 0) width = 1; if (height <= 0) height = 1; @@ -62,32 +60,32 @@ public class ScreenDrawing { float b = (color & 255) / 255.0F; Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBufferBuilder(); - GlStateManager.enableBlend(); - GlStateManager.disableTexture(); - GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); - GlStateManager.color4f(r, g, b, a); + RenderSystem.enableBlend(); + RenderSystem.disableTexture(); + RenderSystem.blendFuncSeparate(class_4535.SRC_ALPHA, class_4534.ONE_MINUS_SRC_ALPHA, class_4535.ONE, class_4534.ZERO); + RenderSystem.color4f(r, g, b, a); buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION); //I thought GL_QUADS was deprecated but okay, sure. buffer.vertex(left, top + height, 0.0D).next(); buffer.vertex(left + width, top + height, 0.0D).next(); buffer.vertex(left + width, top, 0.0D).next(); buffer.vertex(left, top, 0.0D).next(); tessellator.draw(); - GlStateManager.enableTexture(); - GlStateManager.disableBlend(); + RenderSystem.enableTexture(); + RenderSystem.disableBlend(); } public static void maskedRect(Identifier mask, Identifier texture, int left, int top, int width, int height) { - rect(mask, left, top, width, height, 0, 0, 1, 1, 0xFFFFFFFF, 7); + texturedRect(left, top, width, height, mask, 0, 0, 1, 1, 0xFFFFFFFF); //TODO: 7 Z - GlStateManager.enableDepthTest(); - GlStateManager.depthFunc(GL11.GL_EQUAL); + RenderSystem.enableDepthTest(); + RenderSystem.depthFunc(GL11.GL_EQUAL); - rect(texture, left, top, width, height, 0, 0, 1, 1, 0xFFFFFFFF, 7); + texturedRect(left, top, width, height, texture, 0, 0, 1, 1, 0xFFFFFFFF); //, 7); - GlStateManager.depthFunc(GL11.GL_LESS); - GlStateManager.disableDepthTest(); + RenderSystem.depthFunc(GL11.GL_LESS); + RenderSystem.disableDepthTest(); } /** @@ -144,25 +142,25 @@ public class ScreenDrawing { } public static void drawGuiPanel(int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) { - rect(x + 3, y + 3, width - 6, height - 6, panel); //Main panel area - - rect(x + 2, y + 1, width - 4, 2, hilight); //Top hilight - rect(x + 2, y + height - 3, width - 4, 2, shadow); //Bottom shadow - rect(x + 1, y + 2, 2, height - 4, hilight); //Left hilight - rect(x + width - 3, y + 2, 2, height - 4, shadow); //Right shadow - rect(x + width - 3, y + 2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel - rect(x + 2, y + height - 3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel - rect(x + 3, y + 3, 1, 1, hilight); //Topleft round hilight pixel - rect(x + width - 4, y + height - 4, 1, 1, shadow); //Bottomright round shadow pixel - - rect(x + 2, y, width - 4, 1, outline); //Top outline - rect(x, y + 2, 1, height - 4, outline); //Left outline - rect(x + width - 1, y + 2, 1, height - 4, outline); //Right outline - rect(x + 2, y + height - 1, width - 4, 1, outline); //Bottom outline - rect(x + 1, y + 1, 1, 1, outline); //Topleft round pixel - rect(x + 1, y + height - 2, 1, 1, outline); //Bottomleft round pixel - rect(x + width - 2, y + 1, 1, 1, outline); //Topright round pixel - rect(x + width - 2, y + height - 2, 1, 1, outline); //Bottomright round pixel + coloredRect(x + 3, y + 3, width - 6, height - 6, panel); //Main panel area + + coloredRect(x + 2, y + 1, width - 4, 2, hilight); //Top hilight + coloredRect(x + 2, y + height - 3, width - 4, 2, shadow); //Bottom shadow + coloredRect(x + 1, y + 2, 2, height - 4, hilight); //Left hilight + coloredRect(x + width - 3, y + 2, 2, height - 4, shadow); //Right shadow + coloredRect(x + width - 3, y + 2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel + coloredRect(x + 2, y + height - 3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel + coloredRect(x + 3, y + 3, 1, 1, hilight); //Topleft round hilight pixel + coloredRect(x + width - 4, y + height - 4, 1, 1, shadow); //Bottomright round shadow pixel + + coloredRect(x + 2, y, width - 4, 1, outline); //Top outline + coloredRect(x, y + 2, 1, height - 4, outline); //Left outline + coloredRect(x + width - 1, y + 2, 1, height - 4, outline); //Right outline + coloredRect(x + 2, y + height - 1, width - 4, 1, outline); //Bottom outline + coloredRect(x + 1, y + 1, 1, 1, outline); //Topleft round pixel + coloredRect(x + 1, y + height - 2, 1, 1, outline); //Bottomleft round pixel + coloredRect(x + width - 2, y + 1, 1, 1, outline); //Topright round pixel + coloredRect(x + width - 2, y + height - 2, 1, 1, outline); //Bottomright round pixel } /** @@ -190,11 +188,11 @@ public class ScreenDrawing { * @param bottomright color of the bottom/right bevel */ public static void drawBeveledPanel(int x, int y, int width, int height, int topleft, int panel, int bottomright) { - rect(x, y, width, height, panel); //Center panel - rect(x, y, width - 1, 1, topleft); //Top shadow - rect(x, y + 1, 1, height - 2, topleft); //Left shadow - rect(x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight - rect(x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight + coloredRect(x, y, width, height, panel); //Center panel + coloredRect(x, y, width - 1, 1, topleft); //Top shadow + coloredRect(x, y + 1, 1, height - 2, topleft); //Left shadow + coloredRect(x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight + coloredRect(x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight } public static void drawString(String s, int x, int y, int color) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java index 335c093..5a7e236 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java @@ -2,7 +2,7 @@ package io.github.cottonmc.cotton.gui.client.modmenu; import java.util.function.Function; -import io.github.cottonmc.cotton.gui.client.ClientCottonScreen; +import io.github.cottonmc.cotton.gui.client.CottonClientScreen; import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.prospector.modmenu.api.ModMenuApi; import net.minecraft.client.gui.screen.Screen; @@ -17,7 +17,7 @@ public class ModMenuSupport implements ModMenuApi { @Override public Function getConfigScreenFactory() { - return screen -> new ClientCottonScreen(new TranslatableText("options.libgui.libgui_settings"), new ConfigGui(screen)) { + return screen -> new CottonClientScreen(new TranslatableText("options.libgui.libgui_settings"), new ConfigGui(screen)) { public void onClose() { this.minecraft.openScreen(screen); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java index d68b1db..1428c1b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java @@ -98,7 +98,7 @@ public class WKirbSprite extends WWidget { } float offset = KIRB_WIDTH * currentFrame; - ScreenDrawing.rect(KIRB, x, y+8, 32, 32, offset, 0, offset+KIRB_WIDTH, 1, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y+8, 32, 32, KIRB, offset, 0, offset+KIRB_WIDTH, 1, 0xFFFFFFFF); long elapsed = now - lastFrame; currentFrameTime += elapsed; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java index 7c05189..0311a73 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java @@ -65,9 +65,9 @@ public class WBar extends WWidget { @Override public void paintBackground(int x, int y) { if (bg!=null) { - ScreenDrawing.rect(bg, x, y, getWidth(), getHeight(), 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), bg, 0xFFFFFFFF); } else { - ScreenDrawing.rect(x, y, getWidth(), getHeight(), ScreenDrawing.colorAtOpacity(0x000000, 0.25f)); + ScreenDrawing.coloredRect(x, y, getWidth(), getHeight(), ScreenDrawing.colorAtOpacity(0x000000, 0.25f)); } float percent = properties.get(field) / (float) properties.get(max); @@ -87,25 +87,25 @@ public class WBar extends WWidget { int top = y + getHeight(); top -= barSize; if (bar!=null) { - ScreenDrawing.rect(bar, left, top, getWidth(), barSize, 0, 1 - percent, 1, 1, 0xFFFFFFFF); + ScreenDrawing.texturedRect(left, top, getWidth(), barSize, bar, 0, 1 - percent, 1, 1, 0xFFFFFFFF); } else { - ScreenDrawing.rect(left, top, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(left, top, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } case RIGHT: { if (bar!=null) { - ScreenDrawing.rect(bar, x, y, barSize, getHeight(), 0, 0, percent, 1, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y, barSize, getHeight(), bar, 0, 0, percent, 1, 0xFFFFFFFF); } else { - ScreenDrawing.rect(x, y, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(x, y, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } case DOWN: { if (bar!=null) { - ScreenDrawing.rect(bar, x, y, getWidth(), barSize, 0, 0, 1, percent, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y, getWidth(), barSize, bar, 0, 0, 1, percent, 0xFFFFFFFF); } else { - ScreenDrawing.rect(x, y, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(x, y, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } @@ -114,9 +114,9 @@ public class WBar extends WWidget { int top = y; left -= barSize; if (bar!=null) { - ScreenDrawing.rect(bar, left, top, barSize, getHeight(), 1 - percent, 0, 1, 1, 0xFFFFFFFF); + ScreenDrawing.texturedRect(left, top, barSize, getHeight(), bar, 1 - percent, 0, 1, 1, 0xFFFFFFFF); } else { - ScreenDrawing.rect(left, top, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(left, top, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } 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 32558a9..7c3a3b5 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 @@ -48,8 +48,8 @@ public class WButton extends WWidget { float buttonEndLeft = (200-(getWidth()/2)) * px; - ScreenDrawing.rect(AbstractButtonWidget.WIDGETS_LOCATION, x, y, getWidth()/2, 20, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF); - ScreenDrawing.rect(AbstractButtonWidget.WIDGETS_LOCATION, x+(getWidth()/2), y, getWidth()/2, 20, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x+(getWidth()/2), y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF); if (label!=null) { int color = 0xE0E0E0; 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 37fe464..16a5f60 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 @@ -84,7 +84,7 @@ public class WLabeledSlider extends WAbstractSlider { if (thumbState == 1 && isFocused()) { float px = 1 / 32f; - ScreenDrawing.rect(WSlider.TEXTURE, x + thumbX, y + thumbY, thumbWidth, thumbHeight, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + thumbX, y + thumbY, thumbWidth, thumbHeight, WSlider.TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); } if (label != null) { @@ -105,8 +105,8 @@ public class WLabeledSlider extends WAbstractSlider { float buttonHeight = 20 * px; float buttonEndLeft = (200 - halfWidth) * px; - ScreenDrawing.rect(AbstractButtonWidget.WIDGETS_LOCATION, x, y, halfWidth, 20, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF); - ScreenDrawing.rect(AbstractButtonWidget.WIDGETS_LOCATION, x + halfWidth, y, halfWidth, 20, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + halfWidth, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); } @FunctionalInterface 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 39c416c..26caa8b 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 @@ -26,9 +26,9 @@ public class WScrollBar extends WWidget { int color = 0xFF_FFFFFF; if (axis==Axis.HORIZONTAL) { - ScreenDrawing.rect(x+1+getHandlePosition(), y+1, getHandleSize(), height-2, color); + ScreenDrawing.coloredRect(x+1+getHandlePosition(), y+1, getHandleSize(), height-2, color); } else { - ScreenDrawing.rect(x+1, y+1+getHandlePosition(), width-2, getHandleSize(), color); + ScreenDrawing.coloredRect(x+1, y+1+getHandlePosition(), width-2, getHandleSize(), color); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index c57b705..e9c862f 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java @@ -63,27 +63,27 @@ public class WSlider extends WAbstractSlider { thumbY = height - THUMB_SIZE + 1 - (int) (coordToValueRatio * (value - min)); thumbXOffset = 0; - ScreenDrawing.rect(TEXTURE, trackX, y + 1, TRACK_WIDTH, 1, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); - ScreenDrawing.rect(TEXTURE, trackX, y + 2, TRACK_WIDTH, height - 2, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); - ScreenDrawing.rect(TEXTURE, trackX, y + height, TRACK_WIDTH, 1, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(trackX, y + 1, TRACK_WIDTH, 1, TEXTURE, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(trackX, y + 2, TRACK_WIDTH, height - 2, TEXTURE, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(trackX, y + height, TRACK_WIDTH, 1, TEXTURE, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); } else { int trackY = y + height / 2 - TRACK_WIDTH / 2; thumbX = Math.round(coordToValueRatio * (value - min)); thumbY = height / 2 - THUMB_SIZE / 2; thumbXOffset = 8; - ScreenDrawing.rect(TEXTURE, x, trackY, 1, TRACK_WIDTH, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.rect(TEXTURE, x + 1, trackY, width - 2, TRACK_WIDTH, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.rect(TEXTURE, x + width - 1, trackY, 1, TRACK_WIDTH, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, trackY, 1, TRACK_WIDTH, TEXTURE, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + 1, trackY, width - 2, TRACK_WIDTH, TEXTURE, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + width - 1, trackY, 1, TRACK_WIDTH, TEXTURE, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); } // thumbState values: // 0: default, 1: dragging, 2: hovered int thumbState = dragging ? 1 : (mouseX >= thumbX && mouseX <= thumbX + THUMB_SIZE && mouseY >= thumbY && mouseY <= thumbY + THUMB_SIZE ? 2 : 0); - ScreenDrawing.rect(TEXTURE, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, TEXTURE, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); if (thumbState == 0 && isFocused()) { - ScreenDrawing.rect(TEXTURE, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, TEXTURE, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java index b3ce4cf..44f8998 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java @@ -75,7 +75,7 @@ public class WSprite extends WWidget { @Override public void paintBackground(int x, int y) { if (singleImage) { - ScreenDrawing.rect(frames[0], x, y, getWidth(), getHeight(), tint); + ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), frames[0], tint); } else { //grab the system time at the very start of the frame. long now = System.nanoTime() / 1_000_000L; @@ -85,7 +85,7 @@ public class WSprite extends WWidget { if (!inBounds) currentFrame = 0; //assemble and draw the frame calculated last iteration. Identifier currentFrameTex = frames[currentFrame]; - ScreenDrawing.rect(currentFrameTex, x, y, getWidth(), getHeight(), tint); + ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), currentFrameTex, tint); //calculate how much time has elapsed since the last animation change, and change the frame if necessary. long elapsed = now - lastFrame; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index 99ea221..d8d5955 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java @@ -8,14 +8,16 @@ import javax.annotation.Nullable; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; -import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.class_4493; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gl.GlProgramManager; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; @@ -313,8 +315,8 @@ public class WTextField extends WWidget { if (this.font==null) this.font = MinecraftClient.getInstance().textRenderer; int borderColor = (this.isFocused()) ? 0xFF_FFFFA0 : 0xFF_A0A0A0; - ScreenDrawing.rect(x-1, y-1, width+2, height+2, borderColor); - ScreenDrawing.rect(x, y, width, height, 0xFF000000); + ScreenDrawing.coloredRect(x-1, y-1, width+2, height+2, borderColor); + ScreenDrawing.coloredRect(x, y, width, height, 0xFF000000); int textColor = this.editable ? this.enabledColor : this.uneditableColor; @@ -368,7 +370,7 @@ public class WTextField extends WWidget { //} else { // caretLoc = textX+caretLoc-1; //} - ScreenDrawing.rect(preCursorAdvance-1, textY-2, 1, 12, 0xFFD0D0D0); + ScreenDrawing.coloredRect(preCursorAdvance-1, textY-2, 1, 12, 0xFFD0D0D0); //if (boolean_3) { // int var10001 = int_7 - 1; // var10002 = int_9 + 1; @@ -402,18 +404,18 @@ public class WTextField extends WWidget { private void invertedRect(int x, int y, int width, int height) { Tessellator tessellator_1 = Tessellator.getInstance(); BufferBuilder bufferBuilder_1 = tessellator_1.getBufferBuilder(); - GlStateManager.color4f(0.0F, 0.0F, 255.0F, 255.0F); - GlStateManager.disableTexture(); - GlStateManager.enableColorLogicOp(); - GlStateManager.logicOp(GlStateManager.LogicOp.OR_REVERSE); + RenderSystem.color4f(0.0F, 0.0F, 255.0F, 255.0F); + RenderSystem.disableTexture(); + RenderSystem.enableColorLogicOp(); + RenderSystem.logicOp(class_4493.LogicOp.OR_REVERSE); bufferBuilder_1.begin(GL11.GL_QUADS, VertexFormats.POSITION); bufferBuilder_1.vertex(x, y+height, 0.0D).next(); bufferBuilder_1.vertex(x+width, y+height, 0.0D).next(); bufferBuilder_1.vertex(x+width, y, 0.0D).next(); bufferBuilder_1.vertex(x, y, 0.0D).next(); tessellator_1.draw(); - GlStateManager.disableColorLogicOp(); - GlStateManager.enableTexture(); + RenderSystem.disableColorLogicOp(); + RenderSystem.enableTexture(); } public WTextField setTextPredicate(Predicate predicate_1) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java index 846f032..82813ca 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java @@ -87,7 +87,7 @@ public class WToggleButton extends WWidget { @Override public void paintBackground(int x, int y) { - ScreenDrawing.rect(isOn ? DEFAULT_ON_IMAGE : DEFAULT_OFF_IMAGE, x, y, 18, 18, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y, 18, 18, isOn ? DEFAULT_ON_IMAGE : DEFAULT_OFF_IMAGE, 0xFFFFFFFF); if (label!=null) { -- cgit