KLHorseRaceLampPanel.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. ---@class KLHorseRaceLampPanel:UIKmlLuaPanelBase
  2. ---@field view KLHorseRaceLampPanelView
  3. ---@field HorseRaceLamplist table 跑马灯队列
  4. ---@field damage string 伤害
  5. ---@field exp string 经验
  6. ---@field defaultPos
  7. ---@field StationaryStr string[]
  8. local KLHorseRaceLampPanel = class(UIKmlLuaPanelBase)
  9. local this = KLHorseRaceLampPanel
  10. ---创建时调用一次
  11. function this:Init()
  12. SL:KeepOpenPanel("KLHorseRaceLampPanel", true)
  13. -- 盒子服务端过来的信息无法走表,策划要求写死配置(跑马灯)
  14. 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 }
  15. -- 盒子服务端过来的信息无法走表,策划要求写死配置(聊天框)
  16. 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 }
  17. end
  18. ---创建或者刷新界面数据时调用
  19. function this:Refresh()
  20. self.StationaryStr = {}
  21. self.HorseRaceLamplist = {}
  22. GUI:SetActive(self.view.HorseRaceLampBG, false)
  23. GUI:DataListInitData(self.view.stationary_list, function()
  24. return #self.StationaryStr
  25. end, function(realIndex)
  26. end, function(realIndex, kmlcontrol)
  27. end, function(realIndex, kmlcontrol)
  28. return self:StationaryDataUpdateFunc(realIndex, kmlcontrol)
  29. end)
  30. self:InitArchangelExp()
  31. end
  32. ---注册UI事件和服务器消息
  33. function this:RegistEvents()
  34. SL:RegisterLuaNetMsg(LuaMessageIdToClient.HORSE_LAMP, self.Message, self)
  35. SL:RegisterLuaNetMsg(LuaMessageIdToClient.CHAT, self.CHAT_NOTICE, self)
  36. SL:RegisterLuaNetMsg(LuaMessageIdToClient.OTHER_NOTICE, self.MessageType, self)
  37. end
  38. ---@param message {id:number,contentFromServer:boolean ,content:string 缺省则读表, params:string[]
  39. function this:Other(message, type)
  40. local tbl
  41. if message.id == -1 then
  42. tbl = self.BoxHorse
  43. elseif message.id == -2 then
  44. tbl = self.BoxChat
  45. else
  46. tbl = SL:GetConfig("cfg_string", message.id, "id")
  47. end
  48. if string.isNullOrEmpty(message.content) then
  49. message.content = tbl.text
  50. end
  51. if tbl.messageType[1] == 12 then
  52. self:DamageEXP(message.id, message.content)
  53. elseif tbl.messageType[1] == 15 then
  54. self:Stationary(message.id, message.content)
  55. end
  56. end
  57. function this:CHAT_NOTICE(_, message)
  58. SL:onLUAEvent(LUA_EVENT_CHAT_RECEIVE_NOTICE, {
  59. message = message.content,
  60. channel = message.channel,
  61. })
  62. end
  63. function this:Message(_, data)
  64. local HorseRaceLampData = {
  65. id = tonumber(data.cfgId),
  66. content = data.content,
  67. contentFromServer = true
  68. }
  69. local tbl
  70. if HorseRaceLampData.id == -1 then
  71. tbl = self.BoxHorse
  72. elseif HorseRaceLampData.id == -2 then
  73. tbl = self.BoxChat
  74. else
  75. tbl = SL:GetConfig("cfg_string", HorseRaceLampData.id, "id")
  76. end
  77. SL:MessageTip(HorseRaceLampData)
  78. end
  79. --内置跑马灯无法满足策划要求,外置重做
  80. --function this:AddHorseRaceLamplist(data)
  81. -- local userid = SL:GetMetaValue("USER_ID")
  82. -- local level = SL:GetMetaValue("ACTOR_LEVEL", userid)
  83. -- local tbl
  84. -- if data.id == -1 then
  85. -- tbl = self.BoxHorse
  86. -- elseif data.id == -2 then
  87. -- tbl = self.BoxChat
  88. -- else
  89. -- tbl = SL:GetConfig("cfg_string", data.id, "id")
  90. -- end
  91. -- if data.contentFromServer == false then
  92. -- data.content = tbl.text
  93. -- end
  94. -- if tbl then
  95. -- local Marquees = {
  96. -- data = data,
  97. -- tbl = tbl,
  98. -- time = SL:GetMetaValue("SERVER_TIME")
  99. --
  100. -- }
  101. -- if table.count(tbl.messageType) == 1 then
  102. -- --跑马灯类型
  103. -- if tbl.messageType[1] >= 1 and tbl.messageType[1] <= 5 then
  104. -- table.insert(self.HorseRaceLamplist, Marquees)
  105. -- table.sort(self.HorseRaceLamplist, function(a, b)
  106. -- return a.tbl.order > b.tbl.order
  107. -- end)
  108. -- end
  109. -- end
  110. -- end
  111. -- if not self.HorseRaceLampCoroutine then
  112. -- self.HorseRaceLampCoroutine = Coroutine.Start(self.HorseRaceLampFunc, self)
  113. -- end
  114. --end
  115. --function this:HorseRaceLampFunc()
  116. -- local current
  117. -- while table.count(self.HorseRaceLamplist) > 0 do
  118. -- current = self.HorseRaceLamplist[1]
  119. -- local time = SL:GetMetaValue("SERVER_TIME")
  120. -- local timeColumn = time - current.time
  121. -- local doTime = 0
  122. -- timeColumn = timeColumn / 1000
  123. -- if timeColumn >= 30 then
  124. -- Coroutine.WaitForEndOfFrame()
  125. -- else
  126. -- GUI:SetActive(self.view.HorseRaceLampBG, true)
  127. -- GUI:setPosition(self.view.HorseRaceLampBG, 0, 350 + current.tbl.offsetY)
  128. -- local colorTbl = SL:GetConfig("cfg_color", tonumber(current.tbl.textColor), "id")
  129. -- if colorTbl then
  130. -- GUI:Text_setTextColor(self.view.HorseRaceLamp, colorTbl.color)
  131. -- else
  132. -- GUI:Text_setTextColor(self.view.HorseRaceLamp, "#000000")
  133. -- end
  134. --
  135. -- local textsize = current.tbl.textSize
  136. -- if textsize then
  137. -- GUI:Text_setFontSize(self.view.HorseRaceLamp, tonumber(textsize))
  138. -- end
  139. -- GUI:Text_setString(self.view.HorseRaceLamp, current.data.content)
  140. -- local x, y = GUI:getSizeDelta(self.view.HorseRaceLamp)
  141. -- --y = tonumber(textsize)
  142. -- --if tonumber(textsize) > y then
  143. -- -- y = textsize
  144. -- --end
  145. -- GUI:setContentSize(self.view.HorseRaceLampBG, x + 50, y + 10)
  146. -- GUI:setContentSize(self.view.scroll, x + 100, y + 20)
  147. -- GUI:setContentSize(self.view.HorseRaceLampLayout, x + 10, y + 10)
  148. -- GUI:setPosition(self.view.HorseRaceLamp, 0, 0)
  149. --
  150. -- local ax, ay, az = GUI:GetWorldPosition(self.view.scroll)
  151. --
  152. -- GUI:setContentSize(self.view.HorseRace, x + 120, y + 30)
  153. -- GUI:setPosition(self.view.HorseRace, 0, 0)
  154. --
  155. -- local isMove = true
  156. -- if current.tbl.messageType[1] == 1 then
  157. -- GUI:setPositionX(self.view.HorseRaceLampLayout, x + 100)
  158. -- elseif current.tbl.messageType[1] == 2 then
  159. -- GUI:setPositionX(self.view.HorseRaceLampLayout, -(x + 100))
  160. -- elseif current.tbl.messageType[1] == 3 then
  161. -- GUI:setPositionY(self.view.HorseRaceLampLayout, -(y + 100))
  162. -- elseif current.tbl.messageType[1] == 4 then
  163. -- GUI:setPositionY(self.view.HorseRaceLampLayout, y + 100)
  164. -- elseif current.tbl.messageType[1] == 5 then
  165. -- isMove = false
  166. -- end
  167. -- doTime = current.tbl.rollSpeed / 1000
  168. -- if isMove then
  169. -- --SL:EffectDoMove(self.view.HorseRaceLampLayout.rectTransform, Vector3.New(ax, ay, az), doTime)
  170. -- SL:UIDOLocalMove(self.view.HorseRaceLampLayout, Vector3.New(0, 0, 0), doTime)
  171. -- end
  172. --
  173. -- Coroutine.Wait(1 + doTime)
  174. -- end
  175. --
  176. -- GUI:SetActive(self.view.HorseRaceLampBG, false)
  177. -- table.removeByValue(self.HorseRaceLamplist, current)
  178. -- end
  179. -- self.HorseRaceLampCoroutine = nil
  180. --end
  181. function this:MessageType(_, message)
  182. local tbl = SL:GetConfig("cfg_string", 105, "id")
  183. if tbl.messageType == 12 then
  184. self:DamageEXP(message.cfgId, message.content)
  185. elseif tbl.messageType == 15 then
  186. self:Stationary(message.cfgId, message.content)
  187. else
  188. data = {
  189. id = tonumber(message.cfgId),
  190. content = message.content,
  191. contentFromServer = true
  192. }
  193. SL:MessageTip(data)
  194. end
  195. end
  196. --伤害经验显示内置无法使用,外置重做
  197. function this:DamageEXP(cfgId, content)
  198. local tbl = SL:GetConfig("cfg_string", 105, "id")
  199. if tonumber(cfgId) == 105 then
  200. --秒伤
  201. local colorTbl = SL:GetConfig("cfg_color", tonumber(tbl.textColor), "id")
  202. local color = colorTbl and colorTbl.color or "#FFFFFF"
  203. self.damage = "<color=" .. color .. "><size=" .. tbl.textSize .. " >" .. content .. "</size></color>"
  204. self:DamageTip()
  205. elseif tonumber(cfgId) == 106 then
  206. --分钟经验
  207. local colorTbl = SL:GetConfig("cfg_color", tonumber(tbl.textColor), "id")
  208. local color = colorTbl and colorTbl.color or "#FFFFFF"
  209. self.exp = "<color=" .. color .. "><size=" .. tbl.textSize .. " >" .. content .. "</size></color>"
  210. self:EXPTip()
  211. end
  212. end
  213. function this:DamageTip()
  214. local str = self.damage
  215. if self.expTimeID then
  216. str = self.exp .. "\n" .. str
  217. end
  218. if self.damageTimeID then
  219. SL:UnSchedule(self.damageTimeID)
  220. end
  221. self.damageTimeID = SL:ScheduleOnce(1, function()
  222. self:HideDamage()
  223. end)
  224. self:RefreshDamageEXP(str)
  225. end
  226. function this:EXPTip()
  227. local str = self.exp
  228. if self.damageTimeID then
  229. str = str .. "\n" .. self.damage
  230. end
  231. if self.expTimeID then
  232. SL:UnSchedule(self.expTimeID)
  233. end
  234. self.expTimeID = SL:ScheduleOnce(1, function()
  235. self:HideEXP()
  236. end)
  237. self:RefreshDamageEXP(str)
  238. end
  239. function this:RefreshDamageEXP(str)
  240. --刷新
  241. if not GUI:getVisible(self.view.DamageEXPBG) then
  242. --打开
  243. GUI:setVisible(self.view.DamageEXPBG, true)
  244. end
  245. -- 设置文字
  246. GUI:Text_setString(self.view.DamageEXPText, str)
  247. local x, y = GUI:getSizeDelta(self.view.DamageEXPText)
  248. GUI:setContentSize(self.view.DamageEXPBG, x + 150, y + 10)
  249. GUI:setPosition(self.view.DamageEXPText, 0, 0)
  250. end
  251. function this:HideDamage()
  252. self.damageTimeID = nil
  253. self.damage = nil
  254. if self.exp == nil then
  255. GUI:setVisible(self.view.DamageEXPBG, false)
  256. end
  257. end
  258. function this:HideEXP()
  259. self.expTimeID = nil
  260. self.exp = nil
  261. if self.damage == nil then
  262. GUI:setVisible(self.view.DamageEXPBG, false)
  263. end
  264. end
  265. function this:Stationary(cfgId, str)
  266. GUI:setVisible(self.view.stationary, true)
  267. self.StationaryStrTbl = SL:GetConfig("cfg_string", cfgId, "id")
  268. if str == nil then
  269. str = self.StationaryStrTbl.text
  270. end
  271. GUI:setPosition(self.view.stationary, self.StationaryStrTbl.offsetX or 0, self.StationaryStrTbl.offsetY or 0)
  272. self.StationaryStr = string.split(str, "\n")
  273. GUI:setContentSize(self.view.stationary, 1334, 15 * ((#self.StationaryStr) - 2))
  274. -- 操作datalist
  275. GUI:DataListUpdateData(self.view.stationary_list)
  276. if self.stationaryShowDuration then
  277. SL:UnSchedule(self.stationaryShowDuration)
  278. end
  279. self.stationaryShowDuration = SL:ScheduleOnce(self.StationaryStrTbl.ShowDuration / 1000, function()
  280. GUI:setVisible(self.view.stationary, false)
  281. end)
  282. end
  283. function this:StationaryDataUpdateFunc(realIndex, kmlcontrol)
  284. local stationary_text =GUI:GetChildControl(self.view.stationary_list,realIndex,'stationary_text',kmlcontrol) ---self.view.stationary_list:GetChildControl(realIndex, 'stationary_text')
  285. GUI:Text_setFontSize(stationary_text, self.StationaryStrTbl.textSize)
  286. local colorTbl = SL:GetConfig("cfg_color", tonumber(self.StationaryStrTbl.textColor), "id")
  287. if colorTbl then
  288. GUI:Text_setTextColor(stationary_text, colorTbl.color)
  289. else
  290. GUI:Text_setTextColor(stationary_text, "#000000")
  291. end
  292. GUI:Text_setString(stationary_text, self.StationaryStr[realIndex + 1])
  293. local textX, textY = GUI:getSizeDelta(stationary_text)
  294. local img = GUI:GetChildControl(self.view.stationary_list,realIndex,'stationary_img') ---self.view.stationary_list:GetChildControl(realIndex, 'stationary_img')
  295. GUI:setContentSize(img, textX + 50, textY + 5)
  296. GUI:setPosition(stationary_text, 0, 0)
  297. local stationaryX, stationaryY = GUI:getSizeDelta(self.view.stationary)
  298. GUI:setContentSize(self.view.stationary, stationaryX, stationaryY + textY + 5)
  299. end
  300. function this:InitArchangelExp()
  301. self.ArchangelExp = {}
  302. self.ArchangelExpSchedule = {}
  303. self.ArchangelExpList = {}
  304. self.ArchangelExpCount = 0
  305. for i = 1, 7 do
  306. local bgName = "archangelExpBG" .. tostring(i)
  307. self.ArchangelExp[i] = {}
  308. self.ArchangelExp[i].BG = GUI:GetChildControl(self.view.archangelLayout, i - 1, bgName)
  309. self.ArchangelExp[i].text = GUI:GetChildControl(self.ArchangelExp[i].BG, 0, "archangelExp")
  310. end
  311. for i, v in pairs(self.ArchangelExp) do
  312. GUI:setVisible(v.BG)
  313. end
  314. end
  315. function this:AddArchangelExp(level, name)
  316. --table.insert(self.ArchangelExpList, { level = level, name = name })
  317. --if not self.ArchangelListSchedule then
  318. -- self.ArchangelListSchedule = SL:Schedule(self.ArchangelListSchedule, 0, 0.1, -1, function()
  319. -- local index = 0
  320. -- for i, v in pairs(self.ArchangelExpCount) do
  321. -- if not v then
  322. -- index = i
  323. -- break
  324. -- end
  325. -- end
  326. -- if index == 0 and table.count(self.ArchangelExpList) == 0 then
  327. -- SL:UnSchedule(self.ArchangelListSchedule)
  328. -- self.ArchangelListSchedule = nil
  329. -- return
  330. -- elseif index > 0 then
  331. -- self:StartArchangelExp(self.ArchangelExpList[1],index)
  332. -- end
  333. --
  334. -- end)
  335. --end
  336. self.ArchangelExpCount = self.ArchangelExpCount + 1
  337. if self.ArchangelExpCount > 7 then
  338. self.ArchangelExpCount = 1
  339. end
  340. local control = self.ArchangelExp[self.ArchangelExpCount]
  341. if self.ArchangelExpSchedule[self.ArchangelExpCount] then
  342. SL:UnSchedule(self.ArchangelExpSchedule[self.ArchangelExpCount])
  343. GUI:setVisible(control.BG, false)
  344. end
  345. ---@type cfg_string_column
  346. local strTbl = SL:GetConfig("cfg_string", 499, "id")
  347. local color = SL:GetConfig("cfg_color", tonumber(strTbl.textColor), "id").color
  348. GUI:Text_setTextColor(control.text, color)
  349. GUI:Text_setFontSize(control.text, strTbl.textSize)
  350. local text = strTbl.text
  351. text = string.gsub(text, "%%i", name)
  352. text = string.gsub(text, "%%d", tonumber(level))
  353. GUI:Text_setString(control.text, text)
  354. GUI:setLocalZOrder(control.BG, 3)
  355. GUI:setVisible(control.BG, true)
  356. local time = strTbl and strTbl.ShowDuration / 1000 or 2
  357. self.ArchangelExpSchedule[self.ArchangelExpCount] = SL:ScheduleOnce(time, function()
  358. GUI:setVisible(control.BG, false)
  359. self.ArchangelExpSchedule[self.ArchangelExpCount] = nil
  360. end)
  361. end
  362. --function this:StartArchangelExp(data,index)
  363. -- self.ArchangelExpCount[index] = true
  364. -- local level = data.level
  365. -- local name = data.name
  366. -- local control = self.ArchangelExp[index]
  367. -- if self.ArchangelExpSchedule[index] then
  368. -- SL:UnSchedule(self.ArchangelExpSchedule[index])
  369. -- GUI:setVisible(control.BG, false)
  370. -- end
  371. --
  372. -- ---@type cfg_string_column
  373. -- local strTbl = SL:GetConfig("cfg_string", 499, "id")
  374. -- local color = SL:GetConfig("cfg_color", tonumber(strTbl.textColor), "id").color
  375. -- GUI:Text_setTextColor(control.text, color)
  376. -- GUI:Text_setFontSize(control.text, strTbl.textSize)
  377. -- local text = strTbl.text
  378. -- text = string.gsub(text, "%%i", name)
  379. -- text = string.gsub(text, "%%d", tonumber(level))
  380. -- GUI:Text_setString(control.text, text)
  381. --
  382. -- GUI:setLocalZOrder(control.BG, 3)
  383. -- GUI:setVisible(control.BG, true)
  384. -- local time = strTbl and strTbl.ShowDuration / 1000 or 2
  385. -- self.ArchangelExpSchedule[index] = SL:ScheduleOnce(time, function()
  386. -- GUI:setVisible(control.BG, false)
  387. -- self.ArchangelExpCount[index] = false
  388. -- self.ArchangelExpSchedule[index] = nil
  389. -- table.removeByValue(self.ArchangelExpList, data)
  390. -- end)
  391. --end
  392. function this:Check()
  393. end
  394. function this:Close()
  395. Coroutine.StopAll()
  396. if self.damageTimeID then
  397. SL:UnSchedule(self.damageTimeID)
  398. end
  399. if self.expTimeID then
  400. SL:UnSchedule(self.expTimeID)
  401. end
  402. if self.stationaryShowDuration then
  403. SL:UnSchedule(self.stationaryShowDuration)
  404. end
  405. --for i, v in pairs(self.ArchangelExpSchedule) do
  406. -- if v then
  407. -- SL:UnSchedule(v)
  408. -- end
  409. --end
  410. end
  411. return this