源战役客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

194 rader
5.3 KiB

4 veckor sedan
  1. SwallowCoreAttrItem = SwallowCoreAttrItem or BaseClass(BaseItem)
  2. local SwallowCoreAttrItem = SwallowCoreAttrItem
  3. function SwallowCoreAttrItem:__init()
  4. self.base_file = "bag"
  5. self.layout_file = "SwallowCoreAttrItem"
  6. self.model = BagModel:getInstance()
  7. self:Load()
  8. end
  9. function SwallowCoreAttrItem:Load_callback()
  10. self.nodes = {
  11. "attr:tmp", "star:img:obj", "bg", "attrIcon:obj:img", "lockTips:tmp", "star/starRed:obj", "star/lock:obj",
  12. }
  13. self:GetChildren(self.nodes)
  14. self:AddEvents()
  15. if self.need_refreshData then
  16. self:UpdateView()
  17. end
  18. end
  19. function SwallowCoreAttrItem:AddEvents( )
  20. local on_click = function ( click_obj )
  21. if self.star_obj == click_obj then
  22. self:DoUnlock()--激活
  23. end
  24. end
  25. AddClickEvent(self.star_obj, on_click)
  26. local function update_swallow_attr_show()
  27. self:UpdateAttrShow()
  28. end
  29. self:BindEvent(self.model,BagModel.REFRESH_SWALLOW_INIT,update_swallow_attr_show)
  30. self:BindEvent(self.model,BagModel.UPDATE_SWALLOW_ATTR_SHOW,update_swallow_attr_show)
  31. end
  32. function SwallowCoreAttrItem:DoUnlock( )
  33. local can_unlock = self.model:SwallowCanUnlock(self.data.lv)
  34. if can_unlock then
  35. self.model:Fire(BagModel.REQUEST_PROTOCOL,15027)
  36. end
  37. end
  38. function SwallowCoreAttrItem:UpdateView( )
  39. self:SetSelfPosition()
  40. self:UpdateAttrShow()
  41. end
  42. function SwallowCoreAttrItem:UpdateAttrShow( )
  43. local is_locked = self.data.lv > self.model.swallow_active_lv
  44. local can_unlock = self.model:SwallowCanUnlock(self.data.lv)
  45. self.starRed_obj:SetActive(can_unlock)
  46. if is_locked then
  47. self.attrIcon_obj:SetActive(false)
  48. lua_resM:setImageSprite(self, self.star_img, "bag_asset","bag_swallow_star_gray")
  49. self.lock_obj:SetActive(true)
  50. self.lockTips_tmp.text = string.format("Lv.%s 解锁",self.data.lv)
  51. self.attr_tmp.text = ""
  52. else
  53. self.attrIcon_obj:SetActive(true)
  54. lua_resM:setImageSprite(self, self.star_img, "bag_asset","bag_swallow_star")
  55. self.lock_obj:SetActive(false)
  56. local attr_data = stringtotable(self.data.attr_point)
  57. self.lockTips_tmp.text = ""
  58. self.attr_tmp.text = string.format("%s<color=%s>+%s</color>",WordManager:GetProperties(attr_data[1][1]),ColorUtil.WHITE,WordManager:GetPropertyValue(attr_data[1][1],attr_data[1][2]))
  59. SetAttrIconByColorType(self, self.attrIcon_img, attr_data[1][1], nil, 3)
  60. end
  61. end
  62. function SwallowCoreAttrItem:SetSelfPosition( )
  63. if self.item_id == 1 then
  64. self:SetAnchoredPosition(-80,118)
  65. SetSizeDelta(self.star,82,82)
  66. SetLocalPosition(self.star,105,35)
  67. SetLocalScale(self.bg,-1,1,1)
  68. elseif self.item_id == 2 then
  69. self:SetAnchoredPosition(-248,23)
  70. SetSizeDelta(self.star,65,65)
  71. SetLocalPosition(self.star,102,22)
  72. SetLocalScale(self.bg,-1,1,1)
  73. elseif self.item_id == 3 then
  74. self:SetAnchoredPosition(-240,-151)
  75. SetSizeDelta(self.star,102,102)
  76. SetLocalPosition(self.star,95,40)
  77. SetLocalScale(self.bg,-1,1,1)
  78. elseif self.item_id == 4 then
  79. self:SetAnchoredPosition(129,-191)
  80. SetSizeDelta(self.star,82,82)
  81. SetLocalPosition(self.star,-102,33)
  82. SetLocalScale(self.bg,1,1,1)
  83. elseif self.item_id == 5 then
  84. self:SetAnchoredPosition(240,-84)
  85. SetSizeDelta(self.star,65,65)
  86. SetLocalPosition(self.star,-105,27)
  87. SetLocalScale(self.bg,1,1,1)
  88. elseif self.item_id == 6 then
  89. self:SetAnchoredPosition(283,32)
  90. SetSizeDelta(self.star,102,102)
  91. SetLocalPosition(self.star,-110,33)
  92. SetLocalScale(self.bg,1,1,1)
  93. end
  94. if self.item_id >= 1 and self.item_id <= 3 then
  95. SetAnchoredPosition(self.lockTips,-8,4)
  96. SetAnchoredPosition(self.attr,22,4)
  97. SetAnchoredPosition(self.attrIcon,-56,4)
  98. else
  99. SetAnchoredPosition(self.lockTips,14,4)
  100. SetAnchoredPosition(self.attr,33,4)
  101. SetAnchoredPosition(self.attrIcon,-45,4)
  102. end
  103. self:ArrowAnimation(0)
  104. end
  105. --图片上下移动
  106. function SwallowCoreAttrItem:ArrowAnimation(time)
  107. local end_y = 0
  108. local start_y = 0
  109. local anim_time = 0
  110. if self.item_id == 1 then-- 118
  111. end_y = 109
  112. start_y = 120
  113. anim_time = 1.8
  114. elseif self.item_id == 2 then-- 23
  115. start_y = 25
  116. end_y = 15
  117. anim_time = 1.9
  118. elseif self.item_id == 3 then-- -151
  119. end_y = -155
  120. start_y = -145
  121. anim_time = 1.7
  122. elseif self.item_id == 4 then-- -191
  123. start_y = -195
  124. end_y = -186
  125. anim_time = 2
  126. elseif self.item_id == 5 then-- -84
  127. end_y = -90
  128. start_y = -79
  129. anim_time = 2.1
  130. elseif self.item_id == 6 then-- 32
  131. start_y = 37
  132. end_y = 27
  133. anim_time = 1.9
  134. end
  135. self:StopAnim()
  136. local call_fun = function ()
  137. local function onCompleted()
  138. self:ArrowAnimation(time)
  139. end
  140. self.tween_id3 =TweenLite.to(self, self.transform,TweenLite.UiAnimationType.ANCHORED_POSY,end_y,anim_time,onCompleted)
  141. end
  142. local onDelay = function( )
  143. self.tween_id2 =TweenLite.to(self, self.transform,TweenLite.UiAnimationType.ANCHORED_POSY,start_y, anim_time, call_fun)
  144. end
  145. self.arrow_timer_id = setTimeout(onDelay, time)
  146. end
  147. function SwallowCoreAttrItem:StopAnim()
  148. if self.tween_id2 then
  149. TweenLite.Stop(self.tween_id2)
  150. self.tween_id2 = nil
  151. end
  152. if self.tween_id3 then
  153. TweenLite.Stop(self.tween_id3)
  154. self.tween_id3 = nil
  155. end
  156. if self.arrow_timer_id then
  157. GlobalTimerQuest:CancelQuest(self.arrow_timer_id)
  158. self.arrow_timer_id = nil
  159. end
  160. end
  161. function SwallowCoreAttrItem:SetData( data,item_id )
  162. self.data = data
  163. self.item_id = item_id
  164. if self.is_loaded then
  165. self.need_refreshData = false
  166. self:UpdateView()
  167. else
  168. self.need_refreshData = true
  169. end
  170. end
  171. function SwallowCoreAttrItem:__delete( )
  172. self:StopAnim()
  173. end