How does that work? Maybe give an example code or something like that? Would be helpful. Thanks.
Working with Oxide's new "CUI Helper"
Discussion in 'Rust Development' started by LaserHydra, Aug 6, 2015.
-
Wulf Community Admin
-
are there examples or do I need to just try out lol
[DOUBLEPOST=1438877066][/DOUBLEPOST]I can't get it to work lol. -
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); } } }
-
@Nogrod: how can I access the `Oxide.Game.Rust.Cui` namespace in JavaScript? Using `importNamespace('Cui') or something?
-
Wulf Community Admin
-
Alrighty, I'll make a thread if something doesn't work as expected.
-
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 -
havn't tried a new line so far, i'll check it if there is time and no one else is faster, but to destroy elements you need to pass the name:
Code:CuiHelper.DestroyUi(player, "elementName");
-
Please, state it from your example above
Solved:
Code:CuiHelper.DestroyUi(player, mainName); // from example by Nogrod
-
How to choose a color?
-
Code:
elements.Add(new CuiButton { Button = { Command = "cui" + i, Color = "0.8 0.8 0.8 0.2" },
Last edited by a moderator: Oct 30, 2015 -
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"" } ] }
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); ....
Any ideas ;x? -
-
Last edited by a moderator: Nov 7, 2015
-
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);
-
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"); }
-
Wulf Community Admin
-
-
Hey guys, how to use CuiTextComponent?