// Requires: WarMode using static Oxide.Plugins.WarMode; using Oxide.Plugins.WarModeMethods; using Oxide.Game.Rust.Cui; using Newtonsoft.Json; using System.ComponentModel; using System; using Oxide.Core.Plugins; using Oxide.Core.Libraries.Covalence; using ProtoBuf; using VLB; using System.Threading.Tasks; using System.Linq; using UnityEngine.UI; using System.Text.RegularExpressions; using System.Collections.Generic; using Facepunch.Extend; namespace Oxide.Plugins { [Info("War Mode Admin Panel", "mr01sam", "1.0.0")] [Description("Admin UI for configuring War Mode in game.")] public class WarModeAdminPanel : CovalencePlugin { // 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 headerTextColor = "0.54509 0.51372 0.4705 1"; private const float headerHeight = 32; private const float bottomHeight = 48; private const string generalTextColor = "0.7 0.7 0.7 1"; 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"; void OnServerInitialized() { //foreach (var basePlayer in BasePlayer.activePlayerList) //{ // ShowUI(basePlayer); //} } [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 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 editingMode = ModifiedConfig.Modes.First(x => x.Name == modeName); var id = $"val.{targetModeName}.{ruleid}"; var value = false; // EDIT HERE switch (ruleid) { case "canattack": editingMode.CanAttack = ModifyConfigList(editingMode.CanAttack, targetModeName); value = editingMode.CanAttack.Contains(targetModeName); break; case "canraid": editingMode.CanRaid = ModifyConfigList(editingMode.CanRaid, targetModeName); value = editingMode.CanRaid.Contains(targetModeName); break; case "canloot": editingMode.CanLoot = ModifyConfigList(editingMode.CanLoot, targetModeName); value = editingMode.CanLoot.Contains(targetModeName); break; case "cantarget": editingMode.CanTargetWithTraps = ModifyConfigList(editingMode.CanTargetWithTraps, targetModeName); value = editingMode.CanTargetWithTraps.Contains(targetModeName); break; case "canmount": editingMode.CanMountOwnedVehicles = ModifyConfigList(editingMode.CanMountOwnedVehicles, targetModeName); value = editingMode.CanMountOwnedVehicles.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; CreateBottomButton(); } UpdateButtonText(id, value.ToString(), value ? poscolor : negcolor); } [Command("warmode.ui.togglemoderule")] private void CmdWarModeUiToggleModeRule(IPlayer player, string command, string[] args) { // warmode.ui.togglemoderule var basePlayer = player.Object as BasePlayer; if (basePlayer == null || basePlayer != editingPlayer) { return; } var modeName = args[0]; var targetModeName = args[1]; var editingMode = ModifiedConfig.Modes.First(x => x.Name == modeName); var removing = editingMode.CanAttack.Contains(targetModeName); var modeschanges = new List(); // EDIT HERE editingMode.CanAttack = ModifyConfigList(editingMode.CanAttack, targetModeName, !removing); modeschanges.Add("canattack"); editingMode.CanRaid = ModifyConfigList(editingMode.CanRaid, targetModeName, !removing); modeschanges.Add("canraid"); editingMode.CanLoot = ModifyConfigList(editingMode.CanLoot, targetModeName, !removing); modeschanges.Add("canloot"); editingMode.CanTargetWithTraps = ModifyConfigList(editingMode.CanTargetWithTraps, targetModeName, !removing); modeschanges.Add("cantarget"); editingMode.CanMountOwnedVehicles = ModifyConfigList(editingMode.CanMountOwnedVehicles, targetModeName, !removing); modeschanges.Add("canmount"); editingMode.CanLootOwnedVehicles = ModifyConfigList(editingMode.CanLootOwnedVehicles, targetModeName, !removing); modeschanges.Add("canlootvehicle"); if (!isDirty) { isDirty = true; CreateBottomButton(); } foreach (var ruleid in modeschanges) { var id = $"val.{targetModeName}.{ruleid}"; UpdateButtonText(id, (!removing).ToString(), !removing ? poscolor : negcolor); } } string selectedMode = null; [Command("warmode.ui.setmode")] private void CmdWarModeUiSetMode(IPlayer player, string command, string[] args) { // warmode.ui.setmode var basePlayer = player.Object as BasePlayer; if (basePlayer == null || basePlayer != editingPlayer) { return; } var modeName = args[0]; selectedMode = modeName; ReloadUI(); } [Command("warmode.ui.setting")] private void CmdWarModeUiSetting(IPlayer player, string command, string[] args) { // warmode.ui.setting var basePlayer = player.Object as BasePlayer; if (basePlayer == null || basePlayer != editingPlayer) { return; } var modeName = args[0]; var settingid = args[1]; var value = false; var modeConfig = ModifiedConfig.Modes.First(x => x.Name == modeName); switch (settingid) { case "rbpvp": ModifiedConfig.RaidableBases.CanEnterPvpRaidableBases = ModifyConfigList(ModifiedConfig.RaidableBases.CanEnterPvpRaidableBases, modeName); value = ModifiedConfig.RaidableBases.CanEnterPvpRaidableBases.Contains(modeName); break; case "rbpve": ModifiedConfig.RaidableBases.CanEnterPveRaidableBases = ModifyConfigList(ModifiedConfig.RaidableBases.CanEnterPveRaidableBases, modeName); value = ModifiedConfig.RaidableBases.CanEnterPveRaidableBases.Contains(modeName); break; case "marker": modeConfig.ShowMarkerWhenAimedAt = !modeConfig.ShowMarkerWhenAimedAt; value = modeConfig.ShowMarkerWhenAimedAt; break; default: break; } if (!isDirty) { isDirty = true; CreateBottomButton(); } var id = $"setting.{settingid}.value"; UpdateButtonText(id, (value).ToString(), value ? poscolor : negcolor); //ReloadUI(); } [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; } WarMode.INSTANCE.SaveConfigExternal(ModifiedConfig); isDirty = false; 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); editingPlayer = null; ElementsLoaded.Clear(); } [Command("warmode.ui.debugtoggle")] private void CmdWarModeUiDebugToggle(IPlayer player, string command, string[] args) { // warmode.ui.close var basePlayer = player.Object as BasePlayer; if (basePlayer == null || basePlayer != editingPlayer) { return; } WarMode.DEBUGGING = !WarMode.DEBUGGING; ReloadUI(); } private string[] ModifyConfigList(string[] original, string value, bool? given = null) { if (original == null) { return null; } bool adding; if (given == null) { adding = !original.Contains(value); } else { adding = given.Value; } var asList = original.ToList(); if (adding && !original.Contains(value)) { asList.Add(value); return asList.ToArray(); } else if (!adding && original.Contains(value)) { asList.Remove(value); return asList.ToArray(); } return original; } void Unload() { Close(); } private const string ID = "warmodeconfig"; public void ShowUI(BasePlayer basePlayer) { editingPlayer = basePlayer; ModifiedConfig = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(CONFIG)); ReloadUI(); } public void ReloadUI() { if (string.IsNullOrWhiteSpace(selectedMode)) { selectedMode = ModifiedConfig.Modes.FirstOrDefault()?.Name; } var container = new CuiElementContainer(); var 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 titleBarDebugBtn = Create(container, titleBar, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = $"{8} {-8}", OffsetMax = $"{8+16} {8}" }, new CuiButtonComponent { Color = WarMode.DEBUGGING ? poscolor : headerTextColor, Sprite = "assets/icons/info.png", Command = "warmode.ui.debugtoggle" } } }); 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 } } }); var leftBar = Create(container, mainPanel, new CuiElement { Name = ID + "left", Components = { new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "0.12 1", OffsetMin = $"{padding} {bottomHeight+padding}", OffsetMax = $"{-padding} {-headerHeight-padding}" }, new CuiImageComponent { Color = "0 0 0 0" } } }); var leftText = Create(container, leftBar, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-panelHeaderHeight-padding}", OffsetMax = $"{0} {-padding}" }, new CuiTextComponent { Text = "ALL MODES", Color = generalTextColor, FontSize = 14, Align = UnityEngine.TextAnchor.UpperCenter } } }); AllModesList(container, leftBar); var rightBar = Create(container, mainPanel, new CuiElement { Name = ID + "right", Components = { new CuiRectTransformComponent { AnchorMin = "0.15 0", AnchorMax = "0.82 1", OffsetMin = $"{0} {bottomHeight+padding}", OffsetMax = $"{-padding} {-headerHeight-padding-panelHeaderText}" }, new CuiImageComponent { Color = "0 0 0 0" } } }); var rightText = Create(container, rightBar, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{padding} {-panelHeaderHeight-padding}", OffsetMax = $"{-padding} {-padding}" }, new CuiTextComponent { Text = $"Editing rules for {Color(selectedMode.ToUpper(), selcolor)} players", Color = generalTextColor, FontSize = generalTextSize, Align = UnityEngine.TextAnchor.UpperCenter } } }); var settingsBar = Create(container, mainPanel, new CuiElement { Name = ID + "settings", Components = { new CuiRectTransformComponent { AnchorMin = "0.82 0", AnchorMax = "1 1", OffsetMin = $"{0} {bottomHeight+padding}", OffsetMax = $"{-padding} {-headerHeight-padding-panelHeaderText-38}" }, new CuiImageComponent { Color = "0 0 0 0" } } }); CuiHelper.DestroyUi(editingPlayer, ID); CuiHelper.AddUi(editingPlayer, container); CreateSettingsBar(); EditRules(rightBar); CreateBottomButton(); } public void CreateSettingsBar() { var parent = ID + "settings"; var container = new CuiElementContainer(); var titleh = 24; var panel = Create(container, parent, new CuiElement { Name = ID + "settingspanel", Components = { new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }, } }); var titlePanel = Create(container, panel, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-titleh}", OffsetMax = $"{0} {0}" }, new CuiImageComponent { Color = headerBgColor } } }); var titlePanelText = Create(container, titlePanel, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-titleh}", OffsetMax = $"{0} {0}" }, new CuiTextComponent { Text = $"{selectedMode.ToUpper()} SETTINGS", Color = headerTextColor, Align = UnityEngine.TextAnchor.MiddleCenter } } }); var modeConfig = CONFIG.Modes.First(x => x.Name == selectedMode); var settings = new[] { new { ID = "marker", Enabled = true, Label = "Show Marker When Aimed At", Value = modeConfig.ShowMarkerWhenAimedAt, }, new { ID = "rbpvp", Enabled = CONFIG.RaidableBases.IsEnabled, Label = "Can Enter PVP Raidable Bases", Value = CONFIG.RaidableBases.CanEnterPvpRaidableBases.Contains(selectedMode), }, new { ID = "rbpve", Enabled = CONFIG.RaidableBases.IsEnabled, Label = "Can Enter PVE Raidable Bases", Value = CONFIG.RaidableBases.CanEnterPveRaidableBases.Contains(selectedMode), } }; var down = titleh + padding; var settingh = 32; var settingp = 1; var valh = 24; var valw = 50; foreach(var setting in settings) { if (!setting.Enabled) { continue; } var id = $"setting.{setting.ID}"; var settpanel = Create(container, panel, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-down-settingh}", OffsetMax = $"{0} {-down}" }, new CuiImageComponent { Color = headerBgColor } } }); var setttxt = Create(container, settpanel, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "0.7 1", OffsetMin = $"{8} {4}", OffsetMax = $"{-4} {-4}" }, new CuiTextComponent { Text = setting.Label, Align = UnityEngine.TextAnchor.MiddleLeft, FontSize = 9, Color = generalTextColor } } }); var settbtn = Create(container, settpanel, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = $"{-4-valw} {-valh/2}", OffsetMax = $"{-4} {valh/2}" }, new CuiButtonComponent { Color = "0 0 0 0.7", Command = $"warmode.ui.setting {selectedMode} {setting.ID}" } } }); var setttext = Create(container, settbtn, new CuiElement { Name = $"setting.{setting.ID}.value", Components = { new CuiTextComponent { Color = setting.Value ? poscolor : negcolor, Text = setting.Value.ToString(), Align = UnityEngine.TextAnchor.MiddleCenter, FontSize = 11 } } }); down += settingh + settingp; } CuiHelper.DestroyUi(editingPlayer, panel); CuiHelper.AddUi(editingPlayer, container); } public string Create(CuiElementContainer container, CuiElement newElement) => Create(container, "Overlay", newElement); public Dictionary ElementsLoaded = new Dictionary(); 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 CreateBottomButton() { var container = new CuiElementContainer(); 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} {-16}", OffsetMax = $"{60} {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" } } }); CuiHelper.DestroyUi(editingPlayer, bottomBtn); CuiHelper.AddUi(editingPlayer, container); } public void AllModesList(CuiElementContainer container, string parent) { var content = Create(container, parent, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"{0} {padding}", OffsetMax = $"{0} {-padding-panelHeaderHeight-padding}" } } }); var mh = 24f; var down = 0f; foreach(var mode in ModifiedConfig.Modes) { var entry = Create(container, content, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-down-mh}", OffsetMax = $"{0} {-down}" }, new CuiButtonComponent { //Color = "0 1 0 1", Color = selectedMode == mode.Name ? headerBgColor : "0 0 0 0", Command = $"warmode.ui.setmode {mode.Name}" } } }); var entryText = Create(container, entry, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = $"{padding} {0}", OffsetMax = $"{-padding} {0}" }, new CuiTextComponent { Text = selectedMode == mode.Name ? Color(mode.Name.ToUpper(), selcolor) : mode.Name.ToUpper(), Color = generalTextColor, FontSize = 12, Align = UnityEngine.TextAnchor.MiddleLeft } } }); down += mh; } } private bool isDirty = false; private BasePlayer editingPlayer = null; private const string DARKEN = "0.5 0.4 0.4 0.1"; private const string LIGHTEN = "1 1 1 0.1"; public void EditRules(string parent) { var container = new CuiElementContainer(); var allModeKeys = ModifiedConfig.Modes.Select(x => x.Name); var mode = ModifiedConfig.Modes.FirstOrDefault(x => x.Name == selectedMode); var modeNameUpper = Color(mode.Name.ToUpper(), selcolor); // EDIT HERE var rules = new[] { new { ID = "canattack", Enabled = true, Title = "ATTACKING", Text = $"Can {modeNameUpper} players attack players with these modes?", Values = allModeKeys.Select(x => mode.CanAttack.Contains(x)).ToArray() }, new { ID = "canraid", Enabled = true, Title = "RAIDING", Text = $"Can {modeNameUpper} players raid bases that are owned by players with these modes?", Values = allModeKeys.Select(x => mode.CanRaid.Contains(x)).ToArray() }, new { ID = "canloot", Enabled = true, Title = "LOOTING", Text = $"Can {modeNameUpper} players loot containers that are owned by players with these modes?", Values = allModeKeys.Select(x => mode.CanLoot.Contains(x)).ToArray() }, new { ID = "cantarget", Enabled = true, Title = "TRAP TARGETING", Text = $"Can {modeNameUpper} players have their traps triggered for players with these modes?", Values = allModeKeys.Select(x => mode.CanTargetWithTraps.Contains(x)).ToArray() }, new { ID = "canmount", Enabled = CONFIG.Settings.AllowVehicleModeOwnership, Title = "MOUNT OWNED VEHICLES", Text = $"Can {modeNameUpper} players have vehicles they own mounted by players with these modes?", Values = allModeKeys.Select(x => mode.CanMountOwnedVehicles?.Contains(x) ?? false).ToArray() }, new { ID = "canlootvehicle", Enabled = CONFIG.Settings.AllowVehicleModeOwnership, Title = "LOOT OWNED VEHICLES", Text = $"Can {modeNameUpper} players have vehicles they own looted by players with these modes?", Values = allModeKeys.Select(x => mode.CanLootOwnedVehicles?.Contains(x) ?? false).ToArray() } }; var leftW = 0.3f; var rightW = 1f - leftW; // left side var leftSide = Create(container, parent, new CuiElement { Name = ID + "editleft", Components = { new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = $"{leftW} 1", OffsetMin = $"{padding} {padding}", OffsetMax = $"{0} {-padding-panelHeaderText-padding}" }, new CuiImageComponent { Color = "0 0 0 0" } } }); var scrollbarh = 14; var modeLabelH = 32; var modeLabelW = 80; var right = 0f; // right side var totalScrollSize = (allModeKeys.Count() + 1) * (modeLabelW + padding); var rightSide = Create(container, parent, new CuiElement { Name = ID + "editright", Components = { new CuiRectTransformComponent { AnchorMin = $"{leftW} 0", AnchorMax = $"1 1", OffsetMin = $"{0} {padding+scrollbarh}", OffsetMax = $"{-padding} {-padding-panelHeaderText-padding}" }, new CuiImageComponent { Color = "0 0 0 0" }, new CuiScrollViewComponent { Horizontal = true, Vertical = false, Elasticity = 0f, MovementType = UnityEngine.UI.ScrollRect.MovementType.Clamped, ScrollSensitivity = 20f, HorizontalScrollbar = new CuiScrollbar { Invert = true, Size = scrollbarh }, ContentTransform = new CuiRectTransform { AnchorMin = "0 0", AnchorMax = "0 1", OffsetMin = $"{0} 0", OffsetMax = $"{Math.Max(550, totalScrollSize)} 0" } } } }); // mode headers foreach (var modeKey in allModeKeys) { var label = Create(container, rightSide, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = $"0 1", AnchorMax = $"0 1", OffsetMin = $"{right} {-padding-modeLabelH}", OffsetMax = $"{right+modeLabelW-1} {-padding}" }, new CuiButtonComponent { Command = $"warmode.ui.togglemoderule {mode.Name} {modeKey}", Color = "0.5 0.5 0.5 0.1" } } }); var labelText = Create(container, label, new CuiElement { Components = { new CuiTextComponent { Text = modeKey.ToUpper(), Color = generalTextColor, Align = UnityEngine.TextAnchor.MiddleCenter, FontSize = 11 } } }); right += modeLabelW; } // rule text var mh = 56f; var down = 0f; var ruleidx = 0; foreach (var rule in rules.Where(x => x.Enabled)) { var entry = Create(container, leftSide, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = $"{0} {-down-mh-padding-modeLabelH}", OffsetMax = $"{0} {-down-padding-modeLabelH}" }, new CuiImageComponent { Color = ruleidx % 2 == 0 ? DARKEN : LIGHTEN } } }); var text = Create(container, entry, new CuiElement { Components = { new CuiTextComponent { Text = rule.Text, FontSize = 9, Color = generalTextColor, Font = "RobotoCondensed-Regular.ttf", Align = UnityEngine.TextAnchor.UpperLeft }, new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 0.55", OffsetMin = $"{padding} {4}", OffsetMax = $"{-padding} {0}" }, } }); var title = Create(container, entry, new CuiElement { Components = { new CuiTextComponent { Text = rule.Title, FontSize = 13, Color = generalTextColor, Align = UnityEngine.TextAnchor.UpperLeft }, new CuiRectTransformComponent { AnchorMin = "0 0.5", AnchorMax = "1 1", OffsetMin = $"{padding} {0}", OffsetMax = $"{-padding} {-5}" }, } }); var r = 0f; var colIdx = 0; foreach(var modeVal in rule.Values) { var modeForCol = allModeKeys.ElementAt(colIdx); var btn = Create(container, rightSide, new CuiElement { Components = { new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = $"{r} {-down-mh-padding-modeLabelH-0.5f}", OffsetMax = $"{r+modeLabelW-1} {-down-padding-modeLabelH-0.5f}" }, new CuiButtonComponent { Color = ruleidx % 2 == 0 ? DARKEN : LIGHTEN, Command = $"warmode.ui.setrule {mode.Name} {rule.ID} {modeForCol}" //Color = "0 0 0 0" //Color = "1 1 0 1", } } }); var btnText = Create(container, btn, new CuiElement { Name = $"val.{modeForCol}.{rule.ID}", Components = { new CuiTextComponent { Text = modeVal.ToString(), FontSize = 12, Color = modeVal ? poscolor : negcolor, Align = UnityEngine.TextAnchor.MiddleCenter } } }); r += modeLabelW; colIdx++; } down += mh; ruleidx++; } CuiHelper.DestroyUi(editingPlayer, ID + "editleft"); CuiHelper.DestroyUi(editingPlayer, ID + "editright"); CuiHelper.AddUi(editingPlayer, container); } public string Color(string text, string hexColor) { return $"{text}"; } #region Localization protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { }, this); } private string Lang(string key, string id, params object[] args) => string.Format(lang.GetMessage(key, this, id), args); #endregion private WarMode.Configuration ModifiedConfig; #region Config private Configuration config; private class Configuration { public string CustomUI = ""; } protected override void LoadConfig() { base.LoadConfig(); try { config = Config.ReadObject(); 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 } }