-
-
Notifications
You must be signed in to change notification settings - Fork 3
AmbleScript ( LUA ) & JSON defined GUIs #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
duzos
wants to merge
38
commits into
main
Choose a base branch
from
api/gui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
6f1ab0a
json defined guis
duzos dc3db9d
woops i replaced all "json" with "registry" by accident
duzos a4915b3
add builders for each ui elements, add AmbleContainer#copyFrom to rem…
duzos de119c1
remove stupid lambda
duzos fb1d0bf
remove LVTI
duzos c605ad1
fallback msg
duzos 34c794f
add json data to error msg so they know which block it is
duzos 62b7c7e
json buttons & command running buttons
duzos 802ea35
add Lua scripting support for GUI elements
duzos 9a56e17
add LuaJ dependency for GUI scripting
duzos 1980f92
Refactor GUI scripting into general-purpose script system
duzos 30252ca
Expand Lua scripting API with world, player, entity, and item methods
duzos 4436c17
Add playSoundAt method to MinecraftData for Lua scripting support
duzos 9a69fd1
Add script lifecycle system with enable/disable/tick functionality
duzos 6f3bf61
Add server-side scripting support with ServerScriptManager and commands
duzos 853649b
Filter script command suggestions by available methods
duzos e3e1532
Address PR review feedback for AmbleScript and GUI system
duzos 9428647
Address PR review feedback: MethodHandles, getExecutor, LuaScript ref…
duzos 1116d63
Fix corrupted import in AmbleButton.java
duzos 494aa3d
Add support for checking any key in isKeyPressed
duzos bcc9d82
Add comprehensive documentation for Lua scripting and JSON GUI systems
duzos 92f7274
Add skin system API, documentation, and example scripts
duzos dc58258
Update mod_version to 1.1.16
duzos 5a993ef
Add data generation support and translation keys for skin and script …
duzos 82e84b7
Add generated test files to .gitignore
duzos 74ecf73
Refactor script suggestion providers for improved clarity and functio…
duzos 2196af3
Add cross-script function calling support and enhance Lua scripting d…
duzos 2d72265
Implement AmbleElement interface in LuaElement and add findFirstText …
duzos cd69e61
Refactor getDisplayId method to improve string manipulation for scrip…
duzos 105cf49
Merge remote-tracking branch 'origin/api/gui' into api/gui
duzos 671edfd
Add AmbleButton and AmbleText parsers for JSON element handling
duzos 50a5fec
Add AmbleEntityDisplay component for dynamic entity rendering in GUI
duzos 2c722ca
Add AmbleTextInput component and implement focus handling in GUI
duzos 760825d
Refactor command return values to use Command.SINGLE_SUCCESS for cons…
duzos 17a44e4
fix build
duzos fe0f238
Refactor command return values to use Command.SINGLE_SUCCESS for cons…
duzos a12bd5c
Add run2/ to .gitignore to exclude additional run directory
duzos 4209380
name "testmodClient" user "Dev"
duzos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
src/main/java/dev/amble/lib/client/gui/AmbleButton.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| package dev.amble.lib.client.gui; | ||
|
|
||
|
|
||
| import dev.amble.lib.AmbleKit; | ||
| import dev.amble.lib.script.lua.LuaBinder; | ||
| import dev.amble.lib.client.gui.lua.LuaElement; | ||
| import dev.amble.lib.script.AmbleScript; | ||
| import lombok.*; | ||
| import net.minecraft.client.gui.DrawContext; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.luaj.vm2.LuaValue; | ||
| import org.luaj.vm2.Varargs; | ||
| import org.luaj.vm2.lib.jse.CoerceJavaToLua; | ||
|
|
||
| import java.awt.*; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Setter | ||
| public class AmbleButton extends AmbleContainer { | ||
| private AmbleDisplayType hoverDisplay; | ||
| private AmbleDisplayType pressDisplay; | ||
| private @Nullable Runnable onClick; | ||
| private @Nullable AmbleDisplayType normalDisplay = null; | ||
| private boolean isClicked = false; | ||
| private @Nullable AmbleScript script; | ||
|
|
||
| @Override | ||
| public void onRelease(double mouseX, double mouseY, int button) { | ||
| if (onClick != null) { | ||
| onClick.run(); | ||
| } | ||
| this.setBackground( | ||
| isHovered(mouseX, mouseY) ? hoverDisplay : getNormalDisplay() | ||
| ); | ||
| this.isClicked = false; | ||
|
|
||
| if (script != null && script.onRelease() != null && !script.onRelease().isnil()) { | ||
| Varargs args = LuaValue.varargsOf(new LuaValue[]{ | ||
| LuaBinder.bind(new LuaElement(this)), | ||
| LuaValue.valueOf(mouseX), | ||
| LuaValue.valueOf(mouseY), | ||
| LuaValue.valueOf(button) | ||
| }); | ||
|
|
||
| try { | ||
| script.onRelease().invoke(args); | ||
| } catch (Exception e) { | ||
| AmbleKit.LOGGER.error("Error invoking onRelease script for AmbleButton {}:", id(), e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onClick(double mouseX, double mouseY, int button) { | ||
| this.setBackground(pressDisplay); | ||
| this.isClicked = true; | ||
|
|
||
|
|
||
| if (script != null && script.onClick() != null && !script.onClick().isnil()) { | ||
| Varargs args = LuaValue.varargsOf(new LuaValue[]{ | ||
| LuaBinder.bind(new LuaElement(this)), | ||
| LuaValue.valueOf(mouseX), | ||
| LuaValue.valueOf(mouseY), | ||
| LuaValue.valueOf(button) | ||
| }); | ||
|
|
||
| try { | ||
| script.onClick().invoke(args); | ||
| } catch (Exception e) { | ||
| AmbleKit.LOGGER.error("Error invoking onClick script for AmbleButton {}:", id(), e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void onHover(double mouseX, double mouseY) { | ||
| if (script != null && script.onHover() != null && !script.onHover().isnil()) { | ||
| Varargs args = LuaValue.varargsOf(new LuaValue[]{ | ||
| LuaBinder.bind(new LuaElement(this)), | ||
| LuaValue.valueOf(mouseX), | ||
| LuaValue.valueOf(mouseY), | ||
| }); | ||
|
|
||
| try { | ||
| script.onHover().invoke(args); | ||
| } catch (Exception e) { | ||
| AmbleKit.LOGGER.error("Error invoking onHover script for AmbleButton {}:", id(), e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
| if (isHovered(mouseX, mouseY)) { | ||
| onHover(mouseX, mouseY); | ||
| } | ||
|
|
||
| if (isClicked) { | ||
| setBackground(pressDisplay); | ||
| } else if (isHovered(mouseX, mouseY)) { | ||
| setBackground(hoverDisplay); | ||
| } else { | ||
| setBackground(getNormalDisplay()); | ||
| } | ||
|
|
||
| super.render(context, mouseX, mouseY, delta); | ||
| } | ||
|
|
||
| public @Nullable AmbleDisplayType getNormalDisplay() { | ||
| if (normalDisplay == null) { | ||
| normalDisplay = this.getBackground(); | ||
| } | ||
|
|
||
| return normalDisplay; | ||
| } | ||
|
|
||
| public void setScript(AmbleScript script) { | ||
| this.script = script; | ||
| if (script.onInit() != null && !script.onInit().isnil()) { | ||
| try { | ||
| script.onInit().call(CoerceJavaToLua.coerce(new LuaElement(this))); | ||
| } catch (Exception e) { | ||
| AmbleKit.LOGGER.error("Error invoking onInit script for AmbleButton {}:", id(), e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public static Builder buttonBuilder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public static class Builder extends AbstractBuilder<AmbleButton, Builder> { | ||
|
|
||
| @Override | ||
| protected AmbleButton create() { | ||
| return new AmbleButton(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Builder self() { | ||
| return this; | ||
| } | ||
|
|
||
| public Builder hoverDisplay(AmbleDisplayType hoverDisplay) { | ||
| container.setHoverDisplay(hoverDisplay); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder hoverDisplay(Color hoverColor) { | ||
| container.setHoverDisplay(AmbleDisplayType.color(hoverColor)); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder hoverDisplay(AmbleDisplayType.TextureData hoverTexture) { | ||
| container.setHoverDisplay(AmbleDisplayType.texture(hoverTexture)); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder pressDisplay(AmbleDisplayType pressDisplay) { | ||
| container.setPressDisplay(pressDisplay); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder pressDisplay(Color pressColor) { | ||
| container.setPressDisplay(AmbleDisplayType.color(pressColor)); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder pressDisplay(AmbleDisplayType.TextureData pressTexture) { | ||
| container.setPressDisplay(AmbleDisplayType.texture(pressTexture)); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder onClick(Runnable onClick) { | ||
| container.setOnClick(onClick); | ||
| return this; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.