diff options
author | Juuxel <kasperi.kauppi@gmail.com> | 2020-06-18 13:11:48 +0300 |
---|---|---|
committer | Juuxel <kasperi.kauppi@gmail.com> | 2020-06-18 13:11:48 +0300 |
commit | 9d6ded3e6f2060a6d0213fc7ae780cde6aaaa0b1 (patch) | |
tree | 6d7e94ab85e5f3e7c642f81c12cbcd21caa11605 /src/main/java/io | |
parent | 3695e8687874559214ac7310b7cfb4c039b9f2fc (diff) | |
download | LibGui-9d6ded3e6f2060a6d0213fc7ae780cde6aaaa0b1.tar.gz LibGui-9d6ded3e6f2060a6d0213fc7ae780cde6aaaa0b1.tar.bz2 LibGui-9d6ded3e6f2060a6d0213fc7ae780cde6aaaa0b1.zip |
Fix title positioning for real this time, add title rendering control
Diffstat (limited to 'src/main/java/io')
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. + * + * <p>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<T extends SyncedGuiDescription> 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<T extends SyncedGuiDescription> 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; + } } |