--[[ @description:欢迎界面 ]] require("game.welecome.WelecomeModel") require("game.welecome.WelecomeView") WelecomeController = WelecomeController or BaseClass(BaseController) function WelecomeController:__init() WelecomeController.Instance = self self.model = WelecomeModel:getInstance() self:RegisterAllProtocals() self:AddAllEvents() self.model.horse_fly_movie_is_playEnd = false --是否已经播放完了新手坐骑飞行展示 end function WelecomeController:__delete() end function WelecomeController:RegisterAllProtocals() end function WelecomeController:StartUpdate() if self.horse_movie_config == nil then self.horse_movie_config = {} for i, vo in ipairs(Config.Horse_fly_info.list) do self.horse_movie_config[i] = DeepCopy(vo) end end Runner.Instance:AddRunObj(self) end function WelecomeController:StopUpdate() Runner.Instance:RemoveRunObj(self) end function WelecomeController:Update(now_time, elapsed_time) if self.model.horse_fly_movie_is_playEnd or self.horse_movie_config == nil or not Scene.Instance.main_role then return end local is_finish = true for i, vo in ipairs(self.horse_movie_config) do -- if not vo.has_trigger and (vo.time_out == nil or now_time <= vo.time_out) then if not vo.has_trigger then -- print("WelecomeController =", i) is_finish = false if vo.state_name then if vo.state_name == "creatHorse" then if self.main_role_horse_clone_role == nil then local m_role = RoleManager.Instance.mainRoleInfo local clone_id = SceneManager.Instance:CreateCloneRole(m_role.role_id, vo.x, vo.y, vo.horse_id, vo.birthAngle, m_role.name, vo.head_wear_id) self.main_role_horse_clone_role = Scene.Instance:GetRole(clone_id) self.main_role_horse_clone_role:SetModelHideFlag(SceneObj.ModelHideFlag.Story, true) self.main_role_horse_clone_role:SetModelHideFlag(SceneObj.ModelHideFlag.OnlyShowHorse, true) -- self.main_role_horse_clone_role:HideAllWeapon(Character.WeaponHideFlag.Story) self.main_role_horse_clone_role:SetShadowVisible(false) vo.has_trigger = true self.main_role_horse_clone_role.LoadHorseResCompleteUserDefined = function () self.main_role_horse_clone_role:HideAllWeapon() self.main_role_horse_clone_role:DoStand() self.main_role_horse_clone_role:DoFly() end self.main_role_horse_clone_role.SetRealPosUserDefined = function (posx, posy) if self.is_jump_up and Scene.Instance.main_role then Scene.Instance.main_role:SetRealPos(posx, posy + (self.horse_height or 0) ) end end self.main_role_horse_clone_role.SetBodyXYUserDefined = function (posx, posy) if self.is_jump_up and Scene.Instance.main_role then --Scene.Instance.main_role:SetBodyXY(posx, posy , true) end end end elseif vo.state_name == "catchMainRole" then if self.MainRoleJumpUpHorseCallBack == nil then self.MainRoleJumpUpHorseCallBack = function (use_fly_height_time, move_time, move_speed) self.main_role_horse_clone_role:SetModelHideFlag(SceneObj.ModelHideFlag.Story, false) vo.use_fly_height_time = use_fly_height_time - 0.1 vo.move_time = move_time vo.move_speed = move_speed + 50 end end elseif vo.state_name == "jumpDownHorse" then if not vo.jump_time then vo.jump_time = now_time + vo.start_jump_time or 0 elseif now_time - vo.jump_time > 0 then GlobalEventSystem:Fire(EventName.JUMP_DOWN_HORSE, vo.x, vo.y) vo.has_trigger = true if self.main_role_move_event_id == nil then local function onMainRoleMoveHandler(x, y) if self.main_role_horse_clone_role and self.model.horse_fly_movie_is_playEnd then local x2, y2 = self.main_role_horse_clone_role:GetRealPos() if GameMath.GetDistance(x, y, x2, y2, false) > 1000 * 1000 then self.main_role_horse_clone_role:SetModelHideFlag(SceneObj.ModelHideFlag.OnlyShowHorse, false) SceneManager.Instance:DeleteRoleVo(self.main_role_horse_clone_role.id) self.main_role_horse_clone_role.LoadHorseResCompleteUserDefined = nil self.main_role_horse_clone_role.SetRealPosUserDefined = nil self.main_role_horse_clone_role.SetBodyXYUserDefined = nil self.main_role_horse_clone_role = nil if self.main_role_move_event_id then GlobalEventSystem:UnBind(self.main_role_move_event_id) self.main_role_move_event_id = nil end end end end self.main_role_move_event_id = GlobalEventSystem:Bind(ObjectEventType.MAINROLE_MOVE_EVENT, onMainRoleMoveHandler) end end end end if vo.fly_end_pos then local function call_back() vo.has_trigger = true end local x2, y2 = self.main_role_horse_clone_role:GetRealPos() if GameMath.GetDistance(vo.fly_end_pos.x, vo.fly_end_pos.y, x2, y2, false) > 100 * 100 then self.main_role_horse_clone_role:UpdateFlyWithPos(vo.fly_end_pos, vo.move_speed, elapsed_time, call_back) else call_back() end end if not vo.play_end_time then if vo.action_name then if self.main_role_horse_clone_role.horse_animator then self.main_role_horse_clone_role.horse_animator:CrossFade(vo.action_name, 0, 0, 0) self.main_role_horse_clone_role.horse_animator:Update(0) local action_time = 0 local cur_state = self.main_role_horse_clone_role.horse_animator:GetCurrentAnimatorStateInfo(0) if cur_state then if vo.use_fly_height_time then vo.use_fly_height_time = vo.use_fly_height_time + now_time end action_time = cur_state.length end vo.play_end_time = now_time + action_time end elseif vo.move_time then vo.play_end_time = now_time + vo.move_time end elseif now_time - vo.play_end_time < 0 then if vo.move_time then local t = (vo.move_time - vo.play_end_time + now_time) / vo.move_time if t <= 1 then local move_speed = vo.move_speed + (vo.add_speed or 0) * t * vo.move_time local add_speed = (vo.move_speed + (vo.add_speed or 0) * vo.move_time) if add_speed ~= 0 then local angle = vo.dir1 + (vo.dir2 - vo.dir1) * t * move_speed / add_speed self.main_role_horse_clone_role:SetMoveSpeed(move_speed or 500) self.main_role_horse_clone_role:DoFly() local dir = GameMath.AngleToDirection(angle) self.main_role_horse_clone_role:UpdateFlyWithDir(dir, elapsed_time) if vo.height_off then local start_height = vo.start_height or 0 local temp = vo.height_off-start_height self.main_role_horse_clone_role:SetBodyXY(0, start_height + temp * t * move_speed / add_speed) end end end end elseif now_time - vo.play_end_time >= 0 then vo.has_trigger = true end if vo.use_fly_height_time and now_time - vo.use_fly_height_time >= 0 then vo.use_fly_height_time = nil self.main_role_horse_clone_role:ResetResSize(true) self.horse_height = self.main_role_horse_clone_role.horse_res_size.z self.main_role_horse_clone_role:SetRealPos(self.main_role_horse_clone_role.real_pos.x, self.main_role_horse_clone_role.real_pos.y) end break end end if is_finish then self.model.horse_fly_movie_is_playEnd = true self:DeleteCoud() self:StopUpdate() end end --创建云 function WelecomeController:CreateCoud() if self.big_coud then destroy(self.big_coud, true) end self.big_coud = UiFactory.createChild(panelMgr:GetParent("Main"),UIType.Image) self.big_coud.transform:SetAsFirstSibling() self.big_coud_height = 400 self.big_coud_pos_y = ScreenHeight * 0.2 + self.big_coud_height * 0.5 + 50 self.big_coud.transform.localPosition = Vector3(0, self.big_coud_pos_y, 0) if self.coun_ref_tar == nil then self.coun_ref_tar = {} end local function call_back() self.big_coud_has_loaded = true self.big_coud_height = self.big_coud.transform.sizeDelta.y self.big_coud_pos_y = ScreenHeight * 0.2 + self.big_coud_height * 0.5 + 50 self.big_coud.transform.localPosition = Vector3(0, self.big_coud_pos_y, 0) end lua_resM:setImageSprite(self.coun_ref_tar, self.big_coud:GetComponent("Image"), "welecome_asset", "we_big_coud2", true, call_back) end function WelecomeController:DeleteCoud() if self.big_coud then if self.timer_id then GlobalTimerQuest:CancelQuest(self.timer_id) self.timer_id = nil end local alpha = 1 local function onTimer() if alpha > 0.2 then alpha = alpha - 0.1 SetAlpha(self.big_coud:GetComponent("Image"),alpha) else if self.timer_id then GlobalTimerQuest:CancelQuest(self.timer_id) self.timer_id = nil end destroy(self.big_coud) self.big_coud = nil end end self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 0.05, -1) end self.big_coud_has_loaded = nil lua_resM:clearReference(self.coun_ref_tar) end function WelecomeController:PlayEnd() self:DeleteCoud() self:StopUpdate() self.model.forbid_move = false self.horse_movie_config = nil if self.main_role_horse_clone_role then self.main_role_horse_clone_role:SetModelHideFlag(SceneObj.ModelHideFlag.OnlyShowHorse, false) self.main_role_horse_clone_role.ignore_pool = true SceneManager.Instance:DeleteRoleVo(self.main_role_horse_clone_role.id) self.main_role_horse_clone_role.LoadHorseResCompleteUserDefined = nil self.main_role_horse_clone_role.SetRealPosUserDefined = nil self.main_role_horse_clone_role.SetBodyXYUserDefined = nil self.main_role_horse_clone_role = nil self.MainRoleJumpUpHorseCallBack = nil if Scene.Instance.main_role then Scene.Instance.main_role:SetBodyXY(0, 0, true) end end if self.main_role_move_event_id then GlobalEventSystem:UnBind(self.main_role_move_event_id) self.main_role_move_event_id = nil end if self.jump_up_horse_id then GlobalTimerQuest:CancelQuest(self.jump_up_horse_id) self.jump_up_horse_id = nil end self.is_jump_up = false self.model.has_start = false end function WelecomeController:AddAllEvents() --if ClientConfig.alpha_mode then return end -- local open_fun = function () -- if not SceneManager:getInstance():IsSceneStart() then return end -- if RoleManager.Instance.mainRoleInfo.level<10 and TaskModel:getInstance():IsFisrtTask() and (SceneManager:getInstance():IsOutdoorScene() or SceneManager.Instance:IsMainCity()) then -- setTimeout(function() -- self:OpenWelecomeView() -- end,0.1) -- end -- if TaskModel:getInstance():IsDragonFlyTask() and SceneManager:getInstance():GetSceneId() == Config.Horse_fly_info.jump_point.scene_id then --飞龙任务 -- if not self.model.horse_fly_movie_is_playEnd then -- GlobalEventSystem:Fire(EventName.STOP_AUTO_DO_TASK) -- GlobalEventSystem:Fire(EventName.JUMP_UP_HORSE) -- end -- end -- if TaskModel:getInstance():IsCreateDragonTask() and SceneManager:getInstance():GetSceneId() == Config.Horse_fly_info.jump_point.scene_id then -- if not self.model.has_start then -- self.model.has_start = true -- if Scene.Instance.main_role then -- Scene.Instance.main_role:SetBodyXY(0, 0, true) -- end -- self:StartUpdate() -- end -- elseif self.model.horse_fly_movie_is_playEnd then -- self:PlayEnd() -- end -- end -- TaskModel:getInstance():Bind(TaskEvent.TASK_LIST_INIT, open_fun) -- local function onSceneStart() -- open_fun() -- end -- GlobalEventSystem:Bind(SceneManager.START,onSceneStart) -- local function gameStartHandler() -- self:PlayEnd() -- end -- GlobalEventSystem:Bind(EventName.GAME_START, gameStartHandler) -- GlobalEventSystem:Bind(LoginStateEvent.START_LOGIN_MODULE, gameStartHandler) -- local function onMainRoleFLyingHandler(dir, dist) -- if self.is_jump_up and self.big_coud_has_loaded and self.big_coud then -- self.big_coud_pos_y = self.big_coud_pos_y - dist * 0.6 -- self.big_coud.transform.localPosition = Vector3(0, self.big_coud_pos_y, 0) -- if self.big_coud_pos_y < -(ScreenHeight * 0.5 + self.big_coud_height * 0.5 + 50) then -- self.big_coud_pos_y = ScreenHeight * 0.2 + self.big_coud_height * 0.5 + 50 -- self.big_coud.transform.localPosition = Vector3(0, self.big_coud_pos_y, 0) -- end -- end -- end -- GlobalEventSystem:Bind(SceneEventType.MAIN_ROLE_FLYING, onMainRoleFLyingHandler) -- local function onMainRoleUpJumpEndHandler() -- self.is_jump_up = true -- self:CreateCoud() -- if self.main_role_horse_clone_role then -- self.main_role_horse_clone_role:SetModelHideFlag(SceneObj.ModelHideFlag.OnlyShowHorse, false) -- if self.main_role_horse_clone_role.animator then -- self.main_role_horse_clone_role.animator:CrossFade("ride", 0, 0, 0) -- self.main_role_horse_clone_role.animator:Update(0) -- end -- end -- if Scene.Instance.main_role then -- -- Scene.Instance.main_role:DoFly() -- Scene.Instance.main_role:SetModelHideFlag(SceneObj.ModelHideFlag.Story, true) -- end -- end -- self:Bind(SceneEventType.MAIN_ROLE_JUMP_UP_HORSE_END, onMainRoleUpJumpEndHandler) -- local function onMainRoleDownJumpEndHandler() -- self.model.forbid_move = false -- GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK) -- end -- self:Bind(SceneEventType.MAIN_ROLE_JUMP_DOWN_HORSE_END, onMainRoleDownJumpEndHandler) -- local function onMainRoleJumpUpHorseHandler() -- if Scene.Instance.main_role and self.main_role_horse_clone_role then -- local function moveEndFunc() -- local jump_point = co.Vector2(Config.Horse_fly_info.jump_point.x, Config.Horse_fly_info.jump_point.y) -- self.jump_up_horse_time = Scene.Instance.main_role:DoJumpUpHorse(jump_point) or 0 -- local dir = co.TableXY(jump_point.x - self.main_role_horse_clone_role.real_pos.x, jump_point.y - self.main_role_horse_clone_role.real_pos.y) -- local total_distance = co.NormaliseXYTable(dir) -- if self.MainRoleJumpUpHorseCallBack then -- self.MainRoleJumpUpHorseCallBack(self.jump_up_horse_time, self.jump_up_horse_time, total_distance / self.jump_up_horse_time) -- end -- if self.jump_up_horse_id then -- GlobalTimerQuest:CancelQuest(self.jump_up_horse_id) -- self.jump_up_horse_id = nil -- end -- end -- -- local function onCheckToJump() -- -- if Scene.Instance.main_role then -- -- local start_jump_point = co.Vector2(Config.Horse_fly_info.start_jump_point.x, Config.Horse_fly_info.start_jump_point.y) -- -- local x1, y1 = Scene.Instance.main_role:GetRealPos() -- -- if GameMath.GetDistance(x1, y1, start_jump_point.x, start_jump_point.y, false) > 50 * 50 then -- -- local function end_func() -- -- moveEndFunc() -- -- end -- -- OperateManager.Instance:StartMoveAction(co.Vector2(start_jump_point.x / SceneObj.LogicRealRatio.x, start_jump_point.y / SceneObj.LogicRealRatio.y), end_func) -- -- else -- -- moveEndFunc() -- -- end -- -- else -- -- end -- -- end -- -- if self.jump_up_horse_id then -- -- GlobalTimerQuest:CancelQuest(self.jump_up_horse_id) -- -- self.jump_up_horse_id = nil -- -- end -- -- self.jump_up_horse_id = GlobalTimerQuest:AddPeriodQuest(onCheckToJump, 1, -1) -- -- onCheckToJump() -- -- moveEndFunc() -- --走到目的点才开始飞行 -- local function call_back( ) -- moveEndFunc() -- end -- local findVo = FindVo.New() -- findVo.sceneId = SceneManager:getInstance():GetSceneId() -- findVo.type = FindVo.POINT -- findVo.x=2325/ SceneObj.LogicRealRatio.x -- findVo.y=2918/ SceneObj.LogicRealRatio.y -- findVo.call_back = call_back -- GlobalEventSystem:Fire(EventName.FIND,findVo) -- self.model.forbid_move = true -- end -- end -- self:Bind(EventName.JUMP_UP_HORSE, onMainRoleJumpUpHorseHandler) -- local function onMainRoleJumpDownHorseHandler(x, y) -- if self.is_jump_up then -- self.is_jump_up = false -- if Scene.Instance.main_role and self.main_role_horse_clone_role then -- Scene.Instance.main_role:SetModelHideFlag(SceneObj.ModelHideFlag.Story, false) -- local rx, ry = self.main_role_horse_clone_role:GetRealPos() -- if self.main_role_horse_clone_role.transform then -- rx, ry = self.main_role_horse_clone_role.transform.position.x * MainCamera.PixelsToUnits, self.main_role_horse_clone_role.transform.position.y * MainCamera.PixelsToUnits -- end -- Scene.Instance.main_role:SetRealPos(rx, ry - 20) -- if Scene.Instance.main_role.animator then -- Scene.Instance.main_role.animator:CrossFade("ride", 0, 0, 0) -- end -- Scene.Instance.main_role:DoJumpDownHorse(co.Vector2(x, y)) -- self.main_role_horse_clone_role:SetModelHideFlag(SceneObj.ModelHideFlag.OnlyShowHorse, true) -- end -- end -- end -- self:Bind(EventName.JUMP_DOWN_HORSE, onMainRoleJumpDownHorseHandler) end function WelecomeController:OpenWelecomeView() if self.welecomeView == nil then self.welecomeView = WelecomeView.New() end if not self.welecomeView:HasOpen() then self.welecomeView:Open() end end