Created
June 6, 2015 17:17
-
-
Save virtyvoid/5967185f1df5486e6bc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: Oxide.Ext.RustUI | |
using System.IO; | |
using RustUI; | |
using RustUI.UIComponents; | |
using UnityEngine; | |
using UnityEngine.UI; | |
namespace Oxide.Plugins | |
{ | |
[Info("UITest", "DefaultPlayer", "1.0")] | |
class UITest : RustPlugin | |
{ | |
private readonly Color grey = new Color(0.5f, 0.5f, 0.5f, 0.5f); | |
private int clicks; | |
private BaseUIComponent UI; | |
[ChatCommand("cui")] | |
private void OnCUICmd(BasePlayer player, string command, string[] args) | |
{ | |
if (!player.IsAdmin()) | |
return; | |
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", UI.name); | |
} | |
[ChatCommand("ui")] | |
private void OnUICmd(BasePlayer player, string command, string[] args) | |
{ | |
if (!player.IsAdmin()) | |
return; | |
ShowUI(player); | |
} | |
private void ShowUI(BasePlayer player) | |
{ | |
var comp = UI.FindComponent<UIText>("Counter"); | |
comp.text = $"You clicked {clicks} times."; | |
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", UI.GetCompressedJSON()); | |
} | |
[ConsoleCommand("click")] | |
private void cmdClick(ConsoleSystem.Arg arg) | |
{ | |
clicks++; | |
ShowUI(arg.Player()); | |
} | |
private void Loaded() | |
{ | |
var MainUI = BaseUIComponent.Create("Overlay", "Dialog"); | |
MainUI.AddComponent(new UIImage(grey, Image.Type.Simple)) | |
.AddComponent(new UIRectTransform(new Vector2(0.297f, 0.2463031f), new Vector2(.7f, .7f))) | |
.AddComponent(new UINeedsCursor()) | |
// Header | |
.AddNestedComponent(BaseUIComponent.Inherit(MainUI)) | |
.AddComponent(new UIText("Clicker", 26, Color.white, TextAnchor.MiddleCenter)) | |
.AddComponent(new UIRectTransform(new Vector2(0f, 0.8201072f), Vector2.one)) | |
// Counter | |
.GetOwner().AddNestedComponent(BaseUIComponent.Inherit(MainUI)) | |
.AddComponent(new UIText("", 14, Color.yellow, TextAnchor.MiddleCenter).SetName("Counter")) | |
.AddComponent(new UIRectTransform(new Vector2(0,.5f), new Vector2(1f, .9f))) | |
// Button | |
.GetOwner().AddNestedComponent(BaseUIComponent.Inherit(MainUI, "TheButton")) | |
.AddComponent(new UIButton("global.click","Dialog",Color.yellow, Image.Type.Tiled)) | |
.AddComponent(new UIRectTransform(new Vector2(0.0f,0.0f),new Vector2(1f,0.30f))) | |
.GetOwner().AddNestedComponent(BaseUIComponent.Create("TheButton")).AddComponent(new UIText("CLICK ME", 20, Color.white, TextAnchor.MiddleCenter)); | |
// Close Button | |
MainUI.AddNestedComponent(BaseUIComponent.Inherit(MainUI, "CloseBtn")).AddComponent(new UIButton(null, "Dialog", Color.red, Image.Type.Tiled)) | |
.AddComponent(new UIRectTransform(new Vector2(0.95f, 0.95f), Vector2.one)) | |
.GetOwner().AddNestedComponent(BaseUIComponent.Create("CloseBtn")).AddComponent(new UIText("[X]", 14, Color.white, TextAnchor.MiddleCenter)); | |
File.WriteAllText(@"C:\debugui.txt", MainUI.ToString()); | |
UI = MainUI; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment