RefreshActorHUDLabelCommand.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. local RefreshActorHUDLabelCommand = class('RefreshActorHUDLabelCommand', framework.SimpleCommand)
  2. local MMO = global.MMO
  3. local sLen = string.len
  4. local proxyUtils = requireProxy( "proxyUtils" )
  5. local optionsUtils = requireProxy( "optionsUtils" )
  6. local checkPlayerGuildName = proxyUtils.checkPlayerGuildName
  7. -- 以下三个局部变量改变的时候
  8. -- 解决封号显示隐藏后现有机制下动态改变上部称号问题
  9. --[[
  10. 整体结构:
  11. 图片称号
  12. 封号
  13. 血量文本
  14. 血条
  15. ------------ 分割
  16. 前缀文本
  17. 行会信息
  18. 角色名
  19. 血量血条固定 封号称号在上
  20. 下部为分割线为起点 向下排
  21. ]]
  22. local heightMob = (SL:GetMetaValue("GAME_DATA","sceneFontSize") or SL:GetMetaValue("GAME_DATA","SCENE_FONT_SIZE")) + 2
  23. local heightWin = (SL:GetMetaValue("GAME_DATA","sceneFontSize_pc") or SL:GetMetaValue("GAME_DATA","SCENE_FONT_SIZE_PC")) + 2
  24. local height = global.isWinPlayMode and heightWin or heightMob
  25. local LABEL_HUD_HEIGHT =
  26. {
  27. [MMO.HUD_LABEL_NAME] = height,
  28. [MMO.HUD_LABEL_GUILD] = height,
  29. [MMO.HUD_LABEL_HP] = 18,
  30. [MMO.HUD_LABEL_PRE_NAME1] = height,
  31. [MMO.HUD_LABEL_PRE_NAME2] = height,
  32. [MMO.HUD_LABEL_PRE_NAME3] = height,
  33. [MMO.HUD_LABEL_PRE_NAME4] = height,
  34. [MMO.HUD_LABEL_PRE_NAME5] = height,
  35. [MMO.HUD_LABEL_PRE_NAME6] = height,
  36. [MMO.HUD_LABEL_PRE_NAME7] = height,
  37. [MMO.HUD_LABEL_PRE_NAME8] = height,
  38. [MMO.HUD_LABEL_PRE_NAME9] = height,
  39. [MMO.HUD_LABEL_PRE_NAME10] = height,
  40. [MMO.HUD_LABEL_PRE_NAME11] = height,
  41. [MMO.HUD_LABEL_PRE_NAME12] = height,
  42. }
  43. function RefreshActorHUDLabelCommand:ctor()
  44. self._downOffY = 0
  45. if global.isWinPlayMode then
  46. self._downOffY = self._downOffY + 5
  47. elseif SL:GetMetaValue("GAME_DATA", "MobileHudNotUseBmpFont") == 1 then
  48. self._downOffY = self._downOffY + 5
  49. end
  50. end
  51. function RefreshActorHUDLabelCommand:execute(notification)
  52. local data = notification:getBody()
  53. if not data.actor or not data.hudParam then
  54. return nil
  55. end
  56. local actor = global.actorManager:GetActor(data.actorID)
  57. if not actor then
  58. return nil
  59. end
  60. local hudParam = data.hudParam
  61. local nameColor = hudParam and hudParam.nameColor
  62. if nameColor then --只更新名字颜色
  63. self:refreshLableNameColor(actor,nameColor)
  64. return
  65. end
  66. local actorID = actor:GetID()
  67. local actorType = actor:GetType()
  68. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  69. -- 行会战、安全区内
  70. local oldColor = nil
  71. if actor:IsPlayer() or actor:IsMonster() then
  72. if hudParam.Color and actor:IsWarZone() and actor:GetInSafeZone() then
  73. oldColor = hudParam.Color
  74. hudParam.Color = 255
  75. end
  76. end
  77. -- 解开称号字符 分为称号列表和玩家名字
  78. -- 展示顺序 1.前缀文本 2.行会信息 3.角色名
  79. local spName = actor:GetONameStr()
  80. local nameStr = string.split(spName, "\\")
  81. local showName = nameStr[1]
  82. table.remove(nameStr, 1)
  83. table.removebyvalue(nameStr, "", true)
  84. if actor:IsNPC() then
  85. if actor:GetBubbleName() then
  86. showName = ""
  87. end
  88. end
  89. -- check visible
  90. local labelNameVisible = actor:GetValueByKey(MMO.HUD_NAMELabel_VISIBLE) or actor:GetValueByKey(MMO.HUD_PC_MOUSE_SHOW)
  91. local labelGuildVisible = actor:GetValueByKey(MMO.HUD_GUILDLabel_VISIBLE) or actor:GetValueByKey(MMO.HUD_PC_MOUSE_SHOW)
  92. local labelTitleVisible = actor:GetValueByKey(MMO.HUD_TITLELabel_VISIBLE) or actor:GetValueByKey(MMO.HUD_PC_MOUSE_SHOW)
  93. -- 封号
  94. for index=1,12 do
  95. self:refreshLabelTitle(actor, hudParam, labelTitleVisible, nameStr[index], index)
  96. end
  97. -- guild name
  98. self:refreshLabelGuild( actor, hudParam, labelGuildVisible )
  99. if not actor:IsPlayer() and GUIFunction.OnRefreshActorHudName then
  100. showName = GUIFunction:OnRefreshActorHudName(actorID, showName)
  101. end
  102. -- name
  103. self:refreshLabelName( actor, hudParam, labelNameVisible, showName)
  104. optionsUtils:refreshLabelName( actor )
  105. -- refresh actor position
  106. local pos = actor:getPosition()
  107. actor:setPosition( pos.x, pos.y )
  108. -- record player hud param
  109. if actorType == MMO.ACTOR_PLAYER then
  110. SetActorAttr( actor, MMO.ACTOR_ATTR_HUDPARAM, hudParam )
  111. end
  112. if oldColor then
  113. hudParam.Color = oldColor
  114. end
  115. end
  116. function RefreshActorHUDLabelCommand:operateLabelHUD( actorID, hudType, hudIndex, content, color, visible, offsetY, offsetX )
  117. local hudLabel = nil
  118. offsetX = offsetX or 0
  119. if not content or "" == content then -- remove
  120. global.HUDManager:RemoveHUD( actorID, hudType, hudIndex )
  121. else
  122. hudLabel = global.HUDManager:GetHUD( actorID, hudType, hudIndex )
  123. if not hudLabel then -- create
  124. hudLabel = global.HUDManager:CreateHUD( actorID, hudType, hudIndex, cc.p(offsetX, offsetY) )
  125. hudLabel:setAlignment( cc.TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM )
  126. end
  127. global.HUDManager:SetHUDOffset(actorID, hudType, hudIndex, cc.p(offsetX, offsetY) )
  128. hudLabel:setVisible( visible )
  129. hudLabel:setString( content )
  130. hudLabel:setColor( color )
  131. end
  132. return hudLabel
  133. end
  134. function RefreshActorHUDLabelCommand:refreshLabelName( actor, hudParam, visible, showName)
  135. local actorID = actor:GetID()
  136. local hudType = MMO.HUD_TYPE_BATCH_LABEL
  137. local color = nil
  138. if actor:IsDropItem() then
  139. color = GetColorFromHex( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
  140. hudType = MMO.HUD_TYPE_BATCH_LABEL
  141. else
  142. color = GET_COLOR_BYID_C3B( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
  143. end
  144. local offX = 2
  145. local setOffsetYTab = global.ConstantConfig.HudLabelShowOffsetYMap or {}
  146. if actor:IsPlayer() then
  147. self._downOffY = self._downOffY + (setOffsetYTab[1] or 0)
  148. elseif actor:IsMonster() then
  149. self._downOffY = self._downOffY + (setOffsetYTab[3] or 0)
  150. elseif actor:IsNPC() then
  151. self._downOffY = self._downOffY + (setOffsetYTab[5] or 0)
  152. end
  153. local hudLabel = self:operateLabelHUD( actorID, hudType, MMO.HUD_LABEL_NAME, showName, color, visible, self._downOffY, offX )
  154. -- record off y
  155. if visible and showName then
  156. self._downOffY = self._downOffY - LABEL_HUD_HEIGHT[MMO.HUD_LABEL_NAME]
  157. end
  158. end
  159. function RefreshActorHUDLabelCommand:refreshLabelTitle( actor, hudParam, visible, titleStr, index)
  160. local actorID = actor:GetID()
  161. local hudType = MMO.HUD_TYPE_BATCH_LABEL
  162. local hudIndex = MMO.HUD_LABEL_PRE_NAME1 - 1 + index
  163. if not LABEL_HUD_HEIGHT[hudIndex] then
  164. return
  165. end
  166. local offX = 2
  167. local color = GET_COLOR_BYID_C3B( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
  168. local hudLabel = self:operateLabelHUD( actorID, hudType, hudIndex, titleStr, color, visible, self._downOffY, offX )
  169. -- record off y
  170. if visible and titleStr and sLen(titleStr) > 0 then
  171. self._downOffY = self._downOffY - LABEL_HUD_HEIGHT[hudIndex]
  172. end
  173. end
  174. function RefreshActorHUDLabelCommand:refreshLabelGuild( actor, hudParam, visible )
  175. local actorID = actor:GetID()
  176. local hudType = MMO.HUD_TYPE_BATCH_LABEL
  177. local guildName = hudParam.GuildName
  178. -- guild name
  179. if guildName and actor:IsPlayer() then
  180. guildName = checkPlayerGuildName(guildName, hudParam.RankName, hudParam.castlename)
  181. end
  182. local color = GET_COLOR_BYID_C3B( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
  183. self:operateLabelHUD( actorID, hudType, MMO.HUD_LABEL_GUILD, guildName, color, visible, self._downOffY )
  184. -- record off y
  185. if visible and guildName and sLen(guildName)>0 then
  186. self._downOffY = self._downOffY - LABEL_HUD_HEIGHT[MMO.HUD_LABEL_GUILD]
  187. end
  188. end
  189. -- 刷新label颜色
  190. function RefreshActorHUDLabelCommand:refreshLableNameColor(actor, nameColor)
  191. local actorID = actor:GetID()
  192. local hudType = MMO.HUD_TYPE_BATCH_LABEL
  193. local color = nil
  194. if actor:IsDropItem() then
  195. color = GetColorFromHex( nameColor or MMO.HUD_COLOR_DEFAULT )
  196. hudType = MMO.HUD_TYPE_BATCH_LABEL
  197. else
  198. color = GET_COLOR_BYID_C3B( nameColor or MMO.HUD_COLOR_DEFAULT )
  199. end
  200. -- 角色名
  201. local nameHudLabel = global.HUDManager:GetHUD( actorID, hudType, MMO.HUD_LABEL_NAME )
  202. if nameHudLabel then
  203. nameHudLabel:setColor(color)
  204. end
  205. -- 行会名
  206. local guildHudLabel = global.HUDManager:GetHUD( actorID, hudType, MMO.HUD_LABEL_GUILD )
  207. if guildHudLabel then
  208. guildHudLabel:setColor(color)
  209. end
  210. -- 封号
  211. for index=1,12 do
  212. local hudIndex = MMO.HUD_LABEL_PRE_NAME1 - 1 + index
  213. local titleHudLabel = global.HUDManager:GetHUD( actorID, hudType, hudIndex )
  214. if titleHudLabel then
  215. titleHudLabel:setColor(color)
  216. end
  217. end
  218. end
  219. return RefreshActorHUDLabelCommand