|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.ComponentModel; |
4 | | -using ModReloader.Common.Configs.ConfigElements.ModsConfigElements; |
5 | | -using ModReloader.Common.Configs.ConfigElements.PlayerAndWorld; |
6 | | -using ModReloader.Common.Configs.ConfigElements.PlayerAndWorldNew; |
| 1 | +using ModReloader.Common.Configs.ConfigElements.ModsConfigElements; |
| 2 | +using ModReloader.Common.Configs.ConfigElements.PlayerPicker; |
| 3 | +using ModReloader.Common.Configs.ConfigElements.WorldPicker; |
7 | 4 | using ModReloader.Core.Features.MainMenuFeatures; |
8 | 5 | using ModReloader.Core.Features.Reload; |
| 6 | +using System; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.ComponentModel; |
| 9 | +using System.Threading.Channels; |
9 | 10 | using Terraria.ModLoader.Config; |
10 | 11 |
|
11 | | -namespace ModReloader.Common.Configs |
| 12 | +namespace ModReloader.Common.Configs; |
| 13 | +public class Config : ModConfig |
12 | 14 | { |
13 | | - public class Config : ModConfig |
14 | | - { |
15 | | - public override ConfigScope Mode => ConfigScope.ClientSide; |
| 15 | + public override ConfigScope Mode => ConfigScope.ClientSide; |
16 | 16 |
|
17 | | - [Header("ModsToReload")] |
| 17 | + [Header("ModsToReload")] |
18 | 18 |
|
19 | | - [CustomModConfigItem(typeof(ModSourcesConfig))] |
20 | | - public List<string> ModsToReload = []; |
| 19 | + [CustomModConfigItem(typeof(ModSourcesConfig))] |
| 20 | + public List<string> ModsToReload = []; |
21 | 21 |
|
22 | | - [Header("ReloadOptions")] |
| 22 | + [Header("ReloadOptions")] |
23 | 23 |
|
24 | | - [CustomModConfigItem(typeof(PlayerIndexSliderElement))] |
25 | | - [DefaultValue("")] |
26 | | - public string Player; // player index in Main.PlayerList |
| 24 | + [CustomModConfigItem(typeof(PlayerDefinitionElement))] |
| 25 | + public PlayerDefinition Player = new(); |
27 | 26 |
|
28 | | - [CustomModConfigItem(typeof(PlayerDefinitionElement))] |
29 | | - public PlayerDefinition PlayerTest; |
| 27 | + [CustomModConfigItem(typeof(WorldDefinitionElement))] |
| 28 | + public WorldDefinition World = new(); |
30 | 29 |
|
31 | | - [CustomModConfigItem(typeof(WorldIndexSliderElement))] |
32 | | - public string World; // world index in Main.WorldList |
| 30 | + // Used for testing, do not delete! |
| 31 | + //public NPCDefinition NPCTest; |
33 | 32 |
|
34 | | - [DefaultValue(true)] |
35 | | - public bool AutoJoinWorld; |
| 33 | + //[CustomModConfigItem(typeof(WorldIndexSliderElement))] |
| 34 | + //public string World; // world index in Main.WorldList |
36 | 35 |
|
37 | | - [DefaultValue(true)] |
38 | | - public bool SaveWorld; |
| 36 | + [DefaultValue(true)] |
| 37 | + public bool AutoJoinWorld; |
39 | 38 |
|
40 | | - [Header("ExtraInfo")] |
| 39 | + [DefaultValue(true)] |
| 40 | + public bool SaveWorld; |
41 | 41 |
|
42 | | - [DefaultValue(true)] |
43 | | - public bool ShowDebugInfo; |
| 42 | + [Header("ExtraInfo")] |
44 | 43 |
|
45 | | - [DefaultValue(true)] |
46 | | - public bool ShowMainMenuInfo; |
| 44 | + [DefaultValue(true)] |
| 45 | + public bool ShowDebugInfo; |
47 | 46 |
|
48 | | - [DefaultValue(true)] |
49 | | - public bool ShowErrorMenuInfo; |
| 47 | + [DefaultValue(true)] |
| 48 | + public bool ShowMainMenuInfo; |
50 | 49 |
|
51 | | - [DefaultValue(true)] |
52 | | - public bool ShowCopyToClipboardButton; |
| 50 | + [DefaultValue(true)] |
| 51 | + public bool ShowErrorMenuInfo; |
53 | 52 |
|
54 | | - [DefaultValue(true)] |
55 | | - public bool ShowBackToMainMenu; |
| 53 | + [DefaultValue(true)] |
| 54 | + public bool ShowCopyToClipboardButton; |
56 | 55 |
|
57 | | - public enum WorldSize { ExtraSmall, Small, Medium, Large } |
58 | | - [DrawTicks] |
59 | | - [DefaultValue(WorldSize.Small)] |
60 | | - public WorldSize CreateTestWorldSize; |
| 56 | + [DefaultValue(true)] |
| 57 | + public bool ShowBackToMainMenu; |
61 | 58 |
|
62 | | - public enum WorldDifficulty { Normal, Expert, Master, Journey } |
63 | | - [DrawTicks] |
64 | | - [DefaultValue(WorldDifficulty.Normal)] |
65 | | - public WorldDifficulty CreateTestWorldDifficulty; |
| 59 | + public enum WorldSize { ExtraSmall, Small, Medium, Large } |
| 60 | + [DrawTicks] |
| 61 | + [DefaultValue(WorldSize.Small)] |
| 62 | + public WorldSize CreateTestWorldSize; |
66 | 63 |
|
67 | | - [Header("Misc")] |
| 64 | + public enum WorldDifficulty { Normal, Expert, Master, Journey } |
| 65 | + [DrawTicks] |
| 66 | + [DefaultValue(WorldDifficulty.Normal)] |
| 67 | + public WorldDifficulty CreateTestWorldDifficulty; |
68 | 68 |
|
69 | | - [DefaultValue(true)] |
70 | | - public bool RightClickToolOptions; |
| 69 | + [Header("Misc")] |
71 | 70 |
|
72 | | - [DefaultValue(true)] |
73 | | - public bool LogLevelPersistOnReloads; |
| 71 | + [DefaultValue(true)] |
| 72 | + public bool RightClickToolOptions; |
74 | 73 |
|
75 | | - [DefaultValue(false)] |
76 | | - public bool ClearLogOnReload; |
| 74 | + [DefaultValue(true)] |
| 75 | + public bool LogLevelPersistOnReloads; |
77 | 76 |
|
78 | | - [DefaultValue(true)] |
79 | | - public bool LogDebugMessages; |
| 77 | + [DefaultValue(false)] |
| 78 | + public bool ClearLogOnReload; |
80 | 79 |
|
81 | | - public override void OnChanged() |
82 | | - { |
83 | | - base.OnChanged(); |
84 | | - UpdateMainMenuReloadTooltip(); |
85 | | - } |
| 80 | + [DefaultValue(true)] |
| 81 | + public bool LogDebugMessages; |
| 82 | + |
| 83 | + public override void OnLoaded() |
| 84 | + { |
| 85 | + base.OnLoaded(); |
| 86 | + EnsureDefaultPlayerAndWorld(); |
| 87 | + } |
| 88 | + |
| 89 | + public override void OnChanged() |
| 90 | + { |
| 91 | + Log.Info("Config changed"); |
| 92 | + |
| 93 | + base.OnChanged(); |
| 94 | + UpdateMainMenuReloadTooltip(); |
| 95 | + } |
| 96 | + |
| 97 | + private void UpdateMainMenuReloadTooltip() |
| 98 | + { |
| 99 | + var mainMenuSys = ModContent.GetInstance<MainMenuSystem>(); |
| 100 | + if (mainMenuSys?.state == null) |
| 101 | + return; |
| 102 | + |
| 103 | + Main.LoadPlayers(); |
| 104 | + Main.LoadWorlds(); |
| 105 | + |
| 106 | + int p = Conf.C.Player != null ? Utilities.FindPlayerId(Conf.C.Player.Name) : 0; |
| 107 | + int w = Conf.C.World != null ? Utilities.FindWorldId(Conf.C.World.Name) : 0; |
86 | 108 |
|
87 | | - private void UpdateMainMenuReloadTooltip() |
| 109 | + mainMenuSys.state.UpdatePlayerIndex(p); |
| 110 | + mainMenuSys.state.UpdateWorldIndex(w); |
| 111 | + } |
| 112 | + |
| 113 | + private void EnsureDefaultPlayerAndWorld() |
| 114 | + { |
| 115 | + bool changed = false; |
| 116 | + |
| 117 | + // Player |
| 118 | + if (Player == null) |
88 | 119 | { |
89 | | - // Update reload tooltip |
90 | | - var mainMenuSys = ModContent.GetInstance<MainMenuSystem>(); |
91 | | - if (mainMenuSys == null) |
| 120 | + Main.LoadPlayers(); |
| 121 | + |
| 122 | + if (Main.PlayerList.Count > 0) |
92 | 123 | { |
93 | | - Log.Info("main menu sys is null!"); |
94 | | - return; |
| 124 | + Player = new PlayerDefinition(Main.PlayerList[0].Path); |
| 125 | + Log.Info("Default player set to: " + Player.Name); |
| 126 | + changed = true; |
95 | 127 | } |
96 | | - var state = mainMenuSys.state; |
97 | | - if (state == null) return; |
| 128 | + } |
98 | 129 |
|
99 | | - Main.LoadPlayers(); |
| 130 | + // World |
| 131 | + if (World == null) |
| 132 | + { |
100 | 133 | Main.LoadWorlds(); |
101 | 134 |
|
102 | | - int p = Utilities.FindPlayerId(Conf.C.Player); |
103 | | - int w = Utilities.FindWorldId(Conf.C.World); |
| 135 | + if (Main.WorldList.Count > 0) |
| 136 | + { |
| 137 | + World = new WorldDefinition(Main.WorldList[0].Path); |
| 138 | + Log.Info("Default world set to: " + Main.WorldList[0].Name); |
| 139 | + changed = true; |
| 140 | + } |
| 141 | + } |
104 | 142 |
|
105 | | - state.UpdatePlayerIndex(p); |
106 | | - state.UpdateWorldIndex(w); |
| 143 | + if (changed) |
| 144 | + { |
| 145 | + ConfigManager.Save(this); |
| 146 | + SaveChanges(); |
107 | 147 | } |
108 | 148 | } |
109 | 149 |
|
110 | | - public static class Conf |
111 | | - { |
112 | | - /// <summary> |
113 | | - /// Quick instance getter. |
114 | | - /// Usage example: Conf.C.YourField |
115 | | - /// /// </summary> |
116 | | - public static Config C => ModContent.GetInstance<Config>(); |
117 | | - } |
| 150 | +} |
| 151 | + |
| 152 | +public static class Conf |
| 153 | +{ |
| 154 | + /// <summary> |
| 155 | + /// Quick instance getter. |
| 156 | + /// Usage example: Conf.C.YourField |
| 157 | + /// /// </summary> |
| 158 | + public static Config C => ModContent.GetInstance<Config>(); |
118 | 159 | } |
0 commit comments