2 using System.Collections.Generic;
3 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
6 using Microsoft.Xna.Framework.Input;
13 private const int submarinesPerPage = 4;
14 private int currentPage = 1;
15 private int pageCount;
16 private readonly
bool transferService, purchaseService;
17 private bool initialized;
20 private GUIFrame pageIndicatorHolder;
22 private GUILayoutGroup submarineHorizontalGroup, submarineControlsGroup;
23 private GUIButton browseLeftButton, browseRightButton, confirmButton, confirmButtonAlt;
27 private int selectionIndicatorThickness;
32 private readonly List<SubmarineInfo> subsToShow;
33 private readonly SubmarineDisplayContent[] submarineDisplays =
new SubmarineDisplayContent[submarinesPerPage];
35 private LocalizedString purchaseAndSwitchText, purchaseOnlyText, selectedSubText, switchText, missingPreviewText, currencyName;
37 private readonly Action closeAction;
38 private Sprite pageIndicator;
44 private static readonly Color indicatorColor =
new Color(112, 149, 129);
45 private Point createdForResolution;
47 private PlayerBalanceElement? playerBalanceElement;
49 private struct SubmarineDisplayContent
63 private bool TransferItemsOnSwitch
67 return transferItemsOnSwitch;
71 transferItemsOnSwitch = value;
72 if (transferItemsTickBox !=
null)
74 transferItemsTickBox.
Selected = value;
78 private bool transferItemsOnSwitch =
true;
84 transferService = transfer;
85 purchaseService = !transfer;
87 this.closeAction = closeAction;
89 subsToShow =
new List<SubmarineInfo>();
93 messageBoxOptions =
new LocalizedString[2] { TextManager.Get(
"Yes"), TextManager.Get(
"Cancel") };
97 messageBoxOptions =
new LocalizedString[2] { TextManager.Get(
"Yes") +
" " + TextManager.Get(
"initiatevoting"), TextManager.Get(
"Cancel") };
104 private void Initialize()
107 selectedSubText = TextManager.Get(
"selectedsub");
108 switchText = TextManager.Get(
"switchtosubmarinebutton");
109 purchaseAndSwitchText = TextManager.Get(
"purchaseandswitch");
110 purchaseOnlyText = TextManager.Get(
"purchase");
112 currencyName = TextManager.Get(
"credit").
Value.ToLowerInvariant();
115 missingPreviewText = TextManager.Get(
"SubPreviewImageNotFound");
119 private void CreateGUI()
121 createdForResolution =
new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
123 GUILayoutGroup content;
124 GuiFrame =
new GUIFrame(
new RectTransform(
new Vector2(0.75f, 0.7f), parent,
Anchor.TopCenter,
Pivot.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) });
125 selectionIndicatorThickness = HUDLayoutSettings.Padding / 2;
132 content =
new GUILayoutGroup(
new RectTransform(
new Point(background.Rect.Width - HUDLayoutSettings.Padding * 4, background.Rect.Height - HUDLayoutSettings.Padding * 4), background.RectTransform,
Anchor.Center)) { AbsoluteSpacing = (int)(HUDLayoutSettings.Padding * 1.5f) };
133 GUITextBlock header =
new GUITextBlock(
new RectTransform(
new Vector2(1f, 0.0f), content.RectTransform), transferService ? TextManager.Get(
"switchsubmarineheader") : TextManager.GetWithVariable(
"outpostshipyard",
"[location]", GameMain.GameSession.Map.CurrentLocation.DisplayName), font: GUIStyle.LargeFont);
134 header.CalculateHeightFromText(0,
true);
135 playerBalanceElement = CampaignUI.AddBalanceElement(header,
new Vector2(1.0f, 1.5f));
137 new GUIFrame(
new RectTransform(
new Vector2(1.0f, 0.01f), content.RectTransform), style:
"HorizontalLine");
139 GUILayoutGroup submarineContentGroup =
new GUILayoutGroup(
new RectTransform(
new Vector2(1f, 0.4f), content.RectTransform)) { AbsoluteSpacing = HUDLayoutSettings.Padding, Stretch =
true };
140 submarineHorizontalGroup =
new GUILayoutGroup(
new RectTransform(
new Vector2(1f, 0.9f), submarineContentGroup.RectTransform)) { IsHorizontal =
true, AbsoluteSpacing = HUDLayoutSettings.Padding, Stretch =
true };
142 submarineControlsGroup =
new GUILayoutGroup(
new RectTransform(
new Vector2(1f, 0.1f), submarineContentGroup.RectTransform),
true,
Anchor.TopCenter);
144 GUILayoutGroup infoFrame =
new GUILayoutGroup(
new RectTransform(
new Vector2(1f, 0.4f), content.RectTransform)) { IsHorizontal =
true, Stretch =
true, AbsoluteSpacing = HUDLayoutSettings.Padding };
145 new GUIFrame(
new RectTransform(Vector2.One, infoFrame.RectTransform), style:
null,
new Color(8, 13, 19)) { IgnoreLayoutGroups =
true };
146 listBackground =
new GUIImage(
new RectTransform(
new Vector2(0.59f, 1f), infoFrame.RectTransform,
Anchor.CenterRight), style:
null,
true)
148 IgnoreLayoutGroups =
true
150 new GUIListBox(
new RectTransform(Vector2.One, infoFrame.RectTransform)) { IgnoreLayoutGroups =
true, CanBeFocused =
false };
151 specsFrame =
new GUIListBox(
new RectTransform(
new Vector2(0.39f, 1f), infoFrame.RectTransform), style:
null)
153 CurrentSelectMode = GUIListBox.
SelectMode.None,
154 Spacing = GUI.IntScale(5),
155 Padding =
new Vector4(HUDLayoutSettings.Padding / 2f, HUDLayoutSettings.Padding, 0, 0)
157 new GUIFrame(
new RectTransform(
new Vector2(0.02f, 0.8f), infoFrame.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.1f) }, style:
"VerticalLine");
158 GUIListBox descriptionFrame =
new GUIListBox(
new RectTransform(
new Vector2(0.59f, 1f), infoFrame.RectTransform), style:
null) { Padding =
new Vector4(HUDLayoutSettings.Padding / 2f, HUDLayoutSettings.Padding * 1.5f, HUDLayoutSettings.Padding * 1.5f, HUDLayoutSettings.Padding / 2f) };
159 descriptionTextBlock =
new GUITextBlock(
new RectTransform(
new Vector2(1, 0), descriptionFrame.Content.RectTransform),
string.Empty, font: GUIStyle.Font, wrap:
true) { CanBeFocused =
false };
161 GUILayoutGroup bottomContainer =
new GUILayoutGroup(
new RectTransform(
new Vector2(1.0f, 0.075f), content.RectTransform,
Anchor.CenterRight), childAnchor:
Anchor.CenterRight) { IsHorizontal =
true, AbsoluteSpacing = HUDLayoutSettings.
Padding };
162 float transferInfoFrameWidth = 1.0f;
164 if (closeAction !=
null)
166 GUIButton closeButton =
new GUIButton(
new RectTransform(
new Vector2(0.2f, 1f), bottomContainer.RectTransform), TextManager.Get(
"Close"), style:
"GUIButtonFreeScale")
168 OnClicked = (button, userData) =>
174 transferInfoFrameWidth -= closeButton.RectTransform.RelativeSize.X;
179 confirmButtonAlt =
new GUIButton(
new RectTransform(
new Vector2(0.2f, 1f), bottomContainer.RectTransform), purchaseOnlyText, style:
"GUIButtonFreeScale");
182 confirmButton =
new GUIButton(
new RectTransform(
new Vector2(0.2f, 1f), bottomContainer.RectTransform), purchaseService ? purchaseAndSwitchText : switchText, style:
"GUIButtonFreeScale");
183 SetConfirmButtonState(
false);
185 GUIFrame transferInfoFrame =
new GUIFrame(
new RectTransform(
new Vector2(transferInfoFrameWidth, 1.0f), bottomContainer.RectTransform), style:
null)
189 transferItemsTickBox =
new GUITickBox(
new RectTransform(
new Vector2(0.2f, 1.0f), transferInfoFrame.RectTransform,
Anchor.CenterRight), TextManager.Get(
"transferitems"), font: GUIStyle.SubHeadingFont)
193 OnSelected = (tb) => transferItemsOnSwitch = tb.Selected
196 itemTransferInfoBlock =
new GUITextBlock(
new RectTransform(Vector2.One, transferInfoFrame.RectTransform,
Anchor.CenterRight),
null, wrap:
true)
198 TextAlignment = Alignment.CenterRight,
202 pageIndicatorHolder =
new GUIFrame(
new RectTransform(
new Vector2(1f, 1.5f), submarineControlsGroup.
RectTransform), style:
null);
203 pageIndicator = GUIStyle.GetComponentStyle(
"GUIPageIndicator").GetDefaultSprite();
206 for (
int i = 0; i < submarineDisplays.Length; i++)
208 SubmarineDisplayContent submarineDisplayElement =
new SubmarineDisplayContent
210 background =
new GUIFrame(
new RectTransform(
new Vector2(1f / submarinesPerPage, 1f), submarineHorizontalGroup.
RectTransform), style:
null,
new Color(8, 13, 19))
212 submarineDisplayElement.submarineImage =
new GUIImage(
new RectTransform(
new Vector2(0.8f, 1f), submarineDisplayElement.background.RectTransform,
Anchor.Center),
null,
true);
213 submarineDisplayElement.middleTextBlock =
new GUITextBlock(
new RectTransform(
new Vector2(0.8f, 1f), submarineDisplayElement.background.RectTransform,
Anchor.Center),
string.Empty, textAlignment: Alignment.Center);
214 submarineDisplayElement.submarineName =
new GUITextBlock(
new RectTransform(
new Vector2(1f, 0.1f), submarineDisplayElement.background.RectTransform,
Anchor.TopCenter) { AbsoluteOffset = new Point(0, HUDLayoutSettings.Padding) },
string.Empty, textAlignment: Alignment.Center, font: GUIStyle.SubHeadingFont);
215 submarineDisplayElement.submarineFee =
new GUITextBlock(
new RectTransform(
new Vector2(1f, 0.1f), submarineDisplayElement.background.RectTransform,
Anchor.BottomCenter) { AbsoluteOffset = new Point(0, HUDLayoutSettings.Padding) },
string.Empty, textAlignment: Alignment.Center, font: GUIStyle.SubHeadingFont);
216 submarineDisplayElement.selectSubmarineButton =
new GUIButton(
new RectTransform(Vector2.One, submarineDisplayElement.background.RectTransform), style:
null);
217 submarineDisplayElement.previewButton =
new GUIButton(
new RectTransform(Vector2.One * 0.12f, submarineDisplayElement.background.RectTransform, anchor:
Anchor.BottomRight, scaleBasis:
ScaleBasis.BothHeight) { AbsoluteOffset = new Point((int)(0.03f * background.Rect.Height)) }, style:
"ExpandButton")
220 HoverColor = Color.White,
221 PressedColor = Color.White
223 submarineDisplayElement.submarineClass =
new GUITextBlock(
new RectTransform(
new Vector2(1f, 0.1f), submarineDisplayElement.background.RectTransform,
Anchor.TopCenter) { AbsoluteOffset = new Point(0, HUDLayoutSettings.Padding + (int)GUIStyle.Font.MeasureString(submarineDisplayElement.submarineName.Text).Y) },
string.Empty, textAlignment: Alignment.Left);
224 submarineDisplayElement.submarineTier =
new GUITextBlock(
new RectTransform(
new Vector2(0.5f, 0.1f), submarineDisplayElement.background.RectTransform,
Anchor.TopRight) { AbsoluteOffset = new Point(0, HUDLayoutSettings.Padding + (int)GUIStyle.Font.MeasureString(submarineDisplayElement.submarineName.Text).Y) },
string.Empty, textAlignment: Alignment.Right);
226 submarineDisplays[i] = submarineDisplayElement;
229 selectedSubmarineIndicator =
new GUICustomComponent(
new RectTransform(Point.Zero, submarineHorizontalGroup.
RectTransform), onDraw: (sb, component) => DrawSubmarineIndicator(sb, component.Rect)) { IgnoreLayoutGroups =
true, CanBeFocused =
false };
232 private void UpdatePaging()
234 if (pageIndicatorHolder ==
null)
return;
236 if (currentPage > pageCount) currentPage = pageCount;
237 if (pageCount < 2)
return;
239 browseLeftButton =
new GUIButton(
new RectTransform(
new Vector2(1.15f, 1.15f), pageIndicatorHolder.
RectTransform,
Anchor.CenterLeft,
Pivot.CenterRight) { AbsoluteOffset = new Point(-HUDLayoutSettings.Padding * 3, 0) },
string.Empty, style:
"GUIButtonToggleLeft")
241 IgnoreLayoutGroups =
true,
242 OnClicked = (button, userData) =>
249 Point indicatorSize =
new Point(GUI.IntScale(pageIndicator.
SourceRect.Width * 1.5f), GUI.IntScale(pageIndicator.
SourceRect.Height * 1.5f));
253 int yPos = pageIndicatorHolder.
Rect.Height / 2 - indicatorSize.Y / 2;
255 pageIndicators =
new GUIImage[pageCount];
256 for (
int i = 0; i < pageCount; i++)
258 pageIndicators[i] =
new GUIImage(
new RectTransform(indicatorSize, pageIndicatorHolder.
RectTransform) { AbsoluteOffset = new Point(xPos, yPos) }, pageIndicator,
null,
true);
259 xPos += indicatorSize.X + HUDLayoutSettings.Padding;
262 for (
int i = 0; i < pageIndicators.Length; i++)
264 pageIndicators[i].
Color = i == currentPage - 1 ? Color.White : Color.Gray;
267 browseRightButton =
new GUIButton(
new RectTransform(
new Vector2(1.15f, 1.15f), pageIndicatorHolder.
RectTransform,
Anchor.CenterRight,
Pivot.CenterLeft) { AbsoluteOffset = new Point(-HUDLayoutSettings.Padding * 3, 0) },
string.Empty, style:
"GUIButtonToggleRight")
269 IgnoreLayoutGroups =
true,
270 OnClicked = (button, userData) =>
277 browseLeftButton.
Enabled = currentPage > 1;
278 browseRightButton.
Enabled = currentPage < pageCount;
281 private void DrawSubmarineIndicator(SpriteBatch spriteBatch, Rectangle area)
284 GUI.DrawRectangle(spriteBatch, area, indicatorColor, thickness: selectionIndicatorThickness);
301 SelectSubmarine(subsToShow.IndexOf(selectedSubmarine), -1);
305 SelectSubmarine(subsToShow.IndexOf(selectedSubmarine), 1);
323 if (setTransferOptionToTrue)
325 TransferItemsOnSwitch =
true;
332 if (pageIndicators !=
null)
334 for (
int i = 0; i < pageIndicators.Length; i++)
336 pageIndicators[i].
Color = i == currentPage - 1 ? Color.White : Color.Gray;
340 int submarineIndex = (currentPage - 1) * submarinesPerPage;
342 for (
int i = 0; i < submarineDisplays.Length; i++)
344 SubmarineInfo subToDisplay = GetSubToDisplay(submarineIndex);
345 if (subToDisplay ==
null)
347 submarineDisplays[i].submarineImage.Sprite =
null;
348 submarineDisplays[i].submarineName.Text =
string.Empty;
349 submarineDisplays[i].submarineFee.Text =
string.Empty;
350 submarineDisplays[i].submarineClass.Text =
string.Empty;
351 submarineDisplays[i].submarineTier.Text =
string.Empty;
352 submarineDisplays[i].selectSubmarineButton.Enabled =
false;
353 submarineDisplays[i].selectSubmarineButton.OnClicked =
null;
354 submarineDisplays[i].displayedSubmarine =
null;
355 submarineDisplays[i].middleTextBlock.AutoDraw =
false;
356 submarineDisplays[i].previewButton.Visible =
false;
360 submarineDisplays[i].displayedSubmarine = subToDisplay;
361 Sprite previewImage = GetPreviewImage(subToDisplay);
363 if (previewImage !=
null)
365 submarineDisplays[i].submarineImage.Sprite = previewImage;
366 submarineDisplays[i].middleTextBlock.AutoDraw =
false;
370 submarineDisplays[i].submarineImage.
Sprite =
null;
371 submarineDisplays[i].middleTextBlock.Text = missingPreviewText;
372 submarineDisplays[i].middleTextBlock.AutoDraw =
true;
375 submarineDisplays[i].selectSubmarineButton.Enabled =
true;
378 submarineDisplays[i].selectSubmarineButton.OnClicked = (button, userData) =>
380 SelectSubmarine(subToDisplay, submarineDisplays[index].background.Rect);
384 submarineDisplays[i].submarineName.Text = subToDisplay.
DisplayName;
386 submarineDisplays[i].submarineClass.Text = TextManager.GetWithVariable(
"submarineclass.classsuffixformat",
"[type]", TextManager.Get($
"submarineclass.{subToDisplay.SubmarineClass}"));
387 submarineDisplays[i].submarineClass.ToolTip = TextManager.Get(
"submarineclass.description") +
"\n\n" + TextManager.Get($
"submarineclass.{subToDisplay.SubmarineClass}.description");
389 submarineDisplays[i].submarineTier.Text = TextManager.Get($
"submarinetier.{subToDisplay.Tier}");
390 submarineDisplays[i].submarineTier.ToolTip = TextManager.Get(
"submarinetier.description");
395 submarineDisplays[i].submarineFee.Text = TextManager.GetWithVariable(
"price",
"[amount]", amountString);
401 submarineDisplays[i].submarineFee.Text =
string.Empty;
405 submarineDisplays[i].submarineFee.Text = selectedSubText;
411 if (selectedSubmarine ==
null)
413 CoroutineManager.StartCoroutine(SelectOwnSubmarineWithDelay(subToDisplay, submarineDisplays[i]));
417 SelectSubmarine(subToDisplay, submarineDisplays[i].background.Rect);
420 else if (!transferService && selectedSubmarine ==
null || !transferService &&
GameMain.
GameSession.
IsSubmarineOwned(selectedSubmarine) || subToDisplay == selectedSubmarine)
422 SelectSubmarine(subToDisplay, submarineDisplays[i].background.Rect);
425 submarineDisplays[i].previewButton.Visible =
true;
426 submarineDisplays[i].previewButton.OnClicked = (btn, obj) =>
436 if (subsToShow.Count == 0)
442 UpdateItemTransferInfoFrame();
446 private void UpdateSubmarines()
452 subsToShow.Sort(ComparePrice);
454 int currentIndex = subsToShow.FindIndex(s => s.Name == currentSubName);
455 if (currentIndex != -1)
457 currentPage = (int)Math.Ceiling((currentIndex + 1) / (float)submarinesPerPage);
462 subsToShow.AddRange((GameMain.Client is
null ? SubmarineInfo.SavedSubmarines : MultiPlayerCampaign.GetCampaignSubs())
463 .Where(s => s.IsCampaignCompatible && !GameMain.GameSession.OwnedSubmarines.Any(os => os.Name == s.Name)));
464 if (GameMain.GameSession.Campaign?.Map?.CurrentLocation is Location currentLocation)
466 subsToShow.RemoveAll(sub => !currentLocation.IsSubmarineAvailable(sub));
468 subsToShow.Sort(ComparePrice);
476 pageCount = Math.Max(1, (
int)Math.Ceiling(subsToShow.Count / (
float)submarinesPerPage));
480 static int ComparePrice(SubmarineInfo x, SubmarineInfo y)
482 return x.Price.CompareTo(y.Price) * 100 + x.Name.CompareTo(y.Name);
486 private SubmarineInfo GetSubToDisplay(
int index)
488 if (subsToShow.Count <= index || index < 0) {
return null; }
489 return subsToShow[index];
492 private Sprite GetPreviewImage(SubmarineInfo info)
494 Sprite preview = info.PreviewImage;
498 SubmarineInfo potentialMatch = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.EqualityCheckVal == info.EqualityCheckVal);
500 preview = potentialMatch?.PreviewImage;
505 potentialMatch = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == info.Name);
506 preview = potentialMatch?.PreviewImage;
514 private IEnumerable<CoroutineStatus> SelectOwnSubmarineWithDelay(SubmarineInfo info, SubmarineDisplayContent display)
516 yield
return new WaitForSeconds(0.05f);
517 SelectSubmarine(info, display.background.Rect);
521 private void SelectSubmarine(
int index,
int direction)
523 SubmarineInfo nextSub = GetSubToDisplay(index + direction);
524 if (nextSub ==
null)
return;
526 for (
int i = 0; i < submarineDisplays.Length; i++)
528 if (submarineDisplays[i].displayedSubmarine == nextSub)
530 SelectSubmarine(nextSub, submarineDisplays[i].background.Rect);
535 ChangePage(direction);
537 for (
int i = 0; i < submarineDisplays.Length; i++)
539 if (submarineDisplays[i].displayedSubmarine == nextSub)
541 SelectSubmarine(nextSub, submarineDisplays[i].background.Rect);
547 private void SelectSubmarine(SubmarineInfo info, Rectangle backgroundRect)
550 if (selectedSubmarine == info)
return;
553 selectedSubmarine = info;
557 bool owned = GameMain.GameSession.IsSubmarineOwned(info);
561 confirmButton.
Text = switchText;
562 confirmButton.
OnClicked = (button, userData) =>
564 ShowTransferPrompt();
570 confirmButton.
Text = purchaseAndSwitchText;
571 confirmButton.
OnClicked = (button, userData) =>
573 ShowBuyPrompt(
false);
577 confirmButtonAlt.
Text = purchaseOnlyText;
578 confirmButtonAlt.
OnClicked = (button, userData) =>
590 Sprite previewImage = GetPreviewImage(info);
591 listBackground.
Sprite = previewImage;
594 GUIFont font = GUIStyle.Font;
595 info.CreateSpecsWindow(specsFrame, font, includeCrushDepth:
true);
596 descriptionTextBlock.
Text = info.Description;
601 listBackground.
Sprite =
null;
603 descriptionTextBlock.
Text =
string.Empty;
605 SetConfirmButtonState(
false);
608 UpdateItemTransferInfoFrame();
611 private bool IsSelectedSubCurrentSub =>
Submarine.MainSub?.Info?.Name == selectedSubmarine?.
Name;
613 private void UpdateItemTransferInfoFrame()
615 if (selectedSubmarine !=
null)
617 if (IsSelectedSubCurrentSub)
619 TransferItemsOnSwitch =
false;
620 transferItemsTickBox.
Visible =
false;
622 itemTransferInfoBlock.
Text = TextManager.Get(
"switchingbacktocurrentsub");
624 else if (GameMain.GameSession?.Campaign?.PendingSubmarineSwitch?.Name == selectedSubmarine.
Name)
626 transferItemsTickBox.
Visible =
false;
627 itemTransferInfoBlock.
Visible =
true;
628 itemTransferInfoBlock.
Text = GameMain.GameSession.Campaign.TransferItemsOnSubSwitch ? TextManager.Get(
"itemtransferenabledreminder") : TextManager.Get(
"itemtransferdisabledreminder");
632 transferItemsTickBox.
Selected = TransferItemsOnSwitch;
633 transferItemsTickBox.
Visible =
true;
634 itemTransferInfoBlock.
Visible =
false;
639 transferItemsTickBox.
Visible =
false;
640 itemTransferInfoBlock.
Visible =
false;
644 private void SetConfirmButtonState(
bool state)
646 if (confirmButtonAlt !=
null)
648 confirmButtonAlt.
Enabled = state;
651 if (confirmButton !=
null)
669 private void ChangePage(
int pageChangeDirection)
672 if (pageChangeDirection < 0 && currentPage > 1) currentPage--;
673 if (pageChangeDirection > 0 && currentPage < pageCount) currentPage++;
674 browseLeftButton.
Enabled = currentPage > 1;
675 browseRightButton.
Enabled = currentPage < pageCount;
680 private void ShowTransferPrompt()
682 var text = TextManager.GetWithVariables(
"switchsubmarinetext",
684 (
"[submarinename2]", selectedSubmarine.
DisplayName));
685 text += GetItemTransferText();
686 GUIMessageBox msgBox =
new GUIMessageBox(TextManager.Get(
"switchsubmarineheader"), text, messageBoxOptions);
689 msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
691 if (!TransferItemsOnSwitch && !IsSelectedSubCurrentSub)
695 return ShowConfirmationPopup(TextManager.Get(
"noitemsheader"), TextManager.Get(
"noitemswarning"));
697 if (!GameMain.GameSession.IsSubmarineOwned(selectedSubmarine) && !selectedSubmarine.
IsManuallyOutfitted)
699 var (header, body) = GetItemTransferWarningText();
700 return ShowConfirmationPopup(header, body);
704 return ShowConfirmationPopup(TextManager.Get(
"lowfuelheader"), TextManager.Get(
"lowfuelwarning"));
709 msgBox.Buttons[0].OnClicked += msgBox.Close;
710 msgBox.Buttons[1].OnClicked = msgBox.Close;
712 bool ShowConfirmationPopup(LocalizedString header, LocalizedString textBody)
715 var extraConfirmationBox =
new GUIMessageBox(header, textBody,
new LocalizedString[2] { TextManager.Get(
"ok"), TextManager.Get(
"cancel") });
716 extraConfirmationBox.Buttons[0].OnClicked = (b, o) => Confirm();
717 extraConfirmationBox.Buttons[1].OnClicked = (b, o) =>
723 extraConfirmationBox.Buttons[0].OnClicked += extraConfirmationBox.Close;
724 extraConfirmationBox.Buttons[1].OnClicked += extraConfirmationBox.Close;
730 if (GameMain.Client ==
null)
732 GameMain.GameSession.SwitchSubmarine(selectedSubmarine, TransferItemsOnSwitch);
737 GameMain.Client.InitiateSubmarineChange(selectedSubmarine, TransferItemsOnSwitch, Networking.VoteType.SwitchSub);
743 private (LocalizedString header, LocalizedString body) GetItemTransferWarningText()
745 var header = TextManager.Get(
"itemtransferheader").Fallback(TextManager.Get(
"lowfuelheader"), useDefaultLanguageIfFound:
false);
746 var body = TextManager.Get(
"itemtransferwarning").Fallback(TextManager.Get(
"lowfuelwarning"), useDefaultLanguageIfFound:
false);
747 return (header, body);
750 private void ShowBuyPrompt(
bool purchaseOnly)
752 int price = selectedSubmarine.
GetPrice();
754 if (!GameMain.GameSession.Campaign.CanAfford(price))
756 new GUIMessageBox(TextManager.Get(
"purchasesubmarineheader"), TextManager.GetWithVariables(
"notenoughmoneyforpurchasetext",
757 (
"[currencyname]", currencyName),
758 (
"[submarinename]", selectedSubmarine.
DisplayName)));
762 GUIMessageBox msgBox;
765 var text = TextManager.GetWithVariables(
"purchaseandswitchsubmarinetext",
766 (
"[submarinename1]", selectedSubmarine.
DisplayName),
767 (
"[amount]", price.ToString()),
768 (
"[currencyname]", currencyName),
770 text += GetItemTransferText();
771 msgBox =
new GUIMessageBox(TextManager.Get(
"purchaseandswitchsubmarineheader"), text, messageBoxOptions);
773 msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
775 if (!TransferItemsOnSwitch && !IsSelectedSubCurrentSub)
779 ShowConfirmationPopup(TextManager.Get(
"noitemsheader"), TextManager.Get(
"noitemswarning"));
782 if (!GameMain.GameSession.IsSubmarineOwned(selectedSubmarine) && !selectedSubmarine.
IsManuallyOutfitted)
784 var (header, body) = GetItemTransferWarningText();
785 ShowConfirmationPopup(header, body);
790 ShowConfirmationPopup(TextManager.Get(
"lowfuelheader"), TextManager.Get(
"lowfuelwarning"));
797 void ShowConfirmationPopup(LocalizedString header, LocalizedString textBody)
800 var extraConfirmationBox =
new GUIMessageBox(header, textBody,
new LocalizedString[2] { TextManager.Get(
"ok"), TextManager.Get(
"cancel") });
801 extraConfirmationBox.Buttons[0].OnClicked = (b, o) => Confirm();
802 extraConfirmationBox.Buttons[0].OnClicked += extraConfirmationBox.Close;
803 extraConfirmationBox.Buttons[1].OnClicked += extraConfirmationBox.Close;
808 if (GameMain.Client ==
null)
810 if (GameMain.GameSession.TryPurchaseSubmarine(selectedSubmarine))
812 GameMain.GameSession.SwitchSubmarine(selectedSubmarine, TransferItemsOnSwitch);
818 GameMain.Client.InitiateSubmarineChange(selectedSubmarine, TransferItemsOnSwitch, Networking.VoteType.PurchaseAndSwitchSub);
825 msgBox =
new GUIMessageBox(TextManager.Get(
"purchasesubmarineheader"), TextManager.GetWithVariables(
"purchasesubmarinetext",
826 (
"[submarinename]", selectedSubmarine.
DisplayName),
827 (
"[amount]", price.ToString()),
828 (
"[currencyname]", currencyName)) +
'\n' + TextManager.Get(
"submarineswitchinstruction"), messageBoxOptions);
830 msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
832 if (GameMain.Client ==
null)
834 GameMain.GameSession.TryPurchaseSubmarine(selectedSubmarine);
839 GameMain.Client.InitiateSubmarineChange(selectedSubmarine,
false, Networking.VoteType.PurchaseSub);
845 msgBox.Buttons[0].ClickSound =
GUISoundType.ConfirmTransaction;
846 msgBox.Buttons[0].OnClicked += msgBox.Close;
847 msgBox.Buttons[1].OnClicked = msgBox.Close;
850 private LocalizedString GetItemTransferText()
854 return $
"\n\n{TextManager.Get("switchingbacktocurrentsub
")}";
856 var s =
"\n\n" + TextManager.Get(TransferItemsOnSwitch ?
"itemswillbetransferred" :
"itemswontbetransferred");
857 s += $
" {TextManager.Get("toggleitemtransferprompt
")}";
SubmarineInfo PendingSubmarineSwitch
static ? PlayerBalanceElement UpdateBalanceElement(PlayerBalanceElement? playerBalanceElement)
virtual void ClearChildren()
RectTransform RectTransform
GUIComponent that can be used to render custom content on the UI
void SetCrop(bool state, bool center=true)
GUIFrame Content
A frame that contains the contents of the listbox. The frame itself is not rendered.
void CalculateHeightFromText(int padding=0, bool removeExtraSpacing=false)
static GameSession?? GameSession
static int GraphicsHeight
List< SubmarineInfo > OwnedSubmarines
bool IsSubmarineOwned(SubmarineInfo query)
Sprite(ContentXElement element, string path="", string file="", bool lazyLoad=false, float sourceRectScale=1)
static Submarine MainSub
Note that this can be null in some situations, e.g. editors and missions that don't load a submarine.
LocalizedString DisplayName
int GetPrice(Location location=null, ImmutableHashSet< Character > characterList=null)
bool LowFuel
Note: Refreshed for loaded submarines when they are saved, when they are loaded, and on round end....
static void Create(SubmarineInfo submarineInfo)
SubmarineSelection(bool transfer, Action closeAction, RectTransform parent)
void RefreshSubmarineDisplay(bool updateSubs, bool setTransferOptionToTrue=false)
static bool ContentRefreshRequired
static SubmarineInfo CurrentOrPendingSubmarine()