v0.13.0.11
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Barotrauma.Items.Components;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.Items.Components;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
@@ -10,7 +11,57 @@ using System.Linq;
|
||||
namespace Barotrauma
|
||||
{
|
||||
class CharacterHUD
|
||||
{
|
||||
{
|
||||
const float BossHealthBarDuration = 120.0f;
|
||||
|
||||
class BossHealthBar
|
||||
{
|
||||
public readonly Character Character;
|
||||
public float FadeTimer;
|
||||
|
||||
public readonly GUIComponent TopContainer;
|
||||
public readonly GUIComponent SideContainer;
|
||||
|
||||
public readonly GUIProgressBar TopHealthBar;
|
||||
public readonly GUIProgressBar SideHealthBar;
|
||||
|
||||
public BossHealthBar(Character character)
|
||||
{
|
||||
Character = character;
|
||||
FadeTimer = BossHealthBarDuration;
|
||||
|
||||
TopContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.18f, 0.03f), HUDFrame.RectTransform, Anchor.TopCenter)
|
||||
{
|
||||
MinSize = new Point(100, 50),
|
||||
RelativeOffset = new Vector2(0.0f, 0.01f)
|
||||
}, isHorizontal: false, childAnchor: Anchor.TopCenter);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.4f), TopContainer.RectTransform), character.DisplayName, textAlignment: Alignment.Center, textColor: GUI.Style.Red);
|
||||
TopHealthBar = new GUIProgressBar(new RectTransform(new Vector2(1.0f, 0.6f), TopContainer.RectTransform)
|
||||
{
|
||||
MinSize = new Point(100, HUDLayoutSettings.HealthBarArea.Size.Y)
|
||||
}, barSize: 0.0f, style: "CharacterHealthBarCentered")
|
||||
{
|
||||
Color = GUI.Style.Red
|
||||
};
|
||||
|
||||
SideContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), bossHealthContainer.RectTransform)
|
||||
{
|
||||
MinSize = new Point(80, 60)
|
||||
}, isHorizontal: false, childAnchor: Anchor.TopRight);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), SideContainer.RectTransform), character.DisplayName, textAlignment: Alignment.CenterRight, textColor: GUI.Style.Red);
|
||||
SideHealthBar = new GUIProgressBar(new RectTransform(new Vector2(1.0f, 0.7f), SideContainer.RectTransform), barSize: 0.0f, style: "CharacterHealthBar")
|
||||
{
|
||||
Color = GUI.Style.Red
|
||||
};
|
||||
|
||||
TopContainer.Visible = SideContainer.Visible = false;
|
||||
TopContainer.CanBeFocused = false;
|
||||
TopContainer.Children.ForEach(c => c.CanBeFocused = false);
|
||||
SideContainer.CanBeFocused = false;
|
||||
SideContainer.Children.ForEach(c => c.CanBeFocused = false);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<ISpatialEntity, int> orderIndicatorCount = new Dictionary<ISpatialEntity, int>();
|
||||
const float ItemOverlayDelay = 1.0f;
|
||||
private static Item focusedItem;
|
||||
@@ -19,8 +70,12 @@ namespace Barotrauma
|
||||
private static readonly List<Item> brokenItems = new List<Item>();
|
||||
private static float brokenItemsCheckTimer;
|
||||
|
||||
private static readonly List<BossHealthBar> bossHealthBars = new List<BossHealthBar>();
|
||||
|
||||
private static readonly Dictionary<string, string> cachedHudTexts = new Dictionary<string, string>();
|
||||
|
||||
private static GUILayoutGroup bossHealthContainer;
|
||||
|
||||
private static GUIFrame hudFrame;
|
||||
public static GUIFrame HUDFrame
|
||||
{
|
||||
@@ -33,6 +88,13 @@ namespace Barotrauma
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
bossHealthContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.15f, 0.5f), hudFrame.RectTransform, Anchor.CenterRight)
|
||||
{
|
||||
RelativeOffset = new Vector2(0.005f, 0.0f)
|
||||
})
|
||||
{
|
||||
AbsoluteSpacing = GUI.IntScale(10)
|
||||
};
|
||||
}
|
||||
return hudFrame;
|
||||
}
|
||||
@@ -70,7 +132,7 @@ namespace Barotrauma
|
||||
|
||||
public static void AddToGUIUpdateList(Character character)
|
||||
{
|
||||
if (GUI.DisableHUD) return;
|
||||
if (GUI.DisableHUD) { return; }
|
||||
|
||||
if (!character.IsIncapacitated && character.Stun <= 0.0f && !IsCampaignInterfaceOpen)
|
||||
{
|
||||
@@ -83,7 +145,7 @@ namespace Barotrauma
|
||||
|
||||
foreach (ItemComponent ic in item.Components)
|
||||
{
|
||||
if (ic.DrawHudWhenEquipped) ic.AddToGUIUpdateList();
|
||||
if (ic.DrawHudWhenEquipped) { ic.AddToGUIUpdateList(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,13 +161,14 @@ namespace Barotrauma
|
||||
|
||||
public static void Update(float deltaTime, Character character, Camera cam)
|
||||
{
|
||||
UpdateBossHealthBars(deltaTime);
|
||||
|
||||
if (GUI.DisableHUD)
|
||||
{
|
||||
if (character.Inventory != null && !LockInventory(character))
|
||||
{
|
||||
character.Inventory.UpdateSlotInput();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,17 +193,6 @@ namespace Barotrauma
|
||||
{
|
||||
character.Inventory.ClearSubInventories();
|
||||
}
|
||||
|
||||
for (int i = 0; i < character.Inventory.Capacity; i++)
|
||||
{
|
||||
var item = character.Inventory.GetItemAt(i);
|
||||
if (item == null || character.Inventory.SlotTypes[i] == InvSlotType.Any) { continue; }
|
||||
|
||||
foreach (ItemComponent ic in item.Components)
|
||||
{
|
||||
if (ic.DrawHudWhenEquipped) ic.UpdateHUD(character, deltaTime, cam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (character.IsHumanoid && character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
|
||||
@@ -221,10 +273,10 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (DrawIcon(character.CurrentOrder))
|
||||
if (character.GetCurrentOrderWithTopPriority()?.Order is Order currentOrder && DrawIcon(currentOrder))
|
||||
{
|
||||
DrawOrderIndicator(spriteBatch, cam, character, character.CurrentOrder, 1.0f);
|
||||
}
|
||||
DrawOrderIndicator(spriteBatch, cam, character, currentOrder, 1.0f);
|
||||
}
|
||||
|
||||
static bool DrawIcon(Order o) =>
|
||||
o != null &&
|
||||
@@ -253,7 +305,7 @@ namespace Barotrauma
|
||||
return Math.Min((maxDistance - dist) / maxDistance * 2.0f, 1.0f);
|
||||
}
|
||||
|
||||
if (!character.IsIncapacitated && character.Stun <= 0.0f && !IsCampaignInterfaceOpen && (!character.IsKeyDown(InputType.Aim) || character.HeldItems.Any(it => it?.GetComponent<Sprayer>() == null)))
|
||||
if (!character.IsIncapacitated && character.Stun <= 0.0f && !IsCampaignInterfaceOpen && (!character.IsKeyDown(InputType.Aim) || character.HeldItems.None(it => it?.GetComponent<Sprayer>() != null)))
|
||||
{
|
||||
if (character.FocusedCharacter != null && character.FocusedCharacter.CanBeSelected)
|
||||
{
|
||||
@@ -499,6 +551,86 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static void ShowBossHealthBar(Character character)
|
||||
{
|
||||
if (character == null || character.IsDead || character.Removed) { return; }
|
||||
|
||||
var existingBar = bossHealthBars.Find(b => b.Character == character);
|
||||
if (existingBar != null)
|
||||
{
|
||||
existingBar.FadeTimer = BossHealthBarDuration;
|
||||
return;
|
||||
}
|
||||
|
||||
if (bossHealthBars.Count > 5)
|
||||
{
|
||||
BossHealthBar oldestHealthBar = bossHealthBars.First();
|
||||
foreach (var bar in bossHealthBars)
|
||||
{
|
||||
if (bar.TopHealthBar.BarSize < oldestHealthBar.TopHealthBar.BarSize)
|
||||
{
|
||||
oldestHealthBar = bar;
|
||||
}
|
||||
}
|
||||
oldestHealthBar.FadeTimer = Math.Min(oldestHealthBar.FadeTimer, 1.0f);
|
||||
}
|
||||
|
||||
bossHealthBars.Add(new BossHealthBar(character));
|
||||
}
|
||||
|
||||
public static void UpdateBossHealthBars(float deltaTime)
|
||||
{
|
||||
for (int i = 0; i < bossHealthBars.Count; i++)
|
||||
{
|
||||
var bossHealthBar = bossHealthBars[i];
|
||||
|
||||
bool showTopBar = i == 0;
|
||||
if (showTopBar != bossHealthBar.TopContainer.Visible)
|
||||
{
|
||||
bossHealthContainer.Recalculate();
|
||||
}
|
||||
|
||||
bossHealthBar.TopContainer.Visible = showTopBar;
|
||||
bossHealthBar.SideContainer.Visible = !bossHealthBar.TopContainer.Visible;
|
||||
|
||||
float health = bossHealthBar.Character.Vitality / bossHealthBar.Character.MaxVitality;
|
||||
|
||||
float alpha = Math.Min(bossHealthBar.FadeTimer, 1.0f);
|
||||
foreach (var c in bossHealthBar.SideContainer.GetAllChildren().Concat(bossHealthBar.TopContainer.GetAllChildren()))
|
||||
{
|
||||
c.Color = new Color(c.Color, (byte)(alpha * 255));
|
||||
if (c is GUITextBlock textBlock)
|
||||
{
|
||||
textBlock.TextColor = new Color(bossHealthBar.Character.IsDead ? Color.Gray : textBlock.TextColor, (byte)(alpha * 255));
|
||||
}
|
||||
}
|
||||
|
||||
bossHealthBar.TopHealthBar.BarSize = bossHealthBar.SideHealthBar.BarSize = health;
|
||||
|
||||
if (bossHealthBar.Character.Removed || !bossHealthBar.Character.Enabled)
|
||||
{
|
||||
bossHealthBar.FadeTimer = Math.Min(bossHealthBar.FadeTimer, 1.0f);
|
||||
}
|
||||
else if (bossHealthBar.Character.IsDead)
|
||||
{
|
||||
bossHealthBar.FadeTimer = Math.Min(bossHealthBar.FadeTimer, 5.0f);
|
||||
}
|
||||
bossHealthBar.FadeTimer -= deltaTime;
|
||||
}
|
||||
|
||||
for (int i = bossHealthBars.Count - 1; i >= 0 ; i--)
|
||||
{
|
||||
var bossHealthBar = bossHealthBars[i];
|
||||
if (bossHealthBar.FadeTimer <= 0)
|
||||
{
|
||||
bossHealthBar.SideContainer.Parent?.RemoveChild(bossHealthBar.SideContainer);
|
||||
bossHealthBar.TopContainer.Parent?.RemoveChild(bossHealthBar.TopContainer);
|
||||
bossHealthBars.RemoveAt(i);
|
||||
bossHealthContainer.Recalculate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool LockInventory(Character character)
|
||||
{
|
||||
if (character?.Inventory == null || !character.AllowInput || character.LockHands || IsCampaignInterfaceOpen) { return true; }
|
||||
|
||||
Reference in New Issue
Block a user