From fd2367f41f32c458e9d467456be6fa8a6f47f936 Mon Sep 17 00:00:00 2001 From: Jackz Date: Tue, 7 May 2024 13:37:49 -0500 Subject: [PATCH] Add Hide/Show methods --- scripting/include/overlay.inc | 68 +++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/scripting/include/overlay.inc b/scripting/include/overlay.inc index 02101f6..da57d7f 100644 --- a/scripting/include/overlay.inc +++ b/scripting/include/overlay.inc @@ -89,10 +89,17 @@ methodmap UIElement < JSONObject { view_as(this).Clear(); } + public void Hide() { + this.Visibility = false; + } + public void Show() { + this.Visibility = true; + } + public native bool Send(); } -methodmap UIPosition { +methodmap UIPosition < JSONObject { public UIPosition(int x = 0, int y = 0) { JSONObject obj = new JSONObject(); obj.SetInt("x", x); @@ -102,16 +109,16 @@ methodmap UIPosition { property int X { public get() { return view_as(this).GetInt("x"); } - public set(int coord) { return view_as(this).SetInt("x", coord); } + public set(int coord) { view_as(this).SetInt("x", coord); } } property int Y { public get() { return view_as(this).GetInt("y"); } - public set(int coord) { return view_as(this).SetInt("y", coord); } + public set(int coord) { view_as(this).SetInt("y", coord); } } } -methodmap UIColor { +methodmap UIColor < JSONObject { /// Creates a new UIColor with RGB between 0-255, alpha is normalized 0.0-1.0 public UIColor(int r = 255, int g = 255, int b = 255) { JSONObject obj = new JSONObject(); @@ -123,15 +130,15 @@ methodmap UIColor { property int R { public get() { return view_as(this).GetInt("r"); } - public set(int value) { return view_as(this).SetInt("r", value); } + public set(int value) { view_as(this).SetInt("r", value); } } property int G { public get() { return view_as(this).GetInt("g"); } - public set(int value) { return view_as(this).SetInt("g", value); } + public set(int value) { view_as(this).SetInt("g", value); } } property int B { public get() { return view_as(this).GetInt("b"); } - public set(int value) { return view_as(this).SetInt("b", value); } + public set(int value) { view_as(this).SetInt("b", value); } } } @@ -144,7 +151,7 @@ enum UIVisibility { Vis_DisplayOnly } -methodmap TempUIElementDefaults { +methodmap TempUIElementDefaults < JSONObject { public TempUIElementDefaults() { JSONObject obj = new JSONObject(); obj.Set("position", new UIPosition(0, 0)) @@ -154,18 +161,18 @@ methodmap TempUIElementDefaults { } public bool GetTitle(char[] output, int maxlen) { - view_as(this).GetString(output, maxlen); + view_as(this).GetString("title", output, maxlen); } public bool SetTitle(const char[] title) { - view_as(this).SetString(title); + view_as(this).SetString("title", title); } property UIPosition Position { - public get() { return view_as(this).Get("position"); } - public set(UIPosition pos) { view_as(this).Set("position", pos); } + public get() { return view_as(view_as(this).Get("position")); } + public set(UIPosition pos) { view_as(this).Set("position", view_as(pos)); } } property UIColor BackgroundColor { - public get() { return view_as(this).Get("bgColor"); } - public set(UIColor color) { view_as(this).Set("bgColor", color); } + public get() { return view_as(view_as(this).Get("bgColor")); } + public set(UIColor color) { view_as(this).Set("bgColor", view_as(color)); } } /// Returns or sets opacity, -1 is not set property int Opacity { @@ -176,8 +183,8 @@ methodmap TempUIElementDefaults { } public set(int value) { JSONObject obj = view_as(this); - if(value == -1) obj.remove("opacity") - return obj.SetInt("opacity", value); + if(value == -1) obj.Remove("opacity") + else obj.SetInt("opacity", value); } } @@ -197,6 +204,9 @@ enum UIType { Element_Text, Element_List, } +enum UIFlags { + Element_None +} #define UI_TYPES_MAX 2 char UI_TYPE_IDS[UI_TYPES_MAX][] = { @@ -205,11 +215,11 @@ char UI_TYPE_IDS[UI_TYPES_MAX][] = { } -methodmap TempUIElement { +methodmap TempUIElement < JSONObject { public TempUIElement(const char[] type) { JSONObject obj = new JSONObject(); obj.Set("defaults", new TempUIElementDefaults()); - obj.Set("flags", 0); + obj.SetInt("flags", 0); obj.SetString("type", type); return view_as(obj); @@ -232,9 +242,9 @@ methodmap TempUIElement { } property TempUIElementDefaults Defaults { - public get() { return view_as(this).Get("defaults"); } + public get() { return view_as(view_as(this).Get("defaults")); } } - + public void SetVariable(const char[] id, JSON json) { view_as(this).Set(id, json); } @@ -257,16 +267,15 @@ methodmap TempUIElement { } methodmap TextElement < TempUIElement { public TextElement() { - TempUIElement elem = new TempUIElement(); - elem.SetString("type", UI_TYPE_IDS[Element_Text]); + TempUIElement elem = new TempUIElement("text"); return view_as(elem); } public void GetTemplate(char[] output, int maxlen) { - return view_as(this).GetString("template", output, maxlen); + view_as(this).GetString("template", output, maxlen); } public void SetTemplate(const char[] template) { - return view_as(this).SetString("template", template); + view_as(this).SetString("template", template); } } @@ -304,10 +313,10 @@ methodmap TempUI { property TempUIElement Element { public get() { - return view_as(this).Get("element") + return view_as(view_as(this).Get("element")); } public set(TempUIElement newElement) { - view_as(this).Set("element", newElement); + view_as(this).Set("element", view_as(newElement)); } } @@ -332,6 +341,13 @@ methodmap TempUI { view_as(this).Clear(); } + public void Hide() { + this.Visibility = false; + } + public void Show() { + this.Visibility = true; + } + public native bool Send(); } \ No newline at end of file