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

119 lines
2.8 KiB

  1. GoodsDestroyView = GoodsDestroyView or BaseClass(BaseView)
  2. local GoodsDestroyView = GoodsDestroyView
  3. function GoodsDestroyView:__init()
  4. self.base_file = "bag"
  5. self.layout_file = "GoodsDestroyView"
  6. self.layer_name = "Top"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.change_scene_close = true
  10. self.is_set_zdepth = true
  11. self.is_delay_callback = false
  12. self.fix_item_list = {}
  13. --self.use_local_view = true
  14. self.model = GoodsModel:getInstance()
  15. self.load_callback = function ()
  16. self:LoadSuccess()
  17. self:InitEvent()
  18. end
  19. self.open_callback = function ()
  20. self:InitView()
  21. end
  22. self.close_callback = function ()
  23. self:Remove()
  24. end
  25. end
  26. function GoodsDestroyView:Remove()
  27. for i,item in pairs(self.fix_item_list) do
  28. item:ReleaseObj()
  29. end
  30. self.fix_item_list = {}
  31. end
  32. function GoodsDestroyView:InitView()
  33. self.destroy_list = {}
  34. local data = nil
  35. local goods_dic = self.model:GetBagGoodsDic()
  36. for index,good_vo in pairs(goods_dic) do
  37. if self.model:CheckIsExpireTime(good_vo) then
  38. if #self.destroy_list < 20 then --一次性最多20个
  39. data = {
  40. style = 0,
  41. typeId = good_vo.type_id,
  42. goods_id = good_vo.goods_id,
  43. count = good_vo.goods_num
  44. }
  45. table.insert(self.destroy_list,data)
  46. end
  47. end
  48. end
  49. local total_list = self.destroy_list
  50. if #total_list < 5 then
  51. self.item_parent.anchoredPosition = Vector2(240 - ((#total_list - 1) * 98 + 84 )/ 2,-17)
  52. else
  53. self.item_parent.anchoredPosition = Vector2(6,-17)
  54. end
  55. for i,v in ipairs(total_list) do
  56. local item = self.fix_item_list[i]
  57. if item == nil then
  58. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_parent)
  59. self.fix_item_list[i] = item
  60. end
  61. local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v.style, v.typeId)
  62. item:SetData(goods_Id,v.count,nil,nil,lock,nil,nil,nil,self.layer_name)
  63. item:SetVisible(true)
  64. item:SetItemSize(90, 90)
  65. item:SetAnchoredPosition(98 * (i - 1),0)
  66. end
  67. self.mContent.sizeDelta = Vector2(#total_list * 98,200)
  68. for i=#total_list + 1,#self.fix_item_list do
  69. self.fix_item_list[i]:SetVisible(false)
  70. end
  71. end
  72. function GoodsDestroyView:LoadSuccess()
  73. self.confirmBtn,
  74. self.cancelBtn = self:GetChildGameObjects({
  75. "confirmBtn",
  76. "cancelBtn",
  77. })
  78. self.mContent,
  79. self.item_parent = self:GetChildTransforms({
  80. "ScrollView/Viewport/Content",
  81. "ScrollView/Viewport/Content/ItemParent",
  82. })
  83. end
  84. function GoodsDestroyView:Open()
  85. BaseView.Open(self)
  86. end
  87. function GoodsDestroyView:InitEvent()
  88. local function click_handler(target)
  89. if target == self.confirmBtn then
  90. if #self.destroy_list > 0 then
  91. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15051,1, self.destroy_list)
  92. end
  93. self:Close()
  94. elseif target == self.cancelBtn then
  95. self:Close()
  96. end
  97. end
  98. AddClickEvent(self.confirmBtn, click_handler, 2)
  99. AddClickEvent(self.cancelBtn, click_handler, 2)
  100. end