1. I am having this issue too at the moment. It shows the first time the UI is created, then second time I call it, the button text isn't there anymore. Was this bypassed by giving the UI elements random names?
     
  2. Exactly. Unfortunately this is the only way.

    p.s Seems they're not even interested in this problem. Almost a month.
    Bug report: https://github.com/Facepunch/rust-community/issues/3
     
  3. Do anyone have an example on how to do the random name in the json constant? I looked at what AlexALX_[rus-ua] wrote, but I think I am doing something wrong. I don't know how to change the string inside a json. This is what I have:
    Code:
    using Oxide.Core.Plugins;
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Oxide.Core;
    using System.Reflection;
    using System.Data;
    using UnityEngine;
    using Rust;namespace Oxide.Plugins
    {
        [Info("GUI", "Carbonade", "0.0.1")]
        class GUI : RustPlugin
        {
            public string RndName = ((int)Math.Round(UnityEngine.Random.Range(0f, 10000000f))).ToString();
            #region JSON
            const string json = @"[
                            {
                                ""name"": ""UIBackground{RndName}"",
                                ""parent"": ""Overlay"",
                                ""components"":
                                [
                                    {
                                         ""type"":""UnityEngine.UI.Image"",
                                         ""color"":""0.1 0.1 0.1 0.7"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.05 0.05"",
                                        ""anchormax"": ""0.95 0.95""
                                    },
                                    {
                                        ""type"":""NeedsCursor""
                                    }
                                ]
                            },
                            {
                                ""name"": ""UITopBar{RndName}"",
                                ""parent"": ""UIBackground{RndName}"",
                                ""components"":
                                [
                                    {
                                         ""type"":""UnityEngine.UI.Image"",
                                         ""color"":""0.1 0.1 0.5 0.0"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.0 0.9"",
                                        ""anchormax"": ""1.00 1.00""
                                    },
                                ]
                            },
                            {
                                ""name"": ""UIBottomBar{RndName}"",
                                ""parent"": ""UIBackground{RndName}"",
                                ""components"":
                                [
                                    {
                                         ""type"":""UnityEngine.UI.Image"",
                                         ""color"":""0.1 0.1 0.5 0.0"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.0 0.0"",
                                        ""anchormax"": ""1.0 0.1""
                                    },
                                ]
                            },
                            {
                                ""name"": ""TextExitHelp{RndName}"",
                                ""parent"": ""UITopBar{RndName}"",
                                ""components"":
                                [
                                    {
                                        ""type"":""UnityEngine.UI.Text"",
                                        ""text"":""Press to exit window ->"",
                                        ""fontSize"":12,
                                        ""align"": ""UpperRight"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.75 0.95"",
                                        ""anchormax"": ""0.95 1.00""
                                    }
                                ]
                            },
                            {
                                ""name"": ""UITitle{RndName}"",
                                ""parent"": ""UITopBar{RndName}"",
                                ""components"":
                                [
                                    {
                                        ""type"":""UnityEngine.UI.Text"",
                                        ""text"":""Title: Carbonades Test GUI"",
                                        ""fontSize"":16,
                                        ""align"": ""UpperLeft"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.05 0.95"",
                                        ""anchormax"": ""0.15 1.00""
                                    }
                                ]
                            },
                            {
                                ""name"": ""ExitButton1{RndName}"",
                                ""parent"": ""UITopBar{RndName}"",
                                ""components"":
                                [
                                    {
                                        ""type"":""UnityEngine.UI.Button"",
                                        ""close"":""UIBackground{RndName}"",
                                        ""command"":""uir"",
                                        ""color"": ""0.5 0.5 0.8 1.0"",
                                        ""imagetype"": ""Tiled""
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.95 0.95"",
                                        ""anchormax"": ""1.0 1.0""
                                    }
                                ]
                            },
                            {
                                ""name"": ""Text2{RndName}"",
                                ""parent"": ""ExitButton1{RndName}"",
                                ""components"":
                                [
                                    {
                                        ""type"":""UnityEngine.UI.Text"",
                                        ""text"":""X"",
                                        ""fontSize"":18,
                                        ""align"": ""MiddleCenter"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.05 0.05"",
                                        ""anchormax"": ""0.95 0.95""
                                    }
                                ]
                            }
                        ]
                        ";
            #endregion
            [ChatCommand("ui")]
            private void UIChatLoadCMD(BasePlayer player, string command, string[] args)
            {
                if (!player.IsAdmin())
                    return;
                CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", json);
                PrintToChat(player, "Showing GUI. Random number: " + RndName);
            }
            [ConsoleCommand("uir")]
            private void UIChatUnloadCMD(ConsoleSystem.Arg arg)
            {
                CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = arg.Player().net.connection }, null, "DestroyUI", "UIBackground{RndName}");
                RndName = ((int)Math.Round(UnityEngine.Random.Range(0f, 10000000f))).ToString();
                PrintToChat(arg.Player(), "Removing the GUI. Random number: " + RndName);
            }    }
    }
    
     
  4. Try something like this

    Code:
    ""name"": ""Text2" + UnityEngine.Random.Range(1, 1000) + @""",
    ""parent"": ""ExitButton1" + UnityEngine.Random.Range(1, 1000) + @""",
    if you want to include a Variable that contains a random value then you can just replace my example with...

    Code:
    var RndName = UnityEngine.Random.Range(1, 1000) ;""name"": ""Text2" + RndName + @""",
    ""parent"": ""ExitButton1" + RndName + @""",
     
  5. i love it already so easy to work with, i wish i knew about this before 5 hours ago lol

    well i had some fun :)
    i463^cimgpsh_orig.png
     
    Last edited by a moderator: Jul 13, 2015
  6. This is Awesome! Thanks for trying it out! :D
     
  7. its pretty easy and you don't need to name everything random names just name the top part then parent the rest under it :)

    and if anyone needs a hint on setting the data i basically just did .Replace("{level}", ""+mylevel) on the json string just as its put through the ClientRPCEx, ive released some working gui's (ones waiting to verified a announcement system)
     
  8. Can someone take a look at this JSON and figure out why the text doesn't display? Been looking at it for a while now and can't find out what's wrong:
    Code:
    [
      {
        ""name"": ""Background"",
        ""parent"": ""Overlay"",
        ""components"": [
          {
            ""type"": ""UnityEngine.UI.RawImage"",
            ""imagetype"": ""Tiled"",
            ""sprite"": ""Assets/Content/UI/UI.Background.Transparent.Radial.psd"",
            ""color"": ""0.1 0.1 0.1 0""
          },
          {
            ""type"": ""RectTransform"",
            ""anchormin"": ""0 0"",
            ""anchormax"": ""1 1""
          }
        ]
      },
      {
        ""name"": ""testButton"",
        ""parent"": ""Background"",
        ""components"": [
          {
            ""type"": ""UnityEngine.UI.Button"",
            ""command"": ""status"",
            ""sprite"": ""Assets/Content/UI/UI.Background.Transparent.Linear.psd"",
            ""color"": ""0.4 0.4 0.4 1.0"",
            ""imagetype"": ""Tiled""
          },
          {
            ""type"": ""RectTransform"",
            ""anchormin"": ""0.671 0.795"",
            ""anchormax"": ""0.966 0.859""
          }
        ]
      },
      {
        ""name"": ""testText"",
        ""parent"": ""testButton"",
        ""components"": [
          {
            ""type"": ""UnityEngine.UI.Text"",
            ""text"": ""HELLO"",
            ""fontSize"": ""20"",
            ""align"": ""MiddleCenter"",
            ""color"": ""1 1 1 1 ""
          }
        ]
      }
    ]

    Thanks in advance!
     
  9. Does the background + button show up but not the text?

    I could be that the text size is too big then if it's only the text. Does it show up the first time you display it or not at all?
     
  10. Ah yes, it showed up the first time but not after anymore because I forgot to destroy the button and text... sigh. Thanks for your response ^^
     
  11. i found the best way to solve this is parent it all under each other and just place the text under a transparent button so its still clickable so you only need to destroy by 1 name
     
  12. Does this all actually work with LUA? If yes how?
     
  13. Wulf

    Wulf Community Admin

    Yes, just piece together the JSON and pass it to the function that sends it.
     
  14. Ill give it a try
     
  15. Question for you sir: I have multiple buttons that invoke console commands (obviously). I thought I was being smart by invoking a console command called "buttonClick: *button name*". I was hoping that this way I could get one chatcommand handler like this:
    Code:
            [ConsoleCommand("buttonClick:")]
            private void SaveCommand(ConsoleSystem.Arg arg)
            {        }
    Although it seems like this doesn't work, as the handler only fires with the exact name of the command. Is there any way to work around this? Perhaps something like ConsoleCommand.Contains()?
    Because I really hate being redundant and making a different ConsoleCommand handler for every button :\. I'd much rather make one handler with a switch to handle all the buttons.

    Thanks in advance,

    DroneFW
    [DOUBLEPOST=1437175617,1437043063][/DOUBLEPOST]Bump ^^
     
  16. It may not be of great help, but here is an example of how to use it in javascript :)
    Code:
    var GUI = {
       Title : "GUI - JavaScript",
       Description : "Test GUI JavaScript",
       Author : "LEO318x",
       Version : V(0, 0, 1),
       Init : function () {
         this.GUI;
         Network = importNamespace("Network");
         global = importNamespace("");
         command.AddChatCommand("gui", this.Plugin, "GUI");
       },
       GUI : function(player){
         var JS = "[{\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"Is it from plugin?\",\"fontSize\":32,\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0.5\",\"anchormax\":\"1 0.9\"}]},{\"name\":\"Button88\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"close\":\"TestPanel7766\",\"command\":\"status\",\"color\":\"0.9 0.8 0.3 0.8\",\"imagetype\":\"Tiled\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.3 0.15\",\"anchormax\":\"0.7 0.2\"}]},{\"parent\":\"Button88\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"YES!!!!\",\"fontSize\":20,\"align\":\"MiddleCenter\"}]}]";
         var Netw = new Network.SendInfo(conection = player.net.connection);
         global.CommunityEntity.ServerInstance.ClientRPCEx(Netw, null, "AddUI", JS);
       }
    };
    
    Note: Javascript does not allow multi line strings, so you have minify the JSON code and then escape the quotes with \"
    You can use this webpage to minify the JSON string
    Code:
    http://codebeautify.org/jsonviewer
    
     
  17. im looking into it for LUA
     
  18. So i'm back to previous problem with "buttons and text makes button unclickable", after some tests i'm understand that button should not have parent, or it will glitch, but this makes writing ui much harder, because its more simplier to use RectTransform with aligment on parent, that globally. So is there possible to write "fix" for this or this is unity limitation? Or i'm doing something wrong?
     
  19. I must say, I made a UI with 3 Buttons, and all 3 are working. The only problem I have is that when I send it a 2. time, 2 of the 3 buttons hide and the text is away too. But they are normally clickable for me. Got Text on 'em