diff options
5 files changed, 69 insertions, 22 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 0c31912..2e8006b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java @@ -61,4 +61,23 @@ public interface GuiDescription { default void cycleFocus(boolean lookForwards) { FocusHandler.cycleFocus(this, lookForwards); } + + /** + * Gets whether this GUI is fullscreen. + * + * <p>Fullscreen GUIs have no default background painter and + * have the root panel stretched to fit the entire screen on the client. + * + * @return true if this GUI is fullscreen, false otherwise + * @since 2.0.0 + */ + boolean isFullscreen(); + + /** + * Sets whether this GUI is fullscreen. + * + * @param fullscreen true if this GUI is fullscreen, false otherwise + * @since 2.0.0 + */ + void setFullscreen(boolean fullscreen); } 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 8a67c52..cd4e6e8 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -35,6 +35,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio protected WPanel rootPanel = new WGridPanel(); protected int titleColor = WLabel.DEFAULT_TEXT_COLOR; protected int darkTitleColor = WLabel.DEFAULT_DARKMODE_TEXT_COLOR; + protected boolean fullscreen = false; protected WWidget focus; @@ -75,7 +76,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio @Environment(EnvType.CLIENT) public void addPainters() { - if (this.rootPanel!=null) { + if (this.rootPanel!=null && !fullscreen) { this.rootPanel.setBackgroundPainter(BackgroundPainter.VANILLA); } } @@ -455,4 +456,14 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio widget.onFocusLost(); } } + + @Override + public boolean isFullscreen() { + return fullscreen; + } + + @Override + public void setFullscreen(boolean fullscreen) { + this.fullscreen = fullscreen; + } } 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 2229424..6808aa1 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 @@ -15,9 +15,7 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree 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) { @@ -44,20 +42,23 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree reposition(screenWidth, screenHeight); } - public void reposition(int screenWidth, int screenHeight) { + private 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; + if (!description.isFullscreen()) { + this.left = (screenWidth - root.getWidth()) / 2; + this.top = (screenHeight - root.getHeight()) / 2; + } else { + this.left = 0; + this.top = 0; + root.setSize(screenWidth, screenHeight); + } } } } - public void paint(MatrixStack matrices, int mouseX, int mouseY) { + private void paint(MatrixStack matrices, int mouseX, int mouseY) { super.renderBackground(matrices); if (description!=null) { 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 10ff4f6..4891765 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 @@ -65,10 +65,10 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl description.addPainters(); - reposition(); + reposition(screenWidth, screenHeight); } - public void reposition() { + private void reposition(int screenWidth, int screenHeight) { WPanel basePanel = description.getRootPanel(); if (basePanel!=null) { basePanel.validate(description); @@ -80,13 +80,18 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl if (backgroundWidth<16) backgroundWidth=300; if (backgroundHeight<16) backgroundHeight=300; } - x = (width / 2) - (backgroundWidth / 2); - y = (height / 2) - (backgroundHeight / 2); - } - - @Override - public void onClose() { - super.onClose(); + + if (!description.isFullscreen()) { + x = (width / 2) - (backgroundWidth / 2); + y = (height / 2) - (backgroundHeight / 2); + } else { + x = 0; + y = 0; + + if (basePanel != null) { + basePanel.setSize(screenWidth, screenHeight); + } + } } @Override @@ -211,7 +216,7 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl @Override protected void drawBackground(MatrixStack matrices, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. - public void paint(MatrixStack matrices, int mouseX, int mouseY) { + private void paint(MatrixStack matrices, int mouseX, int mouseY) { super.renderBackground(matrices); if (description!=null) { 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 3eb6578..87d8a09 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 @@ -18,6 +18,7 @@ public class LightweightGuiDescription implements GuiDescription { protected WPanel rootPanel = new WGridPanel(); protected int titleColor = WLabel.DEFAULT_TEXT_COLOR; protected int darkmodeTitleColor = WLabel.DEFAULT_DARKMODE_TEXT_COLOR; + protected boolean fullscreen = false; protected PropertyDelegate propertyDelegate; protected WWidget focus; @@ -45,7 +46,7 @@ public class LightweightGuiDescription implements GuiDescription { @Override public void addPainters() { - if (this.rootPanel!=null) { + if (this.rootPanel!=null && !fullscreen) { this.rootPanel.setBackgroundPainter(BackgroundPainter.VANILLA); } } @@ -94,4 +95,14 @@ public class LightweightGuiDescription implements GuiDescription { widget.onFocusLost(); } } + + @Override + public boolean isFullscreen() { + return fullscreen; + } + + @Override + public void setFullscreen(boolean fullscreen) { + this.fullscreen = fullscreen; + } } |