Skip to content

Commit 05a60e2

Browse files
committed
Update main menu (start server still broken)
- New open server log - Also rebuild main menu state every time we re-enter the main menu - Update localization for host and join multiplayer with player and world tooltips - Also update build to v1.1
1 parent d3ec49d commit 05a60e2

9 files changed

Lines changed: 284 additions & 262 deletions

File tree

Common/Configs/Config.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public class Config : ModConfig
3939
[DefaultValue(true)]
4040
public bool SaveWorld;
4141

42-
[DefaultValue(false)]
43-
public bool DebugReload;
42+
[DefaultValue(false)]
43+
public bool DebugReload;
4444

45-
[Header("ExtraInfo")]
45+
[Header("ExtraInfo")]
4646

4747
[DefaultValue(true)]
4848
public bool ShowDebugInfo;
@@ -71,9 +71,6 @@ public enum WorldDifficulty { Normal, Expert, Master, Journey }
7171

7272
[Header("Misc")]
7373

74-
[DefaultValue(true)]
75-
public bool RightClickToolOptions;
76-
7774
[DefaultValue(true)]
7875
public bool LogLevelPersistOnReloads;
7976

Core/Features/MainMenuFeatures/MainMenuActions.cs

Lines changed: 164 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -10,204 +10,202 @@
1010
using Terraria.WorldBuilding;
1111
using static ModReloader.Common.Configs.Config;
1212

13-
namespace ModReloader.Core.Features.MainMenuFeatures
13+
namespace ModReloader.Core.Features.MainMenuFeatures;
14+
public class MainMenuExtraSmallSystem : ModSystem
1415
{
15-
public class MainMenuExtraSmallSystem : ModSystem
16+
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref double totalWeight)
1617
{
17-
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref double totalWeight)
18+
if (Conf.C.CreateTestWorldSize != WorldSize.ExtraSmall)
19+
return;
20+
21+
// Passes known (or very likely) to crash on a 2 100 × 600 map
22+
string[] skipExact =
23+
[
24+
"Dungeon", "Dungeon Entrance", "Pyramids", "Temple", "Jungle Temple", "Bee Hives",
25+
"Oceans", "Ocean Caves", "Ocean Sand",
26+
"Lakes", "Oasis", "Dunes",
27+
"Mushroom Patches", "Mushroom Biomes",
28+
"Gem Caves", "Granite Caves", "Marble Caves",
29+
"Floating Islands", "Sky Lakes",
30+
"Waterfalls", "Water Features", "Rivers",
31+
"Jungle Chests", "Jungle Shrines",
32+
"Micro Biomes"
33+
];
34+
var exact = new HashSet<string>(skipExact, StringComparer.OrdinalIgnoreCase);
35+
36+
// any pass name containing these substrings will also be skipped automatically
37+
string[] skipContains = { "Ocean", "Micro", "Moss" };
38+
39+
for (int i = 0; i < tasks.Count; i++)
1840
{
19-
if (Conf.C.CreateTestWorldSize != WorldSize.ExtraSmall)
20-
return;
21-
22-
// Passes known (or very likely) to crash on a 2 100 × 600 map
23-
string[] skipExact =
24-
[
25-
"Dungeon", "Dungeon Entrance", "Pyramids", "Temple", "Jungle Temple", "Bee Hives",
26-
"Oceans", "Ocean Caves", "Ocean Sand",
27-
"Lakes", "Oasis", "Dunes",
28-
"Mushroom Patches", "Mushroom Biomes",
29-
"Gem Caves", "Granite Caves", "Marble Caves",
30-
"Floating Islands", "Sky Lakes",
31-
"Waterfalls", "Water Features", "Rivers",
32-
"Jungle Chests", "Jungle Shrines",
33-
"Micro Biomes"
34-
];
35-
var exact = new HashSet<string>(skipExact, StringComparer.OrdinalIgnoreCase);
36-
37-
// any pass name containing these substrings will also be skipped automatically
38-
string[] skipContains = { "Ocean", "Micro", "Moss" };
39-
40-
for (int i = 0; i < tasks.Count; i++)
41-
{
42-
string name = tasks[i].Name;
43-
bool bad =
44-
exact.Contains(name) ||
45-
skipContains.Any(s => name.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);
41+
string name = tasks[i].Name;
42+
bool bad =
43+
exact.Contains(name) ||
44+
skipContains.Any(s => name.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);
4645

47-
if (bad)
48-
tasks[i] = new SkippedPass(name, (float)tasks[i].Weight);
49-
}
46+
if (bad)
47+
tasks[i] = new SkippedPass(name, (float)tasks[i].Weight);
5048
}
49+
}
5150

52-
private sealed class SkippedPass : GenPass
53-
{
54-
public SkippedPass(string name, float weight) : base(name, weight) { }
51+
private sealed class SkippedPass : GenPass
52+
{
53+
public SkippedPass(string name, float weight) : base(name, weight) { }
5554

56-
protected override void ApplyPass(GenerationProgress progress, GameConfiguration cfg)
57-
{
58-
// Do absolutely nothing; only update the progress text
59-
progress.Message = $"Skipped {Name} (ExtraSmall world requested!)";
60-
}
55+
protected override void ApplyPass(GenerationProgress progress, GameConfiguration cfg)
56+
{
57+
// Do absolutely nothing; only update the progress text
58+
progress.Message = $"Skipped {Name} (ExtraSmall world requested!)";
6159
}
6260
}
61+
}
6362

64-
public static class MainMenuActions
63+
public static class MainMenuActions
64+
{
65+
public static string GetNextAvailableTestWorldName()
6566
{
66-
public static string GetNextAvailableTestWorldName()
67-
{
68-
Main.LoadWorlds();
69-
var taken = new HashSet<string>(Main.WorldList.Select(w => w.Name), StringComparer.OrdinalIgnoreCase);
67+
Main.LoadWorlds();
68+
var taken = new HashSet<string>(Main.WorldList.Select(w => w.Name), StringComparer.OrdinalIgnoreCase);
7069

71-
const string baseName = "Test";
72-
int n = 1;
73-
while (taken.Contains($"{baseName}{n}"))
74-
n++;
70+
const string baseName = "Test";
71+
int n = 1;
72+
while (taken.Contains($"{baseName}{n}"))
73+
n++;
7574

76-
return $"{baseName}{n}";
77-
}
75+
return $"{baseName}{n}";
76+
}
7877

79-
public static void CreateNewWorld(string desiredName)
78+
public static void CreateNewWorld(string desiredName)
79+
{
80+
Main.LoadPlayers();
81+
if (Main.PlayerList.Count == 0) return;
82+
int pIdx = Conf.C.Player.Type;
83+
if (pIdx < 0 || pIdx >= Main.PlayerList.Count) pIdx = 0;
84+
Main.SelectPlayer(Main.PlayerList[pIdx]);
85+
86+
Main.LoadWorlds();
87+
var taken = new HashSet<string>(Main.WorldList.Select(w => w.Name),
88+
StringComparer.OrdinalIgnoreCase);
89+
string finalName = taken.Contains(desiredName)
90+
? GetNextAvailableTestWorldName()
91+
: desiredName;
92+
93+
// Set world size based on config
94+
switch (Conf.C.CreateTestWorldSize)
8095
{
81-
Main.LoadPlayers();
82-
if (Main.PlayerList.Count == 0) return;
83-
int pIdx = Conf.C.Player.Type;
84-
if (pIdx < 0 || pIdx >= Main.PlayerList.Count) pIdx = 0;
85-
Main.SelectPlayer(Main.PlayerList[pIdx]);
96+
case WorldSize.ExtraSmall:
97+
Main.maxTilesX = 2100;
98+
Main.maxTilesY = 600;
99+
break;
100+
case WorldSize.Small:
101+
Main.maxTilesX = 4200;
102+
Main.maxTilesY = 1200;
103+
break;
104+
case WorldSize.Medium:
105+
Main.maxTilesX = 6400;
106+
Main.maxTilesY = 1800;
107+
break;
108+
case WorldSize.Large:
109+
Main.maxTilesX = 8400;
110+
Main.maxTilesY = 2400;
111+
break;
112+
}
113+
WorldGen.setWorldSize();
86114

87-
Main.LoadWorlds();
88-
var taken = new HashSet<string>(Main.WorldList.Select(w => w.Name),
89-
StringComparer.OrdinalIgnoreCase);
90-
string finalName = taken.Contains(desiredName)
91-
? GetNextAvailableTestWorldName()
92-
: desiredName;
93-
94-
// Set world size based on config
95-
switch (Conf.C.CreateTestWorldSize)
115+
// Set difficulty based on config
116+
int worldDifficultyId = Conf.C.CreateTestWorldDifficulty switch
117+
{
118+
WorldDifficulty.Normal => 0,
119+
WorldDifficulty.Expert => 1,
120+
WorldDifficulty.Master => 2,
121+
WorldDifficulty.Journey => 3,
122+
_ => 0
123+
};
124+
Main.GameMode = worldDifficultyId;
125+
126+
WorldGen.WorldGenParam_Evil = 0; // Corruption
127+
128+
string seed = WorldGen.genRand.Next().ToString();
129+
UIWorldCreation.ProcessSpecialWorldSeeds(seed);
130+
131+
bool cloud = SocialAPI.Cloud != null && SocialAPI.Cloud.EnabledByDefault;
132+
Main.worldName = finalName;
133+
Main.ActiveWorldFileData = WorldFile.CreateMetadata(finalName, cloud, Main.GameMode);
134+
Main.ActiveWorldFileData.SetSeed(seed);
135+
136+
Main.menuMode = 10;
137+
WorldGen.CreateNewWorld();
138+
}
139+
public static void StartClient()
140+
{
141+
try
142+
{
143+
string steamPath = Log.GetSteamPath();
144+
string startGameFileName = Path.Combine(steamPath, "start-tModLoader.bat");
145+
if (!File.Exists(startGameFileName))
96146
{
97-
case WorldSize.ExtraSmall:
98-
Main.maxTilesX = 2100;
99-
Main.maxTilesY = 600;
100-
break;
101-
case WorldSize.Small:
102-
Main.maxTilesX = 4200;
103-
Main.maxTilesY = 1200;
104-
break;
105-
case WorldSize.Medium:
106-
Main.maxTilesX = 6400;
107-
Main.maxTilesY = 1800;
108-
break;
109-
case WorldSize.Large:
110-
Main.maxTilesX = 8400;
111-
Main.maxTilesY = 2400;
112-
break;
147+
Log.Error("Failed to find start-tModLoader.bat file.");
148+
return;
113149
}
114-
WorldGen.setWorldSize();
115150

116-
// Set difficulty based on config
117-
int worldDifficultyId = Conf.C.CreateTestWorldDifficulty switch
151+
// create worldDifficultyId process
152+
ProcessStartInfo process = new(startGameFileName)
118153
{
119-
WorldDifficulty.Normal => 0,
120-
WorldDifficulty.Expert => 1,
121-
WorldDifficulty.Master => 2,
122-
WorldDifficulty.Journey => 3,
123-
_ => 0
154+
UseShellExecute = true,
124155
};
125-
Main.GameMode = worldDifficultyId;
126-
127-
WorldGen.WorldGenParam_Evil = 0; // Corruption
128-
129-
string seed = WorldGen.genRand.Next().ToString();
130-
UIWorldCreation.ProcessSpecialWorldSeeds(seed);
131156

132-
bool cloud = SocialAPI.Cloud != null && SocialAPI.Cloud.EnabledByDefault;
133-
Main.worldName = finalName;
134-
Main.ActiveWorldFileData = WorldFile.CreateMetadata(finalName, cloud, Main.GameMode);
135-
Main.ActiveWorldFileData.SetSeed(seed);
136-
137-
Main.menuMode = 10;
138-
WorldGen.CreateNewWorld();
157+
// start the process
158+
Process gameProcess = Process.Start(process);
159+
Log.Info("Game process started with ID: " + gameProcess.Id + " and name: " + gameProcess.ProcessName);
139160
}
140-
public static void StartClient()
161+
catch (Exception e)
141162
{
142-
try
143-
{
144-
string steamPath = Log.GetSteamPath();
145-
string startGameFileName = Path.Combine(steamPath, "start-tModLoader.bat");
146-
if (!File.Exists(startGameFileName))
147-
{
148-
Log.Error("Failed to find start-tModLoader.bat file.");
149-
return;
150-
}
151-
152-
// create worldDifficultyId process
153-
ProcessStartInfo process = new(startGameFileName)
154-
{
155-
UseShellExecute = true,
156-
};
157-
158-
// start the process
159-
Process gameProcess = Process.Start(process);
160-
Log.Info("Game process started with ID: " + gameProcess.Id + " and name: " + gameProcess.ProcessName);
161-
}
162-
catch (Exception e)
163-
{
164-
Log.Error("Failed to start game process (start-tModLoader.bat failed to launch): " + e.Message);
165-
return;
166-
}
163+
Log.Error("Failed to start game process (start-tModLoader.bat failed to launch): " + e.Message);
164+
return;
167165
}
166+
}
168167

169-
public static void StartServer()
168+
public static void StartServer()
169+
{
170+
try
170171
{
171-
try
172+
Main.LoadWorlds();
173+
174+
if (Main.WorldList.Count == 0)
175+
throw new Exception("No worlds found.");
176+
177+
// Getting Player and World from ClientDataHandler
178+
var world = Main.WorldList.FirstOrDefault(p => p.Path.Equals(ClientDataMemoryStorage.WorldPath)) ?? throw new Exception("World not found: " + ClientDataMemoryStorage.WorldPath);
179+
if (string.IsNullOrEmpty(world.Path))
172180
{
173-
Main.LoadWorlds();
174-
175-
if (Main.WorldList.Count == 0)
176-
throw new Exception("No worlds found.");
177-
178-
// Getting Player and World from ClientDataHandler
179-
var world = Main.WorldList.FirstOrDefault(p => p.Path.Equals(ClientDataMemoryStorage.WorldPath)) ?? throw new Exception("World not found: " + ClientDataMemoryStorage.WorldPath);
180-
if (string.IsNullOrEmpty(world.Path))
181-
{
182-
Log.Error($"World {world.Name} has an invalid or null path.");
183-
var worldPath = world.Path;
184-
throw new ArgumentNullException(nameof(worldPath), "World path cannot be null or empty.");
185-
}
186-
187-
string steamPath = Log.GetSteamPath();
188-
string startServerFileName = Path.Combine(steamPath, "start-tModLoaderServer.bat");
189-
if (!File.Exists(startServerFileName))
190-
{
191-
Log.Error("Failed to find start-tModLoaderServer.bat file.");
192-
return;
193-
}
194-
195-
// create worldDifficultyId process
196-
ProcessStartInfo process = new(startServerFileName)
197-
{
198-
UseShellExecute = true,
199-
Arguments = $"-nosteam -world {world.Path}"
200-
};
201-
202-
// start the process
203-
Process serverProcess = Process.Start(process);
204-
Log.Info("Server process started with ID: " + serverProcess.Id + " and name: " + serverProcess.ProcessName);
181+
Log.Error($"World {world.Name} has an invalid or null path.");
182+
var worldPath = world.Path;
183+
throw new ArgumentNullException(nameof(worldPath), "World path cannot be null or empty.");
205184
}
206-
catch (Exception e)
185+
186+
string steamPath = Log.GetSteamPath();
187+
string startServerFileName = Path.Combine(steamPath, "start-tModLoaderServer.bat");
188+
if (!File.Exists(startServerFileName))
207189
{
208-
Log.Error("Failed to start server (start-tModLoaderServer.bat failed to launch): " + e.Message);
190+
Log.Error("Failed to find start-tModLoaderServer.bat file.");
209191
return;
210192
}
193+
194+
// create worldDifficultyId process
195+
ProcessStartInfo process = new(startServerFileName)
196+
{
197+
UseShellExecute = true,
198+
Arguments = $"-nosteam -world {world.Path}"
199+
};
200+
201+
// start the process
202+
Process serverProcess = Process.Start(process);
203+
Log.Info("Server process started with ID: " + serverProcess.Id + " and name: " + serverProcess.ProcessName);
204+
}
205+
catch (Exception e)
206+
{
207+
Log.Error("Failed to start server (start-tModLoaderServer.bat failed to launch): " + e.Message);
208+
return;
211209
}
212210
}
213211
}

0 commit comments

Comments
 (0)