using UnityEngine.UI;

namespace WS
{
    ///<summary>等待界面控制器</summary>
    public class WaitController : Controller<WaitView>
    {
        ///<summary>打开等待界面</summary>
        public static void OpenWaitView()
        {
            WaitController controller = FacadeComponent.Instance.GetController<WaitController>();
            if (controller == null)
            {
                controller = FacadeComponent.Instance.CreateController<WaitController>();
                controller.OpenView();
            }
        }

        ///<summary>打开等待界面</summary>
        ///<param name="tips">提示文字</param>
        public static void OpenWaitView(string tips)
        {
            WaitController controller = FacadeComponent.Instance.GetController<WaitController>();
            if (controller == null)
            {
                controller = FacadeComponent.Instance.CreateController<WaitController>();
                controller.OpenView();
                controller._View.TipsText.text = tips;
            }
        }

        ///<summary>关闭等待界面</summary>
        public static void CloseWaitView()
        {
            WaitController controller = FacadeComponent.Instance.GetController<WaitController>();
            if (controller != null)
            {
                controller.CloseView();
            }
        }
    }

    ///<summary>等待界面</summary>
    public class WaitView : View
    {
        ///<summary>提示文本</summary>
        public Text TipsText;

        public override void LoadInit()
        {
            Group = ViewGroup.Loading;
            ReferenceCollector rc = UIGameObject.GetComponent<ReferenceCollector>();
            TipsText = rc.GetComponent<Text>("Text");
            TipsText.text = "";
        }
    }
}