1. How does that work? Maybe give an example code or something like that? Would be helpful. Thanks.
     
  2. Wulf

    Wulf Community Admin

  3. are there examples or do I need to just try out lol
    [DOUBLEPOST=1438877066][/DOUBLEPOST]I can't get it to work lol.
     
  4. really simple one i used to try things out:
    Code:
    using Oxide.Game.Rust.Cui;using UnityEngine;namespace Oxide.Plugins
    {
        [Info("CuiExample", "Nogrod", "0.0.1")]
        internal class CuiExample : RustPlugin
        {
            [ChatCommand("cui")]
            private void cmdCui(BasePlayer player, string command, string[] args)
            {
                var elements = new CuiElementContainer();
                var mainName = elements.Add(new CuiPanel
                {
                    Image =
                    {
                        Color = "0.1 0.1 0.1 1"
                    },
                    RectTransform =
                    {
                        AnchorMin = "0.8 0.25",
                        AnchorMax = "0.995 0.8"
                    },
                    CursorEnabled = true
                });
                var closeButton = new CuiButton
                {
                    Button =
                    {
                        Close = mainName,
                        Color = "0.8 0.8 0.8 0.2"
                    },
                    RectTransform =
                    {
                        AnchorMin = "0.86 0.92",
                        AnchorMax = "0.97 0.98"
                    },
                    Text =
                    {
                        Text = "X",
                        FontSize = 22,
                        Align = TextAnchor.MiddleCenter
                    }
                };
                elements.Add(closeButton, mainName);
                for (var i = 2; i < 10; i++)
                {
                    elements.Add(new CuiLabel
                    {
                        Text =
                        {
                            Text = "hello " + i,
                            FontSize = 18,
                            Align = TextAnchor.MiddleCenter
                        },
                        RectTransform =
                        {
                            AnchorMin = $"0.06 {1 - 0.07*i + 0.006}",
                            AnchorMax = $"0.75 {1 - 0.07*(i - 1)}"
                        }
                    }, mainName);
                    elements.Add(new CuiButton
                    {
                        Button =
                        {
                            Command = "cui" + i,
                            Color = "0.8 0.8 0.8 0.2"
                        },
                        RectTransform =
                        {
                            AnchorMin = $"0.76 {1 - 0.07*i + 0.006}",
                            AnchorMax = $"0.87 {1 - 0.07*(i - 1)}"
                        },
                        Text =
                        {
                            Text = "+",
                            FontSize = 22,
                            Align = TextAnchor.MiddleCenter
                        }
                    }, mainName);
                }
                Puts(elements.ToString());
                CuiHelper.AddUi(player, elements);
            }
        }
    }
    
     
  5. @Nogrod: how can I access the `Oxide.Game.Rust.Cui` namespace in JavaScript? Using `importNamespace('Cui') or something?
     
  6. Wulf

    Wulf Community Admin

    Pretty sure you just call it with Cui, the rest is already imported as far as I know. Otherwise, calling a method/function with the full namespace should work.
     
  7. Alrighty, I'll make a thread if something doesn't work as expected. :)
     
  8. How to use new line ('\n') for text?
    '\n' method not working, and <br/> :-(

    How to destroy elements?
    Code:
    CuiHelper.DestroyUi(player, CuiHelper.ToJson(elements));
     
    Last edited by a moderator: Aug 11, 2015
  9. havn't tried a new line so far, i'll check it if there is time and no one else is faster:p, but to destroy elements you need to pass the name:
    Code:
    CuiHelper.DestroyUi(player, "elementName");
     
  10. What is an element name?
    Please, state it from your example above

    Solved:
    Code:
    CuiHelper.DestroyUi(player, mainName); // from example by Nogrod
     
  11. How to choose a color?
     
  12. Code:
                   elements.Add(new CuiButton
                    {
                        Button =
                        {
                            Command = "cui" + i,
                            Color = "0.8 0.8 0.8 0.2"
                        },
    Color Values - PyMOLWiki
     
    Last edited by a moderator: Oct 30, 2015
  13. I got into some CUI playing today .. so i decided to set it to HitmarkerGUI

    With json i was doing (Overlay and type RawImage)
    Code:
    {
                                ""name"": ""HitMarkerImage"",
                                ""parent"": ""HUD/Overlay"",
                                ""components"":
                                [
                                   {
                                        ""type"":""UnityEngine.UI.RawImage"",
                                        ""imagetype"": ""Tiled"",
                                        ""color"": ""1.0 1.0 1.0 1.0"",
                                        ""url"": ""{url}"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.49 0.48"",
                                        ""anchormax"": ""0.51 0.52""
                                    }
                                ]
                            }
    
    I tried with CUI helper and i came up with
    Code:
    var elements = new CuiElementContainer();
                            var mainName = elements.Add(new CuiPanel //
                            {
                                Image =
                                {
                                    Color = "0.1 0.1 0.1 0.0"
                                },
                                RectTransform =
                                {
                                    AnchorMin = "0.49 0.48",
                                    AnchorMax = "0.51 0.52"
                                },
                                CursorEnabled = false
                            });
                            elements.Add(new CuiRawImageComponent
                            {
                                    Url = "http://oxidemod.org/attachments/fuzidev_2-png.10926/"
                            }, mainName);
    CuiHelper.AddUi(attacker, elements);
    ....
    
    I get Check this screenshot! (click it) .... I kind of understand the helper but not that much.

    Any ideas ;x?
     
  14. If you look at line 151 and 264 in RustCui.cs, maybe this will help
     
  15. I want RawImage not Image these are two different types..
     
    Last edited by a moderator: Nov 7, 2015
  16. for now you should have:
    Code:
    var elements = new CuiElementContainer();
    elements.Add(new CuiElement
    {
        Name = "HitMarkerImage",
        Parent = "HUD/Overlay",
        Components =
        {
            new CuiRawImageComponent
            {
                Url = "http://oxidemod.org/attachments/fuzidev_2-png.10926/"
            },
            new CuiRectTransformComponent
            {
                AnchorMin = "0.49 0.48",
                AnchorMax = "0.51 0.52"
            }
        }
    });
    CuiHelper.AddUi(attacker, elements);
    i'll try to extend CuiPanel to support both Image and RawImage
     
  17. Okay i started understanding the CUI helper.. its not that hard.

    I have a problem tho, everytime that i display the ui/execute the command "test"

    It kicks me with a reason RPC Error: addui

    How do i add my ui
    Code:
    void UseUIto(BasePlayer player, string text, string name)
            {
                var elements = new CuiElementContainer();
                elements.Add(new CuiElement
                {
                    Name = name,
                    Parent = "HUD/Overlay",
                    Components =
                    {
                        new CuiTextComponent
                        {
                            Text = text,
                            FontSize = 20, 
                            Align = TextAnchor.MiddleCenter
                        },
                                   
                        new CuiImageComponent
                        {
                            Color = "0.1 0.1 0.1 1"
                        },
                       
                   
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",
                            AnchorMax = "1 1"
                        }
                    }
                });
                var closeButton = new CuiButton
                {
                    Button =
                    {
                        Close = name,
                        Color = "0.8 0.8 0.8 0.2"
                    },
                    RectTransform =
                    {
                        AnchorMin = "0.3 0.16",
                        AnchorMax = "0.7 0.2"
                    },
                    Text =
                    {
                        Text = "I agree",
                        FontSize = 22,
                        Align = TextAnchor.MiddleCenter
                    }
                };
                elements.Add(closeButton, name);
                CuiHelper.AddUi(player, elements);
            }
    void OnPlayerInit(BasePlayer player)
    {
    //some kind of checks/timers
    UseUIto(player, "TestMessage", "RulesGUI");
    }
    
     
  18. Wulf

    Wulf Community Admin

    That means you are setting something wrong, or trying to use something that doesn't exist. One thing I notice is that you aren't adding your button to the container. You're also using some things that aren't available in certain Cui types I believe.
     
  19. I know this thread is old, but it still shows up if we search "Javascript" so, here's a sweet link Javascript CuiHelper plugin/lib [WIP] | Oxide
     
  20. Hey guys, how to use CuiTextComponent?