|
|
-
- SceneLoadView = SceneLoadView or BaseClass(BaseView)
- local SceneLoadView = SceneLoadView
- SceneLoadView.LOAD_SCENE_TITLE = {type = 1, weight = 0.4}
- SceneLoadView.LOAD_PRELOAD_RES = {type = 2, weight = 0.5}
- SceneLoadView.LOAD_SCENE_DATA = {type = 3, weight = 0.1}
-
-
- function SceneLoadView:__init()
- self.base_file = "sceneLoad"
- self.layout_file = "SceneLoadView"
- self.layer_name = "Top"
- self.mask_open_sound = true
- self.mask_close_sound = true
- self.open_guide_close = nil
- -- self.use_local_view = true
- self.close_mode = CloseMode.CloseVisible
- self.destroy_imm = false
- self.use_background = true
- self.is_delay_callback = false
- self.is_set_zdepth = true
- self.hide_maincancas = false
- self.ignore_use_anim = true
- self.background_alpha = 1
- self.auto_update_progress = 0
- self.scene_load_progress_finished = false
- self.progress_time = 7 --进入游戏加载5秒 切换场景3秒
- self.trigger_story = nil
- self.cur_value = 0
- self.is_first_show = true
- -- self.is_first_set_res = true
- self.last_progress_value = 0
- self.curr_progress_value = 0
- self.temp_res_target = {}
- self.default_bg_abname = "icon_sceneload_1"
- self.default_res_name = "1.jpg"
- self:AddPreLoadList("uiComponent_asset", {"ProgressBar2", "progressBg", "progressColor"}, LuaResManager.RES_TYPE.SPRITE)
- self.curr_progress_with_weight = {}
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:InitEvent()
- end
- self.open_callback = function ()
- self:OpenFun()
- self:SetPromptTxt()
- if self.hide_load_progress then
- self.gameObject:SetActive(false)
- end
- self:CheckResLoadTime()
- self:StartSmoothTimer()
- if MainCamera and MainCamera.Instance then
- MainCamera:getInstance():ResetAutoRotateInfo()
- end
- end
-
- self.close_callback = function ()
- --切换角色之后,不需要预更新,等选角之后重新打开再更新加载图
- if self.is_change_role then
- self.is_change_role = false
- self.need_update_bg_in_open = true
- else
- self:UpdateLoadingBg() --预更新
- end
-
- self:Remove()
- self.open_callback_func = nil
- self.curr_progress_with_weight = {}
- GlobalEventSystem:Fire(EventName.PLAY_MAINUI_MOVIE_CENTER_EVENT)
- -- self.is_first_set_res = false
-
- end
-
- self.destroy_callback = function()
- self:DestroySuccess()
- end
- end
-
- function SceneLoadView:DestroySuccess( )
- if self.change_account_id then
- GlobalEventSystem:UnBind(self.change_account_id)
- self.change_account_id = nil
- end
- if self.change_role_id then
- GlobalEventSystem:UnBind(self.change_role_id)
- self.change_role_id = nil
- end
- if self.level_up_id then
- RoleManager.Instance.mainRoleInfo:UnBind(self.level_up_id)
- self.level_up_id = nil
- end
- end
-
- function SceneLoadView:Open(hide_load_progress,scene_id)
- self.open_guide_close = nil --此界面不销毁,需要每次都重置一下该状态
- self.hide_load_progress = hide_load_progress or false
- self.scene_id = scene_id or false
- self.is_show_effect = false
- SceneLoadView.super.Open(self)
-
- if self.need_update_bg_in_open then
- self.need_update_bg_in_open = false
- self:UpdateLoadingBg()
- end
- end
-
- function SceneLoadView:CheckResLoadTime()
- if self.check_close_event then
- GlobalTimerQuest:CancelQuest(self.check_close_event)
- self.check_close_event = nil
- end
- local check_close_func = function()
- if not self.scene_load_progress_finished then
- self.wait_res_load = true
- if not IsNull(self.showText) then
- self:SetLoadText(self.cur_value)
- end
- end
- self.check_close_event = nil
- end
- self.check_close_event = setTimeout(check_close_func,20)
- end
-
- function SceneLoadView:Remove()
- GlobalEventSystem:Fire(EventName.SCENELOADVIEWE_CLOSE)
- if self.anima then
- destroy(self.anima)
- self.anima = nil
- end
- if self.recording_bind_id then
- GlobalTimerQuest:CancelQuest(self.recording_bind_id)
- self.recording_bind_id = nil
- end
- self.scene_load_progress_finished = false
- self.auto_update_progress = 0
- self.cur_value = 0
- self.wait_res_load = false
- if not IsNull(self.showText) then
- self.showText.gameObject:SetActive(true)
- end
-
- if self.check_close_event then
- GlobalTimerQuest:CancelQuest(self.check_close_event)
- self.check_close_event = nil
- end
-
- self:StopSmoothTimer()
- self.last_progress_value = 0
- self.curr_progress_value = 0
- end
-
- function SceneLoadView:LoadSuccess()
- self.bg = self:GetChild("bg"):GetComponent("Image")
- -- self.bottom_conta = self:GetChild("bottom_conta")
- -- self.bottom_conta.sizeDelta = Vector2(SrcScreenWidth,self.bottom_conta.sizeDelta.y)
- -- self.bottom_conta.transform.localPosition = Vector3(-SrcScreenWidth / 2, -ScreenHeight / 2, 0)
- self.progressConta,
- self.showTextTran,
- self.bottom_conta
- = GetChildTransforms(self.transform, {
- "bg/bottom_conta/progressConta",
- "bg/bottom_conta/showText",
- "bg/bottom_conta"
- })
-
- self.showText = self:GetChild("bg/bottom_conta/showText"):GetComponent("TMP_Text")
- self.promptText = self:GetChild("bg/bottom_conta/promptText"):GetComponent("TMP_Text")
- self.defaultTitleText,
- self.defaultText
- = GetChildTexts(self.transform, {
- "bg/bottom_conta/defaultTitleText",
- "bg/bottom_conta/defaultText",
- })
-
- self.progress_bar = ProgressBarComponent.New(self.progressConta, 100, 0, 1150, 14, nil, "progressBg", "progressColor", {x = 0, y = 0}, false, false)
-
- -- if ClientConfig.iphone_x_model then
- -- local p = self.showText.transform.localPosition
- -- self.showText.transform.localPosition = Vector3(p.x, p.y, p.z)
- -- end
-
- if ClientConfig.iphone_x_model and SystemRuntimePlatform.IsIphone() then
- self.bottom_conta.transform.anchoredPosition = Vector3(0, 50 + ClientConfig.iphone_x_offset_bottom)
- end
- self.bg.transform.sizeDelta = Vector2(SrcScreenWidth, ScreenHeight)
- self.bg.transform.sizeDelta = Vector2(1560, 720)
-
- local function load_callback()
- Scene.Instance:SetFirstLoadBgFinish(true)
- local main_role = Scene.Instance.main_role
- if main_role then
- local pos_x = RoleManager.Instance.mainRoleInfo.pos_x
- local pos_y = RoleManager.Instance.mainRoleInfo.pos_y
- main_role:SetRealPos(pos_x,pos_y, true)
- end
- end
- self:UpdateLoadingBg(load_callback)
- end
-
- function SceneLoadView:InitEvent()
- local function change_account()
- self.is_change_role = true
- self.last_role_level = false
- end
- self.change_account_id = GlobalEventSystem:Bind(EventName.CHANGE_ACCOUNT, change_account)
- self.change_role_id = GlobalEventSystem:Bind(EventName.CHANGE_ROLE, change_account)
- self:SetDefaultTxt()
-
- local function on_change_level(lv)
- self.last_role_level = self.last_role_level or lv
- --限制频率
- if self.last_role_level and lv - self.last_role_level > 5 then
- --只在隐藏的时候更新
- if not IsNull(self.gameObject) and not self.gameObject.activeSelf then
- self:UpdateLoadingBg()
- self.last_role_level = lv
- end
- end
- end
- self.level_up_id = RoleManager.Instance.mainRoleInfo:Bind(EventName.CHANGE_LEVEL, on_change_level)
- end
-
- function SceneLoadView:OpenFun()
- -- lua_resM:clearReference(self.temp_res_target)
- GlobalEventSystem:Fire(SceneEventType.SCENE_LOAD_VIEW_HASOPEN)
-
- self.is_first_show = false
- self:Remove()
- self:SetProgressValue(0, 100)
- if self.open_callback_func then
- self.open_callback_func()
- self.open_callback_func = nil
- end
- end
-
- function SceneLoadView:UpdateLoadingBg( call_back )
- local index = SceneManager:getInstance():CheckMatchLoadingRes()
- local res_name = index .. ".jpg"
- local ab_name = "icon_sceneload_" .. index
- local function load_finish( )
- if call_back then
- call_back()
- end
- end
- lua_resM:setImageSprite(self.temp_res_target, self.bg, ab_name, res_name, nil, load_finish, ASSETS_LEVEL.HIGHT)
- end
-
-
- function SceneLoadView:SetOpenCallBackFunc(call_back)
- self.open_callback_func = call_back
- end
-
- function SceneLoadView:AutoToShow(last_time, need_bind_event)
- local has_bind_back = false
- local progress_back = false
-
- if need_bind_event then
- local bind_id
- local on_back = function(...)
- has_bind_back = true
- if progress_back then
- has_bind_back = false
- self:Close()
- end
- GlobalEventSystem:UnBind(bind_id)
- end
- bind_id = GlobalEventSystem:Bind(need_bind_event, on_back)
- else
- has_bind_back = true
- end
-
- local finish = function()
- progress_back = true
- if has_bind_back then
- progress_back = false
- self:Close()
- end
- end
-
- if not self.auto_show_id then
- local inter = 0.05
- local per_add = 100 / (last_time / inter)
- local auto_show_progress = 0
-
- self:Open()
-
- local onTimer = function()
- auto_show_progress = auto_show_progress + per_add
- self:SetProgressValue(auto_show_progress, 100)
-
- if auto_show_progress >= 100 then
- GlobalTimerQuest:CancelQuest(self.auto_show_id)
- self.auto_show_id = nil
-
- finish()
- end
- end
- self.auto_show_id = GlobalTimerQuest:AddPeriodQuest(onTimer, inter, -1)
- end
- end
-
- function SceneLoadView:AddLoadTimer()
- if self.recording_bind_id == nil then
- local time = 0
- local function onTimer()
- time = time + 0.05
- if not self.trigger_story and time >= self.progress_time - 0.3 then
- self.trigger_story = true
- GlobalEventSystem:Fire(EventName.TRIGGER_STORY_START)
- end
-
- if time <= self.progress_time then
- local add = 5 / self.progress_time
- self:AutoUpdateProgress(add)
- else
- GlobalTimerQuest:CancelQuest(self.recording_bind_id)
- self.recording_bind_id = nil
- self.trigger_story = nil
- self.scene_load_progress_finished = true
- self.progress_time = 3
- end
- end
- onTimer()
- self.recording_bind_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 0.05, -1)
- end
- end
-
- --真实的进度条 weight权重
- function SceneLoadView:RealUpdateProgress(curr_value, max_value, load_type)
- if not self.isPop then return end
- if load_type == nil then return end
- curr_value = curr_value or 0
- max_value = max_value or 100
- if max_value == 0 then max_value = 100 end
- self.curr_progress_with_weight[load_type.type] = math.floor(curr_value / max_value * 100) * load_type.weight
- -- self:AutoUpdateProgress()
- end
-
- function SceneLoadView:AutoUpdateProgress()
- local value = 0
- for t, v in pairs(self.curr_progress_with_weight) do
- value = value + v
- end
- if self.is_loaded then
- if value > self.curr_progress_value then
- self:SetProgressValue(value, 100)
- end
- -- self:SetLoadText(value)
- end
-
- if value >= 100 then
- self.trigger_story = nil
- self.scene_load_progress_finished = true
- end
- end
-
- function SceneLoadView:SetProgressValue(value, max_value)
- self.curr_progress_value = value
- self.progress_bar:SetValue(value, max_value)
- self:SetLoadText(value)
- if value >= 0.1 and not self.is_show_effect then
- self.is_show_effect = true
- if self.effectCon then
- self.effectCon.gameObject:SetActive(true)
- end
- end
- end
-
- --设置底部的默认提示信息
- function SceneLoadView:SetLoadText(value)
- self.cur_value = value
- if not self.wait_res_load then
- self.showText.text = "加载中 " .. HtmlColorTxt(math.floor(value) .. "%", "#FFFFFF")
- else
- self.promptText.text = "预先加载场景资源可以让游戏体验更好哦(" .. math.floor(value) .. "%)"
- end
- end
-
- --设置底部的默认提示信息
- function SceneLoadView:SetDefaultTxt()
- self.defaultTitleText.text = "健康提示忠告"
- self.defaultText.text = "抵制不良游戏 拒绝盗版游戏 注意自我保护 谨防受骗上当 适度游戏益脑 沉迷游戏伤身 合理安排时间 享受健康生活"
- end
-
- function SceneLoadView:SetPromptTxt()
- if self.wait_res_load then
- return
- end
-
- --math.randomseed(os.time())
- local cfg = Config.ConfigLoadView.LoadViewPromptMsg
- local str = ""
- local index = math.random(1, #cfg)
- if cfg and cfg[index] then
- str = cfg[index]
- end
- self.promptText.text = str
- end
-
- function SceneLoadView:StopSmoothTimer( )
- if self.timer_id then
- GlobalTimerQuest:CancelQuest(self.timer_id)
- self.timer_id = nil
- end
- end
-
- function SceneLoadView:StartSmoothTimer( step_time )
- self:StopSmoothTimer()
- self.smooth_max_value = 10
- local function onTimer()
- if self.curr_progress_value >= 100 then
- self:StopSmoothTimer()
- self.scene_load_progress_finished = true
- return
- end
- if self.curr_progress_value > self.smooth_max_value then
- local value = 0
- for t, v in pairs(self.curr_progress_with_weight) do
- value = value + v
- end
- --未加载完,停在99
- if self.curr_progress_value > 98 and value < 100 then
- return
- end
- --已经全部加载完了,则提高进度条加载速度
- if value >= 100 and self.logic_step_time == self.real_step_time then
- local faster_step = self.logic_step_time / 5
- self:StartSmoothTimer(faster_step)
- end
- end
- if self.last_progress_value == self.curr_progress_value then
- self.curr_progress_value = self.curr_progress_value + 1
- self:SetProgressValue(self.curr_progress_value,100)
- end
- self.last_progress_value = self.curr_progress_value
-
- end
- self.logic_step_time = 0.08
- if SystemMemoryLevel.Cur == SystemMemoryLevel.Hight then
- self.logic_step_time = 0.06
- elseif SystemMemoryLevel.Cur == SystemMemoryLevel.Middle then
- self.logic_step_time = 0.07
- end
- if SystemRuntimePlatform.IsWindows() then
- self.logic_step_time = 0.01
- end
- self.real_step_time = step_time or self.logic_step_time
- self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, self.real_step_time, -1)
- end
-
|