Unstable 0.17.0.0

This commit is contained in:
Markus Isberg
2022-02-26 02:43:01 +09:00
parent a83f375681
commit 3974067915
913 changed files with 32472 additions and 32364 deletions
@@ -8,6 +8,7 @@ using System.Xml.Linq;
using Barotrauma.IO;
using RestSharp;
using System.Net;
using System.Collections.Immutable;
namespace Barotrauma
{
@@ -66,7 +67,7 @@ namespace Barotrauma
{
foreach (GUIComponent child in Children)
{
if (child.UserData == obj || (child.userData != null && child.userData.Equals(obj))) { return child; }
if (child.UserData == obj || (child.UserData != null && child.UserData.Equals(obj))) { return child; }
}
return null;
}
@@ -107,7 +108,7 @@ namespace Barotrauma
}
public GUIComponent FindChild(object userData, bool recursive = false)
{
var matchingChild = Children.FirstOrDefault(c => c.userData == userData);
var matchingChild = Children.FirstOrDefault(c => c.UserData == userData);
if (recursive && matchingChild == null)
{
foreach (GUIComponent child in Children)
@@ -122,7 +123,7 @@ namespace Barotrauma
public IEnumerable<GUIComponent> FindChildren(object userData)
{
return Children.Where(c => c.userData == userData);
return Children.Where(c => c.UserData == userData);
}
public IEnumerable<GUIComponent> FindChildren(Func<GUIComponent, bool> predicate)
@@ -161,9 +162,7 @@ namespace Barotrauma
protected Alignment alignment;
protected GUIComponentStyle style;
protected object userData;
protected Identifier[] styleHierarchy;
public bool CanBeFocused;
@@ -206,16 +205,14 @@ namespace Barotrauma
}
}
public virtual ScalableFont Font
public virtual GUIFont Font
{
get;
set;
}
// Use the rawtooltip when copying displayed tooltips so that any possible color-data related values are translated over as well
public string RawToolTip;
private string toolTip;
public virtual string ToolTip
private RichString toolTip;
public virtual RichString ToolTip
{
get
{
@@ -223,18 +220,12 @@ namespace Barotrauma
}
set
{
RawToolTip = value;
TooltipRichTextData = RichTextData.GetRichTextData(value, out value);
toolTip = value;
}
}
public List<RichTextData> TooltipRichTextData = null;
public GUIComponentStyle Style
{
get { return style; }
}
=> GUIComponentStyle.FromHierarchy(styleHierarchy);
public bool Visible
{
@@ -258,8 +249,8 @@ namespace Barotrauma
protected Rectangle ClampRect(Rectangle r)
{
if (Parent == null || !ClampMouseRectToParent) { return r; }
Rectangle parentRect = Parent.ClampRect(Parent.Rect);
if (Parent is null) { return r; }
Rectangle parentRect = !Parent.ClampMouseRectToParent ? Parent.Rect : Parent.ClampRect(Parent.Rect);
if (parentRect.Width <= 0 || parentRect.Height <= 0) { return Rectangle.Empty; }
if (parentRect.X > r.X)
{
@@ -293,11 +284,13 @@ namespace Barotrauma
}
public bool ClampMouseRectToParent { get; set; } = false;
public virtual Rectangle MouseRect
{
get
{
if (!CanBeFocused) { return Rectangle.Empty; }
return ClampMouseRectToParent ? ClampRect(Rect) : Rect;
}
}
@@ -310,13 +303,13 @@ namespace Barotrauma
protected ComponentState _state;
protected ComponentState _previousState;
protected bool selected;
protected bool isSelected;
public virtual bool Selected
{
get { return selected; }
get { return isSelected; }
set
{
selected = value;
isSelected = value;
foreach (var child in Children)
{
child.Selected = value;
@@ -338,11 +331,8 @@ namespace Barotrauma
}
}
public object UserData
{
get { return userData; }
set { userData = value; }
}
#warning TODO: this is cursed, stop using this
public object UserData;
public int CountChildren
{
@@ -417,20 +407,20 @@ namespace Barotrauma
Visible = true;
OutlineColor = Color.Transparent;
Font = GUI.Font;
Font = GUIStyle.Font;
CanBeFocused = true;
if (style != null) { GUI.Style.Apply(this, style); }
if (style != null) { GUIStyle.Apply(this, style); }
}
protected GUIComponent(string style)
{
Visible = true;
OutlineColor = Color.Transparent;
Font = GUI.Font;
Font = GUIStyle.Font;
CanBeFocused = true;
if (style != null) { GUI.Style.Apply(this, style); }
if (style != null) { GUIStyle.Apply(this, style); }
}
#region Updating
@@ -486,7 +476,7 @@ namespace Barotrauma
{
if (GUI.IsMouseOn(this) && PlayerInput.SecondaryMouseButtonClicked())
{
OnSecondaryClicked?.Invoke(this, userData);
OnSecondaryClicked?.Invoke(this, UserData);
}
}
@@ -704,7 +694,7 @@ namespace Barotrauma
if (GlowOnSelect && State == ComponentState.Selected)
{
GUI.UIGlow.Draw(spriteBatch, Rect, SelectedColor);
GUIStyle.UIGlow.Draw(spriteBatch, Rect, SelectedColor);
}
if (flashTimer > 0.0f)
@@ -724,7 +714,7 @@ namespace Barotrauma
}
else
{
var glow = useCircularFlash ? GUI.UIGlowCircular : GUI.UIGlow;
var glow = useCircularFlash ? GUIStyle.UIGlowCircular : GUIStyle.UIGlow;
glow.Draw(spriteBatch,
flashRect,
flashColor * (float)Math.Sin(flashTimer % flashCycleDuration / flashCycleDuration * MathHelper.Pi * 0.8f));
@@ -738,24 +728,24 @@ namespace Barotrauma
public void DrawToolTip(SpriteBatch spriteBatch)
{
if (!Visible) { return; }
DrawToolTip(spriteBatch, ToolTip, GUI.MouseOn.Rect, TooltipRichTextData);
DrawToolTip(spriteBatch, ToolTip, GUI.MouseOn.Rect);
}
public static void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Vector2 pos, List<RichTextData> richTextData = null)
public static void DrawToolTip(SpriteBatch spriteBatch, RichString toolTip, Vector2 pos)
{
if (Tutorials.Tutorial.ContentRunning) { return; }
if (GameMain.GameSession?.GameMode is TutorialMode tutorialMode && tutorialMode.Tutorial.ContentRunning) { return; }
int width = (int)(400 * GUI.Scale);
int height = (int)(18 * GUI.Scale);
Point padding = new Point((int)(10 * GUI.Scale));
if (toolTipBlock == null || (string)toolTipBlock.userData != toolTip)
if (toolTipBlock == null || (RichString)toolTipBlock.UserData != toolTip)
{
toolTipBlock = new GUITextBlock(new RectTransform(new Point(width, height), null), richTextData, toolTip, font: GUI.SmallFont, wrap: true, style: "GUIToolTip");
toolTipBlock = new GUITextBlock(new RectTransform(new Point(width, height), null), toolTip, font: GUIStyle.SmallFont, wrap: true, style: "GUIToolTip");
toolTipBlock.RectTransform.NonScaledSize = new Point(
(int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).X + padding.X + toolTipBlock.Padding.X + toolTipBlock.Padding.Z),
(int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).Y + padding.Y + toolTipBlock.Padding.Y + toolTipBlock.Padding.W));
toolTipBlock.userData = toolTip;
(int)(GUIStyle.SmallFont.MeasureString(toolTipBlock.WrappedText).X + padding.X + toolTipBlock.Padding.X + toolTipBlock.Padding.Z),
(int)(GUIStyle.SmallFont.MeasureString(toolTipBlock.WrappedText).Y + padding.Y + toolTipBlock.Padding.Y + toolTipBlock.Padding.W));
toolTipBlock.UserData = toolTip;
}
toolTipBlock.RectTransform.AbsoluteOffset = pos.ToPoint();
@@ -764,21 +754,21 @@ namespace Barotrauma
toolTipBlock.DrawManually(spriteBatch);
}
public static void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle targetElement, List<RichTextData> richTextData = null)
public static void DrawToolTip(SpriteBatch spriteBatch, RichString toolTip, Rectangle targetElement)
{
if (Tutorials.Tutorial.ContentRunning) { return; }
if (GameMain.GameSession?.GameMode is TutorialMode tutorialMode && tutorialMode.Tutorial.ContentRunning) { return; }
int width = (int)(400 * GUI.Scale);
int height = (int)(18 * GUI.Scale);
Point padding = new Point((int)(10 * GUI.Scale));
if (toolTipBlock == null || (string)toolTipBlock.userData != toolTip)
if (toolTipBlock == null || (RichString)toolTipBlock.UserData != toolTip)
{
toolTipBlock = new GUITextBlock(new RectTransform(new Point(width, height), null), richTextData, toolTip, font: GUI.SmallFont, wrap: true, style: "GUIToolTip");
toolTipBlock = new GUITextBlock(new RectTransform(new Point(width, height), null), toolTip, font: GUIStyle.SmallFont, wrap: true, style: "GUIToolTip");
toolTipBlock.RectTransform.NonScaledSize = new Point(
(int)(toolTipBlock.Font.MeasureString(toolTipBlock.WrappedText).X + padding.X + toolTipBlock.Padding.X + toolTipBlock.Padding.Z),
(int)(toolTipBlock.Font.MeasureString(toolTipBlock.WrappedText).Y + padding.Y + toolTipBlock.Padding.Y + toolTipBlock.Padding.W));
toolTipBlock.userData = toolTip;
toolTipBlock.UserData = toolTip;
}
toolTipBlock.RectTransform.AbsoluteOffset = new Point(targetElement.Center.X, targetElement.Bottom);
@@ -811,7 +801,7 @@ namespace Barotrauma
this.useRectangleFlash = useRectangleFlash;
this.useCircularFlash = useCircularFlash;
this.flashDuration = flashDuration;
flashColor = (color == null) ? GUI.Style.Red : (Color)color;
flashColor = (color == null) ? GUIStyle.Red : (Color)color;
}
public void FadeOut(float duration, bool removeAfter, float wait = 0.0f)
@@ -952,8 +942,7 @@ namespace Barotrauma
ApplySizeRestrictions(style);
}
this.style = style;
styleHierarchy = GUIComponentStyle.ToHierarchy(style);
}
public void ApplySizeRestrictions(GUIComponentStyle style)
@@ -972,11 +961,11 @@ namespace Barotrauma
}
}
public static GUIComponent FromXML(XElement element, RectTransform parent)
public static GUIComponent FromXML(ContentXElement element, RectTransform parent)
{
GUIComponent component = null;
foreach (XElement subElement in element.Elements())
foreach (var subElement in element.Elements())
{
if (subElement.Name.ToString().Equals("conditional", StringComparison.OrdinalIgnoreCase) && !CheckConditional(subElement))
{
@@ -1027,7 +1016,7 @@ namespace Barotrauma
if (component != null)
{
foreach (XElement subElement in element.Elements())
foreach (var subElement in element.Elements())
{
if (subElement.Name.ToString().Equals("conditional", StringComparison.OrdinalIgnoreCase)) { continue; }
FromXML(subElement, component is GUIListBox listBox ? listBox.Content.RectTransform : component.RectTransform);
@@ -1078,8 +1067,9 @@ namespace Barotrauma
switch (attribute.Name.ToString().ToLowerInvariant())
{
case "language":
string[] languages = element.GetAttributeStringArray(attribute.Name.ToString(), new string[0]);
if (!languages.Any(l => GameMain.Config.Language.Equals(l, StringComparison.OrdinalIgnoreCase))) { return false; }
var languages = element.GetAttributeIdentifierArray(attribute.Name.ToString(), Array.Empty<Identifier>())
.Select(s => new LanguageIdentifier(s));
if (!languages.Any(l => GameSettings.CurrentConfig.Language == l)) { return false; }
break;
case "gameversion":
var version = new Version(attribute.Value);
@@ -1136,23 +1126,12 @@ namespace Barotrauma
if (element.Attribute("color") != null) { color = element.GetAttributeColor("color", Color.White); }
float scale = element.GetAttributeFloat("scale", 1.0f);
bool wrap = element.GetAttributeBool("wrap", true);
Alignment alignment = Alignment.Center;
Enum.TryParse(element.GetAttributeString("alignment", "Center"), out alignment);
ScalableFont font = GUI.Font;
switch (element.GetAttributeString("font", "Font").ToLowerInvariant())
Alignment alignment =
element.GetAttributeEnum("alignment", text.Contains('\n') ? Alignment.Left : Alignment.Center);
GUIFont font;
if (!GUIStyle.Fonts.TryGetValue(element.GetAttributeIdentifier("font", "Font"), out font))
{
case "font":
font = GUI.Font;
break;
case "smallfont":
font = GUI.SmallFont;
break;
case "largefont":
font = GUI.LargeFont;
break;
case "subheading":
font = GUI.SubHeadingFont;
break;
font = GUIStyle.Font;
}
var textBlock = new GUITextBlock(RectTransform.Load(element, parent),
@@ -1265,7 +1244,7 @@ namespace Barotrauma
};
}
private static GUIImage LoadGUIImage(XElement element, RectTransform parent)
private static GUIImage LoadGUIImage(ContentXElement element, RectTransform parent)
{
Sprite sprite;
string url = element.GetAttributeString("url", "");
@@ -1298,11 +1277,11 @@ namespace Barotrauma
return new GUIImage(RectTransform.Load(element, parent), sprite, scaleToFit: true);
}
private static GUIButton LoadAccordion(XElement element, RectTransform parent)
private static GUIButton LoadAccordion(ContentXElement element, RectTransform parent)
{
var button = LoadGUIButton(element, parent);
List<GUIComponent> content = new List<GUIComponent>();
foreach (XElement subElement in element.Elements())
foreach (var subElement in element.Elements())
{
var contentElement = FromXML(subElement, parent);
if (contentElement != null)