源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

473 wiersze
15 KiB

4 tygodni temu
  1. MarketAttentionView = MarketAttentionView or BaseClass(BaseItem)
  2. local MarketAttentionView = MarketAttentionView
  3. local table_insert = table.insert
  4. function MarketAttentionView:__init()
  5. self.base_file = "market"
  6. self.layout_file = "MarketAttentionView"
  7. self.model = MarketModel:GetInstance()
  8. self.sell_type = 1
  9. self.is_first = true--是否第一次进入
  10. self.series_limit = 0
  11. self.career_limit = RoleManager.Instance.mainRoleInfo.career--默认拿自己的防具
  12. self.color = 99
  13. self.tab_item_list = {}
  14. self:Load()
  15. end
  16. function MarketAttentionView:Load_callback()
  17. self.nodes = {
  18. "series_con:obj","right_scroll","series_con/series_drop","color_con:obj","clean_btn:obj",
  19. "left_scroll/Viewport/left_con","right_scroll/Viewport/right_con","left_scroll","color_con/color_drop",
  20. "career_con/career_drop", "career_con/career_text:tmp", "career_con:obj",
  21. }
  22. self:GetChildren(self.nodes)
  23. self:InitDropDown()
  24. self:AddEvents()
  25. if self.need_refreshData then
  26. self:UpdateView()
  27. end
  28. end
  29. function MarketAttentionView:AddEvents( )
  30. local function on_click( ... )
  31. self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15516, self.sell_type or self.last_sell_type, self.sell_sub_type)
  32. end
  33. AddClickEvent(self.clean_btn_obj, on_click)
  34. end
  35. function MarketAttentionView:InitDropDown()
  36. local list = {}
  37. local cfg_color = Config.Marketgoodsselectbycolor
  38. table.insert(list,"所有品质")
  39. for i,v in ipairs(cfg_color) do
  40. table.insert(list, v.describe)
  41. end
  42. self.color_index = 1
  43. local function update_color_func(index)
  44. self.color_index = index
  45. if index == 1 then
  46. self.color = 99
  47. else
  48. self.color = index-1
  49. end
  50. self.need_reset = true
  51. self:UpdateGoodsList()
  52. end
  53. local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
  54. if not self.combox_color then
  55. self.combox_color = Combox.New(self.color_drop,list,update_color_func,122,38,nil,prefab_data)
  56. else
  57. self.combox_color:ResetData(list,self.color_index,update_color_func,122,38)
  58. end
  59. local list = {}
  60. local cfg_lv = Config.Marketgoodsselectbylev
  61. table.insert(list,"不限套装")
  62. for i,v in ipairs(cfg_lv) do
  63. table.insert(list, v.stage.."")
  64. end
  65. local function update_series_func(index)
  66. self.series_index = index
  67. if index == 1 then
  68. self.series_limit = 0
  69. else
  70. self.series_limit = cfg_lv[index-1].id
  71. end
  72. self.need_reset = true
  73. self:UpdateGoodsList()
  74. end
  75. local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
  76. if not self.combox_series then
  77. self.combox_series = Combox.New(self.series_drop,list,update_series_func,122,38,nil,prefab_data)
  78. else
  79. self.combox_series:ResetData(list,self.series_index,update_series_func,122,38)
  80. end
  81. local list = {}
  82. local cfg_career = Config.Marketgoodsselectbycareer
  83. table.insert(list,"不限职业")
  84. for i,v in ipairs(cfg_career) do
  85. table.insert(list, v.describe)
  86. end
  87. local function update_career_func(index)
  88. self.career_index = index
  89. if index == 1 then
  90. self.career_limit = 0
  91. else
  92. self.career_limit = cfg_career[index-1].id
  93. end
  94. if not self.is_first then
  95. if self.cur_hor_tab_index == 1 then
  96. self.model:CleanMarketGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
  97. else
  98. self.model:CleanMarketGuildGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
  99. end
  100. self.need_reset = true
  101. self:UpdateGoodsList()
  102. end
  103. end
  104. local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
  105. if not self.combox_career then
  106. self.combox_career = Combox.New(self.career_drop,list,update_career_func,122,38,nil,prefab_data)
  107. else
  108. self.combox_career:ResetData(list,self.career_index,update_career_func,122,38)
  109. end
  110. end
  111. function MarketAttentionView:UpdateView( )
  112. self:UpdateVerTabBtns(true)
  113. end
  114. function MarketAttentionView:UpdateVerTabBtns( need_refresh )
  115. self.tab_cfg = self.model:GetMarketGoodsCFG()
  116. self.tab_creator = self.tab_creator or self:AddUIComponent(UI.ItemListCreator)
  117. -- 声明点击回调
  118. local data = {}
  119. if (self.sell_type and need_refresh) or self.tab_all_close then
  120. for i,v in pairsByKeys(self.tab_cfg) do
  121. if i == self.sell_type then--如果是当前选中的第一层
  122. table_insert(data, DeepCopy(v))
  123. data[#data].is_tab = true
  124. table_insert(data, {name = "全部", is_zero = true, sell_sub_type = 0, sell_type = i})--为了插一个全部
  125. for ii,vv in pairsByKeys(v) do
  126. table_insert(data, DeepCopy(vv))
  127. end
  128. else
  129. table_insert(data, DeepCopy(v))
  130. data[#data].is_tab = true
  131. end
  132. end
  133. else
  134. data = self.tab_data
  135. end
  136. if not self.sell_sub_type then--没选中就默认选第一个
  137. self.sell_sub_type = 0
  138. end
  139. self.tab_data = data
  140. local call_back = function(data, sell_type, sell_sub_type)
  141. local need_refresh = self.sell_type ~= sell_type
  142. self.need_reset = true
  143. if sell_type == 0 then
  144. self.career_limit = 0--热卖的话就不用筛职业
  145. elseif sell_type ~= 0 and sell_type ~= 1 and sell_type ~= 3 then --其他类别的 不筛选职业和套装
  146. self.career_limit = 0
  147. self.series_limit = 0
  148. elseif sell_type == 1 and need_refresh then --切页签了 要默认筛自己的防具
  149. local cfg_career = MarketConst.Sex
  150. local career = RoleManager.Instance.mainRoleInfo.career
  151. local career_index = self.model:GetMarketDefultSelectIndexByType(MarketConst.FliterType.Armor, career)
  152. self.career_limit = cfg_career[career_index-1].id
  153. elseif sell_type == 3 and need_refresh then --切页签了 要默认筛自己的武器
  154. local career = RoleManager.Instance.mainRoleInfo.career
  155. -- local cfg_career = MarketConst.Career
  156. -- local career_index = self.model:GetMarketDefultSelectIndexByType(MarketConst.FliterType.Armor, career)
  157. -- self.career_limit = self.model:GetMarketFliterCareerBySex(cfg_career[career_index-1].id)
  158. self.career_limit = career
  159. end
  160. if not need_refresh and not sell_sub_type then--如果不需要刷新 且点到了tab 意思就是要收起来tab
  161. self.need_reset = false
  162. self.tab_all_close = true
  163. self.last_sell_type = self.sell_type --先保存起来上一个选中的tab
  164. self.sell_type = nil
  165. else
  166. self.tab_all_close = false
  167. self.sell_type = sell_type
  168. end
  169. if sell_sub_type then
  170. self.sell_sub_type = sell_sub_type
  171. elseif need_refresh then
  172. self.sell_sub_type = sell_sub_type
  173. end
  174. self:UpdateVerTabBtns(need_refresh)
  175. self:UpdateSelectVer(need_refresh)
  176. end
  177. local tag_all_info = {
  178. data_list = data,
  179. item_con = self.left_con,
  180. item_class = MarketVerTabItem,
  181. item_width = 206,
  182. get_item_height = function(i)
  183. return data[i].is_tab and 56 or 48
  184. end,
  185. reuse_item_num = 12,
  186. start_x = 2,
  187. start_y = -10,
  188. space_y = 2,
  189. scroll_view = self.left_scroll,
  190. create_frequency = 0.01,
  191. on_update_item = function(item, i, v)
  192. item:SetData(v, i, self.sell_type, self.sell_sub_type, MarketModel.VER_TAB_TYPE.ATTENTION_TYPE)
  193. item:SetCallBackFunc(call_back)
  194. end,
  195. }
  196. self.tab_creator:UpdateItems(tag_all_info)
  197. if self.is_first then
  198. self:UpdateSelectVer(true)
  199. self:UpdateGoodsList()
  200. self.is_first = false
  201. end
  202. if need_refresh then
  203. self:UpdateFliter()
  204. end
  205. end
  206. --设置垂直tab选择
  207. function MarketAttentionView:UpdateSelectVer( need_refresh )
  208. self.tab_creator:IterateItems(function(item, i, v)
  209. item:SetSelect(self.sell_type, self.sell_sub_type)
  210. end)
  211. self:UpdateGoodsList()
  212. if need_refresh then
  213. self:ScrollToSelectItem()
  214. end
  215. end
  216. function MarketAttentionView:ScrollToSelectItem( )
  217. if not self.sell_sub_type then--如果没有选中第二层的item就默认选第一个
  218. self.sell_sub_type = 0
  219. end
  220. for i,v in ipairs(self.tab_data) do
  221. if v.sell_type == self.sell_type and v.sell_sub_type == self.sell_sub_type then
  222. self.tab_creator:ScrollToItem(i-1)
  223. end
  224. end
  225. end
  226. function MarketAttentionView:UpdateGoodsList( )
  227. local goods_list = self.model:GetMarketGoodsCFG(self.sell_type or self.last_sell_type, self.sell_sub_type) or {}
  228. local data = {}
  229. local color_pass, series_pass, career_pass
  230. -- local lv_min, lv_max = self.model:GetMarketFliterLv(self.series_limit)
  231. if self.sell_sub_type == 0 then--如果是全部 就要遍历两层
  232. for i,v in pairsByKeys(goods_list) do
  233. for ii,vv in ipairs(v) do
  234. if self.color ~= 99 or self.series_limit ~= 0 or self.career_limit ~= 0 then--需要筛选品质 职业 套
  235. if self.color ~= 99 then
  236. if vv.color == self.color then
  237. color_pass = true
  238. else
  239. color_pass = false
  240. end
  241. else
  242. color_pass = true
  243. end
  244. if color_pass then--如果颜色判断通过 判断职业限制
  245. career_pass = self.model:CheckMarketGoodsCanWear(self.career_limit, vv.career)
  246. else
  247. career_pass = false
  248. end
  249. if career_pass then--如果颜色判断通过 再判断套装限制
  250. if self.series_limit ~= 0 then
  251. if self.series_limit == vv.series then
  252. series_pass = true
  253. else
  254. series_pass = false
  255. end
  256. else
  257. series_pass = true
  258. end
  259. if series_pass then
  260. table_insert(data, vv)
  261. end
  262. else
  263. end
  264. else
  265. table_insert(data, vv)
  266. end
  267. end
  268. end
  269. else
  270. for i,v in ipairs(goods_list) do
  271. if self.color ~= 99 or self.series_limit ~= 0 or self.career_limit ~= 0 then--需要筛选品质 职业 套
  272. if self.color ~= 99 then
  273. if v.color == self.color then
  274. color_pass = true
  275. else
  276. color_pass = false
  277. end
  278. else
  279. color_pass = true
  280. end
  281. if color_pass then--如果颜色判断通过 判断职业限制
  282. career_pass = self.model:CheckMarketGoodsCanWear(self.career_limit, v.career)
  283. else
  284. career_pass = false
  285. end
  286. if career_pass then--如果职业判断通过 再判断套装限制
  287. if self.series_limit ~= 0 then
  288. if self.series_limit == v.series then
  289. series_pass = true
  290. else
  291. series_pass = false
  292. end
  293. else
  294. series_pass = true
  295. end
  296. if series_pass then
  297. table_insert(data, v)
  298. end
  299. end
  300. else
  301. table_insert(data, v)
  302. end
  303. end
  304. end
  305. local function sortfunction( a,b )
  306. local a_attention = self.model:IsMarketAttentionGoods(a.type_id)
  307. local b_attention = self.model:IsMarketAttentionGoods(b.type_id)
  308. if a_attention == b_attention then
  309. return a.type_id < b.type_id
  310. else
  311. return a_attention
  312. end
  313. end
  314. table.sort( data, sortfunction )
  315. if not self.goods_list_com then
  316. self.goods_list_com = self:AddUIComponent(UI.ItemListCreator)
  317. end
  318. if self.need_reset then
  319. self.goods_list_com:Reset()
  320. self.need_reset = false
  321. end
  322. local info = {
  323. data_list = data,
  324. item_con = self.right_con,
  325. scroll_view = self.right_scroll,
  326. item_class = MarketAttentionItem,
  327. start_y = 0, start_x = 8,
  328. create_frequency = 0.02,
  329. create_num_per_time = 3,
  330. item_height = 100,
  331. space_y = 0,
  332. on_update_item = function(item, i, v)
  333. item:SetData(i, v)
  334. end,
  335. }
  336. self.goods_list_com:UpdateItems(info)
  337. end
  338. --更新筛选栏状态
  339. function MarketAttentionView:UpdateFliter( )
  340. local fliter_type = self.model:GetFliterType(self.sell_type,self.sell_sub_type)
  341. if fliter_type == MarketConst.FliterType.Armor then
  342. self.career_con_obj:SetActive(true)
  343. self.series_con_obj:SetActive(true)
  344. self.color_con_obj:SetActive(true)
  345. self.career_text_tmp.text = "性别"
  346. local list = {}
  347. local cfg_career = MarketConst.Sex
  348. local career = RoleManager.Instance.mainRoleInfo.career
  349. self.career_index = self.model:GetMarketDefultSelectIndexByType(fliter_type, career)
  350. table.insert(list,"不限性别")
  351. for i,v in ipairs(cfg_career) do
  352. table.insert(list, v.name)
  353. end
  354. local function update_career_func(index)
  355. self.career_index = index
  356. if index == 1 then
  357. self.career_limit = 0
  358. else
  359. self.career_limit = self.model:GetMarketFliterCareerBySex(cfg_career[index-1].id)
  360. end
  361. if not self.is_first then
  362. if self.cur_hor_tab_index == 1 then
  363. self.model:CleanMarketGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
  364. else
  365. self.model:CleanMarketGuildGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
  366. end
  367. self.need_reset = true
  368. self:UpdateGoodsList()
  369. end
  370. end
  371. local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
  372. if not self.combox_career then
  373. self.combox_career = Combox.New(self.career_drop,list,update_career_func,122,38,nil,prefab_data)
  374. else
  375. self.combox_career:ResetData(list,self.career_index,update_career_func,122,38,nil,true, prefab_data)
  376. end
  377. elseif fliter_type == MarketConst.FliterType.Weapon then
  378. self.career_con_obj:SetActive(true)
  379. self.series_con_obj:SetActive(true)
  380. self.color_con_obj:SetActive(true)
  381. self.career_text_tmp.text = "职业"
  382. local list = {}
  383. local cfg_career = MarketConst.Career
  384. local career = RoleManager.Instance.mainRoleInfo.career
  385. self.career_index = self.model:GetMarketDefultSelectIndexByType(fliter_type, career)
  386. table.insert(list,"不限职业")
  387. for i,v in ipairs(cfg_career) do
  388. table.insert(list, v.name)
  389. end
  390. local function update_career_func(index)
  391. self.career_index = index
  392. if index == 1 then
  393. self.career_limit = 0
  394. else
  395. self.career_limit = cfg_career[index-1].id
  396. end
  397. if not self.is_first then
  398. if self.cur_hor_tab_index == 1 then
  399. self.model:CleanMarketGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
  400. else
  401. self.model:CleanMarketGuildGoodsInfoByType(self.sell_type or self.last_sell_type, self.sell_sub_type)
  402. end
  403. self.need_reset = true
  404. self:UpdateGoodsList()
  405. end
  406. end
  407. local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height-9, show_type = "down"}
  408. if not self.combox_career then
  409. self.combox_career = Combox.New(self.career_drop,list,update_career_func,122,38,nil,prefab_data)
  410. else
  411. self.combox_career:ResetData(list,self.career_index,update_career_func,122,38,nil,true,prefab_data)
  412. end
  413. elseif fliter_type == MarketConst.FliterType.Other then
  414. self.career_con_obj:SetActive(false)
  415. self.series_con_obj:SetActive(false)
  416. self.color_con_obj:SetActive(true)
  417. elseif fliter_type == MarketConst.FliterType.Hot then
  418. self.career_con_obj:SetActive(false)
  419. self.series_con_obj:SetActive(true)
  420. self.color_con_obj:SetActive(true)
  421. end
  422. end
  423. function MarketAttentionView:SetData( data )
  424. self.data = data
  425. if self.is_loaded then
  426. self.need_refreshData = false
  427. self:UpdateView()
  428. else
  429. self.need_refreshData = true
  430. end
  431. end
  432. function MarketAttentionView:__delete( )
  433. if self.combox_career then
  434. self.combox_career:DeleteMe()
  435. self.combox_career = nil
  436. end
  437. if self.combox_series then
  438. self.combox_series:DeleteMe()
  439. self.combox_series = nil
  440. end
  441. if self.combox_color then
  442. self.combox_color:DeleteMe()
  443. self.combox_color = nil
  444. end
  445. end