源战役客户端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.5 KiB

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