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

129 行
3.2 KiB

  1. --正方形cd 30 * 30
  2. NormalCirCleCdView = NormalCirCleCdView or BaseClass(BaseComponent)
  3. local NormalCirCleCdView = NormalCirCleCdView
  4. local math_ceil = math.ceil
  5. local string_format = string.format
  6. function NormalCirCleCdView:__init(handle_wnd, callback, id, width, height, font_size)
  7. self:InitData(callback, id, width, height, font_size)
  8. self:CreateGameObject(UIType.CircleCd)
  9. end
  10. function NormalCirCleCdView:InitData(callback, id, width, height, font_size)
  11. self.callback = callback
  12. self.id = id
  13. self.width = width or 30
  14. self.height = height or 30
  15. self.font_size = font_size
  16. end
  17. function NormalCirCleCdView:LoadSuccess()
  18. self.mask = self:GetChild("mask"):GetComponent("Image")
  19. self.cdTimeText = self:GetChild("cdTimeText"):GetComponent("Text")
  20. self:GetChild("mask").sizeDelta = Vector2(self.width,self.height)
  21. self:InitEvent()
  22. self:Show(0, 0, false)
  23. end
  24. function NormalCirCleCdView:InitEvent()
  25. end
  26. function NormalCirCleCdView:__defineVar()
  27. return {
  28. _class_type = self,
  29. --_cid = self._id,
  30. _iid = _in_obj_ins_id,
  31. _use_delete_method = false,
  32. id = nil,
  33. width = nil,
  34. height = nil,
  35. font_size = nil,
  36. callback = nil,
  37. all_time = 0,
  38. last_time = 0,
  39. curr_show_time = 0,
  40. is_public_cd = false,
  41. is_dead = false,
  42. is_playing = false,
  43. is_pause = false,
  44. show_text = false,
  45. }
  46. end
  47. function NormalCirCleCdView:IsPlaying()
  48. return self.is_playing
  49. end
  50. function NormalCirCleCdView:Show(all_time, last_time, show_text)
  51. self:RemoveTimer()
  52. self.all_time = all_time
  53. self.last_time = last_time or 0
  54. self.curr_show_time = 0
  55. self.show_text = show_text
  56. if self.all_time == 0 or self.last_time >= self.all_time then
  57. self.cdTimeText.text = ""
  58. self.mask.fillAmount = 0
  59. return
  60. end
  61. local cur_percent = self.last_time / self.all_time
  62. self.mask.fillAmount = 1 - cur_percent
  63. if show_text ~= false then
  64. local left_time = self.all_time - self.last_time - self.curr_show_time
  65. if left_time > 1 then
  66. self.cdTimeText.text = math_ceil(left_time)
  67. else
  68. self.cdTimeText.text = string_format("%.1f", left_time)
  69. end
  70. end
  71. self:AddTimer()
  72. end
  73. function NormalCirCleCdView:AddTimer()
  74. Runner.Instance:AddRunObj(self, 3)
  75. self.is_playing = true
  76. end
  77. function NormalCirCleCdView:RemoveTimer()
  78. Runner.Instance:RemoveRunObj(self)
  79. self.is_playing = false
  80. end
  81. --暂停cd
  82. function NormalCirCleCdView:PauseCD()
  83. self.is_pause = true
  84. end
  85. function NormalCirCleCdView:ContinueCD()
  86. self.is_pause = false
  87. end
  88. function NormalCirCleCdView:Update(now_time, elapse_time)
  89. if self.is_pause then return end
  90. self.curr_show_time = elapse_time + self.curr_show_time
  91. local cur_percent = (self.last_time + self.curr_show_time) / self.all_time
  92. if cur_percent >= 1 then
  93. cur_percent = 0
  94. self:RemoveTimer()
  95. self.cdTimeText.text = ""
  96. self.mask.fillAmount = 0
  97. if self.callback then
  98. self.callback()
  99. end
  100. return
  101. end
  102. if not self.is_base_skill then
  103. self.mask.fillAmount = 1 - cur_percent
  104. if self.show_text ~= false then
  105. local left_time = self.all_time - self.last_time - self.curr_show_time
  106. if left_time > 1 then
  107. self.cdTimeText.text = math_.ceil(left_time)
  108. else
  109. self.cdTimeText.text = string_format("%.1f", left_time)
  110. end
  111. end
  112. end
  113. end
  114. function NormalCirCleCdView:__delete( )
  115. self:RemoveTimer()
  116. end