(8814bcb6b) Null checks on GUIStyle fonts
This commit is contained in:
@@ -148,7 +148,7 @@ namespace Barotrauma
|
|||||||
//find the parent GUIListBox highest in the hierarchy
|
//find the parent GUIListBox highest in the hierarchy
|
||||||
for (int i = parentHierarchy.Count - 1; i >= 0; i--)
|
for (int i = parentHierarchy.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (parentHierarchy[i].GUIComponent is GUIListBox) return parentHierarchy[i]?.Parent ?? parentHierarchy[i];
|
if (parentHierarchy[i].GUIComponent is GUIListBox) return parentHierarchy[i];
|
||||||
}
|
}
|
||||||
//or just go with the direct parent if there are no listboxes in the hierarchy
|
//or just go with the direct parent if there are no listboxes in the hierarchy
|
||||||
parentHierarchy.Clear();
|
parentHierarchy.Clear();
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
ToolBox.IsProperFilenameCase(file);
|
ToolBox.IsProperFilenameCase(file);
|
||||||
doc = XDocument.Load(file, LoadOptions.SetBaseUri);
|
doc = XDocument.Load(file, LoadOptions.SetBaseUri);
|
||||||
|
if (doc == null) { throw new Exception("doc is null"); }
|
||||||
|
if (doc.Root == null) { throw new Exception("doc.Root is null"); }
|
||||||
|
if (doc.Root.Elements() == null) { throw new Exception("doc.Root.Elements() is null"); }
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -113,26 +116,34 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private void RescaleFonts()
|
private void RescaleFonts()
|
||||||
{
|
{
|
||||||
|
if (configElement == null) { return; }
|
||||||
|
if (configElement.Elements() == null) { return; }
|
||||||
foreach (XElement subElement in configElement.Elements())
|
foreach (XElement subElement in configElement.Elements())
|
||||||
{
|
{
|
||||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||||
{
|
{
|
||||||
case "font":
|
case "font":
|
||||||
|
if (Font == null) { continue; }
|
||||||
Font.Size = GetFontSize(subElement);
|
Font.Size = GetFontSize(subElement);
|
||||||
break;
|
break;
|
||||||
case "smallfont":
|
case "smallfont":
|
||||||
|
if (SmallFont == null) { continue; }
|
||||||
SmallFont.Size = GetFontSize(subElement);
|
SmallFont.Size = GetFontSize(subElement);
|
||||||
break;
|
break;
|
||||||
case "largefont":
|
case "largefont":
|
||||||
|
if (LargeFont == null) { continue; }
|
||||||
LargeFont.Size = GetFontSize(subElement);
|
LargeFont.Size = GetFontSize(subElement);
|
||||||
break;
|
break;
|
||||||
case "objectivetitle":
|
case "objectivetitle":
|
||||||
|
if (ObjectiveTitleFont == null) { continue; }
|
||||||
ObjectiveTitleFont.Size = GetFontSize(subElement);
|
ObjectiveTitleFont.Size = GetFontSize(subElement);
|
||||||
break;
|
break;
|
||||||
case "objectivename":
|
case "objectivename":
|
||||||
|
if (ObjectiveNameFont == null) { continue; }
|
||||||
ObjectiveNameFont.Size = GetFontSize(subElement);
|
ObjectiveNameFont.Size = GetFontSize(subElement);
|
||||||
break;
|
break;
|
||||||
case "videotitle":
|
case "videotitle":
|
||||||
|
if (VideoTitleFont == null) { continue; }
|
||||||
VideoTitleFont.Size = GetFontSize(subElement);
|
VideoTitleFont.Size = GetFontSize(subElement);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length];
|
tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length];
|
||||||
|
|
||||||
menu = new GUIFrame(new RectTransform(new Vector2(0.85f, 0.8f), GUI.Canvas, Anchor.Center) { MinSize = new Point(GameMain.GraphicsHeight, 0) });
|
menu = new GUIFrame(new RectTransform(new Vector2(0.6f, 0.8f), GUI.Canvas, Anchor.Center) { MinSize = new Point(GameMain.GraphicsHeight, 0) });
|
||||||
|
|
||||||
var container = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.85f), menu.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.05f) }) { Stretch = true };
|
var container = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.85f), menu.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.05f) }) { Stretch = true };
|
||||||
|
|
||||||
@@ -394,7 +394,6 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
IsHorizontal = true,
|
IsHorizontal = true,
|
||||||
Stretch = true,
|
Stretch = true,
|
||||||
RelativeSpacing = 0.05f,
|
|
||||||
CanBeFocused = false
|
CanBeFocused = false
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -406,6 +405,32 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (item.Installed)
|
if (item.Installed)
|
||||||
{
|
{
|
||||||
|
if (listBox != publishedItemList && SteamManager.CheckWorkshopItemEnabled(item) && !SteamManager.CheckWorkshopItemUpToDate(item))
|
||||||
|
{
|
||||||
|
new GUIButton(new RectTransform(new Vector2(0.4f, 0.5f), rightColumn.RectTransform, Anchor.BottomLeft), text: "Update")
|
||||||
|
{
|
||||||
|
UserData = "updatebutton",
|
||||||
|
IgnoreLayoutGroups = true,
|
||||||
|
OnClicked = (btn, userdata) =>
|
||||||
|
{
|
||||||
|
if (SteamManager.UpdateWorkshopItem(item, out string errorMsg))
|
||||||
|
{
|
||||||
|
new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", TextManager.EnsureUTF8(item.Title)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError(errorMsg);
|
||||||
|
new GUIMessageBox(
|
||||||
|
TextManager.Get("Error"),
|
||||||
|
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { TextManager.EnsureUTF8(item.Title), errorMsg }));
|
||||||
|
}
|
||||||
|
btn.Enabled = false;
|
||||||
|
btn.Visible = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
GUITickBox enabledTickBox = null;
|
GUITickBox enabledTickBox = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -451,33 +476,6 @@ namespace Barotrauma
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Rand.Range(0.0f, 1.0f) < 0.5f)//listBox != publishedItemList && SteamManager.CheckWorkshopItemEnabled(item) && !SteamManager.CheckWorkshopItemUpToDate(item))
|
|
||||||
{
|
|
||||||
new GUIButton(new RectTransform(new Vector2(0.4f, 0.5f), rightColumn.RectTransform, Anchor.BottomLeft), text: TextManager.Get("WorkshopItemUpdate"))
|
|
||||||
{
|
|
||||||
UserData = "updatebutton",
|
|
||||||
Font = GUI.SmallFont,
|
|
||||||
OnClicked = (btn, userdata) =>
|
|
||||||
{
|
|
||||||
if (SteamManager.UpdateWorkshopItem(item, out string errorMsg))
|
|
||||||
{
|
|
||||||
new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", TextManager.EnsureUTF8(item.Title)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DebugConsole.ThrowError(errorMsg);
|
|
||||||
new GUIMessageBox(
|
|
||||||
TextManager.Get("Error"),
|
|
||||||
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { TextManager.EnsureUTF8(item.Title), errorMsg }));
|
|
||||||
}
|
|
||||||
btn.Enabled = false;
|
|
||||||
btn.Visible = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (item.Downloading)
|
else if (item.Downloading)
|
||||||
{
|
{
|
||||||
@@ -902,7 +900,7 @@ namespace Barotrauma
|
|||||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), topRightColumn.RectTransform), TextManager.Get("WorkshopItemDescription"));
|
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), topRightColumn.RectTransform), TextManager.Get("WorkshopItemDescription"));
|
||||||
|
|
||||||
var descriptionContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.4f), topRightColumn.RectTransform));
|
var descriptionContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.4f), topRightColumn.RectTransform));
|
||||||
var descriptionBox = new GUITextBox(new RectTransform(Vector2.One, descriptionContainer.Content.RectTransform), itemEditor.Description, textAlignment: Alignment.TopLeft, font: GUI.SmallFont, wrap: true);
|
var descriptionBox = new GUITextBox(new RectTransform(Vector2.One, descriptionContainer.Content.RectTransform), itemEditor.Description, textAlignment: Alignment.TopLeft, wrap: true);
|
||||||
descriptionBox.OnTextChanged += (textBox, text) =>
|
descriptionBox.OnTextChanged += (textBox, text) =>
|
||||||
{
|
{
|
||||||
Vector2 textSize = textBox.Font.MeasureString(descriptionBox.WrappedText);
|
Vector2 textSize = textBox.Font.MeasureString(descriptionBox.WrappedText);
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ namespace Barotrauma
|
|||||||
get { return spriteColor; }
|
get { return spriteColor; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFullCondition => MathUtils.NearlyEqual(Condition, MaxCondition);
|
public bool IsFullCondition => Condition >= MaxCondition;
|
||||||
public float MaxCondition => Prefab.Health;
|
public float MaxCondition => Prefab.Health;
|
||||||
public float ConditionPercentage => MathUtils.Percentage(Condition, MaxCondition);
|
public float ConditionPercentage => MathUtils.Percentage(Condition, MaxCondition);
|
||||||
|
|
||||||
@@ -304,7 +304,6 @@ namespace Barotrauma
|
|||||||
if (Indestructible) return;
|
if (Indestructible) return;
|
||||||
|
|
||||||
float prev = condition;
|
float prev = condition;
|
||||||
|
|
||||||
condition = MathHelper.Clamp(value, 0.0f, Prefab.Health);
|
condition = MathHelper.Clamp(value, 0.0f, Prefab.Health);
|
||||||
if (condition == 0.0f && prev > 0.0f)
|
if (condition == 0.0f && prev > 0.0f)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user