aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java41
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java23
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java3
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java3
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java25
5 files changed, 89 insertions, 6 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 8c0f300..cf1226b 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
@@ -5,6 +5,7 @@ import javax.annotation.Nullable;
import io.github.cottonmc.cotton.gui.impl.FocusHandler;
import io.github.cottonmc.cotton.gui.widget.WPanel;
import io.github.cottonmc.cotton.gui.widget.WWidget;
+import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.screen.PropertyDelegate;
@@ -23,8 +24,30 @@ public interface GuiDescription {
public int getTitleColor();
public GuiDescription setRootPanel(WPanel panel);
+
+ /**
+ * Sets the title color of this GUI.
+ *
+ * <p>The dark-mode title color will also be set by this method.
+ * If the specified color is {@link io.github.cottonmc.cotton.gui.widget.WLabel#DEFAULT_TEXT_COLOR},
+ * the dark-mode color will be {@link io.github.cottonmc.cotton.gui.widget.WLabel#DEFAULT_DARKMODE_TEXT_COLOR};
+ * otherwise it will be the specified color.
+ *
+ * @param color the new title color
+ * @return this GUI
+ */
public GuiDescription setTitleColor(int color);
-
+
+ /**
+ * Sets the light and dark title colors of this GUI.
+ *
+ * @param lightColor the light-mode color
+ * @param darkColor the dark-mode color
+ * @return this GUI
+ * @since 2.1.0
+ */
+ GuiDescription setTitleColor(int lightColor, int darkColor);
+
/** Sets the object which manages the integer properties used by WBars */
public GuiDescription setPropertyDelegate(PropertyDelegate delegate);
@@ -98,4 +121,20 @@ public interface GuiDescription {
* @since 2.0.0
*/
void setTitleVisible(boolean titleVisible);
+
+ /**
+ * Gets the horizontal alignment of the GUI title.
+ *
+ * @return the alignment
+ * @since 2.1.0
+ */
+ HorizontalAlignment getTitleAlignment();
+
+ /**
+ * Sets the horizontal alignment of the GUI title.
+ *
+ * @param alignment the new alignment
+ * @since 2.1.0
+ */
+ void setTitleAlignment(HorizontalAlignment alignment);
}
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 f4ab13e..cd47af4 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java
@@ -8,6 +8,7 @@ import javax.annotation.Nullable;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import io.github.cottonmc.cotton.gui.client.LibGuiClient;
import io.github.cottonmc.cotton.gui.widget.*;
+import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
@@ -39,6 +40,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
protected int darkTitleColor = WLabel.DEFAULT_DARKMODE_TEXT_COLOR;
protected boolean fullscreen = false;
protected boolean titleVisible = true;
+ protected HorizontalAlignment titleAlignment = HorizontalAlignment.LEFT;
protected WWidget focus;
@@ -71,9 +73,18 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
this.rootPanel = panel;
return this;
}
-
+
+ @Override
public SyncedGuiDescription setTitleColor(int color) {
this.titleColor = color;
+ this.darkTitleColor = (color == WLabel.DEFAULT_TEXT_COLOR) ? WLabel.DEFAULT_DARKMODE_TEXT_COLOR : color;
+ return this;
+ }
+
+ @Override
+ public SyncedGuiDescription setTitleColor(int lightColor, int darkColor) {
+ this.titleColor = lightColor;
+ this.darkTitleColor = darkColor;
return this;
}
@@ -529,4 +540,14 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
public void setTitleVisible(boolean titleVisible) {
this.titleVisible = titleVisible;
}
+
+ @Override
+ public HorizontalAlignment getTitleAlignment() {
+ return titleAlignment;
+ }
+
+ @Override
+ public void setTitleAlignment(HorizontalAlignment titleAlignment) {
+ this.titleAlignment = titleAlignment;
+ }
}
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 db1e0d2..95702a6 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
@@ -99,7 +99,8 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
if (getTitle() != null && description.isTitleVisible()) {
- textRenderer.draw(matrices, getTitle(), left + titleX, top + titleY, description.getTitleColor());
+ int width = description.getRootPanel().getWidth();
+ ScreenDrawing.drawString(matrices, getTitle(), description.getTitleAlignment(), left + titleX, top + titleY, width, 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 abc2d17..4287565 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
@@ -266,7 +266,8 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl
@Override
protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) {
if (description != null && description.isTitleVisible()) {
- this.textRenderer.draw(matrices, this.title, titleX, titleY, description.getTitleColor());
+ int width = description.getRootPanel().getWidth();
+ ScreenDrawing.drawString(matrices, getTitle(), description.getTitleAlignment(), titleX, titleY, width, 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 e24c03c..8a57551 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
@@ -1,5 +1,6 @@
package io.github.cottonmc.cotton.gui.client;
+import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
import net.minecraft.screen.PropertyDelegate;
import io.github.cottonmc.cotton.gui.GuiDescription;
@@ -16,12 +17,14 @@ import javax.annotation.Nullable;
*/
public class LightweightGuiDescription implements GuiDescription {
protected WPanel rootPanel = new WGridPanel();
+ protected PropertyDelegate propertyDelegate;
+ protected WWidget focus;
+
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;
+ protected HorizontalAlignment titleAlignment = HorizontalAlignment.LEFT;
@Override
public WPanel getRootPanel() {
@@ -42,6 +45,14 @@ public class LightweightGuiDescription implements GuiDescription {
@Override
public GuiDescription setTitleColor(int color) {
this.titleColor = color;
+ this.darkmodeTitleColor = (color == WLabel.DEFAULT_TEXT_COLOR) ? WLabel.DEFAULT_DARKMODE_TEXT_COLOR : color;
+ return this;
+ }
+
+ @Override
+ public GuiDescription setTitleColor(int lightColor, int darkColor) {
+ this.titleColor = lightColor;
+ this.darkmodeTitleColor = darkColor;
return this;
}
@@ -116,4 +127,14 @@ public class LightweightGuiDescription implements GuiDescription {
public void setTitleVisible(boolean titleVisible) {
this.titleVisible = titleVisible;
}
+
+ @Override
+ public HorizontalAlignment getTitleAlignment() {
+ return titleAlignment;
+ }
+
+ @Override
+ public void setTitleAlignment(HorizontalAlignment titleAlignment) {
+ this.titleAlignment = titleAlignment;
+ }
}