ClothingAnsweringView.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.CommonGame;
  6. using UI.ClothingUpgrade;
  7. using Random = System.Random;
  8. namespace GFGGame
  9. {
  10. class ClothingAnsweringView : BaseWindow
  11. {
  12. private UI_ClothingAnsweringUI _ui;
  13. private int _partIndex;
  14. private int partIndexCommon;
  15. private int level;
  16. private int levelNum;
  17. private int questionNum = 5;
  18. private int questIndex = 0;
  19. private int questionId;
  20. private int cout;
  21. public override void Dispose()
  22. {
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_ClothingAnsweringUI.PACKAGE_NAME;
  29. _ui = UI_ClothingAnsweringUI.Create();
  30. this.viewCom = _ui.target;
  31. this.viewCom.Center();
  32. _ui.m_listResult.itemRenderer = RenderListResultItem;
  33. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  34. }
  35. protected override void OnShown()
  36. {
  37. base.OnShown();
  38. if (this.viewData != null)
  39. {
  40. _partIndex = (int)(this.viewData as object[])[0];
  41. level = (int)(this.viewData as object[])[1];
  42. levelNum = (int)(this.viewData as object[])[2];
  43. }
  44. if (_partIndex != 99)
  45. {
  46. partIndexCommon = 0;
  47. }
  48. else
  49. {
  50. partIndexCommon = 99;
  51. }
  52. _ui.m_bg.url = ResPathUtil.GetBgImgPath("gyp_bg");
  53. questionNum = CollegeRankCfgArray.Instance.GetCfgByRankPartsIdAndSecondLevelRank(partIndexCommon, level).NumberOfAnswers;
  54. cout = LeagueQuestionCfgArray.Instance.dataArray.Length + 1;
  55. questIndex = 0;
  56. UpdateQuestion();
  57. }
  58. protected override void OnHide()
  59. {
  60. base.OnHide();
  61. }
  62. private void RenderListResultItem(int index, GObject obj)
  63. {
  64. LeagueQuestionCfg cfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId); ;
  65. UI_Button123 item = UI_Button123.Proxy(obj);
  66. int data = index + 1;
  67. item.m_c1.selectedIndex = 2;
  68. item.target.title = string.Format("{0}.{1}", data, cfg.answerArr[index]);
  69. if (item.target.data == null)
  70. {
  71. item.target.onClick.Add(OnBtnChooseClick);
  72. }
  73. item.target.data = data;
  74. UI_Button123.ProxyEnd();
  75. }
  76. private async void OnBtnChooseClick(EventContext context)
  77. {
  78. GObject obj = context.sender as GObject;
  79. int data = (int)obj.data;
  80. UI_Button123 item = UI_Button123.Proxy(obj);
  81. LeagueQuestionCfg cfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId);
  82. //测试 正确答案
  83. if (data == int.Parse(cfg.answerCorrect))
  84. {
  85. item.m_c1.selectedIndex = 1;
  86. if (questIndex >= questionNum)
  87. {
  88. //发送升级
  89. var result = await CollegeSProxy.ReqCollectUpgrade(_partIndex, level, levelNum);
  90. string exitTip = "恭喜恭喜!晋升成功!";
  91. AlertUI.Show(exitTip)
  92. .SetLeftButton(false, "取消", (object data) =>
  93. {
  94. })
  95. .SetRightButton(true, "确定", (object data) =>
  96. {
  97. //退出
  98. ViewManager.GoBackFrom(typeof(ClothingAnsweringView).FullName);
  99. });
  100. }
  101. else
  102. {
  103. UpdateQuestion();
  104. }
  105. PromptController.Instance.ShowFloatTextPrompt("回答正确!");
  106. }
  107. else
  108. {
  109. PromptController.Instance.ShowFloatTextPrompt("回答错误!");
  110. item.m_c1.selectedIndex = 0;
  111. }
  112. UI_Button123.ProxyEnd();
  113. }
  114. private void UpdateQuestion()
  115. {
  116. questIndex++;
  117. Random random = new Random();
  118. questionId = random.Next(1, cout); // 生成1到cout之间的随机整数
  119. LeagueQuestionCfg questionCfg = LeagueQuestionCfgArray.Instance.GetCfg(questionId);
  120. _ui.m_txtAnswerNum.text = string.Format("第{0}/{1}题", questIndex,questionNum);
  121. _ui.m_txtContent.text = questionCfg.question;
  122. _ui.m_listResult.numItems = questionCfg.answerArr.Length;
  123. }
  124. private void OnClickBtnBack()
  125. {
  126. string exitTip = "是否退出,退出后将不保存答题进度,并且下次题目将随机出现";
  127. AlertUI.Show(exitTip)
  128. .SetLeftButton(true, "取消", (object data) =>
  129. {
  130. })
  131. .SetRightButton(true, "确定", (object data) =>
  132. {
  133. ViewManager.GoBackFrom(typeof(ClothingAnsweringView).FullName);
  134. });
  135. }
  136. }
  137. }