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

271 行
8.4 KiB

  1. WardrobeShopView = WardrobeShopView or BaseClass(BaseItem)
  2. local WardrobeShopView = WardrobeShopView
  3. WardrobeShopView.SHOP_TYPE = {
  4. SINGLE = 1,
  5. DOUBLE = 2,
  6. }
  7. local table_insert = table.insert
  8. function WardrobeShopView:__init()
  9. self.base_file = "wardrobe"
  10. self.layout_file = "WardrobeShopView"
  11. self.model = WardrobeModel:GetInstance()
  12. self.cur_tab_index = 1
  13. self.tab_item_list = {}--左边tab
  14. self.top_goods_item_list = {}--主打商品表
  15. self.shop_bg_position = {
  16. [1] = {x = 30.5, y = 7.5},
  17. [2] = {x = 140.5, y = 90.5},
  18. }
  19. self.ani_left = -200
  20. self.ani_right = 400
  21. self.adjust_mid = {left = 50, right = 640}
  22. self:Load()
  23. end
  24. function WardrobeShopView:Load_callback()
  25. self.nodes = {
  26. "right/help_btn:obj", "right/bg:raw",
  27. "right/item_scroll/Viewport/item_con", "right/item_scroll:obj",
  28. "left/tab_con",
  29. "right/shop_scroll/Viewport/shop_item", "right/shop_scroll:obj",
  30. --中间总览
  31. "mid/total_mid_con/icon_image:obj:img", "mid/icon_small_image:obj:img",
  32. "mid/total_mid_con/wardrobe_text:txt", "mid/total_mid_con:obj",
  33. --中间商城
  34. "mid/shop_mid_con/shop_bg2:obj:img", "mid/shop_mid_con/shop_bg1:obj:img", "mid/shop_mid_con:obj",
  35. "mid/shop_mid_con/tip_bg:obj", "mid/shop_mid_con/tip_text:tmp",
  36. "mid/shop_mid_con/shop_bg2/shop_item_con2", "mid/shop_mid_con/shop_bg1/shop_item_con1",
  37. }
  38. self:GetChildren(self.nodes)
  39. lua_resM:setOutsideImageSprite(self, self.shop_bg1_img, GameResPath.GetWardrobeImage("wardrobe_shop_mid_bg"))
  40. lua_resM:setOutsideImageSprite(self, self.shop_bg2_img, GameResPath.GetWardrobeImage("wardrobe_shop_mid_bg"))
  41. self:AddEvents()
  42. if self.need_refreshData then
  43. self:UpdateView()
  44. end
  45. end
  46. function WardrobeShopView:AddEvents( )
  47. local function on_click( target )
  48. if self.help_btn_obj == target then
  49. GlobalEventSystem:Fire(EventName.OPEN_INSTRUCTION_VIEW, 42200)
  50. end
  51. end
  52. AddClickEvent(self.help_btn_obj, on_click)
  53. local function on_update_total( )
  54. self:UpdateTabItem()
  55. self:UpdateTotalList()
  56. end
  57. self.on_update_total_id = self.model:BindOne("wardrobe_total_info", on_update_total)
  58. local function on_update_shop( )
  59. self:UpdateShopList()
  60. end
  61. self.on_update_shop_id = self.model:BindOne("wardrobe_shop_info", on_update_shop)
  62. end
  63. function WardrobeShopView:UpdateView( )
  64. self:UpdateTabItem()
  65. self:SwitchTab(self.cur_tab_index)
  66. end
  67. function WardrobeShopView:SetData( index, sub_index )
  68. self.cur_tab_index = sub_index or self.cur_tab_index
  69. if sub_index then
  70. self.model:Fire(WardrobeConst.REQ_WARDROBE_SCMD, 42202, sub_index - 1)
  71. end
  72. if self.is_loaded then
  73. self.need_refreshData = false
  74. self:UpdateView()
  75. else
  76. self.need_refreshData = true
  77. end
  78. end
  79. function WardrobeShopView:SwitchTab( index )
  80. if self.cur_tab_index ~= index and index ~= 1 then
  81. self.model:Fire(WardrobeConst.REQ_WARDROBE_SCMD, 42202, index - 1)
  82. end
  83. self.cur_tab_index = index
  84. self.icon_small_image_obj:SetActive(self.cur_tab_index ~= 1)
  85. self.item_scroll_obj:SetActive(self.cur_tab_index == 1)
  86. self.shop_scroll_obj:SetActive(self.cur_tab_index ~= 1)
  87. self.total_mid_con_obj:SetActive(self.cur_tab_index == 1)
  88. self.shop_mid_con_obj:SetActive(self.cur_tab_index ~= 1)
  89. if self.cur_tab_index == 1 then--选中总览了
  90. self:UpdateTotalList()
  91. else
  92. self:UpdateShopList()
  93. end
  94. for i,v in ipairs(self.tab_item_list) do
  95. v:SetItemSelect(self.cur_tab_index)
  96. end
  97. end
  98. function WardrobeShopView:UpdateTabItem( )
  99. local data = DeepCopy(Config.Wardrobeopen)
  100. table_insert(data, 1, {store_name = "风采总览",condition = 0, icon = 0})
  101. local height = 56
  102. local y_offset = 10
  103. local function call_back_func( index)
  104. self:SwitchTab(index)
  105. end
  106. if not self.tab_data then
  107. self.tab_data = data
  108. end
  109. for i,v in ipairs(data) do
  110. local item = self.tab_item_list[i]
  111. if not item then
  112. item = WardrobeVerTabItem.New(self.tab_con)
  113. item:SetPosition(0, -(i - 1) * (height + y_offset))
  114. self.tab_item_list[i] = item
  115. end
  116. item:SetData(v,i, call_back_func, self.cur_tab_index)
  117. end
  118. end
  119. function WardrobeShopView:UpdateShopList( )
  120. local cfg_data = Config.Wardrobeopen
  121. if cfg_data and cfg_data[self.cur_tab_index - 1] then
  122. local cur_stage = self.model:GetMyWardrobeStage()
  123. if cur_stage < cfg_data[self.cur_tab_index - 1].condition then
  124. self.tip_bg_obj:SetActive(true)
  125. if Config.Wardrobestage[cfg_data[self.cur_tab_index - 1].condition] then
  126. self.tip_text_tmp.text = string.format("风采值达到 %s 解锁本货柜", HtmlColorTxt(Config.Wardrobestage[cfg_data[self.cur_tab_index - 1].condition].low_value, "#FDFFC2"))
  127. end
  128. else
  129. self.tip_bg_obj:SetActive(false)
  130. self.tip_text_tmp.text = ""
  131. end
  132. else
  133. self.tip_bg_obj:SetActive(false)
  134. self.tip_text_tmp.text = ""
  135. end
  136. if not self.tab_data or self.cur_tab_index == 1 then--没有构造好数据的时候不让进来
  137. return
  138. end
  139. local cfg_data = self.model:GetWardrobeShopCFGByID(self.tab_data[self.cur_tab_index].store_id)
  140. local server_data = self.model:GeteWardrobeShopInfo(self.tab_data[self.cur_tab_index].store_id)
  141. local data = {}
  142. local top_data = {}
  143. for i,v in pairsByKeys(cfg_data) do
  144. if v.is_top == 1 then--是主打
  145. if TableSize(top_data) < 2 and server_data[v.pos] then--有服务端数据才插进去
  146. table_insert(top_data, v)
  147. elseif server_data[v.pos] then--有服务端数据才插进去
  148. table_insert(data, v)
  149. end
  150. elseif server_data[v.pos] then--有服务端数据才插进去
  151. table_insert(data, v)
  152. end
  153. end
  154. self:UpdateTopGoods(top_data, server_data)
  155. if not self.shop_item_list_com then
  156. self.shop_item_list_com = self:AddUIComponent(UI.ItemListCreator)
  157. end
  158. self.shop_item_list_com:Reset()
  159. local info = {
  160. data_list = data,
  161. item_con = self.shop_item,
  162. item_class = WardrobeShopItem,
  163. item_height = 157,
  164. item_width = 126,
  165. start_x = 0,
  166. space_x = 2,
  167. start_y = 0,
  168. scroll_view = self.shop_scroll.transform,
  169. create_frequency = 0.05,
  170. is_scroll_back_on_update = false,
  171. child_names = child_names,
  172. on_update_item = function(item, i, v)
  173. item:SetData(v,i)
  174. item:SetServerData(server_data[v.pos])
  175. end,
  176. }
  177. self.shop_item_list_com:UpdateItems(info)
  178. end
  179. --更新主打商品
  180. function WardrobeShopView:UpdateTopGoods( data, server_data)
  181. local len = TableSize(data)
  182. for i,v in ipairs(self.top_goods_item_list) do
  183. v:SetVisible(false)
  184. end
  185. if len == 0 then
  186. self.shop_bg1_obj:SetActive(false)
  187. self.shop_bg2_obj:SetActive(false)
  188. elseif len == 1 then
  189. self.shop_bg1_obj:SetActive(true)
  190. self.shop_bg2_obj:SetActive(false)
  191. SetAnchoredPosition(self.shop_bg1,self.shop_bg_position[len].x, self.shop_bg_position[len].y)
  192. else
  193. self.shop_bg1_obj:SetActive(true)
  194. self.shop_bg2_obj:SetActive(true)
  195. SetAnchoredPosition(self.shop_bg1,self.shop_bg_position[len].x, self.shop_bg_position[len].y)
  196. end
  197. for i,v in ipairs(data) do
  198. local item = self.top_goods_item_list[i]
  199. if not item then
  200. item = WardrobeShopItem.New(self["shop_item_con"..i])
  201. self.top_goods_item_list[i] = item
  202. end
  203. item:SetData(v,i)
  204. item:SetServerData(server_data[v.pos])
  205. end
  206. end
  207. function WardrobeShopView:UpdateTotalList( )
  208. local total_data = self.model:GetWardrobeTotalInfo()
  209. local total_list = total_data.wardrobe_list or {}
  210. self.wardrobe_text_txt.text = total_data.sum_wardrobe_value
  211. local res_name = string.format("wardrobe_level%s", total_data.stage or 1)
  212. lua_resM:setOutsideImageSprite(self, self.icon_image_img, GameResPath.GetWardrobeImage(res_name), true)
  213. lua_resM:setOutsideImageSprite(self, self.icon_small_image_img, GameResPath.GetWardrobeImage(res_name), true)
  214. if not self.total_item_list_com then
  215. self.total_item_list_com = self:AddUIComponent(UI.ItemListCreator)
  216. end
  217. local info = {
  218. data_list = total_list,
  219. item_con = self.item_con,
  220. item_class = WardrobeTotalItem,
  221. item_height = 107,
  222. start_x = 11,
  223. start_y = -8,
  224. scroll_view = self.item_scroll.transform,
  225. create_frequency = 0.05,
  226. is_scroll_back_on_update = false,
  227. child_names = child_names,
  228. on_update_item = function(item, i, v)
  229. item:SetData(v,i)
  230. end,
  231. }
  232. self.total_item_list_com:UpdateItems(info)
  233. end
  234. function WardrobeShopView:UpdateMidInfo( )
  235. end
  236. function WardrobeShopView:__delete( )
  237. for i,v in ipairs(self.tab_item_list) do
  238. v:DeleteMe()
  239. v = nil
  240. end
  241. self.tab_item_list = {}
  242. if self.on_update_total_id then
  243. self.model:UnBind(self.on_update_total_id)
  244. self.on_update_total_id = nil
  245. end
  246. if self.on_update_shop_id then
  247. self.model:UnBind(self.on_update_shop_id)
  248. self.on_update_shop_id = nil
  249. end
  250. for i,v in ipairs(self.top_goods_item_list) do
  251. v:DeleteMe()
  252. v = nil
  253. end
  254. self.top_goods_item_list = {}
  255. end