From be0821a5001221b9411c259342216714960ac27f Mon Sep 17 00:00:00 2001
From: ImproperIssues <114215797+ItziSpyder@users.noreply.github.com>
Date: Tue, 14 May 2024 22:17:36 -0700
Subject: [PATCH] fixed screen resize issues
---
README.md | 12 +++------
gradle.properties | 2 +-
.../itzispyder/improperui/ImproperUIAPI.java | 22 ++-------------
.../improperui/render/ImproperUIPanel.java | 15 ++++++++++-
.../improperui/render/math/Color.java | 12 ++++-----
.../improperui/script/ScriptParser.java | 27 -------------------
6 files changed, 27 insertions(+), 63 deletions(-)
diff --git a/README.md b/README.md
index 8e6edab..9dcee8a 100644
--- a/README.md
+++ b/README.md
@@ -19,13 +19,10 @@ This screen is scripted using ImproperUI Script:
### Recent Changes
```yml
-Version: 0.0.3-BETA
-
-Added:
- - in-game bind to open up home page (right shift) # you can edit this in controls
+Version: 0.0.4-BETA
Patches:
- - attempted to fix script blank or frozen screen due to failed initialization
+ - attempted to fix screen resize issues
```
### Adding ImproperUI to your Project
@@ -125,15 +122,14 @@ Helper Methods:
- ImproperUIPanel.collectOrdered() // a sorted list based on z-index, of all elements and widgets including their children
- ImproperUIPanel.collectById() // a list of elements with specified ID
- ImproperUIPanel.collectByClassAttribute() // a list of elements with specified class attribute
- - ImproperUIPanel.collectById() // first element with specified ID
- - ImproperUIPanel.collectByClassAttribute() // first element with specified class attribute
+ - ImproperUIPanel.collectFirstById() // first element with specified ID
+ - ImproperUIPanel.collectFirstByClassAttribute() // first element with specified class attribute
API:
- ImproperUIAPI.parse() // parses a script then returns all parsed result elements
- ImproperUIAPI.parseAndRunFile() // parses a registered script file NAME (NOT PATH) from init() and opens the screen with the elements
- ImproperUIAPI.parseAndRunScript() // parses a registered script from init() and opens the screen with the elements
- ImproperUIAPI.reload() // reloads the API
- - ImproperUIAPI.reInit() // re-init the API with possibly a different Mod ID
```
diff --git a/gradle.properties b/gradle.properties
index c0588c5..0ee94c3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -9,7 +9,7 @@ org.gradle.java.home=/Program Files/Java/jdk-21
loader_version=0.15.10
# Mod Properties
- mod_version = 0.0.3-BETA
+ mod_version = 0.0.4-BETA
maven_group = io.github.itzispyder
archives_base_name = ImproperUI
diff --git a/src/main/java/io/github/itzispyder/improperui/ImproperUIAPI.java b/src/main/java/io/github/itzispyder/improperui/ImproperUIAPI.java
index ee519dc..fe9149c 100644
--- a/src/main/java/io/github/itzispyder/improperui/ImproperUIAPI.java
+++ b/src/main/java/io/github/itzispyder/improperui/ImproperUIAPI.java
@@ -6,7 +6,6 @@
import io.github.itzispyder.improperui.script.CallbackListener;
import io.github.itzispyder.improperui.script.ScriptParser;
import net.fabricmc.api.ModInitializer;
-import net.minecraft.client.MinecraftClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,23 +60,8 @@ public static List parse(File file) {
return ScriptParser.parseFile(file);
}
- public static void parseAndRunScript(String script) {
- ScriptParser.run(script);
- }
-
- /**
- * Parses and runs the script from the path provided
- * @param modId Multiple mods may use ImproperUI at the same time with their own respective scripts, specify the mod ID!
- * @param fileName The file NAME, NOT THE FILE PATH
- */
- public static void parseAndRunFile(String modId, String fileName) {
- ScriptParser.run(new File(Paths.getScripts(modId) + fileName));
- }
-
public static void parseAndRunScript(String script, CallbackListener... callbackListeners) {
- ImproperUIPanel panel = new ImproperUIPanel(script, callbackListeners);
- MinecraftClient client = MinecraftClient.getInstance();
- client.execute(() -> client.setScreen(panel));
+ new ImproperUIPanel(script, callbackListeners).open();
}
/**
@@ -88,8 +72,6 @@ public static void parseAndRunScript(String script, CallbackListener... callback
*/
public static void parseAndRunFile(String modId, String fileName, CallbackListener... callbackListeners) {
File script = new File(Paths.getScripts(modId) + fileName);
- ImproperUIPanel panel = new ImproperUIPanel(script, callbackListeners);
- MinecraftClient client = MinecraftClient.getInstance();
- client.execute(() -> client.setScreen(panel));
+ new ImproperUIPanel(script, callbackListeners).open();
}
}
diff --git a/src/main/java/io/github/itzispyder/improperui/render/ImproperUIPanel.java b/src/main/java/io/github/itzispyder/improperui/render/ImproperUIPanel.java
index e7efb37..571a690 100644
--- a/src/main/java/io/github/itzispyder/improperui/render/ImproperUIPanel.java
+++ b/src/main/java/io/github/itzispyder/improperui/render/ImproperUIPanel.java
@@ -25,6 +25,9 @@ public class ImproperUIPanel extends Screen {
private final List children;
private final List callbackListeners;
+ private File uiScriptAsFile;
+ private String uiScriptAsString;
+
public ImproperUIPanel() {
super(Text.of("Custom Scripted Panel Screen"));
children = new ArrayList<>();
@@ -42,10 +45,12 @@ public ImproperUIPanel(List widgets, CallbackListener... callbackListen
public ImproperUIPanel(String uiScript, CallbackListener... callbackListeners) {
this(ScriptParser.parse(uiScript), callbackListeners);
+ uiScriptAsString = uiScript;
}
public ImproperUIPanel(File uiScript, CallbackListener... callbackListeners) {
this(ScriptParser.parseFile(uiScript), callbackListeners);
+ uiScriptAsFile = uiScript;
}
@Override
@@ -179,6 +184,14 @@ public void tick() {
children.forEach(Element::onTick);
}
+ @Override
+ public void resize(MinecraftClient client, int width, int height) {
+ if (uiScriptAsFile != null)
+ new ImproperUIPanel(uiScriptAsFile, callbackListeners.toArray(CallbackListener[]::new)).open();
+ else if (uiScriptAsString != null)
+ new ImproperUIPanel(uiScriptAsString, callbackListeners.toArray(CallbackListener[]::new)).open();
+ }
+
public void addChild(Element child) {
if (child == null || child.parentPanel != null || child.parent != null || children.contains(child))
return;
@@ -280,6 +293,6 @@ public Element collectFirstByClassAttribute(String classAttribute) {
public void open() {
var mc = MinecraftClient.getInstance();
if (mc.currentScreen != this)
- mc.setScreen(this);
+ mc.execute(() -> mc.setScreen(this));
}
}
diff --git a/src/main/java/io/github/itzispyder/improperui/render/math/Color.java b/src/main/java/io/github/itzispyder/improperui/render/math/Color.java
index deb6081..88a9221 100644
--- a/src/main/java/io/github/itzispyder/improperui/render/math/Color.java
+++ b/src/main/java/io/github/itzispyder/improperui/render/math/Color.java
@@ -123,16 +123,16 @@ public Color withAlpha(int a) {
return new Color(a, r, g, b);
}
- public void withRed(int r) {
- new Color(a, r, g, b);
+ public Color withRed(int r) {
+ return new Color(a, r, g, b);
}
- public void withBlue(int g) {
- new Color(a, r, g, b);
+ public Color withBlue(int g) {
+ return new Color(a, r, g, b);
}
- public void withGreen(int b) {
- new Color(a, r, g, b);
+ public Color withGreen(int b) {
+ return new Color(a, r, g, b);
}
public int getAlpha() {
diff --git a/src/main/java/io/github/itzispyder/improperui/script/ScriptParser.java b/src/main/java/io/github/itzispyder/improperui/script/ScriptParser.java
index 1e7d05c..1b93abe 100644
--- a/src/main/java/io/github/itzispyder/improperui/script/ScriptParser.java
+++ b/src/main/java/io/github/itzispyder/improperui/script/ScriptParser.java
@@ -2,12 +2,9 @@
import io.github.itzispyder.improperui.config.PropertyCache;
import io.github.itzispyder.improperui.render.Element;
-import io.github.itzispyder.improperui.render.ImproperUIPanel;
import io.github.itzispyder.improperui.render.elements.*;
-import io.github.itzispyder.improperui.script.callbacks.BuiltInCallbacks;
import io.github.itzispyder.improperui.util.ChatUtils;
import io.github.itzispyder.improperui.util.StringUtils;
-import net.minecraft.client.MinecraftClient;
import java.io.File;
import java.util.ArrayList;
@@ -58,31 +55,7 @@ public static PropertyCache getCache(String modId) {
this.put("h6", () -> new Header(0.8F));
}};
- public static void main(String[] args) {
- parseFile(new File("src/main/resources/assets/improperui/scripts/skibidi.ui"));
- }
-
- public static void run(File file) {
- var elements = parseFile(file);
- var mc = MinecraftClient.getInstance();
-
- ImproperUIPanel panel = new ImproperUIPanel();
- panel.registerCallback(new BuiltInCallbacks());
- elements.forEach(panel::addChild);
-
- mc.execute(() -> mc.setScreen(panel));
- }
-
- public static void run(String script) {
- var elements = parse(script);
- var mc = MinecraftClient.getInstance();
- ImproperUIPanel panel = new ImproperUIPanel();
- panel.registerCallback(new BuiltInCallbacks());
- elements.forEach(panel::addChild);
-
- mc.execute(() -> mc.setScreen(panel));
- }
public static List parseFile(File file) {
if (file == null || !file.exists())