源战役客户端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

159 satır
4.9 KiB

  1. GoodsBatchBuyView = GoodsBatchBuyView or BaseClass(BaseView)
  2. local GoodsBatchBuyView = GoodsBatchBuyView
  3. -- 批量购买界面
  4. function GoodsBatchBuyView:__init(parent)
  5. self.base_file = "bag"
  6. self.layout_file = "GoodsBatchBuyView"
  7. self.layer_name = "Top"
  8. self.destroy_imm = true
  9. self.use_background = true
  10. self.change_scene_close = true
  11. self.is_set_zdepth = true
  12. --回调方法
  13. self.load_callback = function()
  14. self:LoadSuccess()
  15. self:InitEvent()
  16. end
  17. self.open_callback = function()
  18. self:SetData()
  19. end
  20. self.close_callback = function()
  21. local vo = ItemUseModel:getInstance():GetItemShowVo()
  22. if vo then
  23. GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
  24. end
  25. end
  26. self.destroy_callback = function()
  27. self:Clear()
  28. end
  29. end
  30. function GoodsBatchBuyView:LoadSuccess()
  31. self.cancelBtn = self:GetChild("cancelBtn").gameObject
  32. self.okBtn = self:GetChild("okBtn").gameObject
  33. self.nameText = self:GetChild("nameText"):GetComponent("Text")
  34. self.itemCon = self:GetChild("itemCon")
  35. self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.itemCon)
  36. self.awardItem:SetItemSize(108,108)
  37. self.addNumComponent = AddNumberComponent.New(self:GetChild("addNumCon"))
  38. self.addNumComponent:SetComponentWidth(422)
  39. local function onChangeCountHandler(count)
  40. self:ChangeCount(count)
  41. end
  42. self.change_count_id = self.addNumComponent:Bind(ComponentEvent.AddNumberComponent.CHANGE_COUNT, onChangeCountHandler)
  43. self.addNumComponent:SetVisibleCalcBtn(false)
  44. self.addNumComponent:InitData(1, 99, 1, 1, 6)
  45. local nodes = {
  46. "Window:raw",
  47. }
  48. self:GetChildren(nodes)
  49. lua_resM:setOutsideRawImage(self, self.Window_raw, GameResPath.GetViewBigBg("tips_comm_bg6"), false)
  50. end
  51. function GoodsBatchBuyView:InitEvent()
  52. local function onClickHandler(target)
  53. if target == self.cancelBtn then
  54. self:Close()
  55. elseif target == self.okBtn then
  56. self:BtnCall()
  57. end
  58. end
  59. AddClickEvent(self.cancelBtn,onClickHandler)
  60. AddClickEvent(self.okBtn,onClickHandler)
  61. -- local function onChangeCountHandler(count)
  62. -- self:ChangeCount(count)
  63. -- end
  64. -- self.change_count_id = self.addNumComponent:Bind(ComponentEvent.AddNumberComponent.CHANGE_COUNT,onChangeCountHandler)
  65. end
  66. function GoodsBatchBuyView:Open(goods_id, cur_count, max_count)
  67. self.goods_id = goods_id
  68. self.cur_count = cur_count
  69. self.max_count = max_count
  70. self.vo = GoodsModel:getInstance():GetBagGoodsInfoById(goods_id)
  71. BaseView.Open(self)
  72. end
  73. function GoodsBatchBuyView:SetData( )
  74. if not self.vo or not self.vo.type_id then return end
  75. local bagGoods = GoodsModel:getInstance():GetBagGoodsInfoById(self.goods_id)
  76. local has_num = bagGoods.goods_num --单独数量,不是绑定+非绑定数量
  77. if self.max_count and has_num >= self.max_count then
  78. has_num = self.max_count
  79. end
  80. self.awardItem:SetData(self.vo.type_id, has_num, nil, nil, nil, nil, nil, nil, nil, true)
  81. self.nameText.text = "<color="..WordManager.GetGoodsColor(self.vo.color)..">" .. Trim(self.vo.goods_name).."</color>"
  82. if self.vo.type==38 and self.vo.subtype==7 then
  83. local max = OffLineModel:getInstance():GetNumMax(self.vo.type_id)
  84. if has_num < max then
  85. max = has_num
  86. end
  87. self.addNumComponent:InitData(1,has_num,1, max)
  88. elseif self.vo.type == 37 and self.vo.subtype == 2 then--经验药水
  89. self.addNumComponent:InitData(1,has_num,1,1)
  90. elseif self.vo.type == 38 and (self.vo.subtype == 35 or self.vo.subtype == 34) then--副本扫荡卷
  91. self.addNumComponent:InitData(1,has_num,1,1)
  92. else
  93. local num = self.cur_count or has_num
  94. self.addNumComponent:InitData(1,has_num,1,num)
  95. end
  96. end
  97. function GoodsBatchBuyView:ChangeCount(count)
  98. if self.vo and self.vo.type_id then
  99. self.awardItem:SetData(self.vo.type_id, count, nil, nil, nil, nil, nil, nil, nil, true)
  100. end
  101. end
  102. function GoodsBatchBuyView:Clear( )
  103. if self.awardItem then
  104. self.awardItem:ReleaseObj()
  105. self.awardItem = nil
  106. end
  107. if self.addNumComponent then
  108. if self.change_count_id then
  109. self.addNumComponent:UnBind(self.change_count_id)
  110. self.change_count_id = nil
  111. end
  112. self.addNumComponent:DeleteMe()
  113. self.addNumComponent = nil
  114. end
  115. end
  116. function GoodsBatchBuyView:BtnCall( )
  117. if not self.vo or not self.goods_id then return end
  118. local cur_num = self.addNumComponent:GetCurrCount()--self.buy_slider.value
  119. if cur_num==0 then
  120. Message.show("使用数量不能为0")
  121. return
  122. else
  123. if self.vo.type==38 and self.vo.subtype==7 then
  124. --离线挂机卡特殊判断
  125. OffLineModel:getInstance():OnBuy(self.goods_id, cur_num)
  126. elseif self.vo.type==37 and self.vo.subtype==3 then
  127. FishModel:getInstance():OnBuy(self.goods_id, cur_num)
  128. else
  129. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.goods_id, self.vo.type_id, cur_num)
  130. end
  131. if self.vo.type == 16 and self.vo.subtype == 7 then -- 坐骑幻形
  132. HorseModel:getInstance():UseItem(self.vo.type_id)
  133. end
  134. if self.vo.type == 20 and self.vo.subtype == 5 then -- 坐骑幻形
  135. WingModel:getInstance():UseItem(self.vo.type_id)
  136. end
  137. end
  138. self:Close()
  139. end