123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System;
- using System.Collections.Generic;
- using ET;
- using FairyGUI;
- using UI.CommonGame;
- using UI.ClothingUpgrade;
- using Random = System.Random;
- namespace GFGGame
- {
- class ClothingAnsweringView : BaseWindow
- {
- private UI_ClothingAnsweringUI _ui;
- private int _partIndex;
- private int partIndexCommon;
- private int level;
- private int levelNum;
- private int questionNum = 5;
- private int questIndex = 0;
- private int questionId;
- private int cout;
- public override void Dispose()
- {
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_ClothingAnsweringUI.PACKAGE_NAME;
- _ui = UI_ClothingAnsweringUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- _ui.m_listResult.itemRenderer = RenderListResultItem;
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- }
- protected override void OnShown()
- {
- base.OnShown();
- if (this.viewData != null)
- {
- _partIndex = (int)(this.viewData as object[])[0];
- level = (int)(this.viewData as object[])[1];
- levelNum = (int)(this.viewData as object[])[2];
- }
- if (_partIndex != 99)
- {
- partIndexCommon = 0;
- }
- else
- {
- partIndexCommon = 99;
- }
- _ui.m_bg.url = ResPathUtil.GetBgImgPath("gyp_bg");
- questionNum = CollegeRankCfgArray.Instance.GetCfgByRankPartsIdAndSecondLevelRank(partIndexCommon, level).NumberOfAnswers;
- cout = LeagueQuestionCfgArray.Instance.dataArray.Length + 1;
- questIndex = 0;
- UpdateQuestion();
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- private void RenderListResultItem(int index, GObject obj)
- {
- LeagueQuestionCfg cfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId); ;
- UI_Button123 item = UI_Button123.Proxy(obj);
- int data = index + 1;
- item.m_c1.selectedIndex = 2;
- item.target.title = string.Format("{0}.{1}", data, cfg.answerArr[index]);
- 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;
- int data = (int)obj.data;
- UI_Button123 item = UI_Button123.Proxy(obj);
- LeagueQuestionCfg cfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId);
- //测试 正确答案
- if (data == int.Parse(cfg.answerCorrect))
- {
- item.m_c1.selectedIndex = 1;
- if (questIndex >= questionNum)
- {
- //发送升级
- var result = await CollegeSProxy.ReqCollectUpgrade(_partIndex, level, levelNum);
- string exitTip = "恭喜恭喜!晋升成功!";
- AlertUI.Show(exitTip)
- .SetLeftButton(false, "取消", (object data) =>
- {
- })
- .SetRightButton(true, "确定", (object data) =>
- {
- //退出
- ViewManager.GoBackFrom(typeof(ClothingAnsweringView).FullName);
- });
- }
- else
- {
- UpdateQuestion();
- }
- PromptController.Instance.ShowFloatTextPrompt("回答正确!");
- }
- else
- {
- PromptController.Instance.ShowFloatTextPrompt("回答错误!");
- item.m_c1.selectedIndex = 0;
- }
- UI_Button123.ProxyEnd();
- }
- private void UpdateQuestion()
- {
- questIndex++;
- Random random = new Random();
- questionId = random.Next(1, cout); // 生成1到cout之间的随机整数
- LeagueQuestionCfg questionCfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId);
- _ui.m_txtAnswerNum.text = string.Format("第{0}/{1}题", questIndex,questionNum);
- _ui.m_txtContent.text = questionCfg.question;
- _ui.m_listResult.numItems = questionCfg.answerArr.Length;
- }
- private void OnClickBtnBack()
- {
- string exitTip = "是否退出,退出后将不保存答题进度,并且下次题目将随机出现";
- AlertUI.Show(exitTip)
- .SetLeftButton(true, "取消", (object data) =>
- {
- })
- .SetRightButton(true, "确定", (object data) =>
- {
- ViewManager.GoBackFrom(typeof(ClothingAnsweringView).FullName);
- });
- }
- }
- }
|