Skip to content

Commit fc2dc8a

Browse files
committed
use localization in disconnected messages, move server stopping code to Network class
1 parent 7b51b8a commit fc2dc8a

File tree

7 files changed

+94
-17
lines changed

7 files changed

+94
-17
lines changed

COTLMP/Data/Resources.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ public static string ServerStarted
5959
}
6060
}
6161

62+
public static string Disconnected
63+
{
64+
get
65+
{
66+
return LocalizationManager.GetTranslation("Multiplayer/UI/Disconnected");
67+
}
68+
}
69+
70+
public static string DisconnectedError
71+
{
72+
get
73+
{
74+
return LocalizationManager.GetTranslation("Multiplayer/UI/DisconnectedError");
75+
}
76+
}
77+
6278
public static string ServerStopConfirm
6379
{
6480
get

COTLMP/Language/en-US.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public class English
3434
new("Multiplayer/UI/WIP", "Multiplayer is currently not implemented yet", false),
3535
new("Multiplayer/UI/StartServer", "Open to LAN", false),
3636
new("Multiplayer/UI/ServerStarted", "Stop server and quit", false),
37-
new("Multiplayer/UI/ServerConfirm", "Are you sure you want to stop the server? This action will return you to the main menu without saving progress.", false)
37+
new("Multiplayer/UI/ServerConfirm", "Are you sure you want to stop the server? This action will return you to the main menu without saving progress.", false),
38+
new("Multiplayer/UI/Disconnected", "Disconnected", false),
39+
new("Multiplayer/UI/DisconnectedError", "An error has ocurred (check console)", false)
3840
];
3941
}
4042
}

COTLMP/Network/.keep

Whitespace-only changes.

COTLMP/Network/Network.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* PROJECT: Cult of the Lamb Multiplayer Mod
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Define the network class
5+
* COPYRIGHT: Copyright 2025 Neco-Arc <[email protected]>
6+
*/
7+
8+
/* IMPORTS ********************************************************************/
9+
10+
using COTLMP.Ui;
11+
using UnityEngine;
12+
using UnityEngine.SceneManagement;
13+
14+
/* CLASSES & CODE *************************************************************/
15+
16+
/**
17+
* @brief
18+
* The namespace for all network-related classes, enums and structs
19+
*/
20+
namespace COTLMP.Network
21+
{
22+
/**
23+
* @brief
24+
* The main class for network features
25+
*/
26+
internal class Network
27+
{
28+
/**
29+
* @brief
30+
* If the scene loaded is main menu, stop the integrated server
31+
*
32+
* @param[in] scene
33+
* The scene
34+
*
35+
* @param[in] _
36+
* The scene load mode, unused
37+
*/
38+
private static void OnSceneLoaded(Scene scene, LoadSceneMode _)
39+
{
40+
if (scene.name.Equals("Main Menu"))
41+
{
42+
// set the quitting flag temporarily so it doesn't try to transition to the main menu on server stop
43+
PauseMenuPatches.Quitting = true;
44+
PauseMenuPatches.Server?.Dispose();
45+
PauseMenuPatches.Quitting = false;
46+
}
47+
}
48+
49+
/**
50+
* @brief
51+
* On game quitting, stop the integrated server
52+
*/
53+
private static void OnQuitting()
54+
{
55+
PauseMenuPatches.Quitting = true;
56+
PauseMenuPatches.Server?.Dispose();
57+
}
58+
59+
/**
60+
* @brief
61+
* Initialize the network components
62+
*/
63+
public static void Initialize()
64+
{
65+
SceneManager.sceneLoaded += OnSceneLoaded;
66+
Application.quitting += OnQuitting;
67+
}
68+
}
69+
}
70+
71+
/* EOF */

COTLMP/Plugin.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,8 @@ private void Awake()
179179
/* Initialize the Settings UI */
180180
COTLMP.Ui.Settings.InitializeUI();
181181

182-
UnityEngine.Application.quitting += () => {
183-
PauseMenuPatches.Quitting = true;
184-
PauseMenuPatches.Server?.Dispose();
185-
};
186-
187-
SceneManager.sceneLoaded += (scene, _) => {
188-
if (scene.name.Equals("Main Menu"))
189-
{
190-
// set the quitting flag temporarily so it doesn't try to transition to the main menu on server stop
191-
PauseMenuPatches.Quitting = true;
192-
PauseMenuPatches.Server?.Dispose();
193-
PauseMenuPatches.Quitting = false;
194-
}
195-
};
182+
// Initialize the network features
183+
COTLMP.Network.Network.Initialize();
196184

197185
/* Log to the debugger that our mod is loaded */
198186
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");

COTLMP/Ui/MainMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static void Start(MainMenu __instance)
6969
{
7070
if(PauseMenuPatches.Message != null)
7171
{
72-
__instance.Push<UIMenuConfirmationWindow>(MonoSingleton<UIManager>.Instance.ConfirmationWindowTemplate).Configure("Server was shutdown", PauseMenuPatches.Message, true);
72+
__instance.Push<UIMenuConfirmationWindow>(MonoSingleton<UIManager>.Instance.ConfirmationWindowTemplate).Configure(MultiplayerModLocalization.UI.Disconnected, PauseMenuPatches.Message, true);
7373
PauseMenuPatches.Message = null;
7474
}
7575
}

COTLMP/Ui/PauseMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private static void ServerStopped(object sender, ServerStoppedArgs e)
180180
UIDynamicNotificationCenter.Reset();
181181
MonoSingleton<UIManager>.Instance.ResetPreviousCursor();
182182
TwitchManager.Abort();
183-
Message = (e.Reason == ServerStopReason.Error) ? "An error has ocurred (check console)" : "";
183+
Message = (e.Reason == ServerStopReason.Error) ? MultiplayerModLocalization.UI.DisconnectedError : "";
184184
MMTransition.Play(MMTransition.TransitionType.ChangeSceneAutoResume, MMTransition.Effect.BlackFade, "Main Menu", 1f, "", null);
185185
}
186186

0 commit comments

Comments
 (0)