aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GuiTest/build.gradle5
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java2
-rw-r--r--build.gradle5
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java16
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java12
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java9
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java9
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java12
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/math/Vec2i.java10
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/math/package-info.java6
10 files changed, 65 insertions, 21 deletions
diff --git a/GuiTest/build.gradle b/GuiTest/build.gradle
index 02c6d2e..ee1fa3b 100644
--- a/GuiTest/build.gradle
+++ b/GuiTest/build.gradle
@@ -52,10 +52,7 @@ tasks.withType(JavaCompile) {
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
options.encoding = "UTF-8"
-
- if (JavaVersion.current().isJava9Compatible()) {
- options.release.set 8
- }
+ options.release.set 16
}
java {
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java
index 82188d2..d443770 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java
@@ -36,7 +36,7 @@ public class GuiBlockEntity extends BlockEntity implements ImplementedInventory,
@Override
public Text getDisplayName() {
- return new LiteralText(""); // no title
+ return new LiteralText("test title");
}
@Nullable
diff --git a/build.gradle b/build.gradle
index 7f3d643..db828bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -57,10 +57,7 @@ tasks.withType(JavaCompile) {
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
options.encoding = "UTF-8"
-
- if (JavaVersion.current().isJava9Compatible()) {
- options.release.set 8
- }
+ options.release.set 16
}
jar {
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 b192808..71fc6a5 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 net.fabricmc.api.Environment;
import net.minecraft.screen.PropertyDelegate;
import io.github.cottonmc.cotton.gui.impl.FocusHandler;
+import io.github.cottonmc.cotton.gui.math.Vec2i;
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;
@@ -137,4 +138,19 @@ public interface GuiDescription {
* @since 2.1.0
*/
void setTitleAlignment(HorizontalAlignment alignment);
+
+ /**
+ * Gets the position of the screen title.
+ *
+ * @since 4.0.0
+ */
+ Vec2i getTitlePos();
+
+ /**
+ * Sets the position of the screen title.
+ *
+ * @param titlePos the new title position
+ * @since 4.0.0
+ */
+ void setTitlePos(Vec2i titlePos);
}
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 b0bf93d..10adbce 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java
@@ -27,6 +27,7 @@ import net.minecraft.world.World;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import io.github.cottonmc.cotton.gui.client.LibGui;
+import io.github.cottonmc.cotton.gui.math.Vec2i;
import io.github.cottonmc.cotton.gui.networking.NetworkSide;
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WLabel;
@@ -58,6 +59,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
protected HorizontalAlignment titleAlignment = HorizontalAlignment.LEFT;
protected WWidget focus;
+ private Vec2i titlePos = new Vec2i(8, 6);
public SyncedGuiDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory) {
super(type, syncId);
@@ -519,6 +521,16 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
this.titleAlignment = titleAlignment;
}
+ @Override
+ public Vec2i getTitlePos() {
+ return titlePos;
+ }
+
+ @Override
+ public void setTitlePos(Vec2i titlePos) {
+ this.titlePos = titlePos;
+ }
+
/**
* Gets the network side this GUI description runs on.
*
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 2acc371..df5108c 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
@@ -88,19 +88,16 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl {
if (description!=null) {
WPanel root = description.getRootPanel();
if (root!=null) {
+ titleX = description.getTitlePos().x();
+ titleY = description.getTitlePos().y();
+
if (!description.isFullscreen()) {
this.left = (screenWidth - root.getWidth()) / 2;
this.top = (screenHeight - root.getHeight()) / 2;
- this.titleX = 0;
- this.titleY = 0;
} else {
this.left = 0;
this.top = 0;
- // Offset the title coordinates a little from the edge
- this.titleX = 10;
- this.titleY = 10;
-
root.setSize(screenWidth, screenHeight);
}
}
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 68f28fe..9c344cd 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
@@ -118,19 +118,16 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl
if (backgroundHeight<16) backgroundHeight=300;
}
+ titleX = description.getTitlePos().x();
+ titleY = description.getTitlePos().y();
+
if (!description.isFullscreen()) {
x = (screenWidth / 2) - (backgroundWidth / 2);
y = (screenHeight / 2) - (backgroundHeight / 2);
- titleX = 0;
- titleY = 0;
} else {
x = 0;
y = 0;
- // Offset the title coordinates a little from the edge
- titleX = 10;
- titleY = 10;
-
if (basePanel != null) {
basePanel.setSize(screenWidth, screenHeight);
}
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 55b62a4..fd0d8dd 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
@@ -4,6 +4,7 @@ import net.minecraft.screen.PropertyDelegate;
import io.github.cottonmc.cotton.gui.GuiDescription;
import io.github.cottonmc.cotton.gui.ValidatedSlot;
+import io.github.cottonmc.cotton.gui.math.Vec2i;
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WLabel;
import io.github.cottonmc.cotton.gui.widget.WPanel;
@@ -25,6 +26,7 @@ public class LightweightGuiDescription implements GuiDescription {
protected boolean fullscreen = false;
protected boolean titleVisible = true;
protected HorizontalAlignment titleAlignment = HorizontalAlignment.LEFT;
+ private Vec2i titlePos = new Vec2i(8, 6);
@Override
public WPanel getRootPanel() {
@@ -137,4 +139,14 @@ public class LightweightGuiDescription implements GuiDescription {
public void setTitleAlignment(HorizontalAlignment titleAlignment) {
this.titleAlignment = titleAlignment;
}
+
+ @Override
+ public Vec2i getTitlePos() {
+ return titlePos;
+ }
+
+ @Override
+ public void setTitlePos(Vec2i titlePos) {
+ this.titlePos = titlePos;
+ }
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/math/Vec2i.java b/src/main/java/io/github/cottonmc/cotton/gui/math/Vec2i.java
new file mode 100644
index 0000000..4515c09
--- /dev/null
+++ b/src/main/java/io/github/cottonmc/cotton/gui/math/Vec2i.java
@@ -0,0 +1,10 @@
+package io.github.cottonmc.cotton.gui.math;
+
+/**
+ * An immutable, two-dimensional int vector.
+ * This record can be used to represent positions on the screen.
+ *
+ * @since 4.0.0
+ */
+public record Vec2i(int x, int y) {
+}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/math/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/math/package-info.java
new file mode 100644
index 0000000..2ab2ffb
--- /dev/null
+++ b/src/main/java/io/github/cottonmc/cotton/gui/math/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * LibGui-specific math data types.
+ *
+ * @since 4.0.0
+ */
+package io.github.cottonmc.cotton.gui.math;