源战役客户端
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.

200 lines
7.1 KiB

  1. ChildDressItem = ChildDressItem or BaseClass(BaseItem)
  2. function ChildDressItem:__init()
  3. self.base_file = "child"
  4. self.layout_file = "ChildDressItem"
  5. self.is_delay_callback = true
  6. -- self.use_local_view = true
  7. self.model = ChildModel:GetInstance()
  8. self:Load()
  9. end
  10. function ChildDressItem:Load_callback()
  11. self.nodes = {
  12. "bg/name_txt:obj:tmp",
  13. "bg:obj:img","bg/chosen_con:obj","bg/lock_con:obj","bg/active_con:obj","bg/dress_icon:obj","bg/red_dot:obj",
  14. "bg/dress_icon/dress_des:tmp",
  15. "bg/dressImg:img",
  16. }
  17. self:GetChildren(self.nodes)
  18. -- 进阶星星
  19. self.img_star_list = {}
  20. for i = 1, 5 do
  21. self.img_star_list[i] = self:GetChild("bg/stars/star" .. i):GetComponent("Image")
  22. end
  23. self:InitEvent()
  24. if self.need_refreshData then
  25. self:SetData(self.data,self.callback,self.index, self.check_effect)
  26. self:SetChosen(self.isChosen)
  27. self:SetRedDot(self.isRedDot)
  28. self:SetScaleNum(self.scaleNum)
  29. end
  30. end
  31. function ChildDressItem:InitEvent()
  32. local function onBtnClickHandler(target, x, y)
  33. if target == self.bg_obj then
  34. self.callback(self)
  35. end
  36. end
  37. AddClickEvent(self.bg_obj, onBtnClickHandler)
  38. end
  39. function ChildDressItem:SetData(data,callback,index, check_effect)
  40. self.data = data or self.data
  41. self.callback = callback or self.callback
  42. self.last_type = self.type
  43. self.type = nil
  44. self.index = index
  45. self.check_effect = check_effect
  46. local have_num = GoodsModel:getInstance():GetTypeGoodsNum(self.data.fashion_id) or 0
  47. local need_num = stringtotable(self.data.upgrade_cost)[1][3]
  48. if self.data.active == false and have_num >= need_num then --可激活
  49. self.type = ChildConst.ChildDressItemType.CanActive
  50. elseif self.data.active == true then -- 已经激活
  51. self.type = ChildConst.ChildDressItemType.isActive
  52. else --不可激活,锁
  53. self.type = ChildConst.ChildDressItemType.Lock
  54. end
  55. if self.is_loaded then
  56. self:UpdateView( )
  57. else
  58. self.need_refreshData = true
  59. end
  60. end
  61. function ChildDressItem:UpdateView( )
  62. local data = self.data
  63. if not self.data.is_vehicle then -- 除了载具
  64. -- 设置原画 原画是以模型id命名的
  65. local figure_id = self.model:GetFashionModelID( self.data.fashion_id )
  66. lua_resM:setOutsideImageSprite(self, self.dressImg_img, GameResPath.GetChildDressIcon(figure_id), true)
  67. self.dress_des_tmp.text = "穿戴中"
  68. else
  69. lua_resM:setOutsideImageSprite(self, self.dressImg_img, GameResPath.GetChildDressIcon(self.data.fashion_id), true)
  70. self.dress_des_tmp.text = "骑乘中"
  71. end
  72. -- local need_star_effect = false
  73. if self.check_effect then
  74. -- self.check_effect = false
  75. -- logWarn('=======Msh:ChildDressItem.lua[80]=======')
  76. -- print('Msh:ChildDressItem.lua[81] data', self.last_type)
  77. -- print('Msh:ChildDressItem.lua[81] data', self.type)
  78. if (not self.is_in_effect) and self.last_type and self.last_type ~= ChildConst.ChildDressItemType.isActive and self.type == ChildConst.ChildDressItemType.isActive then -- 可激活到激活
  79. self.is_in_effect = true
  80. need_star_effect = true
  81. local function call_back( )
  82. self.is_in_effect = false
  83. end
  84. self:ClearUIEffect(self.dressImg)
  85. self:AddUIEffect("ui_hunliqiudianliang", self.dressImg, "Activity", Vector3(0, 10 ,0), 4, false, 0.6, nil, call_back)
  86. end
  87. end
  88. self.chosen_con_obj:SetActive(false)
  89. -- self.lock_con_obj:SetActive(false)
  90. self.active_con_obj:SetActive(false)
  91. self.dress_icon_obj:SetActive(false)
  92. -- self.idle_txt_txt.text = "已解锁"
  93. ---激活
  94. if self.type == ChildConst.ChildDressItemType.CanActive then --可激活
  95. self.active_con_obj:SetActive(true)
  96. -- self.idle_txt_txt.text = "可激活"
  97. elseif self.type == ChildConst.ChildDressItemType.Lock then --不可激活,锁
  98. -- self.lock_con_obj:SetActive(true)
  99. -- self.idle_txt_txt.text = "暂未解锁"
  100. end
  101. if self.data.state == 1 then --穿戴中
  102. self.dress_icon_obj:SetActive(true)
  103. -- self.idle_txt_txt.text = "穿戴中"
  104. end
  105. self.name_txt_tmp.text = self.data.fashion_name or ""
  106. -- 设置进阶星星数
  107. local nowLevel = tonumber(self.data.lv)
  108. for i = 1, 5 do
  109. if i < nowLevel/2 then
  110. if self.check_effect and tonumber(self.img_star_list[i].fillAmount) < 1 then
  111. self:PlayStarEffect(self.img_star_list[i].transform, i)
  112. end
  113. self.img_star_list[i].gameObject:SetActive(true)
  114. self.img_star_list[i].fillAmount = 1
  115. elseif (i-1) < nowLevel/2 then -- 最后一个
  116. self.img_star_list[i].gameObject:SetActive(true)
  117. -- self.img_star_list[i].fillAmount = 1
  118. if nowLevel % 2 ~= 0 then -- 单数就是一半
  119. if self.check_effect and tonumber(self.img_star_list[i].fillAmount) < 0.5 then
  120. self:PlayStarEffect(self.img_star_list[i].transform, i)
  121. end
  122. self.img_star_list[i].fillAmount = 0.5
  123. else
  124. if self.check_effect and tonumber(self.img_star_list[i].fillAmount) < 1 then
  125. self:PlayStarEffect(self.img_star_list[i].transform, i)
  126. end
  127. self.img_star_list[i].fillAmount = 1
  128. end
  129. else
  130. self.img_star_list[i].gameObject:SetActive(false)
  131. self.img_star_list[i].fillAmount = 0
  132. end
  133. end
  134. self.check_effect = false
  135. end
  136. function ChildDressItem:PlayStarEffect( tran, i )
  137. self.showing_star_effect = self.showing_star_effect or {}
  138. if true then
  139. if not self.showing_star_effect[i] then
  140. local function call_back( )
  141. self.showing_star_effect[i] = false
  142. end
  143. self:ClearUIEffect(tran)
  144. self:AddUIEffect("ui_jinjiestar", tran, self.layer_name, nil, 1, false, nil, nil, call_back)
  145. self.showing_star_effect[i] = true
  146. end
  147. end
  148. end
  149. function ChildDressItem:SetChosen(bool)
  150. self.isChosen = bool
  151. if self.is_loaded then
  152. if bool then
  153. self.chosen_con_obj:SetActive(true)
  154. -- self.name_txt_obj:SetActive(false)
  155. else
  156. self.chosen_con_obj:SetActive(false)
  157. -- self.name_txt_obj:SetActive(true)
  158. end
  159. else
  160. self.need_refreshData = true
  161. end
  162. end
  163. function ChildDressItem:SetScaleNum(num)
  164. --[[
  165. self.scaleNum = num or 0.7
  166. if self.is_loaded then
  167. SetLocalScale(self.transform, self.scaleNum)
  168. if self.scaleNum == 0.99 then
  169. self.bg_img.color =Color(1,1,1,0.8)
  170. else
  171. self.bg_img.color =Color(1,1,1,1)
  172. end
  173. else
  174. self.need_refreshData = true
  175. end
  176. ]]
  177. end
  178. function ChildDressItem:SetRedDot(bool)
  179. self.isRedDot = bool
  180. if self.is_loaded then
  181. --print("============>>> YiRan:ChildDressItem [start:83] vehicle_id :",vehicle_id,"self.isRedDot:",self.isRedDot)
  182. self.red_dot_obj:SetActive(self.isRedDot)
  183. else
  184. self.need_refreshData = true
  185. end
  186. end