源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

185 wiersze
7.1 KiB

4 tygodni temu
  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 藏宝图 答题界面
  4. -- *>
  5. TreasureMapQuizView = TreasureMapQuizView or BaseClass(BaseView)
  6. local TreasureMapQuizView = TreasureMapQuizView
  7. function TreasureMapQuizView:__init()
  8. self.base_file = "treasureMap"
  9. self.layout_file = "TreasureMapQuizView"
  10. self.layer_name = "UI"
  11. self.destroy_imm = true
  12. self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
  13. self.hide_maincancas = false --全屏界面需要隐藏主UI
  14. self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
  15. self.model = TreasureMapModel:getInstance()
  16. self.ans_seq = {
  17. [1] = "A", [2] = "B", [3] = "C", [4] = "D",
  18. }
  19. self.ans_item = {}
  20. self.auto_close_time = 30 -- 几秒后自动关闭
  21. self.selected_index = false -- 是否已经选择了选项
  22. self.load_callback = function ()
  23. self:LoadSuccess()
  24. self:AddEvent()
  25. end
  26. self.open_callback = function ( )
  27. self:UpdateView()
  28. end
  29. self.destroy_callback = function ( )
  30. self:DestroySuccess()
  31. end
  32. end
  33. function TreasureMapQuizView:Open(data)
  34. self.data = data
  35. BaseView.Open(self)
  36. end
  37. function TreasureMapQuizView:LoadSuccess()
  38. local nodes = {
  39. "bg:raw", "quiz_role:raw", "close_btn:obj",
  40. "ans_con",
  41. "reward_con",
  42. "ques_lb:tmp",
  43. "sub_title:tmp",
  44. "auto_close:tmp",
  45. }
  46. self:GetChildren(nodes)
  47. lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("tm_quiz_bg"))
  48. lua_resM:setOutsideRawImage(self, self.quiz_role_raw, GameResPath.GetRoleBg("tm_quiz_role_431_618"))
  49. self.sub_title_tmp.text = string.format("没想到居然有人能找到这来,你运气不错嘛!\n来吧,出道题考考你!")
  50. self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.reward_con)
  51. self.awardItem:SetItemSize(78, 78)
  52. self.awardItem:SetAnchoredPosition(0, 0)
  53. end
  54. function TreasureMapQuizView:AddEvent()
  55. local function click_event(target)
  56. if target == self.close_btn_obj then
  57. self:Close()
  58. end
  59. end
  60. AddClickEvent(self.close_btn_obj, click_event)
  61. local function updateViewAfterSelectedAns()
  62. self:UpdateSelectedResult()
  63. end
  64. self:BindEvent(self.model, TreasureMapConst.UPDATE_QUIZ_VIEW, updateViewAfterSelectedAns)
  65. end
  66. function TreasureMapQuizView:UpdateView()
  67. self.quiz_cfg = Config.Treasuremapquiz[self.data.quiz_id]
  68. self.reward_cfg = Config.Treasuremaprewards[self.data.reward_id]
  69. self:UpdateBasicData()
  70. self:AutoCloseTimer()
  71. end
  72. -- 加载谜题等基础数据
  73. function TreasureMapQuizView:UpdateBasicData( )
  74. if self.quiz_cfg then -- 加载谜题和选项
  75. self.ques_lb_tmp.text = Trim(self.quiz_cfg.question)
  76. local ans_data = stringtotable(self.quiz_cfg.option)
  77. self.ans_data = RandomizeSequenceTableData(ans_data)
  78. self.ans_item_creator = self.ans_item_creator or self:AddUIComponent(UI.ItemListCreator)
  79. local info = {
  80. data_list = self.ans_data,
  81. item_con = self.ans_con,
  82. scroll_view = self.ans_con,
  83. prefab_ab_name = "treasureMap",
  84. prefab_res_name = "TreasureMapQuizAnsItem",
  85. item_width = 158,
  86. item_height = 42,
  87. start_y = -5,
  88. space_x = 30,
  89. space_y = 20,
  90. create_frequency = 0.01,
  91. alignment = UnityEngine.TextAnchor.UpperLeft,
  92. child_names = {
  93. "ans_btn:obj", "ans_btn/ans_lb:tmp",
  94. },
  95. on_update_item = function(item, i, v)
  96. item.ans_lb_tmp.text = string.format("%s.%s", self.ans_seq[i], Trim(v[2]))
  97. local function click_event(target)
  98. if target == item.ans_btn_obj then
  99. if self.selected_index then return end -- 选中了答案之后就不处理
  100. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42408, self.data.quiz_id, v[1])
  101. self.selected_index = i
  102. end
  103. end
  104. AddClickEvent(item.ans_btn_obj, click_event)
  105. end,
  106. }
  107. self.ans_item_creator:UpdateItems(info)
  108. end
  109. -- 加载奖励节点
  110. if self.reward_cfg then
  111. local reward = stringtotable(self.reward_cfg.rewards)[1] or {}
  112. local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(reward[1] , reward[2])
  113. self.awardItem:SetData(goods_Id, reward[3], nil, nil, lock)
  114. end
  115. end
  116. function TreasureMapQuizView:AutoCloseTimer( )
  117. local end_time = TimeUtil:getServerTime() + self.auto_close_time
  118. local function auto_close_time_func()
  119. local left_time = end_time - TimeUtil:getServerTime()
  120. if left_time > 0 then
  121. self.auto_close_tmp.text = self.selected_index
  122. and string.format("<color=%s>%s</color> 秒后自动关闭", ColorUtil.GREEN_DARK, left_time)
  123. or string.format("(回答正确可得双倍奖励,<color=%s>%s</color> 秒后自动选择)",
  124. ColorUtil.GREEN_DARK, left_time)
  125. else
  126. if not self.selected_index then
  127. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42408, self.data.quiz_id, 1)
  128. else
  129. self:Close()
  130. end
  131. end
  132. end
  133. self:ClearAutoCloseTimer()
  134. self.auto_close_time_func_id = GlobalTimerQuest:AddPeriodQuest(auto_close_time_func, 0.5, -1)
  135. end
  136. function TreasureMapQuizView:ClearAutoCloseTimer( )
  137. if self.auto_close_time_func_id then
  138. GlobalTimerQuest:CancelQuest(self.auto_close_time_func_id)
  139. self.auto_close_time_func_id = nil
  140. end
  141. end
  142. -- 根据08协议的返回更新界面表现
  143. function TreasureMapQuizView:UpdateSelectedResult( )
  144. if self.quiz_cfg then -- 加载谜题和选项
  145. self.ans_item_creator:IterateItems(function( item, i )
  146. if i == self.selected_index then
  147. local ans_data = self.ans_data[i]
  148. local ans_currect = ans_data[1] == self.quiz_cfg.answer
  149. item.ans_lb_tmp.text = string.format("<color=%s>%s.%s</color>",
  150. ans_currect and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK,
  151. self.ans_seq[i], Trim(ans_data[2]))
  152. -- 飘字表现
  153. Message.show(ans_currect and "回答正确,获得双倍奖励~" or "回答错误", ans_currect and "success" or "fault")
  154. end
  155. end)
  156. -- 重置自动关闭时间
  157. self.auto_close_time = 5
  158. self:AutoCloseTimer()
  159. end
  160. end
  161. function TreasureMapQuizView:DestroySuccess( )
  162. if self.awardItem then
  163. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
  164. self.awardItem = nil
  165. end
  166. self:ClearAutoCloseTimer()
  167. -- 没选的话自动选中第一个
  168. if not self.selected_index then
  169. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42408, self.data.quiz_id, 1)
  170. end
  171. self.model._check_tm_tips = TreasureMapConst.Normal
  172. self.model:CheckTreasureTipUseViewOpen()
  173. end