Skip to content

Commit

Permalink
fixed screen resize issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ItziSpyder committed May 15, 2024
1 parent 01e341a commit be0821a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 63 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```
<br>
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 2 additions & 20 deletions src/main/java/io/github/itzispyder/improperui/ImproperUIAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -61,23 +60,8 @@ public static List<Element> 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();
}

/**
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ImproperUIPanel extends Screen {
private final List<Element> children;
private final List<CallbackListener> callbackListeners;

private File uiScriptAsFile;
private String uiScriptAsString;

public ImproperUIPanel() {
super(Text.of("Custom Scripted Panel Screen"));
children = new ArrayList<>();
Expand All @@ -42,10 +45,12 @@ public ImproperUIPanel(List<Element> 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Element> parseFile(File file) {
if (file == null || !file.exists())
Expand Down

0 comments on commit be0821a

Please sign in to comment.