Skip to content

Commit

Permalink
Initial GUI support (#29)
Browse files Browse the repository at this point in the history
* Initial setup & a few base types

* Scroll panels (not tested yet)

* Buttons, enum util, better id handling, cleanups

* Text support, `getTaggedObject`

* Insets support

* Labels and dynamic labels

* Registration based system

* Allow specifying GUI scripts as widgets

* Proper `registerGuiElement` error checking

* Cleaner insets handling

* Cleanup button handling

* Item elements

* Debug handling rework/cleanup

* Improve dynamic label error handling

* Scroll panel scroll speed setters

* Text field elements

* Grid panels

* Box elements

* Slider elements

* Progress bars

* Improve texture parsing, minor cleanups

* Cleaner icon format

* Sprite elements

* Fix texture/icon parsing no value handling

* Toggle buttons

* Cleaner path handling

* Error handling & context fixups

* No wildcard static imports

* Minor cleanups to tab panel parsing

* Plain panels: match naming for child widgets

* Initial work on meta

* Bar documentation

* Document insets, textures, and icons

* Finalize `gui` command

* Box elements meta

* Button meta, minor cleanups, remove event for now

* Dynamic label element

* Grid panel meta + minor rename for consistency

* Item elements meta

* Slider element meta

* Labeled slider meta

* Properly document slider context values

* Label elements meta

* Plain panel elements meta

* Scroll panel elements meta

* Sprite element meta docs

* Tab panel element meta

* Text element meta

* Text field elements meta

* Toggle buttons meta docs

* Consistency

* Bump LibGUI and other deps

* Revert outdated `ItemTag` change

* `getTaggedStringList`: support in-line `ListTag`s

* `bar` -> `progress_bar`

* Consistent box panel naming

* Clearer dynamic label warning

* Grid panels: `gap` -> `spacing`

* Sliders: direction must match axis

* Clarify slider dynamic label meta

* `Item` element: `duration` -> `frame_duration`

* UV handling: width & height instead of 2 points

* Better gui script handling in screen event

* `GUI` command: support closing

* Why is `gui` `Holdable`

* `SpriteElement`: `frame_time` -> `duration`

* `TextFieldElement`: consistent naming

* Fix `gui` command syntax

* Meta fixup
  • Loading branch information
tal5 committed Dec 27, 2023
1 parent f0c361a commit 0c802bb
Show file tree
Hide file tree
Showing 26 changed files with 1,758 additions and 41 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Expand Up @@ -12,6 +12,7 @@ indent_style = space

[*.java]
indent_style = space
ij_java_names_count_to_use_import_on_demand = 1000 # never

[*.json]
indent_style = space
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Expand Up @@ -4,8 +4,8 @@ org.gradle.parallel = true

# Fabric Properties
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.0
yarn_mappings=1.20.4+build.3
loader_version=0.15.2

# Mod Properties
version = beta-1.0
Expand All @@ -14,8 +14,8 @@ maven_group = com.denizenscript
archives_base_name = clientizen

# Dependencies
fabric_version=0.91.1+1.20.4
libgui_version=9.2.0+1.20.2
fabric_version=0.91.2+1.20.4
libgui_version=9.2.1+1.20.2
denizencore_version=1.91.0-SNAPSHOT
snakeyaml_version=1.33
devauth_version=1.1.2
Expand Up @@ -22,7 +22,7 @@ public class ScreenOpenCloseEvent extends ScriptEvent {
//
// @Context
// <context.screen_type> returns an ElementTag of the screen type that opened/closed.
// <context.previous_screen_type> returns an ElementTag of the screen this screen was opened from, if any.
// <context.previous_screen_type> returns an ElementTag of the screen type this screen was opened from, if any.
//
// -->

Expand Down Expand Up @@ -71,8 +71,8 @@ public void handleScreenChange(Screen screen, Screen previousScreen, boolean ope
if (!eventData.isEnabled) {
return;
}
type = ScreenNameMapping.getScreenName(screen.getClass());
previousType = previousScreen != null ? ScreenNameMapping.getScreenName(previousScreen.getClass()) : null;
type = ScreenNameMapping.getScreenName(screen);
previousType = previousScreen != null ? ScreenNameMapping.getScreenName(previousScreen) : null;
opened = open;
fire();
}
Expand Down
@@ -1,36 +1,80 @@
package com.denizenscript.clientizen.scripts.commands;

import com.denizenscript.clientizen.scripts.containers.GuiScriptContainer;
import com.denizenscript.clientizen.scripts.containers.gui.GuiScriptContainer;
import com.denizenscript.clientizen.scripts.containers.gui.GuiScriptGuiDescription;
import com.denizenscript.clientizen.scripts.containers.gui.GuiScriptScreen;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.scripts.commands.Holdable;
import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull;
import com.denizenscript.denizencore.scripts.commands.generator.ArgLinear;
import com.denizenscript.denizencore.scripts.commands.generator.ArgName;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import io.github.cottonmc.cotton.gui.widget.WPanel;
import net.minecraft.client.MinecraftClient;

public class GuiCommand extends AbstractCommand implements Holdable {
public class GuiCommand extends AbstractCommand {

// <--[command]
// @Name gui
// @Syntax gui [open <script>/close]
// @Required 1
// @Maximum 2
// @Short Opens a GUI script into a GUI or closes a currently open one.
// @Group GUI System
//
// @Description
// Opens the GUI script specified as a GUI, or closes a currently open one.
// The GUI script must have a panel of any kind as it's element to be opened (which can contain any other elements within it).
//
// @Tags
// None
//
// @Usage
// Opens a GUI script named "my_gui".
// - gui open my_gui
//
// @Usage
// Closes the currently open GUI.
// - gui close
//
// -->

public GuiCommand() {
setName("gui");
setSyntax("gui [<script>]");
setRequiredArguments(1, 1);
setSyntax("gui [open <script>/close]");
setRequiredArguments(1, 2);
autoCompile();
}

public static void autoExecute(ScriptEntry scriptEntry,
@ArgLinear @ArgName("script") ScriptTag script) {
if (script.getContainer() instanceof GuiScriptContainer gui) {
/*SpruceScreen screen = new SpruceScreen(Text.literal("Test GUI screen")) {
@Override
public void addCustomTabCompletions(TabCompletionsBuilder tab) {
tab.addScriptsOfType(GuiScriptContainer.class);
}

public enum Action {OPEN, CLOSE}

@Override
protected void init() {
super.init();
addDrawableChild(new SpruceButtonWidget(Position.center(width, height), 150, 20, Text.literal(gui.buttonName), btn -> {
client.player.sendMessage(Text.literal("hello"), false);
}));
public static void autoExecute(@ArgName("action") Action action,
@ArgName("script") @ArgLinear @ArgDefaultNull ScriptTag script) {
MinecraftClient client = MinecraftClient.getInstance();
switch (action) {
case OPEN -> {
if (script == null) {
throw new InvalidArgumentsRuntimeException("Must specify a GUI script to open.");
}
if (!(script.getContainer() instanceof GuiScriptContainer guiScript)) {
Debug.echoError("Invalid script '" + script.debuggable() + "<W>' specified: must be a GUI script.");
return;
}
WPanel rootPanel = guiScript.createGUIRoot();
if (rootPanel == null) {
Debug.echoError("GUI script '" + script.debuggable() + "<W>' is invalid.");
return;
}
};
screen.init(MinecraftClient.getInstance(), 500, 500);*/
GuiScriptScreen screen = new GuiScriptScreen(new GuiScriptGuiDescription(rootPanel), guiScript);
client.send(() -> client.setScreen(screen));
}
case CLOSE -> client.send(() -> client.setScreen(null));
}
}
}
@@ -1,5 +1,6 @@
package com.denizenscript.clientizen.scripts.containers;

import com.denizenscript.clientizen.scripts.containers.gui.GuiScriptContainer;
import com.denizenscript.denizencore.scripts.ScriptRegistry;

public class ClientizenContainerRegistry {
Expand Down

This file was deleted.

0 comments on commit 0c802bb

Please sign in to comment.