1. lel no thx to me. okay. okay.
    :(
     
  2. LOL xD
    He didnt see your reply :p
     
  3. 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""
                                    }
                                ]
                            }
                        ]
                        ";
    
    like do something like jsonmixed = json + json2
    this is a bad exemple but i hope you guys get what i'm trying to do ^^
     
  4. 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""
                }
            ]
        }
    ]
    ";
    And here a good motivation to continue Reneb :) (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)
     
  5. You guys need to stop messing around and just make a small API plugin to handle the json mess.
     
  6. um whatever. I was just working on easier handling for that plugin you see there. That damn shop there has 1000 lines of code for GUI json only. 70 per item.
    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...
     
  7. That's what I meant :)
     
  8. 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.
     
  9. you could do it like this: (Example incoming - UNTESTED)
    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
    - Laser
     
    Last edited by a moderator: Jul 30, 2015
  10. aha thx ^^
    was going to do something like that ^^
     
  11. well yea, just did this right now. I need to implement this into my shop too lol
    [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));
     
  12. 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)
     
  13. Well, yea but don't name it Overlay. Overlay is just the space which always exists where you place stuff on
     
  14. no, i know ^^ but it's a type: overlay ^^
     
  15. Firstly thanks to everyone here, this thread has been really helpful while i have been playing with the GUI stuff.

    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.
     
  16. 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""
                                }
                            ]
                        }
     
  17. 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.
     
  18. Calytic

    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%.
     
  19. 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
        }}
    Error msg: AddUI: Unknown Parent: GClock.
    Any idea?
     
  20. Okay so the current, or well not so current, bug is that you need to keep your Names of each GUI unique. The best approach is to use something like "GUINAMHERE" + Random.Range(0, 1000000) and keep a reference of it.