From 8e05560911f05bf7e726bb7e0358578762aecfeb Mon Sep 17 00:00:00 2001 From: Schwer <42115696+itsschwer@users.noreply.github.com> Date: Sat, 3 Feb 2024 16:49:41 +1100 Subject: [PATCH 1/4] Split config binding into functions by component --- ConfigManager.cs | 56 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/ConfigManager.cs b/ConfigManager.cs index 742d1783..173efbe2 100644 --- a/ConfigManager.cs +++ b/ConfigManager.cs @@ -185,8 +185,20 @@ static ConfigManager() ConfigFileStatsDisplay = new ConfigFile(Paths.ConfigPath + "\\BetterUI-StatsDisplay.cfg", true); ConfigFileSorting = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Sorting.cfg", true); - // Components + BindComponentsConfig(); + + BindMiscConfig(); + BindAdvancedIconsConfig(); + BindBuffsConfig(); + BindCommandScrapperImprovementsConfig(); + BindDPSMeterConfig(); + BindItemCountersConfig(); + BindStatsDisplayConfig(); + BindSortingConfig(); + } + static void BindComponentsConfig() + { ComponentsAdvancedIcons = Bind(ConfigFileComponents, "Components", "AdvancedIcons", true, "Enable/Disable the component entirely, stopping it from hooking any game functions."); ComponentsBuffTimers = Bind(ConfigFileComponents, "Components", "Buffs", true, "Enable/Disable the component entirely, stopping it from hooking any game functions."); @@ -202,9 +214,10 @@ static ConfigManager() ComponentsMisc = Bind(ConfigFileComponents, "Components", "Misc", true, "Enable/Disable the component entirely, stopping it from hooking any game functions."); ComponentsStatsDisplay = Bind(ConfigFileComponents, "Components", "StatsDisplay", true, "Enable/Disable the component entirely, stopping it from hooking any game functions."); + } - // Misc - + static void BindMiscConfig() + { MiscShowHidden = Bind(ConfigFileMisc, "Misc", "ShowHidden", false, "Show hidden items in the item inventory."); MiscAdvancedPickupNotificationsItems = Bind(ConfigFileMisc, "Misc", "AdvancedPickupNotificationsItems", false, "Show advanced descriptions when picking up an item."); @@ -220,9 +233,10 @@ static ConfigManager() MiscShowPickupDescription = Bind(ConfigFileMisc, "Misc", "ShowPickupDescription", true, "Show the item description on the interaction pop-up."); MiscPickupDescriptionAdvanced = Bind(ConfigFileMisc, "Misc", "PickupDescriptionAdvanced", false, "Show advanced descriptions for the interaction pop-up."); + } - // Advanced Icons - + static void BindAdvancedIconsConfig() + { AdvancedIconsItemAdvancedDescriptions = Bind(ConfigFileAdvancedIcons, "Item Improvements", "AdvancedDescriptions", true, "Show advanced descriptions when hovering over an item."); AdvancedIconsItemItemStatsIntegration = Bind(ConfigFileAdvancedIcons, "Item Improvements", "ItemStatsIntegration", true, "Show ItemStats where applicable."); @@ -244,9 +258,10 @@ static ConfigManager() AdvancedIconsSkillShowProcCoefficient = Bind(ConfigFileAdvancedIcons, "Skill Improvements", "ShowProcCoefficient", true, "Show the proc coefficient when hovering over a skill."); AdvancedIconsSkillCalculateSkillProcEffects = Bind(ConfigFileAdvancedIcons, "Skill Improvements", "CalculateProcEffects", true, "Show the effects of carried items, adjusted for each skill's proc coefficient."); + } - // Buffs - + static void BindBuffsConfig() + { BuffTimers = Bind(ConfigFileBuffs, "Buffs", "BuffTimers", true, "Show buff timers (host only)."); BuffTimersDecimal = Bind(ConfigFileBuffs, "Buffs", "BuffTimersDecimal", true, "Show 1 decimal point when timer is below 10."); @@ -265,9 +280,10 @@ static ConfigManager() BuffTimersTextAlignmentOption = (TMPro.TextAlignmentOptions)Enum.Parse(typeof(TMPro.TextAlignmentOptions), BuffTimersPosition.Value, true); BuffTimersFontSize = Bind(ConfigFileBuffs, "Buffs", "CountersFontSize", 23f, "Size of the buff timer text."); + } - // Command / Scrapper Improvements - + static void BindCommandScrapperImprovementsConfig() + { CommandResizeCommandWindow = Bind(ConfigFileCommandImprovements, "Command / Scrapper Improvements", "ResizeCommandWindow", true, "Resize the command window depending on the number of items."); CommandRemoveBackgroundBlur = Bind(ConfigFileCommandImprovements, "Command / Scrapper Improvements", "RemoveBackgroundBlur", true, "Remove the blur behind the command window that hides the rest of the UI."); @@ -302,9 +318,10 @@ static ConfigManager() CommandCountersFontSize = Bind(ConfigFileCommandImprovements, "Command / Scrapper Improvements", "CountersFontSize", 20f, "Size of the command item counter text."); CommandCountersPrefix = Bind(ConfigFileCommandImprovements, "Command / Scrapper Improvements", "CountersPrefix", "x", "Prefix for the command item counter. Example 'x' will show x0, x1, x2, etc.\nCan be empty."); + } - // DPSMeter - + static void BindDPSMeterConfig() + { DPSMeterTimespan = Bind(ConfigFileDPSMeter, "DPSMeter", "Timespan", 5f, "Calculate DPS across this many seconds."); DPSMeterWindowShow = Bind(ConfigFileDPSMeter, "DPSMeter", "WindowShow", true, "Show a dedicated DPSMeter."); @@ -333,9 +350,10 @@ static ConfigManager() DPSMeterWindowSize = Bind(ConfigFileDPSMeter, "DPSMeter", "WindowSize", new Vector2(350, 45), "Size of the DPSMeter window."); DPSMeterWindowAngle = Bind(ConfigFileDPSMeter, "DPSMeter", "WindowAngle", new Vector3(0, -6, 0), "Angle of the DPSMeter window."); + } - // ItemCounters - + static void BindItemCountersConfig() + { ItemCountersShowItemCounters = Bind(ConfigFileItemCounters, "ItemCounters", "ShowItemCounters", true, "Enable/Disable ItemCounters entirely."); ItemCountersShowItemScore = Bind(ConfigFileItemCounters, "ItemCounters", "ShowItemScore", true, "Show your item score."); @@ -378,10 +396,10 @@ static ConfigManager() ItemCountersItemScores = new Dictionary(); + } - - // StatsDisplay - + static void BindStatsDisplayConfig() + { StatsDisplayEnable = Bind(ConfigFileStatsDisplay, "StatsDisplay", "Enable", true, "Enable/Disable the StatsDisplay entirely."); StatsDisplayStatString = Bind(ConfigFileStatsDisplay, "StatsDisplay", "StatString", @@ -455,9 +473,10 @@ static ConfigManager() StatsDisplayWindowSize = Bind(ConfigFileStatsDisplay, "StatsDisplay", "WindowSize", new Vector2(200, 600), "Size of the StatsDisplay window."); StatsDisplayWindowAngle = Bind(ConfigFileStatsDisplay, "StatsDisplay", "WindowAngle", new Vector3(0, 6, 0), "Angle of the StatsDisplay window."); + } - // Sorting - + static void BindSortingConfig() + { SortingSortItemsInventory = Bind(ConfigFileSorting, "Sorting", "SortItemsInventory", true, "Sort items in the inventory and scoreboard."); SortingSortItemsCommand = Bind(ConfigFileSorting, "Sorting", "SortItemsCommand", true, "Sort items in the command window."); @@ -514,7 +533,6 @@ static ConfigManager() SortingSortOrderScrapper = Bind(ConfigFileSorting, "Sorting", "SortOrderScrapper", "134", "Sort order for the scrapper window."); - } /// From 2e82c034f254b6e79751040e6b9b8d38ed41c5bc Mon Sep 17 00:00:00 2001 From: Schwer <42115696+itsschwer@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:52:46 +1100 Subject: [PATCH 2/4] Only generate configs for enabled components Avoid cluttering users' config folder --- ConfigManager.cs | 52 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/ConfigManager.cs b/ConfigManager.cs index 173efbe2..91f02883 100644 --- a/ConfigManager.cs +++ b/ConfigManager.cs @@ -175,30 +175,30 @@ internal static class ConfigManager static ConfigManager() { - ConfigFileComponents = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Components.cfg", true); - ConfigFileMisc = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Misc.cfg", true); - ConfigFileAdvancedIcons = new ConfigFile(Paths.ConfigPath + "\\BetterUI-AdvancedIcons.cfg", true); - ConfigFileBuffs = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Buffs.cfg", true); - ConfigFileCommandImprovements = new ConfigFile(Paths.ConfigPath + "\\BetterUI-CommandImprovements.cfg", true); - ConfigFileDPSMeter = new ConfigFile(Paths.ConfigPath + "\\BetterUI-DPSMeter.cfg", true); - ConfigFileItemCounters = new ConfigFile(Paths.ConfigPath + "\\BetterUI-ItemCounters.cfg", true); - ConfigFileStatsDisplay = new ConfigFile(Paths.ConfigPath + "\\BetterUI-StatsDisplay.cfg", true); - ConfigFileSorting = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Sorting.cfg", true); - BindComponentsConfig(); - BindMiscConfig(); - BindAdvancedIconsConfig(); - BindBuffsConfig(); - BindCommandScrapperImprovementsConfig(); - BindDPSMeterConfig(); - BindItemCountersConfig(); - BindStatsDisplayConfig(); - BindSortingConfig(); + if (ComponentsMisc.Value) + BindMiscConfig(); + if (ComponentsAdvancedIcons.Value) + BindAdvancedIconsConfig(); + if (ComponentsBuffTimers.Value) + BindBuffsConfig(); + if (ComponentsCommandImprovements.Value) + BindCommandScrapperImprovementsConfig(); + if (ComponentsDPSMeter.Value) + BindDPSMeterConfig(); + if (ComponentsItemCounters.Value) + BindItemCountersConfig(); + if (ComponentsStatsDisplay.Value) + BindStatsDisplayConfig(); + if (ComponentsItemSorting.Value) + BindSortingConfig(); } static void BindComponentsConfig() { + ConfigFileComponents = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Components.cfg", true); + ComponentsAdvancedIcons = Bind(ConfigFileComponents, "Components", "AdvancedIcons", true, "Enable/Disable the component entirely, stopping it from hooking any game functions."); ComponentsBuffTimers = Bind(ConfigFileComponents, "Components", "Buffs", true, "Enable/Disable the component entirely, stopping it from hooking any game functions."); @@ -218,6 +218,8 @@ static void BindComponentsConfig() static void BindMiscConfig() { + ConfigFileMisc = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Misc.cfg", true); + MiscShowHidden = Bind(ConfigFileMisc, "Misc", "ShowHidden", false, "Show hidden items in the item inventory."); MiscAdvancedPickupNotificationsItems = Bind(ConfigFileMisc, "Misc", "AdvancedPickupNotificationsItems", false, "Show advanced descriptions when picking up an item."); @@ -237,6 +239,8 @@ static void BindMiscConfig() static void BindAdvancedIconsConfig() { + ConfigFileAdvancedIcons = new ConfigFile(Paths.ConfigPath + "\\BetterUI-AdvancedIcons.cfg", true); + AdvancedIconsItemAdvancedDescriptions = Bind(ConfigFileAdvancedIcons, "Item Improvements", "AdvancedDescriptions", true, "Show advanced descriptions when hovering over an item."); AdvancedIconsItemItemStatsIntegration = Bind(ConfigFileAdvancedIcons, "Item Improvements", "ItemStatsIntegration", true, "Show ItemStats where applicable."); @@ -262,6 +266,8 @@ static void BindAdvancedIconsConfig() static void BindBuffsConfig() { + ConfigFileBuffs = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Buffs.cfg", true); + BuffTimers = Bind(ConfigFileBuffs, "Buffs", "BuffTimers", true, "Show buff timers (host only)."); BuffTimersDecimal = Bind(ConfigFileBuffs, "Buffs", "BuffTimersDecimal", true, "Show 1 decimal point when timer is below 10."); @@ -284,6 +290,8 @@ static void BindBuffsConfig() static void BindCommandScrapperImprovementsConfig() { + ConfigFileCommandImprovements = new ConfigFile(Paths.ConfigPath + "\\BetterUI-CommandImprovements.cfg", true); + CommandResizeCommandWindow = Bind(ConfigFileCommandImprovements, "Command / Scrapper Improvements", "ResizeCommandWindow", true, "Resize the command window depending on the number of items."); CommandRemoveBackgroundBlur = Bind(ConfigFileCommandImprovements, "Command / Scrapper Improvements", "RemoveBackgroundBlur", true, "Remove the blur behind the command window that hides the rest of the UI."); @@ -322,6 +330,8 @@ static void BindCommandScrapperImprovementsConfig() static void BindDPSMeterConfig() { + ConfigFileDPSMeter = new ConfigFile(Paths.ConfigPath + "\\BetterUI-DPSMeter.cfg", true); + DPSMeterTimespan = Bind(ConfigFileDPSMeter, "DPSMeter", "Timespan", 5f, "Calculate DPS across this many seconds."); DPSMeterWindowShow = Bind(ConfigFileDPSMeter, "DPSMeter", "WindowShow", true, "Show a dedicated DPSMeter."); @@ -354,6 +364,8 @@ static void BindDPSMeterConfig() static void BindItemCountersConfig() { + ConfigFileItemCounters = new ConfigFile(Paths.ConfigPath + "\\BetterUI-ItemCounters.cfg", true); + ItemCountersShowItemCounters = Bind(ConfigFileItemCounters, "ItemCounters", "ShowItemCounters", true, "Enable/Disable ItemCounters entirely."); ItemCountersShowItemScore = Bind(ConfigFileItemCounters, "ItemCounters", "ShowItemScore", true, "Show your item score."); @@ -400,6 +412,8 @@ static void BindItemCountersConfig() static void BindStatsDisplayConfig() { + ConfigFileStatsDisplay = new ConfigFile(Paths.ConfigPath + "\\BetterUI-StatsDisplay.cfg", true); + StatsDisplayEnable = Bind(ConfigFileStatsDisplay, "StatsDisplay", "Enable", true, "Enable/Disable the StatsDisplay entirely."); StatsDisplayStatString = Bind(ConfigFileStatsDisplay, "StatsDisplay", "StatString", @@ -477,6 +491,8 @@ static void BindStatsDisplayConfig() static void BindSortingConfig() { + ConfigFileSorting = new ConfigFile(Paths.ConfigPath + "\\BetterUI-Sorting.cfg", true); + SortingSortItemsInventory = Bind(ConfigFileSorting, "Sorting", "SortItemsInventory", true, "Sort items in the inventory and scoreboard."); SortingSortItemsCommand = Bind(ConfigFileSorting, "Sorting", "SortItemsCommand", true, "Sort items in the command window."); From 7d70c3af2b7dbfaf4577fe91414d139691d29258 Mon Sep 17 00:00:00 2001 From: Schwer <42115696+itsschwer@users.noreply.github.com> Date: Sat, 3 Feb 2024 18:18:52 +1100 Subject: [PATCH 3/4] Fix StatsDisplay using wrong config for enabling To further improve consistency with other components, hooking functions should be moved from the constructor to the currently empty `StatsDisplay.Hook()` --- ConfigManager.cs | 3 --- ModComponents/StatsDisplay.cs | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ConfigManager.cs b/ConfigManager.cs index 91f02883..4a882544 100644 --- a/ConfigManager.cs +++ b/ConfigManager.cs @@ -119,7 +119,6 @@ internal static class ConfigManager // StatsDisplay - public static ConfigEntry StatsDisplayEnable; public static ConfigEntry StatsDisplayStatString; public static ConfigEntry StatsDisplayStatStringCustomBind; public static ConfigEntry StatsDisplayCustomBind; @@ -414,8 +413,6 @@ static void BindStatsDisplayConfig() { ConfigFileStatsDisplay = new ConfigFile(Paths.ConfigPath + "\\BetterUI-StatsDisplay.cfg", true); - StatsDisplayEnable = Bind(ConfigFileStatsDisplay, "StatsDisplay", "Enable", true, "Enable/Disable the StatsDisplay entirely."); - StatsDisplayStatString = Bind(ConfigFileStatsDisplay, "StatsDisplay", "StatString", "" + "Stats\n" + diff --git a/ModComponents/StatsDisplay.cs b/ModComponents/StatsDisplay.cs index 79dc403a..4c06cbb9 100644 --- a/ModComponents/StatsDisplay.cs +++ b/ModComponents/StatsDisplay.cs @@ -100,7 +100,7 @@ static StatsDisplay() regexpattern = new Regex(@"(\" + String.Join(@"|\", sortedKeys) + ")"); - if (ConfigManager.StatsDisplayEnable.Value) + if (ConfigManager.ComponentsStatsDisplay.Value) { RoR2.Run.onRunStartGlobal += runStartGlobal; } @@ -137,7 +137,7 @@ internal static void runStartGlobal(RoR2.Run self) } static void onHUDAwake(RoR2.UI.HUD self) { - if (ConfigManager.StatsDisplayEnable.Value) + if (ConfigManager.ComponentsStatsDisplay.Value) { statsDisplayContainer = new GameObject("StatsDisplayContainer"); RectTransform rectTransform = statsDisplayContainer.AddComponent(); From f089677bbe8aa2bfa36bb12672fef7a55e0fb9ec Mon Sep 17 00:00:00 2001 From: Schwer <42115696+itsschwer@users.noreply.github.com> Date: Sat, 3 Feb 2024 18:31:54 +1100 Subject: [PATCH 4/4] Respect sorting config in command/scrapper menu Sorting logic should probably be moved to ItemSorting.cs --- ModComponents/CommandImprovements.cs | 51 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/ModComponents/CommandImprovements.cs b/ModComponents/CommandImprovements.cs index 6df5f09f..e5215633 100644 --- a/ModComponents/CommandImprovements.cs +++ b/ModComponents/CommandImprovements.cs @@ -18,8 +18,7 @@ static CommandImprovements() internal static void Hook() { if (ConfigManager.CommandResizeCommandWindow.Value || - ConfigManager.SortingSortItemsCommand.Value || - ConfigManager.SortingSortItemsScrapper.Value) + ConfigManager.ComponentsItemSorting.Value && (ConfigManager.SortingSortItemsCommand.Value || ConfigManager.SortingSortItemsScrapper.Value)) { BetterUIPlugin.Hooks.Add("SetPickupOptions", PickupPickerPanel_SetPickupOptions); } @@ -136,14 +135,14 @@ public static void PickupPickerPanel_SetPickupOptions(Action().enabled = false; } - if (ConfigManager.SortingSortItemsCommand.Value) + if (ConfigManager.ComponentsItemSorting.Value && ConfigManager.SortingSortItemsCommand.Value) { sortOrder = ConfigManager.SortingSortOrderCommand.Value; break; } goto default; case "SCRAPPER_CONTEXT": - if (ConfigManager.SortingSortItemsScrapper.Value) + if (ConfigManager.ComponentsItemSorting.Value && ConfigManager.SortingSortItemsScrapper.Value) { sortOrder = ConfigManager.SortingSortOrderScrapper.Value; break; @@ -154,34 +153,36 @@ public static void PickupPickerPanel_SetPickupOptions(Action PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex != EquipmentIndex.None)) + if (ConfigManager.ComponentsItemSorting.Value) { - foreach (RoR2.PickupPickerController.Option option in options) + Inventory inventory = LocalUserManager.GetFirstLocalUser().cachedMasterController.master.inventory; + + if (options.All(option => PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex != EquipmentIndex.None)) { - availableIndex[(int)PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex] = option.available; - } + foreach (RoR2.PickupPickerController.Option option in options) + { + availableIndex[(int)PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex] = option.available; + } - List sortedItems = ItemSorting.sortItems(options.Select(option => PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex).ToList(), sortOrder); + List sortedItems = ItemSorting.sortItems(options.Select(option => PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex).ToList(), sortOrder); - sortedItems.Select(equipemntIndex => new RoR2.PickupPickerController.Option { pickupIndex = PickupCatalog.FindPickupIndex(equipemntIndex), available = availableIndex[(int)equipemntIndex] }).ToArray().CopyTo(sortedOptions, 0); ; - sortedOptions.Select(option => Array.IndexOf(options, option)).ToArray().CopyTo(optionMap, 0); - options = sortedOptions.Take(options.Length).ToArray(); - } - else if (options.All(option => PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex != ItemIndex.None)) - { - foreach (RoR2.PickupPickerController.Option option in options) - { - availableIndex[(int)PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex] = option.available; + sortedItems.Select(equipemntIndex => new RoR2.PickupPickerController.Option { pickupIndex = PickupCatalog.FindPickupIndex(equipemntIndex), available = availableIndex[(int)equipemntIndex] }).ToArray().CopyTo(sortedOptions, 0); ; + sortedOptions.Select(option => Array.IndexOf(options, option)).ToArray().CopyTo(optionMap, 0); + options = sortedOptions.Take(options.Length).ToArray(); } + else if (options.All(option => PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex != ItemIndex.None)) + { + foreach (RoR2.PickupPickerController.Option option in options) + { + availableIndex[(int)PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex] = option.available; + } - List sortedItems = ItemSorting.sortItems(options.Select(option => PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex).ToList(), inventory, sortOrder); + List sortedItems = ItemSorting.sortItems(options.Select(option => PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex).ToList(), inventory, sortOrder); - sortedItems.Select(itemIndex => new RoR2.PickupPickerController.Option { pickupIndex = PickupCatalog.FindPickupIndex(itemIndex), available = availableIndex[(int)itemIndex] }).ToArray().CopyTo(sortedOptions, 0); - sortedOptions.Select(option => Array.IndexOf(options, option)).ToArray().CopyTo(optionMap, 0); - options = sortedOptions.Take(options.Length).ToArray(); + sortedItems.Select(itemIndex => new RoR2.PickupPickerController.Option { pickupIndex = PickupCatalog.FindPickupIndex(itemIndex), available = availableIndex[(int)itemIndex] }).ToArray().CopyTo(sortedOptions, 0); + sortedOptions.Select(option => Array.IndexOf(options, option)).ToArray().CopyTo(optionMap, 0); + options = sortedOptions.Take(options.Length).ToArray(); + } } orig(self, options);