lel no thx to me. okay. okay.
![]()
Community entity UI
Discussion in 'Rust Development' started by ShadowEvil, Jun 5, 2015.
-
He didnt see your reply -
lol laser sorry i didnt see your reply as you posted 2 things at the same time, didnt see one was for me
thx ^^ i was wondering if we could use arguments, but i can see we can ^^
[DOUBLEPOST=1438218663,1438202475][/DOUBLEPOST]this string json is very confusing having to put double " and stuff ...
anyone could tell me how i can mix 2 json strings together please?
Code:string json = @"[ { ""name"": ""TestButton"", ""parent"": ""Overlay"", ""components"": [ { ""type"":""UnityEngine.UI.Button"", ""close"":""TestButton"", ""command"":""chat.say 'Button was pressed!'"", ""color"": ""0.3 0.6 0.4 0.8"", ""imagetype"": ""Tiled"" }, { ""type"":""RectTransform"", ""anchormin"": ""0.2 0.15"", ""anchormax"": ""0.8 0.25"" } ] } ] "; string json2 = @"[ { ""name"": ""TestButton2"", ""parent"": ""Overlay"", ""components"": [ { ""type"":""UnityEngine.UI.Button"", ""close"":""TestButton2"", ""command"":""chat.say 'Button 2 was pressed!'"", ""color"": ""0.3 0.6 0.4 0.8"", ""imagetype"": ""Tiled"" }, { ""type"":""RectTransform"", ""anchormin"": ""0.9 0.15"", ""anchormax"": ""0.95 0.25"" } ] } ] ";
this is a bad exemple but i hope you guys get what i'm trying to do ^^ -
Code:
string json = @" [ { ""name"": ""TestButton"", ""parent"": ""Overlay"", ""components"": [ { ""type"": ""UnityEngine.UI.Button"", ""close"": ""TestButton"", ""command"": ""chat.say 'Button was pressed!'"", ""color"": ""0.3 0.6 0.4 0.8"", ""imagetype"": ""Tiled"" }, { ""type"": ""RectTransform"", ""anchormin"": ""0.2 0.15"", ""anchormax"": ""0.8 0.25"" } ] }, { ""name"": ""TestButton2"", ""parent"": ""Overlay"", ""components"": [ { ""type"": ""UnityEngine.UI.Button"", ""close"": ""TestButton2"", ""command"": ""chat.say 'Button 2 was pressed!'"", ""color"": ""0.3 0.6 0.4 0.8"", ""imagetype"": ""Tiled"" }, { ""type"": ""RectTransform"", ""anchormin"": ""0.9 0.15"", ""anchormax"": ""0.95 0.25"" } ] } ] ";
(I needed some when starting with GUI lol - cuz of all this json shitz. But after some time its barely easy):
http://rustrd.com/viewtopic.php?f=16&t=59&p=125#p125
(I know it propaply aint perfect. But its nice for me lol) -
You guys need to stop messing around and just make a small API plugin to handle the json mess.
-
I was going for something like this:
Code:void addGUI(string name, string parent, string type, string color, string anchormin, string anchormax) but more specific for that shop...
-
That's what I meant
-
laser i know ^^
but i want it to be dynamic, basically use it in a foreach, so it will create as much button as there is in the foreach.
that's why i need them to add themselves and not it to be static.
[DOUBLEPOST=1438258172][/DOUBLEPOST]well i guess i could also create multiple GUIs and save them in a List<string> to destroy them when finished. -
Code:using System.Collections.Generic; using System.Reflection; using System; using UnityEngine; using System.Linq;namespace Oxide.Plugins { [Info("Dynamic GUI Example", "LaserHydra", "1.0.0", ResourceId = 0)] [Description("a Dynamic GUI Example")] class DynamicGUI : RustPlugin { #region GUI string json = @"[ { ""name"": ""{NAME}{RANDOM}"", ""parent"": ""{PARENT}"", ""components"": [ { ""type"": ""{TYPE}"", ""close"": ""{NAME}{RANDOM}"", ""command"": ""{COMMAND}'"", ""color"": ""{COLOR}"", ""imagetype"": ""Tiled"" }, { ""type"": ""RectTransform"", ""anchormin"": ""{ANCHORMIN}"", ""anchormax"": ""{ANCHORMAX}"" } ] } ] "; #endregion // On Plugin Load: Call Config void Loaded() { LoadDefaultConfig(); } // Load config protected override void LoadDefaultConfig() { Dictionary<string, string> TestButton = new Dictionary<string, string>(); TestButton.Add("{NAME}", "TestButton"); TestButton.Add("{TYPE}", "UnityEngine.UI.Button"); TestButton.Add("{PARENT}", "Overlay"); TestButton.Add("{COMMAND}", "chat.say 'Button was pressed!'"); TestButton.Add("{COLOR}", "0.3 0.6 0.4 0.8"); TestButton.Add("{ANCHORMIN}", "0.2 0.15"); TestButton.Add("{ANCHORMAX}", "0.8 0.25"); GUIConfig("GUI", "TestButton", TestButton); Dictionary<string, string> TestButton2 = new Dictionary<string, string>(); TestButton2.Add("{NAME}", "TestButton2"); TestButton2.Add("{TYPE}", "UnityEngine.UI.Button"); TestButton2.Add("{PARENT}", "Overlay"); TestButton2.Add("{COMMAND}", "chat.say 'Button 2 was pressed!'"); TestButton2.Add("{COLOR}", "0.3 0.6 0.4 0.8"); TestButton2.Add("{ANCHORMIN}", "0.9 0.15"); TestButton2.Add("{ANCHORMAX}", "0.95 0.25"); GUIConfig("GUI", "TestButton2", TestButton2); } // Generate a Random String string GetRandomString(int length) { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var random = new System.Random(); var result = new string( Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]) .ToArray()); return result; } // Generate a Config styled for GUI void GUIConfig(string GroupName, string DataName, Dictionary<string, string> Data) { if (Config[GroupName, DataName] == null) Config[GroupName, DataName] = Data; if (Config[GroupName, DataName] as Dictionary<string, string> != Data) return; } // Draw dynamic GUI [ChatCommand("draw_gui")] void cmdDrawGUI(BasePlayer player) { foreach(var curConfig in Config) { if("GUI" != curConfig.Key.ToString()) continue; foreach(var current in curConfig.Value as Dictionary<string, object>) { string GUI = json; Dictionary<string, object> list = current.Value as Dictionary<string, object>; foreach(var Key in list.Keys) { GUI = GUI.Replace(Key.ToString(), list[Key.ToString()].ToString()); } GUI = GUI.Replace("{RANDOM}", GetRandomString(5)); CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", GUI); } } } } }
Hope that helps.
With this you should even be able to add GUI using the Config
- LaserLast edited by a moderator: Jul 30, 2015 -
aha thx ^^
was going to do something like that ^^ -
[DOUBLEPOST=1438272249,1438258534][/DOUBLEPOST]I made my shop more dynamic and simple lol.
Just need one line to add a new Item now.
Code:DrawShopItem(player, "AK", "AK-47u", "rifle_ak", "http://vignette3.wikia.nocookie.net/play-rust/images/d/d1/Assault_Rifle_icon.png/revision/latest/scale-to-width-down/480?cb=20150405105940", GetRandomString(5));
-
what you do is create 1 main overlay
then you add 1 by 1 the items and set the overlay as parent
so when you close the shop it closes everything.
am i right?
(that's what i did for the kits, but i can't test it so i don't know if it will work XD) -
-
no, i know ^^ but it's a type: overlay ^^
-
In this quote it seems like you are pulling in an image off the net? is that correct? if so i was hoping you would be so kind as to post that snippet of the json as i havnt been able to work out how to display an image off the net yet. -
Code:
{ ""name"": ""WebImage"", ""parent"": ""Overlay"", ""components"": [ { ""type"":""UnityEngine.UI.RawImage"", ""imagetype"": ""Tiled"", ""color"": ""1.0 1.0 1.0 1.0"", ""url"": ""{URL}"" }, { ""type"":""RectTransform"", ""anchormin"": ""0 0"", ""anchormax"": ""1 1"" } ] }
-
Can someone give me an example on how to make an icon pressable ? Like i know that we can add buttons and stuff but i want to make an Overlay clickable or sth like that ? Or even to add an image on the button.
-
Calytic Community Admin Community Mod
You have to add the image as a child of the button (using "parent") with the position: left 0, top 0, width 100% height 100%.
-
Hi!
I just started playing with this UI thing. But i ran into a problem and can't figure it out
Code:using System; using System.Collections.Generic; using Oxide.Core; using UnityEngine; using Rust;namespace Oxide.Plugins { [Info("GhosstClock", "Ghosst", 0.1)] [Description("Basic in-game clock")] public class GhosstClock : RustPlugin { private TOD_Sky sky; private DateTime dt; private Timer TimeUpdater; private string time = ""; private int playerCounter = 0; void Init() { Puts("Init works!"); } private void OnServerInitialized() { sky = TOD_Sky.Instance; RefreshTime(); TimeUpdater = timer.Repeat(2, 0, () => RefreshTime()); Puts("Load works!"); } private void Unload() { DestroyGUI(); } private void RefreshTime() { dt = sky.Cycle.DateTime; TimeToHuman(); DestroyGUI(); AddGUI(); Puts("Refresh"); } private void DestroyGUI() { foreach (BasePlayer bp in BasePlayer.activePlayerList) CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(bp.net.connection), null, "DestroyUI", "GhosstPanel"); } private void AddGUI() { foreach (BasePlayer bp in BasePlayer.activePlayerList) { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(bp.net.connection), null, "AddUI", json.Replace("{timee}", time)); } } private void TimeToHuman() { time = dt.ToString("HH:mm"); } [ChatCommand("gclockshow")] private void ChatTime(BasePlayer player, string command, string[] args) { PrintToChat(player, time); } #region JSON private string json = @" [{ ""name"": ""GhosstPanel"", ""parent"": ""Overlay"", ""components"": [ { ""type"": ""UnityEngine.UI.Image"", ""color"": ""0.1 0.1 0.1 0.3"" }, { ""type"": ""RectTransform"", ""anchormin"": ""0.2 0.05"", ""anchormax"": ""0.25 0.08"" }, ] }, { ""name"": ""GClock"", ""parent"": ""GhosstPanel"", ""components"": [ { ""type"": ""UnityEngine.UI.Button"", ""color"": ""0.1 0.2 0.3 0.5"", ""imagetype"": ""Tiled"" }, { ""type"": ""RectTransform"", ""anchormin"": ""0.1 0.1"", ""anchormax"": ""0.9 0.9"" }, ] }, { ""name"": ""ClockText"", ""parent"": ""GClock"", ""components"": [ { ""type"": ""UnityEngine.UI.Text"", ""text"": ""{timee}"", ""fontSize"": ""14"", ""align"": ""MiddleCenter"" }, { ""type"": ""RectTransform"", ""anchormin"": ""0 0"", ""anchormax"": ""1 1"" } ] },]"; #endregion }}
Any idea? -