104 lines
3.2 KiB
C#
104 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using SLSFramework.General;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Continentis.MainGame.UI
|
|
{
|
|
public partial class HUD_MainAttributesBar : HUDElementBase
|
|
{
|
|
public HealthBar healthBar;
|
|
public DefenseModule defenseModule;
|
|
|
|
public override void OnEnableHud()
|
|
{
|
|
UpdateHud();
|
|
}
|
|
|
|
public override void UpdateHud()
|
|
{
|
|
Dictionary<string, float> currentAttributes = container.characterView.character.attributeSubmodule.generalAttributeGroup.current;
|
|
|
|
int currentHealth = currentAttributes.GetRoundValue("Health");
|
|
int maxHealth = currentAttributes.GetRoundValue("MaximumHealth");
|
|
healthBar.UpdateHealth(currentHealth, maxHealth);
|
|
|
|
int currentBlock = currentAttributes.GetRoundValue("Block");
|
|
int currentDodge = currentAttributes.GetRoundValue("Dodge");
|
|
int currentTemporaryHealth = currentAttributes.GetRoundValue("TemporaryHealth");
|
|
defenseModule.UpdateBlock(currentBlock);
|
|
defenseModule.UpdateDodge(currentDodge);
|
|
defenseModule.UpdateShield(currentTemporaryHealth);
|
|
}
|
|
}
|
|
|
|
public partial class HUD_MainAttributesBar
|
|
{
|
|
[Serializable]
|
|
public class HealthBar
|
|
{
|
|
public Image fillingImage;
|
|
public Image backgroundImage;
|
|
public TMP_Text healthText;
|
|
|
|
public void UpdateHealth(int currentHealth, int maxHealth)
|
|
{
|
|
float healthRatio = (float)currentHealth / maxHealth;
|
|
fillingImage.fillAmount = healthRatio;
|
|
healthText.text = $"{currentHealth}/{maxHealth}";
|
|
|
|
Color fillingColor = Color.Lerp(Color.red, Color.black, (1 - healthRatio));
|
|
fillingImage.color = fillingColor;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class DefenseModule
|
|
{
|
|
public HUD_BaseIcon block;
|
|
public HUD_BaseIcon dodge;
|
|
public HUD_BaseIcon shield;
|
|
|
|
public void UpdateBlock(int currentBlock)
|
|
{
|
|
if (currentBlock <= 0)
|
|
{
|
|
block.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
block.gameObject.SetActive(true);
|
|
block.iconText.text = $"{currentBlock}";
|
|
}
|
|
}
|
|
|
|
public void UpdateDodge(int currentDodge)
|
|
{
|
|
if (currentDodge <= 0)
|
|
{
|
|
dodge.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
dodge.gameObject.SetActive(true);
|
|
dodge.iconText.text = $"{currentDodge}";
|
|
}
|
|
}
|
|
|
|
public void UpdateShield(int currentShield)
|
|
{
|
|
if (currentShield <= 0)
|
|
{
|
|
shield.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
shield.gameObject.SetActive(true);
|
|
shield.iconText.text = $"{currentShield}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |