| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- using System.Collections.Generic;
- using System.Linq;
- using cfg.GfgCfg;
- 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 List<long> _memberIds; //该玩家id列表,会按照答题数量降序排列
- 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;
- isReturnView = true;
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
- _ui.m_btnBack.onClick.Add(OnBtnBackClick);
- _ui.m_btnRule.onClick.Add(OnBtnRuleClick);
- _ui.m_btnSend.target.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);
- EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_league", "Answer_bgtx",
- onComplete: (effect) =>
- {
- if (effect != null)
- {
- _effectUI1 = effect;
- }
- });
- EffectUIPool.CreateEffectUI(_ui.m_holderHead, "ui_league", "Answer_Succeed",
- onComplete: (effect) =>
- {
- if (effect != null)
- {
- _effectUI2 = effect;
- }
- });
- }
- 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);
- EventAgent.AddEventListener(ConstMessage.LEAGUE_ANSWER_INFO, ReferInfo);
- }
- protected override void RemoveEventListener()
- {
- EventAgent.RemoveEventListener(ConstMessage.LEAGUE_ANSWER_START, UpdateQuestion);
- EventAgent.RemoveEventListener(ConstMessage.LEAGUE_ANSWER_END, UpdateResult);
- EventAgent.RemoveEventListener(ConstMessage.LEAGUE_ANSWER_RESULT_CHANGE, UpdateResult);
- EventAgent.RemoveEventListener(ConstMessage.LEAGUE_ANSWER_RESULT_CHANGE, UpdateJoinList);
- EventAgent.RemoveEventListener(ConstMessage.LEAGUE_ANSWER_MEMBER_CHANGE, UpdateJoinList);
- EventAgent.RemoveEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);
- EventAgent.RemoveEventListener(ConstMessage.LEAGUE_ANSWER_INFO, ReferInfo);
- base.RemoveEventListener();
- }
- protected override void OnShown()
- {
- base.OnShown();
- LeagueSproxy.ReqJoinAnswer().Coroutine();
- }
- protected override void OnHide()
- {
- base.OnHide();
- Timers.inst.Remove(UpdateAnswerTime);
- Timers.inst.Remove(UpdateResultTime);
- Timers.inst.Remove(UpdateActiveTime);
- _ui.m_holderHead.visible = false;
- }
- private void ReferInfo()
- {
- UpdateJoinList();
- UpdateQuestionState();
- UpdateChatList();
- Timers.inst.Add(1, 0, UpdateActiveTime);
- }
- private void OnBtnBackClick()
- {
- if (LeagueDataManager.Instance.LastAnswerRoleData.LastQuestionResult == LastQuestionResult.Ending)
- {
- LeagueSproxy.ReqQuitAnswer().Coroutine();
- // ViewManager.GoBackFrom(typeof(LeagueAnsweringView).FullName);
- Hide();
- }
- else
- {
- AlertUI.Show("退出活动会损失奖励哦,是否仍要退出?")
- .SetLeftButton(true, "否")
- .SetRightButton(true, "是", (object data) =>
- {
- LeagueSproxy.ReqQuitAnswer().Coroutine();
- // ViewManager.GoBackFrom(typeof(LeagueAnsweringView).FullName);
- Hide();
- });
- }
- }
- private void OnBtnRuleClick()
- {
- ViewManager.Show<LeagueAnswerRewardView>();
- }
- private async void OnBtnSendClick()
- {
- if (_ui.m_btnSend.m_c1.selectedIndex == 1)
- {
- PromptController.Instance.ShowFloatTextPrompt("消息发送频繁");
- return;
- }
- 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();
- int num = CommonDataManager.Tables.TblGlobalCfg.ChatTime;
- _ui.m_btnSend.m_timeStr.text = num.ToString();
- _ui.m_btnSend.m_c1.selectedIndex = 1;
- Timers.inst.Add(1, 10, (param) =>
- {
- num--;
- _ui.m_btnSend.m_timeStr.text = num.ToString();
- if (num == 0)
- {
- _ui.m_btnSend.m_c1.selectedIndex = 0;
- }
- });
- }
- }
- private void UpdateActiveTime(object param)
- {
- long curTime = TimeHelper.ServerNow();
- long endTime = 0;
- string str = "";
- //leagueQuestionStartTimeArr与leagueQuestionCloseTimeArr与leagueQuestionEndTimeArr数组长度相同,且索引对应。跟曾威定的
- int curIndex =
- DateUtil.GetNearestStartTimeIndex(CommonDataManager.Tables.TblGlobalCfg.LeagueQuestionCloseTime);
- if (LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) ==
- LeagueQuestionStatus.End
- || LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) ==
- LeagueQuestionStatus.AnswerEnd)
- {
- endTime = TimeUtil.GetCurDayTime(
- CommonDataManager.Tables.TblGlobalCfg.LeagueQuestionCloseTime[curIndex]);
- str = "房间剩余时间 ";
- }
- else
- {
- endTime = TimeUtil.GetCurDayTime(CommonDataManager.Tables.TblGlobalCfg.LeagueQuestionEndTime[curIndex]);
- str = "活动剩余时间 ";
- }
- if (endTime - curTime < 0 &&
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) ==
- LeagueQuestionStatus.End)
- {
- Timers.inst.Remove(UpdateResultTime);
- // ViewManager.GoBackFrom(typeof(LeagueAnsweringView).FullName);
- Hide();
- return;
- }
- _ui.m_txtTime.text = string.Format("{0}[color=#E07748]{1}[/color]", str,
- TimeUtil.FormattingTimeTo_mmss(endTime - curTime));
- }
- private void UpdateQuestionState()
- {
- if (LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionStatus) ==
- LeagueQuestionStatus.Open) //答题中
- {
- UpdateQuestion();
- }
- else //cd中、答题结束
- {
- UpdateResult();
- }
- UpdateJoinList();
- }
- private void UpdateQuestion()
- {
- _ui.m_holderHead.visible = false;
- _ui.m_txtRightCount.SetVar("value",
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString())
- .FlushVars();
- ;
- _ui.m_txtRightCount1.SetVar("value",
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString())
- .FlushVars();
- ;
- _ui.m_ctrlQuestionState.selectedIndex = 0;
- int questionId = (int)LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionId);
- LeagueQuestionCfg questionCfg = CommonDataManager.Tables.TblLeagueQuestionCfg.GetOrDefault(questionId);
- _ui.m_txtAnswerNum.text = string.Format("第{0}/{1}题",
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionCount),
- CommonDataManager.Tables.TblGlobalCfg.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(LeagueDataManager.Instance.LastAnswerRoleData.MyAnswer) &&
- LeagueDataManager.Instance.LastAnswerRoleData.LastQuestionId ==
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionId);
- _ui.m_txtResult.text = isAnswer ? LeagueDataManager.Instance.LastAnswerRoleData.MyAnswer : "";
- _ui.m_txtResult.enabled = !(isAnswer &&
- LeagueDataManager.Instance.LastAnswerRoleData.MyAnswer !=
- questionCfg.AnswerCorrect);
- _ui.m_imgFault.visible = isAnswer &&
- LeagueDataManager.Instance.LastAnswerRoleData.MyAnswer !=
- questionCfg.AnswerCorrect;
- _ui.m_ctrlQuestionType.selectedIndex = questionCfg.Type;
- if (questionCfg.Type == 1)
- {
- _ui.m_listResult.numItems = questionCfg.Answer.Count;
- }
- _ui.m_txtAnswerTime.text = "00:" + CommonDataManager.Tables.TblGlobalCfg.LeagueQuestionRunTime;
- 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 = LeagueDataManager.Instance.LastAnswerRoleData.LastQuestionResult;
- _ui.m_txtRightCount.text = string.Format("全员已答对[color=#AF5638]{0}[/color]题",
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount));
- _ui.m_txtRightCount.SetVar("value",
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString())
- .FlushVars();
- _ui.m_txtRightCount1.SetVar("value",
- LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionTrueCount).ToString())
- .FlushVars();
- _ui.m_txtCdTime.SetVar("value", CommonDataManager.Tables.TblGlobalCfg.LeagueQuestionNextTime.ToString())
- .FlushVars();
- _ui.m_ctrlQuestionState.selectedIndex = 1;
- if (LeagueDataManager.Instance.LastAnswerRoleData.LastQuestionResult == LastQuestionResult.SomeBodyRight)
- {
- _ui.m_comRightHead.target.visible = true;
- _ui.m_imgFail.visible = false;
- OtherRoleInfoData roleInfoData =
- LeagueDataManager.Instance.GetMemberRoleInfo(LeagueDataManager.Instance.LastAnswerRoleData
- .RightRoleId);
- ItemCfg headCfg =
- CommonDataManager.Tables.TblItemCfg.GetOrDefault(roleInfoData.headId == 0
- ? ConstItemID.HEADID
- : roleInfoData.headId);
- _ui.m_comRightHead.m_loaIcon.url = ResPathUtil.GetHeadPath(headCfg.Res);
- _ui.m_txtInfo.text = string.Format("{0} [color=#915E15]答对了![/color]", roleInfoData.roleName);
- _ui.m_holderHead.visible = true;
- Timers.inst.Remove(UpdateResultTime);
- Timers.inst.Add(1, 0, UpdateResultTime);
- }
- else if (LeagueDataManager.Instance.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 (LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionCount) ==
- CommonDataManager.Tables.TblGlobalCfg.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 = LeagueDataManager.Instance.ListAnsweringDatas
- .OrderByDescending(pair => pair.Value) // 按值(答题数量)降序排序
- .Select(pair => pair.Key)
- .ToList();
- _ui.m_listJoin.numItems = _memberIds.Count;
- _ui.m_txtJoinNum.text = string.Format("当前参与人员:{0}/{1}", _memberIds.Count,
- LeagueDataManager.Instance.LeagueData.LeagueMemberDatas.Count);
- }
- private void UpdateChatList()
- {
- _memberIds.Sort((long a, long b) =>
- {
- int countA = LeagueDataManager.Instance.ListAnsweringDatas[a];
- int countB = LeagueDataManager.Instance.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)LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionId);
- LeagueQuestionCfg cfg = CommonDataManager.Tables.TblLeagueQuestionCfg.GetOrDefault(questionId);
- ;
- UI_Button123 item = UI_Button123.Proxy(obj);
- int data = index + 1;
- item.target.title = string.Format("{0}.{1}", data, cfg.Answer[index]);
- //测试 正确答案
- //if (data == int.Parse(cfg.answerCorrect))
- //{
- // item.target.title = string.Format("{0}.{1} 正确", data, cfg.answerArr[index]);
- //}
- string myAnswer = LeagueDataManager.Instance.LastAnswerRoleData.MyAnswer;
- bool isAnswer = !string.IsNullOrEmpty(LeagueDataManager.Instance.LastAnswerRoleData.MyAnswer) &&
- LeagueDataManager.Instance.LastAnswerRoleData.LastQuestionId ==
- LeagueDataManager.Instance.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)LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionId);
- LeagueQuestionCfg cfg = CommonDataManager.Tables.TblLeagueQuestionCfg.GetOrDefault(questionId);
- bool result = await LeagueSproxy.ReqAnswerQuestion(questionId, answer);
- if (result)
- {
- _ui.m_listResult.numItems = cfg.Answer.Count;
- }
- }
- private async void OnFocuseOut()
- {
- if (string.IsNullOrEmpty(_ui.m_txtResult.text))
- {
- PromptController.Instance.ShowFloatTextPrompt("还没有输入答案哦");
- return;
- }
- int questionId = (int)LeagueDataManager.Instance.GetNumeriValue(LeagueNumericType.LeagueQuestionId);
- bool result = await LeagueSproxy.ReqAnswerQuestion(questionId, _ui.m_txtResult.text);
- if (result)
- {
- LeagueQuestionCfg questionCfg = CommonDataManager.Tables.TblLeagueQuestionCfg.GetOrDefault(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 = LeagueDataManager.Instance.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 = LeagueDataManager.Instance.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 && roldRank > 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";
- }
- }
- }
|