Иконка ресурса

FREE TeamGUI : 1.0.4 1.0.4

Нет прав для скачивания
C#:
using UnityEngine;
using System.Text;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using System.Linq;
using Oxide.Core.Configuration;
using Oxide.Core;
using TeamGUIEx;
using System.Reflection;
using System;
using Network;
using Oxide.Game.Rust.Cui;
using System.IO;
using System.Runtime.Serialization;
using System.Drawing.Drawing2D;
namespace Oxide.Plugins {
    [Info("TeamGUI", "Waggy", "1.0.4", ResourceId = 169 )]
    [Description("" )]
    class TeamGUI : RustPlugin {
        public static TeamGUI _plugin;
        public JSONFile<ConfigData> _settingsFile;
        public ConfigData Settings {
            get {
                return _settingsFile.Instance;
            }
        }
        public PlayerDataController<TeamGUIPlayerData> PlayerData;
        public Timer HealthUpdateTimer;
#region UI
        public void RegisterImages() {
            timer.Every(60, () => {
                if (ImageLibrary == null ) {
                    PrintWarning("ImageLibrary is not installed, images will not work correctly." );
                }
            }
            );
            AddImage("http://i.imgur.com/k1nfo79.png", "offline_overlay", 5 );
            AddImage("http://i.imgur.com/pulQPKL.png", "naked_head_alive", 3 );
            AddImage("http://i.imgur.com/r6RnyZG.png", "naked_head_offline", 3 );
            AddImage("http://i.imgur.com/SjzJi3J.png", "no_health", 3 );
            AddImage("http://i.imgur.com/yGTVaxa.png", "1/10_health", 3 );
            AddImage("http://i.imgur.com/Rzav5dh.png", "2/10_health", 3 );
            AddImage("http://i.imgur.com/n9Eggpx.png", "3/10_health", 3 );
            AddImage("http://i.imgur.com/6M3KAtr.png", "4/10_health", 3 );
            AddImage("http://i.imgur.com/s4H7LNV.png", "5/10_health", 3 );
            AddImage("http://i.imgur.com/RYw5SmW.png", "6/10_health", 3 );
            AddImage("http://i.imgur.com/1sg1taT.png", "7/10_health", 3 );
            AddImage("http://i.imgur.com/MGwSlHQ.png", "8/10_health", 3 );
            AddImage("http://i.imgur.com/vBy7api.png", "9/10_health", 3 );
            AddImage("http://i.imgur.com/LIJPxsj.png", "full_health", 3 );
            AddImage("http://i.imgur.com/ceDzWUy.png", "offline", 2 );
            AddImage("http://i.imgur.com/JlNBYmT.png", "wounded", 2 );
        }
        public void DestroyUI() {
            if (PlayerData == null ) {
                return;
            }
            foreach (var playerData in PlayerData.All ) {
                playerData?.TeamGUIIcon?.HideAll();
            }
        }
#region UI Functions
        public void UpdateIcons() {
            foreach(var playerData in PlayerData.All) {
                playerData?.UpdateUI();
            }
        }
        void SetupPlayerIcon(ulong steamID ) {
            var data = PlayerData.Get(steamID );
            data.IsConnected = true;
            data.BuildTeamGUI(steamID );
        }
        public static UIPlacement GetTeamIconPlacement(RelationshipManager.PlayerTeam team, ulong steamID ) {
            var index = team.members.IndexOf(steamID );
            if (!_plugin.Settings.ShowOwnHealthBar ) {
                index--;
            }
            if (index == -1 ) {
                index++;
            }
            UIPlacement placement = UIPlacement.MiddleCenter_Pixels(0, 0, 0, 0 );
            _plugin.Settings.TeamIconPlacements.TryGetValue(index, out placement );
            return placement;
        }
        public void RefreshTeamGUIForTeam(RelationshipManager.PlayerTeam team ) {
            RefreshTeamGUIForTeam(team.members );
        }
        public void RefreshTeamGUIForTeam(List<ulong> members ) {
            foreach (var memberID in members ) {
                var memberData = PlayerData.Get(memberID );
                foreach (var mID in members ) {
                    BasePlayer member = null;
                    if (RelationshipManager.Instance.cachedPlayers.TryGetValue(mID, out member ) ) {
                        if (member != null && member.IsConnected ) {
                            memberData.TeamGUIIcon?.Refresh(member );
                            memberData.TeleportButton?.Refresh(member );
                            //Puts( $"Refreshed {memberData.PlayerModel.displayName}'s icon for {member.displayName}" );
                        }
                    }
                }
            }
        }
#region Image Handling
        public string GetHealthBarImage(int healthFraction ) {
            switch (healthFraction ) {
                default : case 0 : {
                    return GetImage("no_health", 3 );
                }
                case 1 : {
                    return GetImage("1/10_health", 3 );
                }
                case 2 : {
                    return GetImage("2/10_health", 3 );
                }
                case 3 : {
                    return GetImage("3/10_health", 3 );
                }
                case 4 : {
                    return GetImage("4/10_health", 3 );
                }
                case 5 : {
                    return GetImage("5/10_health", 3 );
                }
                case 6 : {
                    return GetImage("6/10_health", 3 );
                }
                case 7 : {
                    return GetImage("7/10_health", 3 );
                }
                case 8 : {
                    return GetImage("8/10_health", 3 );
                }
                case 9 : {
                    return GetImage("9/10_health", 3 );
                }
                case 10 : {
                    return GetImage("full_health", 3 );
                }
            }
        }
        public static string GetPlayerProfilePicture(string userIDString ) {
            if (HasImage(userIDString, 1 ) ) {
                return GetImage(userIDString, 1 );
            }
            if (!HasImage(userIDString, 0 ) ) {
                return GetImage("naked_head_alive", 3 );
            }
            var imageBytes = GetImageBytes(userIDString, 0 );
            var circleBytes = CropToCircle(imageBytes );
            AddImage(circleBytes, userIDString, 1 );
            return GetImage("naked_head_alive", 3 );
        }
        public static byte[] CropToCircle(byte[] srcImage ) {
            System.Drawing.Image sourceImage = System.Drawing.Bitmap.FromStream(new MemoryStream(srcImage ) );
            System.Drawing.Image finalImage = new System.Drawing.Bitmap(sourceImage.Width, sourceImage.Height );
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage ) ) {
                System.Drawing.RectangleF r = new System.Drawing.RectangleF(0, 0, sourceImage.Width, sourceImage.Height );
                // enables smoothing of the edge of the circle (less pixelated)
                g.SmoothingMode = SmoothingMode.AntiAlias;
                // fills background color
                using (System.Drawing.Brush br = new System.Drawing.SolidBrush(System.Drawing.Color.Transparent ) ) {
                    g.FillRectangle(br, 0, 0, sourceImage.Width, sourceImage.Height );
                }
                // adds the new ellipse & draws the image again
                GraphicsPath path = new GraphicsPath();
                path.AddEllipse(r );
                g.SetClip(path );
                g.DrawImage(sourceImage, 0, 0 );
            }
            return ImageToByteArray(finalImage );
        }
        public static byte[] ImageToByteArray(System.Drawing.Image imageIn ) {
            using (var ms = new MemoryStream() ) {
                imageIn.Save(ms, imageIn.RawFormat );
                return ms.ToArray();
            }
        }
#endregion
#endregion
#endregion
#region Classes
        public class Invite {
            public ulong InvitedPlayerID;
            public ulong InvitingPlayerID;
        }
#endregion
#region Functions
        public RelationshipManager.PlayerTeam GetTeam(BasePlayer player ) {
            return RelationshipManager.Instance.FindTeam(player.currentTeam );
        }
        public RelationshipManager.PlayerTeam GetTeam(ulong steamID ) {
            return RelationshipManager.Instance.FindPlayersTeam(steamID );
        }
        public int GetPlayerHealthFraction(float healthFractionFloat ) {
            return Mathf.RoundToInt(healthFractionFloat );
        }
#endregion
#region Commands
        void ToggleHUDCommand(BasePlayer player, string command, string[] args ) {
            var data = PlayerData.Get(player );
            var team = GetTeam(player );
            if (data.ShowUI ) {
                data.ShowUI = false;
            }
            else {
                data.ShowUI = true;
            }
            if (team != null ) {
                RefreshTeamGUIForTeam(team );
            }
        }
#endregion
#region Hooks
        void OnServerInitialized() {
            _plugin = this;
            try {
                _settingsFile = new JSONFile<ConfigData>("TeamGUI", ConfigLocation.Config );
            }
            catch {
                PrintError("Config file has errors within it, please verify you aren't missing commas or brackets." );
                NextFrame(() => {
                    rust.RunServerCommand("o.unload TeamGUI" );
                }
                );
                return;
            }
            permission.RegisterPermission("teamgui.allow", this );
            cmd.AddChatCommand(Settings.CommandName, this, ToggleHUDCommand );
            PlayerData = new PlayerDataController<TeamGUIPlayerData>();
            RegisterUICommands();
            RegisterImages();
            foreach (var team in RelationshipManager.Instance.teams.Values ) {
                foreach (var member in team.members ) {
                    SetupPlayerIcon(member );
                }
                RefreshTeamGUIForTeam(team );
            }
            HealthUpdateTimer = timer.Every(1f, UpdateIcons );
        }
        void Unload() {
            DestroyUI();
            _plugin = null;
            HealthUpdateTimer?.Destroy();
        }
        void OnPlayerInit(BasePlayer player ) {
            SetupPlayerIcon(player.userID );
            RelationshipManager.PlayerTeam team = GetTeam(player );
            if (team != null ) {
                RefreshTeamGUIForTeam(team );
            }
        }
        void OnPlayerDisconnected(BasePlayer player, string reason ) {
            var playerData = PlayerData.Get(player.userID );
            playerData.IsConnected = false;
            playerData.UpdateUI();
        }
        void OnUserPermissionGranted(string id, string permName ) {
            if (permName != "teamgui.allow" ) {
                return;
            }
            var team = RelationshipManager.Instance.FindPlayersTeam(Convert.ToUInt64(id ) );
            if (team != null ) {
                RefreshTeamGUIForTeam(team );
            }
        }
        void OnUserPermissionRevoked(string id, string permName ) {
            if (permName != "teamgui.allow" ) {
                return;
            }
            var team = RelationshipManager.Instance.FindPlayersTeam(Convert.ToUInt64(id ) );
            if (team != null ) {
                RefreshTeamGUIForTeam(team );
            }
        }
#region Team Hooks
        object OnTeamDisband(RelationshipManager.PlayerTeam team ) {
            var members = team.members.ToList();
            NextFrame(() => {
                RefreshTeamGUIForTeam(members );
            }
            );
            return null;
        }
        object OnTeamLeave(RelationshipManager.PlayerTeam team, BasePlayer player ) {
            var members = team.members.ToList();
            NextFrame(() => {
                RefreshTeamGUIForTeam(members );
            }
            );
            return null;
        }
        object OnTeamKick(RelationshipManager.PlayerTeam team, BasePlayer player ) {
            NextFrame(() => {
                RefreshTeamGUIForTeam(team );
            }
            );
            return null;
        }
        object OnTeamCreated(BasePlayer player, RelationshipManager.PlayerTeam team ) {
            RefreshTeamGUIForTeam(team );
            return null;
        }
        object OnTeamAcceptInvite(RelationshipManager.PlayerTeam team, BasePlayer player ) {
            NextFrame(() => {
                RefreshTeamGUIForTeam(team );
            }
            );
            return null;
        }
#endregion
#endregion
#region Player Data
        public class TeamGUIPlayerData : BasePlayerData {
            public RustUIElement<ImageData> TeamGUIIcon;
            public RustUIElement<ImageData> HealthBar;
            public RustUIElement<ImageData> DropDownMenu;
            public RustUIElement<ImageButton> TeleportButton;
            public int HealthImageIndex;
            public bool IsConnected;
            public int TimeSinceLastUpdate;
            public bool IsWounded;
            public bool ShowUI = true;
            public BasePlayer SelectedPlayer = null;
            public bool DropDownMenuShowing = false;
            public void BuildTeamGUI(ulong steamID ) {
                TeamGUIIcon = ImageData.CreateRawImage(UIPlacement.MiddleCenter_Pixels(45, 45, -400, 400 ), null );
                TeamGUIIcon.Settings.RawImage = true;
                TeamGUIIcon.Settings.PNG = GetPlayerProfilePicture(steamID.ToString() );
                TeamGUIIcon.Layer = "Under";
                TeamGUIIcon.AddConditional((uiPlayer, data ) => {
                    if (!_plugin.permission.UserHasPermission(uiPlayer.UserIDString, "teamgui.allow") || !_plugin.PlayerData.Get(uiPlayer ).ShowUI ) {
                        data.ShouldShow = false;
                        return;
                    }
                    BasePlayer player;
                    if (!RelationshipManager.Instance.cachedPlayers.TryGetValue(steamID, out player ) || (player != null && !player.IsConnected ) ) {
                        data.Color = Colors.Grey.darkgray.MakeTransparent(0.20f );
                    }
                    RelationshipManager.PlayerTeam uiPlayerTeam = _plugin.GetTeam(uiPlayer );
                    RelationshipManager.PlayerTeam currentTeam = _plugin.GetTeam(steamID );
                    if (!_plugin.Settings.ShowOwnHealthBar && uiPlayer.userID == steamID ) {
                        data.ShouldShow = false;
                    }
                    if (uiPlayerTeam == null || uiPlayer.currentTeam == 0uL || !RelationshipManager.Instance.teams.ContainsValue(uiPlayerTeam ) ) {
                        data.ShouldShow = false;
                    }
                    if (currentTeam == null || !RelationshipManager.Instance.teams.ContainsValue(currentTeam ) ) {
                        data.ShouldShow = false;
                    }
                    if (currentTeam != uiPlayerTeam ) {
                        data.ShouldShow = false;
                    }
                    if (currentTeam != null ) {
                        data.Placement = GetTeamIconPlacement(currentTeam, steamID );
                    }
                    string profilePicture = GetPlayerProfilePicture(steamID.ToString() );
                    data.PNG = profilePicture;
                }
                );
                HealthBar = ImageData.CreateRawImage(UIPlacement.MiddleCenter_Pixels(75, 75, 0, 0 ), TeamGUIIcon );
                HealthBar.Settings.RawImage = true;
                HealthBar.AddConditional((uiPlayer, data) => {
                    if (!_plugin.Settings.ShowOwnHealthBar && uiPlayer.userID == steamID ) {
                        data.ShouldShow = false;
                    }
                    BasePlayer player;
                    if (!RelationshipManager.Instance.cachedPlayers.TryGetValue(steamID, out player ) || player == null || !player.IsConnected ) {
                        data.PNG = GetImage("offline", 2 );
                    }
                    else if (player.IsDead() ) {
                        data.PNG = GetImage("no_health", 3 );
                    }
                    else if (player.IsWounded() ) {
                        data.PNG = GetImage("wounded", 2 );
                    }
                    else {
                        ReassignHealthImageIndex();
                        data.PNG = _plugin.GetHealthBarImage(HealthImageIndex );
                    }
                }
                );
                TeleportButton = ImageButton.CreateElement(UIPlacement.MiddleCenter(0, 0, 0, 0 ), null, null );
                TeleportButton.Settings.Image.Color = Colors.Transparent;
                TeleportButton.Settings.Callback = (uiPlayer ) => {
                    BasePlayer player;
                    if (!RelationshipManager.Instance.cachedPlayers.TryGetValue(steamID, out player ) || (player != null && !player.IsConnected ) ) {
                        return;
                    }
                    uiPlayer.SendConsoleCommand("chat.say", $"/tpr \"{player.displayName}\"");
                }
                ;
                TeleportButton.AddConditional((uiPlayer, data ) => {
                    if (!_plugin.permission.UserHasPermission(uiPlayer.UserIDString, "teamgui.allow" ) || !_plugin.PlayerData.Get(uiPlayer ).ShowUI ) {
                        data.ShouldShow = false;
                        return;
                    }
                    RelationshipManager.PlayerTeam uiPlayerTeam = _plugin.GetTeam(uiPlayer );
                    RelationshipManager.PlayerTeam currentTeam = _plugin.GetTeam(steamID );
                    if (!_plugin.Settings.ShowOwnHealthBar && uiPlayer.userID == steamID ) {
                        data.ShouldShow = false;
                    }
                    if (uiPlayerTeam == null || uiPlayer.currentTeam == 0uL || !RelationshipManager.Instance.teams.ContainsValue(uiPlayerTeam ) ) {
                        data.ShouldShow = false;
                    }
                    if (currentTeam == null || !RelationshipManager.Instance.teams.ContainsValue(currentTeam ) ) {
                        data.ShouldShow = false;
                    }
                    if (currentTeam != uiPlayerTeam ) {
                        data.ShouldShow = false;
                    }
                    if (currentTeam != null ) {
                        data.Placement = GetTeamIconPlacement(currentTeam, steamID );
                    }
                }
                );
#region Drop Down Menu (scrapped for now)
                //DropDownMenu = ImageData.CreateImage( UIPlacement.MiddleCenter_Pixels( 25, 78, -55, 0 ), TeamGUIIcon, Colors.HexColor( 0xf0, 0xf0, 0xf0 ) );
                //DropDownMenu.AddConditional( ( uiPlayer, data ) =>
                //{
                //    BasePlayer player;
                //    if ( !RelationshipManager.Instance.cachedPlayers.TryGetValue( steamID, out player ) || ( player != null && !player.IsConnected ) )
                //    {
                //        data.ShouldShow = false;
                //        return;
                //    }
                //    var uiPlayerData = _plugin.PlayerData.Get( uiPlayer );
                //    if ( uiPlayerData.SelectedPlayer == null || uiPlayerData.SelectedPlayer != player )
                //    {
                //        data.ShouldShow = false;
                //        return;
                //    }
                //    if ( uiPlayerData.DropDownMenuShowing )
                //    {
                //        data.ShouldShow = false;
                //        uiPlayerData.DropDownMenuShowing = false;
                //    }
                //    else
                //    {
                //        uiPlayerData.DropDownMenuShowing = true;
                //    }
                //} );
                //var teleportButton = RustUIElement.Create( DropDownMenu, new TextButton()
                //{
                //    Label = new LabelData()
                //    {
                //        Text = "TPR",
                //        TextColor = Colors.Green.limegreen,
                //    },
                //    Button = new ButtonData()
                //    {
                //        ButtonColor = Colors.Red.red,
                //        Callback = ( uiPlayer ) =>
                //        {
                //            //send teleport request
                //        }
                //    },
                //    Placement = UIPlacement.MiddleCenter_Pixels( 25, 25, 0, 0 )
                //} );
                //var dropDownMenuExitButton = RustUIElement.Create( DropDownMenu, new TextButton()
                //{
                //    Label = new LabelData()
                //    {
                //        Text = "X",
                //        TextColor = Colors.White.white,
                //    },
                //    Button = new ButtonData()
                //    {
                //        ButtonColor = Colors.Red.red,
                //        Callback = ( uiPlayer ) =>
                //        {
                //            DropDownMenu.Refresh( uiPlayer );
                //        }
                //    },
                //    Placement = UIPlacement.MiddleCenter_Pixels( 25, 26, -26, 26 )
                //} );
#endregion
            }
            public void UpdateUI() {
                bool oldIsConnected = IsConnected;
                IsConnected = PlayerModel != null && PlayerModel.IsConnected;
                if (oldIsConnected != IsConnected ) {
                    //Has either come online or gone offline
                    TeamGUIIcon.RefreshAll();
                    TeleportButton.RefreshAll();
                }
                if (IsConnected ) {
                    int oldHealthImageIndex = HealthImageIndex;
                    ReassignHealthImageIndex();
                    bool oldWounded = IsWounded;
                    IsWounded = PlayerModel.IsWounded();
                    if (oldHealthImageIndex != HealthImageIndex || oldWounded != IsWounded ) {
                        //Need to update health image
                        HealthBar.RefreshAll();
                    }
                }
            }
            private void ReassignHealthImageIndex() {
                if (PlayerModel == null ) {
                    HealthImageIndex = 0;
                    return;
                }
                //Grab the correct health image (1 - 10 bars) based on current health floored
                HealthImageIndex = Mathf.RoundToInt(PlayerModel._health / PlayerModel.MaxHealth() * 10 );
                if (HealthImageIndex == 0 && PlayerModel.IsDead() == false ) {
                    //It would round down from <5 health to 0 health bars, so keep displaying 1 bar unless they are actually dead
                    HealthImageIndex = 1;
                }
            }
        }
#endregion
#region Config
        public class ConfigData {
            [JsonProperty("Show Your Own Health Bar" )]
            public bool ShowOwnHealthBar = true;
            [JsonProperty("Team Icon Size and Placement ( xSize, ySize, xOffset, yOffset )" )]
            public Dictionary<int, UIPlacement> TeamIconPlacements = new Dictionary<int, UIPlacement>() {
                {
                    0, UIPlacement.MiddleCenter_Pixels(55, 55, 550, 500 )
                }
                , {
                    1, UIPlacement.MiddleCenter_Pixels(55, 55, 635, 500 )
                }
                , {
                    2, UIPlacement.MiddleCenter_Pixels(55, 55, 720, 500 )
                }
                , {
                    3, UIPlacement.MiddleCenter_Pixels(55, 55, 805, 500 )
                }
                , {
                    4, UIPlacement.MiddleCenter_Pixels(55, 55, 550, 420 )
                }
                , {
                    5, UIPlacement.MiddleCenter_Pixels(55, 55, 635, 420 )
                }
                , {
                    6, UIPlacement.MiddleCenter_Pixels(55, 55, 720, 420 )
                }
                , {
                    7, UIPlacement.MiddleCenter_Pixels(55, 55, 805, 420 )
                }
                ,
            }
            ;
            [JsonProperty("Command Name for Player Hiding Team GUI" )]
            public string CommandName = "teamhud";
        }
#endregion
#region Framework
#region Player Data
        public class BasePlayerData {
            [JsonIgnore]
            public BasePlayer PlayerModel {
                get {
                    if (_player == null) {
                        RelationshipManager.Instance.cachedPlayers.TryGetValue(userID, out _player );
                    }
                    else {
                        if (_player.IsDestroyed) {
                            _player = null;
                        }
                    }
                    return _player;
                }
            }
            private BasePlayer _player;
            public ulong userID {
                get;
                set;
            }
            public BasePlayerData() {
            }
            public BasePlayerData(BasePlayer player ) : base() {
                userID = player.userID;
            }
        }
        public class PlayerDataController<T> where T : BasePlayerData {
            [JsonPropertyAttribute(Required = Required.Always )]
            private Dictionary<string, T> playerData {
                get;
                set;
            }
            = new Dictionary<string, T>();
            [JsonIgnore]
            private List<T> playerDataList = new List<T>();
            private JSONFile<Dictionary<string, T>> _file;
            private Timer _timer;
            public IEnumerable<T> All {
                get {
                    return playerDataList;
                }
            }
            public PlayerDataController() {
            }
            public PlayerDataController(string filename = null ) {
                if (filename == null ) {
                    return;
                }
                _file = new JSONFile<Dictionary<string, T>>(filename );
                playerData = _file.Instance;
                _timer = _plugin.timer.Every(600f, () => {
                    _file.Save();
                }
                );
            }
            [OnDeserialized]
            internal void OnDeserializedMethod(StreamingContext context ) {
                //Recreates the cached list after it is deserialized
                //Someone smart would of saved it as a list instead of a dictionary and used the dictionary as the cache, OH WELL
                playerDataList.AddRange(playerData.Values );
            }
            public void Unload() {
                if (_file == null ) {
                    return;
                }
                _file.Save();
            }
            public T Get(string identifer ) {
                T data;
                if (!playerData.TryGetValue(identifer, out data ) ) {
                    data = Activator.CreateInstance<T>();
                    data.userID = ulong.Parse(identifer );
                    playerData[identifer ] = data;
                    playerDataList.Add(data );
                }
                return data;
            }
            public T Get(ulong userID ) {
                return Get(userID.ToString() );
            }
            public T Get(BasePlayer player ) {
                var data = Get(player.UserIDString );
                return data;
            }
            public bool Has(ulong userID ) {
                return playerData.ContainsKey(userID.ToString() );
            }
            public void Set(string userID, T data ) {
                playerData[userID ] = data;
            }
        }
#endregion
#region ImageLibrary
        [PluginReference]
        RustPlugin ImageLibrary;
        public static bool ImageLibraryReady() {
            return _plugin.ImageLibrary != null;
        }
        public static string GetItemURL(string shortname, ulong skinID ) {
            if (_plugin.ImageLibrary == null ) {
                _plugin.PrintError("ImageLibrary not found!" );
                return "";
            }
            string url = _plugin.ImageLibrary.Call("GetImage", shortname, skinID, true ) as string;
            return url;
        }
        public static string GetImage(string shortname, ulong skinID ) {
            var str = _plugin.ImageLibrary.Call("GetImage", shortname, skinID ) as string;
            return str;
        }
        public static bool HasImage(string shortname, ulong skinID ) {
            return (_plugin.ImageLibrary.Call("HasImage", shortname, skinID ) as bool? ) ?? false;
        }
        public static byte[] GetImageBytes(string shortname, ulong skinID = 0 ) {
            var imageString = GetImage(shortname, skinID );
            uint id;
            if (!uint.TryParse(imageString, out id ) ) {
                return null;
            }
            return FileStorage.server.Get(id, FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID );
        }
        public static void AddImage(string url, string shortname, ulong skinID ) {
            _plugin.ImageLibrary.Call("AddImage", url, shortname, skinID );
        }
        public static void AddImage(byte[] pngBytes, string shortname, ulong skinID ) {
            _plugin.ImageLibrary.Call("AddImageData", shortname, pngBytes, skinID );
        }
#endregion
#region Configuration Files
        public enum ConfigLocation {
            Data = 0, Config = 1, Logs = 2, Plugins = 3, Lang = 4, Custom = 5,
        }
        public class JSONFile<Type> where Type : class {
            private DynamicConfigFile _file;
            public string _name {
                get;
                set;
            }
            public Type Instance {
                get;
                set;
            }
            private ConfigLocation _location {
                get;
                set;
            }
            private string _path {
                get;
                set;
            }
            public JSONFile(string name, ConfigLocation location = ConfigLocation.Data, string path = null, string extension = ".json" ) {
                _name = name.Replace(".json", "" );
                _location = location;
                switch (location ) {
                    case ConfigLocation.Data : {
                        _path = $"{Oxide.Core.Interface.Oxide.DataDirectory}/{name}{extension}";
                        break;
                    }
                    case ConfigLocation.Config : {
                        _path = $"{Oxide.Core.Interface.Oxide.ConfigDirectory}/{name}{extension}";
                        break;
                    }
                    case ConfigLocation.Logs : {
                        _path = $"{Oxide.Core.Interface.Oxide.LogDirectory}/{name}{extension}";
                        break;
                    }
                    case ConfigLocation.Lang : {
                        _path = $"{Oxide.Core.Interface.Oxide.LangDirectory}/{name}{extension}";
                        break;
                    }
                    case ConfigLocation.Custom : {
                        _path = $"{path}/{name}{extension}";
                        break;
                    }
                }
                _file = new DynamicConfigFile(_path );
                _file.Settings = new JsonSerializerSettings() {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                }
                ;
                Init();
            }
            public virtual void Init() {
                Load();
                Save();
                Load();
            }
            public virtual void Load() {
                if (!_file.Exists() ) {
                    Save();
                }
                Instance = _file.ReadObject<Type>();
                if (Instance == null ) {
                    Instance = Activator.CreateInstance<Type>();
                    Save();
                }
                return;
            }
            public virtual void Save() {
                _file.WriteObject(Instance );
                return;
            }
            public virtual void Reload() {
                Load();
            }
            private void Unload(Plugin sender, PluginManager manager ) {
            }
        }
#endregion
#region UI
        private void RegisterUICommands() {
            cmd.AddConsoleCommand("ui.tuclose", this, AUCloseUICommand );
            cmd.AddConsoleCommand("ui.tuclicked", this, AUUIClickedCommands );
            cmd.AddConsoleCommand("ui.tuinput", this, AUUIInputCommand );
        }
        bool AUCloseUICommand(ConsoleSystem.Arg args ) {
            UICallbackManager.OnUIClosedOnClient(args );
            return true;
        }
        bool AUUIClickedCommands(ConsoleSystem.Arg args ) {
            UICallbackManager.OnButtonClicked(args );
            return true;
        }
        bool AUUIInputCommand(ConsoleSystem.Arg args ) {
            UICallbackManager.OnInputFieldEntered(args );
            return true;
        }
#region Colors
        public static class Colors {
            public static Color Transparent => new Color();
            public static class Rust {
                public static readonly Color player = HexColor(0x50, 0xa0, 0xf0 );
                public static readonly Color admin = HexColor(0xa0, 0xf0, 0x50 );
                public static readonly Color dev = HexColor(0xf0, 0xa0, 0x50 );
            }
            public static class Red {
                public static readonly Color lightsalmon = HexColor(0xFF, 0xA0, 0x7A );
                public static readonly Color salmon = HexColor(0xFA, 0x80, 0x72 );
                public static readonly Color darksalmon = HexColor(0xE9, 0x96, 0x7A );
                public static readonly Color lightcoral = HexColor(0xF0, 0x80, 0x80 );
                public static readonly Color indianred = HexColor(0xCD, 0x5C, 0x5C );
                public static readonly Color crimson = HexColor(0xDC, 0x14, 0x3C );
                public static readonly Color firebrick = HexColor(0xB2, 0x22, 0x22 );
                public static readonly Color red = HexColor(0xFF, 0x00, 0x00 );
                public static readonly Color darkred = HexColor(0x8B, 0x00, 0x00 );
            }
            public static class Orange {
                public static readonly Color coral = HexColor(0xFF, 0x7F, 0x50 );
                public static readonly Color tomato = HexColor(0xFF, 0x63, 0x47 );
                public static readonly Color orangered = HexColor(0xFF, 0x45, 0x00 );
                public static readonly Color gold = HexColor(0xFF, 0xD7, 0x00 );
                public static readonly Color orange = HexColor(0xFF, 0xA5, 0x00 );
                public static readonly Color darkorange = HexColor(0xFF, 0x8C, 0x00 );
            }
            public static class Yellow {
                public static readonly Color lightyellow = HexColor(0xFF, 0xFF, 0xE0 );
                public static readonly Color lemonchiffon = HexColor(0xFF, 0xFA, 0xCD );
                public static readonly Color lightgoldenrodyellow = HexColor(0xFA, 0xFA, 0xD2 );
                public static readonly Color papayawhip = HexColor(0xFF, 0xEF, 0xD5 );
                public static readonly Color moccasin = HexColor(0xFF, 0xE4, 0xB5 );
                public static readonly Color peachpuff = HexColor(0xFF, 0xDA, 0xB9 );
                public static readonly Color palegoldenrod = HexColor(0xEE, 0xE8, 0xAA );
                public static readonly Color khaki = HexColor(0xF0, 0xE6, 0x8C );
                public static readonly Color darkkhaki = HexColor(0xBD, 0xB7, 0x6B );
                public static readonly Color yellow = HexColor(0xFF, 0xFF, 0x00 );
            }
            public static class Green {
                public static readonly Color lawngreen = HexColor(0x7C, 0xFC, 0x00 );
                public static readonly Color chartreuse = HexColor(0x7F, 0xFF, 0x00 );
                public static readonly Color limegreen = HexColor(0x32, 0xCD, 0x32 );
                public static readonly Color lime = HexColor(0x00, 0xFF, 0x00 );
                public static readonly Color forestgreen = HexColor(0x22, 0x8B, 0x22 );
                public static readonly Color green = HexColor(0x00, 0x80, 0x00 );
                public static readonly Color darkgreen = HexColor(0x00, 0x64, 0x00 );
                public static readonly Color greenyellow = HexColor(0xAD, 0xFF, 0x2F );
                public static readonly Color yellowgreen = HexColor(0x9A, 0xCD, 0x32 );
                public static readonly Color springgreen = HexColor(0x00, 0xFF, 0x7F );
                public static readonly Color mediumspringgreen = HexColor(0x00, 0xFA, 0x9A );
                public static readonly Color lightgreen = HexColor(0x90, 0xEE, 0x90 );
                public static readonly Color palegreen = HexColor(0x98, 0xFB, 0x98 );
                public static readonly Color darkseagreen = HexColor(0x8F, 0xBC, 0x8F );
                public static readonly Color mediumseagreen = HexColor(0x3C, 0xB3, 0x71 );
                public static readonly Color seagreen = HexColor(0x2E, 0x8B, 0x57 );
                public static readonly Color olive = HexColor(0x80, 0x80, 0x00 );
                public static readonly Color darkolivegreen = HexColor(0x55, 0x6B, 0x2F );
                public static readonly Color olivedrab = HexColor(0x6B, 0x8E, 0x23 );
            }
            public static class Cyan {
                public static readonly Color lightcyan = HexColor(0xE0, 0xFF, 0xFF );
                public static readonly Color cyan = HexColor(0x00, 0xFF, 0xFF );
                public static readonly Color aqua = HexColor(0x00, 0xFF, 0xFF );
                public static readonly Color aquamarine = HexColor(0x7F, 0xFF, 0xD4 );
                public static readonly Color mediumaquamarine = HexColor(0x66, 0xCD, 0xAA );
                public static readonly Color paleturquoise = HexColor(0xAF, 0xEE, 0xEE );
                public static readonly Color turquoise = HexColor(0x40, 0xE0, 0xD0 );
                public static readonly Color mediumturquoise = HexColor(0x48, 0xD1, 0xCC );
                public static readonly Color darkturquoise = HexColor(0x00, 0xCE, 0xD1 );
                public static readonly Color lightseagreen = HexColor(0x20, 0xB2, 0xAA );
                public static readonly Color cadetblue = HexColor(0x5F, 0x9E, 0xA0 );
                public static readonly Color darkcyan = HexColor(0x00, 0x8B, 0x8B );
                public static readonly Color teal = HexColor(0x00, 0x80, 0x80 );
            }
            public static class Blue {
                public static readonly Color powderblue = HexColor(0xB0, 0xE0, 0xE6 );
                public static readonly Color lightblue = HexColor(0xAD, 0xD8, 0xE6 );
                public static readonly Color lightskyblue = HexColor(0x87, 0xCE, 0xFA );
                public static readonly Color skyblue = HexColor(0x87, 0xCE, 0xEB );
                public static readonly Color deepskyblue = HexColor(0x00, 0xBF, 0xFF );
                public static readonly Color lightsteelblue = HexColor(0xB0, 0xC4, 0xDE );
                public static readonly Color dodgerblue = HexColor(0x1E, 0x90, 0xFF );
                public static readonly Color cornflowerblue = HexColor(0x64, 0x95, 0xED );
                public static readonly Color steelblue = HexColor(0x46, 0x82, 0xB4 );
                public static readonly Color royalblue = HexColor(0x41, 0x69, 0xE1 );
                public static readonly Color blue = HexColor(0x00, 0x00, 0xFF );
                public static readonly Color mediumblue = HexColor(0x00, 0x00, 0xCD );
                public static readonly Color darkblue = HexColor(0x00, 0x00, 0x8B );
                public static readonly Color navy = HexColor(0x00, 0x00, 0x80 );
                public static readonly Color midnightblue = HexColor(0x19, 0x19, 0x70 );
                public static readonly Color mediumslateblue = HexColor(0x7B, 0x68, 0xEE );
                public static readonly Color slateblue = HexColor(0x6A, 0x5A, 0xCD );
                public static readonly Color darkslateblue = HexColor(0x48, 0x3D, 0x8B );
            }
            public static class Purple {
                public static readonly Color lavender = HexColor(0xE6, 0xE6, 0xFA );
                public static readonly Color thistle = HexColor(0xD8, 0xBF, 0xD8 );
                public static readonly Color plum = HexColor(0xDD, 0xA0, 0xDD );
                public static readonly Color violet = HexColor(0xEE, 0x82, 0xEE );
                public static readonly Color orchid = HexColor(0xDA, 0x70, 0xD6 );
                public static readonly Color fuchsia = HexColor(0xFF, 0x00, 0xFF );
                public static readonly Color magenta = HexColor(0xFF, 0x00, 0xFF );
                public static readonly Color mediumorchid = HexColor(0xBA, 0x55, 0xD3 );
                public static readonly Color mediumpurple = HexColor(0x93, 0x70, 0xDB );
                public static readonly Color blueviolet = HexColor(0x8A, 0x2B, 0xE2 );
                public static readonly Color darkviolet = HexColor(0x94, 0x00, 0xD3 );
                public static readonly Color darkorchid = HexColor(0x99, 0x32, 0xCC );
                public static readonly Color darkmagenta = HexColor(0x8B, 0x00, 0x8B );
                public static readonly Color purple = HexColor(0x80, 0x00, 0x80 );
                public static readonly Color indigo = HexColor(0x4B, 0x00, 0x82 );
            }
            public static class Pink {
                public static readonly Color pink = HexColor(0xFF, 0xC0, 0xCB );
                public static readonly Color lightpink = HexColor(0xFF, 0xB6, 0xC1 );
                public static readonly Color hotpink = HexColor(0xFF, 0x69, 0xB4 );
                public static readonly Color deeppink = HexColor(0xFF, 0x14, 0x93 );
                public static readonly Color palevioletred = HexColor(0xDB, 0x70, 0x93 );
                public static readonly Color mediumvioletred = HexColor(0xC7, 0x0, 0x85 );
            }
            public static class White {
                public static readonly Color white = HexColor(0xFF, 0xFF, 0xFF );
                public static readonly Color snow = HexColor(0xFF, 0xFA, 0xFA );
                public static readonly Color honeydew = HexColor(0xF0, 0xFF, 0xF0 );
                public static readonly Color mintcream = HexColor(0xF5, 0xFF, 0xFA );
                public static readonly Color azure = HexColor(0xF0, 0xFF, 0xFF );
                public static readonly Color aliceblue = HexColor(0xF0, 0xF8, 0xFF );
                public static readonly Color ghostwhite = HexColor(0xF8, 0xF8, 0xFF );
                public static readonly Color whitesmoke = HexColor(0xF5, 0xF5, 0xF5 );
                public static readonly Color seashell = HexColor(0xFF, 0xF5, 0xEE );
                public static readonly Color beige = HexColor(0xF5, 0xF5, 0xDC );
                public static readonly Color oldlace = HexColor(0xFD, 0xF5, 0xE6 );
                public static readonly Color floralwhite = HexColor(0xFF, 0xFA, 0xF0 );
                public static readonly Color ivory = HexColor(0xFF, 0xFF, 0xF0 );
                public static readonly Color antiquewhite = HexColor(0xFA, 0xEB, 0xD7 );
                public static readonly Color linen = HexColor(0xFA, 0xF0, 0xE6 );
                public static readonly Color lavenderblush = HexColor(0xFF, 0xF0, 0xF5 );
            }
            public static class Grey {
                public static readonly Color gainsboro = HexColor(0xDC, 0xDC, 0xDC );
                public static readonly Color lightgray = HexColor(0xD3, 0xD3, 0xD3 );
                public static readonly Color silver = HexColor(0xC0, 0xC0, 0xC0 );
                public static readonly Color darkgray = HexColor(0xA9, 0xA9, 0xA9 );
                public static readonly Color gray = HexColor(0x80, 0x80, 0x80 );
                public static readonly Color dimgray = HexColor(0x69, 0x69, 0x69 );
                public static readonly Color lightslategray = HexColor(0x77, 0x88, 0x99 );
                public static readonly Color slategray = HexColor(0x70, 0x80, 0x90 );
                public static readonly Color darkslategray = HexColor(0x2F, 0x4F, 0x4F );
                public static readonly Color black = HexColor(0x00, 0x00, 0x00 );
            }
            public static class Black {
                public static readonly Color gainsboro = HexColor(0xDC, 0xDC, 0xDC );
                public static readonly Color lightgray = HexColor(0xD3, 0xD3, 0xD3 );
                public static readonly Color silver = HexColor(0xC0, 0xC0, 0xC0 );
                public static readonly Color darkgray = HexColor(0xA9, 0xA9, 0xA9 );
                public static readonly Color gray = HexColor(0x80, 0x80, 0x80 );
                public static readonly Color dimgray = HexColor(0x69, 0x69, 0x69 );
                public static readonly Color lightslategray = HexColor(0x77, 0x88, 0x99 );
                public static readonly Color slategray = HexColor(0x70, 0x80, 0x90 );
                public static readonly Color darkslategray = HexColor(0x2F, 0x4F, 0x4F );
                public static readonly Color black = HexColor(0x00, 0x00, 0x00 );
            }
            public static class Brown {
                public static readonly Color cornsilk = HexColor(0xFF, 0xF8, 0xDC );
                public static readonly Color blanchedalmond = HexColor(0xFF, 0xEB, 0xCD );
                public static readonly Color bisque = HexColor(0xFF, 0xE4, 0xC4 );
                public static readonly Color navajowhite = HexColor(0xFF, 0xDE, 0xAD );
                public static readonly Color wheat = HexColor(0xF5, 0xDE, 0xB3 );
                public static readonly Color burlywood = HexColor(0xDE, 0xB8, 0x87 );
                public static readonly Color tan = HexColor(0xD2, 0xB4, 0x8C );
                public static readonly Color rosybrown = HexColor(0xBC, 0x8F, 0x8F );
                public static readonly Color sandybrown = HexColor(0xF4, 0xA4, 0x60 );
                public static readonly Color goldenrod = HexColor(0xDA, 0xA5, 0x20 );
                public static readonly Color peru = HexColor(0xCD, 0x85, 0x3F );
                public static readonly Color chocolate = HexColor(0xD2, 0x69, 0x1E );
                public static readonly Color saddlebrown = HexColor(0x8B, 0x45, 0x10 );
                public static readonly Color sienna = HexColor(0xA0, 0x52, 0x2D );
                public static readonly Color brown = HexColor(0xA5, 0x2A, 0x2A );
                public static readonly Color maroon = HexColor(0x80, 0x00, 0x00 );
            }
            public static Color HexColor(int r, int g, int b ) {
                return new Color(r / 255f, g / 255f, b / 255f );
            }
        }
#endregion
        public class
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху