The dev blog update said that he was working on GUI for plugin usage... And posted his github source... Any idea oh how to use it?
Community entity UI
Discussion in 'Rust Development' started by ShadowEvil, Jun 5, 2015.
-
Hi there! I'm refering to the Community Entity that Garry mentioned in his devblog http://playrust.com/devblog-63/#more-3642 yesterday:
https://github.com/OxideMod/Oxide/blob/master/Oxide.Game.Rust/RustCore.cs#L115
Has anyone played around with it yet? Has someone found out how it works? Found possibilities/limitations?
I was going to look into it in the upcomming days, perhaps someone already spent some time on this. -
Maybe
Code:CommunityEntity.ServerInstance.ClientRPCEx( new Network.SendInfo() { connection = args.connection }, null, "AddUI", json );
[DOUBLEPOST=1433519476][/DOUBLEPOST]Wow, it's working perfect! http://savepic.ru/7216319.png
Test code (copy from github):
Code:using UnityEngine; using Rust;namespace Oxide.Plugins { [Info("GUI", "Bombardir", "0.0.1")] class GUI : RustPlugin { #region JSON const string json = @"[ { ""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"" } ] } ] "; #endregion [ChatCommand("gui")] void gui_test(BasePlayer player, string command, string[] args) { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", json); } } }
Last edited by a moderator: Jun 5, 2015 -
I was trying it, and it is working.
You only need to call the line of Bombardir´s post with an json string like in the example on the github.
the "args.connection" must be an instance of Network.Connection.
You get this object, in example, in the "OnUserApprove" hook.
Not really sure how to get this connection object from an BasePlayer object, therefore i was assigning it to an internal array of my plugin class to be able to acccess it later in an other hooks where i only have the BasePlayer object.
But i still need a list of "parent" Panels, and some example how to define the size and possition of the elements.
For now parent "Overlay" looks like the the main Window/Area (visibile in all cases), i was also trying some other names and found "Inventory".
But i like to know the name of the Panel of the complete Window after using tab ( where Inventory, Player and Craftmenu is ) to add some new buttons... -
I played a bit .. and all i can say at the moment it is tooo-o much pain in positioning of the components
[DOUBLEPOST=1433520410,1433510521][/DOUBLEPOST]EDIT:
Spent some time and created this small panel (online/sleepers/time).
Good thing that Garry decided to advance the client modding, but currently possibilities is very and very limited.
-
It's not so hard after some tests)
[DOUBLEPOST=1433536961][/DOUBLEPOST] -
Been trying to do this, can i look at the definition? -
How do I get out of using that dreaded string bullcrap with the json? I tried formatting it, and it was the same every which way... But it still does NOT like my formatting... I can't insert non-static information like the Level of the character and such....
Nevermind... Fixed it... Stupid string... Who uses @ anymore anyway...
[DOUBLEPOST=1433565571,1433542584][/DOUBLEPOST]Anybody figure out how to make it refresh information on the screen? Or is it still static? -
-
Yeah, but it's horribly refreshed. it doesn't destroy very quickly... Takes about 100ms to actually do anything on the client's screen... The way I had to do it was this...
Code:PluginTimers t = new PluginTimers(this); if (gui != null) gui.ProfileGUI_remove(player); if (args != null && args.Length >= 1 && args[0].ToLower() == "hide") return; t.Once(0.100f, () => InsertNewGUI(PanelName, player));
-
I have attempted to create an UI builder extension for my needs (instead of working with json by hands, hate it).
Here is some result for the moment:
Sample Plugin (Usage)
The code of extension is a bit complicated, but seems now easier to maintain the UI.
Will this have any interest or pure json is better? -
Wulf Community Admin
-
[DOUBLEPOST=1433612730][/DOUBLEPOST]And the use of PluginTimer to refresh information is a pain in the ass... Having to reload the information by destroying it and rewriting it is a horrible method :/ but it's what works right now... And the only way I could get it to refresh was to add a slight delay on when it redraw's itself -
Well, I think I might actually work on some library/class to help simplify the json crap. it should be fairly easy once the basics is written up. It's an Alpha game and the UI is very early but possesses a lot of potential. From what I can see with the example codes so-far is that Garry has a very flexible system in-mind for the future. I don't think he should really change the json part, we are suppose to be modders, so we should write up our own system to work with json.
Also json uses up a lot less bytes over xml. Network optimization also needs to be taken into consideration. -
-
Ive read in the last devblog that garry added a possibility to put UI elements on a players screen, how would that be possible to for example show a picture or a text? [Lel this got moved xD, ill try what I've seen on the top (looks difficult to me on the first sight ^^)]
[DOUBLEPOST=1433881355,1433855402][/DOUBLEPOST]Wow I don't understand json xD
propably... or im just confused -
What are you struggling to understand about the JSON format?
-
Well actually I wrote bullshit, its not really the JSON format i don't understand, I don't really understand how that JSON part works, for example how I can make that button do something like close the UI again and that stuff ^^
Also how to even set an Button etc. just copied Bombardirs code right now and playing around with it
Also im trying to remove the UI which doesnt really work like I tried ^^
Code:CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI");
Last edited by a moderator: Jun 9, 2015 -
Code:CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", "LevelBar");
-