源战役客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

456 rindas
14 KiB

CSGWarSceneView = CSGWarSceneView or BaseClass(BaseView)
local CSGWarSceneView = CSGWarSceneView
--[[
CSGWarSceneView.TabData = {
[1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
}
--]]
function CSGWarSceneView:__init()
self.base_file = "CSGWar"
self.layout_file = "CSGWarSceneView"
self.layer_name = "Main"
self.destroy_imm = true
self.use_background = false --全屏界面默认使用这个参数
--self.hide_maincancas = true --全屏界面需要放开隐藏主UI
self.change_scene_close = false
self.append_to_ctl_queue = false --是否要添加进界面堆栈
self.need_show_money = false --是否要显示顶部的金钱栏
self.is_first = true
self.is_show_order = false
self.model = CSGWarModel:getInstance()
self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60110)
self.buff_item = {}
self.has_show_dialog = false
self.is_show_left_time = false
self.city_list = {}
self.order_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 CSGWarSceneView:Open( )
--self.data = data
BaseView.Open(self)
end
function CSGWarSceneView:LoadSuccess()
local nodes = {
"left_con/time_text:tmp", "left_con/city_con", "left_con", "right_con",
"middle_con/order_con:obj", "middle_con:obj", "middle_con/btnCon/order_btn:obj", "middle_con/btnCon/defend_btn:obj", "middle_con/btnCon/attack_btn:obj",
"right_con/instruction_btn:obj", "right_con/exit_btn:obj",
}
self:GetChildren(nodes)
self:AddEvent()
self.country = KfWorldModel:GetInstance():GetMyCountryId()
SetAnchoredPosition(self.transform, 0, 0)
self.transform.sizeDelta = Vector3(ScreenWidth, ScreenHeight)
SetAnchoredPositionX(self.instruction_btn, -134)
self:ChangeUiPosition()
self.model:Fire(CSGWarConst.OPEN_CSGWAR_INSTRUCTION_VIEW, true)
self.exit_btn_obj:SetActive(false)
if not self.init_exit_btn then
self.init_exit_btn = true
local function call_back( ... )
local ok = function ( )
self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60109)
end
Alert.show("即将退出跨国团战,是否确定?",Alert.Type.Two,ok)
end
local data = {call_back = call_back, pos = {x = 196,y = 275}} -- pos 为左侧侧边栏的长度
GlobalEventSystem:Fire(EventName.SHOW_EXIT_BTN_STATE, data)
end
end
function CSGWarSceneView:AddEvent()
--适配刘海屏
local function onOrientationChange()
self:ChangeUiPosition()
end
self.orientation_change_id = GlobalEventSystem:Bind(EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
local function changeFunc(is_hide)
-- self.exit_btn_obj:SetActive(is_hide)
self.instruction_btn_obj:SetActive(is_hide)
end
self.change_icon_event_id = GlobalEventSystem:Bind(EventName.CHANGE_RIGHT_TIP_ICON, changeFunc)
local function on_update_blood( )
self:UpdateCityBlood()
end
self.on_update_blood_id = self.model:Bind(CSGWarConst.UPDATE_CSGWAR_CITY_INFO, on_update_blood)
local function on_update_btn_state( )
self:UpdateOrderBtn()
end
self.on_update_btn_state_id = self.model:BindOne("CSGWar_sign_info", on_update_btn_state)
local function on_show_command( id )
if id then
local cfg = Config.Crossguildwarscene[id]
local str = string.format("团长下令:请火速赶往%s", cfg.name)
local special_tip_data = {
type = SpecialTipType.Middle,
sepeical_str = str,
need_flash = true,
show_time = 10,
}
CommonController.Instance:Fire(EventName.OPEN_SPECIALTIPVIEW, special_tip_data)
local temp_head_name = RoleManager.Instance.mainRoleInfo.name
-- local str = string.format("团长下令全员前往%s!", cfg.name)
-- local data = {
-- head_type = 1004,
-- desc = str,
-- head_name = temp_head_name or "",
-- hide_time = 15,
-- dalay_time = 1,
-- is_task_type = true,
-- pos = Vector3(230,0,0),
-- }
-- GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
end
end
self.on_show_command_id = self.model:Bind(CSGWarConst.SHOW_CSGWAR_COMMAND, on_show_command)
local function on_click( target )
if self.order_btn_obj == target then
self.is_show_order = not self.is_show_order
self:ShowOrderCon(self.is_show_order)
elseif self.exit_btn_obj == target then
local ok = function ( )
self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60109)
end
Alert.show("即将退出跨国团战,是否确定?",Alert.Type.Two,ok)
elseif self.defend_btn_obj == target then
self:GoNearestCity(false,1)
elseif self.attack_btn_obj == target then
self:GoNearestCity(true,2)
elseif self.instruction_btn_obj == target then
self.model:Fire(CSGWarConst.OPEN_CSGWAR_INSTRUCTION_VIEW)
end
end
AddClickEvent(self.order_btn_obj, on_click)
AddClickEvent(self.exit_btn_obj, on_click)
AddClickEvent(self.defend_btn_obj, on_click)
AddClickEvent(self.attack_btn_obj, on_click)
AddClickEvent(self.instruction_btn_obj, on_click)
self:BindLittleMove(self.middle_con, BaseView.LittleMoveDir.Bottom, 147.5)
self:BindLittleMove(self.left_con, BaseView.LittleMoveDir.Left, 0)
self:BindLittleMove(self.right_con, BaseView.LittleMoveDir.Right, 0)
-- 主界面聊天展开事件
self:BindMainUIExpandEvent( self.middle_con )
end
--寻路到最近的城
function CSGWarSceneView:GoNearestCity( is_attack,go_type )
local data = self.model:GetCSGWarCityInfo()
local has_city = self:HasOccupy(data)
local near_index = nil
local cfg = Config.Crossguildwarscene
local main_role = Scene.Instance:GetMainRole()
local main_role_pos = CoVector2.New(main_role.real_pos.x,main_role.real_pos.y)
local near_pos = 9999999
local dis = 0
local city_pos = CoVector2.New(0,0)
local temp_pos = {}
for i,v in ipairs(cfg) do
--如果没有占领城 就不去核心城了
if not has_city and i == 1 then
else
local need_cal = false
local city_data = data[i]
if city_data then
if self.country == city_data.group and city_data.group ~= 0 then
--如果是自己的城 且不是攻击才参与计算距离
need_cal = not is_attack
else
--如果不是自己的城 且是攻击才参与计算距离
need_cal = is_attack
end
end
if need_cal then--经过上面的判断才知道符不符合条件
temp_pos = stringtotable(v.flag)
city_pos.x = temp_pos[2]
city_pos.y = temp_pos[3]
dis = CoVector2.distance(main_role_pos,city_pos)
if dis < near_pos then
near_pos = dis
near_index = i
end
end
end
end
if near_index then
local city_pos = cfg[near_index].city_pos
if not city_pos then
city_pos = stringtotable(cfg[near_index].flag)
end
local function call_back( ... )
GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
end
local findVo = FindVo.New()
findVo.sceneId = SceneManager.Instance:GetSceneId()
findVo.type = FindVo.POINT
findVo.x = city_pos[2]/ SceneObj.LogicRealRatio.x
findVo.y = city_pos[3]/ SceneObj.LogicRealRatio.y
findVo.call_back = call_back
GlobalEventSystem:Fire(EventName.FIND,findVo)
if go_type == 1 then
Message.show("准备前往我方城池进行守卫!")
elseif go_type == 2 then
Message.show("准备前往敌方城池进行攻击!")
end
else
local str = ""
if is_attack then
str = "太厉害了!您已经占领了全部地区!"
else
str = "您现在没有占领任何地区!"
end
Message.show(str)
end
end
function CSGWarSceneView:ChangeUiPosition( )
SetAnchoredPositionX(self.right_con.transform, -ClientConfig.iphone_x_offset_right)
SetAnchoredPosition(self.left_con.transform, ClientConfig.iphone_x_offset_left, -169)
end
function CSGWarSceneView:OpenSuccess()
self:UpdateView()
end
function CSGWarSceneView:UpdateView()
self:UpdateCityBlood()
self:UpdateOrderBtn()
self:StartLeftTime()
self:UpdateOccupyBuff()
end
function CSGWarSceneView:SwitchTab( index )
end
function CSGWarSceneView:UpdateCityBlood( )
local near_index = nil
if self.is_first then
self.is_first = false
local cfg = Config.Crossguildwarscene
local main_role = Scene.Instance:GetMainRole()
local main_role_pos = CoVector2.New(main_role.real_pos.x,main_role.real_pos.y)
local near_pos = 9999999
local dis = 0
local city_pos = CoVector2.New(0,0)
local temp_pos = {}
for i,v in ipairs(cfg) do
temp_pos = stringtotable(v.flag)
city_pos.x = temp_pos[2]
city_pos.y = temp_pos[3]
dis = CoVector2.distance(main_role_pos,city_pos)
if dis < near_pos then
near_pos = dis
near_index = i
end
end
end
local select_callback = function( index )
for i,v in ipairs(self.city_list) do
v:SetSelected(i == index)
end
end
local data = self.model:GetCSGWarCityInfo()
local has_city = self:HasOccupy(data)
local y_offset = 48
for i=1,5 do
local item = self.city_list[i]
if not item then
item = CSGWarCityItem.New(self.city_con)
item:SetPosition(0, -(i-1)*y_offset)
self.city_list[i] = item
end
item:SetData(data[i], i, has_city, near_index, select_callback)
end
end
--获取本阵营是否有占领某一个副城
function CSGWarSceneView:HasOccupy( data )
local bool = false
for i=1,5 do
if data[i] then
if data[i].group ~= 0 and data[i].group == self.country then
bool = true
break
end
end
end
return bool
end
function CSGWarSceneView:StartLeftTime()
if self.exit_timer_id then
GlobalTimerQuest:CancelQuest(self.exit_timer_id)
self.exit_timer_id = nil
end
local data = self.model:GetCSGWarBaseInfo()
if TableSize(data) == 0 then return end
local left_time = math.max(0,data.etime - TimeUtil:getServerTime())
if left_time <= 0 then
else
local function onExitTimer()
left_time = data.etime - TimeUtil:getServerTimeMs() / 1000
if left_time <= 300 and not self.has_show_dialog then
self:ShowTimeDialog()
end
if left_time <= 15 then
self:ShowLeftTime(left_time)
end
if left_time > 0 then
self.time_text_tmp.text = string.format("活动剩余时间:%s",HtmlColorTxt(TimeUtil:convertMillisecondTime(left_time), ColorUtil.GREEN_DARK))
else
if self.exit_timer_id then
GlobalTimerQuest:CancelQuest(self.exit_timer_id)
self.exit_timer_id = nil
end
end
end
onExitTimer()
self.exit_timer_id = GlobalTimerQuest:AddPeriodQuest(onExitTimer, 0.03, -1)
end
end
function CSGWarSceneView:ShowLeftTime( left_time )
if self.is_show_left_time then
return
end
self.is_show_left_time = true
left_time = math.floor(left_time)
local data = {
time = left_time,
time_str = "秒后",
exit_desc = "自动退出",
}
GlobalEventSystem:Fire(EventName.OPEN_EXIT_TIME_TIP, data, true)
end
function CSGWarSceneView:ShowTimeDialog( )
if self.has_show_dialog then
return
end
local temp_head_name = RoleManager.Instance.mainRoleInfo.name
local str = "这是最后的时刻了!一定要拿下核心区!"
local data = {
head_type = 1004,
desc = str,
head_name = temp_head_name or "",
hide_time = 15,
dalay_time = 1,
is_task_type = true,
pos = Vector3(230,0,0),
}
GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
self.has_show_dialog = true
end
function CSGWarSceneView:UpdateOrderBtn( )
local my_guild_id = RoleManager.Instance.mainRoleInfo.guild_id
local is_fight_guild = self.model:IsCSGWarFightGuild(my_guild_id)
local is_leader = RoleManager.Instance.mainRoleInfo.position == GuildModel.GuildPosition.Leader or RoleManager.Instance.mainRoleInfo.position == GuildModel.GuildPosition.ViceLeader
self.order_btn_obj:SetActive(is_fight_guild and is_leader)
if is_fight_guild and is_leader then
else
self:ShowOrderCon(false)
end
end
function CSGWarSceneView:ShowOrderCon( bool )
self.order_con_obj:SetActive(bool)
if bool and TableSize(self.order_list) == 0 then
local y_offset = 36
for i=1,5 do
local item = self.order_list[i]
if not item then
item = CSGWarOrderItem.New(self.order_con)
item:SetPosition(0, -y_offset*(i-1))
item:SetData(i)
self.order_list[i] = item
end
end
end
end
function CSGWarSceneView:UpdateOccupyBuff( )
local data = SandTableModel:getInstance():GetBuffListByFaction(self.country)
local x_offset = 114
local y_offset = 120
for i,v in ipairs(data) do
local item = self.buff_item[i]
if not item then
item = CSGWarBuffItem.New(self.right_con)
item:SetPosition(-((i-1)%2)*x_offset,math.floor((i-1)/2)*y_offset)
self.buff_item[i] = item
end
item:SetData(i,v)
end
-- print("HWR:CSGWarSceneView [start:357] data:", data)
-- PrintTable(data)
-- print("HWR:CSGWarSceneView [end]")
end
function CSGWarSceneView:DestroySuccess( )
GlobalEventSystem:Fire(EventName.HIDE_EXIT_BTN_STATE)
if self.orientation_change_id then
GlobalEventSystem:UnBind(self.orientation_change_id)
self.orientation_change_id = nil
end
if self.change_icon_event_id then
GlobalEventSystem:UnBind(self.change_icon_event_id)
self.change_icon_event_id = nil
end
if self.exit_timer_id then
GlobalTimerQuest:CancelQuest(self.exit_timer_id)
self.exit_timer_id = nil
end
if self.on_update_blood_id then
self.model:UnBind(self.on_update_blood_id)
self.on_update_blood_id = nil
end
if self.on_show_command_id then
self.model:UnBind(self.on_show_command_id)
self.on_show_command_id = nil
end
for i,v in ipairs(self.city_list) do
v:DeleteMe()
v = nil
end
self.city_list = {}
for i,v in ipairs(self.order_list) do
v:DeleteMe()
v = nil
end
self.order_list = {}
if self.on_update_btn_state_id then
self.model:UnBind(self.on_update_btn_state_id)
self.on_update_btn_state_id = nil
end
for i,v in ipairs(self.buff_item) do
v:DeleteMe()
v = nil
end
self.buff_item = {}
-- 清除横幅
GlobalEventSystem:Fire(EventName.OPEN_EXIT_TIME_TIP, nil, false)
CommonController.Instance:Fire(EventName.CLOSE_SPECIALTIPVIEW)
end