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

204 line
6.4 KiB

  1. CSGWarSupportView = CSGWarSupportView or BaseClass(BaseView)
  2. local CSGWarSupportView = CSGWarSupportView
  3. -- CSGWarSupportView.TabData = {
  4. -- {id = 1, name = "主战区",level = 1},
  5. -- {id = 2, name = "副战区",level = 1},
  6. -- }
  7. function CSGWarSupportView:__init()
  8. self.base_file = "CSGWar"
  9. self.layout_file = "CSGWarSupportView"
  10. self.layer_name = "Activity"
  11. self.destroy_imm = true
  12. self.use_background = true --全屏界面默认使用这个参数
  13. self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  14. self.change_scene_close = true
  15. self.append_to_ctl_queue = true --是否要添加进界面堆栈
  16. self.need_show_money = false --是否要显示顶部的金钱栏
  17. self.select_index = 1
  18. self.cur_select_item_index = 1
  19. self.model = CSGWarModel:getInstance()
  20. self.item_list = {}
  21. self.load_callback = function ()
  22. self:LoadSuccess()
  23. end
  24. self.open_callback = function ( )
  25. self:OpenSuccess()
  26. end
  27. self.switch_callback = function(index)
  28. self:SwitchTab(index)
  29. end
  30. self.destroy_callback = function ( )
  31. self:DestroySuccess()
  32. end
  33. end
  34. function CSGWarSupportView:Open( )
  35. --self.data = data
  36. BaseView.Open(self)
  37. end
  38. function CSGWarSupportView:LoadSuccess()
  39. local nodes = {
  40. "support_btn:obj", "container", "item_con", "banner:img:obj","con_money",
  41. "cost_text:tmp", "support_num_text:tmp", "vip_text:tmp", "support_btn/support_btn_red:obj",
  42. "btn_reward:obj",
  43. }
  44. self:GetChildren(nodes)
  45. self:AddEvent()
  46. self:CreateMoneyView()
  47. local closeWin_callback = function()
  48. self:Close()
  49. end
  50. lua_resM:setOutsideImageSprite(self, self.banner_img, GameResPath.GetCSGWarImage("csgwar_banner"),false)
  51. self.tabWindowComponent = UITabWindow.New(self.transform,{},self.switch_callback,closeWin_callback,self.background_wnd,self.container, UITabWindow.SizeSmallNoTab, false,nil,true)
  52. self.tabWindowComponent:SetBackgroundRes("CSGWar_support_bg")
  53. self.tabWindowComponent:SetTitleText("社团应援")
  54. local cfg = self.model:GetCSGWarKVCFG("support_cost")
  55. self.support_max = self.model:GetCSGWarKVCFG("support_max").value
  56. local vip = RoleManager.Instance.mainRoleInfo.vip_flag
  57. local vip_extra_num = VipModel.Instance:GetVipPrivilegeValue(601,1,vip)
  58. self.support_max = self.support_max + vip_extra_num
  59. self.vip_text_tmp.text = string.format("(%s额外获得%s次)", HtmlColorTxt("V"..vip, ColorUtil.YELLOW_DARK), vip_extra_num)
  60. local cost_data = stringtotable(cfg.value)
  61. self.cost = cost_data[1][3] or 0
  62. self:SwitchTab(self.select_index)
  63. end
  64. function CSGWarSupportView:AddEvent()
  65. local function on_update_view( )
  66. self:UpdateView()
  67. end
  68. self.on_update_view_id = self.model:BindOne("CSGWar_support_info", on_update_view)
  69. local function on_click( ... )
  70. local function ok_callback( ... )
  71. local data = self.cur_select_data
  72. if data then
  73. self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60104,data.server_id, data.guild_id)
  74. else
  75. Message.show("请选择一个社团应援哦")
  76. end
  77. end
  78. local function toggle_function( flag )
  79. self.model.support_view_toggle = flag
  80. end
  81. local function use_function( toggle_tip_data,call_fun_sum )
  82. if not self.model.support_view_toggle then
  83. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  84. else
  85. call_fun_sum()
  86. end
  87. end
  88. if self.model:GetMyFreeSupportNum() > 0 then
  89. ok_callback()
  90. else
  91. local buy_tip_data = {
  92. gold_type = 2,--货币类型
  93. cost_price = self.cost,--消耗金额
  94. ok_callback = ok_callback,--成功
  95. toggle_function = toggle_function,--多选
  96. togglePriceStr = string.format("<color=#fdffc2>%s</color> 应援一次",self.cost),--提示语
  97. use_function = use_function,--最终调用
  98. }
  99. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  100. end
  101. end
  102. AddClickEvent(self.support_btn_obj, on_click)
  103. local function on_click_reward( )
  104. self.model:Fire(CSGWarConst.OPEN_CSGWAR_REWARD_VIEW)
  105. end
  106. AddClickEvent(self.btn_reward_obj, on_click_reward)
  107. end
  108. function CSGWarSupportView:OpenSuccess()
  109. self:UpdateView()
  110. end
  111. function CSGWarSupportView:CreateMoneyView( )
  112. if not self.money_view then
  113. self.money_view = UIMoneyView.New(self.con_money)
  114. end
  115. self.money_view:SetPosition(0,0)
  116. self.money_view:SetData()
  117. end
  118. function CSGWarSupportView:UpdateView()
  119. local data = self.model:GetCSGWarSupportInfo(self.select_index)
  120. if data and TableSize(data) > 0 then
  121. if self.model:GetMyFreeSupportNum() > 0 then
  122. self.cost_text_tmp.text = "本次免费"
  123. else
  124. self.cost_text_tmp.text = self.cost
  125. end
  126. self.support_btn_red_obj:SetActive(self.model:GetMyFreeSupportNum() > 0)
  127. else
  128. self.cost_text_tmp.text = self.cost
  129. self.support_btn_red_obj:SetActive(false)
  130. end
  131. local max_num = self.support_max
  132. local cur_num = self.model:GetMySupportNum()
  133. local color = ColorUtil.GREEN_DARK
  134. if cur_num >= max_num then
  135. color = ColorUtil.RED_DARK
  136. end
  137. self.support_num_text_tmp.text = string.format("剩余可应援次数%s/%s", HtmlColorTxt(cur_num, color), max_num)
  138. local function call_back( data,index )
  139. self.cur_select_data = data
  140. self:SetSelect(index, data)
  141. end
  142. local x_offset = 234
  143. for i=1,4 do
  144. local item = self.item_list[i]
  145. if not item then
  146. item = CSGWarSupportItem.New(self.item_con)
  147. item:SetPosition((i-1)*x_offset, 6)
  148. item:SetCallBackFunc(call_back)
  149. self.item_list[i] = item
  150. end
  151. item:SetData(data[i],i, data.all_support_num)
  152. end
  153. self:SetSelect(self.cur_select_item_index)
  154. end
  155. function CSGWarSupportView:SwitchTab( index )
  156. self.select_index = index
  157. self.tabWindowComponent:SetTabBarIndex(index)
  158. local function call_back( )
  159. self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60103)
  160. end
  161. TimeManager.GetInstance():StartTime("CSGWarSupportView:SwitchTab",0.3,call_back)--不能让他一直点来请求协议吧,限制一下
  162. self:UpdateView()
  163. end
  164. function CSGWarSupportView:SetSelect( index,data )
  165. self.cur_select_item_index = index
  166. self.cur_select_data = data
  167. if not self.cur_select_data and self.item_list[index] then
  168. self.cur_select_data = self.item_list[index]:GetData()
  169. end
  170. for i,v in ipairs(self.item_list) do
  171. v:SetSelect(index == i)
  172. end
  173. end
  174. function CSGWarSupportView:DestroySuccess( )
  175. if self.tabWindowComponent then
  176. self.tabWindowComponent:DeleteMe()
  177. self.tabWindowComponent = nil
  178. end
  179. if self.on_update_view_id then
  180. self.model:UnBind(self.on_update_view_id)
  181. self.on_update_view_id = nil
  182. end
  183. for i,v in ipairs(self.item_list) do
  184. v:DeleteMe()
  185. v = nil
  186. end
  187. self.item_list = {}
  188. if self.money_view then
  189. self.money_view:DeleteMe()
  190. self.money_view = nil
  191. end
  192. end