| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- local RefreshActorHUDLabelCommand = class('RefreshActorHUDLabelCommand', framework.SimpleCommand)
- local MMO = global.MMO
- local sLen = string.len
- local proxyUtils = requireProxy( "proxyUtils" )
- local optionsUtils = requireProxy( "optionsUtils" )
- local checkPlayerGuildName = proxyUtils.checkPlayerGuildName
- -- 以下三个局部变量改变的时候
- -- 解决封号显示隐藏后现有机制下动态改变上部称号问题
- --[[
- 整体结构:
- 图片称号
- 封号
- 血量文本
- 血条
- ------------ 分割
- 前缀文本
- 行会信息
- 角色名
-
- 血量血条固定 封号称号在上
- 下部为分割线为起点 向下排
- ]]
- local heightMob = (SL:GetMetaValue("GAME_DATA","sceneFontSize") or SL:GetMetaValue("GAME_DATA","SCENE_FONT_SIZE")) + 2
- local heightWin = (SL:GetMetaValue("GAME_DATA","sceneFontSize_pc") or SL:GetMetaValue("GAME_DATA","SCENE_FONT_SIZE_PC")) + 2
- local height = global.isWinPlayMode and heightWin or heightMob
- local LABEL_HUD_HEIGHT =
- {
- [MMO.HUD_LABEL_NAME] = height,
- [MMO.HUD_LABEL_GUILD] = height,
- [MMO.HUD_LABEL_HP] = 18,
- [MMO.HUD_LABEL_PRE_NAME1] = height,
- [MMO.HUD_LABEL_PRE_NAME2] = height,
- [MMO.HUD_LABEL_PRE_NAME3] = height,
- [MMO.HUD_LABEL_PRE_NAME4] = height,
- [MMO.HUD_LABEL_PRE_NAME5] = height,
- [MMO.HUD_LABEL_PRE_NAME6] = height,
- [MMO.HUD_LABEL_PRE_NAME7] = height,
- [MMO.HUD_LABEL_PRE_NAME8] = height,
- [MMO.HUD_LABEL_PRE_NAME9] = height,
- [MMO.HUD_LABEL_PRE_NAME10] = height,
- [MMO.HUD_LABEL_PRE_NAME11] = height,
- [MMO.HUD_LABEL_PRE_NAME12] = height,
- }
- function RefreshActorHUDLabelCommand:ctor()
- self._downOffY = 0
- if global.isWinPlayMode then
- self._downOffY = self._downOffY + 5
- elseif SL:GetMetaValue("GAME_DATA", "MobileHudNotUseBmpFont") == 1 then
- self._downOffY = self._downOffY + 5
- end
- end
- function RefreshActorHUDLabelCommand:execute(notification)
- local data = notification:getBody()
- if not data.actor or not data.hudParam then
- return nil
- end
- local actor = global.actorManager:GetActor(data.actorID)
- if not actor then
- return nil
- end
- local hudParam = data.hudParam
- local nameColor = hudParam and hudParam.nameColor
- if nameColor then --只更新名字颜色
- self:refreshLableNameColor(actor,nameColor)
- return
- end
- local actorID = actor:GetID()
- local actorType = actor:GetType()
- local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
- -- 行会战、安全区内
- local oldColor = nil
- if actor:IsPlayer() or actor:IsMonster() then
- if hudParam.Color and actor:IsWarZone() and actor:GetInSafeZone() then
- oldColor = hudParam.Color
- hudParam.Color = 255
- end
- end
- -- 解开称号字符 分为称号列表和玩家名字
- -- 展示顺序 1.前缀文本 2.行会信息 3.角色名
- local spName = actor:GetONameStr()
- local nameStr = string.split(spName, "\\")
- local showName = nameStr[1]
- table.remove(nameStr, 1)
- table.removebyvalue(nameStr, "", true)
- if actor:IsNPC() then
- if actor:GetBubbleName() then
- showName = ""
- end
- end
- -- check visible
- local labelNameVisible = actor:GetValueByKey(MMO.HUD_NAMELabel_VISIBLE) or actor:GetValueByKey(MMO.HUD_PC_MOUSE_SHOW)
- local labelGuildVisible = actor:GetValueByKey(MMO.HUD_GUILDLabel_VISIBLE) or actor:GetValueByKey(MMO.HUD_PC_MOUSE_SHOW)
- local labelTitleVisible = actor:GetValueByKey(MMO.HUD_TITLELabel_VISIBLE) or actor:GetValueByKey(MMO.HUD_PC_MOUSE_SHOW)
- -- 封号
- for index=1,12 do
- self:refreshLabelTitle(actor, hudParam, labelTitleVisible, nameStr[index], index)
- end
-
- -- guild name
- self:refreshLabelGuild( actor, hudParam, labelGuildVisible )
-
- if not actor:IsPlayer() and GUIFunction.OnRefreshActorHudName then
- showName = GUIFunction:OnRefreshActorHudName(actorID, showName)
- end
- -- name
- self:refreshLabelName( actor, hudParam, labelNameVisible, showName)
- optionsUtils:refreshLabelName( actor )
- -- refresh actor position
- local pos = actor:getPosition()
- actor:setPosition( pos.x, pos.y )
- -- record player hud param
- if actorType == MMO.ACTOR_PLAYER then
- SetActorAttr( actor, MMO.ACTOR_ATTR_HUDPARAM, hudParam )
- end
- if oldColor then
- hudParam.Color = oldColor
- end
- end
- function RefreshActorHUDLabelCommand:operateLabelHUD( actorID, hudType, hudIndex, content, color, visible, offsetY, offsetX )
- local hudLabel = nil
- offsetX = offsetX or 0
- if not content or "" == content then -- remove
- global.HUDManager:RemoveHUD( actorID, hudType, hudIndex )
- else
- hudLabel = global.HUDManager:GetHUD( actorID, hudType, hudIndex )
- if not hudLabel then -- create
- hudLabel = global.HUDManager:CreateHUD( actorID, hudType, hudIndex, cc.p(offsetX, offsetY) )
- hudLabel:setAlignment( cc.TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM )
- end
- global.HUDManager:SetHUDOffset(actorID, hudType, hudIndex, cc.p(offsetX, offsetY) )
- hudLabel:setVisible( visible )
- hudLabel:setString( content )
- hudLabel:setColor( color )
- end
-
- return hudLabel
- end
- function RefreshActorHUDLabelCommand:refreshLabelName( actor, hudParam, visible, showName)
- local actorID = actor:GetID()
- local hudType = MMO.HUD_TYPE_BATCH_LABEL
- local color = nil
- if actor:IsDropItem() then
- color = GetColorFromHex( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
- hudType = MMO.HUD_TYPE_BATCH_LABEL
- else
- color = GET_COLOR_BYID_C3B( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
- end
- local offX = 2
- local setOffsetYTab = global.ConstantConfig.HudLabelShowOffsetYMap or {}
- if actor:IsPlayer() then
- self._downOffY = self._downOffY + (setOffsetYTab[1] or 0)
- elseif actor:IsMonster() then
- self._downOffY = self._downOffY + (setOffsetYTab[3] or 0)
- elseif actor:IsNPC() then
- self._downOffY = self._downOffY + (setOffsetYTab[5] or 0)
- end
- local hudLabel = self:operateLabelHUD( actorID, hudType, MMO.HUD_LABEL_NAME, showName, color, visible, self._downOffY, offX )
- -- record off y
- if visible and showName then
- self._downOffY = self._downOffY - LABEL_HUD_HEIGHT[MMO.HUD_LABEL_NAME]
- end
- end
- function RefreshActorHUDLabelCommand:refreshLabelTitle( actor, hudParam, visible, titleStr, index)
- local actorID = actor:GetID()
- local hudType = MMO.HUD_TYPE_BATCH_LABEL
- local hudIndex = MMO.HUD_LABEL_PRE_NAME1 - 1 + index
- if not LABEL_HUD_HEIGHT[hudIndex] then
- return
- end
- local offX = 2
- local color = GET_COLOR_BYID_C3B( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
- local hudLabel = self:operateLabelHUD( actorID, hudType, hudIndex, titleStr, color, visible, self._downOffY, offX )
- -- record off y
- if visible and titleStr and sLen(titleStr) > 0 then
- self._downOffY = self._downOffY - LABEL_HUD_HEIGHT[hudIndex]
- end
- end
- function RefreshActorHUDLabelCommand:refreshLabelGuild( actor, hudParam, visible )
- local actorID = actor:GetID()
- local hudType = MMO.HUD_TYPE_BATCH_LABEL
- local guildName = hudParam.GuildName
- -- guild name
- if guildName and actor:IsPlayer() then
- guildName = checkPlayerGuildName(guildName, hudParam.RankName, hudParam.castlename)
- end
- local color = GET_COLOR_BYID_C3B( hudParam.Color or MMO.HUD_COLOR_DEFAULT )
- self:operateLabelHUD( actorID, hudType, MMO.HUD_LABEL_GUILD, guildName, color, visible, self._downOffY )
- -- record off y
- if visible and guildName and sLen(guildName)>0 then
- self._downOffY = self._downOffY - LABEL_HUD_HEIGHT[MMO.HUD_LABEL_GUILD]
- end
- end
- -- 刷新label颜色
- function RefreshActorHUDLabelCommand:refreshLableNameColor(actor, nameColor)
- local actorID = actor:GetID()
- local hudType = MMO.HUD_TYPE_BATCH_LABEL
- local color = nil
- if actor:IsDropItem() then
- color = GetColorFromHex( nameColor or MMO.HUD_COLOR_DEFAULT )
- hudType = MMO.HUD_TYPE_BATCH_LABEL
- else
- color = GET_COLOR_BYID_C3B( nameColor or MMO.HUD_COLOR_DEFAULT )
- end
- -- 角色名
- local nameHudLabel = global.HUDManager:GetHUD( actorID, hudType, MMO.HUD_LABEL_NAME )
- if nameHudLabel then
- nameHudLabel:setColor(color)
- end
-
- -- 行会名
- local guildHudLabel = global.HUDManager:GetHUD( actorID, hudType, MMO.HUD_LABEL_GUILD )
- if guildHudLabel then
- guildHudLabel:setColor(color)
- end
-
- -- 封号
- for index=1,12 do
- local hudIndex = MMO.HUD_LABEL_PRE_NAME1 - 1 + index
- local titleHudLabel = global.HUDManager:GetHUD( actorID, hudType, hudIndex )
- if titleHudLabel then
- titleHudLabel:setColor(color)
- end
- end
- end
- return RefreshActorHUDLabelCommand
|