KLMapMonsterPointItem.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ---@class KLMapMonsterPointItem:UIKmlLuaPanelBase
  2. ---@field view KLMapMonsterPointItemView
  3. local KLMapMonsterPointItem = class(UIKmlLuaPanelBase)
  4. local this = KLMapMonsterPointItem
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:Refresh()
  10. end
  11. function this:SetActiveUI(val)
  12. if self.view.root.kmlControl:GetSource()==nil then
  13. return
  14. end
  15. GUI:SetActive(self.view.root, val)
  16. end
  17. function this:setScale(size)
  18. --[[ if self.view.root.kmlControl:GetSource()==nil then
  19. return
  20. end]]
  21. GUI:setScale(self.view.root, size)
  22. end
  23. function this:SetMonsterData(id,x,y)
  24. self.mosnterId = id
  25. self.x = x
  26. self.y = y
  27. end
  28. function this:SetPanelXY(x, y)
  29. --[[ if self.view.root.kmlControl:GetSource()==nil then
  30. return
  31. end]]
  32. GUI:setPosition(self.view.root, x, y)
  33. end
  34. function this:SetPanelRotation(rotation)
  35. --[[ if self.view.root.kmlControl:GetSource()==nil then
  36. return
  37. end]]
  38. GUI:setRotation(self.view.root, rotation)
  39. end
  40. function this:SetNormalDead()
  41. if self.data.type ~= MonsterType.NormalMonster then
  42. GUI:setGrey(self.view.Icon, true)
  43. GUI:Text_setString(self.view.Name, string.format("<color=%s>lv.%s%s</color>", "#706c6c",self.data.level , self.data.name))
  44. else
  45. GUI:setGrey(self.view.Icon, false)
  46. GUI:setVisible(self.view.Icon,false)
  47. end
  48. end
  49. function this:SetDead()
  50. GUI:Image_loadTexture(self.view.Icon, self.iconName, "Atlas/UIMapPanel.spriteatlas")
  51. GUI:Text_setString(self.view.Name, string.format("<color=%s>%s</color>", "#706c6c", self.txtName))
  52. if self.data.headPicture then
  53. SL:ScheduleOnce(self.data.headPicture, function()
  54. GUI:SetActive(self.view.Icon, true)
  55. GUI:Image_setGrey(self.view.Icon, true)
  56. GUI:SetImageNativeSize(self.view.Icon)
  57. end)
  58. else
  59. GUI:SetActive(self.view.Icon, true)
  60. GUI:Image_setGrey(self.view.Icon, true)
  61. GUI:SetImageNativeSize(self.view.Icon)
  62. end
  63. end
  64. function this:SetLive()
  65. GUI:SetActive(self.view.Icon, true)
  66. GUI:Image_setGrey(self.view.Icon, false)
  67. GUI:Image_loadTexture(self.view.Icon, self.iconName, "Atlas/UIMapPanel.spriteatlas")
  68. self:SetNormalTextColor()
  69. GUI:SetImageNativeSize(self.view.Icon)
  70. end
  71. -- 初始化或者刷新界面时调用(如果不需要刷新整个模板,另外写函数调用(推荐方式))
  72. function this:ShowBigMonsterIcon(v, isSpecial)
  73. GUI:SetActive(self.view.root, true)
  74. self.data = SL:GetConfig("cfg_monster",v.configId)
  75. self.iconName = self.data.efficiencyLvIcon
  76. if self.data.monsterShowIcon == 1 or isSpecial then
  77. GUI:SetActive(self.view.Icon, true)
  78. GUI:Image_loadTexture(self.view.Icon, self.iconName, "Atlas/UIMapPanel.spriteatlas")
  79. else
  80. GUI:SetActive(self.view.Icon, false)
  81. end
  82. GUI:SetImageNativeSize(self.view.Icon)
  83. GUI:SetActive(self.view.Lv, false)
  84. self.txtName = self:GetMonsterName(self.data,isSpecial)
  85. GUI:Text_setString(self.view.Name, self.txtName)
  86. self:SetNormalTextColor()
  87. end
  88. ---@param monster cfg_monster_column
  89. function this:GetMonsterName(monster,isSpecial)
  90. local txt = ""
  91. if monster.monsterShowName == 1 or isSpecial then
  92. GUI:SetActive(self.view.Name, true)
  93. txt = self.data.name
  94. end
  95. if monster.monsterShowLv == 1 or isSpecial then
  96. txt = "lv." .. self.data.level .. self.data.name
  97. else
  98. GUI:SetActive(self.view.Lv, false)
  99. end
  100. return txt
  101. end
  102. ---显示小怪图标
  103. ---@param monster cfg_monster_column
  104. function this:ShowNormalMonsterIcon(monster)
  105. GUI:Text_setString(self.view.Name, self:GetMonsterName(monster))
  106. GUI:setGrey(self.view.Icon, false)
  107. GUI:SetActive(self.view.root, true)
  108. GUI:SetActive(self.view.Icon, true)
  109. GUI:SetActive(self.view.Lv, false)
  110. if monster then
  111. ---@type cfg_monster_column
  112. local monsterTbl = monster.data.monsterTbl
  113. self.data = monsterTbl
  114. if monsterTbl and monsterTbl.type and monsterTbl.level and monsterTbl.type ~= MonsterType.NormalMonster then
  115. if monsterTbl.efficiencyLvIcon then
  116. GUI:Image_loadTexture(self.view.Icon, monsterTbl.efficiencyLvIcon, "Atlas/UIMapPanel.spriteatlas")
  117. end
  118. if monsterTbl.name then
  119. self.txtName = "lv." .. monsterTbl.level .. monsterTbl.name
  120. self:SetNormalTextColor()
  121. else
  122. GUI:Text_setString(self.view.Name, "")
  123. end
  124. else
  125. GUI:Image_loadTexture(self.view.Icon, "img_minimap__shuaguaidian", "Atlas/UIMapPanel.spriteatlas")
  126. GUI:Text_setString(self.view.Name, "")
  127. end
  128. end
  129. GUI:SetImageNativeSize(self.view.Icon)
  130. end
  131. function this:SetNormalTextColor()
  132. if self.data and self.data.txtColor then
  133. if SL:GetConfig("cfg_color", self.data.txtColor) then
  134. local strColor = SL:GetConfig("cfg_color", self.data.txtColor).color
  135. GUI:Text_setString(self.view.Name, string.format("<color=%s>%s</color>", strColor, self.txtName))
  136. end
  137. end
  138. end
  139. ---注册UI事件和服务器消息
  140. function this:RegistEvents()
  141. end
  142. function this:Close()
  143. end
  144. return this