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

91 line
2.9 KiB

  1. SellView = SellView or BaseClass(BaseView)
  2. function SellView:__init()
  3. self.base_file = "bag"
  4. self.layout_file = "SellView"
  5. self.layer_name = "Activity"
  6. self.use_background = true
  7. self.click_bg_toClose= true
  8. self.is_set_zdepth = true
  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 SellView:Remove()
  20. if self.icon_item then
  21. self.icon_item:DeleteMe()
  22. self.icon_item = nil
  23. end
  24. if self.addNumComponent then
  25. if self.change_count_id then
  26. self.addNumComponent:UnBind(self.change_count_id)
  27. self.change_count_id = nil
  28. end
  29. self.addNumComponent:DeleteMe()
  30. self.addNumComponent = nil
  31. end
  32. end
  33. function SellView:LocalSuccess()
  34. self.icon_item = BagIconItem.New(self:GetChild("iconItem"))
  35. self.icon_item:ChangeCountVisible(false)
  36. self.nameText = self:GetChild("nameText"):GetComponent("Text")
  37. self.moneyIcon = self:GetChild("moneyIcon"):GetComponent("Image")
  38. self.moneyText = self:GetChild("moneyText"):GetComponent("Text")
  39. self.sellBtn = self:GetChild("sellBtn").gameObject
  40. self.addNumComponent = AddNumberComponent.New(self:GetChild("addNumCon"))
  41. self:InitEvent()
  42. end
  43. function SellView:InitEvent()
  44. local function onBtnClickHandler(target)
  45. if target == self.sellBtn then
  46. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15021,1,self.goods_vo.goods_id,self.addNumComponent:GetCurrCount(), self.goods_vo.type_id)
  47. self:Close()
  48. end
  49. end
  50. AddClickEvent(self.sellBtn,onBtnClickHandler)
  51. local function onChangeCountHandler(count)
  52. self:ChangeCount(count)
  53. end
  54. self.change_count_id = self.addNumComponent:Bind(ComponentEvent.AddNumberComponent.CHANGE_COUNT,onChangeCountHandler)
  55. end
  56. function SellView:Open(goods_vo)
  57. self.goods_vo = goods_vo
  58. BaseView.Open(self)
  59. end
  60. function SellView:SetData()
  61. if self.goods_vo then
  62. self.icon_item:SetData(self.goods_vo)
  63. self.addNumComponent:InitData(1,self.goods_vo.goods_num,1,1,8)
  64. self:ChangeCount(1)
  65. local name = Trim(self.goods_vo.goods_name)
  66. if self.goods_vo.type == 11 and (self.goods_vo.subtype == 10 or self.goods_vo.subtype == 11) then
  67. local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(self.goods_vo.type_id, RoleManager.Instance.mainRoleInfo.career, self.goods_vo.color)
  68. name = _name
  69. end
  70. self.nameText.text = "<color="..WordManager.GetGoodsColor(self.goods_vo.color)..">" .. name.."</color>"
  71. local price_type = Config.Goodsprice[self.goods_vo.type_id] and Config.Goodsprice[self.goods_vo.type_id].sell_price_type or 3
  72. local asset, source = WordManager:GetCommonMoneyIcon(tonumber(price_type))
  73. lua_resM:setImageSprite(self, self.moneyIcon, asset, source, true)
  74. end
  75. end
  76. function SellView:ChangeCount(count)
  77. local price = GoodsModel:getInstance():GetSellPriceByTypeId(self.goods_vo.type_id)
  78. self.moneyText.text = tonumber(price) * count
  79. end