---@class KLHorseRaceLampPanel:UIKmlLuaPanelBase ---@field view KLHorseRaceLampPanelView ---@field HorseRaceLamplist table 跑马灯队列 ---@field damage string 伤害 ---@field exp string 经验 ---@field defaultPos ---@field StationaryStr string[] local KLHorseRaceLampPanel = class(UIKmlLuaPanelBase) local this = KLHorseRaceLampPanel ---创建时调用一次 function this:Init() SL:KeepOpenPanel("KLHorseRaceLampPanel", true) -- 盒子服务端过来的信息无法走表,策划要求写死配置(跑马灯) self.BoxHorse = { id = -1, description = "", name = "", messageType = { 1 }, receiver = 3, textColor = "255", rollSpeed = 10000, text = "", subType = "系统", condition = { { 1, 1 } }, backgroundColor = "0", transparencyB = 40, transparencyT = 0, textSize = 20, offsetX = 0, offsetY = 0, rollCount = 0, releaseEffect = {}, ShowDuration = 0, order = 0 } -- 盒子服务端过来的信息无法走表,策划要求写死配置(聊天框) self.BoxChat = { id = -2, description = "", name = "", messageType = { 7 }, receiver = 3, textColor = "255", rollSpeed = 10000, text = "", subType = "系统", condition = { { 1, 1 } }, backgroundColor = "0", transparencyB = 40, transparencyT = 0, textSize = 20, offsetX = 0, offsetY = 0, rollCount = 0, releaseEffect = {}, ShowDuration = 0, order = 0 } end ---创建或者刷新界面数据时调用 function this:Refresh() self.StationaryStr = {} self.HorseRaceLamplist = {} GUI:SetActive(self.view.HorseRaceLampBG, false) GUI:DataListInitData(self.view.stationary_list, function() return #self.StationaryStr end, function(realIndex) end, function(realIndex, kmlcontrol) end, function(realIndex, kmlcontrol) return self:StationaryDataUpdateFunc(realIndex, kmlcontrol) end) self:InitArchangelExp() end ---注册UI事件和服务器消息 function this:RegistEvents() SL:RegisterLuaNetMsg(LuaMessageIdToClient.HORSE_LAMP, self.Message, self) SL:RegisterLuaNetMsg(LuaMessageIdToClient.CHAT, self.CHAT_NOTICE, self) SL:RegisterLuaNetMsg(LuaMessageIdToClient.OTHER_NOTICE, self.MessageType, self) end ---@param message {id:number,contentFromServer:boolean ,content:string 缺省则读表, params:string[] function this:Other(message, type) local tbl if message.id == -1 then tbl = self.BoxHorse elseif message.id == -2 then tbl = self.BoxChat else tbl = SL:GetConfig("cfg_string", message.id, "id") end if string.isNullOrEmpty(message.content) then message.content = tbl.text end if tbl.messageType[1] == 12 then self:DamageEXP(message.id, message.content) elseif tbl.messageType[1] == 15 then self:Stationary(message.id, message.content) end end function this:CHAT_NOTICE(_, message) SL:onLUAEvent(LUA_EVENT_CHAT_RECEIVE_NOTICE, { message = message.content, channel = message.channel, }) end function this:Message(_, data) local HorseRaceLampData = { id = tonumber(data.cfgId), content = data.content, contentFromServer = true } local tbl if HorseRaceLampData.id == -1 then tbl = self.BoxHorse elseif HorseRaceLampData.id == -2 then tbl = self.BoxChat else tbl = SL:GetConfig("cfg_string", HorseRaceLampData.id, "id") end SL:MessageTip(HorseRaceLampData) end --内置跑马灯无法满足策划要求,外置重做 --function this:AddHorseRaceLamplist(data) -- local userid = SL:GetMetaValue("USER_ID") -- local level = SL:GetMetaValue("ACTOR_LEVEL", userid) -- local tbl -- if data.id == -1 then -- tbl = self.BoxHorse -- elseif data.id == -2 then -- tbl = self.BoxChat -- else -- tbl = SL:GetConfig("cfg_string", data.id, "id") -- end -- if data.contentFromServer == false then -- data.content = tbl.text -- end -- if tbl then -- local Marquees = { -- data = data, -- tbl = tbl, -- time = SL:GetMetaValue("SERVER_TIME") -- -- } -- if table.count(tbl.messageType) == 1 then -- --跑马灯类型 -- if tbl.messageType[1] >= 1 and tbl.messageType[1] <= 5 then -- table.insert(self.HorseRaceLamplist, Marquees) -- table.sort(self.HorseRaceLamplist, function(a, b) -- return a.tbl.order > b.tbl.order -- end) -- end -- end -- end -- if not self.HorseRaceLampCoroutine then -- self.HorseRaceLampCoroutine = Coroutine.Start(self.HorseRaceLampFunc, self) -- end --end --function this:HorseRaceLampFunc() -- local current -- while table.count(self.HorseRaceLamplist) > 0 do -- current = self.HorseRaceLamplist[1] -- local time = SL:GetMetaValue("SERVER_TIME") -- local timeColumn = time - current.time -- local doTime = 0 -- timeColumn = timeColumn / 1000 -- if timeColumn >= 30 then -- Coroutine.WaitForEndOfFrame() -- else -- GUI:SetActive(self.view.HorseRaceLampBG, true) -- GUI:setPosition(self.view.HorseRaceLampBG, 0, 350 + current.tbl.offsetY) -- local colorTbl = SL:GetConfig("cfg_color", tonumber(current.tbl.textColor), "id") -- if colorTbl then -- GUI:Text_setTextColor(self.view.HorseRaceLamp, colorTbl.color) -- else -- GUI:Text_setTextColor(self.view.HorseRaceLamp, "#000000") -- end -- -- local textsize = current.tbl.textSize -- if textsize then -- GUI:Text_setFontSize(self.view.HorseRaceLamp, tonumber(textsize)) -- end -- GUI:Text_setString(self.view.HorseRaceLamp, current.data.content) -- local x, y = GUI:getSizeDelta(self.view.HorseRaceLamp) -- --y = tonumber(textsize) -- --if tonumber(textsize) > y then -- -- y = textsize -- --end -- GUI:setContentSize(self.view.HorseRaceLampBG, x + 50, y + 10) -- GUI:setContentSize(self.view.scroll, x + 100, y + 20) -- GUI:setContentSize(self.view.HorseRaceLampLayout, x + 10, y + 10) -- GUI:setPosition(self.view.HorseRaceLamp, 0, 0) -- -- local ax, ay, az = GUI:GetWorldPosition(self.view.scroll) -- -- GUI:setContentSize(self.view.HorseRace, x + 120, y + 30) -- GUI:setPosition(self.view.HorseRace, 0, 0) -- -- local isMove = true -- if current.tbl.messageType[1] == 1 then -- GUI:setPositionX(self.view.HorseRaceLampLayout, x + 100) -- elseif current.tbl.messageType[1] == 2 then -- GUI:setPositionX(self.view.HorseRaceLampLayout, -(x + 100)) -- elseif current.tbl.messageType[1] == 3 then -- GUI:setPositionY(self.view.HorseRaceLampLayout, -(y + 100)) -- elseif current.tbl.messageType[1] == 4 then -- GUI:setPositionY(self.view.HorseRaceLampLayout, y + 100) -- elseif current.tbl.messageType[1] == 5 then -- isMove = false -- end -- doTime = current.tbl.rollSpeed / 1000 -- if isMove then -- --SL:EffectDoMove(self.view.HorseRaceLampLayout.rectTransform, Vector3.New(ax, ay, az), doTime) -- SL:UIDOLocalMove(self.view.HorseRaceLampLayout, Vector3.New(0, 0, 0), doTime) -- end -- -- Coroutine.Wait(1 + doTime) -- end -- -- GUI:SetActive(self.view.HorseRaceLampBG, false) -- table.removeByValue(self.HorseRaceLamplist, current) -- end -- self.HorseRaceLampCoroutine = nil --end function this:MessageType(_, message) local tbl = SL:GetConfig("cfg_string", 105, "id") if tbl.messageType == 12 then self:DamageEXP(message.cfgId, message.content) elseif tbl.messageType == 15 then self:Stationary(message.cfgId, message.content) else data = { id = tonumber(message.cfgId), content = message.content, contentFromServer = true } SL:MessageTip(data) end end --伤害经验显示内置无法使用,外置重做 function this:DamageEXP(cfgId, content) local tbl = SL:GetConfig("cfg_string", 105, "id") if tonumber(cfgId) == 105 then --秒伤 local colorTbl = SL:GetConfig("cfg_color", tonumber(tbl.textColor), "id") local color = colorTbl and colorTbl.color or "#FFFFFF" self.damage = "" .. content .. "" self:DamageTip() elseif tonumber(cfgId) == 106 then --分钟经验 local colorTbl = SL:GetConfig("cfg_color", tonumber(tbl.textColor), "id") local color = colorTbl and colorTbl.color or "#FFFFFF" self.exp = "" .. content .. "" self:EXPTip() end end function this:DamageTip() local str = self.damage if self.expTimeID then str = self.exp .. "\n" .. str end if self.damageTimeID then SL:UnSchedule(self.damageTimeID) end self.damageTimeID = SL:ScheduleOnce(1, function() self:HideDamage() end) self:RefreshDamageEXP(str) end function this:EXPTip() local str = self.exp if self.damageTimeID then str = str .. "\n" .. self.damage end if self.expTimeID then SL:UnSchedule(self.expTimeID) end self.expTimeID = SL:ScheduleOnce(1, function() self:HideEXP() end) self:RefreshDamageEXP(str) end function this:RefreshDamageEXP(str) --刷新 if not GUI:getVisible(self.view.DamageEXPBG) then --打开 GUI:setVisible(self.view.DamageEXPBG, true) end -- 设置文字 GUI:Text_setString(self.view.DamageEXPText, str) local x, y = GUI:getSizeDelta(self.view.DamageEXPText) GUI:setContentSize(self.view.DamageEXPBG, x + 150, y + 10) GUI:setPosition(self.view.DamageEXPText, 0, 0) end function this:HideDamage() self.damageTimeID = nil self.damage = nil if self.exp == nil then GUI:setVisible(self.view.DamageEXPBG, false) end end function this:HideEXP() self.expTimeID = nil self.exp = nil if self.damage == nil then GUI:setVisible(self.view.DamageEXPBG, false) end end function this:Stationary(cfgId, str) GUI:setVisible(self.view.stationary, true) self.StationaryStrTbl = SL:GetConfig("cfg_string", cfgId, "id") if str == nil then str = self.StationaryStrTbl.text end GUI:setPosition(self.view.stationary, self.StationaryStrTbl.offsetX or 0, self.StationaryStrTbl.offsetY or 0) self.StationaryStr = string.split(str, "\n") GUI:setContentSize(self.view.stationary, 1334, 15 * ((#self.StationaryStr) - 2)) -- 操作datalist GUI:DataListUpdateData(self.view.stationary_list) if self.stationaryShowDuration then SL:UnSchedule(self.stationaryShowDuration) end self.stationaryShowDuration = SL:ScheduleOnce(self.StationaryStrTbl.ShowDuration / 1000, function() GUI:setVisible(self.view.stationary, false) end) end function this:StationaryDataUpdateFunc(realIndex, kmlcontrol) local stationary_text =GUI:GetChildControl(self.view.stationary_list,realIndex,'stationary_text',kmlcontrol) ---self.view.stationary_list:GetChildControl(realIndex, 'stationary_text') GUI:Text_setFontSize(stationary_text, self.StationaryStrTbl.textSize) local colorTbl = SL:GetConfig("cfg_color", tonumber(self.StationaryStrTbl.textColor), "id") if colorTbl then GUI:Text_setTextColor(stationary_text, colorTbl.color) else GUI:Text_setTextColor(stationary_text, "#000000") end GUI:Text_setString(stationary_text, self.StationaryStr[realIndex + 1]) local textX, textY = GUI:getSizeDelta(stationary_text) local img = GUI:GetChildControl(self.view.stationary_list,realIndex,'stationary_img') ---self.view.stationary_list:GetChildControl(realIndex, 'stationary_img') GUI:setContentSize(img, textX + 50, textY + 5) GUI:setPosition(stationary_text, 0, 0) local stationaryX, stationaryY = GUI:getSizeDelta(self.view.stationary) GUI:setContentSize(self.view.stationary, stationaryX, stationaryY + textY + 5) end function this:InitArchangelExp() self.ArchangelExp = {} self.ArchangelExpSchedule = {} self.ArchangelExpList = {} self.ArchangelExpCount = 0 for i = 1, 7 do local bgName = "archangelExpBG" .. tostring(i) self.ArchangelExp[i] = {} self.ArchangelExp[i].BG = GUI:GetChildControl(self.view.archangelLayout, i - 1, bgName) self.ArchangelExp[i].text = GUI:GetChildControl(self.ArchangelExp[i].BG, 0, "archangelExp") end for i, v in pairs(self.ArchangelExp) do GUI:setVisible(v.BG) end end function this:AddArchangelExp(level, name) --table.insert(self.ArchangelExpList, { level = level, name = name }) --if not self.ArchangelListSchedule then -- self.ArchangelListSchedule = SL:Schedule(self.ArchangelListSchedule, 0, 0.1, -1, function() -- local index = 0 -- for i, v in pairs(self.ArchangelExpCount) do -- if not v then -- index = i -- break -- end -- end -- if index == 0 and table.count(self.ArchangelExpList) == 0 then -- SL:UnSchedule(self.ArchangelListSchedule) -- self.ArchangelListSchedule = nil -- return -- elseif index > 0 then -- self:StartArchangelExp(self.ArchangelExpList[1],index) -- end -- -- end) --end self.ArchangelExpCount = self.ArchangelExpCount + 1 if self.ArchangelExpCount > 7 then self.ArchangelExpCount = 1 end local control = self.ArchangelExp[self.ArchangelExpCount] if self.ArchangelExpSchedule[self.ArchangelExpCount] then SL:UnSchedule(self.ArchangelExpSchedule[self.ArchangelExpCount]) GUI:setVisible(control.BG, false) end ---@type cfg_string_column local strTbl = SL:GetConfig("cfg_string", 499, "id") local color = SL:GetConfig("cfg_color", tonumber(strTbl.textColor), "id").color GUI:Text_setTextColor(control.text, color) GUI:Text_setFontSize(control.text, strTbl.textSize) local text = strTbl.text text = string.gsub(text, "%%i", name) text = string.gsub(text, "%%d", tonumber(level)) GUI:Text_setString(control.text, text) GUI:setLocalZOrder(control.BG, 3) GUI:setVisible(control.BG, true) local time = strTbl and strTbl.ShowDuration / 1000 or 2 self.ArchangelExpSchedule[self.ArchangelExpCount] = SL:ScheduleOnce(time, function() GUI:setVisible(control.BG, false) self.ArchangelExpSchedule[self.ArchangelExpCount] = nil end) end --function this:StartArchangelExp(data,index) -- self.ArchangelExpCount[index] = true -- local level = data.level -- local name = data.name -- local control = self.ArchangelExp[index] -- if self.ArchangelExpSchedule[index] then -- SL:UnSchedule(self.ArchangelExpSchedule[index]) -- GUI:setVisible(control.BG, false) -- end -- -- ---@type cfg_string_column -- local strTbl = SL:GetConfig("cfg_string", 499, "id") -- local color = SL:GetConfig("cfg_color", tonumber(strTbl.textColor), "id").color -- GUI:Text_setTextColor(control.text, color) -- GUI:Text_setFontSize(control.text, strTbl.textSize) -- local text = strTbl.text -- text = string.gsub(text, "%%i", name) -- text = string.gsub(text, "%%d", tonumber(level)) -- GUI:Text_setString(control.text, text) -- -- GUI:setLocalZOrder(control.BG, 3) -- GUI:setVisible(control.BG, true) -- local time = strTbl and strTbl.ShowDuration / 1000 or 2 -- self.ArchangelExpSchedule[index] = SL:ScheduleOnce(time, function() -- GUI:setVisible(control.BG, false) -- self.ArchangelExpCount[index] = false -- self.ArchangelExpSchedule[index] = nil -- table.removeByValue(self.ArchangelExpList, data) -- end) --end function this:Check() end function this:Close() Coroutine.StopAll() if self.damageTimeID then SL:UnSchedule(self.damageTimeID) end if self.expTimeID then SL:UnSchedule(self.expTimeID) end if self.stationaryShowDuration then SL:UnSchedule(self.stationaryShowDuration) end --for i, v in pairs(self.ArchangelExpSchedule) do -- if v then -- SL:UnSchedule(v) -- end --end end return this