#if defined _overlay_included #endinput #endif #define _overlay_included #include native bool SendTempUI(int client, const char[] id, int lifetime, JSONObject element); native bool ShowUI(int client, const char[] elemNamespace, const char[] elemId, JSONObject variables); native bool HideUI(int client, const char[] elemNamespace, const char[] elemId); native bool PlayAudio(int client, const char[] url); native bool IsOverlayConnected(); forward void OnUIAction(const char[] elemNamespace, const char[] elemId, const char[] action); typedef UIActionCallback = function void (const char[][] args, int numArgs); methodmap UIElement < JSONObject { public UIElement(const char[] elemNamespace, const char[] elemId) { JSONObject obj = new JSONObject(); obj.SetString("namespace", elemNamespace); obj.SetString("elem_id", elemId); obj.SetBool("visibility", false); obj.Set("variables", new JSONObject()); return view_as(obj); } property bool Visible { public get() { return view_as(this).GetBool("visibility"); } public set(bool value) { view_as(this).SetBool("visibility", value); this.Send(); } } /** Is the UI element globally sent to all connected players? * Specify players with .AddClient() or clear with .ClearClients() */ property bool Global { public get() { return !view_as(this).HasKey("steamids") } } public void SetVariable(const char[] id, JSON json) { view_as(this).Set(id, json); } public void SetVariableInt(const char[] id, int value) { view_as(this).SetInt(id, value); } public void SetVariableFloat(const char[] id, float value) { view_as(this).SetFloat(id, value); } public void SetVariableString(const char[] id, const char[] value) { view_as(this).SetString(id, value); } public void SetVariableBool(const char[] id, bool value) { view_as(this).SetBool(id, value); } public void SetActionCallback(UIActionCallback callback) {} public void AddClient(const char[] steamid) { // if(!IsClientInGame(client) || steamidCache[client][0] == '\0') ThrowError("Client %d is not connected, ingame, or authorized"); JSONObject obj = view_as(this); JSONArray steamids = view_as(obj.Get("steamids")); if(steamids == null) { steamids = new JSONArray(); obj.Set("steamids", steamids) } steamids.PushString(steamid); } public void ClearClients() { view_as(this).Remove("steamids"); } public void Clear() { view_as(this).Clear(); } public void Hide() { this.Visibility = false; } public void Show() { this.Visibility = true; } public native bool Send(); } methodmap UIPosition < JSONObject { public UIPosition(int x = 0, int y = 0) { JSONObject obj = new JSONObject(); obj.SetInt("x", x); obj.SetInt("y", y); return view_as(obj); } property int X { public get() { return view_as(this).GetInt("x"); } 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) { view_as(this).SetInt("y", coord); } } } 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(); obj.SetInt("r", r); obj.SetInt("g", g); obj.SetInt("g", b); return view_as(obj); } property int R { public get() { return view_as(this).GetInt("r"); } 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) { view_as(this).SetInt("g", value); } } property int B { public get() { return view_as(this).GetInt("b"); } public set(int value) { view_as(this).SetInt("b", value); } } } enum UIVisibility { /// Always show Vis_Always = 0, /// Only show when overlay is in interact mode or edit mode Vis_InteractableOnly, /// Only show when overlay is in non-interactable mode or edit mode Vis_DisplayOnly } methodmap TempUIElementDefaults < JSONObject { public TempUIElementDefaults() { JSONObject obj = new JSONObject(); obj.Set("position", new UIPosition(0, 0)) obj.Set("bgColor", new UIColor()); obj.SetInt("visibility", 0); return view_as(obj); } public bool GetTitle(char[] output, int maxlen) { view_as(this).GetString("title", output, maxlen); } public bool SetTitle(const char[] title) { view_as(this).SetString("title", title); } property UIPosition Position { 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(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 { public get() { JSONObject obj = view_as(this); if(!obj.HasKey("opacity")) return -1; return obj.GetInt("opacity"); } public set(int value) { JSONObject obj = view_as(this); if(value == -1) obj.Remove("opacity") else obj.SetInt("opacity", value); } } property UIVisibility Visibility { public get() { return view_as(view_as(this).GetInt("visibility")); } public set(UIVisibility value) { view_as(this).SetInt("visibility", view_as(value)) } } } enum UIType { Element_Unknown = -1, Element_Text, Element_List, } enum UIFlags { Element_None } #define UI_TYPES_MAX 2 char UI_TYPE_IDS[UI_TYPES_MAX][] = { "text", // Element_Text "list" // Element_List } methodmap TempUIElement < JSONObject { public TempUIElement(const char[] type) { JSONObject obj = new JSONObject(); obj.Set("defaults", new TempUIElementDefaults()); obj.SetInt("flags", 0); obj.SetString("type", type); return view_as(obj); } property UIType Type { public get() { char type[32]; view_as(this).GetString("type", type, sizeof(type)); for(int i = 0; i < UI_TYPES_MAX; i++) { if(StrEqual(type, UI_TYPE_IDS[i])) { return view_as(i); } } return Element_Unknown } public set(UIType type) { view_as(this).SetString("type", UI_TYPE_IDS[view_as(type)]); } } property TempUIElementDefaults 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); } public void SetVariableInt(const char[] id, int value) { view_as(this).SetInt(id, value); } public void SetVariableFloat(const char[] id, float value) { view_as(this).SetFloat(id, value); } public void SetVariableString(const char[] id, const char[] value) { view_as(this).SetString(id, value); } public void SetVariableBool(const char[] id, bool value) { view_as(this).SetBool(id, value); } } methodmap TextElement < TempUIElement { public TextElement() { TempUIElement elem = new TempUIElement("text"); return view_as(elem); } public void GetTemplate(char[] output, int maxlen) { view_as(this).GetString("template", output, maxlen); } public void SetTemplate(const char[] template) { view_as(this).SetString("template", template); } } methodmap TempUI { /** Creates a new TempUI with an optional predefined option * @param elemId a unique id of temp element * @param The lifetime (in seconds) of element until element is deleted. 0 for never */ public TempUI(const char[] elemId, const char[] type, int lifetime = 0) { JSONObject obj = new JSONObject(); obj.SetString("elem_id", elemId); TempUIElement element = new TempUIElement(type); obj.Set("element", element); return view_as(obj); } property bool Visible { public get() { return view_as(this).GetBool("visibility"); } public set(bool value) { view_as(this).SetBool("visibility", value); this.Send(); } } /** Is the UI element globally sent to all connected players? * Specify players with .AddClient() or clear with .ClearClients() */ property bool Global { public get() { return !view_as(this).HasKey("steamids") } } property TempUIElement Element { public get() { return view_as(view_as(this).Get("element")); } public set(TempUIElement newElement) { view_as(this).Set("element", view_as(newElement)); } } public void SetActionCallback(UIActionCallback callback) {} public void AddClient(const char[] steamid) { // if(!IsClientInGame(client) || steamidCache[client][0] == '\0') ThrowError("Client %d is not connected, ingame, or authorized"); JSONObject obj = view_as(this); JSONArray steamids = view_as(obj.Get("steamids")); if(steamids == null) { steamids = new JSONArray(); obj.Set("steamids", steamids) } steamids.PushString(steamid); } public void ClearClients() { view_as(this).Remove("steamids"); } public void Clear() { view_as(this).Clear(); } public void Hide() { this.Visibility = false; } public void Show() { this.Visibility = true; } public native bool Send(); }