Warning texts when water pressure is increasing to dangerous levels and when running out of oxygen, added a method for invoking an arbitrary action after a delay to CoroutineManager
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<return>[sub] has returned to [location].</return>
|
||||
<gameover>The ocean has claimed [sub] and its crew.</gameover>
|
||||
|
||||
<OxygenBarInfo>Running out of oxygen!</OxygenBarInfo>
|
||||
<PressureInfo>Water pressure increasing!</PressureInfo>
|
||||
|
||||
<CauseOfDeath.Damage>Succumbed to their injuries</CauseOfDeath.Damage>
|
||||
<CauseOfDeath.Bloodloss>Bled out</CauseOfDeath.Bloodloss>
|
||||
<CauseOfDeath.Drowning>Drowned</CauseOfDeath.Drowning>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -37,6 +37,26 @@ namespace Barotrauma
|
||||
return handle;
|
||||
}
|
||||
|
||||
public static void InvokeAfter(Action action, float delay)
|
||||
{
|
||||
StartCoroutine(DoInvokeAfter(action, delay));
|
||||
}
|
||||
|
||||
private static IEnumerable<object> 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);
|
||||
|
||||
Reference in New Issue
Block a user