diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs index 8eff06f59..a68b49a21 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs @@ -16,7 +16,9 @@ namespace Barotrauma private static GUIButton suicideButton; - private static GUIProgressBar drowningBar, healthBar; + private static GUIProgressBar oxygenBar, healthBar; + + private static bool oxyMsgShown, pressureMsgShown; public static float damageOverlayTimer { get; private set; } @@ -61,10 +63,10 @@ namespace Barotrauma public static void Update(float deltaTime, Character character) { - if (drowningBar != null) + if (oxygenBar != null) { - drowningBar.Update(deltaTime); - if (character.Oxygen < 10.0f) drowningBar.Flash(); + oxygenBar.Update(deltaTime); + if (character.Oxygen < 10.0f) oxygenBar.Flash(); } if (healthBar != null) healthBar.Update(deltaTime); @@ -76,7 +78,6 @@ namespace Barotrauma if (!character.IsUnconscious && character.Stun <= 0.0f) { - if (character.Inventory != null) { if (!character.LockHands && character.Stun >= -0.1f) @@ -290,21 +291,26 @@ namespace Barotrauma GUI.DrawString(spriteBatch, new Vector2(30, GameMain.GraphicsHeight - 260), "Stun: "+character.Stun, Color.White); } - if (drowningBar == null) + if (oxygenBar == null) { int width = 100, height = 20; - drowningBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 200, width, height), Color.Blue, "", 1.0f, Alignment.TopLeft); - new GUIImage(new Rectangle(-27, -7, 20, 20), new Rectangle(17, 0, 20, 24), statusIcons, Alignment.TopLeft, drowningBar); + oxygenBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 200, width, height), Color.Blue, "", 1.0f, Alignment.TopLeft); + new GUIImage(new Rectangle(-27, -7, 20, 20), new Rectangle(17, 0, 20, 24), statusIcons, Alignment.TopLeft, oxygenBar); healthBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 230, width, height), Color.Red, "", 1.0f, Alignment.TopLeft); new GUIImage(new Rectangle(-26, -7, 20, 20), new Rectangle(0, 0, 13, 24), statusIcons, Alignment.TopLeft, healthBar); } - drowningBar.BarSize = character.Oxygen / 100.0f; - if (drowningBar.BarSize < 0.99f) + oxygenBar.BarSize = character.Oxygen / 100.0f; + if (oxygenBar.BarSize < 0.99f) { - drowningBar.Draw(spriteBatch); + oxygenBar.Draw(spriteBatch); + if (!oxyMsgShown) + { + GUI.AddMessage(InfoTextManager.GetInfoText("OxygenBarInfo"), new Vector2(oxygenBar.Rect.Right + 10, oxygenBar.Rect.Y), Alignment.Left, Color.White, 5.0f); + oxyMsgShown = true; + } } healthBar.BarSize = character.Health / character.MaxHealth; @@ -322,17 +328,24 @@ namespace Barotrauma } float pressureFactor = (character.AnimController.CurrentHull == null) ? - 100.0f : Math.Min(character.AnimController.CurrentHull.LethalPressure,100.0f); + 100.0f : Math.Min(character.AnimController.CurrentHull.LethalPressure, 100.0f); if (character.PressureProtection > 0.0f) pressureFactor = 0.0f; - if (pressureFactor>0.0f) + if (pressureFactor > 0.0f) { float indicatorAlpha = ((float)Math.Sin(character.PressureTimer * 0.1f) + 1.0f) * 0.5f; + indicatorAlpha = MathHelper.Clamp(indicatorAlpha, 0.1f, pressureFactor / 100.0f); - indicatorAlpha = MathHelper.Clamp(indicatorAlpha, 0.1f, pressureFactor/100.0f); + if (indicatorAlpha > 0.1f) + { + if (!pressureMsgShown) + { + GUI.AddMessage(InfoTextManager.GetInfoText("PressureInfo"), new Vector2(40.0f, healthBar.Rect.Y - 60.0f), Alignment.Left, Color.White, 5.0f); + pressureMsgShown = true; + } + } - spriteBatch.Draw(statusIcons.Texture, new Vector2(10.0f, healthBar.Rect.Y - 60.0f), new Rectangle(0, 24, 24, 25), Color.White * indicatorAlpha); - + spriteBatch.Draw(statusIcons.Texture, new Vector2(10.0f, healthBar.Rect.Y - 60.0f), new Rectangle(0, 24, 24, 25), Color.White * indicatorAlpha); } } } diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs index 17d991505..08468d81f 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs @@ -548,16 +548,28 @@ namespace Barotrauma public static void AddMessage(string message, Color color, float lifeTime = 3.0f, bool playSound = true) { - if (messages.Count>0 && messages[messages.Count-1].Text == message) + if (messages.Count > 0 && messages[messages.Count - 1].Text == message) { messages[messages.Count - 1].LifeTime = lifeTime; return; } - Vector2 currPos = new Vector2(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight * 0.7f); - currPos.Y += messages.Count * 30; + Vector2 pos = new Vector2(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight * 0.7f); + pos.Y += messages.FindAll(m => m.Centered).Count * 30; - messages.Add(new GUIMessage(message, color, currPos, lifeTime)); + messages.Add(new GUIMessage(message, color, pos, lifeTime, Alignment.Center, true)); + if (playSound) PlayUISound(GUISoundType.Message); + } + + public static void AddMessage(string message, Vector2 position, Alignment alignment, Color color, float lifeTime = 3.0f, bool playSound = true) + { + if (messages.Count > 0 && messages[messages.Count - 1].Text == message) + { + messages[messages.Count - 1].LifeTime = lifeTime; + return; + } + + messages.Add(new GUIMessage(message, color, position, lifeTime, alignment, false)); if (playSound) PlayUISound(GUISoundType.Message); } @@ -587,23 +599,24 @@ namespace Barotrauma alpha -= 1.0f - msg.LifeTime; } - msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime*20.0f); + if (msg.Centered) + { + msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime * 20.0f); + currPos.Y += 30.0f; + } Font.DrawString(spriteBatch, msg.Text, new Vector2((int)msg.Pos.X - 1, (int)msg.Pos.Y - 1), - Color.Black * alpha*0.5f, 0.0f, - new Vector2((int)(0.5f * msg.Size.X), (int)(0.5f * msg.Size.Y)), 1.0f, SpriteEffects.None, 0.0f); + Color.Black * alpha * 0.5f, 0.0f, + msg.Origin, 1.0f, SpriteEffects.None, 0.0f); Font.DrawString(spriteBatch, msg.Text, - new Vector2((int)msg.Pos.X, (int)msg.Pos.Y), + new Vector2((int)msg.Pos.X, (int)msg.Pos.Y), msg.Color * alpha, 0.0f, - new Vector2((int)(0.5f * msg.Size.X), (int)(0.5f * msg.Size.Y)), 1.0f, SpriteEffects.None, 0.0f); + msg.Origin, 1.0f, SpriteEffects.None, 0.0f); - - currPos.Y += 30.0f; - - messages[0].LifeTime -= deltaTime/i; + messages[0].LifeTime -= deltaTime / i; i++; } diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs index 017985208..cb1f6b437 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs @@ -32,6 +32,7 @@ namespace Barotrauma get { return size; } } + public Vector2 Origin; public float LifeTime { @@ -39,13 +40,41 @@ namespace Barotrauma set { lifeTime = value; } } - public GUIMessage(string text, Color color, Vector2 position, float lifeTime) + public Alignment Alignment + { + get; + private set; + } + + public bool Centered; + + public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool centered) { coloredText = new ColoredText(text, color); pos = position; this.lifeTime = lifeTime; + this.Alignment = textAlignment; - size = GUI.Font.MeasureString(text); + if (textAlignment.HasFlag(Alignment.Left)) + Origin.X += size.X * 0.5f; + + if (textAlignment.HasFlag(Alignment.Right)) + Origin.X -= size.X * 0.5f; + + if (textAlignment.HasFlag(Alignment.Top)) + Origin.Y += size.Y * 0.5f; + + if (textAlignment.HasFlag(Alignment.Bottom)) + Origin.Y -= size.Y * 0.5f; + + if (centered) + { + Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y)); + } + else + { + size = GUI.Font.MeasureString(text); + } } } } diff --git a/Barotrauma/BarotraumaShared/Content/InfoTexts.xml b/Barotrauma/BarotraumaShared/Content/InfoTexts.xml index f5eb2b35b..50dae9c58 100644 --- a/Barotrauma/BarotraumaShared/Content/InfoTexts.xml +++ b/Barotrauma/BarotraumaShared/Content/InfoTexts.xml @@ -5,6 +5,9 @@ [sub] has returned to [location]. The ocean has claimed [sub] and its crew. + Running out of oxygen! + Water pressure increasing! + Succumbed to their injuries Bled out Drowned diff --git a/Barotrauma/BarotraumaShared/Content/Missions.xml b/Barotrauma/BarotraumaShared/Content/Missions.xml index 8b5a1f289..98598526c 100644 --- a/Barotrauma/BarotraumaShared/Content/Missions.xml +++ b/Barotrauma/BarotraumaShared/Content/Missions.xml @@ -230,7 +230,7 @@ descriptionneutral="A Coalition vessel has been dispatched from [location1] to destroy a renegade vessel at the outskirts of [location2]." description1="A renegade vessel has been detected at the outskirts of [location2]. Treason against the Europa Coalition is punishable by death - eliminate the renegades and return to [location1]!" - description2="You're a member of a renegade group opposing the Europa Coalition. According to your informants at [location1], a Coalition ship has just been dispatched on a mission to take down your vessel. Eliminate their crew and return to [location2]." + description2="You're a member of a renegade group opposing the Europa Coalition. According to your informants at [location1], a Coalition vessel has just been dispatched on a mission to take down your boat. Eliminate their crew and return to [location2]." teamname1="Coalition" teamname2="Renegade" diff --git a/Barotrauma/BarotraumaShared/Source/CoroutineManager.cs b/Barotrauma/BarotraumaShared/Source/CoroutineManager.cs index 710edba33..fa7bd8b5b 100644 --- a/Barotrauma/BarotraumaShared/Source/CoroutineManager.cs +++ b/Barotrauma/BarotraumaShared/Source/CoroutineManager.cs @@ -37,6 +37,26 @@ namespace Barotrauma return handle; } + public static void InvokeAfter(Action action, float delay) + { + StartCoroutine(DoInvokeAfter(action, delay)); + } + + private static IEnumerable DoInvokeAfter(Action action, float delay) + { + if (action == null) + { + yield return CoroutineStatus.Failure; + } + + yield return new WaitForSeconds(delay); + + action(); + + yield return CoroutineStatus.Success; + } + + public static bool IsCoroutineRunning(string name) { return Coroutines.Any(c => c.Name == name);