1 using Microsoft.Xna.Framework;
3 using System.Globalization;
8 partial class SubmarineInfo : IDisposable
12 partial
void InitProjectSpecific()
14 string previewImageData =
SubmarineElement.GetAttributeString(
"previewimage",
"");
15 if (!
string.IsNullOrEmpty(previewImageData))
19 using (System.IO.MemoryStream mem =
new System.IO.MemoryStream(Convert.FromBase64String(previewImageData)))
21 var texture = TextureLoader.FromStream(mem, path:
FilePath, compress:
false);
22 if (texture ==
null) {
throw new Exception(
"PreviewImage texture returned null"); }
28 DebugConsole.ThrowError(
"Loading the preview image of the submarine \"" +
Name +
"\" failed. The file may be corrupted.", e);
29 GameAnalyticsManager.AddErrorEventOnce(
"Submarine..ctor:PreviewImageLoadingFailed", GameAnalyticsManager.ErrorSeverity.Error,
30 "Loading the preview image of the submarine \"" +
Name +
"\" failed. The file may be corrupted.");
40 var previewButton =
new GUIButton(
new RectTransform(
new Vector2(1f, 0.5f), content.RectTransform), style:
null)
47 if (previewImage ==
null)
53 var submarinePreviewBackground =
new GUIFrame(
new RectTransform(Vector2.One, previewButton.RectTransform), style:
null)
56 HoverColor = Color.Black,
57 SelectedColor = Color.Black,
58 PressedColor = Color.Black,
61 new GUIImage(
new RectTransform(
new Vector2(0.98f), submarinePreviewBackground.RectTransform,
Anchor.Center), previewImage, scaleToFit:
true) { CanBeFocused =
false };
62 new GUIFrame(
new RectTransform(Vector2.One, submarinePreviewBackground.RectTransform),
"InnerGlow", color: Color.Black) { CanBeFocused =
false };
69 AbsoluteOffset = new Point((int)(0.03f * previewButton.Rect.Height))
71 "ExpandButton", Color.White)
74 HoverColor = Color.White,
75 PressedColor = Color.White
81 UserData =
"descriptionbox",
82 ScrollBarVisible =
true,
87 GUIFont font = parent.
Rect.Width < 350 ? GUIStyle.SmallFont : GUIStyle.Font;
93 bool includeTitle =
true,
94 bool includeClass =
true,
95 bool includeDescription =
false,
96 bool includeCrushDepth =
false)
98 float leftPanelWidth = 0.6f;
99 float rightPanelWidth = 0.4f / leftPanelWidth;
101 TextManager.GetWithVariables(
"submarine.classandtier",
102 (
"[class]", TextManager.Get($
"submarineclass.{SubmarineClass}")),
103 (
"[tier]", TextManager.Get($
"submarinetier.{Tier}"))) :
104 TextManager.Get(
"shuttle");
106 int classHeight = (int)GUIStyle.SubHeadingFont.MeasureString(className).Y;
107 int leftPanelWidthInt = (int)(parent.
Rect.Width * leftPanelWidth);
113 int nameHeight = (int)GUIStyle.LargeFont.MeasureString(
DisplayName,
true).Y;
124 ToolTip = TextManager.Get(
"submarinetierandclass.description")+
"\n\n"+ TextManager.Get($
"submarineclass.{SubmarineClass}.description")
126 submarineClassText.
HoverColor = Color.Transparent;
133 TextManager.Get(
"subeditor.price"), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
134 { CanBeFocused =
false };
136 TextManager.GetWithVariable(
"currencyformat",
"[credits]",
string.Format(CultureInfo.InvariantCulture,
"{0:N0}",
Price)), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
137 { CanBeFocused =
false };
140 Vector2 realWorldDimensions =
Dimensions * Physics.DisplayToRealWorldRatio;
141 if (realWorldDimensions != Vector2.Zero)
143 LocalizedString dimensionsStr = TextManager.GetWithVariables(
"DimensionsFormat", (
"[width]", ((
int)realWorldDimensions.X).ToString()), (
"[height]", ((
int)realWorldDimensions.Y).ToString()));
145 TextManager.Get(
"Dimensions"), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
146 { CanBeFocused =
false };
148 dimensionsStr, textAlignment: Alignment.TopLeft, font: font, wrap:
true)
149 { CanBeFocused =
false };
150 dimensionsText.
RectTransform.
MinSize =
new Point(0, dimensionsText.Children.First().Rect.Height);
153 var cargoCapacityStr =
CargoCapacity < 0 ? TextManager.Get(
"unknown") : TextManager.GetWithVariable(
"cargocapacityformat",
"[cratecount]",
CargoCapacity.ToString());
155 TextManager.Get(
"cargocapacity"), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
156 { CanBeFocused =
false };
158 cargoCapacityStr, textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
159 { CanBeFocused =
false };
160 cargoCapacityText.
RectTransform.
MinSize =
new Point(0, cargoCapacityText.Children.First().Rect.Height);
162 if (includeCrushDepth)
165 TextManager.Get(
"CrushDepth"), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
170 TextManager.GetWithVariable(
"meterformat",
"[meters]",
string.Format(CultureInfo.InvariantCulture,
"{0:N0}", GetSubCrushDepth())),
171 textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
175 crushDepthText.
RectTransform.
MinSize =
new Point(0, crushDepthText.Children.First().Rect.Height);
178 if (RecommendedCrewSizeMax > 0)
181 TextManager.Get(
"RecommendedCrewSize"), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
182 { CanBeFocused =
false };
184 RecommendedCrewSizeMin +
" - " + RecommendedCrewSizeMax, textAlignment: Alignment.TopLeft, font: font, wrap:
true)
185 { CanBeFocused =
false };
192 TextManager.Get(
"RecommendedCrewExperience"), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
193 { CanBeFocused =
false };
196 { CanBeFocused =
false };
197 crewExperienceText.
RectTransform.
MinSize =
new Point(0, crewExperienceText.Children.First().Rect.Height);
203 TextManager.Get(
"RequiredContentPackages"), textAlignment: Alignment.
TopLeft, font: font)
204 { CanBeFocused =
false };
207 { CanBeFocused =
false };
208 contentPackagesText.
RectTransform.
MinSize =
new Point(0, contentPackagesText.Children.First().Rect.Height);
215 TextManager.Get(
"serverlistversion"), textAlignment: Alignment.
TopLeft, font: font, wrap:
true)
216 { CanBeFocused =
false };
218 GameVersion.ToString(), textAlignment: Alignment.TopLeft, font: font, wrap:
true)
219 { CanBeFocused =
false };
224 if (submarineNameText !=
null)
230 if (includeDescription)
238 TextManager.Get(
"SaveSubDialogDescription",
"WorkshopItemDescription"), font: GUIStyle.Font, wrap:
true)
253 private float GetSubCrushDepth()
256 return GetSubCrushDepth(
this, ref pendingSubInfo);
266 else if (subInfo !=
null)
268 if (pendingSubInfo.PendingSub != subInfo)
271 pendingSubInfo =
new PendingSubInfo(subInfo, subInfo.IsCrushDepthDefinedInStructures(out
float realWorldCrushDepth), realWorldCrushDepth);
273 subCrushDepth = pendingSubInfo.RealWorldCrushDepth;
280 int currentLevel = 0;
281 if (pendingSubInfo.PendingSub is
null || pendingSubInfo.StructuresDefineRealWorldCrushDepth)
285 if (pendingLevel > currentLevel)
287 string updateValueStr = hullUpgradePrefab.SourceElement?.GetChildElement(
"Structure")?.GetAttributeString(
"crushdepth",
null);
288 if (!
string.IsNullOrEmpty(updateValueStr))
290 if (currentLevel > 0)
293 int upgradePercentage = UpgradePrefab.ParsePercentage(updateValueStr, Identifier.Empty, suppressWarnings:
true);
294 subCrushDepth /= (1f + (upgradePercentage / 100f * currentLevel));
296 subCrushDepth = PropertyReference.CalculateUpgrade(subCrushDepth, pendingLevel, updateValueStr);
300 return subCrushDepth;
UpgradeManager UpgradeManager
IEnumerable< GUIComponent > GetAllChildren()
Returns all child elements in the hierarchy.
RectTransform RectTransform
GUIFrame Content
A frame that contains the contents of the listbox. The frame itself is not rendered.
override void ForceLayoutRecalculation()
bool AutoScaleHorizontal
When enabled, the text is automatically scaled down to fit the textblock horizontally.
static void AutoScaleAndNormalize(params GUITextBlock[] textBlocks)
Set the text scale of the GUITextBlocks so that they all use the same scale and can fit the text with...
static GameSession?? GameSession
const float DefaultRealWorldCrushDepth
float RealWorldCrushDepth
bool IsVanillaSubmarine()
LocalizedString DisplayName
XElement SubmarineElement
CrewExperienceLevel RecommendedCrewExperience
LocalizedString Description
int RecommendedCrewSizeMin
readonly record struct PendingSubInfo(SubmarineInfo PendingSub=null, bool StructuresDefineRealWorldCrushDepth=false, float RealWorldCrushDepth=Level.DefaultRealWorldCrushDepth)
void CreatePreviewWindow(GUIComponent parent)
HashSet< string > RequiredContentPackages
void CreateSpecsWindow(GUIListBox parent, GUIFont font, bool includeTitle=true, bool includeClass=true, bool includeDescription=false, bool includeCrushDepth=false)
static float GetSubCrushDepth(SubmarineInfo subInfo, ref PendingSubInfo pendingSubInfo)
static IEnumerable< SubmarineInfo > SavedSubmarines
bool HasTag(SubmarineTag tag)
static void Create(SubmarineInfo submarineInfo)
int GetUpgradeLevel(UpgradePrefab prefab, UpgradeCategory category, SubmarineInfo? info=null)
Gets the progress that is shown on the store interface. Includes values stored in the metadata and Pe...
int GetRealUpgradeLevelForSub(UpgradePrefab prefab, UpgradeCategory category, SubmarineInfo info)
Gets the level of the upgrade that is stored in the metadata. Takes into account the limits of the pr...