From 9d6ded3e6f2060a6d0213fc7ae780cde6aaaa0b1 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Thu, 18 Jun 2020 13:11:48 +0300 Subject: Fix title positioning for real this time, add title rendering control --- .../io/github/cottonmc/cotton/gui/GuiDescription.java | 18 ++++++++++++++++++ .../cottonmc/cotton/gui/SyncedGuiDescription.java | 13 ++++++++++++- .../cottonmc/cotton/gui/client/CottonClientScreen.java | 12 ++++++------ .../cotton/gui/client/CottonInventoryScreen.java | 8 ++++---- .../cotton/gui/client/LightweightGuiDescription.java | 11 +++++++++++ 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java index 2e8006b..8c0f300 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java @@ -80,4 +80,22 @@ public interface GuiDescription { * @since 2.0.0 */ void setFullscreen(boolean fullscreen); + + /** + * Gets whether the title of this GUI should be rendered by the screen. + * + *

Modders can disable this to render the title themselves with a widget. + * + * @return true if the title is visible, false otherwise + * @since 2.0.0 + */ + boolean isTitleVisible(); + + /** + * Sets whether the title of this GUI should be rendered by the screen. + * + * @param titleVisible true if the title is visible, false otherwise + * @since 2.0.0 + */ + void setTitleVisible(boolean titleVisible); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java index cd4e6e8..d6940e1 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -36,7 +36,8 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio protected int titleColor = WLabel.DEFAULT_TEXT_COLOR; protected int darkTitleColor = WLabel.DEFAULT_DARKMODE_TEXT_COLOR; protected boolean fullscreen = false; - + protected boolean titleVisible = true; + protected WWidget focus; public SyncedGuiDescription(ScreenHandlerType type, int syncId, PlayerInventory playerInventory) { @@ -466,4 +467,14 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio public void setFullscreen(boolean fullscreen) { this.fullscreen = fullscreen; } + + @Override + public boolean isTitleVisible() { + return titleVisible; + } + + @Override + public void setTitleVisible(boolean titleVisible) { + this.titleVisible = titleVisible; + } } 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 e10bd4c..db1e0d2 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 @@ -69,8 +69,8 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree if (!description.isFullscreen()) { this.left = (screenWidth - root.getWidth()) / 2; this.top = (screenHeight - root.getHeight()) / 2; - this.titleX = this.left; - this.titleY = this.top; + this.titleX = 0; + this.titleY = 0; } else { this.left = 0; this.top = 0; @@ -97,10 +97,10 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree GL11.glDisable(GL11.GL_SCISSOR_TEST); Scissors.checkStackIsEmpty(); } - } - - if (getTitle() != null) { - textRenderer.draw(matrices, getTitle(), titleX, titleY, description.getTitleColor()); + + if (getTitle() != null && description.isTitleVisible()) { + textRenderer.draw(matrices, getTitle(), left + titleX, top + titleY, description.getTitleColor()); + } } } 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 dbc7404..abc2d17 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 @@ -91,8 +91,8 @@ public class CottonInventoryScreen extends Handl if (!description.isFullscreen()) { x = (width / 2) - (backgroundWidth / 2); y = (height / 2) - (backgroundHeight / 2); - titleX = x; - titleY = y; + titleX = 0; + titleY = 0; } else { x = 0; y = 0; @@ -265,8 +265,8 @@ public class CottonInventoryScreen extends Handl @Override protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) { - if (description != null) { - this.textRenderer.draw(matrices, this.title, (float) this.titleX, (float) this.titleY, description.getTitleColor()); + if (description != null && description.isTitleVisible()) { + this.textRenderer.draw(matrices, this.title, titleX, titleY, description.getTitleColor()); } // Don't draw the player inventory label as it's drawn by the widget itself diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java index 87d8a09..e24c03c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java @@ -19,6 +19,7 @@ public class LightweightGuiDescription implements GuiDescription { protected int titleColor = WLabel.DEFAULT_TEXT_COLOR; protected int darkmodeTitleColor = WLabel.DEFAULT_DARKMODE_TEXT_COLOR; protected boolean fullscreen = false; + protected boolean titleVisible = true; protected PropertyDelegate propertyDelegate; protected WWidget focus; @@ -105,4 +106,14 @@ public class LightweightGuiDescription implements GuiDescription { public void setFullscreen(boolean fullscreen) { this.fullscreen = fullscreen; } + + @Override + public boolean isTitleVisible() { + return titleVisible; + } + + @Override + public void setTitleVisible(boolean titleVisible) { + this.titleVisible = titleVisible; + } } -- cgit