Rust UI Extension
This is my first release of the UI extension that I have been working on. I made this into an extension instead of a plug-in because of the amount of classes and features that I have created and are planning on adding in the future. No more JSON required to create your UI, you now only need to use C#. (Not supporting other languages)
I simplified it as much as possible and it's a lot easier to position your controls.
You can find the extension attached below and also a simple plug-in example to help you get started.
The first thing you need to do is get the instance of the extension.
you then need to create an unassigned WindowUI to be able to create the UI.Code:private readonly Ext.RUI.RustUI _rustUI = Interface.GetMod().GetLibrary<Ext.RUI.RustUI>();
You now only need to create the window Properties and then start building your UI.Code:private WindowUI testWindow;
So each button, text, image, rawimage is called a control. So now you can start adding your controls.Code:WindowProperties windowProperties = new WindowProperties("MainWindowName"); testWindow = _rustUI.CreateNewWindow(windowProperties, new Image(new Grid(GridType.Small), new ColorData("1", "1", "1", "0.5")));
Once you are done creating your UI, you can now send the window to the player by doing this.Code:// Create Close Button testWindow.AddControl("btn_CloseWindow", new Button(new Grid(10, 10, 1, 1, GridType.Small), new ColorData("0.5", "0.5", "0.5", "0.5"), new ButtonData("MainWindow" + counter), new TextData("X"))); // Row of Buttons testWindow.AddControl("btn_one", new Button(new Grid(2, 9, 2, 1, GridType.Small), new ColorData("0.5", "0.5", "0.5", "0.5"), new TextData("one", 20, TextAnchor.MiddleCenter))); testWindow.AddControl("btn_two", new Button(new Grid(4, 9, 2, 1, GridType.Small), new ColorData("0.5", "0.5", "0.5", "0.5"), new TextData("two", 20, TextAnchor.MiddleCenter))); testWindow.AddControl("btn_three", new Button(new Grid(6, 9, 2, 1, GridType.Small), new ColorData("0.5", "0.5", "0.5", "0.5"), new TextData("three", 20, TextAnchor.MiddleCenter)));
You can also remove the window from the player by doing this.Code:testWindow.SendWindow(player);
The positioning of your controls is done by using the Grid class. I made it work similar to how unity GUI works.Code:testWindow.DestroyWindow(player);
So a Grid constructor takes 5 parameters. x start position, y start position, width of the control, height of the control, and then lastly is the GridType.
GridType has 4 options.
So positioning of a control is done by using a grid system. I will be using Excel to explain how you can use it.
- Small = 10x10 Grid
- Medium = 50x50 Grid
- Large = 100x100 Grid
- Ultra = 250x250 Grid
So lets say you wanted to work with a GridType Small. That means the grid will be using a (10 x 10) row/column space.
http://gyazo.com/bbb10f37865d7856cf6ab005a17f8b35
So using that Grid size, lets say you wanted to have your control at the top right. with a height of 2 and width of 3. It will basically look like this.
http://gyazo.com/b323073892636e7e77e67495455c8158
so in code it will be...
X and Y will be the value of the TOP RIGHT block. so x = 8 and y = 10.Code:new Grid(8, 10, 3, 2, GridType.Small)
The reason that I have different types of grid sizes, is if you wanted to create a detailed UI with a lot of buttons and text and w/e you need.
Sending a Notification
I have 3 types of ways to send a notification. You can access them by using...
Code:_rustUI.SendNotification(1, "Notification Message Here") _rustUI.SendPlayerNotification(player, "Notification Message Here") _rustUI.SendNotificationAll("Notification Message Here")This sends a notification to a specified auth level. This is best used for when you want send something ot only auth 1 or w/e you likeCode:public void SendNotification(int authLevel, string message)
This sends a notification to only one specific player.Code:public void SendPlayerNotification(BasePlayer player, string message)
This sends a notification to all active players on the server.Code:public void SendNotificationAll(string message)
For debugging purposes, you can access the raw JSON by using...
Code:testWindow.GetJSON();
My explanation is a bit short, so PLEASE do not hesitate to ask me. I will be extended this tutorial A LOT in the near future. I would first like to see who is interested in using this Extension.
P.S. Can a mod perhaps pin this if they thinks it's a useful extension for the community. Also ignore the grammar errors for now
Love,
ZuenTheMan
Rust community UI extension
Discussion in 'Rust Development' started by Zuen, Jul 13, 2015.
-
Attached Files:
Last edited by a moderator: Jul 13, 2015 -
-
Wulf Community Admin
Note: Keep in mind that this is a community provided extension, and with it we have no control over what it can do. It is not an official extension, so use at your own risk.
-
-
nice good job, but i still find the json just as easy
-
Wulf Community Admin
-
-
Still no feedback on the extension for any issues or if it is useful D: #SadPanda
-
i guess a lot people lack knowledge to even use this let alone the json way (yeah i know yours is just a wrapper for creating json) or can't be asked to spend time and want a quick plugin already made, this should help a lot of new developers you did a good thing even if it helps one person it matters.
-
Good Job Bro!
-
Hello ! I have this error :
Code:[Oxide] 4:34 AM [Error] Oxide.Ext.RUI is referenced by RustUITest plugin but is not loaded! An appropriate include file needs to be saved to Plugins\Include\Ext.RUI.cs if this extension is not required.
-
-
-
Thanks will give this a try soon!
-
You know how to install it?
-
You should just place it in your managed folder of the server files ... I will try and find some time to see if I need to do any updating on it.