300 lines
9.2 KiB
Lua
300 lines
9.2 KiB
Lua
|
require("Base/BasePanel")
|
|||
|
StoryDialoguePanel = Inherit(BasePanel)
|
|||
|
local this = StoryDialoguePanel
|
|||
|
local chapterEventPointData = ConfigManager.GetConfig(ConfigName.ChapterEventPointConfig)
|
|||
|
local OpConfig = ConfigManager.GetConfig(ConfigName.ChapterOptionConfig)
|
|||
|
local artResConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
|
|||
|
local lastLive2DId = 0
|
|||
|
local jumpId = 0
|
|||
|
local optionID = 0
|
|||
|
--是否这个面板是第一次打开
|
|||
|
local isFirstOpen = false
|
|||
|
-- 记录场景特效
|
|||
|
local preEffPar = 0
|
|||
|
local lastSceneEffect
|
|||
|
-- 设置场景特效
|
|||
|
local orginLayer
|
|||
|
local static_callBack
|
|||
|
|
|||
|
function StoryDialoguePanel:InitComponent()
|
|||
|
orginLayer = 10
|
|||
|
-- 背景图
|
|||
|
this.Bg = Util.GetGameObject(self.gameObject, "bg"):GetComponent("Image")
|
|||
|
-- 右切入
|
|||
|
this.right2dRoot = Util.GetGameObject(self.gameObject, "rightLive2d")
|
|||
|
-- 左切入
|
|||
|
this.left2dRoot = Util.GetGameObject(self.gameObject, "leftLive2d")
|
|||
|
|
|||
|
-- 点击按钮
|
|||
|
this.btnNext = Util.GetGameObject(self.gameObject, "goOnButton/Click")
|
|||
|
this.btnRoot = Util.GetGameObject(self.gameObject, "goOnButton")
|
|||
|
|
|||
|
--对话文字内容
|
|||
|
this.RoleName = Util.GetGameObject(self.gameObject, "TextMask/Name"):GetComponent("Text")
|
|||
|
this.NameFrame = Util.GetGameObject(self.gameObject, "TextMask/Image")
|
|||
|
this.Context = Util.GetGameObject(self.gameObject, "TextMask/context")
|
|||
|
|
|||
|
--跳过按钮
|
|||
|
this.btnJump = Util.GetGameObject(self.gameObject, "btnContinue/btnGo")
|
|||
|
this.jumpRoot = Util.GetGameObject(self.gameObject, "btnContinue")
|
|||
|
-- 黑幕遮罩
|
|||
|
this.mask = Util.GetGameObject(self.gameObject, "Mask")
|
|||
|
-- 中间乱入的图片
|
|||
|
this.showImg = Util.GetGameObject(self.gameObject, "showImg")
|
|||
|
|
|||
|
-- 特效的节点
|
|||
|
this.effectRoot = Util.GetGameObject(self.gameObject, "effectRoot")
|
|||
|
-- 场景特效
|
|||
|
this.sceneEffect = Util.GetGameObject(self.gameObject, "scenceEffect")
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
--绑定事件(用于子类重写)
|
|||
|
function StoryDialoguePanel:BindEvent()
|
|||
|
Util.AddClick(this.btnNext, function ()
|
|||
|
local isEnd = OpConfig[optionID].JumpType == 4
|
|||
|
if isEnd and static_callBack then
|
|||
|
static_callBack()
|
|||
|
static_callBack = nil
|
|||
|
end
|
|||
|
|
|||
|
-- 点击下一步关闭配音音效关闭
|
|||
|
SoundManager.StopSoundByChannel(10)
|
|||
|
|
|||
|
StoryManager.StoryJumpType(optionID, self)
|
|||
|
end)
|
|||
|
|
|||
|
Util.AddClick(this.btnJump, function ()
|
|||
|
if jumpId == 0 then
|
|||
|
self:ClosePanel()
|
|||
|
else
|
|||
|
StoryManager.StoryJumpType(jumpId, self)
|
|||
|
end
|
|||
|
end)
|
|||
|
end
|
|||
|
|
|||
|
--添加事件监听(用于子类重写)
|
|||
|
function StoryDialoguePanel:AddListener()
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
--移除事件监听(用于子类重写)
|
|||
|
function StoryDialoguePanel:RemoveListener()
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--界面打开时调用(用于子类重写)
|
|||
|
function StoryDialoguePanel:OnOpen(...)
|
|||
|
local data = {...}
|
|||
|
if data then
|
|||
|
local eventId = data[1]
|
|||
|
Log("剧情对话事件ID" .. eventId)
|
|||
|
--- 新手第一次对话
|
|||
|
if eventId == 138018 then
|
|||
|
SoundManager.PlayMusic(SoundConfig.BGM_Adventure)
|
|||
|
end
|
|||
|
|
|||
|
--- 新手战斗结束之后的第一次对话
|
|||
|
if eventId == 100001 then
|
|||
|
SoundManager.PlayMusic(SoundConfig.BGM_Story_1)
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
isFirstOpen = data[2]
|
|||
|
this.RefreshPanel(eventId, isFirstOpen)
|
|||
|
|
|||
|
if data[3] then
|
|||
|
static_callBack = data[3]
|
|||
|
end
|
|||
|
|
|||
|
else
|
|||
|
Log("传入的参数为空!!")
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
-- 打开面板的时候刷新一次数据
|
|||
|
function this.RefreshPanel(eventId, isFirstOpen)
|
|||
|
local showType = chapterEventPointData[eventId].ShowType
|
|||
|
local isRightType = showType == 11
|
|||
|
this.RoleName.gameObject:SetActive(isRightType)
|
|||
|
this.btnNext:SetActive(isRightType)
|
|||
|
|
|||
|
-- 新手隐藏阶段必须隐藏,其他时候随着面板变化
|
|||
|
if GuideManager.IsInMainGuide() then
|
|||
|
this.jumpRoot:SetActive(false)
|
|||
|
else
|
|||
|
this.jumpRoot:SetActive(isRightType)
|
|||
|
end
|
|||
|
|
|||
|
local showValues = chapterEventPointData[eventId].ShowValues
|
|||
|
local options = chapterEventPointData[eventId].Option
|
|||
|
local dir = chapterEventPointData[eventId].ShowDir
|
|||
|
local live2dRoot = dir == 2 and this.left2dRoot or this.right2dRoot
|
|||
|
|
|||
|
local showMask = chapterEventPointData[eventId].Isdark == 1
|
|||
|
this.mask:SetActive(showMask)
|
|||
|
|
|||
|
-- 设置对话背景图
|
|||
|
this.Bg.sprite = Util.LoadSprite(chapterEventPointData[eventId].DialogueBg)
|
|||
|
StoryDialoguePanel:SetScenceEffect(eventId)
|
|||
|
|
|||
|
-- 跳转值
|
|||
|
optionID = options[1]
|
|||
|
jumpId = chapterEventPointData[eventId].NextOptPanelId
|
|||
|
if jumpId and jumpId ~= 0 then
|
|||
|
jumpId = chapterEventPointData[jumpId].Option[1]
|
|||
|
else
|
|||
|
jumpId = 0
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
-- 角色信息
|
|||
|
local contents = string.split(showValues, "|")
|
|||
|
local resId = tonumber(contents[1])
|
|||
|
|
|||
|
-- 文字内容
|
|||
|
local contexts =(contents[2])
|
|||
|
|
|||
|
--contexts = string.gsub(contexts, "【此处为玩家名】", PlayerManager.nickName)
|
|||
|
contexts = string.gsub(contexts, "【此处为玩家名】", NameManager.roleName)
|
|||
|
|
|||
|
|
|||
|
-- 配音资源名
|
|||
|
local voice = chapterEventPointData[eventId].VoiceRes
|
|||
|
if voice then
|
|||
|
-- 使用相同通道播放,避免跳过剧情导致音效重复
|
|||
|
SoundManager.PlaySound(voice, nil, nil, 10)
|
|||
|
end
|
|||
|
|
|||
|
--当前不是选择界面
|
|||
|
if isRightType then
|
|||
|
ShowText(this.Context, contexts, 3)
|
|||
|
PlayUIAnim(this.gameObject)
|
|||
|
this.btnRoot:SetActive(true)
|
|||
|
else
|
|||
|
this.btnRoot:SetActive(false)
|
|||
|
this.NameFrame:SetActive(false)
|
|||
|
this.ReSetLive2d()
|
|||
|
this.Context:GetComponent("Text").text = contexts
|
|||
|
end
|
|||
|
|
|||
|
if showMask then this.ReSetLive2d() this.RoleName.text = "" end
|
|||
|
if not isRightType then return end
|
|||
|
|
|||
|
-- 又配置数据使用新的加载方法,不然使用原有的
|
|||
|
local setId = chapterEventPointData[eventId].DialogueViewId
|
|||
|
-- Log(string.format("配置资源ID" .. setId))
|
|||
|
|
|||
|
-- 显示立绘
|
|||
|
if resId > 0 and resId ~= 999 then
|
|||
|
local data = artResConfig[resId]
|
|||
|
this.RoleName.text =string.gsub(data.Desc, "玩家", NameManager.roleName)
|
|||
|
|
|||
|
-- 初始化特效
|
|||
|
StoryManager.InitEffect(this.effectRoot)
|
|||
|
-- 如果面板是第一次打开
|
|||
|
if isFirstOpen then
|
|||
|
lastLive2DId = 0
|
|||
|
end
|
|||
|
|
|||
|
local roleSex = NameManager.roleSex
|
|||
|
local resPath
|
|||
|
if resId == 8001 then --- 主角专用字段
|
|||
|
resPath = roleSex == ROLE_SEX.BOY and StoryManager.boyRes or StoryManager.bitchRes
|
|||
|
else
|
|||
|
resPath = artResConfig[resId].Name
|
|||
|
end
|
|||
|
|
|||
|
if lastLive2DId ~= resId then
|
|||
|
-- 需要加载立绘的时候清除所有
|
|||
|
this.ReSetLive2d()
|
|||
|
Log("立绘配置ID" .. setId)
|
|||
|
|
|||
|
|
|||
|
if setId and setId ~= 0 then
|
|||
|
StoryManager.InitLive2dState(setId, resPath, live2dRoot, this.effectRoot, true, this)
|
|||
|
else
|
|||
|
this.LoadLive2D(data, resPath, live2dRoot)
|
|||
|
end
|
|||
|
else
|
|||
|
if setId then
|
|||
|
StoryManager.InitLive2dState(setId, resPath, live2dRoot, this.effectRoot, false, this)
|
|||
|
end
|
|||
|
end
|
|||
|
this.NameFrame:SetActive(true)
|
|||
|
this.showImg:SetActive(false)
|
|||
|
elseif resId == 999 then -- 显示图片
|
|||
|
StoryManager.InitEffect(this.effectRoot)
|
|||
|
this.showImg:SetActive(true)
|
|||
|
this.ReSetLive2d()
|
|||
|
this.RoleName.text = ""
|
|||
|
this.NameFrame:SetActive(false)
|
|||
|
if setId then
|
|||
|
StoryManager.InitImgState(setId, this.showImg, this.effectRoot, this)
|
|||
|
end
|
|||
|
|
|||
|
else
|
|||
|
StoryManager.InitEffect(this.effectRoot)
|
|||
|
this.showImg:SetActive(false)
|
|||
|
this.ReSetLive2d()
|
|||
|
this.RoleName.text = ""
|
|||
|
this.NameFrame:SetActive(false)
|
|||
|
end
|
|||
|
lastLive2DId = resId
|
|||
|
end
|
|||
|
|
|||
|
-- 动态加载立绘
|
|||
|
function this.LoadLive2D(data, resPath, live2dRoot)
|
|||
|
PlayUIAnim(live2dRoot)
|
|||
|
poolManager:LoadLive(resPath, live2dRoot.transform, Vector3.one * data.Scale, Vector3.New(data.Position[1], data.Position[2], 0))
|
|||
|
end
|
|||
|
|
|||
|
-- 清除立绘
|
|||
|
function this.ReSetLive2d()
|
|||
|
Util.ClearChild(this.left2dRoot.transform)
|
|||
|
Util.ClearChild(this.right2dRoot.transform)
|
|||
|
end
|
|||
|
|
|||
|
function StoryDialoguePanel:SetScenceEffect(eventId)
|
|||
|
|
|||
|
local effectStr = chapterEventPointData[eventId].scenceEffec
|
|||
|
if not effectStr then ClearChild(this.scenceEffect) return end
|
|||
|
local str = string.split(effectStr, "#")
|
|||
|
local isUse = tonumber(str[1]) == 1
|
|||
|
if not isUse then ClearChild(this.sceneEffect) preEffPar = "" return end
|
|||
|
if effectStr ~= preEffPar then ClearChild(this.sceneEffect) end
|
|||
|
local resPath = str[2]
|
|||
|
Log("场景特效资源名 " .. resPath)
|
|||
|
|
|||
|
-- 下次需要打开同样的特效,不用重新加载
|
|||
|
if effectStr ~= preEffPar then
|
|||
|
local go = StoryManager.LoadEffect(this.sceneEffect, resPath)
|
|||
|
lastSceneEffect = go
|
|||
|
Util.AddParticleSortLayer(this.sceneEffect, self.sortingOrder + orginLayer)
|
|||
|
orginLayer = self.sortingOrder
|
|||
|
end
|
|||
|
|
|||
|
preEffPar = effectStr
|
|||
|
end
|
|||
|
|
|||
|
--界面关闭时调用(用于子类重写)
|
|||
|
function StoryDialoguePanel:OnClose()
|
|||
|
-- 界面关闭,配音音效关闭
|
|||
|
SoundManager.StopSoundByChannel(10)
|
|||
|
end
|
|||
|
|
|||
|
--界面销毁时调用(用于子类重写)
|
|||
|
function StoryDialoguePanel:OnDestroy()
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
return StoryDialoguePanel
|