KLTitleItem.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ---@class KLTitleItem:UIKmlLuaPanelBase
  2. ---@field view KLTitleItemView
  3. ---@field baseUI KLTitlePanel
  4. ---@field titleId number
  5. local KLTitleItem = class(UIKmlLuaPanelBase)
  6. local this = KLTitleItem
  7. ---创建时调用一次
  8. function this:Init()
  9. self.lastClick = 0
  10. end
  11. ---创建或者刷新界面数据时调用
  12. function this:Refresh()
  13. end
  14. ---@param dt TitleData
  15. function this:UpdateUI(dt, isSelect)
  16. self.titleId = dt.confId
  17. ---@type cfg_item_column
  18. local itemTbl = SL:GetConfig("cfg_item", self.titleId)
  19. ---@type cfg_model_charactor_column
  20. local modelTbl = SL:GetConfig('cfg_model_charactor', itemTbl.shape[1])
  21. ---@type cfg_fashion_column
  22. local fashionTbl = SL:GetConfig("cfg_fashion", dt.confId)
  23. local scale = "300,300,300"
  24. if fashionTbl.modelScale > 0 then
  25. scale = string.replace(scale, "300", tostring(fashionTbl.modelScale))
  26. end
  27. GUI:Model_setSrc(self.view.TitleModel, modelTbl.path, scale)
  28. if fashionTbl.timeType == E_TitleTimeType.Limit then
  29. --限时
  30. GUI:SetActive(self.view.TimeDown, true)
  31. GUI:SetActive(self.view.TxtTime, false)
  32. local svTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  33. local countdown = dt.expiresTime - svTime / 1000
  34. countdown = math.floor(countdown)
  35. GUI:SetControl_time(self.view.TimeDown, countdown)
  36. else
  37. GUI:SetActive(self.view.TxtTime, true)
  38. GUI:SetActive(self.view.TimeDown, false)
  39. if fashionTbl.timeType == E_TitleTimeType.NotLimit then
  40. GUI:Text_setString(self.view.TxtTime, "永久生效")
  41. elseif fashionTbl.timeType == E_TitleTimeType.UntilNext then
  42. GUI:Text_setString(self.view.TxtTime, "下次活动移除")
  43. else
  44. GUI:Text_setString(self.view.TxtTime, "排行榜实时刷新")
  45. end
  46. end
  47. if fashionTbl.vestedType == E_TitleBelong.Role then
  48. GUI:Text_setString(self.view.TxtType, "角色生效")
  49. else
  50. GUI:Text_setString(self.view.TxtType, "账号生效")
  51. end
  52. if isSelect then
  53. self:TitleItemOnClick()
  54. else
  55. self:SetIsSelect(false)
  56. end
  57. end
  58. ---注册UI事件和服务器消息
  59. function this:RegistEvents()
  60. GUI:AddOnClickEvent(self.view.Bg, self, self.TitleItemOnClick)
  61. end
  62. function this:TitleItemOnClick()
  63. if Time.frameCount - self.lastClick < 3 then
  64. return
  65. end
  66. self.lastClick = Time.frameCount
  67. return self.baseUI:TitleItemOnClick(self, self.titleId)
  68. end
  69. function this:SetIsSelect(isSelect)
  70. local spName = isSelect and "tab_title_selected" or "tab_title_unselect"
  71. GUI:Image_loadTexture(self.view.SpState, spName, "Atlas/AppearGroup.spriteatlas")
  72. end
  73. function this:Close()
  74. end
  75. return this