Progress bars that show the health of wall sections when welding/cutting

This commit is contained in:
Regalis
2016-09-20 18:40:30 +03:00
parent f8368f464a
commit 5918e845ac
7 changed files with 140 additions and 41 deletions
+46 -5
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;
@@ -498,6 +500,8 @@ namespace Barotrauma
selectedItems = new Item[2];
hudProgressBars = new Dictionary<object, HUDProgressBar>();
IsNetworkPlayer = isNetworkPlayer;
oxygen = 100.0f;
@@ -516,8 +520,6 @@ namespace Barotrauma
XDocument doc = ToolBox.TryLoadXml(file);
if (doc == null || doc.Root == null) return;
SpeciesName = ToolBox.GetAttributeString(doc.Root, "name", "Unknown");
@@ -1184,6 +1186,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)
@@ -1292,8 +1304,6 @@ namespace Barotrauma
{
if (!Enabled) return;
Vector2 pos = DrawPosition;
pos.Y = -pos.Y;
if (GameMain.DebugDraw)
{
@@ -1302,7 +1312,18 @@ namespace Barotrauma
if (aiTarget != null) aiTarget.Draw(spriteBatch);
}
if (this == controlled) return;
if (this == controlled)
{
foreach (HUDProgressBar progressBar in hudProgressBars.Values)
{
progressBar.Draw(spriteBatch);
}
return;
}
Vector2 pos = DrawPosition;
pos.Y = -pos.Y;
if (info != null)
{
@@ -1333,6 +1354,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, 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;