99using System ;
1010using System . Collections . Generic ;
1111using System . Linq ;
12+ using System . Reflection ;
1213using System . Text . RegularExpressions ;
1314using UnityEngine ;
1415
@@ -20,7 +21,7 @@ public sealed class Mod : BaseUnityPlugin
2021 //Mod Details
2122 private const string modGUID = "Distance.DistanceModConfigurationManager" ;
2223 private const string modName = "Distance Mod Configuration Manager" ;
23- public const string modVersion = "1.2 .0" ;
24+ public const string modVersion = "1.3 .0" ;
2425
2526 //Config Entry Settings
2627 public static string ShowVersionKey = "Show Version Info" ;
@@ -33,7 +34,7 @@ public sealed class Mod : BaseUnityPlugin
3334
3435 //Private Variables
3536
36- private string _modsWithoutSettings ;
37+ private List < string > _modsWithoutSettings ;
3738
3839 private List < SettingEntryBase > _allSettings ;
3940 private List < PluginSettingsData > _filteredSettings = new List < PluginSettingsData > ( ) ;
@@ -53,8 +54,6 @@ private void Awake()
5354 Log = BepInEx . Logging . Logger . CreateLogSource ( modGUID ) ;
5455 Logger . LogInfo ( "Thanks for using the Distance Mod Configuration Manager!" ) ;
5556
56- CreateSettingsMenu ( ) ;
57-
5857 //Config Setup
5958 ShowVersionInfo = Config . Bind ( "General" ,
6059 ShowVersionKey ,
@@ -74,14 +73,16 @@ private void OnConfigChanged(object sender, EventArgs e)
7473 if ( settingChangedEventArgs == null ) return ;
7574 }
7675
77- private void CreateSettingsMenu ( )
76+ /* private void CreateSettingsMenu()
7877 {
78+ //Originally how the GSL displayed the settings for showing version info.
79+
7980 MenuTree settingsMenu = new MenuTree("menu.distance.modding.settings", "Mod Settings");
8081
8182 //settingsMenu.CheckBox(MenuDisplayMode.Both, "setting:show_version_info", modVersion, () => ShowVersionInfo.Value, (value) => ShowVersionInfo.Value = value, "Display the Config Manager Version in the main menu");
8283
8384 //MenuSystem.MenuTree.SubmenuButton(MenuDisplayMode.Both, "navigate:menu.distance.modding.settings", "MOD CONFIGURATION MANAGER SETTINGS", settingsMenu, "Settings related to installed mods");
84- }
85+ }*/
8586
8687 private static bool IsKeyboardShortcut ( SettingEntryBase x )
8788 {
@@ -95,7 +96,8 @@ public void BuildSettingList()
9596 {
9697 SettingSearcher . CollectSettings ( out var results , out var modsWithoutSettings ) ;
9798
98- _modsWithoutSettings = string . Join ( ", " , modsWithoutSettings . Select ( x => x . TrimStart ( '!' ) ) . OrderBy ( x => x ) . ToArray ( ) ) ;
99+ //_modsWithoutSettings = string.Join(", ", modsWithoutSettings.Select(x => x.TrimStart('!')).OrderBy(x => x).ToArray());
100+ _modsWithoutSettings = modsWithoutSettings ;
99101 _allSettings = results . ToList ( ) ;
100102 Log . LogInfo ( "Settings found: " + results . Count ( ) ) ;
101103 foreach ( var jeff in results )
@@ -135,28 +137,67 @@ private void BuildFilteredSettingList()
135137 }
136138
137139 _filteredSettings = filteredSettings ;
138- modsLoaded = _filteredSettings . Count ;
140+ modsLoaded = filteredSettings . Count + _modsWithoutSettings . Count - 1 ;
139141
140142 AddFilteredSettingsToMenu ( ) ;
141143 }
142144
143145 private void AddFilteredSettingsToMenu ( )
144146 {
145- foreach ( var plugin in _filteredSettings )
147+ foreach ( PluginSettingsData plugin in _filteredSettings )
146148 {
149+
147150 MenuTree settingsMenu = new MenuTree ( $ "menu.distance.mod.{ Regex . Replace ( plugin . Info . Name , @"\s+" , "" ) . ToLower ( ) } ", $ "{ plugin . Info . Name . ToUpper ( ) } SETTINGS") ;
148151
149- foreach ( var setting in plugin . Settings )
152+ List < string > _categories = new List < string > ( ) ;
153+
154+ foreach ( SettingEntryBase setting in plugin . Settings )
155+ {
156+ if ( _categories . Any ( ) )
157+ {
158+ if ( _categories . Last ( ) != setting . Category )
159+ {
160+ _categories . Add ( setting . Category ) ;
161+ }
162+ }
163+ else
164+ {
165+ _categories . Add ( setting . Category ) ;
166+ }
167+ }
168+
169+ if ( _categories . Count >= 2 )
170+ {
171+ //An attempt to make submenus for categories of a plugin's settings. IT DISPLAYS BAD! IDK WHY! D:
172+ foreach ( string category in _categories )
173+ {
174+ MenuTree menuTree = new MenuTree ( $ "submenu.distance.mod.{ Regex . Replace ( plugin . Info . Name , @"\s+" , "" ) . ToLower ( ) } ", category . ToUpper ( ) ) ;
175+
176+ foreach ( SettingEntryBase setting in plugin . Settings )
177+ {
178+ if ( menuTree . Title == setting . Category . ToUpper ( ) )
179+ {
180+ menuTree . Add ( CreateUIForSetting ( setting ) ) ;
181+ }
182+ }
183+
184+ SubMenu subMenu = settingsMenu . SubmenuButton (
185+ MenuDisplayMode . Both ,
186+ $ "submenu:{ category . ToLower ( ) } ",
187+ category . ToUpper ( ) ,
188+ menuTree ,
189+ $ "{ Regex . Replace ( plugin . Info . Name , @"\s+" , "" ) } settings related to { category } ") ;
190+ }
191+ }
192+ else
150193 {
151- //For now, just skipping keyboard shortcuts entirely
152- //if (typeof(KeyboardShortcut) != setting.SettingType)
153- //{
194+ foreach ( SettingEntryBase setting in plugin . Settings )
195+ {
154196 settingsMenu . Add ( CreateUIForSetting ( setting ) ) ;
155- // }
197+ }
156198 }
157199
158200 Menus . AddNew ( MenuDisplayMode . Both , settingsMenu , plugin . Info . Name . ToUpper ( ) , $ "Settings for the { plugin . Info . Name } mod") ;
159-
160201 }
161202 }
162203
@@ -234,7 +275,24 @@ private MenuItemBase CreateUIForSetting(SettingEntryBase setting)
234275 . WithDescription ( $ "{ setting . Description } ") ;
235276 }
236277
237- if ( typeof ( KeyboardShortcut ) == setting . SettingType )
278+ /*if (typeof(Dictionary<string, int>) == setting.SettingType)
279+ {
280+ Dictionary<string, int> settingDict = new Dictionary<string, int>();
281+ PropertyInfo[] properties = setting.SettingType.GetProperties();
282+
283+ foreach(PropertyInfo property in properties)
284+ {
285+ object value = property.GetValue(setting.Get());
286+ }
287+
288+ return new ListBox<int>(MenuDisplayMode.Both, $"settings:{Regex.Replace(setting.DispName, @"\s+", "_").ToLower()}", setting.DispName.ToUpper())
289+ .WithEntries((Dictionary<string, int>)setting.SettingType)
290+ .WithGetter(() => (int)setting.Get())
291+ .WithSetter((x) => setting.Set(x))
292+ .WithDescription($"{setting.Description}");
293+ }*/
294+
295+ if ( typeof ( KeyboardShortcut ) == setting . SettingType )
238296 {
239297 return new InputPrompt ( MenuDisplayMode . Both , $ "settings:{ Regex . Replace ( setting . DispName , @"\s+" , "_" ) . ToLower ( ) } ", setting . DispName . ToUpper ( ) )
240298 . WithDefaultValue ( setting . DefaultValue . ToString ( ) )
0 commit comments