1 using Microsoft.Xna.Framework;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.Globalization;
16 private int prevInitialMoney;
28 RelativeSpacing = 0.025f
39 RelativeSpacing = 0.0f
43 var saveLabel =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.03f), nameSeedLayout.
RectTransform) { MinSize = new Point(0, GUI.IntScale(24)) }, TextManager.Get(
"SaveName"), textAlignment: Alignment.CenterLeft);
46 textFilterFunction = ToolBox.RemoveInvalidFileNameChars
50 var seedLabel =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.03f), nameSeedLayout.
RectTransform) { MinSize = new Point(0, GUI.IntScale(24)) }, TextManager.Get(
"MapSeed"), textAlignment: Alignment.CenterLeft);
52 seedLabel.InheritTotalChildrenMinHeight();
59 verticalLayout.RectTransform) { MaxSize = new Point(int.MaxValue, GUI.IntScale(30)) }, childAnchor:
Anchor.BottomRight, isHorizontal:
true);
61 prevInitialMoney = CampaignSettings.DefaultInitialMoney;
62 InitialMoneyText =
new GUITextBlock(
new RectTransform(
new Vector2(0.6f, 1f), buttonContainer.RectTransform),
"", font: GUIStyle.SmallFont, textColor: GUIStyle.Green, textAlignment: Alignment.CenterRight)
66 int defaultInitialMoney = CampaignSettings.DefaultInitialMoney;
67 int initialMoney = defaultInitialMoney;
68 if (CampaignModePresets.TryGetAttribute(
69 nameof(CampaignSettings.StartingBalanceAmount).ToIdentifier(),
73 initialMoney = attribute.GetAttributeInt(defaultInitialMoney);
75 if (prevInitialMoney != initialMoney)
78 prevInitialMoney = initialMoney;
84 initialMoney = Math.Max(initialMoney, 0);
86 return TextManager.GetWithVariable(
"campaignstartingmoney",
"[money]",
string.Format(CultureInfo.InvariantCulture,
"{0:N0}", initialMoney));
90 verticalLayout.Recalculate();
112 new GUIMessageBox(TextManager.Get(
"error"), TextManager.Get(
"undefinedsubmarineselected"));
118 new GUIMessageBox(TextManager.Get(
"error"), TextManager.Get(
"nohashsubmarineselected"));
122 string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer,
saveNameBox.
Text);
125 CampaignSettings settings = campaignSettingElements.
CreateSettings();
129 if (!hasRequiredContentPackages)
131 var msgBox =
new GUIMessageBox(TextManager.Get(
"ContentPackageMismatch"),
132 TextManager.GetWithVariable(
"ContentPackageMismatchWarning",
"[requiredcontentpackages]",
string.Join(
", ", selectedSub.
RequiredContentPackages)),
133 new LocalizedString[] { TextManager.Get(
"Yes"), TextManager.Get(
"No") });
135 msgBox.Buttons[0].OnClicked = msgBox.Close;
136 msgBox.Buttons[0].OnClicked += (button, obj) =>
140 StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
141 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
146 msgBox.Buttons[1].OnClicked = msgBox.Close;
151 var msgBox =
new GUIMessageBox(TextManager.Get(
"ShuttleSelected"),
152 TextManager.Get(
"ShuttleWarning"),
153 new LocalizedString[] { TextManager.Get(
"Yes"), TextManager.Get(
"No") });
155 msgBox.Buttons[0].OnClicked = (button, obj) =>
157 StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
158 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
161 msgBox.Buttons[0].OnClicked += msgBox.Close;
163 msgBox.Buttons[1].OnClicked = msgBox.Close;
169 StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
170 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
176 private IEnumerable<CoroutineStatus> WaitForCampaignSetup()
178 GUI.SetCursorWaiting();
179 var headerText = TextManager.Get(
"CampaignStartingPleaseWait");
182 msgBox.Buttons[0].OnClicked = (btn, userdata) =>
186 GUI.ClearCursorWait();
187 CoroutineManager.StopCoroutines(
"WaitForCampaignSetup");
190 msgBox.Buttons[0].OnClicked += msgBox.Close;
192 DateTime timeOut = DateTime.Now +
new TimeSpan(0, 0, 20);
193 while (Screen.Selected != GameMain.GameScreen && DateTime.Now < timeOut)
195 msgBox.Header.Text = headerText +
new string(
'.', (
int)Timing.TotalTime % 3 + 1);
196 yield
return CoroutineStatus.Running;
199 GUI.ClearCursorWait();
200 yield
return CoroutineStatus.Success;
203 public override void CreateLoadMenu(IEnumerable<CampaignMode.SaveInfo> saveFiles =
null)
207 loadGameContainer.ClearChildren();
209 if (saveFiles ==
null)
211 saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
217 RelativeSpacing = 0.03f
222 PlaySoundOnSelect =
true,
223 OnSelected = SelectSaveFile
235 OnClicked = (btn, obj) =>
238 if (
string.IsNullOrWhiteSpace(saveInfo.FilePath)) {
return false; }
239 LoadGame?.Invoke(saveInfo.FilePath, backupIndex: Option.None);
241 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
249 RelativeSpacing = 0.05f,
253 rollbackSaveButton =
new GUIButton(
new RectTransform(
new Vector2(1f, 0.5f), leftButtonContainer.
RectTransform), TextManager.Get(
"rollbackbutton"), style:
"GUIButtonSmallFreeScale")
256 ToolTip = TextManager.Get(
"backuptooltip"),
257 OnClicked = ViewBackupSaveMenu
260 TextManager.Get(
"Delete"), style:
"GUIButtonSmallFreeScale")
267 private bool ViewBackupSaveMenu(
GUIButton button,
object obj)
269 if (obj is not
CampaignMode.SaveInfo saveInfo) {
return false; }
270 if (
string.IsNullOrWhiteSpace(saveInfo.FilePath)) {
return false; }
272 if (GameMain.Client.IsServerOwner)
276 LoadGame(saveInfo.FilePath, backupIndex: Option.Some(index.Index));
281 RequestBackupIndexData(saveInfo.FilePath);
286 private const string PleaseWaitUserData =
"PleaseWaitPopup";
288 private void RequestBackupIndexData(
string savePath)
290 if (GameMain.Client ==
null) {
return; }
292 GUI.SetCursorWaiting();
293 var msgBox =
new GUIMessageBox(TextManager.Get(
"CampaignStartingPleaseWait"), TextManager.Get(
"CampaignStarting"),
new[] { TextManager.Get(
"Cancel") })
295 UserData = PleaseWaitUserData
297 msgBox.Buttons[0].OnClicked = (btn, obj) =>
299 GUI.ClearCursorWait();
306 GameMain.Client?.ClientPeer?.Send(msg, DeliveryMethod.Reliable);
311 GUI.ClearCursorWait();
321 string path = message.ReadString();
322 var indexData = INetSerializableStruct.Read<NetCollection<SaveUtil.BackupIndexData>>(message);
325 LoadGame?.Invoke(path, backupIndex: Option.Some(selectedIndex.Index));
329 private bool SelectSaveFile(
GUIComponent component,
object obj)
331 if (obj is not
CampaignMode.SaveInfo saveInfo) {
return true; }
332 string fileName = saveInfo.FilePath;
335 rollbackSaveButton.
Visible =
true;
336 deleteMpSaveButton.
Visible = deleteMpSaveButton.
Enabled = GameMain.Client.IsServerOwner;
337 rollbackSaveButton.
Enabled = deleteMpSaveButton.
Enabled = GameMain.GameSession?.DataPath.LoadPath != fileName;
338 if (deleteMpSaveButton.
Visible)
340 deleteMpSaveButton.
UserData = saveInfo;
343 if (rollbackSaveButton.
Visible)
345 rollbackSaveButton.
UserData = saveInfo;
readonly GUIComponent newGameContainer
GUITextBlock InitialMoneyText
LoadGameDelegate LoadGame
GUIComponent CreateSaveElement(CampaignMode.SaveInfo saveInfo)
Action< SubmarineInfo, string, string, CampaignSettings > StartNewGame
static CampaignSettingElements CreateCampaignSettingList(GUIComponent parent, CampaignSettings prevSettings, bool isSinglePlayer)
List< CampaignMode.SaveInfo > prevSaveFiles
void CreateBackupMenu(IEnumerable< SaveUtil.BackupIndexData > indexData, Action< SaveUtil.BackupIndexData > loadBackup)
bool DeleteSave(GUIButton button, object obj)
virtual void Flash(Color? color=null, float flashDuration=1.5f, bool useRectangleFlash=false, bool useCircularFlash=false, Vector2? flashRectInflate=null)
void Pulsate(Vector2 startScale, Vector2 endScale, float duration)
void InheritTotalChildrenMinHeight()
Sets the minimum height of the transfrom to equal to the sum of the minimum heights of the children (...
RectTransform RectTransform
static readonly List< GUIComponent > MessageBoxes
override void Flash(Color? color=null, float flashDuration=1.5f, bool useRectangleFlash=false, bool useCircularFlash=false, Vector2? flashRectOffset=null)
static NetLobbyScreen NetLobbyScreen
readonly string StringRepresentation
bool StartGameClicked(GUIButton button, object userdata)
void OnBackupIndicesReceived(IReadMessage message)
MultiPlayerCampaignSetupUI(GUIComponent newGameContainer, GUIComponent loadGameContainer, List< CampaignMode.SaveInfo > saveFiles=null)
override void CreateLoadMenu(IEnumerable< CampaignMode.SaveInfo > saveFiles=null)
HashSet< string > RequiredContentPackages
SubmarineClass SubmarineClass
bool HasTag(SubmarineTag tag)
bool RequiredContentPackagesInstalled
void WriteString(string val)
SettingValue< StartingBalanceAmountOption > StartingFunds
readonly CampaignSettings CreateSettings()
void HighlightMode(int modeIndex)
void SelectMode(int modeIndex)
SubmarineInfo SelectedSub
void RefreshEnabledElements()