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

266 lines
7.5 KiB

  1. DepotView = DepotView or BaseClass(BaseItem)
  2. function DepotView:__init(parent_wnd, prefab_asset, layer_name)
  3. self.base_file = "bag"
  4. self.layout_file = "DepotView"
  5. self.item_list = {}
  6. self.curr_list = {}
  7. self.event_list = {}
  8. self.column_num = 4 --一行多少个图标
  9. self.loop_mgr = LoopScrowViewMgr.New()
  10. self.model = GoodsModel:getInstance()
  11. self.titleTabbar = {[1] = "全部",[2] = "常用",[3] = "礼包",}
  12. self.title_cur_index = 1
  13. self.titleTabbar_list = {}
  14. self.titleTabbar_text = {}
  15. self.need_sort = true
  16. self.full_screen = true
  17. self.ani_right = 400
  18. self:Load()
  19. end
  20. --清除界面
  21. function DepotView:__delete()
  22. self:Clear()
  23. end
  24. function DepotView:Load_callback()
  25. self:LoadSuccess()
  26. self:InitEvent()
  27. end
  28. function DepotView:Clear()
  29. for i,item in pairs(self.item_list) do
  30. item:DeleteMe()
  31. end
  32. self.item_list = {}
  33. for k,v in pairs(self.event_list) do
  34. GoodsModel:getInstance():UnBind(v)
  35. v = nil
  36. end
  37. if self.loop_mgr then
  38. self.loop_mgr:DeleteMe()
  39. self.loop_mgr = nil
  40. end
  41. if self.maskID then
  42. self:UnRegisterMask(self.maskID)
  43. self.maskID = nil
  44. end
  45. if self.step_sort_bag_cd_id then
  46. GlobalTimerQuest:CancelQuest(self.step_sort_bag_cd_id)
  47. self.step_sort_bag_cd_id = nil
  48. end
  49. end
  50. function DepotView:Close()
  51. BaseView.Close(self)
  52. end
  53. function DepotView:LoadSuccess()
  54. self.scroll_image = self:GetChild("right/ScrollView/Viewport"):GetComponent("Image")
  55. self.scroll,self.scroll_content,
  56. self.con = GetChildTransforms(self.transform,
  57. {
  58. "right/ScrollView","right/ScrollView/Viewport/Content",
  59. "right/ScrollView/Viewport/Content/con"
  60. })
  61. self.sortBtn = GetChildGameObjects (self.transform,
  62. {
  63. "right/Button"
  64. })
  65. self.sortBtn_img = self:GetChild("right/Button"):GetComponent("Image")
  66. self.sortBtn_txt = self:GetChild("right/Button/Text"):GetComponent("TextMeshProUGUI")
  67. for i=1,#self.titleTabbar do
  68. table.insert(self.titleTabbar_list,self:GetChild("right/titleBarCon/tabbar"..i).gameObject)
  69. table.insert(self.titleTabbar_text,self:GetChild("right/titleBarCon/tabbar"..i.."/Background/Text"):GetComponent("TextMeshProUGUI"))
  70. end
  71. self:SetTextColor(self.title_cur_index)
  72. self.maskID = self:RegisterMask(self.scroll_image)
  73. BagModel:getInstance().cur_click_bag_time = 0
  74. BagModel:getInstance().cur_click_warehouse_time = 0
  75. self:UpdateItems(true)
  76. end
  77. function DepotView:InitEvent()
  78. local function onBtnClickHandler(target)
  79. if target == self.close_btn then
  80. self:Close()
  81. elseif target == self.sortBtn then
  82. self.need_sort = true
  83. if BagModel:getInstance():TrySortBag(GoodsModel.GOODS_POS_TYPE.warehouse) then
  84. self.model:DelayFire(GoodsModel.CHANGE_WAREHOUSE_LIST)
  85. end
  86. self:UpdateSortCD()
  87. --GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15004,GoodsModel.GOODS_POS_TYPE.warehouse)
  88. else
  89. for i,v in ipairs(self.titleTabbar) do
  90. local obj = self.titleTabbar_list[i]
  91. if target == obj then
  92. self.title_cur_index = i
  93. self:SetTextColor(self.title_cur_index)
  94. self:UpdateItems()
  95. self.loop_mgr:RestToBeginning()
  96. break
  97. end
  98. end
  99. end
  100. end
  101. --AddClickEvent(self.close_btn,onBtnClickHandler)
  102. AddClickEvent(self.sortBtn,onBtnClickHandler)
  103. for i=1,#self.titleTabbar do
  104. AddClickEvent(self.titleTabbar_list[i],onBtnClickHandler)
  105. end
  106. local function onChangeBagListHandler()
  107. self:UpdateItems()
  108. end
  109. self.event_list[1] = self.model:Bind(GoodsModel.CHANGE_WAREHOUSE_LIST,onChangeBagListHandler)
  110. local function event_func2()
  111. self:UpdateItems()
  112. end
  113. self.event_list[2] = self.model:BindOne("slot_info_pos_3",event_func2)
  114. local click_fun = function (index,pos_type)
  115. if pos_type == GoodsModel.GOODS_POS_TYPE.warehouse then
  116. self.click_item_index = index
  117. self:UpdateItemState()
  118. end
  119. end
  120. self.event_list[3] = self.model:Bind(GoodsModel.CLICK_BAG_ITEM, click_fun)
  121. end
  122. function DepotView:SetTextColor( )
  123. for i,v in ipairs(self.titleTabbar_text) do
  124. if self.title_cur_index == i then
  125. v.text = "<color=#ffffff>"..self.titleTabbar[i].."</color>"
  126. SetTMPSharedMaterial(v, ShaderTools.TMPSharedMaterialType.HKYTW7OutlineBlueTab)
  127. else
  128. v.text = "<color=#9eb3cf>"..self.titleTabbar[i].."</color>"
  129. SetTMPSharedMaterial(v, ShaderTools.TMPSharedMaterialType.MSYHSDFDefault)
  130. end
  131. end
  132. end
  133. function DepotView:UpdateItems(to_top)
  134. local item = nil
  135. local info = self.model.slot_info_pos_3
  136. local slot_num = info.slot_num
  137. local all_slot = info.all_slot
  138. local warehouse_goods_list = self.model.warehouse_goods_list
  139. if self.need_sort then
  140. self.need_sort = false
  141. self.model:SortBagListByBagView(warehouse_goods_list)
  142. self.model:SortBagListByBagView(self.model.warehouse_goods_list)
  143. end
  144. self.curr_list = {}
  145. local m_index = 1
  146. for k,v in pairs(warehouse_goods_list) do
  147. if self.title_cur_index == 2 then ---常用(消耗 3 和 碎片 4)
  148. if self.model:GetGoodsTab(v.type, v.subtype) == 3 or self.model:GetGoodsTab(v.type, v.subtype) == 4 then
  149. self.curr_list[m_index] = v
  150. self.curr_list[m_index].index = m_index
  151. m_index = m_index + 1
  152. end
  153. elseif self.title_cur_index == 3 then --礼包
  154. if self.model:GetGoodsTab(v.type, v.subtype) == 5 then
  155. self.curr_list[m_index] = v
  156. self.curr_list[m_index].index = m_index
  157. m_index = m_index + 1
  158. end
  159. else --全部
  160. self.curr_list[k] = v
  161. self.curr_list[k].index = k
  162. end
  163. end
  164. if slot_num and all_slot then
  165. for k = #self.curr_list + 1,slot_num do
  166. self.curr_list[k] = {type_id = 0, goods_num = 0,index = k}
  167. end
  168. for k = slot_num + 1,all_slot do
  169. self.curr_list[k] = {lock_index = k - slot_num,index = k}
  170. end
  171. for k = 1,35 do
  172. local item = self.item_list[k]
  173. if item == nil then
  174. item = BagItem.New(self.con,nil,self.maskID)
  175. self.item_list[k] = item
  176. item:SetPosType(GoodsModel.GOODS_POS_TYPE.warehouse)
  177. end
  178. end
  179. end
  180. if to_top then
  181. self.loop_mgr:Init(self.scroll,self.scroll_content,self.column_num,89.5,89.5,function(item,index,realIndex )
  182. self:OnInitializeItem(item,index,realIndex )
  183. end, 0, 0, {x=10,y=-6})
  184. self.loop_mgr:InitChildren(self.item_list, #self.curr_list)
  185. self.loop_mgr:RestToBeginning()
  186. self.loop_mgr:SetContentSizeData()
  187. else
  188. self.loop_mgr:InitChildren(self.item_list, #self.curr_list)
  189. self.loop_mgr:ForceUpdateCurrentItems()
  190. self.loop_mgr:SetContentSizeData()
  191. end
  192. end
  193. function DepotView:OnInitializeItem(item,index,realIndex)
  194. if item and realIndex > 0 and realIndex <= #self.curr_list then
  195. item:SetData(self.curr_list[realIndex],self.maskID, nil,nil, "BagView")
  196. self:UpdateItemState()
  197. end
  198. end
  199. function DepotView:UpdateItemState()
  200. if not self.click_item_index then return end
  201. for k,item in pairs(self.item_list) do
  202. item:SetSelect(item.index == self.click_item_index)
  203. end
  204. end
  205. function DepotView:UpdateSortCD( )
  206. if not self.is_loaded then return end
  207. local last_sort_bag_time = BagModel:getInstance():GetLastSortBagTime(GoodsModel.GOODS_POS_TYPE.warehouse)
  208. if not last_sort_bag_time then
  209. self.sortBtn_img.color = ColorUtilValue.WHITE
  210. self.sortBtn_txt.text = "整理"
  211. return
  212. end
  213. local function step_sort_bag_cd( ... )
  214. local left_cd = 5 - (Time.time - last_sort_bag_time)
  215. if left_cd > 0 then
  216. self.sortBtn_txt.text = math.ceil(left_cd)
  217. self.sortBtn_img.color = Color(148/255,148/255,148/255)
  218. else
  219. self.sortBtn_img.color = ColorUtilValue.WHITE
  220. self.sortBtn_txt.text = "整理"
  221. if self.step_sort_bag_cd_id then
  222. GlobalTimerQuest:CancelQuest(self.step_sort_bag_cd_id)
  223. self.step_sort_bag_cd_id = nil
  224. end
  225. end
  226. end
  227. step_sort_bag_cd()
  228. if not self.step_sort_bag_cd_id then
  229. self.step_sort_bag_cd_id = GlobalTimerQuest:AddPeriodQuest(step_sort_bag_cd, 1, -1)
  230. end
  231. end