diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs index 91fc473be..064473e99 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs @@ -110,13 +110,13 @@ namespace Barotrauma t = new Texture2D(graphicsDevice, 1, 1); t.SetData(new Color[] { Color.White });// fill the texture with white - submarineIcon = new Sprite("Content/UI/uiIcons.png", new Rectangle(0, 192, 64, 64), null); + submarineIcon = new Sprite("Content/UI/uiIcons.png", new Rectangle(0, 192, 64, 64)); submarineIcon.Origin = submarineIcon.size / 2; - arrow = new Sprite("Content/UI/uiIcons.png", new Rectangle(80, 240, 16, 16), null); + arrow = new Sprite("Content/UI/uiIcons.png", new Rectangle(80, 240, 16, 16)); arrow.Origin = arrow.size / 2; - SpeechBubbleIcon = new Sprite("Content/UI/uiIcons.png", new Rectangle(0, 129, 65, 61), null); + SpeechBubbleIcon = new Sprite("Content/UI/uiIcons.png", new Rectangle(0, 129, 65, 61)); SpeechBubbleIcon.Origin = SpeechBubbleIcon.size / 2; } diff --git a/Barotrauma/BarotraumaShared/Source/Sprite/Sprite.cs b/Barotrauma/BarotraumaShared/Source/Sprite/Sprite.cs index 73eda078d..b93fe030c 100644 --- a/Barotrauma/BarotraumaShared/Source/Sprite/Sprite.cs +++ b/Barotrauma/BarotraumaShared/Source/Sprite/Sprite.cs @@ -26,7 +26,7 @@ namespace Barotrauma public float rotation; - public SpriteEffects effects; + public SpriteEffects effects = SpriteEffects.None; protected float depth; @@ -61,6 +61,7 @@ namespace Barotrauma partial void LoadTexture(ref Vector4 sourceVector, ref bool shouldReturn); partial void CalculateSourceRect(); + // TODO: use the Init method below? public Sprite(XElement element, string path = "", string file = "") { if (file == "") @@ -106,50 +107,39 @@ namespace Barotrauma public Sprite(string newFile, Vector2 newOrigin) { - file = newFile; - - Vector4 sourceVector = Vector4.Zero; - bool shouldReturn = false; - LoadTexture(ref sourceVector, ref shouldReturn); - if (shouldReturn) return; - - CalculateSourceRect(); - - size = new Vector2(sourceRect.Width, sourceRect.Height); - - origin = new Vector2((float)sourceRect.Width * newOrigin.X, (float)sourceRect.Height * newOrigin.Y); - - effects = SpriteEffects.None; - - list.Add(this); + Init(newFile, newOrigin: newOrigin); } - public Sprite(string newFile, Rectangle? sourceRectangle, Vector2? newOffset, float newRotation = 0.0f) + public Sprite(string newFile, Rectangle? sourceRectangle, Vector2? newOffset = null, float newRotation = 0) + { + Init(newFile, sourceRectangle: sourceRectangle, newOffset: newOffset, newRotation: newRotation); + } + + private void Init(string newFile, Rectangle? sourceRectangle = null, Vector2? newOrigin = null, Vector2? newOffset = null, float newRotation = 0) { file = newFile; Vector4 sourceVector = Vector4.Zero; bool shouldReturn = false; LoadTexture(ref sourceVector, ref shouldReturn); if (shouldReturn) return; - - if (sourceRectangle != null) + if (sourceRectangle.HasValue) { - sourceRect = (Rectangle)sourceRectangle; + sourceRect = sourceRectangle.Value; } else { CalculateSourceRect(); } - - offset = newOffset ?? Vector2.Zero; - - size = new Vector2(sourceRect.Width, sourceRect.Height); - - origin = Vector2.Zero; - + offset = newOffset ?? Vector2.Zero; + if (newOrigin.HasValue) + { + origin = new Vector2(sourceRect.Width * newOrigin.Value.X, sourceRect.Height * newOrigin.Value.Y); + } rotation = newRotation; - - list.Add(this); + if (!list.Contains(this)) + { + list.Add(this); + } } public void Remove()