源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

182 行
4.8 KiB

  1. GuideIntroduceView = GuideIntroduceView or BaseClass(BaseView)
  2. local GuideIntroduceView = GuideIntroduceView
  3. function GuideIntroduceView:__init()
  4. self.base_file = "guide"
  5. self.layout_file = "GuideIntroduceView"
  6. self.layer_name = "Top"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.is_set_order_sorting = false
  10. self.is_set_zdepth = true
  11. self.model = GuideModel:getInstance()
  12. self.load_callback = function ()
  13. self:LoadSuccess()
  14. self:InitEvent()
  15. end
  16. self.open_callback = function ()
  17. self:InitView()
  18. end
  19. self.close_callback = function ()
  20. GlobalEventSystem:Fire(EventName.START_AUTO_DO_TASK)
  21. end
  22. self.destroy_callback = function ()
  23. self:Clear()
  24. end
  25. end
  26. function GuideIntroduceView:Open(helpVo)
  27. self.helpVo = helpVo
  28. BaseView.Open(self)
  29. end
  30. function GuideIntroduceView:Clear()
  31. self:CancelTimer()
  32. end
  33. function GuideIntroduceView:Close()
  34. BaseView.Close(self)
  35. end
  36. function GuideIntroduceView:LoadSuccess()
  37. self.black_bg,
  38. self.nameCon = self:GetChildTransforms({
  39. "Mask",
  40. "nameCon",
  41. })
  42. self.chapter_name_txt,
  43. self.sub_chapter_name_txt,
  44. self.content_txt,
  45. self.time = self:GetChildTexts({
  46. "Name",
  47. "SubName",
  48. "Content",
  49. "time",
  50. })
  51. self.jumpBtn
  52. = GetChildGameObjects(self.transform,
  53. {
  54. "jumpBtn",
  55. })
  56. self.black_bg.sizeDelta = Vector2(ScreenWidth,ScreenHeight)
  57. self.black_bg.gameObject:SetActive(false)
  58. end
  59. function GuideIntroduceView:InitEvent()
  60. local function onClickHandler(target)
  61. if target == self.jumpBtn then
  62. self:Close()
  63. end
  64. end
  65. AddClickEvent(self.jumpBtn, onClickHandler, 2)
  66. end
  67. function GuideIntroduceView:InitView()
  68. if not self.helpVo then
  69. return
  70. end
  71. self:SetNameImage()
  72. -- self.chapter_name_txt.text = self.helpVo.chapter or ""
  73. self.sub_chapter_name_txt.text = self.helpVo.sub_chapter or ""
  74. self.content_txt.text = Trim(self.helpVo.saying) or ""
  75. self.time_num = 5
  76. self.time.text = "("..self.time_num.."秒后自动关闭)"
  77. -- local func = function ()
  78. -- if self._use_delete_method then
  79. -- return
  80. -- end
  81. -- self:CancelTimer()
  82. -- self:FinishHelp()
  83. -- self:Close()
  84. -- end
  85. -- self.timer_id = TimerQuest.AddDelayQuest(GlobalTimerQuest, func, self.time_num)
  86. local function onTimer()
  87. self.time_num = self.time_num - 1
  88. self.time.text = "("..self.time_num.."秒后自动关闭)"
  89. if self.time_num <= 0 then
  90. self:CancelTimer()
  91. self:FinishHelp()
  92. self:Close()
  93. end
  94. end
  95. self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  96. end
  97. function GuideIntroduceView:CancelTimer()
  98. if self.timer_id then
  99. TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_id)
  100. self.timer_id = nil
  101. end
  102. end
  103. function GuideIntroduceView:FinishHelp( )
  104. --结束引导
  105. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.SHOW_CHAPTER,1)
  106. if helpVo then
  107. GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
  108. end
  109. end
  110. --设置名字图片
  111. function GuideIntroduceView:SetNameImage()
  112. if not self.helpVo then return end
  113. -- 这里的chapter默认是 1,2..21..33等罗马数字的这种格式
  114. if self.helpVo.chapter then
  115. local vo = self.helpVo.chapter
  116. -- local vo = "31"
  117. local num_table = self:GetNumber(vo)
  118. -- local num_len = string.len(vo)
  119. local num_len = #num_table
  120. self.nameCon.sizeDelta = co.TableXY((num_len + 2)*52, self.nameCon.sizeDelta.y)
  121. local image_root
  122. local image_icon
  123. local res = "icon_zj_"
  124. local first_pos
  125. image_root = UiFactory.createChild(self.nameCon, UIType.ImageExtend) --先创建 "第" 字
  126. image_icon = image_root:GetComponent("ImageExtend")
  127. SetAnchoredPosition(image_root.transform, -(num_len + 2)*52/2 + 26, 0)
  128. lua_resM:setImageSprite(self, image_icon, "guide_asset", res.."0", true)
  129. first_pos = -(num_len + 2)*52/2 + 26
  130. if num_table then
  131. for k,v in pairs(num_table) do
  132. image_root = UiFactory.createChild(self.nameCon, UIType.ImageExtend) --再创建 中间的数字
  133. image_icon = image_root:GetComponent("ImageExtend")
  134. first_pos = first_pos + 52
  135. SetAnchoredPosition(image_root.transform, first_pos, 0)
  136. lua_resM:setImageSprite(self, image_icon, "guide_asset", res..v, true)
  137. end
  138. end
  139. image_root = UiFactory.createChild(self.nameCon, UIType.ImageExtend) --最后创建 "章" 字
  140. image_icon = image_root:GetComponent("ImageExtend")
  141. SetAnchoredPosition(image_root.transform, (num_len + 2)*52/2 - 26, 0)
  142. lua_resM:setImageSprite(self, image_icon, "guide_asset", res.."11", true)
  143. end
  144. end
  145. function GuideIntroduceView:GetNumber(num)
  146. local num_table = {}
  147. local num = tonumber(num)
  148. if num >= 1 and num <= 10 then
  149. table.insert(num_table, num)
  150. elseif num > 10 and num <= 19 then
  151. table.insert(num_table, 10)
  152. table.insert(num_table, num - 10)
  153. elseif num > 10 and num <= 99 then
  154. local ten, unit = math.modf(num/10)
  155. table.insert(num_table, ten)
  156. table.insert(num_table, 10)
  157. table.insert(num_table, unit * 10)
  158. end
  159. return num_table
  160. end