ro-webgl/Assets/Lua/UI/UIPlayStory/UIPlayStoryCtr.lua

85 lines
1.7 KiB
Lua

local UIPlayStoryCtr = class("UIPlayStoryCtr", require("UICtrBase"))
function UIPlayStoryCtr:Init(view)
self.view = view
end
function UIPlayStoryCtr:SetData(data)
self.asyncIdx = 0
if data == nil then return end
self.data = data
local storyData = self.data
local storyId = storyData.StoryId
local storyIntro = storyData.StoryIntro or {}
local storyPerforms = ManagerContainer.CfgMgr:GetStoryPerformDataById(storyId)
local cfgs = {}
for i = 1, #storyIntro do
cfgs[i] = cfgs[i] or {}
for j=1, #storyPerforms do
if storyPerforms[j].Type == i then
table.insert(cfgs[i], storyPerforms[j])
end
end
end
local idx = 1
self.selectIdx = idx
self.listIdx = idx - 1
self.cfgs = cfgs
self.cfgLength = #cfgs
self.storyId = storyId
end
function UIPlayStoryCtr:GetStoryId()
return self.storyId
end
function UIPlayStoryCtr:GetListIdx()
return self.listIdx
end
function UIPlayStoryCtr:SetListIdx(listIdx)
if self.listIdx == listIdx then return false end
self.listIdx = listIdx
self.selectIdx = self:GetSelectIdxByListIdx(listIdx)
return true
end
function UIPlayStoryCtr:GetSelectIdxByListIdx(listIdx)
if listIdx >= 0 then
return listIdx % self.cfgLength + 1
else
return self.cfgLength - Mathf.Abs(listIdx + 1) % self.cfgLength
end
end
function UIPlayStoryCtr:GetSelectIdx()
return self.selectIdx
end
function UIPlayStoryCtr:GetCfgByIdx(idx)
return self.cfgs[idx]
end
function UIPlayStoryCtr:GetCfgLength()
return self.cfgLength
end
function UIPlayStoryCtr:GetAsyncIdx()
self.asyncIdx = self.asyncIdx + 1
return self.asyncIdx
end
function UIPlayStoryCtr:GetData()
return self.data
end
function UIPlayStoryCtr:OnDispose()
self.data = nil
self.view = nil
end
return UIPlayStoryCtr