using BingoBrain.Core;
using BingoBrain.HotFix;
using FairyGUI;
using FGUI.ACommon;
using FGUI.JMain;
using UnityEngine;

namespace BingoBrain
{
    public class PalUI : BaseUI
    {
        private PalUICtrl ctrl;
        private PalModel model;
        private FGUI.JMain.com_pal ui;

        public PalUI(PalUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.PalUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "JMain";
            uiInfo.assetName = "com_pal";
            uiInfo.layerType = UILayerType.Popup;
            uiInfo.isNeedOpenAnim = false;
            uiInfo.isNeedCloseAnim = false;
            uiInfo.isNeedUIMask = true;
        }

        #region 生命周期
        protected override void OnInit()
        {
            //model = ModuleManager.Instance.GetModel(ModelConst.PalModel) as PalModel;
        }

        protected override void OnClose()
        {
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.JMain.com_pal;
        }

        protected override void OnOpenBefore(object args)
        {
            ui.list_pal.itemRenderer = RendererList;
            ui.list_pal.numItems = 2;


            ui.list_pal.scrollPane.onScrollEnd.Add(() =>
            {
                int index = ui.list_pal.GetFirstChildInView();

                ui.state.selectedIndex = index;
            });
            ui.btn_close.SetClick(CtrlCloseUI);
            InitView();
        }

        protected override void OnOpen(object args)
        {
        }

        protected override void OnHide()
        {
        }

        protected override void OnDisplay(object args)
        {
        }
        #endregion

        #region 消息
        protected override void AddListener()
        {

        }
        protected override void RemoveListener()
        {

        }
        #endregion
        void RendererList(int index, GObject obj)
        {
            item_pal item = obj as item_pal;
            item.state.selectedIndex = index;

        }
        //初始化页面逻辑
        private void InitView()
        {

        }
    }
}