Merge branch 'walldamage'

This commit is contained in:
Regalis
2016-09-26 16:28:52 +03:00
32 changed files with 871 additions and 329 deletions
+42 -9
View File
@@ -93,6 +93,8 @@ namespace Barotrauma
protected Item closestItem;
private Character closestCharacter, selectedCharacter;
private Dictionary<object, HUDProgressBar> hudProgressBars;
protected bool isDead;
private CauseOfDeath lastAttackCauseOfDeath;
private CauseOfDeath causeOfDeath;
@@ -301,6 +303,11 @@ namespace Barotrauma
}
}
public Dictionary<object, HUDProgressBar> HUDProgressBars
{
get { return hudProgressBars; }
}
public HuskInfection huskInfection;
public float HuskInfectionState
{
@@ -498,6 +505,8 @@ namespace Barotrauma
selectedItems = new Item[2];
hudProgressBars = new Dictionary<object, HUDProgressBar>();
IsNetworkPlayer = isNetworkPlayer;
oxygen = 100.0f;
@@ -516,8 +525,6 @@ namespace Barotrauma
XDocument doc = ToolBox.TryLoadXml(file);
if (doc == null || doc.Root == null) return;
SpeciesName = ToolBox.GetAttributeString(doc.Root, "name", "Unknown");
@@ -1184,6 +1191,16 @@ namespace Barotrauma
{
Lights.LightManager.ViewTarget = this;
CharacterHUD.Update(deltaTime, this);
foreach (HUDProgressBar progressBar in hudProgressBars.Values)
{
progressBar.Update(deltaTime);
}
foreach (var pb in hudProgressBars.Where(pb => pb.Value.FadeTimer<=0.0f).ToList())
{
hudProgressBars.Remove(pb.Key);
}
}
if (IsUnconscious)
@@ -1277,10 +1294,6 @@ namespace Barotrauma
if (!Enabled) return;
AnimController.Draw(spriteBatch);
//GUI.DrawLine(spriteBatch, ConvertUnits.ToDisplayUnits(animController.limbs[0].SimPosition.X, animController.limbs[0].SimPosition.Y),
// ConvertUnits.ToDisplayUnits(animController.limbs[0].SimPosition.X, animController.limbs[0].SimPosition.Y) +
// ConvertUnits.ToDisplayUnits(animController.targetMovement.X, animController.targetMovement.Y), Color.Green);
}
public void DrawHUD(SpriteBatch spriteBatch, Camera cam)
@@ -1292,9 +1305,6 @@ namespace Barotrauma
{
if (!Enabled) return;
Vector2 pos = DrawPosition;
pos.Y = -pos.Y;
if (GameMain.DebugDraw)
{
AnimController.DebugDraw(spriteBatch);
@@ -1303,6 +1313,9 @@ namespace Barotrauma
}
if (this == controlled) return;
Vector2 pos = DrawPosition;
pos.Y = -pos.Y;
if (info != null)
{
@@ -1333,6 +1346,26 @@ namespace Barotrauma
}
}
/// <summary>
/// Creates a progress bar that's "linked" to the specified object (or updates an existing one if there's one already linked to the object)
/// The progress bar will automatically fade out after 1 sec if the method hasn't been called during that time
/// </summary>
public HUDProgressBar UpdateHUDProgressBar(object linkedObject, Vector2 worldPosition, float progress, Color emptyColor, Color fullColor)
{
HUDProgressBar progressBar = null;
if (!hudProgressBars.TryGetValue(linkedObject, out progressBar))
{
progressBar = new HUDProgressBar(worldPosition, Submarine, emptyColor, fullColor);
hudProgressBars.Add(linkedObject, progressBar);
}
progressBar.WorldPosition = worldPosition;
progressBar.FadeTimer = Math.Max(progressBar.FadeTimer, 1.0f);
progressBar.Progress = progress;
return progressBar;
}
public void PlaySound(AIController.AiState state)
{
if (sounds == null || !sounds.Any()) return;
+6 -1
View File
@@ -150,7 +150,12 @@ namespace Barotrauma
textPos.Y += 25;
}
}
}
foreach (HUDProgressBar progressBar in character.HUDProgressBars.Values)
{
progressBar.Draw(spriteBatch, cam);
}
}
if (Screen.Selected == GameMain.EditMapScreen) return;
@@ -0,0 +1,87 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace Barotrauma
{
class HUDProgressBar
{
private float progress;
public float Progress
{
get { return progress; }
set { progress = MathHelper.Clamp(value, 0.0f, 1.0f); }
}
public float FadeTimer;
private Color fullColor, emptyColor;
private Vector2 worldPosition;
public Vector2 WorldPosition
{
get
{
return worldPosition;
}
set
{
worldPosition = value;
if (parentSub != null)
{
worldPosition -= parentSub.DrawPosition;
}
}
}
public Vector2 Size;
private Submarine parentSub;
public HUDProgressBar(Vector2 worldPosition, Submarine parentSubmarine = null)
: this(worldPosition, parentSubmarine, Color.Red, Color.Green)
{
}
public HUDProgressBar(Vector2 worldPosition, Submarine parentSubmarine, Color emptyColor, Color fullColor)
{
this.emptyColor = emptyColor;
this.fullColor = fullColor;
parentSub = parentSubmarine;
WorldPosition = worldPosition;
Size = new Vector2(100.0f, 20.0f);
FadeTimer = 1.0f;
}
public void Update(float deltatime)
{
FadeTimer -= deltatime;
}
public void Draw(SpriteBatch spriteBatch, Camera cam)
{
float a = Math.Min(FadeTimer, 1.0f);
Vector2 pos = new Vector2(WorldPosition.X - Size.X / 2, WorldPosition.Y + Size.Y / 2);
if (parentSub != null)
{
pos += parentSub.DrawPosition;
}
pos = cam.WorldToScreen(pos);
GUI.DrawProgressBar(spriteBatch,
new Vector2(pos.X, -pos.Y),
Size, progress,
Color.Lerp(emptyColor, fullColor, progress) * a,
Color.White * a * 0.8f);
}
}
}