Skip to content
176 changes: 144 additions & 32 deletions CommunityEntity.UI.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
#if SERVER
public class cui
{
[ServerUserVar]
public static void test( ConsoleSystem.Arg args )
{
const string json = @"[
[ServerUserVar]
public static void cui_test( ConsoleSystem.Arg args )
{
const string json = @"[
{
""name"": ""TestPanel7766"",
""parent"": ""Overlay"",

""components"":
[
{
Expand All @@ -22,22 +21,19 @@ public static void test( ConsoleSystem.Arg args )
""color"": ""1.0 1.0 1.0 1.0"",
""url"": ""http://files.facepunch.com/garry/2015/June/03/2015-06-03_12-19-17.jpg"",
},

{
""type"":""RectTransform"",
""anchormin"": ""0 0"",
""anchormax"": ""1 1""
},

{
""type"":""NeedsCursor""
}
]
},

{
""parent"": ""TestPanel7766"",

""name"": ""buttonText"",
""components"":
[
{
Expand All @@ -46,19 +42,16 @@ public static void test( ConsoleSystem.Arg args )
""fontSize"":32,
""align"": ""MiddleCenter"",
},

{
""type"":""RectTransform"",
""anchormin"": ""0 0.5"",
""anchormax"": ""1 0.9""
}
]
},

{
""name"": ""Button88"",
""parent"": ""TestPanel7766"",

""components"":
[
{
Expand All @@ -68,18 +61,15 @@ public static void test( ConsoleSystem.Arg args )
""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"":
[
{
Expand All @@ -89,29 +79,151 @@ public static void test( ConsoleSystem.Arg args )
""align"": ""MiddleCenter""
}
]
}
},
{
""name"": ""ItemIcon"",
""parent"": ""TestPanel7766"",
""components"":
[
{
""type"":""UnityEngine.UI.Image"",
""color"": ""1.0 1.0 1.0 1.0"",
""imagetype"": ""Simple"",
""itemid"": -151838493,
},
{
""type"":""RectTransform"",
""anchormin"":""0.4 0.4"",
""anchormax"":""0.4 0.4"",
""offsetmin"": ""-32 -32"",
""offsetmax"": ""32 32""
}
]
},
{
""name"": ""ItemIconSkinTest"",
""parent"": ""TestPanel7766"",
""components"":
[
{
""type"":""UnityEngine.UI.Image"",
""color"": ""1.0 1.0 1.0 1.0"",
""imagetype"": ""Simple"",
""itemid"": -733625651,
""skinid"": 13035
},
{
""type"":""RectTransform"",
""anchormin"":""0.6 0.6"",
""anchormax"":""0.6 0.6"",
""offsetmin"": ""-32 -32"",
""offsetmax"": ""32 32""
}
]
},
{
""name"": ""UpdateLabelTest"",
""parent"": ""TestPanel7766"",
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""This should go away once you update!"",
""fontSize"":32,
""align"": ""MiddleRight"",
},
]
},
]
";

CommunityEntity.ServerInstance.ClientRPCEx( new Network.SendInfo() { connection = args.Connection }, null, "AddUI", json );
}

[ServerUserVar]
public static void cui_test_update( ConsoleSystem.Arg args )
{
//adding an allowUpdate field will try and update components based on the name
//if a gameObject isn't named then update will not work
//only fields that are included will be updated, so it's not necessary to pass every variable
//for instance, the below update json will update the background image and text of the test command above
const string json = @"[
{
""name"": ""TestPanel7766"",
""update"": true,
""components"":
[
{
""type"":""UnityEngine.UI.RawImage"",
""url"": ""https://files.facepunch.com/paddy/20220405/zipline_01.jpg"",
},
]
},
{
""name"": ""buttonText"",
""update"": true,
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""This text just got updated!"",
},
]
},
{
""name"": ""ItemIcon"",
""update"": true,
""components"":
[
{
""type"":""UnityEngine.UI.Image"",
""itemid"": -2067472972,
},
]
},
{
""name"": ""Button88"",
""update"": true,
""components"":
[
{
""type"":""UnityEngine.UI.Button"",
""color"": ""0.9 0.3 0.3 0.8"",
},
]
},
{
""name"": ""UpdateLabelTest"",
""update"": true,
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""enabled"": false,
},
]
},
]
";

CommunityEntity.ServerInstance.ClientRPCEx( new Network.SendInfo() { connection = args.Connection }, null, "AddUI", json );
}
CommunityEntity.ServerInstance.ClientRPCEx( new Network.SendInfo() { connection = args.Connection }, null, "AddUI", json );
}

#if UNITY_EDITOR && CLIENT && SERVER
[UnityEditor.MenuItem( "Debug/CUI/Load custom UI" )]
public static void loadcustomjson()
{
if ( LocalPlayer.Entity == null || !Application.isPlaying )
return;

#if UNITY_EDITOR && CLIENT && SERVER
[UnityEditor.MenuItem("Debug/CUI/Load custom UI")]
public static void loadcustomjson()
{
if(LocalPlayer.Entity == null || !Application.isPlaying)
return;

var toLoad = UnityEditor.EditorUtility.OpenFilePanel("JSON to load", Application.dataPath, "txt");
var toLoad = UnityEditor.EditorUtility.OpenFilePanel( "JSON to load", Application.dataPath, "txt" );

if (!string.IsNullOrEmpty(toLoad))
{
CommunityEntity.ServerInstance.ClientRPC( null, "AddUI", System.IO.File.ReadAllText(toLoad));
}
}
#endif
if ( !string.IsNullOrEmpty( toLoad ) )
{
CommunityEntity.ServerInstance.ClientRPC( null, "AddUI", System.IO.File.ReadAllText( toLoad ) );
}
}
#endif

[ServerUserVar]
public static void endtest( ConsoleSystem.Arg args )
Expand Down
Loading