123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- ---@class KLGuideManager
- KLGuideManager = {}
- local this = KLGuideManager
- function this.Init()
- this.showPanelList = {}
- this.now_guide_id_list = {}
- this.now_guide_next_list = {}
-
- this.rear_guide_list = {}
- this.first_guide_list = {}
- this.now_guide_to_first_guide = {}
- this.now_guide_to_pre_guide = {}
- this.career_last_guide = {}
-
- this.InitData()
- this.RegistEvents()
-
- end
- function this.RegistEvents()
- SL:RegisterLUAEvent(LUA_EVENT_OPEN_UI,this.LUA_EVENT_OPEN_UI)
- SL:RegisterLUAEvent(LUA_EVENT_MAIN_UI_VISIBLE_AFTER,this.LUA_EVENT_MAIN_UI_VISIBLE_AFTER)
- SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN,this.LUA_EVENT_CLOSEWIN)
-
- SL:RegisterLUAEvent(LUA_EVENT_TASK_NEW,this.LUA_EVENT_TASK_NEW)
- SL:RegisterLUAEvent(LUA_EVENT_TASK_FINISH,this.LUA_EVENT_TASK_FINISH)
- SL:RegisterLUAEvent(LUA_EVENT_LEVELCHANGE,this.LUA_EVENT_LEVELCHANGE)
-
- SL:RegisterLUAEvent(LUA_EVENT_ENTER_MAP,this.LUA_EVENT_ENTER_MAP)
- --SL:RegisterLUAEvent(LUA_EVENT_CHANGESCENE,this.LUA_EVENT_CHANGESCENE)
- SL:RegisterLUAEvent(LUA_EVENT_BAG_CHANGE_AFTER,this.LUA_EVENT_BAG_CHANGE_AFTER)
- --SL:RegisterLUAEvent(LUA_EVENT_BAG_CHANGE_AFTER,this.LUA_EVENT_BAG_CHANGE_AFTER)
- end
- function this:LUA_EVENT_BAG_CHANGE_AFTER()
- this.UpdateGuide()
- end
- function this:LUA_EVENT_CHANGESCENE()
- this.UpdateGuide()
- end
- function this:LUA_EVENT_ENTER_MAP()
- this.Reset()
- end
- function this:LUA_EVENT_TASK_NEW()
- this.UpdateGuide()
- end
- function this:LUA_EVENT_TASK_FINISH()
- this.UpdateGuide()
- end
- function this:LUA_EVENT_LEVELCHANGE()
- this.UpdateGuide()
- end
- function this.InitData()
- local rookie_guide_tbl = SL:GetConfigTable('cfg_rookie_guide')
- for _, rookieInfo in pairs(rookie_guide_tbl) do
- local rear_id = rookieInfo["rearGuide"]
- if rear_id then
- table.insert(this.rear_guide_list, rear_id)
- end
- end
- for _, rookieInfo in pairs(rookie_guide_tbl) do
- local now_id = rookieInfo["id"]
- if not table.contains(this.rear_guide_list, now_id) then
- table.insert(this.first_guide_list, rookieInfo)
- end
- end
- -- 保存每个引导的起始引导
- for _, rookieInfo in pairs(this.first_guide_list) do
- local nowId = rookieInfo["id"]
- local rearId = rookieInfo["rearGuide"]
- this.now_guide_to_first_guide[nowId] = nowId
- while rearId ~= 0 do
- this.now_guide_to_first_guide[rearId] = nowId
- rearId = SL:GetConfig('cfg_rookie_guide', rearId).rearGuide
- end
-
- end
- -- 保存当前引导的上一个引导
- for _, rookieInfo in pairs(rookie_guide_tbl) do
- local nowId = rookieInfo["id"]
- local rearId = rookieInfo["rearGuide"]
- if rearId ~= 0 then
- this.now_guide_to_pre_guide[rearId] = nowId
- end
- end
- -- 获取每个职业的最后一个引导
- for _, rookieInfo in pairs(rookie_guide_tbl) do
- local sequence = rookieInfo["sequence"]
- for i, v in pairs(sequence) do
- if this.career_last_guide[v[1]] == nil then
- this.career_last_guide[v[1]] = {sort = v[2],id = rookieInfo.id}
- else
- if this.career_last_guide[v[1]].sort < v[2] then
- this.career_last_guide[v[1]] = {sort = v[2],id = rookieInfo.id}
- elseif this.career_last_guide[v[1]].sort == v[2] and this.career_last_guide[v[1]].id < rookieInfo.id then
- this.career_last_guide[v[1]] = {sort = v[2],id = rookieInfo.id}
- end
- end
- end
- end
- end
- function this.getMaxGuideId()
- if this.career_last_guide then
- local job = SL:GetMetaValue(EMetaVarGetKey.JOB)
- if this.career_last_guide[0].sort > this.career_last_guide[job].sort then
- return this.career_last_guide[0].id
- else
- return this.career_last_guide[job].id
- end
- end
- end
- function this.addRookieGuide(guideId)
- if this.showPanelList[guideId] == nil then
- if this.CheckUiIsActive(guideId) then
- this.showPanelList[guideId] = {}
- ---@type KLRookieGuidePanel
- GUI:UIPanel_Open("dev/outui/Guide/Panel/KLRookieGuide/KLRookieGuidePanel",nil, nil, {guideId=guideId}, true,
- function(panel)
- this.showPanelList[guideId] = panel
- end)
-
- if not table.contains(this.now_guide_id_list, guideId) then
- table.insert(this.now_guide_id_list, guideId)
- end
- end
- end
- end
- function this.CheckRookieGuide(guideId)
- if this.showPanelList[guideId] == nil then
- if this.CheckUiIsActive(guideId) then
- this.showPanelList[guideId] = {}
- ---@type KLRookieGuidePanel
- GUI:UIPanel_Open("dev/outui/Guide/Panel/KLRookieGuide/KLRookieGuidePanel",nil, nil, {guideId=guideId}, true,
- function(panel)
- this.showPanelList[guideId] = panel
- end)
-
- if not table.contains(this.now_guide_id_list, guideId) then
- table.insert(this.now_guide_id_list, guideId)
- end
- end
- end
- end
- function this:LUA_EVENT_MAIN_UI_VISIBLE_AFTER(info)
- local vis = info.vis
- local name = info.name
- if vis then
- SL:ScheduleOnce(Time.deltaTime,function()
- this.UiShowGuide(name)
- end)
- --Coroutine.Start(this.UiShowGuide,name)
- else
- this.UiHide(name)
- end
- end
- ---@param win UIKmlLuaPanelBase
- function this:LUA_EVENT_OPEN_UI(win)
- if win then
- local openPanelName = win.panelName
- SL:ScheduleOnce(Time.deltaTime,function()
- this.UiShowGuide(openPanelName)
- end)
- --Coroutine.Start(this.UiShowGuide,openPanelName)
- --this.UiShowGuide(openPanelName)
- end
- end
- function this.UiShowGuide(name)
- --Coroutine.Wait(0.1)
- --Coroutine.WaitForEndOfFrame()
- local already_first_guide_list = this.GetFirstGuideIdList()
- for _, rookie_info in pairs(this.first_guide_list) do
- local nowId = rookie_info["id"]
- if not table.contains(already_first_guide_list, nowId) then
- local conditions = rookie_info["conditions"]
- local panel_info = string.split(rookie_info["uiAddress"], '&')
- local panel_id = panel_info[1]
- if panel_id == name then
- if SL:CheckCondition(conditions) then
- this.addRookieGuide(nowId)
- end
- end
- end
- end
- for _, nowId in pairs(this.now_guide_next_list) do
- local rookie_info = SL:GetConfig('cfg_rookie_guide', nowId)
- if not table.contains(already_first_guide_list, nowId) then
- local conditions = rookie_info["conditions"]
- local panel_info = string.split(rookie_info["uiAddress"], '&')
- local panel_id = panel_info[1]
- if panel_id == name then
- if SL:CheckCondition(conditions) then
- this.CheckRookieGuide(nowId)
- end
- end
- end
- end
- end
- function this.HideGuide(guideId)
- local panel = this.showPanelList[guideId]
- if panel then
- GUI:UIPanel_Close(nil, panel)
- this.showPanelList[guideId] = nil
- end
- end
- function this:LUA_EVENT_CLOSEWIN(panelName)
- this.UiHide(panelName)
- end
- function this.UiHide(panelName)
- if not next(this.now_guide_next_list) and not next(this.now_guide_id_list) then
- return
- end
- for index, guideId in pairs(this.now_guide_id_list) do
- local rookie_info = SL:GetConfig('cfg_rookie_guide', guideId)
- local panel_info = string.split(rookie_info["uiAddress"], '&')
- local panel_id = panel_info[1]
- if panel_id == panelName then
- this.HideGuide(guideId)
- this.now_guide_id_list[index] = nil
- end
- end
- for index, guideId in pairs(this.now_guide_next_list) do
- local rookie_info = SL:GetConfig('cfg_rookie_guide', guideId)
- local panel_info = string.split(rookie_info["uiAddress"], '&')
- local panel_id = panel_info[1]
- if panel_id == panelName then
- this.HideGuide(guideId)
- this.now_guide_next_list[index] = nil
- end
- end
-
- end
- -- 获取正在引导的首个组id列表
- function this.GetFirstGuideIdList()
- local resultList = {}
- for _, guideId in pairs(this.now_guide_id_list) do
- table.insert(resultList, guideId)
- end
- for _, guideId in pairs(this.now_guide_next_list) do
- local firstId = this.now_guide_to_first_guide[guideId]
- if firstId then
- table.insert(resultList, firstId)
- end
- end
-
- return resultList
- end
- function this.CheckUiIsActive(guideId)
- local rookieCfg = SL:GetConfig('cfg_rookie_guide', guideId)
- local address = rookieCfg.uiAddress
- local panelId
- if address then
- local contrTransform
- -- 弹出的特殊处理
- if table.contains(rookieCfg.showType, EGuideShowType.ToProp) then
- contrTransform = GUI:GetPanelTransform(address)
- panelId = address
- else
- local addrSplit = string.split(address, '&')
- panelId = addrSplit[1]
- local contrName = addrSplit[2]
- contrTransform = GUI:GetControlTransform(panelId, contrName)
- end
-
- if MainUiStateManager.showPanelMap[panelId] ~= nil then
- return MainUiStateManager.showPanelMap[panelId]
- end
- if not contrTransform then
- return false
- end
-
- return contrTransform.gameObject.activeSelf
- end
-
- return false
- end
- -- 更新引导
- function this.UpdateGuide()
- for index, guideId in pairs(this.now_guide_id_list) do
- local rookieCfg = SL:GetConfig('cfg_rookie_guide', guideId)
- local conditions = rookieCfg["conditions"]
- if not SL:CheckCondition(conditions) then
- this.HideGuide(guideId)
- this.now_guide_id_list[index] = nil
- end
- end
- for index, guideId in pairs(this.now_guide_next_list) do
- local rookieCfg = SL:GetConfig('cfg_rookie_guide', guideId)
- local conditions = rookieCfg["conditions"]
- if not SL:CheckCondition(conditions) then
- this.HideGuide(guideId)
- this.now_guide_next_list[index] = nil
- end
- end
-
- local already_first_guide_list = this.GetFirstGuideIdList()
- for _, guideInfo in pairs(this.first_guide_list) do
- local guideId = guideInfo["id"]
- if not table.contains(already_first_guide_list, guideId) then
- if SL:CheckCondition(guideInfo["conditions"]) then
- this.addRookieGuide(guideId)
- end
- end
- end
-
- end
- function this.SetNextGuide(rearId)
- local preId = this.now_guide_to_pre_guide[rearId]
- if preId then
- if table.contains(this.now_guide_id_list, preId) then
- this.HideGuide(preId)
- table.removeByValue(this.now_guide_id_list, preId)
- table.insert(this.now_guide_next_list, rearId)
- --Coroutine.Start(function()
- -- Coroutine.WaitForEndOfFrame()
- -- this.CheckRookieGuide(rearId)
- --end)
- SL:ScheduleOnce(Time.deltaTime,function()
- this.CheckRookieGuide(rearId)
- end)
- elseif table.contains(this.now_guide_next_list, preId) then
- this.HideGuide(preId)
- table.removeByValue(this.now_guide_next_list, preId)
- table.insert(this.now_guide_next_list, rearId)
- --Coroutine.Start(function()
- -- Coroutine.WaitForEndOfFrame()
- -- this.CheckRookieGuide(rearId)
- --end)
-
- SL:ScheduleOnce(Time.deltaTime,function()
- this.CheckRookieGuide(rearId)
- end)
- end
- end
- end
- function this.AddPointControlGuide(panelId, contrId, guideId)
- local panel = this.showPanelList[guideId]
- if panel then
- panel:AddPointControlGuide(panelId, contrId, guideId)
- end
- end
- function this.HidePointControlGuide(guideId)
- local panel = this.showPanelList[guideId]
- if panel then
- panel:HidePointControlGuide()
- end
- end
- function this.Reset()
- for guideId, showPanel in pairs(this.showPanelList) do
- this.HideGuide(guideId)
- end
- this.showPanelList = {}
- this.now_guide_id_list = {}
- this.now_guide_next_list = {}
- end
- return this
|