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

152 lines
5.5 KiB

  1. AddTimeView = AddTimeView or BaseClass(BaseView)
  2. local AddTimeView = AddTimeView
  3. AddTimeView.Type = {
  4. DESIGNATION = 1,
  5. FASHION = 2,
  6. }
  7. --通用续时界面
  8. function AddTimeView:__init()
  9. self.base_file = "uiComponent"
  10. self.layout_file = "AddTimeView"
  11. self.layer_name = "Top"
  12. self.destroy_imm = true
  13. self.use_background = true --全屏界面默认使用这个参数
  14. self.change_scene_close = true
  15. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  16. self.need_show_money = false --是否要显示顶部的金钱栏
  17. self.load_callback = function ()
  18. self:LoadSuccess()
  19. self:AddEvent()
  20. end
  21. self.open_callback = function ( )
  22. self:OpenSuccess()
  23. end
  24. self.switch_callback = function(index)
  25. self:SwitchTab(index)
  26. end
  27. self.destroy_callback = function ( )
  28. self:DestroySuccess()
  29. end
  30. end
  31. function AddTimeView:Open( data)
  32. self.data = data
  33. BaseView.Open(self)
  34. end
  35. function AddTimeView:LoadSuccess()
  36. local nodes = {
  37. "num_text:txt","name_text:txt","add_num_con","bg:raw","close_btn:obj",
  38. "rest_time_text:txt","btn:obj","add_time_text:txt","title_text:txt",
  39. "item_con","goods_name_text:txt",
  40. }
  41. self:GetChildren(nodes)
  42. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("add_time_bg"),false)
  43. self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
  44. self.awardItem:SetItemSize(59, 59)
  45. self.addNumComponent = AddNumberComponent.New(self.add_num_con)
  46. self.addNumComponent:SetComponentWidth(380)
  47. self.addNumComponent:SetVisibleCalcBtn(false)
  48. end
  49. function AddTimeView:AddEvent()
  50. local function on_click( target )
  51. if target == self.btn_obj then
  52. if self.data.type == AddTimeView.Type.DESIGNATION then
  53. if self.count > 0 then
  54. DesignationModel:GetInstance():Fire(DesignationModel.REQUEST_DESIGNATION, 41106, self.data.goods_id, self.data.id, self.count)
  55. else
  56. Message.show("您没有该物品哦~")
  57. end
  58. elseif self.data.type == AddTimeView.Type.FASHION then
  59. if self.count > 0 then
  60. FashionModel:GetInstance():Fire(FashionEvent.REQUEST_FASHION_PROTOCOL, 41304, self.data.goods_id, self.data.id, self.count)
  61. else
  62. Message.show("您没有该物品哦~")
  63. end
  64. end
  65. self:Close()
  66. elseif target == self.close_btn_obj then
  67. self:Close()
  68. end
  69. end
  70. AddClickEvent(self.btn_obj, on_click)
  71. AddClickEvent(self.close_btn_obj, on_click)
  72. local function onChangeCountHandler(count)
  73. self:SetCountNum(count)
  74. end
  75. self.change_count_id = self.addNumComponent:Bind(ComponentEvent.AddNumberComponent.CHANGE_COUNT, onChangeCountHandler)
  76. end
  77. function AddTimeView:OpenSuccess()
  78. self:UpdateView()
  79. end
  80. function AddTimeView:UpdateView()
  81. local rest_time = 0
  82. if self.data.type == AddTimeView.Type.DESIGNATION then
  83. rest_time = DesignationModel:GetInstance():GetDesignationRestTimeById(self.data.id)
  84. rest_time = rest_time > 0 and rest_time or 0
  85. self.rest_time_text_txt.text = string.format("剩余时间:%s", TimeUtil:timeConvert10(rest_time, true))
  86. self.title_text_txt.text = "称号续费"
  87. self.goods_num = GoodsModel:getInstance():GetTypeGoodsNum(self.data.goods_id)
  88. local goods_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, true)
  89. self.num_text_txt.text = HtmlColorTxt(self.goods_num, ColorUtil.GREEN_DARK)
  90. self.goods_name_text_txt.text = goods_name
  91. self.name_text_txt.text = DesignationModel:GetInstance():GetDesignationNameById(self.data.id)
  92. self.awardItem:SetData(self.data.goods_id, 1, nil, nil, nil, nil, nil, self.mask_id)
  93. self.addNumComponent:InitData(1, self.goods_num, 1, 1, 12)
  94. self:SetCountNum(self.goods_num > 0 and 1 or 0)
  95. elseif self.data.type == AddTimeView.Type.FASHION then
  96. rest_time = FashionModel:GetInstance():GetFashionRestTimeById(self.data.id)
  97. rest_time = rest_time > 0 and rest_time or 0
  98. self.rest_time_text_txt.text = string.format("剩余时间:%s", TimeUtil:timeConvert10(rest_time, true))
  99. self.title_text_txt.text = "时装续费"
  100. self.goods_num = GoodsModel:getInstance():GetTypeGoodsNum(self.data.goods_id)
  101. local goods_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, true)
  102. local fashion_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, false)
  103. self.num_text_txt.text = HtmlColorTxt(self.goods_num, ColorUtil.GREEN_DARK)
  104. self.goods_name_text_txt.text = goods_name
  105. self.name_text_txt.text = fashion_name
  106. self.awardItem:SetData(self.data.goods_id, 1, nil, nil, nil, nil, nil, self.mask_id)
  107. self.addNumComponent:InitData(1, self.goods_num, 1, 1, 12)
  108. self:SetCountNum(self.goods_num > 0 and 1 or 0)
  109. end
  110. end
  111. function AddTimeView:SetCountNum( count )
  112. self.count = count
  113. if self.data.type == AddTimeView.Type.DESIGNATION then
  114. local expire_time = 0
  115. local cfg = Config.Dsgt[self.data.id]
  116. if cfg then
  117. expire_time = cfg.expire_time
  118. end
  119. self.add_time_text_txt.text = TimeUtil:timeConvert10(expire_time * self.count, true)
  120. elseif self.data.type == AddTimeView.Type.FASHION then
  121. local career = RoleManager.Instance.mainRoleInfo.career
  122. local cfg = Config.Fashionmodel[self.data.id.."@"..career]
  123. local expire_time = 0
  124. if cfg then
  125. expire_time = cfg.expire_time
  126. end
  127. self.add_time_text_txt.text = TimeUtil:timeConvert10(expire_time * self.count, true)
  128. end
  129. end
  130. function AddTimeView:DestroySuccess( )
  131. if self.awardItem then
  132. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
  133. self.awardItem = nil
  134. end
  135. if self.addNumComponent then
  136. if self.change_count_id then
  137. self.addNumComponent:UnBind(self.change_count_id)
  138. self.change_count_id = nil
  139. end
  140. self.addNumComponent:DeleteMe()
  141. self.addNumComponent = nil
  142. end
  143. end