Files
Continentis/Assets/Scripts/MainGame/UI/HUDPage/HUDElements/HUD_MainAttributesBar.cs
SoulliesOfficial 61a397dd4c MOD!
2025-10-23 00:49:44 -04:00

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 currentShield = currentAttributes.GetRoundValue("Shield");
defenseModule.UpdateBlock(currentBlock);
defenseModule.UpdateDodge(currentDodge);
defenseModule.UpdateShield(currentShield);
}
}
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}";
}
}
}
}
}