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:
Joonas Rikkonen
2017-11-14 19:10:43 +02:00
parent 157d9dcaba
commit ff926c1da2
6 changed files with 110 additions and 32 deletions
+26 -13
View File
@@ -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);
}
}
}
}