PGRData/Script/matrix/xui/xuidraw/XUiDrawNew.lua

129 lines
4.7 KiB
Lua
Raw Normal View History

local XUiDrawNew = XLuaUiManager.Register(XLuaUi,"UiDrawNew")
local MAX_DRAW_COUNT = 10
local COMPlETE_CUE_ID = CS.XGame.ClientConfig:GetInt("DrawCompleteCueId")
local DRAW_MUSIC_VOLUME_PERCENT = CS.XGame.ClientConfig:GetInt("DrawMusicVolumePercent")
function XUiDrawNew:OnStart(drawInfo,rewardList)
self.DrawInfo = drawInfo
self.RewardList = rewardList
self:InitSceneObject()
self:RegisterButton()
self:RefreshItem()
self.OriginMusicVolume = XSoundManager.GetVolumeByType(XSoundManager.SoundType.BGM)
end
function XUiDrawNew:OnEnable()
XSoundManager.SetVolumeByType(self.OriginMusicVolume * (DRAW_MUSIC_VOLUME_PERCENT / 100), XSoundManager.SoundType.BGM)
end
function XUiDrawNew:OnDisable()
XSoundManager.SetVolumeByType(self.OriginMusicVolume, XSoundManager.SoundType.BGM)
end
function XUiDrawNew:RegisterButton()
self.BtnSkip.CallBack = function()
self.IsSkip = true
XLuaUiManager.Remove("UiDrawNew")
XLuaUiManager.Open("UiDrawResult",self.DrawInfo,self.RewardList,function()
end)
end
end
function XUiDrawNew:InitSceneObject()
---@type UnityEngine.Transform
local root = self.UiModelGo.transform
---@type UnityEngine.Playables.PlayableDirector
self.DrawEnableAnimationSingle = root:FindTransform("DrawEnable2"):GetComponent(typeof(CS.UnityEngine.Playables.PlayableDirector))
---@type UnityEngine.Playables.PlayableDirector
self.DrawEnableAnimationMulti = root:FindTransform("DrawEnable"):GetComponent(typeof(CS.UnityEngine.Playables.PlayableDirector))
self.SliderTips = root:FindTransform("SlideTips")
---@type XTimelineSlider
self.TimelineSlider = root:FindTransform("Slider"):GetComponent(typeof(CS.XTimelineSlider))
self.TimelineSlider.CompleteAction = function(slider)
if COMPlETE_CUE_ID and COMPlETE_CUE_ID ~= 0 then
XSoundManager.PlaySoundByType(COMPlETE_CUE_ID,XSoundManager.SoundType.Sound)
end
if #self.RewardList > 1 then
self.DrawEnableAnimationMulti.gameObject:PlayTimelineAnimation(function()
self:OnDrawEnd()
end)
else
self.DrawEnableAnimationSingle.gameObject:PlayTimelineAnimation(function()
self:OnDrawEnd()
end)
end
end
self.TimelineSlider.PointerUpAction = function()
if self.SliderTips then
self.SliderTips.gameObject:SetActiveEx(true)
end
end
self.TimelineSlider.PointerDownAction = function()
if self.SliderTips then
self.SliderTips.gameObject:SetActiveEx(false)
end
end
self.ItemParent = {}
for i = 1, MAX_DRAW_COUNT do
local obj = self.UiModelGo.transform:FindTransform("item" .. i)
if obj then
table.insert(self.ItemParent,obj)
end
end
self.JiGuangRoot = self.UiModelGo.transform:FindTransform("Jiguang")
end
function XUiDrawNew:OnDrawEnd()
if self.IsSkip then
return
end
XLuaUiManager.Remove("UiDrawNew")
XLuaUiManager.Open("UiDrawShow",self.DrawInfo,self.RewardList,function()
XLuaUiManager.Open("UiDrawResult",self.DrawInfo,self.RewardList,function()
end)
end,nil)
end
function XUiDrawNew:RefreshItem()
local maxQuality = -1
for i = 1,#self.RewardList do
local item = self.RewardList[i]
---@type UnityEngine.Transform
local parent = self.ItemParent[i]
local quality = self:GetQuality(i)
local effectPath = CS.XGame.ClientConfig:GetString("DrawRingQualityEffect"..quality)
if maxQuality < quality then
maxQuality = quality
end
parent:LoadPrefab(effectPath)
end
if maxQuality >= 0 and self.JiGuangRoot then
local effectPath = CS.XGame.ClientConfig:GetString("DrawQualityEffect"..maxQuality)
self.JiGuangRoot:LoadPrefab(effectPath)
end
end
function XUiDrawNew:GetQuality(showIndex)
local reward = self.RewardList[showIndex]
local id = reward.Id and reward.Id > 0 and reward.Id or reward.TemplateId
if reward.ConvertFrom > 0 then
id = reward.ConvertFrom
end
local quality
local templateIdData = XGoodsCommonManager.GetGoodsShowParamsByTemplateId(id)
local Type = XTypeManager.GetTypeById(id)
if Type == XArrangeConfigs.Types.Wafer then
quality = templateIdData.Star
elseif Type == XArrangeConfigs.Types.Weapon then
quality = templateIdData.Star
elseif Type == XArrangeConfigs.Types.Character then
quality = XCharacterConfigs.GetCharMinQuality(id)
else
quality = XTypeManager.GetQualityById(id)
end
local showTable = XDataCenter.DrawManager.GetDrawShow(Type)
return showTable.DrawEffectGroupId[quality]
end
return XUiDrawNew