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

197 行
5.1 KiB

  1. SoulPowerItem = SoulPowerItem or BaseClass(BaseItem)
  2. local SoulPowerItem = SoulPowerItem
  3. function SoulPowerItem:__init()
  4. self.base_file = "soulPower"
  5. self.layout_file = "SoulPowerItem"
  6. self.model = SoulPowerModel:getInstance()
  7. self.old_lock_state = nil
  8. self:Load()
  9. end
  10. function SoulPowerItem:Load_callback()
  11. self.nodes = {
  12. "Icon:img:obj", "bg:img", "select:obj", "dizuo", "IconGray:img:obj", "next:obj",
  13. }
  14. self:GetChildren(self.nodes)
  15. SetImageGray(self.IconGray_img, true)
  16. self.select_obj:SetActive(true)
  17. SetAnchoredPositionY(self.select,35)
  18. self:AddEvents()
  19. if self.need_refreshData then
  20. self:BeforeUpdate()
  21. end
  22. end
  23. function SoulPowerItem:AddEvents( )
  24. local update_soul_power_view = function()
  25. if not self.is_loaded then return end
  26. if self.model.has_create_once then
  27. self:BeforeUpdate()
  28. end
  29. end
  30. self:BindEvent(self.model, SoulPowerConst.UPDATE_SOUL_POWER_VIEW, update_soul_power_view)
  31. end
  32. function SoulPowerItem:BeforeUpdate()
  33. local sp_grade, sp_lv = self.model:GetSoulPowerNowGradeLv()
  34. if self.index == sp_lv + 1 then
  35. self.next_obj:SetActive(true)
  36. else
  37. self.next_obj:SetActive(false)
  38. end
  39. if self.old_lock_state then
  40. self.old_lock_state = self.index > sp_lv
  41. SetImageGray(self.bg_img, true)
  42. self.in_anim_state = true
  43. self:DoActiveEffect()
  44. if self.delay_timer_1 then
  45. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_timer_1)
  46. self.delay_timer_1 = nil
  47. end
  48. local function delay_method( )
  49. self:UpdateView()
  50. self.in_anim_state = false
  51. end
  52. self.delay_timer_1 = setTimeout(delay_method, 0.5)
  53. else
  54. --之前就已经是激活状态且现在还是激活,那就不进行update了
  55. if self.old_active_state and self.index <= sp_lv then
  56. self.old_active_state = true
  57. else
  58. --如果还在播放激活特效动画,这个时候不允许update
  59. if not self.in_anim_state then
  60. self:UpdateView()
  61. end
  62. end
  63. end
  64. end
  65. function SoulPowerItem:UpdateView( )
  66. self:ClearUIEffect(self.dizuo)
  67. self:ClearUIEffect(self.Icon)
  68. if self.index >= 3 and self.index <= 6 then
  69. SetLocalScale(self.Icon,0.95,0.95,1)
  70. SetLocalScale(self.select,0.95,0.95,1)
  71. lua_resM:setImageSprite(self, self.bg_img, "soulPower_asset","soul_power_img_7",true)
  72. else
  73. SetLocalScale(self.Icon,1,1,1)
  74. SetLocalScale(self.select,1,1,1)
  75. lua_resM:setImageSprite(self, self.bg_img, "soulPower_asset","soul_power_img_8",true)
  76. end
  77. local sp_grade, sp_lv = self.model:GetSoulPowerNowGradeLv()
  78. if self.index <= sp_lv then
  79. -- SetImageGray(self.Icon_img, false)
  80. self.Icon_obj:SetActive(true)
  81. SetImageGray(self.bg_img, false)
  82. self.IconGray_obj:SetActive(false)
  83. else
  84. -- SetImageGray(self.Icon_img, true)
  85. self.Icon_obj:SetActive(false)
  86. SetImageGray(self.bg_img, true)
  87. self.IconGray_obj:SetActive(true)
  88. end
  89. -- if self.index == sp_lv + 1 then
  90. -- self.next_obj:SetActive(true)
  91. -- else
  92. -- self.next_obj:SetActive(false)
  93. -- end
  94. local function delay_method( )
  95. if self.index <= sp_lv then
  96. self:AddUIEffect("ui_hunlidizuo", self.dizuo, "UI", nil, 4, true)
  97. self:AddUIEffect("ui_hunliqiu", self.Icon, "UI", nil, 5, true)
  98. end
  99. -- self:AddUIEffect("ui_hunliqiudianliang", self.bg, "Activity", nil, 2, true)
  100. -- self:AddUIEffect("ui_hunliqiudizuo", self.bg, "Activity", nil, 2, true)
  101. end
  102. self.delay_timer_2 = setTimeout(delay_method, 0.02)
  103. --之前是否是未激活状态
  104. self.old_lock_state = self.index > sp_lv
  105. --之前是否是激活状态
  106. self.old_active_state = self.index <= sp_lv
  107. self:ArrowAnimation(0)
  108. end
  109. function SoulPowerItem:ArrowAnimation(time)
  110. local random_time = math.random(1.5,2.8)
  111. self:StopAnim()
  112. local call_fun = function ()
  113. local function onCompleted()
  114. self:ArrowAnimation(time)
  115. end
  116. self.tween_id3 =TweenLite.to(self, self.Icon,TweenLite.UiAnimationType.ANCHORED_POSY,50, random_time, onCompleted)
  117. end
  118. local onDelay = function( )
  119. self.tween_id2 =TweenLite.to(self, self.Icon,TweenLite.UiAnimationType.ANCHORED_POSY,15, random_time, call_fun)
  120. end
  121. self.arrow_timer_id = setTimeout(onDelay, time)
  122. end
  123. function SoulPowerItem:StopAnim()
  124. if self.tween_id2 then
  125. TweenLite.Stop(self.tween_id2)
  126. self.tween_id2 = nil
  127. end
  128. if self.tween_id3 then
  129. TweenLite.Stop(self.tween_id3)
  130. self.tween_id3 = nil
  131. end
  132. if self.arrow_timer_id then
  133. GlobalTimerQuest:CancelQuest(self.arrow_timer_id)
  134. self.arrow_timer_id = nil
  135. end
  136. end
  137. function SoulPowerItem:DoActiveEffect( )
  138. self:ClearUIEffect(self.select)
  139. local sp_grade, sp_lv = self.model:GetSoulPowerNowGradeLv()
  140. if self.index == sp_lv then
  141. self:AddUIEffect("ui_hunliqiudianliang", self.select, "UI", nil, 4.5, false,nil,nil,nil,nil,1)
  142. end
  143. end
  144. function SoulPowerItem:SetData( data, index)
  145. self.data = data
  146. self.index = index
  147. if self.is_loaded then
  148. self.need_refreshData = false
  149. self:BeforeUpdate()
  150. else
  151. self.need_refreshData = true
  152. end
  153. end
  154. function SoulPowerItem:__delete( )
  155. self:StopAnim()
  156. self:ClearUIEffect(self.dizuo)
  157. self:ClearUIEffect(self.select)
  158. self:ClearUIEffect(self.Icon)
  159. if self.delay_timer_2 then
  160. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_timer_2)
  161. self.delay_timer_2 = nil
  162. end
  163. if self.delay_timer_1 then
  164. TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_timer_1)
  165. self.delay_timer_1 = nil
  166. end
  167. end