| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- local UIStoryMgr = class("UIStoryMgr")
- local storyPlayStatus = false
- local curStoryData
- local storyList = {}
- function UIStoryMgr:ctor()
- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UISTORY_CONDITION_TRIGGER, self, self.StoryConditionTrigger)
- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UISTORY_UI_START_OR_OVER, self, self.StoryUIStartOrOver)
- end
- function UIStoryMgr:StoryConditionTrigger(type, ...)
- local params = {...}
- local storyData
- local storyDatas = ManagerContainer.DataMgr.StoryData:GetStoryDatas()
- local condition = params[1]
- local storyId = params[2]
- if type == Enum.UIStoryCondType.FirstSceneEnter then
- local storyCfgData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
- if storyCfgData == nil then
- return
- end
- if storyCfgData.Condition ~= nil then
- if storyCfgData.Condition[2] == condition then
- storyData = storyCfgData
- end
- end
- local record = UIStoryMgr:CheckRecord(storyId)
- if record then
- return
- end
- else
- local storyCfgDatas = ManagerContainer.CfgMgr:GetAllStoryDatasByType(type)
- if storyCfgDatas ~= nil then
- for _,v in pairs(storyCfgDatas) do
- if v.Condition ~= nil then
- if v.Condition[2] == condition then
- storyData = v
- local record = UIStoryMgr:CheckRecord(v.Id)
- if record then
- return
- end
- end
- end
- end
- end
- end
- if storyData == nil then
- return
- end
- self:StoryCheckData(storyData)
- if condition == storyData.Condition[2] then
- storyList[#storyList + 1] = storyData
- self:StartStory()
- end
- end
- function UIStoryMgr:MapStartStoryByStoryId(storyId)
- local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
- if storyData == nil then
- LogError("hurui: "..tostring(storyId) .." storyId isnt exist")
- return
- end
- self:StoryCheckData(storyData)
- storyData.isMap = true
- storyList[#storyList + 1] = storyData
- self:StartStory()
- end
- function UIStoryMgr:StartStoryByStoryId(storyId, skipCheckCache)
- local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
- if storyData == nil then
- LogError("hurui: "..tostring(storyId) .." storyId isnt exist")
- --LuaBattleBridge.CurStoryOver(storyId)
- return
- end
- local record = false
- if not skipCheckCache then
- record = UIStoryMgr:CheckRecord(storyId)
- end
- if not record then
- self:StoryCheckData(storyData)
- storyList[#storyList + 1] = storyData
- self:StartStory()
- end
- end
- function UIStoryMgr:GetNextStory(storyId)
- local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
- local storyDatas = ManagerContainer.DataMgr.StoryData:GetStoryDatas()
- storyId = storyData.SelectionNext[storyDatas[storyId]]
- storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
- if storyData then
- if storyDatas[storyId] ~= nil then
- if storyData.SelectionNext == nil then
- if storyDatas[storyId] >= 0 then
- return nil
- end
- else
- return self:GetNextStory(storyId)
- end
- else
- return storyData
- end
- end
- return nil
- end
- function UIStoryMgr:CheckRecord(storyId)
- local storyData
- local list = ManagerContainer.CfgMgr:GetSameStoryGroupDatasById(storyId)
- local storyDatas = ManagerContainer.DataMgr.StoryData:GetStoryDatas()
- if list == nil then
- if storyDatas[storyId] ~= nil then
- storyData = self:GetNextStory(storyId)
- if storyData == nil then
- --LogError("hurui: "..storyId .." story is recorded")
- LuaBattleBridge.CurStoryOver(storyId)
- return true
- end
- end
- else
- for _,v in pairs(list) do
- if storyDatas[v.Id] ~= nil then
- storyData = self:GetNextStory(v.Id)
- if storyData == nil then
- --LogError("hurui: "..storyId .." story is recorded")
- LuaBattleBridge.CurStoryOver(storyId)
- return true
- end
- end
- end
- end
- return false
- end
- function UIStoryMgr:StoryCheckData(storyData)
- if storyData.Group ~= nil and storyData.DataCheck ~= nil then
- local list = ManagerContainer.CfgMgr:GetSameStoryGroupDatasById(storyData.Id)
- if list ~= nil then
- for k,v in pairs(list) do
- if ManagerContainer.DataMgr.StoryData:CheckDataConditions(v.DataCheck) then
- storyData = v
- break
- end
- end
- end
- end
- end
- function UIStoryMgr:StartStory()
- if storyPlayStatus then
- return
- end
- if #storyList == 0 then
- return
- end
- curStoryData = storyList[1]
- table.remove(storyList, 1)
- storyPlayStatus = true
- --LogError("open story "..curStoryData.Id)
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIStory, curStoryData)
- end
- function UIStoryMgr:NeedNextStory()
- return #storyList > 0
- end
- function UIStoryMgr:ImmediateRecord(storyId, idx)
- local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
- if storyData == nil then
- return
- end
- local default = storyData.SelectionTexts ~= nil and 1 or 0
- idx = idx or default
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ROLE_STORY_REQ, {story_id = {key = storyId, value = idx}})
- end
- function UIStoryMgr:StartNextStory(storyId)
- if curStoryData == nil then return end
- if curStoryData.ProgramControl and not curStoryData.isMap then
- LuaBattleBridge.CurStoryOver(curStoryData.Id)
- end
- if curStoryData.NeedSave then
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ROLE_STORY_REQ, {story_id = {key = curStoryData.Id, value = idx or 0}})
- end
- if storyId ~= nil and storyId > 0 then
- curStoryData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
- if curStoryData ~= nil then
- return curStoryData
- end
- end
- if #storyList == 0 then
- return
- end
- curStoryData = storyList[1]
- table.remove(storyList, 1)
- storyPlayStatus = true
- return curStoryData
- end
- function UIStoryMgr:StoryUIStartOrOver(status, idx)
- if curStoryData == nil then return end
- if curStoryData.HideUi then
- ManagerContainer.LuaUIMgr:StoryHideUIStatus(not status)
- end
- if not status then
- if curStoryData.ProgramControl and not curStoryData.isMap then
- LuaBattleBridge.CurStoryOver(curStoryData.Id)
- end
- if curStoryData.NeedSave then
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ROLE_STORY_REQ, {story_id = {key = curStoryData.Id, value = idx or 0}})
- end
- local storyId = curStoryData.Id
- storyPlayStatus = false
- curStoryData = nil
- --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_TRIGGER, Enum.ForceGuideTriggerEnum.Story, storyId)
- ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIStory)
- end
- end
- function UIStoryMgr:Dispose()
- storyPlayStatus = false
- curStoryData = nil
- storyList = {}
- ManagerContainer.LuaUIMgr:CloseInputMask()
- end
- function UIStoryMgr:Destroy()
- self:Dispose()
- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UISTORY_CONDITION_TRIGGER, self, self.StoryConditionTrigger)
- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UISTORY_UI_START_OR_OVER, self, self.StoryUIStartOrOver)
- if tolua.getpeer(self) ~= nil then
- tolua.setpeer(self, nil)
- end
- end
- return UIStoryMgr
|