using System;
using UnityEngine;
using XGame.Database;
using XGame.Framework.Map;
using XGame.Framework.ObjectCollection;

namespace FL.Map.UI
{
    public class HpAddEntityView : EntityView<HpAddEntityVM>
    {
        protected override void OnEnable(object intent)
        {
        }
        protected override void OnDisable()
        {
        }
        protected override void OnDispose()
        {
        }

        public void ShowValue(int value, Vector3 position, EElementType elementType, Action callback)
        {
            VM.HpText.text = /*value > 0 ? $"+{value}" : */value.ToString();
            VM.HpText.color = value > 0 ? ColorDefine.green : elementType.ToDamageColor();
            VM.Tr.localPosition = position;

            var timer = Context.Time.AddDelayTimer(500, callback);
        }
    }
    public class HpAddEntityVM : EntityViewModel
    {
        public UnityEngine.UI.Text HpText { get; private set; }
        public Transform Root { get; private set; }
        public Animation AniRoot { get; private set; }
        protected override void OnInit(IObjectCollector collector)
        {
            HpText = collector.GetComponent<UnityEngine.UI.Text>("HpText");
            Root = collector.GetGameObject("Root").transform;
            AniRoot = collector.GetComponent<Animation>("AniRoot");
        }
    }
}
