源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 rivejä
5.6 KiB

4 viikkoa sitten
  1. --圆形cd
  2. CirCleCdView = CirCleCdView or BaseClass(BaseComponent)
  3. local CirCleCdView = CirCleCdView
  4. local math_ceil = math.ceil
  5. local string_format = string.format
  6. function CirCleCdView:__init(handle_wnd, callback, is_base_skill, skill_id, width, height, font_size)
  7. self:InitData(callback, is_base_skill, skill_id, width, height, font_size)
  8. self:CreateGameObject(UIType.CircleCd)
  9. end
  10. function CirCleCdView:InitData(callback, is_base_skill, skill_id, width, height, font_size)
  11. self.callback = callback
  12. self.is_base_skill = is_base_skill
  13. self.skill_id = skill_id
  14. self.width = width or 86
  15. self.height = height or 86
  16. self.font_size = font_size
  17. self.is_light_guide = true --幻光新手引导
  18. end
  19. function CirCleCdView:LoadSuccess()
  20. self.mask = self:GetChild("mask"):GetComponent("Image")
  21. self.cdTimeText = self:GetChild("cdTimeText"):GetComponent("Text")
  22. self:GetChild("mask").sizeDelta = Vector2(self.width,self.height)
  23. self:InitEvent()
  24. self:Show(0,0)
  25. SkillManager:getInstance():AddCDItem(self.skill_id,self)
  26. end
  27. function CirCleCdView:InitEvent()
  28. local function onStartCdHandler(skill_id,cdTime)
  29. if self.skill_id == skill_id then
  30. --幻光新手引导
  31. if self.skill_id == 120001 and self.is_light_guide then
  32. GlobalEventSystem:Fire(EventName.HIDE_LIGHT_EFFCT_ICON)
  33. self.is_light_guide = false
  34. end
  35. self:Show(cdTime,0)
  36. end
  37. end
  38. self.start_cd_id = SkillManager:getInstance():Bind(SkillManager.START_SKILL_CD,onStartCdHandler)
  39. local function onLockCDHandler(lock)
  40. if self.skill_id ~= SkillManager.JUMP_SKILL_ID then --不能控制跳跃的cd状态
  41. if lock then
  42. self:PauseCD()
  43. else
  44. self:ContinueCD()
  45. end
  46. end
  47. end
  48. self.lock_cd_id = SkillManager:getInstance():Bind(SkillManager.LOCK_CD,onLockCDHandler)
  49. local function onRefreshCDHandler(list)
  50. if not self:IsPlaying() then
  51. return
  52. end
  53. for index,vo in pairs(list) do
  54. if self.skill_id == vo.skill_id then
  55. local left_cd_time = (vo.cd_time - TimeUtil:getServerTimeMs( )) / 1000
  56. local skillVo = SkillManager:getInstance():getSkill(self.skill_id)
  57. if skillVo ~= nil then
  58. local real_cd_time = skillVo:getRealCD()
  59. if real_cd_time > left_cd_time then
  60. local cd_time = skillVo:getCd() / 1000
  61. local last_time = cd_time - left_cd_time
  62. skillVo:refreshCD(real_cd_time - left_cd_time)
  63. self:Show(cd_time,last_time)
  64. end
  65. end
  66. break
  67. end
  68. end
  69. end
  70. self.refresh_cd_id = SkillManager:getInstance():Bind(SkillManager.REFRESH_CD,onRefreshCDHandler)
  71. end
  72. function CirCleCdView:__defineVar()
  73. return {
  74. _class_type = self,
  75. --_cid = self._id,
  76. _iid = _in_obj_ins_id,
  77. _use_delete_method = false,
  78. skill_id = nil,
  79. width = nil,
  80. height = nil,
  81. font_size = nil,
  82. callback = nil,
  83. all_time = 0,
  84. last_time = 0,
  85. curr_show_time = 0,
  86. is_dead = false,
  87. is_playing = false,
  88. is_pause = false,
  89. is_base_skill = false
  90. }
  91. end
  92. function CirCleCdView:IsPlaying()
  93. return self.is_playing
  94. end
  95. function CirCleCdView:SetSkillId(skill_id)
  96. self:RemoveTimer()
  97. self.cdTimeText.text = ""
  98. self.mask.fillAmount = 0
  99. self.skill_id = skill_id
  100. SkillManager:getInstance():AddCDItem(self.skill_id,self)
  101. local skillVo = SkillManager:getInstance():getSkill(self.skill_id)
  102. if skillVo ~= nil then
  103. local cdTime = skillVo:getRealCD()
  104. if cdTime > 0 then
  105. self:Show(cdTime,0)
  106. end
  107. end
  108. -- local cdTime = 1
  109. -- cdTime = skillVo:getCd()/1000
  110. -- self:Show(cdTime,0)
  111. -- end
  112. end
  113. function CirCleCdView:Show(all_time, last_time, skill_id)
  114. self:RemoveTimer()
  115. self.all_time = all_time
  116. self.last_time = last_time or 0
  117. self.curr_show_time = 0
  118. self.skill_id = skill_id or self.skill_id
  119. self.mask.color = Color(1,1,1,1)
  120. self.cdTimeText.color = Color(1,1,1,1)
  121. SkillManager:getInstance():AddCDItem(self.skill_id,self)
  122. if self.all_time == 0 or self.last_time >= self.all_time then
  123. self.cdTimeText.text = ""
  124. self.mask.fillAmount = 0
  125. return
  126. end
  127. if not self.is_base_skill then
  128. local cur_percent = 1 - self.last_time / self.all_time
  129. self.mask.fillAmount = cur_percent
  130. local left_time = self.all_time - self.last_time - self.curr_show_time
  131. if left_time > 1 then
  132. self.cdTimeText.text = math_ceil(left_time)
  133. else
  134. self.cdTimeText.text = string_format("%.1f", left_time)
  135. end
  136. end
  137. self:AddTimer()
  138. end
  139. function CirCleCdView:AddTimer()
  140. Runner.Instance:AddRunObj(self, 3)
  141. self.is_playing = true
  142. end
  143. function CirCleCdView:RemoveTimer()
  144. Runner.Instance:RemoveRunObj(self)
  145. self.is_playing = false
  146. end
  147. --暂停cd
  148. function CirCleCdView:PauseCD()
  149. self.is_pause = true
  150. end
  151. function CirCleCdView:ContinueCD()
  152. self.is_pause = false
  153. end
  154. function CirCleCdView:Update(now_time, elapse_time)
  155. if self.is_pause then return end
  156. self.curr_show_time = elapse_time + self.curr_show_time
  157. local cur_percent = 1 - (self.last_time + self.curr_show_time) / self.all_time
  158. if cur_percent <= 0 then
  159. cur_percent = 0
  160. self:RemoveTimer()
  161. self.cdTimeText.text = ""
  162. self.mask.fillAmount = 0
  163. if self.callback then
  164. self.callback()
  165. end
  166. return
  167. end
  168. if not self.is_base_skill then
  169. self.mask.fillAmount = cur_percent
  170. local left_time = self.all_time - self.last_time - self.curr_show_time
  171. if left_time > 1 then
  172. self.cdTimeText.text = math_ceil(left_time)
  173. else
  174. self.cdTimeText.text = string_format("%.1f", left_time)
  175. end
  176. end
  177. end
  178. function CirCleCdView:__delete( )
  179. self:RemoveTimer()
  180. if self.start_cd_id then
  181. SkillManager:getInstance():UnBind(self.start_cd_id)
  182. self.start_cd_id = nil
  183. end
  184. if self.lock_cd_id then
  185. SkillManager:getInstance():UnBind(self.lock_cd_id)
  186. self.lock_cd_id = nil
  187. end
  188. if self.refresh_cd_id then
  189. SkillManager:getInstance():UnBind(self.refresh_cd_id)
  190. self.refresh_cd_id = nil
  191. end
  192. SkillManager:getInstance():RemoveCdItem(self.skill_id)
  193. end