Files
Continentis/Assets/Scripts/MainGame/UI/HUDPage/HUDContainer.cs

71 lines
2.3 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
using System.Collections.Generic;
using Continentis.MainGame.Character;
2025-10-23 00:49:44 -04:00
using NaughtyAttributes;
using SLSFramework.UModAssistance;
2025-10-03 00:02:43 -04:00
using UnityEngine;
using UnityEngine.Serialization;
namespace Continentis.MainGame.UI
{
public class HUDContainer : MonoBehaviour
{
2025-10-23 00:49:44 -04:00
//预先保存的HUD信息
private Dictionary<string, HUDInfo> preservedHudInfos;
[Header("Runtime Info")]
2025-10-03 00:02:43 -04:00
public CombatCharacterViewBase characterView;
public Dictionary<string, HUDElementBase> enablingHUDs;
public void Initialize(CombatCharacterViewBase characterView)
{
this.characterView = characterView;
this.characterView.hudContainer = this;
2025-10-23 00:49:44 -04:00
this.enablingHUDs = new Dictionary<string, HUDElementBase>();
this.preservedHudInfos = new Dictionary<string, HUDInfo>();
foreach (string hudDataRef in this.characterView.character.data.hudDataRefs)
{
HUDData hudData = ModManager.GetData<HUDData>(hudDataRef);
foreach (KeyValuePair<string, HUDInfo> hudInfo in hudData.hudInfos)
{
preservedHudInfos.TryAdd(hudInfo.Key, hudInfo.Value);
}
}
2025-10-03 00:02:43 -04:00
}
public void EnableHUD(string hudName)
{
2025-10-23 00:49:44 -04:00
if (preservedHudInfos.TryGetValue(hudName, out HUDInfo hudInfo))
2025-10-03 00:02:43 -04:00
{
2025-10-23 00:49:44 -04:00
if (!enablingHUDs.ContainsKey(hudName))
{
var hud = hudInfo.GenerateHUD(characterView, this);
hud.OnEnableHud();
enablingHUDs[hudName] = hud;
}
2025-10-03 00:02:43 -04:00
}
else
{
Debug.LogWarning($"HUD Info for {hudName} not found in character's HUD data.");
}
}
public void DisableHUD(string hudName)
{
if (enablingHUDs.TryGetValue(hudName, out HUDElementBase hud))
{
hud.OnDisableHud();
Destroy(hud.gameObject);
enablingHUDs.Remove(hudName);
}
}
public void UpdateAllHUD()
{
foreach (KeyValuePair<string, HUDElementBase> hud in enablingHUDs)
{
hud.Value.UpdateHud();
}
}
}
}