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

113 lines
3.1 KiB

  1. CapsuleEggWarehouseView = CapsuleEggWarehouseView or BaseClass(BaseItem)
  2. local CapsuleEggWarehouseView = CapsuleEggWarehouseView
  3. function CapsuleEggWarehouseView:__init()
  4. self.base_file = "capsuleEgg"
  5. self.layout_file = "CapsuleEggWarehouseView"
  6. self.model = CapsuleEggModel:getInstance()
  7. self.bag_item_list = {} --背包物品列表
  8. self.column_num = 9 --一行几个图标
  9. self.defult_slot = 45 --默认最少生成空格数
  10. self.warehouse_item_count = 0 --仓库物品数量
  11. self:Load()
  12. end
  13. function CapsuleEggWarehouseView:Load_callback()
  14. self.nodes = {
  15. "ScrollView", "ScrollView/Viewport/Content", "ScrollView/Viewport/Content/item_con",
  16. "takeOutBtn:obj",
  17. }
  18. self:GetChildren(self.nodes)
  19. self.loop_mgr = LoopScrowViewMgr.New()
  20. self:AddEvents()
  21. if self.need_refreshData then
  22. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17007)
  23. end
  24. end
  25. function CapsuleEggWarehouseView:AddEvents( )
  26. local on_click = function ( click_obj )
  27. if self.takeOutBtn_obj == click_obj then --一键取出
  28. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17009)
  29. end
  30. end
  31. AddClickEvent(self.takeOutBtn_obj, on_click)
  32. --取出之后的处理
  33. local function on_take_all()
  34. if self.is_loaded then
  35. self:UpdateView()
  36. end
  37. end
  38. self:BindEvent(self.model,CapsuleEggConst.TAKE_OUT_ALL_REWARD,on_take_all)
  39. --刷新仓库界面
  40. local function on_update_warehouse_view()
  41. if self.is_loaded then
  42. self:UpdateView()
  43. end
  44. end
  45. self:BindEvent(self.model,CapsuleEggConst.UPDATE_WAREHOUSE_VIEW,on_update_warehouse_view)
  46. end
  47. function CapsuleEggWarehouseView:UpdateView( )
  48. self.warehouse_data = self.model:GetWarehouseData()
  49. self.warehouse_item_count = #self.warehouse_data
  50. local total_num = 0
  51. if self.warehouse_item_count > self.defult_slot then
  52. total_num = self.warehouse_item_count+(9-self.warehouse_item_count%9)
  53. else
  54. total_num = self.defult_slot
  55. end
  56. for k = 1,self.defult_slot do
  57. local item = self.bag_item_list[k]
  58. if item == nil then
  59. item = CapsuleEggWarehouseItem.New(self.item_con,nil,self.layer_name)
  60. item:SetVisible(false,true)
  61. self.bag_item_list[k] = item
  62. end
  63. end
  64. self.loop_mgr:Init(self.ScrollView,self.Content,self.column_num,84+17,84+6,function(item,index,realIndex )
  65. self:OnInitializeItem(item,index,realIndex )
  66. end)
  67. self.loop_mgr:InitChildren(self.bag_item_list, total_num)
  68. self.loop_mgr:RestToBeginning()
  69. self.loop_mgr:ForceUpdateCurrentItems()
  70. self.loop_mgr:SetContentSizeData()
  71. end
  72. function CapsuleEggWarehouseView:OnInitializeItem(item,index,realIndex)
  73. if item and realIndex > 0 and realIndex <= self.warehouse_item_count then
  74. item:SetData(self.warehouse_data[realIndex],realIndex)
  75. else
  76. item:SetData(nil)
  77. end
  78. end
  79. function CapsuleEggWarehouseView:SetData( )
  80. if self.is_loaded then
  81. self.need_refreshData = false
  82. self.model:Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17007)
  83. else
  84. self.need_refreshData = true
  85. end
  86. end
  87. function CapsuleEggWarehouseView:__delete( )
  88. for k,v in pairs(self.bag_item_list) do
  89. v:DeleteMe()
  90. v = nil
  91. end
  92. self.bag_item_list = {}
  93. if self.loop_mgr then
  94. self.loop_mgr:DeleteMe()
  95. self.loop_mgr = nil
  96. end
  97. end