using Oxide.Game.Rust.Cui; using UnityEngine; using Newtonsoft.Json; using System.Collections.Generic; using Oxide.Core.Plugins; namespace Oxide.Plugins { [Info("TheButton", "MikeHawke", "1.0.8")] [Description("One Extra Button")] class TheButton : RustPlugin { [PluginReference] private Plugin FurnaceSplitter; Dictionary record = new Dictionary(); public class BtnOpenUI { public bool btnUIopen; } void Init() { permission.RegisterPermission("TheButton.use", this); } void Unload() { foreach (BasePlayer current in BasePlayer.activePlayerList) { CuiHelper.DestroyUi(current, "ButtonUI"); record.Remove(current.userID); } } void OnServerInitialized() { LoadConfigVariables(); SaveConfig(configData); Setup(); } private ConfigData configData; class ConfigData { public Global GlobalSettings = new Global(); public AlignmentSettings AlignmentSettings = new AlignmentSettings(); } class Global { [JsonProperty(PropertyName = "Image Url for The Button")] public string OneURL = "https://i.imgur.com/7L1uDrs.png"; [JsonProperty(PropertyName = "Command For The Button")] public string OneCommand = "backpack"; [JsonProperty(PropertyName = "Background color of Button RGBA format")] public string color = "0.3 0.3 0.3 0.8"; [JsonProperty(PropertyName = "Open By Default true/false")] public bool defopen = true; } class AlignmentSettings { [JsonProperty(PropertyName = "AnchorMin")] public string AnchorMin = "0.645 0.023"; [JsonProperty(PropertyName = "AnchorMax")] public string AnchorMax = "0.688 0.095"; } private void LoadConfigVariables() { configData = Config.ReadObject(); if (configData.GlobalSettings.OneURL == "") configData.GlobalSettings.OneURL = "https://i.imgur.com/6RjWdNd.png"; SaveConfig(configData); } protected override void LoadDefaultConfig() { Puts("Creating new config file."); var config = new ConfigData(); SaveConfig(config); } void SaveConfig(ConfigData config) { Config.WriteObject(config, true); } void Setup() { record.Clear(); foreach (BasePlayer current in BasePlayer.activePlayerList) { if (configData.GlobalSettings.defopen == true) { record.Add(current.userID, new BtnOpenUI() { btnUIopen = true }); ButtonUI(current); } else { record.Add(current.userID, new BtnOpenUI() { btnUIopen = false }); } } } private void OnPlayerConnected(BasePlayer player) { record[player.userID] = new BtnOpenUI() { btnUIopen = configData.GlobalSettings.defopen }; } private void OnPlayerSleepEnded(BasePlayer player) { if (!record.ContainsKey(player.userID)) { record.Add(player.userID, new BtnOpenUI() { btnUIopen = configData.GlobalSettings.defopen }); } if (record[player.userID].btnUIopen == true) { ButtonUI(player); } } private void OnLootEntity(BasePlayer player, BaseEntity entity) { BaseOven Furnace = entity as BaseOven; if ((permission.UserHasPermission(player.userID.ToString(), "furnacesplitter.use")) && (Furnace != null) && (FurnaceSplitter != null)) { CuiHelper.DestroyUi(player, "ButtonUI"); } } private void OnLootEntityEnd(BasePlayer player, BaseCombatEntity entity) { BaseOven Furnace = entity as BaseOven; if ((permission.UserHasPermission(player.userID.ToString(), "furnacesplitter.use")) && (Furnace != null) && (FurnaceSplitter != null) && (record[player.userID].btnUIopen == true)) { ButtonUI(player); } } void OnPlayerDisconnected(BasePlayer player) { record.Remove(player.userID); } [ChatCommand("Button")] void ButtonUIcall(BasePlayer player) { if (!permission.UserHasPermission(player.userID.ToString(), "TheButton.use")) { SendReply(player, "You do not have permission to use this command"); return; } if (record[player.userID].btnUIopen == true) { CuiHelper.DestroyUi(player, "ButtonUI"); record[player.userID].btnUIopen = false; } else { ButtonUI(player); record[player.userID].btnUIopen = true; } } void ButtonUI(BasePlayer player) { if(!permission.UserHasPermission(player.userID.ToString(), "TheButton.use")) return; CuiHelper.DestroyUi(player, "ButtonUI"); var elements = new CuiElementContainer(); var ButtonUIPanel = elements.Add(new CuiPanel { Image = { Color = $"{configData.GlobalSettings.color}" }, RectTransform = { AnchorMin = $"{configData.AlignmentSettings.AnchorMin}", AnchorMax = $"{configData.AlignmentSettings.AnchorMax}" }, CursorEnabled = false }, "Overlay", "ButtonUI"); elements.Add(new CuiElement { Parent = "ButtonUI", Components = { new CuiRawImageComponent { Url = $"{configData.GlobalSettings.OneURL}" }, new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" } } }); if (configData.GlobalSettings.OneURL != "https://i.imgur.com/6RjWdNd.png") { elements.Add(new CuiButton { Button = { Command = "button.onecom", Color = "0 0 0 0" }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }, Text = { Text = "" } }, ButtonUIPanel); } CuiHelper.AddUi(player, elements); } [ConsoleCommand("button.onecom")] private void OneCom(ConsoleSystem.Arg arg) { if (arg.Player() == null) return; arg.Player().SendConsoleCommand("chat.say", "/" + configData.GlobalSettings.OneCommand); } } }