148 lines
3.6 KiB
Lua
148 lines
3.6 KiB
Lua
local UIStoryPreviewView = require("UIStoryPreview/UIStoryPreviewView_Generate")
|
|
|
|
local stroycfg = {}
|
|
|
|
|
|
--region 生命周期
|
|
function UIStoryPreviewView:OnAwake(data)
|
|
self.controller = require("UIStoryPreview/UIStoryPreviewCtr"):new()
|
|
self.controller:Init(self)
|
|
self.controller:SetData(data)
|
|
end
|
|
|
|
function UIStoryPreviewView:AddEventListener()
|
|
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
|
|
end
|
|
|
|
function UIStoryPreviewView:FillContent(data, uiBase)
|
|
self.uiBase = uiBase
|
|
local gameObject = self.uiBase:GetRoot()
|
|
if gameObject ~= nil then
|
|
self.gameObject = gameObject
|
|
self.transform = gameObject.transform
|
|
end
|
|
self:InitGenerate(self.transform, data)
|
|
|
|
self:Init()
|
|
end
|
|
|
|
function UIStoryPreviewView:Init()
|
|
self:Init_StoryItem()
|
|
end
|
|
|
|
function UIStoryPreviewView:RemoveEventListener()
|
|
ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
|
|
end
|
|
|
|
function UIStoryPreviewView:AddUIEventListener()
|
|
self.uiBase:AddButtonEventListener(self.btnBack.button, self, self.OnBtn_Back)
|
|
end
|
|
|
|
function UIStoryPreviewView:OnHide()
|
|
|
|
end
|
|
|
|
function UIStoryPreviewView:OnShow(data)
|
|
self.controller:SetData(data)
|
|
end
|
|
|
|
function UIStoryPreviewView:OnClose()
|
|
end
|
|
|
|
function UIStoryPreviewView:OnDispose()
|
|
self.controller:OnDispose()
|
|
self.sv_story.loopGridView:Dispose()
|
|
end
|
|
|
|
--region 生命周期
|
|
|
|
|
|
|
|
|
|
|
|
--关闭页面按钮
|
|
function UIStoryPreviewView:OnBtn_Back()
|
|
self:UIClose();
|
|
end
|
|
|
|
--sv story
|
|
function UIStoryPreviewView:Init_StoryItem()
|
|
local loopview = self.sv_story.loopGridView
|
|
|
|
loopview:InitGridView(0,
|
|
function(loopview, index, row, col)
|
|
return self:Gen_StoryItem(loopview, index, row, col)
|
|
end, nil)
|
|
|
|
local stroycfg1 = ManagerContainer.CfgMgr:GetStoryCfgV2()
|
|
|
|
local size = 1
|
|
for k, v in pairs(stroycfg1) do
|
|
stroycfg[size] = v
|
|
size = size + 1
|
|
end
|
|
table.sort(stroycfg, function(a, b) return a.Id < b.Id end)
|
|
|
|
local curMapId, curLevelId = ManagerContainer.LuaBattleMgr:GetCurMapAndLevel()
|
|
self.maplevel = curMapId * 10000 + curLevelId
|
|
--self.maplevel = 20000
|
|
LogWarning("tzy_" .. "cur_mapid " .. curMapId .. " _cur_levelid " .. curLevelId .. " _mapLevel " .. self.maplevel)
|
|
|
|
|
|
|
|
loopview:SetListItemCount(size - 1)
|
|
end
|
|
|
|
function UIStoryPreviewView:Gen_StoryItem(loopview, index, row, col)
|
|
if index < 0 then return nil end
|
|
|
|
local item = loopview:NewListViewItem("UIStoryPreviewItem")
|
|
local itemlua = CommonUtil.BindGridViewItem2Lua(self, "UIStoryPreviewItem", item.gameObject)
|
|
local go = item.gameObject
|
|
|
|
local info = stroycfg[index + 1]
|
|
|
|
|
|
itemlua.text_title1.text.text = "第" .. index + 1 .. "章"
|
|
local title = info.StoryTitle
|
|
itemlua.text_title2.text.text = I18N.T(title)
|
|
|
|
--加锁
|
|
if self.maplevel >= info.MapLevel then
|
|
itemlua.img_lock:SetActive(false)
|
|
else
|
|
itemlua.img_lock:SetActive(true)
|
|
end
|
|
|
|
itemlua.btn_momo:SetActive(false)
|
|
itemlua.btn_comic:SetActive(false)
|
|
|
|
--类型
|
|
if info.Type == 0 then --漫画
|
|
itemlua.btn_comic:SetActive(true)
|
|
self.uiBase:AddButtonUniqueEventListener(itemlua.btn_comic.button, self, self.OnClickComic, info)
|
|
itemlua.text_type.text.text = I18N.T("漫画")
|
|
|
|
elseif info.Type == 1 then --momo
|
|
itemlua.btn_momo:SetActive(true)
|
|
self.uiBase:AddButtonUniqueEventListener(itemlua.btn_momo.button, self, self.OnClickMomo, info)
|
|
itemlua.text_type.text.text = I18N.T("聊天")
|
|
end
|
|
|
|
return item
|
|
end
|
|
|
|
function UIStoryPreviewView:OnClickComic(button, params)
|
|
local storyCfg = params[0]
|
|
local storyId = storyCfg.StoryId
|
|
ManagerContainer.UIStoryMgr:StartStoryByStoryId(tonumber(storyId), true)
|
|
end
|
|
|
|
function UIStoryPreviewView:OnClickMomo(button, params)
|
|
local storyCfg = params[0]
|
|
local storyId = storyCfg.StoryId
|
|
ManagerContainer.UIStoryMgr:StartStoryByStoryId(tonumber(storyId), true)
|
|
end
|
|
|
|
return UIStoryPreviewView
|