Major Update - 2.0.0.143

EN: 2.0.0.143
CN: 2.0.0.142
JP: 2.0.0.145
KR: 2.0.0.150
This commit is contained in:
SL1900
2026-10-20 13:00:00 +09:00
parent 4bcada6061
commit 08b515afd9
1773 changed files with 1095195 additions and 65670 deletions
+668 -226
View File
@@ -1,64 +1,68 @@
local BaseCtrl = require("GameCore.UI.BaseCtrl")
local StoryChapterCtrl = class("StoryChapterCtrl", BaseCtrl)
local AvgData = PlayerData.Avg
local LocalData = require("GameCore.Data.LocalData")
local WwiseAudioMgr = CS.WwiseAudioManager.Instance
local RapidJson = require("rapidjson")
StoryChapterCtrl._mapNodeConfig = {
loopsvChapterList = {
sNodeName = "svChapterList",
sComponentName = "LoopScrollView"
animBg = {sNodeName = "----Bg----", sComponentName = "Animator"},
animTopBar = {sNodeName = "goBack", sComponentName = "Animator"},
animChapterList = {
sNodeName = "----Root_List----",
sComponentName = "Animator"
},
txtName = {sNodeName = "txtName", sComponentName = "TMP_Text"},
goPersonality = {
sNodeName = "goPersonality",
sComponentName = "GameObject"
animBtnShowStoryLineList = {
sNodeName = "btnShowStoryLineList",
sComponentName = "Animator"
},
btnChangeInfo = {
sNodeName = "btnChangeInfo",
sComponentName = "UIButton",
callback = "OnBtn_ClickChangeInfo"
},
btnLeft = {
sComponentName = "UIButton",
callback = "OnBtn_ClickStoryChapter"
},
btnRight = {
sComponentName = "UIButton",
callback = "OnBtn_ClickActivity"
},
Select = {nCount = 2},
unSelect = {nCount = 2},
rtActor2D = {
sNodeName = "----Actor2D_PNG----",
sComponentName = "Transform"
},
animActor2D = {
sNodeName = "----Actor2D_PNG----",
animMoWang = {
sNodeName = "----Root_MoWang----",
sComponentName = "Animator"
},
TopBar = {
sNodeName = "TopBarPanel",
sCtrlName = "Game.UI.TopBarEx.TopBarCtrl"
},
aniBg = {sNodeName = "----Bg----", sComponentName = "Animator"},
txtTitle_Show = {sComponentName = "TMP_Text"},
txtTitle2_Show = {sComponentName = "TMP_Text"},
imgStoryIcon = {sComponentName = "Image"},
TabRedDot = {},
txt_Select_1 = {
sComponentName = "TMP_Text",
sLanguageId = "WorldMap_MainLine_Avg"
btnShowStoryLineList = {
sComponentName = "UIButton",
callback = "OnBtn_ShowStoryLineList"
},
txt_unSelect_1 = {
sComponentName = "TMP_Text",
sLanguageId = "WorldMap_MainLine_Avg"
btnHideStoryLineList = {
sComponentName = "UIButton",
callback = "OnBtn_HideStoryLineList"
},
txt_Select_2 = {
sComponentName = "TMP_Text",
sLanguageId = "Story_Activity"
loopsvChapterList = {
sNodeName = "svChapterList",
sComponentName = "LoopScrollView"
},
txt_unSelect_2 = {
sComponentName = "TMP_Text",
sLanguageId = "Story_Activity"
loopsvStoryLineList = {
sNodeName = "svStoryLineList",
sComponentName = "LoopScrollView"
},
btnArrow = {
sComponentName = "UIButton",
callback = "OnBtn_HideStoryLineList"
},
rtActor2D = {
sNodeName = "----Actor2D_PNG----",
sComponentName = "Transform"
},
txtName = {sNodeName = "txtName", sComponentName = "TMP_Text"},
goPersonality = {
sNodeName = "goPersonality",
sComponentName = "GameObject"
},
txtBtnChangeInfo = {
sComponentName = "TMP_Text",
sLanguageId = "Change_Role_Character"
},
btnChangeInfo = {
sNodeName = "btnChangeInfo",
sComponentName = "UIButton",
callback = "OnBtn_ChangeInfo"
}
}
StoryChapterCtrl._mapEventConfig = {
@@ -66,142 +70,285 @@ StoryChapterCtrl._mapEventConfig = {
[EventId.UIHomeConfirm] = "OnEvent_BackHome"
}
StoryChapterCtrl._mapRedDotConfig = {
[RedDotDefine.Map_MainLine] = {sNodeName = "TabRedDot"}
[RedDotDefine.Map_MainLine_Entrance] = {sNodeName = "TabRedDot"}
}
function StoryChapterCtrl:Awake()
self.bInitLoop = true
local tbParam = self:GetPanelParam()
self.fromPanel = tbParam[1] ~= nil and tbParam[1] or 0
self.aniSafeRoot = self.gameObject:GetComponent("Animator")
self.constImgTitleBgWidth = 143.5
local callback = function()
self.bHasAchievementData = true
end
PlayerData.Achievement:SendAchievementInfoReq(callback)
self.tbPlayedUnlockEffectChapter = {}
end
function StoryChapterCtrl:FadeIn()
EventManager.Hit(EventId.SetTransition)
end
function StoryChapterCtrl:OnEnable()
self:SwitchTog(true)
self.tbGridCtrl = {}
local count = 0
self.nCompletedChapter = AvgData:GetNewLockChapterIndex()
count, self.tbAllChapter = PlayerData.Avg:GetChapterCount()
self.nRecentChapterId = PlayerData.Avg:GetRecentChapterId()
self._mapNode.loopsvChapterList:Init(count, self, self.RefreshChapterList)
self._mapNode.loopsvChapterList:SetScrollGridPos(self.nRecentChapterId - 3)
if not self.bInitLoop then
local index = 0
for k, v in pairs(self.tbGridCtrl) do
if v.Id ~= self.nCompletedChapter + 1 then
v.aniTrans:Play("StoryChapter_chapter_back")
self:ParseData()
self.nStoryLineId_From = 0
self.nStoryLineId_To = 0
self.bStoryLine_NeedPlayUnlockAnim = false
self.bStoryLine_NeedPlaySwitchAnim = false
self.nChapterId_From = 0
self.nChapterId_To = 0
self.bChapter_NeedPlayUnlockAnim = false
self.nCurLineId = 0
self.nCurChapterId = 0
self.goLineSel = nil
local tbParam = self:GetPanelParam()
if type(tbParam) == "table" then
local nSpecifyChapterId = tbParam[1] or 0
if type(nSpecifyChapterId) == "number" and 0 < nSpecifyChapterId then
local bUnlock, sTxt = PlayerData.Avg:IsStoryChapterUnlock(nSpecifyChapterId)
if bUnlock == true then
self.nChapterId_From = nSpecifyChapterId
local cfgdata = ConfigTable.GetData("StoryChapter", nSpecifyChapterId)
self.nStoryLineId_From = cfgdata.StoryLineId
else
printLog("specified chapter hasn't unlocked, chapter id:" .. tostring(nSpecifyChapterId))
end
end
end
self.bInitLoop = false
self:RefreshPersonality()
self._mapNode.animActor2D:Play("Actor2D_PNG_right_in")
self.nCompletedChapter = -1
self:SetMoWang()
self:CheckJustRead()
if type(tbParam) == "table" then
local nPreviousSelectedChapterId = tbParam[2] or 0
if type(nPreviousSelectedChapterId) == "number" and 0 < nPreviousSelectedChapterId then
local bUnlock, sTxt = PlayerData.Avg:IsStoryChapterUnlock(nPreviousSelectedChapterId)
if bUnlock == true then
self.nChapterId_From = nPreviousSelectedChapterId
local cfgdata = ConfigTable.GetData("StoryChapter", nPreviousSelectedChapterId)
self.nStoryLineId_From = cfgdata.StoryLineId
else
printLog("previous selected chapter hasn't unlocked, chapter id:" .. tostring(nPreviousSelectedChapterId))
end
end
end
self:CheckLatest()
self:FallbackToDefault()
self.bPlayEnterChapter = false
self.bPlayChapterIn = true
self.nChapterIn = 0.333
self.nCurLineId = self.nStoryLineId_From
self:SetBtn_IconTitle(self.nCurLineId)
self._mapNode.loopsvStoryLineList:Init(#self.tbLine, self, self.OnGrid_StoryLine, self.OnBtn_StoryLine)
for i, v in ipairs(self.tbLine) do
if v.nLineId == self.nStoryLineId_From then
self._mapNode.loopsvStoryLineList:SetScrollGridPos(i - 1, 0, -1)
break
end
end
self.tbChapter = self:GetChapters(self.nCurLineId)
self._mapNode.loopsvChapterList:Init(#self.tbChapter, self, self.OnGrid_Chapter, self.OnBtn_Chapter)
local nHeadIdx = table.indexof(self.tbChapter, self.nChapterId_From)
local nLocateChapterDuration = (nHeadIdx - 1) * 0.1
local PlayAnim_RootIn = function()
self:PlayRootAnim(true)
end
local PlayAnim_LocateChapter = function()
self.bPlayChapterIn = false
self.nChapterIn = 0
self._mapNode.loopsvChapterList:SetScrollGridPos(nHeadIdx - 1, nLocateChapterDuration, -1)
end
local PlayAnim_UnlockBtn = function()
self._mapNode.animBtnShowStoryLineList:Play("StoryChapter_LineBtn_Unlock")
WwiseAudioMgr:PlaySound("ui_mainline_ago_appear")
self:SetBtn_IconTitle(self.nStoryLineId_To, true)
end
local PlayAnim_MoveRight = function()
self:OnBtn_ShowStoryLineList()
end
local PlayAnim_ScrollToLine = function()
for i, v in ipairs(self.tbLine) do
if v.nLineId == self.nStoryLineId_To then
self._mapNode.loopsvStoryLineList:SetScrollGridPos(i - 1, 0.2, 0)
break
end
end
end
local PlayAnim_UnlockNewLine = function()
for i, v in ipairs(self.tbLine) do
if v.nLineId == self.nStoryLineId_To then
local goLineGridBtn = self._mapNode.loopsvStoryLineList.transform:Find("Viewport/Content/" .. tostring(i - 1)).gameObject
self:OnGrid_StoryLine(goLineGridBtn, true)
break
end
end
end
local PlayAnim_ClickLine = function()
for i, v in ipairs(self.tbLine) do
if v.nLineId == self.nStoryLineId_To then
local goLineGridBtn = self._mapNode.loopsvStoryLineList.transform:Find("Viewport/Content/" .. tostring(i - 1)).gameObject
self:OnBtn_StoryLine(goLineGridBtn)
break
end
end
end
local PlayAnim_Locate_To_Chapter = function()
self.bPlayChapterIn = false
self.nChapterIn = 0
local nIdx = table.indexof(self.tbChapter, self.nChapterId_To)
self._mapNode.loopsvChapterList:SetScrollGridPos(nIdx - 1, 0.2, -1)
end
local PlayAnim_Unlock_To_Chapter = function()
local nIdx = table.indexof(self.tbChapter, self.nChapterId_To)
local goChapterGridBtn = self._mapNode.loopsvChapterList.transform:Find("Viewport/Content/" .. tostring(nIdx - 1)).gameObject
self:OnGrid_Chapter(goChapterGridBtn, true)
end
local AnimDone = function()
self.nChapterIn = 0
end
local nAnimDuration = 0
local seq = DOTween.Sequence()
seq:AppendInterval(0.1)
seq:AppendCallback(PlayAnim_RootIn)
if self.nChapterIn < 0.4 then
seq:AppendInterval(0.4)
nAnimDuration = 0.5
else
seq:AppendInterval(self.nChapterIn)
nAnimDuration = self.nChapterIn + 0.1
end
seq:AppendCallback(PlayAnim_LocateChapter)
seq:AppendInterval(nLocateChapterDuration)
nAnimDuration = nAnimDuration + nLocateChapterDuration
if self.bStoryLine_NeedPlayUnlockAnim == true then
if self.nStoryLineId_From == 1 and self.nStoryLineId_To == 2 then
seq:AppendCallback(PlayAnim_UnlockBtn)
seq:AppendInterval(2)
nAnimDuration = nAnimDuration + 2
end
seq:AppendCallback(PlayAnim_MoveRight)
seq:AppendInterval(0.5)
seq:AppendCallback(PlayAnim_ScrollToLine)
seq:AppendInterval(0.2)
seq:AppendCallback(PlayAnim_UnlockNewLine)
seq:AppendInterval(1)
seq:AppendCallback(PlayAnim_ClickLine)
seq:AppendInterval(0.7)
seq:AppendCallback(PlayAnim_Locate_To_Chapter)
seq:AppendInterval(0.2)
seq:AppendCallback(PlayAnim_Unlock_To_Chapter)
seq:AppendInterval(1.3)
nAnimDuration = nAnimDuration + 0.5 + 0.2 + 1 + 0.7 + 0.2 + 1.3
elseif self.bStoryLine_NeedPlaySwitchAnim == true then
seq:AppendCallback(PlayAnim_MoveRight)
seq:AppendInterval(0.5)
seq:AppendCallback(PlayAnim_ScrollToLine)
seq:AppendInterval(0.2)
seq:AppendCallback(PlayAnim_ClickLine)
seq:AppendInterval(0.7)
seq:AppendCallback(PlayAnim_Locate_To_Chapter)
seq:AppendInterval(0.2)
seq:AppendCallback(PlayAnim_Unlock_To_Chapter)
seq:AppendInterval(1.3)
nAnimDuration = nAnimDuration + 0.5 + 0.2 + 0.7 + 0.2 + 1.3
elseif self.bChapter_NeedPlayUnlockAnim == true then
seq:AppendCallback(PlayAnim_Locate_To_Chapter)
seq:AppendInterval(0.2)
seq:AppendCallback(PlayAnim_Unlock_To_Chapter)
seq:AppendInterval(1.3)
nAnimDuration = nAnimDuration + 0.2 + 1.3
end
seq:AppendCallback(AnimDone)
seq:SetUpdate(true)
EventManager.Hit(EventId.TemporaryBlockInput, nAnimDuration)
end
function StoryChapterCtrl:OnDisable()
self.nStoryLineId_From = 0
self.nStoryLineId_To = 0
self.bStoryLine_NeedPlayUnlockAnim = false
self.bStoryLine_NeedPlaySwitchAnim = false
self.nChapterId_From = 0
self.nChapterId_To = 0
self.bChapter_NeedPlayUnlockAnim = false
self.nCurLineId = 0
self.nCurChapterId = 0
self.goLineSel = nil
self.bPlayEnterChapter = false
delChildren(self._mapNode.loopsvChapterList.transform:Find("Viewport/Content"))
delChildren(self._mapNode.loopsvStoryLineList.transform:Find("Viewport/Content"))
end
function StoryChapterCtrl:RefreshChapterGrid(grid, index)
local chapterData = self.tbAllChapter[index]
local trans = grid.transform:Find("AnimRoot")
local imgBg = trans:Find("imgBg"):GetComponent("Image")
if chapterData.Type == GameEnum.chapterType.Mainline then
local txtIndex = trans:Find("txtIndex"):GetComponent("TMP_Text")
NovaAPI.SetTMPText(txtIndex, chapterData.Index)
function StoryChapterCtrl:ParseData()
self.tbLine = {}
self.mapChapter = {}
self.tbUnlockAnimPlayedChapter = {}
self:LoadLocalData()
local foreach_Line = function(cfg)
table.insert(self.tbLine, {
nLineId = cfg.Id,
nSort = cfg.SortIndex,
tbChapterId = {},
bVisible = cfg.Visible,
bIsUnlock = false
})
end
local txtChapterIndex = trans:Find("imgTitle1/txtChapterIndex"):GetComponent("TMP_Text")
local goUnlock = trans:Find("goUnlock")
local goLock = trans:Find("goLock")
local txtTitle = goUnlock:Find("txtTitle"):GetComponent("TMP_Text")
local txtIndexTitle = goUnlock:Find("txtIndexTitle"):GetComponent("TMP_Text")
local aniTrans = trans:GetComponent("Animator")
local goFXChapterList = trans:Find("FXChapterList")
if self.bInitLoop and self.nCompletedChapter < 0 and self.nRecentChapterId <= 3 then
if index <= 5 then
if index == 1 then
aniTrans:Play("StoryChapter_chapter_in")
else
self:AddTimer(1, 0.1 * (index - 1), function()
aniTrans:Play("StoryChapter_chapter_in")
end, true, true, true)
local foreach_Chapter = function(cfg)
if PlayerData.Avg:IsStoryChapterShow(cfg.Id) == true then
local bUnlock, sTxt = PlayerData.Avg:IsStoryChapterUnlock(cfg.Id)
self.mapChapter[cfg.Id] = {
nHeadStoryId = 0,
bHeadRead = false,
tbPrevStoryId = cfg.PrevStories,
bIsUnlock = bUnlock,
sUnlockTips = sTxt
}
for i, v in ipairs(self.tbLine) do
if v.nLineId == cfg.StoryLineId and 0 >= table.indexof(v.tbChapterId, cfg.Id) then
table.insert(v.tbChapterId, cfg.Id)
break
end
end
else
aniTrans:Play("StoryChapter_chapter_defaut")
end
else
aniTrans:Play("StoryChapter_chapter_defaut")
end
NovaAPI.SetTMPText(txtChapterIndex, chapterData.Name)
self:SetPngSprite(imgBg, chapterData.ChapterIcon)
local isUnlock, lockText = PlayerData.Avg:IsStoryChapterUnlock(chapterData.Id)
goFXChapterList.gameObject:SetActive(false)
if self.nCompletedChapter + 1 == chapterData.Id and isUnlock then
goFXChapterList.gameObject:SetActive(true)
aniTrans:Play("StoryChapter_chapter_Unlock")
local foreach_Story = function(cfg)
local data = self.mapChapter[cfg.Chapter]
if data ~= nil then
local tb = cfg.ParentStoryId
if tb == nil or type(tb) == "table" and #tb == 0 then
local n = self.mapChapter[cfg.Chapter].nHeadStoryId
if n == 0 or 0 < n and n > cfg.Id then
self.mapChapter[cfg.Chapter].nHeadStoryId = cfg.Id
self.mapChapter[cfg.Chapter].bHeadRead = PlayerData.Avg:IsStoryReaded(cfg.Id)
if cfg.Chapter == 1 then
self.mapChapter[cfg.Chapter].bHeadRead = true
end
end
end
end
end
goUnlock.gameObject:SetActive(true)
goLock.gameObject:SetActive(not isUnlock or self.nCompletedChapter + 1 == chapterData.Id)
NovaAPI.SetTMPText(txtTitle, chapterData.Desc)
local RecentStoryId = PlayerData.Avg:GetRecentStoryId(chapterData.Id)
if RecentStoryId ~= nil and isUnlock then
local storyData = ConfigTable.GetData_Story(RecentStoryId)
NovaAPI.SetTMPText(txtIndexTitle, storyData.Index .. " " .. storyData.Title)
elseif not isUnlock then
NovaAPI.SetTMPText(txtIndexTitle, ConfigTable.GetUIText("Chapter_Not_Unlock"))
end
if not isUnlock then
local txtLock = goLock:Find("txtLock"):GetComponent("TMP_Text")
NovaAPI.SetTMPText(txtLock, lockText)
end
local btn = grid.transform:GetComponent("UIButton")
btn.onClick:RemoveAllListeners()
btn.onClick:AddListener(function()
if isUnlock then
goLock.gameObject:SetActive(false)
aniTrans:Play("StoryChapter_chapter_setout")
self:OnBtn_ClickChapterGrid(chapterData.Id, grid)
ForEachTableLine(DataTable.StoryLine, foreach_Line)
ForEachTableLine(DataTable.StoryChapter, foreach_Chapter)
ForEachTableLine(DataTable.Story, foreach_Story)
table.sort(self.tbLine, function(a, b)
if a.nSort == b.nSort then
return a.nLineId < b.nLineId
else
EventManager.Hit(EventId.OpenMessageBox, lockText)
return a.nSort < b.nSort
end
end)
end
function StoryChapterCtrl:RefreshChapterList(grid, index)
index = index + 1
local chapterData = self.tbAllChapter[index]
if chapterData == nil then
return
local tbChapterId_HasNoStory = {}
for k, v in pairs(self.mapChapter) do
if v.nHeadStoryId == 0 then
table.insert(tbChapterId_HasNoStory, k)
end
end
local chapterType = chapterData.Type
local gridTrans = grid.transform
local mainlineTrans = gridTrans:Find("btn")
local branchlineTrans = gridTrans:Find("Branch")
if chapterType == GameEnum.chapterType.Mainline then
gridTrans = mainlineTrans
elseif chapterType == GameEnum.chapterType.Branchline then
gridTrans = branchlineTrans
for i, v in ipairs(tbChapterId_HasNoStory) do
self.mapChapter[v] = nil
end
for i, v in ipairs(self.tbLine) do
for ii, vv in ipairs(tbChapterId_HasNoStory) do
local nIdx = table.indexof(v.tbChapterId, vv)
if 0 < nIdx then
table.remove(v.tbChapterId, nIdx)
end
end
end
local n = #self.tbLine
for i = n, 1, -1 do
local data = self.tbLine[i]
if 0 >= #data.tbChapterId then
table.remove(self.tbLine, i)
else
table.sort(data.tbChapterId)
local nChapterId = data.tbChapterId[1]
self.tbLine[i].bIsUnlock = self.mapChapter[nChapterId].bIsUnlock
if data.bVisible == false and data.bIsUnlock == false then
table.remove(self.tbLine, i)
end
end
end
mainlineTrans.gameObject:SetActive(chapterType == GameEnum.chapterType.Mainline)
branchlineTrans.gameObject:SetActive(chapterType == GameEnum.chapterType.Branchline)
self:RefreshChapterGrid(gridTrans, index)
local ChapterRedDot = gridTrans:Find("AnimRoot/ChapterRedDot")
local aniTrans = gridTrans:Find("AnimRoot"):GetComponent("Animator")
local nInstanceID = grid:GetInstanceID()
self.tbGridCtrl[nInstanceID] = {
Id = chapterData.Id,
aniTrans = aniTrans
}
RedDotManager.RegisterNode(RedDotDefine.Map_MainLine_Chapter, chapterData.Id, ChapterRedDot, nil, nil, true)
end
function StoryChapterCtrl:RefreshPersonality()
local tbPersonality, sTitle = PlayerData.Avg:CalcPersonality(1)
NovaAPI.SetPersonalityRing(self._mapNode.goPersonality, tbPersonality)
NovaAPI.SetTMPText(self._mapNode.txtName, sTitle)
function StoryChapterCtrl:SetMoWang()
local charId = AdjustMainRoleAvgCharId()
local spBody, spFace, v3OffsetPos, v3OffsetScale, spBlackBody = self:GetAvgPortrait(charId, "a", "002")
local trans = self._mapNode.rtActor2D
@@ -214,75 +361,370 @@ function StoryChapterCtrl:RefreshPersonality()
NovaAPI.SetImageSpriteAsset(imgFace, spFace)
NovaAPI.SetImageNativeSize(imgBody)
NovaAPI.SetImageNativeSize(imgFace)
local tbPersonality, sTitle = PlayerData.Avg:CalcPersonality(1)
NovaAPI.SetPersonalityRing(self._mapNode.goPersonality, tbPersonality)
NovaAPI.SetTMPText(self._mapNode.txtName, sTitle)
end
function StoryChapterCtrl:SwitchTog(bLeft)
self._mapNode.Select[1]:SetActive(bLeft)
self._mapNode.unSelect[1]:SetActive(not bLeft)
self._mapNode.Select[2]:SetActive(not bLeft)
self._mapNode.unSelect[2]:SetActive(bLeft)
end
function StoryChapterCtrl:PlayAnimOut()
self._mapNode.aniBg:Play("StoryChapter_bg_out")
self.aniSafeRoot:Play("StoryChapter_out")
self._mapNode.animActor2D:Play("Actor2D_PNG_right_out")
local time1 = NovaAPI.GetAnimClipLength(self._mapNode.aniBg, {
"StoryChapter_bg_out"
})
local time2 = NovaAPI.GetAnimClipLength(self.aniSafeRoot, {
"StoryChapter_out"
})
local time = math.min(time1, time2)
return time
end
function StoryChapterCtrl:OnBtn_ClickChapterGrid(index, grid)
EventManager.Hit(EventId.TemporaryBlockInput, 1)
for k, v in pairs(self.tbGridCtrl) do
if v.Id ~= index then
v.aniTrans:Play("StoryChapter_chapter_unsetout")
end
end
local time = self:PlayAnimOut()
self:AddTimer(1, time, function()
local chapterData = self.tbAllChapter[index]
if chapterData == nil then
return
end
if chapterData.Type == GameEnum.chapterType.Mainline then
EventManager.Hit(EventId.OpenPanel, PanelId.MainlineEx, index, PanelId.StoryChapter)
elseif chapterData.Type == GameEnum.chapterType.Branchline then
EventManager.Hit(EventId.OpenPanel, chapterData.StoryPanelId, index)
end
end, true, true, true)
end
function StoryChapterCtrl:OnBtn_ClickChangeInfo()
local time = self:PlayAnimOut()
self:AddTimer(1, time, function()
EventManager.Hit(EventId.OpenPanel, PanelId.ChangeGender)
end, true, true, true)
end
function StoryChapterCtrl:OnBtn_ClickStoryChapter()
self:SwitchTog(true)
self._mapNode.loopsvChapterList.gameObject:SetActive(true)
local count = PlayerData.Avg:GetChapterCount()
self._mapNode.loopsvChapterList:Init(count, self, self.RefreshChapterList)
end
function StoryChapterCtrl:OnBtn_ClickActivity()
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("Function_NotAvailable"))
end
function StoryChapterCtrl:OnEvent_UIBackConfirm()
if self.fromPanel ~= 0 and self.fromPanel ~= PanelId.StoryChapter then
if self.fromPanel == PanelId.MainlineEx then
EventManager.Hit(EventId.ClosePanel, PanelId.MainlineEx)
else
EventManager.Hit(EventId.OpenPanel, PanelId.LevelMenu)
end
end
EventManager.Hit(EventId.ClosePanel, PanelId.StoryChapter)
end
function StoryChapterCtrl:OnEvent_BackHome(nPanelId)
if self._panel._nPanelId ~= nPanelId then
function StoryChapterCtrl:CheckJustRead()
if self.nChapterId_From ~= 0 then
return
end
PanelManager.Home()
local nStoryId = PlayerData.Avg.nJustReadStoryId
if nStoryId <= 0 then
return
end
local cfg = ConfigTable.GetData("Story", nStoryId)
if cfg == nil then
return
end
local nChapterId = cfg.Chapter
if self.mapChapter[nChapterId].bIsUnlock ~= true then
return
end
local _cfg = ConfigTable.GetData("StoryChapter", nChapterId)
local nStoryLineId = _cfg.StoryLineId
local mapLine
for i, v in ipairs(self.tbLine) do
if v.nLineId == nStoryLineId then
mapLine = v
break
end
end
if mapLine == nil then
return
end
if mapLine.bIsUnlock ~= true then
return
end
local sAvgLuaName = cfg.StoryId
self.nChapterId_From = cfg.Chapter
self.nStoryLineId_From = _cfg.StoryLineId
self.bChapter_NeedPlayUnlockAnim = false
local nNextChapterId = self.nChapterId_From + 1
local data = self.mapChapter[nNextChapterId]
if type(data) == "table" and 0 < table.indexof(data.tbPrevStoryId, sAvgLuaName) and data.bIsUnlock == true and data.bHeadRead == false and self:UnlockAnimHasPlayed(nNextChapterId) == false then
self.bChapter_NeedPlayUnlockAnim = true
end
self:Check_StoryLine_NeedPlayUnlockAnim(nNextChapterId)
end
function StoryChapterCtrl:CheckLatest()
if self.nChapterId_From ~= 0 then
return
end
self.bChapter_NeedPlayUnlockAnim = false
local tb = {}
for k, v in pairs(self.mapChapter) do
table.insert(tb, k)
end
table.sort(tb)
local nNewUnlockChapterId = 0
local n = #tb
for i = n, 1, -1 do
local nChapterId = tb[i]
local data = self.mapChapter[nChapterId]
if data.bIsUnlock == true then
self.nChapterId_From = nChapterId
if data.bHeadRead == false and self:UnlockAnimHasPlayed(nChapterId) == false then
self.bChapter_NeedPlayUnlockAnim = true
self.nChapterId_From = tb[i - 1]
nNewUnlockChapterId = nChapterId
end
break
end
end
local cfg = ConfigTable.GetData("StoryChapter", self.nChapterId_From)
self.nStoryLineId_From = cfg.StoryLineId
self:Check_StoryLine_NeedPlayUnlockAnim(nNewUnlockChapterId)
end
function StoryChapterCtrl:Check_StoryLine_NeedPlayUnlockAnim(nNextChapterId)
self.nChapterId_To = 0
self.nStoryLineId_To = 0
self.bStoryLine_NeedPlayUnlockAnim = false
self.bStoryLine_NeedPlaySwitchAnim = false
if self.bChapter_NeedPlayUnlockAnim == true and 0 < nNextChapterId then
self.nChapterId_To = nNextChapterId
cfg = ConfigTable.GetData("StoryChapter", nNextChapterId)
if cfg ~= nil then
for i, v in ipairs(self.tbLine) do
if v.nLineId == cfg.StoryLineId then
if v.tbChapterId[1] == nNextChapterId then
self.nStoryLineId_To = v.nLineId
self.bStoryLine_NeedPlayUnlockAnim = true
break
end
if cfg.StoryLineId ~= self.nStoryLineId_From then
self.nStoryLineId_To = v.nLineId
self.bStoryLine_NeedPlaySwitchAnim = true
end
break
end
end
end
end
end
function StoryChapterCtrl:FallbackToDefault()
if self.nChapterId_From ~= 0 then
return
end
self.nStoryLineId_From = 1
self.nStoryLineId_To = 0
self.bStoryLine_NeedPlayUnlockAnim = false
self.bStoryLine_NeedPlaySwitchAnim = false
self.nChapterId_From = 1
self.nChapterId_To = 0
self.bChapter_NeedPlayUnlockAnim = false
end
function StoryChapterCtrl:LoadLocalData()
local sJson = LocalData.GetPlayerLocalData("UnlockAnimPlayedChapter")
local tb = decodeJson(sJson)
if type(tb) == "table" then
self.tbUnlockAnimPlayedChapter = tb
if table.indexof(self.tbUnlockAnimPlayedChapter, "1") <= 0 then
table.insert(self.tbUnlockAnimPlayedChapter, "1")
end
end
end
function StoryChapterCtrl:MarkAndSaveLocalData(nChapterId)
if type(self.tbUnlockAnimPlayedChapter) == "table" then
local sId = tostring(nChapterId)
if table.indexof(self.tbUnlockAnimPlayedChapter, sId) <= 0 then
table.insert(self.tbUnlockAnimPlayedChapter, sId)
local sJson = RapidJson.encode(self.tbUnlockAnimPlayedChapter)
LocalData.SetPlayerLocalData("UnlockAnimPlayedChapter", sJson)
end
end
end
function StoryChapterCtrl:UnlockAnimHasPlayed(nChapterId)
if type(self.tbUnlockAnimPlayedChapter) == "table" and table.indexof(self.tbUnlockAnimPlayedChapter, tostring(nChapterId)) > 0 then
return true
end
return false
end
function StoryChapterCtrl:GetChapters(nLineId)
for i, v in ipairs(self.tbLine) do
if v.nLineId == nLineId then
return v.tbChapterId
end
end
end
function StoryChapterCtrl:PlayRootAnim(bIn)
local sAnimName = ""
if bIn == true then
sAnimName = "StoryChapter_Bg_MoveIn"
else
sAnimName = "StoryChapter_Bg_MoveOut"
end
self._mapNode.animBg:Play(sAnimName)
if bIn == true then
sAnimName = "tc_top_back_01_t_in"
else
sAnimName = "tc_top_back_01_t_out"
end
self._mapNode.animTopBar:Play(sAnimName)
if bIn == true then
sAnimName = "StoryChapterList_MoveIn"
else
sAnimName = "StoryChapterList_MoveOut"
end
self._mapNode.animChapterList:Play(sAnimName)
if bIn == true then
sAnimName = "StoryChapterMW_MoveIn"
else
sAnimName = "StoryChapterMW_MoveOut"
end
self._mapNode.animMoWang:Play(sAnimName)
if bIn == true then
sAnimName = "StoryChapter_LineBtn_In"
else
sAnimName = "StoryChapter_LineBtn_Out"
end
self._mapNode.animBtnShowStoryLineList:Play(sAnimName)
end
function StoryChapterCtrl:SetBtn_IconTitle(nLineId, bForceVisible)
if bForceVisible == true then
self._mapNode.btnShowStoryLineList.transform.localScale = Vector3.one
else
local b = false
if #self.tbLine > 1 then
b = true
if self.bStoryLine_NeedPlayUnlockAnim == true and self.nStoryLineId_From == 1 and self.nStoryLineId_To == 2 then
b = false
end
end
self._mapNode.btnShowStoryLineList.transform.localScale = b == true and Vector3.one or Vector3.zero
end
local cfg = ConfigTable.GetData("StoryLine", nLineId)
local sRemovedMain = string.gsub(cfg.TitleMain, "\n", "")
local sRemovedSub = string.gsub(cfg.TitleSub, "\n", "")
sRemovedMain = string.gsub(sRemovedMain, "\r", "")
sRemovedSub = string.gsub(sRemovedSub, "\r", "")
NovaAPI.SetTMPText(self._mapNode.txtTitle_Show, sRemovedMain)
NovaAPI.SetTMPText(self._mapNode.txtTitle2_Show, sRemovedSub)
self:SetPngSprite(self._mapNode.imgStoryIcon, cfg.Icon)
end
function StoryChapterCtrl:OnGrid_StoryLine(go, bPlayUnlockAnim)
local nIndex = tonumber(go.name) + 1
local data = self.tbLine[nIndex]
local cfg = ConfigTable.GetData("StoryLine", data.nLineId)
local tr = go.transform:Find("scale_on_click")
local goSel = tr:Find("imgDb_Sel").gameObject
local trOff = tr:Find("imgDb_off")
local trOn = tr:Find("imgDb_on")
NovaAPI.SetTMPText(trOff:Find("tmpTabTitle_off"):GetComponent("TMP_Text"), "???")
NovaAPI.SetTMPText(trOn:Find("tmpTabTitle_on"):GetComponent("TMP_Text"), cfg.TitleMain)
NovaAPI.SetTMPText(trOn:Find("tmpTabTitle_on/tmpTabTitle2_on"):GetComponent("TMP_Text"), cfg.TitleSub)
self:SetPngSprite(trOn:Find("imgStoryIcon_on"):GetComponent("Image"), cfg.Icon)
goSel:SetActive(self.nCurLineId == data.nLineId)
if self.nCurLineId == data.nLineId then
self.goLineSel = goSel
end
local goRedDot = trOn:Find("tmpTabTitle_on/redDotTab").gameObject
RedDotManager.RegisterNode(RedDotDefine.Map_MainLine_StoryLine, data.nLineId, goRedDot)
if bPlayUnlockAnim == true and data.nLineId == self.nStoryLineId_To then
WwiseAudioMgr:PlaySound("ui_mainline_ago_unlock")
go:GetComponent("Animator"):Play("StoryChapter_Line_unlock")
elseif data.bIsUnlock == true and data.nLineId == self.nStoryLineId_To and self.nChapterId_To == data.tbChapterId[1] then
go:GetComponent("Animator"):Play("StoryChapter_Line_off")
else
go:GetComponent("Animator"):Play("StoryChapter_Line_on")
end
end
function StoryChapterCtrl:OnBtn_StoryLine(go)
WwiseAudioMgr:PlaySound("ui_mainline_ago_point")
local nIndex = tonumber(go.name) + 1
local data = self.tbLine[nIndex]
if self.nCurLineId == data.nLineId then
return
end
if IsNull(self.goLineSel) == false then
self.goLineSel:SetActive(false)
end
self.goLineSel = go.transform:Find("scale_on_click/imgDb_Sel").gameObject
self.goLineSel:SetActive(true)
self.nCurLineId = data.nLineId
self.tbChapter = self:GetChapters(self.nCurLineId)
self.bPlayChapterIn = true
self.nChapterIn = 0.333
self._mapNode.loopsvChapterList:Init(#self.tbChapter, self, self.OnGrid_Chapter, self.OnBtn_Chapter)
self:SetBtn_IconTitle(self.nCurLineId, true)
end
function StoryChapterCtrl:OnGrid_Chapter(go, bPlayUnlockAnim)
local nIndex = tonumber(go.name) + 1
local nChapterId = self.tbChapter[nIndex]
local data = self.mapChapter[nChapterId]
local cfg = ConfigTable.GetData("StoryChapter", nChapterId)
local goA = go.transform:Find("btn").gameObject
local goB = go.transform:Find("Branch").gameObject
goA:SetActive(cfg.Type == GameEnum.chapterType.Mainline)
goB:SetActive(cfg.Type == GameEnum.chapterType.Branchline)
local tr = goA.transform:Find("AnimRoot")
if cfg.Type == GameEnum.chapterType.Branchline then
tr = goB.transform:Find("AnimRoot")
end
self:SetPngSprite(tr:Find("imgBg"):GetComponent("Image"), cfg.ChapterIcon)
NovaAPI.SetTMPText(tr:Find("imgTitle1/txtChapterIndex"):GetComponent("TMP_Text"), cfg.Name)
NovaAPI.SetTMPText(tr:Find("txtIndex"):GetComponent("TMP_Text"), cfg.Index)
NovaAPI.SetTMPText(tr:Find("goUnlock/txtTitle"):GetComponent("TMP_Text"), cfg.Desc)
local sTxt = ConfigTable.GetUIText("Chapter_Not_Unlock")
if data.bIsUnlock == true then
local nStoryId = PlayerData.Avg:GetRecentStoryId(nChapterId)
cfg = ConfigTable.GetData("Story", nStoryId)
sTxt = cfg.Index .. " " .. cfg.Title
end
NovaAPI.SetTMPText(tr:Find("goUnlock/txtIndexTitle"):GetComponent("TMP_Text"), sTxt)
NovaAPI.SetTMPText(tr:Find("goLock/txtLock"):GetComponent("TMP_Text"), data.sUnlockTips or "")
local goRedDot = tr:Find("ChapterRedDot").gameObject
RedDotManager.RegisterNode(RedDotDefine.Map_MainLine_Chapter, {
self.nCurLineId,
nChapterId
}, goRedDot)
local bIsOn = data.bIsUnlock == true and nChapterId ~= self.nChapterId_To
tr:Find("goLock").gameObject:SetActive(bIsOn == false)
local anim = tr:GetComponent("Animator")
if self.bPlayChapterIn == true then
if (nIndex - 1) * 0.1 + 0.333 > self.nChapterIn then
self.nChapterIn = (nIndex - 1) * 0.1 + 0.333
end
anim:Play("StoryChapter_CH_in2")
self._mapNode.loopsvChapterList:PlayAnim(anim, "StoryChapter_CH_in", (nIndex - 1) * 0.1)
elseif bPlayUnlockAnim == true and nChapterId == self.nChapterId_To then
self:MarkAndSaveLocalData(nChapterId)
WwiseAudioMgr:PlaySound("ui_mainline_ago_unlock_2")
anim:Play("StoryChapter_CH_unlock")
elseif self.bPlayEnterChapter == true then
if nChapterId == self.nCurChapterId then
anim:Play("StoryChapter_CH_setout")
else
anim:Play("StoryChapter_CH_unsetout")
end
else
anim:Play("StoryChapter_CH_refresh")
end
end
function StoryChapterCtrl:OnBtn_Chapter(go)
WwiseAudioMgr:PlaySound("ui_mainline_chapter_click")
local nIndex = tonumber(go.name) + 1
local nChapterId = self.tbChapter[nIndex]
local cfg = ConfigTable.GetData("StoryChapter", nChapterId)
if self.mapChapter[nChapterId].bIsUnlock == false then
EventManager.Hit(EventId.OpenMessageBox, self.mapChapter[nChapterId].sUnlockTips)
return
end
EventManager.Hit(EventId.TemporaryBlockInput, 1)
self.nCurChapterId = nChapterId
local Play_ChapterAnim = function()
self.bPlayEnterChapter = true
self._mapNode.loopsvChapterList:Init(#self.tbChapter, self, self.OnGrid_Chapter, self.OnBtn_Chapter, true)
self._mapNode.animMoWang:Play("StoryChapterMW_MoveOut")
end
local OpenPanel = function()
local nPanelId = cfg.StoryPanelId
if nPanelId == 0 then
nPanelId = PanelId.MainlineEx
end
EventManager.Hit(EventId.OpenPanel, nPanelId, self.nCurChapterId)
end
if type(self._panel._tbParam) ~= "table" then
self._panel._tbParam = {}
end
self._panel._tbParam[1] = 0
self._panel._tbParam[2] = self.nCurChapterId
local seq = DOTween.Sequence()
seq:AppendInterval(0.1)
seq:AppendCallback(Play_ChapterAnim)
seq:AppendInterval(0.3)
seq:AppendCallback(OpenPanel)
seq:SetUpdate(true)
end
function StoryChapterCtrl:OnBtn_ShowStoryLineList()
WwiseAudioMgr:PlaySound("ui_mainline_ago_point")
self._mapNode.animBtnShowStoryLineList:Play("StoryChapter_LineBtn_Out")
self._mapNode.animChapterList:Play("StoryChapterList_MoveRight")
self._mapNode.animMoWang:Play("StoryChapterMW_MoveOut")
WwiseAudioMgr:PlaySound("ui_mainline_ago")
end
function StoryChapterCtrl:OnBtn_HideStoryLineList()
WwiseAudioMgr:PlaySound("ui_mainline_ago_out")
self.bPlayChapterIn = false
self.nChapterIn = 0
self._mapNode.animBtnShowStoryLineList:Play("StoryChapter_LineBtn_In")
self._mapNode.animChapterList:Play("StoryChapterList_MoveLeft")
self._mapNode.animMoWang:Play("StoryChapterMW_MoveIn")
end
function StoryChapterCtrl:OnBtn_ChangeInfo()
EventManager.Hit(EventId.TemporaryBlockInput, 0.5)
EventManager.Hit(EventId.OpenPanel, PanelId.ChangeGender)
end
function StoryChapterCtrl:OnEvent_UIBackConfirm(nPanelId)
if nPanelId == PanelId.StoryChapter then
EventManager.Hit(EventId.TemporaryBlockInput, 0.5)
EventManager.Hit(EventId.ClosePanel, nPanelId)
end
end
function StoryChapterCtrl:OnEvent_BackHome(nPanelId)
if nPanelId == PanelId.StoryChapter then
EventManager.Hit(EventId.TemporaryBlockInput, 0.5)
PanelManager.Home()
end
end
return StoryChapterCtrl