CSGWarSubView = CSGWarSubView or BaseClass(BaseItem) local CSGWarSubView = CSGWarSubView function CSGWarSubView:__init() self.base_file = "CSGWar" self.layout_file = "CSGWarSubView" self.mainVo = RoleManager.Instance.mainRoleInfo self.model = CSGWarModel:GetInstance() self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60101) self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60102) self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60103,1) self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60105,0,1) self.show_item_list = {}--展示城区item self.sign_item_list = {}--报名阶段item self.cur_area_index = 1--当前选择的战区 1主2副 self.cur_sign_index = 1--当前选择的报名列表 1本社团2应援 self:Load() end function CSGWarSubView:Load_callback() self.nodes = { "show_con/power_text:txt", "tip_text:tmp", "instruction_btn:obj", "sign_con:obj", "show_con/show_item_con", "bg:obj:raw", "support_btn:obj", "record_btn:obj", "show_con:obj", "show_con/occupy_server_text:tmp", "reward_btn:obj", "show_con/receive_image:obj:img", "sign_con/sign_btn:obj:imgex", "show_con/guild_text:tmp", "sign_con/sign_item_con", "sign_con/list_scroll", "bg2:obj:raw", "sign_con/enter_btn:obj", "show_con/name_text:tmp", "show_con/occupy_bg:obj", "sign_con/list_scroll/Viewport/list_con", "show_con/occupy_text:tmp", "show_con/role_con", "show_con/reward_image:obj:img", "sign_con/rank_text:tmp", "sign_con/sign_btn/sign_btn_text:tmp", "support_btn/support_btn_red:obj", "show_con/reward_red_image:obj", "sign_con/enter_btn/enter_btn_red:obj", "sign_con/title_text:tmp", "sign_con/unsign_btn:obj","sign_con/unsign_btn/unsign_btn_text:tmp", "sign_con/lb_time:tmp", "open_tips_btn:obj", "open_tips_btn/open_tips_red:obj", } self:GetChildren(self.nodes) self:AddEvents() lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("CSGWar_sub_bg"),false) lua_resM:setOutsideRawImage(self,self.bg2_raw,GameResPath.GetViewBigBg("CSGWar_sub_bg2"),false) self.unsign_btn_text_tmp.text = "取消报名" local cfg1 = self.model:GetCSGWarKVCFG("sign_up_help_max") local cfg2 = self.model:GetCSGWarKVCFG("sign_up_max") if cfg1 then self.support_role_max = cfg1.value else self.support_role_max = 0 end if cfg2 then self.sign_role_max = cfg2.value else self.sign_role_max = 0 end self:MoveUIToBack(self.bg) self:MoveUIToBack(self.bg2) if self.need_refreshData then self:UpdateView() end end function CSGWarSubView:AddEvents( ) local function on_click( target ) if target == self.sign_btn_obj then local data = self.model:GetCSGWarBaseInfo() if data and TableSize(data) > 0 and ( data.state ~= CSGWarConst.CSGWAR_STATE.SIGN) then Message.show("现在还不是报名阶段哦~") return end if self.model:IsCSGWarSign() then -- local function ok( ... ) -- self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60106, 0) -- end -- local ask_str = "是否取消报名?" -- Alert.show(ask_str,Alert.Type.Two,ok) else -- 检查CD local last_sign_time = self.model:GetLastSignTime( ) local remain_time = TimeUtil:getServerTime( ) - last_sign_time if remain_time > CSGWarConst.SIGN_CD then -- 三十分钟 self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60106, 1) else -- 没够三十分钟 local tip_str = string.format('%s后可报名', TimeUtil:timeConvert2(CSGWarConst.SIGN_CD - remain_time)) Message.show(tip_str) end end elseif target == self.unsign_btn_obj then local function ok( ... ) self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60106, 0) end local ask_str = string.format("是否取消报名?\n(取消报名后%s内不可再次报名)", HtmlColorTxt(TimeUtil:timeConvert2(CSGWarConst.SIGN_CD), ColorUtil.GREEN_DARK) ) Alert.show(ask_str,Alert.Type.Two,ok) elseif target == self.support_btn_obj then local data = self.model:GetCSGWarBaseInfo() if data and TableSize(data) > 0 and (data.state == CSGWarConst.CSGWAR_STATE.SUPPORT or data.state == CSGWarConst.CSGWAR_STATE.SIGN) then self.model:Fire(CSGWarConst.OPEN_CSGWAR_SUPPORT_VIEW) else Message.show("现在还不是应援阶段哦~") end elseif target == self.instruction_btn_obj then self.model:Fire(CSGWarConst.OPEN_CSGWAR_INSTRUCTION_VIEW) elseif target == self.record_btn_obj then self.model:Fire(CSGWarConst.OPEN_CSGWAR_RECORD_VIEW) elseif target == self.reward_btn_obj then self.model:Fire(CSGWarConst.OPEN_CSGWAR_REWARD_VIEW) elseif target == self.enter_btn_obj then self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60108) elseif target == self.reward_image_obj then self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60107, self.cur_area_index, 1) elseif target == self.open_tips_btn_obj then GuildModel.getInstance():SetWarActiveRedDot(601, 1, false) GuildModel.getInstance():Fire(GuildModel.OPEN_ACTIVE_OPEN_TIPS_VIEW, true) end end AddClickEvent(self.sign_btn_obj, on_click) AddClickEvent(self.unsign_btn_obj, on_click) AddClickEvent(self.support_btn_obj, on_click) AddClickEvent(self.instruction_btn_obj, on_click) AddClickEvent(self.record_btn_obj, on_click) AddClickEvent(self.reward_btn_obj, on_click) AddClickEvent(self.enter_btn_obj, on_click) AddClickEvent(self.reward_image_obj, on_click) AddClickEvent(self.open_tips_btn_obj, on_click) local function on_update_active_state( ) self:UpdateActiveState() if self.view_type == "show" then self:UpdateShowItem() self:UpdateCentralInfo() end end self.on_update_active_state_id = self.model:BindOne("CSGWar_base_info", on_update_active_state) local function on_update_sign_item( ) self:UpdateActiveState() self:UpdateSignItem() end self.on_update_sign_item_id = self.model:BindOne("CSGWar_sign_info", on_update_sign_item) local function on_update_show_item( ) self:UpdateShowItem() self:UpdateCentralInfo() end self.on_update_show_item_id = self.model:BindOne("CSGWar_occupy_info", on_update_show_item) local function on_update_player_list( ) self:UpdateSignPlayerList() end self.on_update_player_list_id = self.model:Bind(CSGWarConst.UPDATE_CSGWAR_SIGN_LIST, on_update_player_list) local function on_update_red( ) self:UpdateRedDot() end self.on_update_red_id = self.model:Bind(CSGWarConst.ANS_CSGWAR_RED, on_update_red) local function onShowACtiveOpenTipsRed() self.open_tips_red_obj:SetActive(GuildModel.getInstance():GetWarActiveRedDot(601, 1)) end self:BindEvent(GuildModel.getInstance(), GuildModel.SHOW_ACTIVE_OPEN_TIPS_RED, onShowACtiveOpenTipsRed) self.open_tips_red_obj:SetActive(GuildModel.getInstance():GetWarActiveRedDot(601, 1)) end function CSGWarSubView:UpdateView( ) self:UpdateActiveState() self:UpdateSignPlayerList() self:SwitchAreaTab() end function CSGWarSubView:UpdateActiveState( ) if self.model:IsCSGWarOpen() then--活动开始的时候只能显示报名信息 self.view_type = "sign" else self.view_type = "show" end self.bg_obj:SetActive(self.view_type == "show") self.bg2_obj:SetActive(self.view_type == "sign") self.sign_con_obj:SetActive(self.view_type == "sign") self.show_con_obj:SetActive(self.view_type == "show") local str = ChuanWenManager:getInstance():FormatColorTag2(CSGWarConst.TIP_DESC, true) self.tip_text_tmp.text = str -- if self.view_type == "sign" then -- SetAnchoredPosition(self.tip_text, -262, -190) -- else -- SetAnchoredPosition(self.tip_text, -262, -270) -- end local last_sign_time = self.model:GetLastSignTime( ) local end_show_time = last_sign_time + CSGWarConst.SIGN_CD local sign_is_in_cd = end_show_time and end_show_time - TimeUtil:getServerTime() > 0 self.unsign_btn_obj:SetActive(false) local data = self.model:GetCSGWarBaseInfo() if data and TableSize(data) > 0 then self.enter_btn_obj:SetActive(data.state == CSGWarConst.CSGWAR_STATE.START) self.sign_btn_obj:SetActive(data.state == CSGWarConst.CSGWAR_STATE.SIGN or data.state == CSGWarConst.CSGWAR_STATE.SUPPORT) self.sign_btn_imgex.gray = data.state ~= CSGWarConst.CSGWAR_STATE.SIGN or sign_is_in_cd if data.state ~= CSGWarConst.CSGWAR_STATE.SIGN or sign_is_in_cd then SetTMPSharedMaterial(self.sign_btn_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn) else SetTMPSharedMaterial(self.sign_btn_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn) end if data.state == CSGWarConst.CSGWAR_STATE.SIGN then local is_sign = self.model:IsCSGWarSign() self.sign_btn_obj:SetActive(not is_sign) self.unsign_btn_obj:SetActive(is_sign) self.sign_btn_text_tmp.text = "我要报名" else self.sign_btn_text_tmp.text = "报名截止" end self:SetSignCDTimerShow() end end -- 报名冷却倒计时 function CSGWarSubView:SetSignCDTimerShow( ) if self.model:IsCSGWarSign() then -- 已经报了 self.lb_time_tmp.text = "" return end local last_sign_time = self.model:GetLastSignTime( ) local remain_time = TimeUtil:getServerTime( ) - last_sign_time local end_show_time = last_sign_time + CSGWarConst.SIGN_CD if end_show_time and end_show_time - TimeUtil:getServerTime() > 0 then local function onTimer() local sec = end_show_time - TimeUtil:getServerTime() if sec > 0 then self.lb_time_tmp.text = string.format("%s后可再次报名" ,TimeUtil:timeConvert3(sec)) else self:UpdateActiveState( ) self.lb_time_tmp.text = "" GlobalTimerQuest:CancelQuest(self.timer_id) self.timer_id = nil end end if not self.timer_id then self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1) end else self.lb_time_tmp.text = "" end end --更新中心城区信息 function CSGWarSubView:UpdateCentralInfo( ) local data = self.model:GetCSGWarOccupyInfo() or {} if data[1] then local guild_str = GetCSLongName(data[1].guild_name, data[1].server_num, false, ColorUtil.GREEN_DARK) local boss_str = string.format("%s %s", HtmlColorTxt("团长:", ColorUtil.YELLOW_DARK), data[1].chief_name) local str = string.format("%s\n%s", guild_str, boss_str) self.occupy_text_tmp.text = str -- self.occupy_server_text_tmp.text = GetCSLongName("服", data[1].server_num, true) self.occupy_server_text_tmp.text = KfWorldModel:GetInstance():GetContrayNameById(data[1].fact_id) local server_id = RoleManager.Instance.mainRoleInfo.server_id self.reward_image_obj:SetActive(server_id == data[1].server_id) self.receive_image_obj:SetActive(data[1].is_received_reward == 1) if data[1].is_received_reward == 1 then lua_resM:setImageSprite(self, self.reward_image_img, "CSGWar_asset", "CSGWar_item3") else lua_resM:setImageSprite(self, self.reward_image_img, "CSGWar_asset", "CSGWar_item2") end self.guild_text_tmp.text = guild_str self.name_text_tmp.text = boss_str self.power_text_txt.text = "f"..data[1].chief_power self:SetRoleModel(data[1].chief_id) else local guild_str = "暂无社团占领" local boss_str = "团长: 暂无" local str = string.format("%s\n%s", guild_str, boss_str) self.occupy_text_tmp.text = str self.occupy_server_text_tmp.text = "暂无社团占领" self.receive_image_obj:SetActive(false) self.reward_image_obj:SetActive(false) self.guild_text_tmp.text = guild_str self.name_text_tmp.text = boss_str self.power_text_txt.text = "" self:SetRoleModel() end end function CSGWarSubView:UpdateShowItem( ) local data = self.model:GetCSGWarOccupyInfo() or {} -- print("HWR:CSGWarSubView [start:177] data:", data) -- PrintTable(data) -- print("HWR:CSGWarSubView [end]") local x_offset = 352 local y_offset = 208 for i=1,4 do local item = self.show_item_list[i] if not item then item = CSGWarSubShowItem.New(self.show_item_con) item:SetPosition((i - 1) % 2 * x_offset-6, -math.floor((i - 1) / 2) * y_offset+8) self.show_item_list[i] = item end item:SetData(data[i+1], i, self.cur_area_index) end end function CSGWarSubView:UpdateSignItem( ) local data = self.model:GetCSGWarSignInfo() or {} -- print("HWR:CSGWarSubView [start:192] data:", data) -- PrintTable(data) -- print("HWR:CSGWarSubView [end]") local x_offset = 352 local y_offset = 208 for i=1,4 do local item = self.sign_item_list[i] if not item then item = CSGWarSubSignItem.New(self.sign_item_con) item:SetPosition((i - 1) % 2 * x_offset-6, -math.floor((i - 1) / 2) * y_offset+8) self.sign_item_list[i] = item end item:SetData(data[i], i) end end --更新报名玩家列表 function CSGWarSubView:UpdateSignPlayerList( ) local data = {} local is_fight_guild = self.model:IsCSGWarFightGuild(self.mainVo.guild_id) if is_fight_guild then data = self.model:GetCSGWarGuildSignList() self.rank_text_tmp.text = string.format("战力排名前 %s 的玩家可进入\n战场参加比赛", HtmlColorTxt(self.sign_role_max, ColorUtil.YELLOW_DARK)) self.title_text_tmp.text = "社团参战成员榜" else data = self.model:GetCSGWarSupportSignList() self.rank_text_tmp.text = string.format("战力排名前 %s 的玩家可进入\n战场参加比赛", HtmlColorTxt(self.support_role_max, ColorUtil.YELLOW_DARK)) self.title_text_tmp.text = "本国协助参战榜" end if not self.sign_list_com then self.sign_list_com = self:AddUIComponent(UI.ItemListCreator) end if self.need_sign_list_reset then self.sign_list_com:Reset() self.need_sign_list_reset = false end local info = { data_list = data, item_con = self.list_con, scroll_view = self.list_scroll, item_class = CSGWarSubPlayerItem, start_y = 0, start_x = 4, create_frequency = 0.02, create_num_per_time = 3, item_height = 42, space_y = 3, on_update_item = function(item, i, v) item:SetData(i, v) end, } self.sign_list_com:UpdateItems(info) end function CSGWarSubView:SetData( data ) self.data = data if self.is_loaded then self.need_refreshData = false self:UpdateView() self:SetRoleModel(self.role_id) else self.need_refreshData = true end end function CSGWarSubView:SetRoleModel( role_id ) role_id = role_id or 0 self.role_id = role_id if role_id ~= 0 then SetLocalScale(self.role_con, 1, 1, 1) else SetLocalScale(self.role_con, 0.001, 0.001, 0.001) end local res_data = { father_node = self, transform = self.role_con, fashion_type = FuncOpenModel.TypeId.Clothes, size = Vector2(720,720), scale = 180, position = Vector3(35,-10,0), ui_model_type = UIModelCommon.ModelType.BackModel, } FuncOpenModel:getInstance():SetRoleModelByID(role_id, res_data) end --切换主副战区按钮 function CSGWarSubView:SwitchAreaTab( ) -- self.cur_area_index = index -- if index == 1 then -- lua_resM:setImageSprite(self, self.tab_area_btn1_img, "CSGWar_asset", "CSGWar_item8") -- lua_resM:setImageSprite(self, self.tab_area_btn2_img, "CSGWar_asset", "CSGWar_item9") -- self.tab_area_btn_text1_tmp.color = ColorUtil:ConvertHexToRGBColor("6e81bf") -- self.tab_area_btn_text2_tmp.color = ColorUtil:ConvertHexToRGBColor("edeaea") -- else -- lua_resM:setImageSprite(self, self.tab_area_btn1_img, "CSGWar_asset", "CSGWar_item9") -- lua_resM:setImageSprite(self, self.tab_area_btn2_img, "CSGWar_asset", "CSGWar_item8") -- self.tab_area_btn_text1_tmp.color = ColorUtil:ConvertHexToRGBColor("edeaea") -- self.tab_area_btn_text2_tmp.color = ColorUtil:ConvertHexToRGBColor("6e81bf") -- end local is_fight_guild = self.model:IsCSGWarFightGuild(self.mainVo.guild_id) if self.view_type == "sign" then self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60105, is_fight_guild and 0 or 1)--0是本社团 1是外援 self:UpdateSignItem() self:UpdateSignPlayerList() else self:UpdateShowItem() end self:UpdateCentralInfo() self:UpdateRedDot() end function CSGWarSubView:SwitchSignTab( index ) do return end if self.cur_sign_index ~= index then self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60105,index-1,self.cur_area_index) end self.cur_sign_index = index if index == 1 then lua_resM:setImageSprite(self, self.tab_sign_btn1_img, "CSGWar_asset", "CSGWar_item10") lua_resM:setImageSprite(self, self.tab_sign_btn2_img, "CSGWar_asset", "CSGWar_item11") self.tab_sign_btn_text1_tmp.color = ColorUtil:ConvertHexToRGBColor("6e81bf") self.tab_sign_btn_text2_tmp.color = ColorUtil:ConvertHexToRGBColor("edeaea") else lua_resM:setImageSprite(self, self.tab_sign_btn1_img, "CSGWar_asset", "CSGWar_item11") lua_resM:setImageSprite(self, self.tab_sign_btn2_img, "CSGWar_asset", "CSGWar_item10") self.tab_sign_btn_text1_tmp.color = ColorUtil:ConvertHexToRGBColor("edeaea") self.tab_sign_btn_text2_tmp.color = ColorUtil:ConvertHexToRGBColor("6e81bf") end if self.cur_sign_index == 1 then self.rank_text_tmp.text = string.format("战力排名前%s的社团团员可进入战场参加比赛", HtmlColorTxt(20,"ffea9c")) else if self.cur_area_index == 1 then self.rank_text_tmp.text = string.format("战力排名前%s的外援可进入战场参加比赛", HtmlColorTxt(10,"ffea9c")) else self.rank_text_tmp.text = string.format("战力排名%s的外援可进入战场参加比赛", HtmlColorTxt("10~20","ffea9c")) end end if self.view_type == "sign" then self:UpdateSignItem() self:UpdateSignPlayerList() else self:UpdateShowItem() end end function CSGWarSubView:UpdateRedDot( ) local red_data = self.model:GetCSGWarRedData() -- print("HWR:CSGWarSubView [start:342] red_data:", red_data) -- PrintTable(red_data) -- print("HWR:CSGWarSubView [end]") if red_data.support_red then self.support_btn_red_obj:SetActive(true) else self.support_btn_red_obj:SetActive(false) end if red_data.fight_red then self.enter_btn_red_obj:SetActive(true) else self.enter_btn_red_obj:SetActive(false) end if red_data.occupy_red and red_data.occupy_red_data[1] then self.reward_red_image_obj:SetActive(true) else self.reward_red_image_obj:SetActive(false) end end function CSGWarSubView:__delete( ) if self.on_update_active_state_id then self.model:UnBind(self.on_update_active_state_id) self.on_update_active_state_id = nil end if self.on_update_sign_item_id then self.model:UnBind(self.on_update_sign_item_id) self.on_update_sign_item_id = nil end if self.on_update_show_item_id then self.model:UnBind(self.on_update_show_item_id) self.on_update_show_item_id = nil end if self.on_update_player_list_id then self.model:UnBind(self.on_update_player_list_id) self.on_update_player_list_id = nil end for i,v in ipairs(self.show_item_list) do v:DeleteMe() v = nil end self.show_item_list = {} for i,v in ipairs(self.sign_item_list) do v:DeleteMe() v = nil end self.sign_item_list = {} if not self.model.has_open_csgwar_view then self.model.has_open_csgwar_view = true self.model:Fire(CSGWarConst.UPDATE_CSGWAR_RED) end if self.on_update_red_id then self.model:UnBind(self.on_update_red_id) self.on_update_red_id = nil end if self.timer_id then GlobalTimerQuest:CancelQuest(self.timer_id) self.timer_id = nil end end