| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 | 
							- using System.Collections.Generic;
 
- using ET;
 
- using FairyGUI;
 
- using Hutool;
 
- using UI.League;
 
- using UnityEngine;
 
- namespace GFGGame
 
- {
 
-     //联盟答题中
 
-     public class LeagueAnsweringView : BaseWindow
 
-     {
 
-         private UI_LeagueAnsweringUI _ui;
 
-         private EffectUI _effectUI1;
 
-         private EffectUI _effectUI2;
 
-         private LeagueDataManager _dataManager;
 
-         private List<long> _memberIds;
 
-         public override void Dispose()
 
-         {
 
-             EffectUIPool.Recycle(_effectUI1);
 
-             _effectUI1 = null;
 
-             EffectUIPool.Recycle(_effectUI2);
 
-             _effectUI2 = null;
 
-             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);
 
-             _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_league", "Answer_bgtx");
 
-             _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderHead, "ui_league", "Answer_Succeed");
 
-         }
 
-         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;
 
-             bool result = await LeagueSproxy.ReqJoinAnswer();
 
-             if (result)
 
-             {
 
-                 UpdateJoinList();
 
-             }
 
-             UpdateQuestionState();
 
-             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 = "";
 
-             //leagueQuestionStartTimeArr与leagueQuestionCloseTimeArr与leagueQuestionEndTimeArr数组长度相同,且索引对应。跟曾威定的
 
-             int curIndex = DateUtil.GetNearestStartTimeIndex(GlobalCfgArray.globalCfg.leagueQuestionCloseTimeArr);
 
-             if (LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.End
 
-             || LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.AnswerEnd)
 
-             {
 
-                 endTime = TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.leagueQuestionCloseTimeArr[curIndex]);
 
-                 str = "房间剩余时间 ";
 
-             }
 
-             else
 
-             {
 
-                 endTime = TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.leagueQuestionEndTimeArr[curIndex]);
 
-                 str = "活动剩余时间 ";
 
-             }
 
-             if (endTime - curTime < 0 && LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) == LeagueQuestionStatus.End)
 
-             {
 
-                 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_imgFault.visible = 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()
 
-         {
 
-             _memberIds.Sort((long a, long b) =>
 
-             {
 
-                 int countA = _dataManager.ListAnsweringDatas[a];
 
-                 int countB = _dataManager.ListAnsweringDatas[b];
 
-                 if (countA > countB) return -1;
 
-                 if (countB > countA) return 1;
 
-                 return countB - countA;
 
-             });
 
-             _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]);
 
-             //测试 正确答案
 
-            // if (data == int.Parse(cfg.answerCorrect))
 
-            // {
 
-             //    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)
 
-             {
 
-                 LeagueQuestionCfg questionCfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId);
 
-                 _ui.m_txtResult.enabled = false;
 
-                 _ui.m_imgFault.visible = _ui.m_txtResult.text != questionCfg.answerCorrect;
 
-             }
 
-         }
 
-         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_ListChatAnswerItem item = UI_ListChatAnswerItem.Proxy(obj);
 
-             RoleInfoManager.Instance.UpdateHeadWithLv(item.m_comHead, roleInfo.headId, roleInfo.headBorderId, roleInfo.roleLv);
 
-             item.m_txtName.text = roleInfo.roleName;
 
-             int roldRank = _memberIds.IndexOf(roleInfo.roleId);
 
-             item.m_c1.selectedIndex = roldRank < 3 && _dataManager.ListAnsweringDatas[roleInfo.roleId] > 0 ? roldRank : 3;
 
-             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_ListChatAnswerItem.ProxyEnd();
 
-         }
 
-         private string GetListChatItemResource(int index)
 
-         {
 
-             if (ChatDataManager.Instance.GetChatDatas(ChatType.LeagueQuestion)[index].RoleInfo.roleId == RoleDataManager.roleId)
 
-                 return "ui://League/ListChatAnswerItemMine";
 
-             else
 
-                 return "ui://League/ListChatAnswerItem";
 
-         }
 
-     }
 
- }
 
 
  |