---@class KLUIOpenServerFirstKillPanel:UIKmlLuaPanelBase ---@field view KLUIOpenServerFirstKillPanelView ---@field rankingBoss cfg_goldFirstKill_column[] local KLUIOpenServerFirstKillPanel = class(UIKmlLuaPanelBase) local this =KLUIOpenServerFirstKillPanel function this:AsyncLoadUI() end ---创建时调用一次 function this:Init() self.globalServerRewardListData = {} self.personRewardListData = {} self.monsterTemps = {} self.globalServerRewardListItem = {} self.personRewardListItem = {} self.rankingBoss = SL:GetConfigTable("cfg_goldFirstKill") self.curSelectIndex = 1 self.SpSelectParent = nil self.lastSelectItem = nil self.startPosX = -975 self.addSign = 1 self:InitUI() end function this:InitUI() self:InitMonsterList() self:InitGlobalServerRewardList() self:InitPersonRewardList() end --region 个人奖励列表 function this:InitPersonRewardList() GUI:DataListInitData(self.view.DataPersonRewardList, function() return self:PersonRewardItemCountFunc() end, function(realIndex) return self:PersonRewardItemGetFunc(realIndex) end, function(realIndex, kmlcontrol) return self:PersonRewardItemInitFunc(realIndex, kmlcontrol) end, function(realIndex, kmlcontrol) return self:PersonRewardItemUpdateFunc(realIndex, kmlcontrol) end) end function this:PersonRewardItemCountFunc() return table.count(self.personRewardListData) end function this:PersonRewardItemGetFunc(realIndex) end function this:PersonRewardItemInitFunc(realIndex, kmlcontrol) end function this:PersonRewardItemUpdateFunc(realIndex, kmlcontrol) ---设置个人首杀奖励item local data = self.personRewardListData[realIndex + 1] local ctrlItem = GUI:GetChildControl(self.view.DataPersonRewardList,realIndex,'ItemPerson') local stateImg = GUI:GetChildControl(self.view.DataPersonRewardList,realIndex,'StateImg') GUI:Item_setItemId(ctrlItem,data[1]) GUI:setVisible(stateImg,self.isPersonGet) GUI:Item_setItemCount(ctrlItem,tostring(data[2])) GUI:AddOnClickEvent(ctrlItem,self,function() SL:OpenTips(nil, data[1]) end) end --endregion --region 全服奖励列表 function this:InitGlobalServerRewardList() GUI:DataListInitData(self.view.DataGlobalServerRewardList, function() return self:GlobalServerRewardItemCountFunc() end, function(realIndex) return self:GlobalServerRewardItemGetFunc(realIndex) end, function(realIndex, kmlcontrol) return self:GlobalServerRewardItemInitFunc(realIndex, kmlcontrol) end, function(realIndex, kmlcontrol) return self:GlobalServerRewardItemUpdateFunc(realIndex, kmlcontrol) end) end function this:GlobalServerRewardItemCountFunc() return table.count(self.globalServerRewardListData) end function this:GlobalServerRewardItemGetFunc(realIndex) end function this:GlobalServerRewardItemInitFunc(realIndex, kmlcontrol) end function this:GlobalServerRewardItemUpdateFunc(realIndex, kmlcontrol) local data = self.globalServerRewardListData[realIndex + 1] local ctrlItem = GUI:GetChildControl(self.view.DataGlobalServerRewardList,realIndex,'ItemServer') local tickImg = GUI:GetChildControl(self.view.DataGlobalServerRewardList,realIndex,'TickImg') local sendTxt = GUI:GetChildControl(self.view.DataGlobalServerRewardList,realIndex,'SendTxt') GUI:Item_setItemId(ctrlItem,data[1]) GUI:Item_setItemCount(ctrlItem,data[2]) GUI:setVisible(tickImg,self.state) GUI:setVisible(sendTxt,self.state) GUI:AddOnClickEvent(ctrlItem,self,function() SL:OpenTips(nil, data[1]) end) end --endregion --region boss列表 function this:InitMonsterList() GUI:DataListInitData(self.view.DataMonsterList, function() return self:MonsterItemCountFunc() end, function(realIndex) return self:MonsterItemGetFunc(realIndex) end, function(realIndex, kmlcontrol) return self:MonsterItemInitFunc(realIndex, kmlcontrol) end, function(realIndex, kmlcontrol) return self:MonsterItemUpdateFunc(realIndex, kmlcontrol) end) end function this:MonsterItemCountFunc() return table.count(self.rankingBoss) end function this:MonsterItemGetFunc(realIndex) ---@type KLUIFirstKillMonsterItem local item = GUI:UIPanel_Open("dev/outui/OpenServerActivity/Item/KLUIFirstKillMonster/KLUIFirstKillMonsterItem", self.view.DataMonsterList, self, nil, true,function(_item) self.monsterTemps[_item.view.root] = _item self:MonsterItemUpdateFunc(realIndex,_item.view.root) if SL:GetIsWebGL() then self.addSign = self.addSign + 1 if self.addSign >= 6 then self.addSign = 1 GUI:SetScrollView_scrollpos(self.view.MonsterViewList,self.curSelectIndex-1) end end end) local kmlCtrl = item.view.root self.monsterTemps[kmlCtrl] = item return kmlCtrl end function this:MonsterItemInitFunc(realIndex, kmlcontrol) end ---@param rectTrans KingML.KmlControl function this:MonsterItemUpdateFunc(cIndex, rectTrans) ---@type KLUIFirstKillMonsterItem local loopTemp = self.monsterTemps[rectTrans] if loopTemp.view and loopTemp.view.root.panel.isLoading then return end local bossFistKillInfo = InfoManager.openServiceAthleticsInfo.bossFistKillInfo local isShowRedDot = false local luaIndex = cIndex + 1 local dat = self.rankingBoss[luaIndex] local monsterId = tostring(dat.id) if bossFistKillInfo then if (bossFistKillInfo.allServerData[monsterId] and (not bossFistKillInfo.envelope[monsterId] or bossFistKillInfo.envelope[monsterId] == false)) or bossFistKillInfo.taskInfo[monsterId] == "2" then isShowRedDot = true end end loopTemp:RefreshUI(dat, luaIndex, isShowRedDot,self) if self.curSelectIndex == luaIndex then loopTemp:SetSelectActive(true) self.lastSelectItem = loopTemp self.SpSelectParent = rectTrans self:MonsterIconOnClick(loopTemp) elseif self.SpSelectParent and self.SpSelectParent == rectTrans then loopTemp:SetSelectActive(false) end end ---注册UI事件和服务器消息 function this:RegistEvents() GUI:AddOnClickEvent(self.view.BtnFullServiceAward, self, self.BtnFullServiceAwardOnClick) GUI:AddOnClickEvent(self.view.LeaveForKill, self, self.LeaveForKillOnClick) GUI:AddOnClickEvent(self.view.ClaimPersonReward, self, self.ClaimPersonRewardOnClick) SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ALL_SERVER_FIRST_KILL_INFO, self.RES_ALL_SERVER_FIRST_KILL_INFO, self) SL:RegisterLUAEvent(LUA_EVENT_OPENSERVICE_GOLDBOSSKILL_REDPONT_CHANGE,self.OpenServiceBossKillChangeRedPoint,self) end ----响应全服首杀和红包数据 ----@param message GoldFirstKillProtos.ResponseAllServerFirstKillData function this:RES_ALL_SERVER_FIRST_KILL_INFO(_, message) self:ShowTime() self.curMessage = message self:SetCurMonsterScrollRect(message) self:SetCurMonsterInfo(message) end function this:BtnFullServiceAwardOnClick(control) local bossId = self.rankingBoss[self.curSelectIndex].id local serverData = self.curMessage.allServerData[tostring(bossId)] local envelopeState = self.curMessage.envelope[tostring(bossId)] if serverData then envelopeState = envelopeState and 2 or 1 else envelopeState = 0 end ---全服红包 if envelopeState == 1 then if SL:HasConfig("cfg_monster", bossId) then SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_FIRST_KILL_ENVELOPE,{monsterId = bossId}) end InfoManager.openServiceAthleticsInfo.isClaimEvent = true end end ---领取个人首杀奖励 function this:ClaimPersonRewardOnClick() local bossId = self.rankingBoss[self.curSelectIndex].id local personalReward = self.curMessage.taskInfo[tostring(bossId)] if personalReward == "2" then SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_PERSONAL_FIRST_KILL_AWARD,{monsterId = bossId}) InfoManager.openServiceAthleticsInfo.isClaimEvent = true end end function this:LeaveForKillOnClick(control) GUI:UIPanel_Close("dev/outui/MainActivity/Panel/KLMainActivity/KLMainActivityPanel") SL.HideMainPanel() local monsterId = self.rankingBoss[self.curSelectIndex].id --local monsterType = SL:GetConfigMultiKeys('cfg_BOSS_challenge',monsterId , 'monsterid').monsterType GUI:UIPanel_Open("dev/outui/ChallengeBoss/Panel/KLChallengeBoss/KLChallengeBossPanel",nil, nil,{monsterId = monsterId,monsterType = 1 }) end ---界面显示时调用一次 function this:Show() end ---创建或者刷新界面数据时调用 function this:Refresh() self.FirtBossKillOpen =true SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ALL_SERVER_FIRST_KILL_INFO) end function this:Close() self:StopCoroutine() self:StopTick() self:StopRankTimer() if self.scheduleId then SL:UnSchedule(self.scheduleId) self.scheduleId = nil end end ----@param message GoldFirstKillProtos.ResponseAllServerFirstKillData function this:SetCurMonsterScrollRect(message) self.curSelectIndex = self:GetDefaultIdnex(message) if self.FirtBossKillOpen then GUI:DataListUpdateData(self.view.DataMonsterList) GUI:SetScrollView_scrollpos(self.view.MonsterViewList,self.curSelectIndex-1) self.FirtBossKillOpen = false end end ---获取默认选中的下标 ----@param message GoldFirstKillProtos.ResponseAllServerFirstKillData function this:GetDefaultIdnex(message) local curSelectIndex = 1 local selectbossId = self.rankingBoss[1].id local haveRedMinLevel = 100000 local ishaveRedDot = false for i, v in pairs(self.rankingBoss) do local isShowRedDot = self:JudgThisMonsterIsHaveRedDot(message,v.id) if isShowRedDot then local monsterLevel = SL:GetConfig("cfg_monster",v.id).level ishaveRedDot = true if monsterLevel < haveRedMinLevel then haveRedMinLevel = monsterLevel selectbossId = v.id end end end if ishaveRedDot == false then local level = 100000 for i, v in pairs(self.rankingBoss) do local monsterId = tostring(v.id) if message.allServerData[monsterId] == nil or (not message.envelope[monsterId] or message.envelope[monsterId] == false) or message.taskInfo[monsterId] ~= "3" then local monsterLevel = SL:GetConfig("cfg_monster",v.id).level if monsterLevel < level then level = monsterLevel selectbossId = v.id end end end end for k, bossinfo in ipairs(self.rankingBoss) do local dtbossId = bossinfo.id if dtbossId == selectbossId then curSelectIndex = k break end end return curSelectIndex end ---红点数据回包 ---@param redPointInfo table function this:OpenServiceBossKillChangeRedPoint(id,data) local bossFistKillInfo = InfoManager.openServiceAthleticsInfo.bossFistKillInfo if data then self.FirtBossKillOpen = true self:SetCurMonsterScrollRect(bossFistKillInfo) end self:SetCurMonsterInfo(bossFistKillInfo) self:RefreshRedDot() end ---设置当前boss信息 ---@param data GoldFirstKillProtos.ResponseAllServerFirstKillData function this:SetCurMonsterInfo(data) local monsterConfig = self.rankingBoss[self.curSelectIndex] ---@type cfg_monster_column local monster = SL:GetConfig("cfg_monster", monsterConfig.id) local strId = tostring(monsterConfig.id) local serverData = data.allServerData[strId] local envelopeState = data.envelope[strId] local message = nil if serverData then envelopeState = envelopeState and 2 or 1 message = { playerName = serverData.killerName, killTime = tonumber(serverData.killTime) , personalReward = tonumber(data.taskInfo[strId]), redPacket = envelopeState } else envelopeState = 0 message = { personalReward = tonumber(data.taskInfo[strId]) , redPacket = envelopeState } end self:ShowMonsterModel(monster.appr,monsterConfig) GUI:Text_setString(self.view.CurBossName, monster.name) GUI:Text_setString(self.view.CurBossLevel, monster.level .. "级") self.state = message.playerName and true or false if self.state == false then GUI:Text_setString(self.view.TxtName, "暂无") else GUI:Text_setString(self.view.TxtName, message.playerName) end if message.killTime and message.killTime > 0 then local time = message.killTime // 1000 local killTime = Time.FormatTimeYMDHMS(time) GUI:Text_setString(self.view.FirstKillTime, killTime) else GUI:Text_setString(self.view.FirstKillTime, "暂无") end self.globalServerRewardListData = monsterConfig.serReward GUI:DataListUpdateData(self.view.DataGlobalServerRewardList) self.isPersonGet = false ---1:不可领取 2可领取 3:已领取 if message.personalReward == 1 then GUI:setVisible(self.view.ClaimPersonReward, false) GUI:setVisible(self.view.LeaveForKill, true) GUI:setVisible(self.view.FirstKillFinished, false) elseif message.personalReward == 2 then GUI:setVisible(self.view.LeaveForKill, false) GUI:setVisible(self.view.ClaimPersonReward, true) GUI:setVisible(self.view.FirstKillFinished, false) elseif message.personalReward == 3 then GUI:setVisible(self.view.ClaimPersonReward, false) GUI:Text_setString(self.view.FirstKillFinished, "已领取") GUI:setVisible(self.view.LeaveForKill, false) GUI:setVisible(self.view.FirstKillFinished, true) self.isPersonGet = true end self.personRewardListData = monsterConfig.perReward GUI:DataListUpdateData(self.view.DataPersonRewardList) if message.redPacket == 0 then GUI:setVisible(self.view.BtnFullServiceAward, false) GUI:setVisible(self.view.FullServiceAwardClaimed, false) self.isFlash = false elseif message.redPacket == 1 then GUI:setVisible(self.view.BtnFullServiceAward, true) GUI:setVisible(self.view.FullServiceAwardClaimed, false) --GUI:Text_setString(self.view.BtnFullServiceAwardTips, "可领取") self:StopCoroutine() self.isFlash = true self.coroutine = Coroutine.Start(self.ClaimBtnFlash, self) elseif message.redPacket == 2 then GUI:setVisible(self.view.BtnFullServiceAward, false) GUI:setVisible(self.view.FullServiceAwardClaimed, true) --GUI:Text_setString(self.view.BtnFullServiceAwardTips, "已领取") self.isFlash = false end GUI:setVisible(self.view.BossReliveTime, false) end ---福袋闪烁 function this:ClaimBtnFlash() local alpha = 1 local spike = -0.05 while (self.isFlash) do if alpha >= 1 then spike = -0.05 elseif alpha <= 0 then spike = 0.05 end alpha = alpha + spike GUI:Image_setAlpha(self.view.BtnFullServiceAward, alpha) Coroutine.WaitForEndOfFrame() end end function this:StopCoroutine() if self.coroutine then Coroutine.Stop(self.coroutine) self.coroutine = nil end end ---开启倒计时 ---@param time number @倒计时时间,毫秒 function this:SetCountDown(time) self:StopTick() self.countDown = time if not self.countDownTimer then self.countDownTimer = SL:Schedule(self.countDownTimer,0,1,-1,self.Tick) end end ---黄金boss复活倒计时,展示不用展示 function this:Tick() local time = Time.FormatTimeHMS(self.countDown) GUI:Text_setString(self.view.BossReliveTime, time) if self.countDown <= 0 then self:StopTick() else self.countDown = self.countDown - 1000 end end function this:StopTick() if self.countDownTimer then SL:UnSchedule(self.countDownTimer) self.countDownTimer = nil end end ---创建怪物模型 function this:ShowMonsterModel(modelId, monsterConfig) local path = SL:GetConfig("cfg_model_monster",modelId).path local _mscale = "50,50,50" if monsterConfig and monsterConfig.size then local scale = math.ceil(monsterConfig.size/100) _mscale = scale .. "," .. scale .. "," .. scale end local y = -120 if self.MonsterModel then GUI:Model_setSrc(self.view.MonsterModel,path,_mscale,nil,"0,0,-1000") else self.MonsterModel = GUI:Model_Create(self.view.CurBossModelRoot,{ id="MonsterModel", x="0", y="-120", z="-1000", a="00", mscale =_mscale, mrotate="0,200,0", src=path, }) end if monsterConfig.offset and #monsterConfig.offset >= 2 then GUI:setPosition(self.view.MonsterModel,monsterConfig.offset[1],y+monsterConfig.offset[2]) else GUI:setPosition(self.view.MonsterModel,0,y) end end ---一天毫秒数 function this:ShowTime() local ONE_DAY_MILLISECOND = 86400000 local differenceTime = self:GetServerOpendifferenceTime() local tabRankingConfig = SL:GetConfig("sub_mainActivity", 1) local serverTime = Time.GetServerTime() local outTimeTbl = ConditionManager.GetConditionParams(tabRankingConfig.actualCondition) local endTime = (tonumber(outTimeTbl[2])) * ONE_DAY_MILLISECOND + SL:GetEnterRoleRes().openServerTime local diff = endTime - serverTime - differenceTime * 1000 if diff <= 0 then GUI:Text_setString(self.view.TxtTimePrefix, "挑战已结束") GUI:setPositionX(self.view.TxtTimePrefix,-936) self:StopRankTimer() GUI:Text_setString(self.view.TxtTime, "") self.isGoing = false else GUI:Text_setString(self.view.TxtTimePrefix, "挑战结束倒计时") GUI:setPositionX(self.view.TxtTimePrefix,self.startPosX) self:StartRankTimer(diff) self.isGoing = true end end function this:GetServerOpendifferenceTime() local enterRoleRes = SL:GetEnterRoleRes() if enterRoleRes == nil then return -1 end local openTime = Time.FormatTimeYMDHMS(enterRoleRes.openServerTime / 1000) local hour = tonumber(string.sub(openTime, 12, 13)) local minute = tonumber(string.sub(openTime, 15, 16)) local second = tonumber(string.sub(openTime, 18, 19)) local differenceTime = 0 --刷新差值 differenceTime = hour * 3600 + minute * 60 + second return differenceTime end ---开启倒计时 ---@param time number @倒计时时间,毫秒 function this:StartRankTimer(time) local rankcountDown = time / 1000 local txtTime = Time.FormatTimeDHMSFormColon(rankcountDown) GUI:Text_setString(self.view.TxtTime, txtTime) self:StopRankTimer() self.rankTimer = SL:Schedule(self.rankTimer,0,1,-1, function() local time = Time.FormatTimeDHMSFormColon(rankcountDown) GUI:Text_setString(self.view.TxtTime, time) if rankcountDown <= 0 then self:StopRankTimer() return end rankcountDown = rankcountDown - 1 end) end function this:StopRankTimer() if self.rankTimer then SL:UnSchedule(self.rankTimer) self.rankTimer = nil end end ---@param temp KLUIFirstKillMonsterItem function this:MonsterIconOnClick(temp) self.curSelectIndex = temp.luaIndex if self.lastSelectItem then self.lastSelectItem:SetSelectActive(false) end temp:SetSelectActive(true) self:SetCurMonsterInfo(InfoManager.openServiceAthleticsInfo.bossFistKillInfo) self.lastSelectItem = temp end function this:RefreshRedDot() if self.lastSelectItem then local bossFistKillInfo = InfoManager.openServiceAthleticsInfo.bossFistKillInfo local dat = self.rankingBoss[self.curSelectIndex] local isShowRedDot = self:JudgThisMonsterIsHaveRedDot(bossFistKillInfo,dat.id) self.lastSelectItem:RefreshRedDot(isShowRedDot) end end function this:JudgThisMonsterIsHaveRedDot(bossFistKillInfo,_monsterId) local isShowRedDot = false local monsterId = tostring(_monsterId) if (bossFistKillInfo.allServerData[monsterId] and (not bossFistKillInfo.envelope[monsterId] or bossFistKillInfo.envelope[monsterId] == false)) or bossFistKillInfo.taskInfo[monsterId] == "2" then isShowRedDot = true end return isShowRedDot end return this