1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
4 using System.Globalization;
12 private int prevInitialMoney;
24 RelativeSpacing = 0.025f
35 RelativeSpacing = 0.0f
39 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);
42 textFilterFunction = ToolBox.RemoveInvalidFileNameChars
46 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);
48 seedLabel.InheritTotalChildrenMinHeight();
55 verticalLayout.RectTransform) { MaxSize = new Point(int.MaxValue, GUI.IntScale(30)) }, childAnchor:
Anchor.BottomRight, isHorizontal:
true);
57 prevInitialMoney = CampaignSettings.DefaultInitialMoney;
58 InitialMoneyText =
new GUITextBlock(
new RectTransform(
new Vector2(0.6f, 1f), buttonContainer.RectTransform),
"", font: GUIStyle.SmallFont, textColor: GUIStyle.Green, textAlignment: Alignment.CenterRight)
62 int defaultInitialMoney = CampaignSettings.DefaultInitialMoney;
63 int initialMoney = defaultInitialMoney;
64 if (CampaignModePresets.TryGetAttribute(
65 nameof(CampaignSettings.StartingBalanceAmount).ToIdentifier(),
69 initialMoney = attribute.GetAttributeInt(defaultInitialMoney);
71 if (prevInitialMoney != initialMoney)
74 prevInitialMoney = initialMoney;
80 initialMoney = Math.Max(initialMoney, 0);
82 return TextManager.GetWithVariable(
"campaignstartingmoney",
"[money]",
string.Format(CultureInfo.InvariantCulture,
"{0:N0}", initialMoney));
86 verticalLayout.Recalculate();
108 new GUIMessageBox(TextManager.Get(
"error"), TextManager.Get(
"undefinedsubmarineselected"));
114 new GUIMessageBox(TextManager.Get(
"error"), TextManager.Get(
"nohashsubmarineselected"));
118 string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer,
saveNameBox.
Text);
121 CampaignSettings settings = campaignSettingElements.
CreateSettings();
125 if (!hasRequiredContentPackages)
127 var msgBox =
new GUIMessageBox(TextManager.Get(
"ContentPackageMismatch"),
128 TextManager.GetWithVariable(
"ContentPackageMismatchWarning",
"[requiredcontentpackages]",
string.Join(
", ", selectedSub.
RequiredContentPackages)),
129 new LocalizedString[] { TextManager.Get(
"Yes"), TextManager.Get(
"No") });
131 msgBox.Buttons[0].OnClicked = msgBox.Close;
132 msgBox.Buttons[0].OnClicked += (button, obj) =>
136 StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
137 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
142 msgBox.Buttons[1].OnClicked = msgBox.Close;
147 var msgBox =
new GUIMessageBox(TextManager.Get(
"ShuttleSelected"),
148 TextManager.Get(
"ShuttleWarning"),
149 new LocalizedString[] { TextManager.Get(
"Yes"), TextManager.Get(
"No") });
151 msgBox.Buttons[0].OnClicked = (button, obj) =>
153 StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
154 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
157 msgBox.Buttons[0].OnClicked += msgBox.Close;
159 msgBox.Buttons[1].OnClicked = msgBox.Close;
165 StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
166 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
172 private IEnumerable<CoroutineStatus> WaitForCampaignSetup()
174 GUI.SetCursorWaiting();
175 var headerText = TextManager.Get(
"CampaignStartingPleaseWait");
178 msgBox.Buttons[0].OnClicked = (btn, userdata) =>
182 GUI.ClearCursorWait();
183 CoroutineManager.StopCoroutines(
"WaitForCampaignSetup");
186 msgBox.Buttons[0].OnClicked += msgBox.Close;
188 DateTime timeOut = DateTime.Now +
new TimeSpan(0, 0, 20);
189 while (Screen.Selected != GameMain.GameScreen && DateTime.Now < timeOut)
191 msgBox.Header.Text = headerText +
new string(
'.', (
int)Timing.TotalTime % 3 + 1);
192 yield
return CoroutineStatus.Running;
195 GUI.ClearCursorWait();
196 yield
return CoroutineStatus.Success;
199 public override void CreateLoadMenu(IEnumerable<CampaignMode.SaveInfo> saveFiles =
null)
203 loadGameContainer.ClearChildren();
205 if (saveFiles ==
null)
207 saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
213 RelativeSpacing = 0.03f
218 PlaySoundOnSelect =
true,
219 OnSelected = SelectSaveFile
231 OnClicked = (btn, obj) =>
234 if (
string.IsNullOrWhiteSpace(saveInfo.FilePath)) {
return false; }
235 LoadGame?.Invoke(saveInfo.FilePath);
237 CoroutineManager.StartCoroutine(WaitForCampaignSetup(),
"WaitForCampaignSetup");
243 TextManager.Get(
"Delete"), style:
"GUIButtonSmall")
251 private bool SelectSaveFile(
GUIComponent component,
object obj)
253 if (obj is not
CampaignMode.SaveInfo saveInfo) {
return true; }
254 string fileName = saveInfo.FilePath;
257 deleteMpSaveButton.
Visible = deleteMpSaveButton.
Enabled = GameMain.Client.IsServerOwner;
258 deleteMpSaveButton.
Enabled = GameMain.GameSession?.SavePath != fileName;
259 if (deleteMpSaveButton.
Visible)
261 deleteMpSaveButton.
UserData = saveInfo;
Action< string > LoadGame
readonly GUIComponent newGameContainer
GUITextBlock InitialMoneyText
GUIComponent CreateSaveElement(CampaignMode.SaveInfo saveInfo)
Action< SubmarineInfo, string, string, CampaignSettings > StartNewGame
static CampaignSettingElements CreateCampaignSettingList(GUIComponent parent, CampaignSettings prevSettings, bool isSinglePlayer)
List< CampaignMode.SaveInfo > prevSaveFiles
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)
MultiPlayerCampaignSetupUI(GUIComponent newGameContainer, GUIComponent loadGameContainer, List< CampaignMode.SaveInfo > saveFiles=null)
override void CreateLoadMenu(IEnumerable< CampaignMode.SaveInfo > saveFiles=null)
void HighlightMode(int modeIndex)
void SelectMode(int modeIndex)
SubmarineInfo SelectedSub
void RefreshEnabledElements()
HashSet< string > RequiredContentPackages
SubmarineClass SubmarineClass
bool HasTag(SubmarineTag tag)
bool RequiredContentPackagesInstalled
SettingValue< StartingBalanceAmountOption > StartingFunds
readonly CampaignSettings CreateSettings()