using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
///
/// 这里主要处理课程开始后的UI
///
///
public class CoursePannelManager : MonoBehaviour
{
[SerializeField]
private CourseBarView CourseUI;
[SerializeField]
private GameObject Quanxi;
[SerializeField]
private BasePannel[] pannelAry;//所有的POP弹框
private Dictionary pannelDict = new Dictionary();
[SerializeField]
private OnLineUserListPannel mOnLineUserListPannel;
[SerializeField]
private StudentPannel mStudentUIPannel;
//当前的展示页面
private PannelType curType = PannelType.Default;
private void Awake()
{
mOnLineUserListPannel.Hide();
mStudentUIPannel.Hide();
}
void Start()
{
InitPannels();
CourseUI.Hide();
SetQuanxi(false);
MessageCenterController.Instance.Register(GameEnum.MESSAGE_ENTER_COURSE, EnterCourse);//进入房间
MessageCenterController.Instance.Register(GameEnum.MESSAGE_EXIT_COURSE, ExitCourse);//关闭房间
MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_COURSE, ShowCourse);//显示房间
MessageCenterController.Instance.Register(GameEnum.MESSAGE_HIDE_COURSE, HideCourse);//隐藏房间
MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_LOGOUT, ExitCourse);//登出
MessageCenterController.Instance.Register(GameEnum.MESSAGE_RESET_ACCOUNT, ExitCourse);//账号重置
MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_PANNEL_BY_TYPE, ShowPannelByType);//
MessageCenterController.Instance.Register(GameEnum.MESSAGE_SEND_CHANGE_ROOM_OWNER_REFRESH, OwnerChange);//有房主的变动
MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_MSG_NOTICE, ShowNotice);//显示提示
MessageCenterController.Instance.Register(GameEnum.MESSAGE_HIDE_MSG_NOTICE, HideNotice);//隐藏提示
}
private void OnDestroy()
{
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_ENTER_COURSE, EnterCourse);//进入房间
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_EXIT_COURSE, ExitCourse);//关闭房间
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_LOGOUT, ExitCourse);//登出
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_RESET_ACCOUNT, ExitCourse);//账号重置
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_PANNEL_BY_TYPE, ShowPannelByType);//房间列表
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SEND_CHANGE_ROOM_OWNER_REFRESH, OwnerChange);//有房主的变动
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_MSG_NOTICE, ShowNotice);//显示提示
MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_HIDE_MSG_NOTICE, HideNotice);//隐藏提示
}
private void InitPannels()
{
//刚开始的时候影藏Pannel的列表
for (int i = 0; i < pannelAry.Length; i++)
{
if (pannelDict.ContainsKey(pannelAry[i].MType))
{
CDebug.Log(pannelAry[i].name + " 类型异常");
}
else
{
pannelAry[i].Hide();
pannelDict.Add(pannelAry[i].MType, pannelAry[i]);
}
}
}
private void ResetAllPannelDatas()
{
//刚开始的时候影藏Pannel的列表
for (int i = 0; i < pannelAry.Length; i++)
{
pannelAry[i].InitManagerData();
}
}
private void ChangePannel(PannelType t)
{
if (curType != PannelType.Default)
pannelDict[curType].Hide();
curType = t;
if (curType != PannelType.Default)
pannelDict[curType].Show();
if (curType != PannelType.Question)
{
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HIDE_IMAGE_POP);
}
}
private void ShowPannelByType(System.Object datas = null)
{
PannelType t = (PannelType)datas;
pannelDict[t].InitManagerData();
ChangePannel(t);
OwnerChange();
this.CourseUI.Show();
SetQuanxi(GamePlayerData.Instance.IsFangzhu());
LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
}
private string title_str = "{0}-{1}";
private string user_name_str = "用户名: {0}";
private string room_str = "房间名字: {0}";
private void EnterCourse(System.Object datas = null)
{
UIDataManager.Instance.Init();//清空需要同步的数据
LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
CourseUI.Show();//主面板的初始化
SetQuanxi(GamePlayerData.Instance.IsFangzhu());
if (GamePlayerData.Instance.IsFangzhu())
{
ResetAllPannelDatas();
CDebug.Log("是房主直接打开默认的Pannel");
ChangePannel(PannelType.Goal);
}
else
{
CDebug.Log("不是房主等待同步房主的Pannel");
}
OwnerChange();
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_USER_LIST_DATA);
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_OPEN_COURSE_PANNEL);
}
private void ExitCourse(System.Object datas = null)
{
UIDataManager.Instance.Reset();
//移除有可能存在的答案的弹框
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HIDE_POP_BY_TYPE, PopType.Answer);
CourseUI.Hide();
SetQuanxi(false);
if(pannelDict.ContainsKey(curType))
pannelDict[curType].Hide();
mOnLineUserListPannel.Hide();
mStudentUIPannel.Hide();
LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
UIDataManager.Instance.ClearAll();
}
private void ShowCourse(System.Object datas = null)
{
OwnerChange();
this.CourseUI.Show();
pannelDict[curType].Show();
SetQuanxi(GamePlayerData.Instance.IsFangzhu());
LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
}
private void HideCourse(System.Object datas = null)
{
this.CourseUI.Hide();
mOnLineUserListPannel.Hide();
mStudentUIPannel.Hide();
SetQuanxi(false);
if (pannelDict.ContainsKey(curType))
pannelDict[curType].Hide();
}
private void SetQuanxi(bool v)
{
Quanxi.gameObject.SetActive(false);
}
private void OwnerChange(System.Object data = null)
{
if (GamePlayerData.Instance.user_type == 0 || GamePlayerData.Instance.user_type == 3)
{
mOnLineUserListPannel.Show();
mStudentUIPannel.Hide();
}
else
{
mOnLineUserListPannel.Hide();
mStudentUIPannel.Show();
}
}
private void ShowNotice(System.Object data = null)
{
//CDebug.Log("ShowNotice-->" + data.ToString());
}
private void HideNotice(System.Object data = null)
{
//CDebug.Log("HideNotice-->");
}
private void ShowLogOut(System.Object data = null)
{
//如果当前面板有开启的话 就关掉它
}
private void RefreshChatTip()
{
}
}