115 lines
No EOL
3.8 KiB
Lua
115 lines
No EOL
3.8 KiB
Lua
--
|
|
local XUiGWSelectDifficultGrid = XClass(nil, "XUiGWSelectDifficultGrid")
|
|
|
|
function XUiGWSelectDifficultGrid:Ctor(prefab)
|
|
self:Init(prefab)
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:Init(prefab)
|
|
XTool.InitUiObjectByUi(self, prefab)
|
|
self.GridBuff.gameObject:SetActiveEx(false)
|
|
self.GridBuffs = {}
|
|
self.BtnHelp.CallBack = function() self:OnClickBtnHelp() end
|
|
end
|
|
--[[
|
|
local data = {
|
|
Id = id,
|
|
Name = cfg.Name,
|
|
RecommendActive = cfg.RecommendActive,
|
|
FightEventIds = cfg.FightEventIds,
|
|
PreId = cfg.PreId}
|
|
]]--
|
|
function XUiGWSelectDifficultGrid:Refresh(data)
|
|
self.Data = data
|
|
self.RImgSelectLevel:SetRawImage(data.BgPath)
|
|
self.TxtLevelName.text = data.Name
|
|
self.TxtRecommendActive.text = XUiHelper.GetText("GuildWarRecommendActive", data.RecommendActive)
|
|
self.ImgClear.gameObject:SetActiveEx(XDataCenter.GuildWarManager.CheckDifficultyIsPass(self.Data.Id))
|
|
self.IsUnLock = XDataCenter.GuildWarManager.CheckDifficultyIsPass(self.Data.PreId)
|
|
self.TxtLock.text = data.LockText
|
|
self.PanelLock.gameObject:SetActiveEx(not self.IsUnLock)
|
|
local preSelect = XDataCenter.GuildWarManager.GetDifficultyPreSelected() == self.Data.Id
|
|
self.TxtOpenTime.gameObject:SetActiveEx(preSelect)
|
|
if preSelect then
|
|
self:StartOpenTimeCount()
|
|
end
|
|
self:RefreshBuff()
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:RefreshBuff()
|
|
for index, fightEventId in pairs(self.Data.FightEventIds or {}) do
|
|
local buff = self:GetBuff(index)
|
|
buff:Show()
|
|
buff:Refresh(fightEventId)
|
|
end
|
|
for index = #self.Data.FightEventIds + 1, #self.GridBuffs do
|
|
local buff = self:GetBuff(index)
|
|
buff:Hide()
|
|
end
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:StartOpenTimeCount()
|
|
if self.TimeId then return end
|
|
self:RefreshOpenTime()
|
|
self.TimeId = XScheduleManager.ScheduleForever(function()
|
|
if XTool.UObjIsNil(self.GameObject) then self:StopCount() return end
|
|
self:RefreshOpenTime()
|
|
end, 1000)
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:RefreshOpenTime()
|
|
local targetTimeConfig = XGuildWarConfig.GetClientConfigValues("AutoSelectDifficultyTime", "Float")
|
|
local targetTime = targetTimeConfig[1]
|
|
local leftTime = XTime.GetServerLeftTimeToTargetTime(targetTime)
|
|
if leftTime <= 1 then
|
|
self:StopCount()
|
|
XLuaUiManager.RunMain()
|
|
XUiManager.TipText("GuildWarAutoSelectDifficultComplete")
|
|
return
|
|
end
|
|
self.TxtOpenTime.text = XUiHelper.GetText(
|
|
"GuildWarSelectDifficultAutoOpen",
|
|
XUiHelper.GetTime(
|
|
XTime.GetServerLeftTimeToTargetTime(targetTime),
|
|
XUiHelper.TimeFormatType.CHALLENGE
|
|
)
|
|
)
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:StopCount()
|
|
XScheduleManager.UnSchedule(self.TimeId)
|
|
self.TimeId = nil
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:GetBuff(index)
|
|
local buff = self.GridBuffs[index]
|
|
if buff then
|
|
return buff
|
|
end
|
|
local newGo = XUiHelper.Instantiate(self.GridBuff, self.PanelBuff)
|
|
if newGo then
|
|
local buffGridScript = require("XUi/XUiGuildWar/DifficultSelect/XUiGWSelectBuffGrid")
|
|
local newBuff = buffGridScript.New(newGo)
|
|
self.GridBuffs[index] = newBuff
|
|
end
|
|
return self.GridBuffs[index]
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:OnClick()
|
|
if not XDataCenter.GuildManager.IsGuildLeader() then
|
|
XUiManager.TipText("GuildWarNotGuildMaster")
|
|
return
|
|
end
|
|
XDataCenter.GuildWarManager.SelectDifficulty(self.Data.Id, function()
|
|
CsXGameEventManager.Instance:Notify(XEventId.EVENT_GUILD_WAR_DIFFICULTY_SELECTED)
|
|
XDataCenter.GuildWarManager.GetActivityData(function ()
|
|
XLuaUiManager.Open("UiGuildWarStageMain")
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function XUiGWSelectDifficultGrid:OnClickBtnHelp()
|
|
XLuaUiManager.Open("UiGuildWarMap", self.Data.Id)
|
|
end
|
|
|
|
return XUiGWSelectDifficultGrid |