| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 | using System.Collections.Generic;using ET;using FairyGUI;using UI.League;using UnityEngine;namespace GFGGame{    //联盟答题中    public class LeagueAnsweringView : BaseWindow    {        private UI_LeagueAnsweringUI _ui;        private GameObject _gameObject0;        private GameObject _gameObject1;        private GoWrapper _wrapper0;        private GoWrapper _wrapper1;        private LeagueDataManager _dataManager;        private List<long> _memberIds;        public override void Dispose()        {            SceneController.DestroyObjectFromView(_gameObject0, _wrapper0);            SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);            if (_ui != null)            {                _ui.Dispose();                _ui = null;            }            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_LeagueAnsweringUI.PACKAGE_NAME;            _ui = UI_LeagueAnsweringUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("lm_beijing2");            _ui.m_btnBack.onClick.Add(OnBtnBackClick);            _ui.m_btnRule.onClick.Add(OnBtnRuleClick);            _ui.m_btnSend.onClick.Add(OnBtnSendClick);            _ui.m_listResult.itemRenderer = RenderListResultItem;            _ui.m_listJoin.itemRenderer = RenderListJoinItem;            _ui.m_listChat.itemRenderer = RenderListChatItem;            _ui.m_listChat.itemProvider = GetListChatItemResource;            _ui.m_listChat.SetVirtual();            _ui.m_txtResult.onFocusOut.Add(OnFocuseOut);            string resPath = ResPathUtil.GetViewEffectPath("ui_league", "Answer_bgtx");            SceneController.AddObjectToView(null, null, _ui.m_holder, resPath, out _gameObject0, out _wrapper0);            string resPath1 = ResPathUtil.GetViewEffectPath("ui_league", "Answer_Succeed");            SceneController.AddObjectToView(null, null, _ui.m_holderHead, resPath1, out _gameObject1, out _wrapper1);        }        protected override void AddEventListener()        {            base.AddEventListener();            EventAgent.AddEventListener(ConstMessage.LEAGUE_ANSWER_START, UpdateQuestion);            EventAgent.AddEventListener(ConstMessage.LEAGUE_ANSWER_END, UpdateResult);            EventAgent.AddEventListener(ConstMessage.LEAGUE_ANSWER_RESULT_CHANGE, UpdateResult);            EventAgent.AddEventListener(ConstMessage.LEAGUE_ANSWER_RESULT_CHANGE, UpdateJoinList);            EventAgent.AddEventListener(ConstMessage.LEAGUE_ANSWER_MEMBER_CHANGE, UpdateJoinList);            EventAgent.AddEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);        }        protected override async void OnShown()        {            base.OnShown();            _dataManager = LeagueDataManager.Instance;            UpdateQuestionState();            UpdateChatList();            bool result = await LeagueSproxy.ReqJoinAnswer();            if (result)            {                UpdateJoinList();            }            UpdateChatList();            Timers.inst.Add(1, 0, UpdateActiveTime);        }        protected override void OnHide()        {            base.OnHide();            Timers.inst.Remove(UpdateAnswerTime);            Timers.inst.Remove(UpdateResultTime);            Timers.inst.Remove(UpdateActiveTime);            _ui.m_holderHead.visible = false;        }        protected override void RemoveEventListener()        {            base.RemoveEventListener();        }        private void OnBtnBackClick()        {            if (_dataManager.LastAnswerRoleData.LastQuestionResult == LastQuestionResult.Ending)            {                LeagueSproxy.ReqQuitAnswer().Coroutine();                ViewManager.GoBackFrom(typeof(LeagueAnsweringView).FullName);            }            else            {                AlertUI.Show("退出活动会损失奖励哦,是否仍要退出?")                .SetLeftButton(true, "否")                .SetRightButton(true, "是", (object data) =>                {                    LeagueSproxy.ReqQuitAnswer().Coroutine();                    ViewManager.GoBackFrom(typeof(LeagueAnsweringView).FullName);                });            }        }        private void OnBtnRuleClick()        {            ViewManager.Show<LeagueAnswerRewardView>();        }        private async void OnBtnSendClick()        {            if (string.IsNullOrEmpty(_ui.m_txtChat.text))            {                PromptController.Instance.ShowFloatTextPrompt("还没有输入想发送的内容哦");                return;            }            bool result = await ChatSProxy.ReqSendChatMsg(ChatType.LeagueQuestion, _ui.m_txtChat.text);            if (result)            {                _ui.m_txtChat.text = "";                UpdateChatList();            }        }        private void UpdateActiveTime(object param)        {            long curTime = TimeHelper.ServerNow();            long endTime = 0;            string str = "";            if (LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.End            || LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.AnswerEnd)            {                endTime = TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.leagueQuestionCloseTime);                str = "房间剩余时间 ";            }            else            {                endTime = TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.leagueQuestionEndTime);                str = "活动剩余时间 ";            }            if (endTime - curTime < 0)            {                Timers.inst.Remove(UpdateResultTime);                ViewManager.GoBackFrom(typeof(LeagueAnsweringView).FullName);                return;            }            _ui.m_txtTime.text = string.Format("{0}{1}", str, TimeUtil.FormattingTimeTo_mmss(endTime - curTime));        }        private void UpdateQuestionState()        {            if (_dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.Open)//答题中            {                UpdateQuestion();            }            else//cd中、答题结束            {                UpdateResult();            }            UpdateJoinList();        }        private void UpdateQuestion()        {            _ui.m_holderHead.visible = false;            _ui.m_txtRightCount.SetVar("value", _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString()).FlushVars(); ;            _ui.m_txtRightCount1.SetVar("value", _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString()).FlushVars(); ;            _ui.m_ctrlQuestionState.selectedIndex = 0;            int questionId = (int)_dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionId);            LeagueQuestionCfg questionCfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId);            _ui.m_txtAnswerNum.text = string.Format("第{0}/{1}题", _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionCount), GlobalCfgArray.globalCfg.leagueQuestionNum);            _ui.m_ctrlHasIcon.selectedIndex = string.IsNullOrEmpty(questionCfg.res) ? 1 : 0;            _ui.m_loaIocn.url = string.IsNullOrEmpty(questionCfg.res) ? "" : ResPathUtil.GetIconPath(questionCfg.res, "png");            _ui.m_txtContent.text = questionCfg.question;            bool isAnswer = !string.IsNullOrEmpty(_dataManager.LastAnswerRoleData.MyAnswer) && _dataManager.LastAnswerRoleData.LastQuestionId == _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionId);            _ui.m_txtResult.text = isAnswer ? _dataManager.LastAnswerRoleData.MyAnswer : "";            _ui.m_txtResult.enabled = !(isAnswer && _dataManager.LastAnswerRoleData.MyAnswer != questionCfg.answerCorrect);            _ui.m_ctrlQuestionType.selectedIndex = questionCfg.type;            if (questionCfg.type == 1)            {                _ui.m_listResult.numItems = questionCfg.answerArr.Length;            }            _ui.m_txtAnswerTime.text = "00:" + GlobalCfgArray.globalCfg.leagueQuestionRunTime.ToString();            Timers.inst.Remove(UpdateAnswerTime);            Timers.inst.Add(1, 0, UpdateAnswerTime);        }        private void UpdateAnswerTime(object param)        {            long curTime = TimeHelper.ServerNow();            long endTime = LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatusEndTime);            if (LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.End            || LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.AnswerEnd            || endTime - curTime < 0)            {                Debug.Log("endTime:" + endTime + "   curTime:" + curTime);                Timers.inst.Remove(UpdateAnswerTime);                return;            }            _ui.m_txtAnswerTime.text = TimeUtil.FormattingTimeTo_mmss((int)(endTime - curTime));        }        private void UpdateResult()        {            _ui.m_ctrlResult.selectedIndex = _dataManager.LastAnswerRoleData.LastQuestionResult;            _ui.m_txtRightCount.text = string.Format("全员已答对{0}题", _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount));            _ui.m_txtRightCount.SetVar("value", _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString()).FlushVars();            _ui.m_txtRightCount1.SetVar("value", _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString()).FlushVars();            _ui.m_txtCdTime.SetVar("value", GlobalCfgArray.globalCfg.leagueQuestionNextTime.ToString()).FlushVars();            _ui.m_ctrlQuestionState.selectedIndex = 1;            if (_dataManager.LastAnswerRoleData.LastQuestionResult == LastQuestionResult.SomeBodyRight)            {                _ui.m_comRightHead.target.visible = true;                _ui.m_imgFail.visible = false;                OtherRoleInfoData roleInfoData = _dataManager.GetMemberRoleInfo(_dataManager.LastAnswerRoleData.RightRoleId);                ItemCfg headCfg = ItemCfgArray.Instance.GetCfg(roleInfoData.headId == 0 ? ConstItemID.HEADID : roleInfoData.headId);                _ui.m_comRightHead.m_loaIcon.url = ResPathUtil.GetHeadPath(headCfg.res);                _ui.m_txtInfo.text = string.Format("{0} 答对了!", roleInfoData.roleName);                _ui.m_holderHead.visible = true;                Timers.inst.Remove(UpdateResultTime);                Timers.inst.Add(1, 0, UpdateResultTime);            }            else if (_dataManager.LastAnswerRoleData.LastQuestionResult == LastQuestionResult.NobodyRight)            {                _ui.m_comRightHead.target.visible = false;                _ui.m_imgFail.visible = true;                _ui.m_txtInfo.text = "哎呀,没人答对呀,大家加油鸭~";                Timers.inst.Remove(UpdateResultTime);                Timers.inst.Add(1, 0, UpdateResultTime);            }            else            {                _ui.m_comRightHead.target.visible = false;                _ui.m_imgFail.visible = false;                if (_dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionCount) == GlobalCfgArray.globalCfg.leagueQuestionNum)//全部答完                {                    _ui.m_txtInfo.text = "全部题目答完啦~";                }                else//答题时间结束                {                    _ui.m_txtInfo.text = "活动结束啦~";                }            }        }        private void UpdateResultTime(object param)        {            long curTime = TimeHelper.ServerNow();            long endTime = LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatusEndTime);            if (LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) != LeagueQuestionStatus.WaitNext            || endTime - curTime < 0)            {                Timers.inst.Remove(UpdateResultTime);                return;            }            _ui.m_txtCdTime.SetVar("value", (((endTime - curTime) / 1000) + 1).ToString()).FlushVars();        }        private void UpdateJoinList()        {            _memberIds = new List<long>(_dataManager.ListAnsweringDatas.Keys);            _ui.m_listJoin.numItems = _memberIds.Count;            _ui.m_txtJoinNum.text = string.Format("当前参与人员:{0}/{1}", _memberIds.Count, _dataManager.LeagueData.LeagueMemberDatas.Count);        }        private void UpdateChatList()        {            _ui.m_listChat.numItems = ChatDataManager.Instance.GetChatDatas(ChatType.LeagueQuestion).Count;            _ui.m_listChat.scrollPane.ScrollBottom(true);        }        private void RenderListResultItem(int index, GObject obj)        {            int questionId = (int)_dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionId);            LeagueQuestionCfg cfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId); ;            UI_Button123 item = UI_Button123.Proxy(obj);            int data = index + 1;            item.target.title = string.Format("{0}.{1}", data, cfg.answerArr[index]);            string myAnswer = _dataManager.LastAnswerRoleData.MyAnswer;            bool isAnswer = !string.IsNullOrEmpty(_dataManager.LastAnswerRoleData.MyAnswer) && _dataManager.LastAnswerRoleData.LastQuestionId == _dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionId);            item.target.touchable = !isAnswer;            item.m_c1.selectedIndex = isAnswer && myAnswer == data.ToString() && myAnswer != cfg.answerCorrect.ToString() ? 0 : 1;            if (item.target.data == null)            {                item.target.onClick.Add(OnBtnChooseClick);            }            item.target.data = data;            UI_Button123.ProxyEnd();        }        private async void OnBtnChooseClick(EventContext context)        {            GObject obj = context.sender as GObject;            string answer = obj.data.ToString();            int questionId = (int)_dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionId);            LeagueQuestionCfg cfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId);            bool result = await LeagueSproxy.ReqAnswerQuestion(questionId, answer);            if (result)            {                _ui.m_listResult.numItems = cfg.answerArr.Length;            }        }        private async void OnFocuseOut()        {            if (string.IsNullOrEmpty(_ui.m_txtResult.text))            {                PromptController.Instance.ShowFloatTextPrompt("还没有输入答案哦");                return;            }            int questionId = (int)_dataManager.GetNumeriValue(LeagueNumericType.LeagueQuestionId);            bool result = await LeagueSproxy.ReqAnswerQuestion(questionId, _ui.m_txtResult.text);            if (result)            {                _ui.m_txtResult.enabled = false;            }        }        private void RenderListJoinItem(int index, GObject obj)        {            OtherRoleInfoData roleInfo = _dataManager.GetMemberRoleInfo(_memberIds[index]);            UI_ListAnswerJoinItem item = UI_ListAnswerJoinItem.Proxy(obj);            RoleInfoManager.Instance.UpdateHead(item.m_comHead, roleInfo.headId, roleInfo.headBorderId);            item.m_txtName.text = roleInfo.roleName;            item.m_txtAnswerCount.text = _dataManager.ListAnsweringDatas[roleInfo.roleId].ToString();            UI_ListAnswerJoinItem.ProxyEnd();        }        private void RenderListChatItem(int index, GObject obj)        {            ChatData chatData = ChatDataManager.Instance.ChatDatas[ChatType.LeagueQuestion][index];            OtherRoleInfoData roleInfo = chatData.RoleInfo;            UI_ListChatItem item = UI_ListChatItem.Proxy(obj);            RoleInfoManager.Instance.UpdateHeadWithLv(item.m_comHead, roleInfo.headId, roleInfo.headBorderId, roleInfo.roleLv);            item.m_txtName.text = roleInfo.roleName;            string content = "";            for (int i = 0; i < chatData.Content.Length; i++)            {                string str = i == 12 * (i + 1) ? chatData.Content[i] + "/n" : chatData.Content[i].ToString();                content += str;            }            item.m_txtChatContent.text = chatData.Content;            UI_ListChatItem.ProxyEnd();        }        private string GetListChatItemResource(int index)        {            if (ChatDataManager.Instance.GetChatDatas(ChatType.LeagueQuestion)[index].RoleInfo.roleId == RoleDataManager.roleId)                return "ui://League/ListChatItemMine";            else                return "ui://League/ListChatItem";        }    }}
 |