using Excel2Json;
using Fort23.Core;
using Fort23.UTool;
using GameLogic.Combat;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace Fort23.Mono
{
    [UIBinding(prefab = "GuidePanel")]
    public partial class GuidePanel : UIPanel
    {
        private void Init()
        {
            isAddStack = false;
        }
        protected override void AddEvent()
        {
        }
        private void SkipGuide()
        {
            PlayerGuideManager.Instance.guideLogic.SkipGuide();
        }
        protected override void DelEvent()
        {
        }
        public override void AddButtonEvent()
        {
            Btn_Skip.onClick.AddListener(async () =>
            {
                // bool isKip = await UIManager.Instance.ShowTips("是否确认跳过引导");
                // if (isKip)
                SkipGuide();
            });
            Btn_Bg.onClick.AddListener(() =>
            {
                if (PlayerGuideManager.Instance.guideConfig.desc == -1)
                {
                    if (PlayerGuideManager.Instance.guideConfig.ForceOnclick == 0)
                    {
                        PlayerGuideManager.Instance.NextGuide();
                    }
                }
                else
                {
                    PlayerGuideManager.Instance.dialogBox.OnClickScreen();
                }
            });
            Btn_MessageBG.onClick.AddListener(() => { PlayerGuideManager.Instance.dialogBox.OnClickScreen(); });
        }
        [CustomMethod(customMethodType: CustomMethodType.Update)]
        public void Update()
        {
            // if (UIManager.Instance.currOpenPanel == null || UIManager.Instance.currOpenPanel.GetType() != typeof(MainPanel) || UIManager.Instance.popUIPanels.Count > 0)
            // {
            //     return;
            // }
            Vector3 worldPos = CombatDrive.Instance.CombatController.playerHeroEntity.combatHeroGameObject.hpTransform
                .position;
            Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint(worldPos);
            Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
            dotPoint.transform.position = p2;
        }
        public void SetTarget(GameObject gameObject)
        {
            MyGuideMask.SetTargetImage(gameObject);
        }
        /// 
        /// 设置点击屏蔽
        /// 
        /// 
        public void SetOnClickMask(bool value)
        {
            OnClickMask.gameObject.SetActive(value);
        }
        /// 
        /// 设置蒙版点击事件
        /// 
        /// 
        public void SetOnClickMaskOnClickAction(UnityAction unityAction)
        {
            OnClickMask.onClick.RemoveAllListeners();
            OnClickMask.onClick.AddListener(unityAction);
        }
        /// 
        /// 设置蒙版大小
        /// 
        /// 
        public void SetOnClickMaskSize(Vector2 size)
        {
            OnClickMask.GetComponent().sizeDelta = size;
        }
        public async override CTask Close()
        {
            await base.Close();
            PlayerGuideManager.Instance._timerEntity?.Dispose();
            PlayerGuideManager.Instance._timerEntity = null;
        }
        public override void Hide()
        {
            base.Hide();
        }
    }
}