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

150 line
4.9 KiB

  1. EnlargeView = EnlargeView or BaseClass(BaseView)
  2. function EnlargeView:__init()
  3. self.base_file = "bag"
  4. self.layout_file = "EnlargeView"
  5. self.layer_name = "Top"
  6. self.use_background = true
  7. self.is_set_zdepth = true
  8. self.model = GoodsModel:getInstance()
  9. self.load_callback = function ()
  10. self:LocalSuccess()
  11. end
  12. self.open_callback = function ()
  13. self:SetData()
  14. end
  15. self.destroy_callback = function ()
  16. self:Remove()
  17. end
  18. end
  19. function EnlargeView:Remove()
  20. if self.icon_item then
  21. self.icon_item:ReleaseObj()
  22. self.icon_item = nil
  23. end
  24. end
  25. function EnlargeView:LocalSuccess()
  26. self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self:GetChild("iconItem"))
  27. self.icon_item:ChangeCountVisible(false)
  28. self.bg_raw = self:GetChild("Window"):GetComponent("RawImage")
  29. self.num = self:GetChild("num"):GetComponent("TextMeshProUGUI")
  30. self.count_text = self:GetChild("countbg/count"):GetComponent("TextMeshProUGUI")
  31. self.btn_text = self:GetChild("confirmBtn/Text"):GetComponent("TextMeshProUGUI")
  32. self.name_text = self:GetChild("namebg/name"):GetComponent("TextMeshProUGUI")
  33. self.confirmBtn,self.lblTip, self.cancelBtn, self.addBtn, self.subBtn =GetChildGameObjects (self.transform,
  34. {
  35. "confirmBtn","lblTip", "cancelBtn", "addBtn", "subBtn",
  36. })
  37. lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("tips_comm_bg6"), false)
  38. self:InitEvent()
  39. end
  40. function EnlargeView:InitEvent()
  41. local function onBtnClickHandler(target)
  42. if target == self.confirmBtn then
  43. local own_count = GoodsModel:getInstance():GetTypeGoodsNum(102601)
  44. if own_count >= self.total_count then
  45. if target == self.confirmBtn then
  46. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15002,self.pos,self.lock_index)
  47. end
  48. else
  49. local function ok()
  50. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15002,self.pos,self.lock_index)
  51. end
  52. Alert.show(string.format("您的扩展钥匙不足,是否花费%d红钻补足缺额",self.total_cost),Alert.Type.Two,ok)
  53. end
  54. self:Close()
  55. elseif target == self.cancelBtn then
  56. self:Close()
  57. elseif target == self.addBtn then
  58. self:ChangeCount(self.lock_index + 1)
  59. elseif target == self.subBtn then
  60. self:ChangeCount(self.lock_index - 1)
  61. end
  62. end
  63. AddClickEvent(self.confirmBtn,onBtnClickHandler)
  64. AddClickEvent(self.cancelBtn,onBtnClickHandler)
  65. AddClickEvent(self.addBtn,onBtnClickHandler)
  66. AddClickEvent(self.subBtn,onBtnClickHandler)
  67. end
  68. function EnlargeView:Open(pos,lock_index)
  69. self.pos = pos or GoodsModel.GOODS_POS_TYPE.bag
  70. self.lock_index = lock_index
  71. BaseView.Open(self)
  72. end
  73. function EnlargeView:SetData()
  74. local good_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(102601)
  75. self.base_view_titleText:GetComponent("TextMeshProUGUI").text = string.format("拓展%s",self.pos == GoodsModel.GOODS_POS_TYPE.bag and "背包" or "仓库")
  76. self.btn_text.text = self.pos == GoodsModel.GOODS_POS_TYPE.bag and "拓展背包" or "拓展仓库"
  77. self.icon_item:SetData(102601, 1, nil, nil, true)
  78. self.icon_item:SetItemSize(62, 62)
  79. self.name_text.text = HtmlColorTxt(good_vo.goods_name, WordManager.GetGoodsColor(good_vo.color))
  80. local own_count = GoodsModel:getInstance():GetTypeGoodsNum(102601)
  81. local info
  82. if self.pos == GoodsModel.GOODS_POS_TYPE.bag then
  83. info = self.model.slot_info_pos_2
  84. else
  85. info = self.model.slot_info_pos_3
  86. end
  87. local slot_num = info.slot_num or 0 --开放格子
  88. local def_num = info.def_cell or 0 --默认开放格子数
  89. local isOpenNum = slot_num - def_num
  90. self.total_count,self.total_cost = 0,0
  91. for i=1,self.lock_index do
  92. local num,cost = self:GetEnlargeCost(i+isOpenNum)
  93. self.total_count = self.total_count + num
  94. if own_count < self.total_count then
  95. self.total_cost = self.total_cost + cost
  96. end
  97. end
  98. local color = own_count >= self.total_count and ColorUtil.GREEN or ColorUtil.RED
  99. self.icon_item:SetNumText("")
  100. self.count_text.text = string.format("<color=%s>%d</color>/%d",color,own_count,self.total_count)
  101. --self.count_text.text = string.format("%d/%d",own_count,self.total_count)
  102. self.num.text = self.lock_index
  103. --self.lblTip:SetActive(own_count < self.total_count)
  104. self.lblTip:SetActive(false)
  105. end
  106. function EnlargeView:GetEnlargeCost( open_index )
  107. local num,cost = 0,0
  108. for k,v in pairs(Config.Expandbagcosts) do
  109. if self.pos == v.bag_type and v.min_cell <= open_index and v.max_cell >= open_index then
  110. local list = ErlangParser:GetInstance():Parse(v.cost_goods_list)
  111. if list then
  112. num = list[1][3]
  113. end
  114. local goods_price = Config.Goodsprice[102601]
  115. price = goods_price and goods_price.price or 5
  116. cost = price * num
  117. break
  118. end
  119. end
  120. return num,cost
  121. end
  122. function EnlargeView:ChangeCount(count)
  123. if count < 1 then
  124. return
  125. end
  126. local info
  127. if self.pos == GoodsModel.GOODS_POS_TYPE.bag then
  128. info = self.model.slot_info_pos_2
  129. else
  130. info = self.model.slot_info_pos_3
  131. end
  132. if count > info.all_slot - info.slot_num then
  133. return
  134. end
  135. self.lock_index = count
  136. self:SetData()
  137. end