CSGWarSupportView = CSGWarSupportView or BaseClass(BaseView) local CSGWarSupportView = CSGWarSupportView -- CSGWarSupportView.TabData = { -- {id = 1, name = "主战区",level = 1}, -- {id = 2, name = "副战区",level = 1}, -- } function CSGWarSupportView:__init() self.base_file = "CSGWar" self.layout_file = "CSGWarSupportView" self.layer_name = "Activity" self.destroy_imm = true self.use_background = true --全屏界面默认使用这个参数 self.hide_maincancas = true --全屏界面需要放开隐藏主UI self.change_scene_close = true self.append_to_ctl_queue = true --是否要添加进界面堆栈 self.need_show_money = false --是否要显示顶部的金钱栏 self.select_index = 1 self.cur_select_item_index = 1 self.model = CSGWarModel:getInstance() self.item_list = {} self.load_callback = function () self:LoadSuccess() end self.open_callback = function ( ) self:OpenSuccess() end self.switch_callback = function(index) self:SwitchTab(index) end self.destroy_callback = function ( ) self:DestroySuccess() end end function CSGWarSupportView:Open( ) --self.data = data BaseView.Open(self) end function CSGWarSupportView:LoadSuccess() local nodes = { "support_btn:obj", "container", "item_con", "banner:img:obj","con_money", "cost_text:tmp", "support_num_text:tmp", "vip_text:tmp", "support_btn/support_btn_red:obj", "btn_reward:obj", } self:GetChildren(nodes) self:AddEvent() self:CreateMoneyView() local closeWin_callback = function() self:Close() end lua_resM:setOutsideImageSprite(self, self.banner_img, GameResPath.GetCSGWarImage("csgwar_banner"),false) self.tabWindowComponent = UITabWindow.New(self.transform,{},self.switch_callback,closeWin_callback,self.background_wnd,self.container, UITabWindow.SizeSmallNoTab, false,nil,true) self.tabWindowComponent:SetBackgroundRes("CSGWar_support_bg") self.tabWindowComponent:SetTitleText("社团应援") local cfg = self.model:GetCSGWarKVCFG("support_cost") self.support_max = self.model:GetCSGWarKVCFG("support_max").value local vip = RoleManager.Instance.mainRoleInfo.vip_flag local vip_extra_num = VipModel.Instance:GetVipPrivilegeValue(601,1,vip) self.support_max = self.support_max + vip_extra_num self.vip_text_tmp.text = string.format("(%s额外获得%s次)", HtmlColorTxt("V"..vip, ColorUtil.YELLOW_DARK), vip_extra_num) local cost_data = stringtotable(cfg.value) self.cost = cost_data[1][3] or 0 self:SwitchTab(self.select_index) end function CSGWarSupportView:AddEvent() local function on_update_view( ) self:UpdateView() end self.on_update_view_id = self.model:BindOne("CSGWar_support_info", on_update_view) local function on_click( ... ) local function ok_callback( ... ) local data = self.cur_select_data if data then self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60104,data.server_id, data.guild_id) else Message.show("请选择一个社团应援哦") end end local function toggle_function( flag ) self.model.support_view_toggle = flag end local function use_function( toggle_tip_data,call_fun_sum ) if not self.model.support_view_toggle then GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) else call_fun_sum() end end if self.model:GetMyFreeSupportNum() > 0 then ok_callback() else local buy_tip_data = { gold_type = 2,--货币类型 cost_price = self.cost,--消耗金额 ok_callback = ok_callback,--成功 toggle_function = toggle_function,--多选 togglePriceStr = string.format("%s 应援一次",self.cost),--提示语 use_function = use_function,--最终调用 } CustomActivityModel:getInstance():BuyTips(buy_tip_data) end end AddClickEvent(self.support_btn_obj, on_click) local function on_click_reward( ) self.model:Fire(CSGWarConst.OPEN_CSGWAR_REWARD_VIEW) end AddClickEvent(self.btn_reward_obj, on_click_reward) end function CSGWarSupportView:OpenSuccess() self:UpdateView() end function CSGWarSupportView:CreateMoneyView( ) if not self.money_view then self.money_view = UIMoneyView.New(self.con_money) end self.money_view:SetPosition(0,0) self.money_view:SetData() end function CSGWarSupportView:UpdateView() local data = self.model:GetCSGWarSupportInfo(self.select_index) if data and TableSize(data) > 0 then if self.model:GetMyFreeSupportNum() > 0 then self.cost_text_tmp.text = "本次免费" else self.cost_text_tmp.text = self.cost end self.support_btn_red_obj:SetActive(self.model:GetMyFreeSupportNum() > 0) else self.cost_text_tmp.text = self.cost self.support_btn_red_obj:SetActive(false) end local max_num = self.support_max local cur_num = self.model:GetMySupportNum() local color = ColorUtil.GREEN_DARK if cur_num >= max_num then color = ColorUtil.RED_DARK end self.support_num_text_tmp.text = string.format("剩余可应援次数%s/%s", HtmlColorTxt(cur_num, color), max_num) local function call_back( data,index ) self.cur_select_data = data self:SetSelect(index, data) end local x_offset = 234 for i=1,4 do local item = self.item_list[i] if not item then item = CSGWarSupportItem.New(self.item_con) item:SetPosition((i-1)*x_offset, 6) item:SetCallBackFunc(call_back) self.item_list[i] = item end item:SetData(data[i],i, data.all_support_num) end self:SetSelect(self.cur_select_item_index) end function CSGWarSupportView:SwitchTab( index ) self.select_index = index self.tabWindowComponent:SetTabBarIndex(index) local function call_back( ) self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60103) end TimeManager.GetInstance():StartTime("CSGWarSupportView:SwitchTab",0.3,call_back)--不能让他一直点来请求协议吧,限制一下 self:UpdateView() end function CSGWarSupportView:SetSelect( index,data ) self.cur_select_item_index = index self.cur_select_data = data if not self.cur_select_data and self.item_list[index] then self.cur_select_data = self.item_list[index]:GetData() end for i,v in ipairs(self.item_list) do v:SetSelect(index == i) end end function CSGWarSupportView:DestroySuccess( ) if self.tabWindowComponent then self.tabWindowComponent:DeleteMe() self.tabWindowComponent = nil end if self.on_update_view_id then self.model:UnBind(self.on_update_view_id) self.on_update_view_id = nil end for i,v in ipairs(self.item_list) do v:DeleteMe() v = nil end self.item_list = {} if self.money_view then self.money_view:DeleteMe() self.money_view = nil end end