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