miduo_client/Assets/ManagedResources/~Lua/Modules/Story/StoryDialoguePanel.lua

335 lines
11 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
local bgName
function StoryDialoguePanel:InitComponent()
this.spLoader = SpriteLoader.New()
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")
this.LiveBg=nil
end
--绑定事件(用于子类重写)
function StoryDialoguePanel:BindEvent()
Util.AddClick(this.btnNext, function ()
self:GoNext(optionID)
end)
Util.AddClick(this.btnJump, function ()
if jumpId == 0 then
self:ClosePanel()
if static_callBack then
static_callBack()
static_callBack = nil
end
else
self:GoNext(jumpId)
end
end)
end
function StoryDialoguePanel:GoNext(optionID)
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,static_callBack)
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)
local showValues = GetLanguageStrById(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)
-- 新手隐藏阶段必须隐藏,其他时候随着面板变化
if GuideManager.IsInMainGuide() then
if options[2] then
this.jumpRoot:SetActive(true)
else
this.jumpRoot:SetActive(false)
end
else
this.jumpRoot:SetActive(isRightType)
end
-- 设置对话背景图
bgName = chapterEventPointData[eventId].DialogueBg
if not bgName or bgName == "" then
this.Bg.gameObject:SetActive(false)
else
this.Bg.gameObject:SetActive(true)
this.Bg.sprite = this.spLoader:LoadSprite(bgName)
if this.Bg.sprite==nil then
if this.LiveBg then
GameObject.Destroy(this.LiveBg.gameObject)
end
this.LiveBg=poolManager:LoadLive(bgName, this.Bg.transform, Vector3.New(1.5,1.5,1.5), Vector3.zero)
else
if this.LiveBg then
this.LiveBg:SetActive(false)
end
end
end
StoryDialoguePanel:SetScenceEffect(eventId)
-- 跳转值
optionID = options[1]
jumpId = options[2] or 0
-- jumpId = chapterEventPointData[eventId].NextOptPanelId
-- if jumpId and jumpId ~= 0 then
-- -- jumpId = chapterEventPointData[jumpId].Option[1]
-- jumpId = options[2]
-- 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, Language[11248], NameManager.roleName)
contexts = string.gsub(contexts, "{ta}", NameManager.roleSex == ROLE_SEX.BOY and "" or "")
-- 配音资源名
local voice = chapterEventPointData[eventId].VoiceRes
if voice and IS_PLAY_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]
if NameManager.roleName == tostring(PlayerManager.uid) then
this.RoleName.text =string.gsub(GetLanguageStrById(data.Desc), Language[11252], "")
else
this.RoleName.text =string.gsub(GetLanguageStrById(data.Desc), Language[11252], NameManager.roleName)
end
-- 初始化特效
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()
lastLive2DId = 0
-- 界面关闭,配音音效关闭
SoundManager.StopSoundByChannel(10)
end
--界面销毁时调用(用于子类重写)
function StoryDialoguePanel:OnDestroy()
this.spLoader:Destroy()
if this.LiveBg then
poolManager:UnLoadLive(bgName,this.LiveBg)
this.LiveBg=nil
end
end
return StoryDialoguePanel