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

FREE WarModeAdminPanel : 1.1.1 1.1.1

Нет прав для скачивания
C#:
// Requires: WarMode
using static Oxide.Plugins.WarMode;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using UnityEngine.UI;
using Oxide.Core.Plugins;
using System.Collections.Generic;
using Oxide.Plugins.WarModeMethods;
using System;
using UnityEngine;
using Oxide.Core.Libraries.Covalence;
using System.Linq;
namespace Oxide.Plugins {
    [Info("War Mode Admin Panel", "mr01sam", "1.1.1")]
    [Description("Admin UI for configuring War Mode in game.")]
    public partial class WarModeAdminPanel : CovalencePlugin {
        [PluginReference]
        private readonly Plugin SimpleStatus, RaidableBases;
        // UI SETTINGS
        private const float w = 1080;
        private const float h = 640;
        private const float padding = 8;
        private const string mainBgColor = "0.08627 0.08627 0.08627 1";
        private const string headerBgColor = "0.15686 0.15686 0.12549 1";
        private const string headerBgColorFaded = "0.15686 0.15686 0.12549 0.4";
        private const string headerTextColor = "0.54509 0.51372 0.4705 1";
        private const float headerHeight = 32;
        private const string inputFieldBgColor = "0.15686 0.15686 0.12549 1";
        private const float bottomHeight = 48;
        private const string generalTextColor = "0.7 0.7 0.7 1";
        private const string generalTextColorFaded = "0.7 0.7 0.7 0.6";
        private const int generalTextSize = 14;
        private const float panelHeaderText = 14;
        private const float panelHeaderHeight = 18;
        private const string poscolor = "0.69804 0.83137 0.46667 1";
        private const string negcolor = "0.77255 0.23922 0.15686 1";
        private const string selcolor = "#f5f542";
        private const float ruleWidth = 212;
        private const float ruleHeaderHeight = 28;
        private float ruleRowHeight = 24;
        private const float ruleGap = 2;
        private const float navHeight = 24;
        private const float modeColGap = 2;
        private const float maxModeColWidth = 80;
        private const float minModeColNum = 6;
        private const float totalModeColWidth = maxModeColWidth * minModeColNum;
        private float modeColWidth = maxModeColWidth;
        private const float toolBtnHeight = 24;
        private const float toolBtnWidth = 64;
        private const float toolBtnGap = 2;
        private const float toolBtnSpriteSize = 12;
        private const int toolBtnTextSize = 8;
        private const float toolBtnPadding = 4;
        private const string toolBtnColor = headerBgColor;
        private const string toolBtnTextColor = headerTextColor;
        private bool descriptive = true;
        public static WarModeAdminPanel INSTANCE = null;
        public WarMode.Configuration ModifiedConfig;
        void OnServerInitialized() {
            INSTANCE = this;
            //foreach (var basePlayer in BasePlayer.activePlayerList)
            //{
            //    currentPageRoute = "modes";
            //    ShowUI(basePlayer);
            //}
        }
        void Unload() {
            Close();
        }
        private string mainPanel;
        private string pageId;
        private string navBar;
        private string currentModeName = null;
        private string currentPageRoute = "rules";
        private bool isDirty = false;
        private BasePlayer editingPlayer = null;
        [Command("warmode.ui.applychanges")]
        private void CmdWarModeUiApplyChanges(IPlayer player, string command, string[] args) {
            // warmode.ui.applychanges
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            ApplyChanges();
            ShowUI(basePlayer);
        }
        [Command("warmode.ui.resetchanges")]
        private void CmdWarModeUiResetChanges(IPlayer player, string command, string[] args) {
            // warmode.ui.resetchanges
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            ResetChanges();
            ShowUI(basePlayer);
        }
        [Command("warmode.ui.close")]
        private void CmdWarModeUiClose(IPlayer player, string command, string[] args) {
            // warmode.ui.close
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer.UserIDString != editingPlayer.UserIDString) {
                return;
            }
            Close();
        }
        private void Close() {
            CuiHelper.DestroyUi(editingPlayer, ID);
            if (isDirty) {
                editingPlayer.ChatMessage("Your WarMode config changes have NOT been applied.Reopen the WarMode admin panel and click APPLY CHANGES for them to take effect.");
            }
            editingPlayer = null;
            ElementsLoaded.Clear();
        }
        public void ApplyChanges() {
            WarMode.INSTANCE.SaveConfigExternal(ModifiedConfig);
            isDirty = false;
        }
        public void ResetChanges() {
            ModifiedConfig = JsonConvert.DeserializeObject<WarMode.Configuration>(JsonConvert.SerializeObject(CONFIG));
            isDirty = false;
        }
        public void CreateBottomButton() {
            var container = new CuiElementContainer();
            var offset = 70f;
            var bottomBar = ID + "bottom";
            var bottomBtn = Create(container, bottomBar, new CuiElement {
                Name = ID + "bottomBtn", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-60-offset} {-16}", OffsetMax = $"{60-offset} {16}"
                    }
                    , new CuiButtonComponent {
                        Color = isDirty ? $"0.385 0.478 0.228 1" : "0.3 0.3 0.3 0.5", Command = isDirty ? "warmode.ui.applychanges" : ""
                    }
                }
            }
            );
            var bottomBtnText = Create(container, bottomBtn, new CuiElement {
                Components = {
                    new CuiTextComponent {
                        Text = "APPLY CHANGES", Align = UnityEngine.TextAnchor.MiddleCenter, Color = isDirty ? $"0.76078 0.94510 0.41176 1" : "0.5 0.5 0.5 0.5"
                    }
                }
            }
            );
            var resetBtn = Create(container, bottomBar, new CuiElement {
                Name = ID + "resetBtn", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-60+offset} {-16}", OffsetMax = $"{60+offset} {16}"
                    }
                    , new CuiButtonComponent {
                        Color = isDirty ? $"0.3 0.3 0.3 1" : "0.3 0.3 0.3 0.5", Command = isDirty ? "warmode.ui.resetchanges" : ""
                    }
                }
            }
            );
            var resetBtnText = Create(container, resetBtn, new CuiElement {
                Components = {
                    new CuiTextComponent {
                        Text = "UNDO CHANGES", Align = UnityEngine.TextAnchor.MiddleCenter, Color = isDirty ? $"0.9 0.9 0.9 1" : "0.5 0.5 0.5 0.5"
                    }
                }
            }
            );
            CuiHelper.DestroyUi(editingPlayer, bottomBtn);
            CuiHelper.DestroyUi(editingPlayer, resetBtn);
            CuiHelper.AddUi(editingPlayer, container);
        }
        public void ShowUI(BasePlayer basePlayer) {
            editingPlayer = basePlayer;
            expanededRules = new List<string>();
            if (ModifiedConfig == null) {
                ResetChanges();
            }
            currentModeName = ModifiedConfig.Modes.FirstOrDefault()?.Name;
            var container = new CuiElementContainer();
            mainPanel = Create(container, new CuiElement {
                Name = ID, Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-w/2} {-h/2}", OffsetMax = $"{w/2} {h/2}"
                    }
                    , new CuiImageComponent {
                        Color = mainBgColor
                    }
                    , new CuiNeedsCursorComponent {
                    }
                }
            }
            );
            var titleBar = Create(container, mainPanel, new CuiElement {
                Name = ID + "title", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-headerHeight}", OffsetMax = $"{0} {0}"
                    }
                    , new CuiImageComponent {
                        Color = headerBgColor
                    }
                }
            }
            );
            var titleBarText = Create(container, titleBar, new CuiElement {
                Components = {
                    new CuiTextComponent {
                        Text = "WAR MODE CONFIGURATION", Color = headerTextColor, Align = UnityEngine.TextAnchor.MiddleCenter
                    }
                }
            }
            );
            var titleBarBtn = Create(container, titleBar, new CuiElement {
                Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = $"{-16-8} {-8}", OffsetMax = $"{-8} {8}"
                    }
                    , new CuiButtonComponent {
                        Color = headerTextColor, Sprite = "assets/icons/close.png", Command = "warmode.ui.close"
                    }
                }
            }
            );
            var bottomBar = Create(container, mainPanel, new CuiElement {
                Name = ID + "bottom", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = $"{0} {0}", OffsetMax = $"{0} {bottomHeight}"
                    }
                    , new CuiImageComponent {
                        Color = headerBgColor
                    }
                }
            }
            );
            CuiHelper.DestroyUi(editingPlayer, ID);
            CuiHelper.AddUi(editingPlayer, container);
            ShowNavBar();
            CreateBottomButton();
            ReloadPageRoute();
        }
        [Command("warmode.ui.setnavpage")]
        private void CmdWarModeUiSetNavPage(IPlayer player, string command, string[] args) {
            // warmode.ui.setnavpage <route>
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            var route = args[0];
            currentPageRoute = route;
            ReloadPageRoute();
        }
        private void ReloadPageRoute() {
            switch (currentPageRoute) {
                case "rules" : ReloadRulesPage();
                break;
                case "modes" : ReloadModesPage();
                break;
                case "settings" : ReloadSettingsPage();
                break;
            }
            ShowNavBar();
        }
        private void ShowNavBar() {
            var container = new CuiElementContainer();
            var navBar = Create(container, mainPanel, new CuiElement {
                Name = ID + "navbar", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-headerHeight-navHeight}", OffsetMax = $"{0} {-headerHeight}"
                    }
                    ,  //new CuiImageComponent
                    //{
                    //    Color = DARKEN
                    //}
                }
            }
            );
            var navPages = new[] {
                new {
                    Title = "Rules", Route = "rules"
                }
                , new {
                    Title = "Modes", Route = "modes"
                }
                , new {
                    Title = "Settings", Route = "settings"
                }
            }
            ;
            var w = 100;
            var p = 8;
            var left = p;
            foreach(var page in navPages) {
                var navBtn = Create(container, navBar, new CuiElement {
                    Components = {
                        new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "0 1", OffsetMin = $"{left} {4}", OffsetMax = $"{left+w} {-4}"
                        }
                        , new CuiButtonComponent {
                            Color = page.Route == currentPageRoute ? headerBgColor : headerBgColorFaded, Command = $"warmode.ui.setnavpage {page.Route}"
                        }
                    }
                }
                );
                var navTxt = Create(container, navBtn, new CuiElement {
                    Components = {
                        new CuiTextComponent {
                            Text = page.Title, Align = TextAnchor.MiddleCenter, Color = headerTextColor, FontSize = 10
                        }
                    }
                }
                );
                left += p + w;
            }
            CuiHelper.DestroyUi(editingPlayer, navBar);
            CuiHelper.AddUi(editingPlayer, container);
        }
#region Helper Methods
        public string Create(CuiElementContainer container, CuiElement newElement) => Create(container, "Overlay", newElement);
        public Dictionary<string, CuiElement> ElementsLoaded = new Dictionary<string, CuiElement>();
        public string Create(CuiElementContainer container, string parent, CuiElement newElement) {
            newElement.Parent = parent;
            if (string.IsNullOrWhiteSpace(newElement.Name)) {
                newElement.Name = Guid.NewGuid().ToString();
            }
            ElementsLoaded[newElement.Name] = newElement;
            container.Add(newElement);
            return newElement.Name;
        }
        public void Update(CuiElement newElement) {
            var container = new CuiElementContainer();
            container.Add(newElement);
            ElementsLoaded[newElement.Name] = newElement;
            CuiHelper.AddUi(editingPlayer, container);
        }
        public void UpdateButtonText(string id, string text, string textColor) {
            var element = ElementsLoaded.GetValueOrDefault(id);
            if (element == null) {
                return;
            }
            foreach (var comp in element.Components) {
                if (comp is CuiTextComponent textComp) {
                    textComp.Text = text;
                    textComp.Color = textColor;
                    element.Update = true;
                }
            }
            Update(element);
        }
        public void UpdateInputText(string id, string text, string textColor) {
            var element = ElementsLoaded.GetValueOrDefault(id);
            if (element == null) {
                return;
            }
            foreach (var comp in element.Components) {
                if (comp is CuiInputFieldComponent textComp) {
                    textComp.Text = text;
                    textComp.Color = textColor;
                    element.Update = true;
                }
            }
            Update(element);
        }
        public string Color(string text, string hexColor) {
            return $"<color={hexColor}>{text}</color>";
        }
#endregion
#region Localization
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
            }
            , this);
        }
        private string Lang(string key, string id, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
#endregion
#region Config
        private Configuration config;
        private class Configuration {
            public string CustomUI = "";
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config == null) throw new Exception();
            }
            catch {
                PrintError("Your configuration file contains an error.Using default configuration values.");
                LoadDefaultConfig();
            }
            SaveConfig();
        }
        protected override void SaveConfig() => Config.WriteObject(config);
        protected override void LoadDefaultConfig() => config = new Configuration();
#endregion
    }
}
namespace Oxide.Plugins {
    public partial class WarModeAdminPanel {
        public void ReloadModesPage() {
            var container = new CuiElementContainer();
            pageId = Create(container, mainPanel, new CuiElement {
                Name = ID + "page", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"{0} {0}", OffsetMax = $"{0} {-headerHeight-navHeight-padding}"
                    }
                }
            }
            );
            CuiHelper.DestroyUi(editingPlayer, pageId);
            CuiHelper.AddUi(editingPlayer, container);
            ShowModesGrid();
        }
        public struct ColumnDef {
            public string Label;
            public string SubLabel;
            public string Property;
            public string Type;
            public float Width;
            public Func<WarMode.ModeConfig, string, bool> Validate;
            public Func<WarMode.ModeConfig, string, string> Clean;
            public Func<WarMode.ModeConfig, string> Value;
            public Action<WarMode.ModeConfig, object> OnSet;
            public Func<WarMode.ModeConfig, bool> Hidden;
            public Func<WarMode.ModeConfig, bool> ReadOnly;
            public Func<bool> HideCol;
            public string HelpText;
        }
        public static readonly string WhiteHex = "#ffffff";
        private const float ShortColWidth = 60;
        private const float DefaultColWidth = 90;
        private const float LongColWidth = 120;
        private const int LabelFontSize = 12;
        ColumnDef[] ModeColumns = new ColumnDef[] {
            new ColumnDef {
                Label = "", Property = null, Width = 16
            }
            , new ColumnDef {
                Label = "Mode ID", Property = "mode", Width = DefaultColWidth, Value = (m) => m.Name, Clean = (m, v) => {
                    v.Trim().ToLower().Replace(" ", "_");
                    var invalid = "INVALID";
                    if (string.IsNullOrWhiteSpace(v)) {
                        v = invalid;
                    }
                    else if (INSTANCE.ModifiedConfig.Modes.Any(x => x.Name.ToLower().Trim() == v)) {
                        v = invalid;
                    }
                    return v;
                }
                , OnSet = (m, v) => m.Name = v.ToString(), ReadOnly = (m) => (INSTANCE.ModifiedConfig.Settings.NpcMode == m.Name) || (WarMode.CONFIG.Modes.Any(x => x.Name == m.Name)), HelpText = "The unique ID of the mode.This is NOT the display text.This should not be changed after it is initially set."
            }
            , new ColumnDef {
                Label = "Priority", Property = "priority", Width = ShortColWidth, Value = (m) => m.Priority.ToString(), Clean = (m, v) => {
                    v = v.Trim();
                    if (!int.TryParse(v, out int intval)) {
                        intval = 0;
                    }
                    if (intval <= 0) {
                        intval = 1;
                    }
                    if (INSTANCE.ModifiedConfig.Modes.Any(x => x.Priority == intval && x.Name != m.Name)) {
                        intval = (INSTANCE.ModifiedConfig.Modes.Where(x => x.Name != m.Name).Max(x => x.Priority) ?? 0)+1;
                    }
                    return intval.ToString();
                }
                , OnSet = (m, v) => m.Priority = int.Parse(v.ToString()), Hidden = (m) => INSTANCE.ModifiedConfig.Settings.NpcMode == m.Name, HelpText = "A number that is used to determine how important this mode is when compared to other modes.For example this is used when determining what the mode of a base should be when all the owners have different modes.Two modes should NOT have the same priority."
            }
            , new ColumnDef {
                Label = "Display Name", Property = "displayname", Width = DefaultColWidth, Value = (m) => m.DisplayName, OnSet = (m, v) => m.DisplayName = v.ToString(), HelpText = "The name of the mode that is displayed to players.This is not a localized value."
            }
            , new ColumnDef {
                Label = "Chat Color", Property = "color", Type = "color", Width = DefaultColWidth, Value = (m) => m.ColorHex, Clean = (m, v) => {
                    v = v.Trim();
                    if (!ColorUtility.TryParseHtmlString(v, out UnityEngine.Color color)) {
                        color = UnityEngine.Color.white;
                    }
                    return "#" + ColorUtility.ToHtmlStringRGBA(color);
                }
                , OnSet = (m, v) => m.ColorHex = v.ToString(), HelpText = "The color associated with this mode.When the mode is referenced in chat messages it will appear as this color.This does NOT affect the color the mode appears in SimpleStatus or the SpawnUI.You must edit the color in those respective configs."
            }
            , new ColumnDef {
                Label = "Permission Group", Property = "group", Width = LongColWidth, Clean = (m, v) => {
                    var invalid = "INVALID";
                    if (v == null) {
                        return invalid;
                    }
                    v.Trim().ToLower().Replace(" ", "");
                    if (string.IsNullOrWhiteSpace(v)) {
                        v = invalid;
                    }
                    else if (INSTANCE.ModifiedConfig.Modes.Any(x => x.Group?.ToLower().Trim() == v && x.Name != m.Name)) {
                        v = invalid;
                    }
                    return v;
                }
                , Value = (m) => m.Group, OnSet = (m, v) => m.Group = v.ToString(), Hidden = (m) => INSTANCE.ModifiedConfig.Settings.NpcMode == m.Name, HelpText = "The oxide/carbon permission group assigned to this mode.All modes except the NPC mode MUST have a permission group assigned to them.All modes must have a unique permission group."
            }
            ,  //new ColumnDef
            //{
            //    Label = "Bar Color",
            //    SubLabel = "SimpleStatus",
            //    Property = "ssbarcolor",
            //    Width = DefaultColWidth,
            //    Type = "color",
            //    HideCol = () => INSTANCE.SimpleStatus?.IsLoaded != true,
            //    Value = (m) =>
            //    {
            //        try
            //        {
            //            return INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.BackgroundColor?.ColorRgbToHex();
            //        } catch(Exception) { return WhiteHex; }
            //    },
            //    OnSet = (m, v) =>
            //    {
            //        try
            //        {
            //            if (!INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.ContainsKey(m.Name))
            //            {
            //                INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars[m.Name] = new WarMode.StatusDetailsConfig();
            //            }
            //            INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.BackgroundColor = v.ToString().ColorHexToRgb();
            //        } catch(Exception e) { throw e; }
            //    }
            //},
            //new ColumnDef
            //{
            //    Label = "Title Color",
            //    SubLabel = "SimpleStatus",
            //    Property = "sstitlecolor",
            //    Width = DefaultColWidth,
            //    Type = "color",
            //    HideCol = () => INSTANCE.SimpleStatus?.IsLoaded != true,
            //    Value = (m) =>
            //    {
            //        try
            //        {
            //            return INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.TitleColor?.ColorRgbToHex();
            //        } catch(Exception) { return WhiteHex; }
            //    },
            //    OnSet = (m, v) =>
            //    {
            //        try
            //        {
            //            if (!INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.ContainsKey(m.Name))
            //            {
            //                INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars[m.Name] = new WarMode.StatusDetailsConfig();
            //            }
            //            INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.TitleColor = v.ToString().ColorHexToRgb();
            //        } catch(Exception e) { throw e; }
            //    }
            //},
            //new ColumnDef
            //{
            //    Label = "Text Color",
            //    SubLabel = "SimpleStatus",
            //    Property = "sstextcolor",
            //    Width = DefaultColWidth,
            //    Type = "color",
            //    HideCol = () => INSTANCE.SimpleStatus?.IsLoaded != true,
            //    Value = (m) =>
            //    {
            //        try
            //        {
            //            return INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.TextColor?.ColorRgbToHex();
            //        } catch(Exception) { return WhiteHex; }
            //    },
            //    OnSet = (m, v) =>
            //    {
            //        try
            //        {
            //            if (!INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.ContainsKey(m.Name))
            //            {
            //                INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars[m.Name] = new WarMode.StatusDetailsConfig();
            //            }
            //            INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.TextColor = v.ToString().ColorHexToRgb();
            //        } catch(Exception e) { throw e; }
            //    }
            //},
            //new ColumnDef
            //{
            //    Label = "Image Color",
            //    SubLabel = "SimpleStatus",
            //    Property = "ssimagecolor",
            //    Width = DefaultColWidth,
            //    Type = "color",
            //    HideCol = () => INSTANCE.SimpleStatus?.IsLoaded != true,
            //    Value = (m) =>
            //    {
            //        try
            //        {
            //            return INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.ImageColor?.ColorRgbToHex();
            //        } catch(Exception) { return WhiteHex; }
            //    },
            //    OnSet = (m, v) =>
            //    {
            //        try
            //        {
            //            if (!INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.ContainsKey(m.Name))
            //            {
            //                INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars[m.Name] = new WarMode.StatusDetailsConfig();
            //            }
            //            INSTANCE.ModifiedConfig.SimpleStatus.ModeStatusBars.FirstOrDefault(x => x.Key == m.Name).Value.ImageColor = v.ToString().ColorHexToRgb();
            //        } catch(Exception e) { throw e; }
            //    }
            //}
        }
        ;
        private const float modeGridColHeight = 24;
        private const float modeGridRowHeight = 24;
        private const float modeGridColGap = 8;
        private const float modeGridRowGap = 8;
        [Command("warmode.ui.setmodeproperty")]
        private void CmdWarModeUiModeProperty(IPlayer player, string command, string[] args) {
            // warmode.ui.setmodeproperty <modeid> <property> <value>
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            var modeid = args[0];
            var property = args[1];
            var value = string.Join(" ", args.Skip(2));
            var mode = ModifiedConfig.Modes.First(x => x.Name == modeid);
            var col = ModeColumns.First(x => x.Property == property);
            if (value == null || col.Value(mode) == value.ToString()) {
                return;
            }
            value = col.Clean?.Invoke(mode, value) ?? value;
            if (!(col.Validate?.Invoke(mode, value) ?? true)) {
                // TODO invalid
                return;
            }
            col.OnSet.Invoke(mode, value);
            if (!isDirty) {
                isDirty = true;
                CreateBottomButton();
            }
            ShowModesGrid();
        }
        [Command("warmode.ui.addmode")]
        private void CmdWarModeUiAddMode(IPlayer player, string command, string[] args) {
            // warmode.ui.addmode
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            var modes = ModifiedConfig.Modes.ToList();
            var newmode = WarMode.ModeConfig.New();
            newmode.Name = $"mode" + modes.Count;
            newmode.DisplayName = "Mode " + modes.Count;
            newmode.Priority = ModifiedConfig.Modes.Max(x => x.Priority) + 1;
            newmode.Group = newmode.Name;
            modes.Add(newmode);
            ModifiedConfig.Modes = modes.ToArray();
            if (!isDirty) {
                isDirty = true;
                CreateBottomButton();
            }
            ShowModesGrid();
            // TODO
        }
        [Command("warmode.ui.deletemode")]
        private void CmdWarModeUiDeleteMode(IPlayer player, string command, string[] args) {
            // warmode.ui.deletemode <name>
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            var modename = args[0];
            var newList = ModifiedConfig.Modes.ToList();
            newList.RemoveAll(x => x.Name == modename);
            ModifiedConfig.Modes = newList.ToArray();
            if (!isDirty) {
                isDirty = true;
                CreateBottomButton();
            }
            selectedMode = ModifiedConfig.Modes.FirstOrDefault()?.Name;
            ReloadModesPage();
        }
        [Command("warmode.ui.helptext")]
        private void CmdWarModeUiHelpText(IPlayer player, string command, string[] args) {
            // warmode.ui.helptext <titlecount> <title> <msg>
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            var skip = int.Parse(args[0]);
            var titletxt = string.Join(" ", args.Skip(1).Take(skip));
            var msg = string.Join(" ", args.Skip(skip+1));
            var container = new CuiElementContainer();
            var shadow = Create(container, ID, new CuiElement {
                Name = ID + "helptext", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1",
                    }
                    , new CuiButtonComponent {
                        Color = "0 0 0 0.9", Close = ID + "helptext"
                    }
                }
            }
            );
            var window = Create(container, shadow, new CuiElement {
                Name = ID + "helptextwindow", Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0.3 0.4", AnchorMax = "0.7 0.7",
                    }
                    , new CuiButtonComponent {
                        Color = mainBgColor, Close = ID + "helptext"
                    }
                }
            }
            );
            var padding = 8;
            var title = Create(container, window, new CuiElement {
                Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{padding} {-24-padding}", OffsetMax = $"{-padding} {-padding}"
                    }
                    , new CuiTextComponent {
                        Color = generalTextColor, Text = titletxt, Align = TextAnchor.MiddleCenter
                    }
                }
            }
            );
            var text = Create(container, window, new CuiElement {
                Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"{padding} {padding}", OffsetMax = $"{-padding} {-28-padding}"
                    }
                    , new CuiTextComponent {
                        Color = generalTextColor, Text = msg, Align = TextAnchor.MiddleCenter
                    }
                }
            }
            );
            CuiHelper.DestroyUi(editingPlayer, shadow);
            CuiHelper.AddUi(editingPlayer, container);
        }
        private void ShowModesGrid() {
            var gridid = ID + "modegrid";
            var container = new CuiElementContainer();
            var modeGrid = Create(container, pageId, new CuiElement {
                Name = gridid, Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"{padding} {padding}", OffsetMax = $"{-padding} {-padding}"
                    }
                }
            }
            );
            var modeGridHeader = Create(container, modeGrid, new CuiElement {
                Name = gridid, Components = {
                    new CuiRectTransformComponent {
                        AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"0 {-modeGridColHeight}", OffsetMax = $"0 0"
                    }
                }
            }
            );
            var modes = ModifiedConfig.Modes;
            var left = 0f;
            var colidx = 0;
            foreach (var col in ModeColumns) {
                if (col.HideCol?.Invoke() ?? false) {
                    continue;
                }
                var colLabel = Create(container, modeGridHeader, new CuiElement {
                    Components = {
                        new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "0 1", OffsetMin = $"{left} 0", OffsetMax = $"{left+col.Width} 0"
                        }
                        , new CuiTextComponent {
                            Text = col.Label, Color = generalTextColor, FontSize = LabelFontSize, Align = UnityEngine.TextAnchor.UpperLeft
                        }
                    }
                }
                );
                if (col.SubLabel != null) {
                    var colSubLabel = Create(container, modeGridHeader, new CuiElement {
                        Components = {
                            new CuiRectTransformComponent {
                                AnchorMin = "0 0", AnchorMax = "0 1", OffsetMin = $"{left} {-4}", OffsetMax = $"{left+col.Width} {-4}"
                            }
                            , new CuiTextComponent {
                                Text = "(" + col.SubLabel + ")", FontSize = LabelFontSize-2, Color = generalTextColorFaded, Align = UnityEngine.TextAnchor.LowerLeft
                            }
                        }
                    }
                    );
                }
                if (col.HelpText != null) {
                    var btnSize = 11;
                    var offset = -2;
                    var helpBtn = Create(container, modeGridHeader, new CuiElement {
                        Components = {
                            new CuiRectTransformComponent {
                                AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{left+col.Width-btnSize} {-btnSize+offset}", OffsetMax = $"{left+col.Width} {offset}"
                            }
                            , new CuiButtonComponent {
                                Sprite = "assets/icons/info.png", Color = generalTextColor, Command = $"warmode.ui.helptext {col.Label.Split(" ").Length} {col.Label} {col.HelpText}"
                            }
                        }
                    }
                    );
                }
                var down = modeGridColHeight + modeGridRowGap;
                var modeidx = 0;
                foreach (var mode in modes) {
                    if (col.Property == null) {
                        if (ModifiedConfig.Settings.NpcMode != mode.Name) {
                            var btnsize = 12;
                            var addbtnsprite = Create(container, modeGrid, new CuiElement {
                                Components = {
                                    new CuiRectTransformComponent {
                                        AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{left} {-down-modeGridRowHeight/2f-btnsize/2}", OffsetMax = $"{left+btnsize} {-down-modeGridRowHeight/2f+btnsize/2}"
                                    }
                                    , new CuiButtonComponent {
                                        Sprite = "assets/icons/close.png", Color = negcolor, Command = $"warmode.ui.deletemode {mode.Name}"
                                    }
                                }
                            }
                            );
                        }
                    }
                    else if (!(col.Hidden?.Invoke(mode) ?? false)) {
                        var modeField = Create(container, modeGrid, new CuiElement {
                            Components = {
                                new CuiRectTransformComponent {
                                    AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{left} {-down-modeGridRowHeight}", OffsetMax = $"{left+col.Width} {-down}"
                                }
                                , new CuiImageComponent {
                                    Color = inputFieldBgColor
                                }
                            }
                        }
                        );
                        var value = col.Value.Invoke(mode);
                        var readOnly = col.ReadOnly?.Invoke(mode) ?? false;
                        var modeInput = Create(container, modeField, new CuiElement {
                            Components = {
                                new CuiRectTransformComponent {
                                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"{4} {0}", OffsetMax = $"{-2} {0}"
                                }
                                , new CuiInputFieldComponent {
                                    Text = value == null ? string.Empty : value, FontSize = LabelFontSize, Align = UnityEngine.TextAnchor.MiddleLeft, Command = $"warmode.ui.setmodeproperty {mode.Name} {col.Property}", NeedsKeyboard = true, Color = readOnly ? "1 1 1 0.1" : generalTextColor, ReadOnly = readOnly
                                }
                            }
                        }
                        );
                        if (col.Type == "color") {
                            UnityEngine.Color color = UnityEngine.Color.white;
                            ColorUtility.TryParseHtmlString(col.Value(mode), out color);
                            var colorbox = Create(container, modeField, new CuiElement {
                                Components = {
                                    new CuiRectTransformComponent {
                                        AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = $"{-20} {-8}", OffsetMax = $"{-4} {8}"
                                    }
                                    , new CuiImageComponent {
                                        Color = color.ToColorString()
                                    }
                                }
                            }
                            );
                        }
                    }
                    if (colidx == 1 && modeidx == modes.Length-1) {
                        var addbtn = Create(container, modeGrid, new CuiElement {
                            Components = {
                                new CuiRectTransformComponent {
                                    AnchorMin = $"0 1", AnchorMax = $"0 1", OffsetMin = $"{left+padding} {-down-modeGridRowHeight-modeGridRowHeight-modeGridRowGap}", OffsetMax = $"{left+col.Width-padding} {-down-modeGridRowHeight-modeGridRowGap}"
                                }
                                , new CuiButtonComponent {
                                    Color = headerBgColor, Command = $"warmode.ui.addmode"
                                }
                            }
                        }
                        );
                        var addbtnsprite = Create(container, addbtn, new CuiElement {
                            Components = {
                                new CuiRectTransformComponent {
                                    AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = $"{toolBtnPadding} {-toolBtnSpriteSize/2}", OffsetMax = $"{toolBtnPadding+toolBtnSpriteSize} {toolBtnSpriteSize/2}"
                                }
                                , new CuiImageComponent {
                                    Sprite = "assets/icons/add.png", Color = toolBtnTextColor,
                                }
                            }
                        }
                        );
                        var addbtntext = Create(container, addbtn, new CuiElement {
                            Components = {
                                new CuiRectTransformComponent {
                                    AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"{toolBtnPadding+toolBtnSpriteSize} {0}", OffsetMax = $"{0} {0}"
                                }
                                , new CuiTextComponent {
                                    Color = headerTextColor, Align = TextAnchor.MiddleCenter, Text = "ADD MODE", FontSize = 9
                                }
                            }
                        }
                        );
                    }
                    down += modeGridColHeight + modeGridRowGap;
                    modeidx += 1;
                }
                left = left + col.Width + modeGridColGap;
                colidx += 1;
            }
            CuiHelper.DestroyUi(editingPlayer, gridid);
            CuiHelper.AddUi(editingPlayer, container);
        }
    }
}
namespace Oxide.Plugins {
    public partial class WarModeAdminPanel {
        [Command("warmode.config", "wmc")]
        private void CmdWarModeConfig(IPlayer player, string command, string[] args) {
            if (!permission.UserHasPermission(player.Id, "warmode.admin")) {
                return;
            }
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null) {
                return;
            }
            if (editingPlayer != null) {
                basePlayer.ChatMessage($"The player {editingPlayer.displayName} is currently using the admin panel.Only one person can be using it at a time in order to prevent conflicts.");
                return;
            }
            ShowUI(basePlayer);
        }
        [Command("warmode.ui.setrule")]
        private void CmdWarModeUiSetRule(IPlayer player, string command, string[] args) {
            // warmode.ui.setrule <modeName> <ruleIdx> <targetModeName> <ttype>
            var basePlayer = player.Object as BasePlayer;
            if (basePlayer == null || basePlayer != editingPlayer) {
                return;
            }
            var modeName = args[0];
            var ruleid = args[1];
            var targetModeName = args[2];
            var ttype = Enum.Parse<TargetType>(args[3]);
            var editingMode = ModifiedConfig.Modes.First(x => x.Name == modeName);
            var id = $"val.{targetModeName}.{ruleid}.{ttype}";
            var value = false;
            // EDIT HERE
            switch (ruleid) {
                case "canattack" : editingMode.CanAttackTypes[ttype] = ModifyConfigList(editingMode.CanAttackTypes[ttype], targetModeName);
                value = editingMode.CanAttackTypes[ttype].Contains(targetModeName);
                break;
                //case "canraid":
                //    editingMode.CanRaid = ModifyConfigList(editingMode.CanRaid, targetModeName);
                //    value = editingMode.CanRaid.Contains(targetModeName);
                //    break;
                case "canloot" : editingMode.CanLootTypes[ttype] = ModifyConfigList(editingMode.CanLootTypes[ttype], targetModeName);
                value = editingMode.CanLootTypes[ttype].Contains(targetModeName);
                break;
                case "cantarget" : editingMode.CanTargetTypes[ttype] = ModifyConfigList(editingMode.CanTargetTypes[ttype], targetModeName);
                value = editingMode.CanTargetTypes[ttype].Contains(targetModeName);
                break;
                case "canmount" : editingMode.CanMountTypes[ttype] = ModifyConfigList(editingMode.CanMountTypes[ttype], targetModeName);
                value = editingMode.CanMountTypes[ttype].Contains(targetModeName);
                break;
                case "canenter" : editingMode.CanEnterTypes[ttype] = ModifyConfigList(editingMode.CanEnterTypes[ttype], targetModeName);
                value = editingMode.CanEnterTypes[ttype].Contains(targetModeName);
                break;
                //case "canlootvehicle":
                //    editingMode.CanLootOwnedVehicles = ModifyConfigList(editingMode.CanLootOwnedVehicles, targetModeName);
                //    value = editingMode.CanLootOwnedVehicles.Contains(targetModeName);
                //    break;
                //case "mo":
                //    editingMode.CanEnterOwnedMonuments = ModifyConfigList(editingMode.CanEnterOwnedMonuments, targetModeName);
                //    value = editingMode.CanEnterOwnedMonuments.Contains(targetModeName);
                //    break;
                default : break;
            }
            if (!isDirty) {
                isDirty = true;
                CreateBott
// ... [Code preview truncated due to length. Full source in attached file] ...

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

Другие ресурсы пользователя 15FPS

Сверху