diff --git a/SlightlyImprovedUnitFrames.lua b/SlightlyImprovedUnitFrames.lua index 8df57ab..1b57209 100644 --- a/SlightlyImprovedUnitFrames.lua +++ b/SlightlyImprovedUnitFrames.lua @@ -1,4 +1,4 @@ --- SlightlyImprovedUnitFrames 0.2.0beta +-- SlightlyImprovedUnitFrames 0.4.0 beta_250816 -- Licensed under CC-BY-NC-SA-4.0 local SIUF = "SlightlyImprovedUnitFrames" @@ -11,33 +11,35 @@ local function d() end -- local function Siuf_CreateControl(suffix, parent, template) - return CreateControlFromVirtual(parent:GetName()..suffix, parent, template) + return CreateControlFromVirtual(parent:GetName()..suffix, parent, template) end local function Siuf_UpdateGroupBarText(control, healthPool, maxHealthPool) - -- local healthPool, maxHealthPool = GetUnitPower(unitTag, POWERTYPE_HEALTH) - local percentage = (healthPool > 0) and zo_round(healthPool * 100 / maxHealthPool) or 0 - control:SetText(string.format("%d / %d (%d%%)", healthPool, maxHealthPool, percentage)) + -- local healthPool, maxHealthPool = GetUnitPower(unitTag, POWERTYPE_HEALTH) + local percentage = (healthPool > 0) and zo_round(healthPool * 100 / maxHealthPool) or 0 + control:SetText(string.format("%d / %d (%d%%)", healthPool, maxHealthPool, percentage)) + end local function Siuf_UpdateGroupTagText(control, unitTag) - control:SetText(unitTag) + control:SetText(unitTag) end -local function Siuf_UpdateGroupClassIcon(control, classId, gender, level, veteranRank) - local texture = GetClassIcon(classId) +local function Siuf_UpdateGroupClassIcon(control, classId, gender, level, championRank) + local texture = GetClassIcon(classId) - control.tooltipText = zo_strformat(SI_CLASS_NAME, GetClassName(gender, classId)) + control.tooltipText = zo_strformat(SI_CLASS_NAME, GetClassName(gender, classId)) - if (veteranRank > 0) then - local icon = zo_iconFormat("esoui/art/lfg/lfg_veterandungeon_up.dds", 28, 28) - control.tooltipText = control.tooltipText..icon..veteranRank - else - local icon = zo_iconFormat("esoui/art/lfg/lfg_normaldungeon_up.dds", 28, 28) - control.tooltipText = control.tooltipText..icon..level - end + if (championRank > 0) then + local icon = zo_iconFormat("esoui/art/lfg/lfg_championdungeon_up.dds", 28, 28) + control.tooltipText = control.tooltipText..icon..championRank + else + local icon = zo_iconFormat("esoui/art/lfg/lfg_normaldungeon_up.dds", 28, 28) + control.tooltipText = control.tooltipText..icon..level + end + + control:SetTexture(GetClassIcon(classId)) - control:SetTexture(GetClassIcon(classId)) end -- @@ -45,113 +47,207 @@ end -- local function Siuf_ImproveGroupUnitFrame(unitFrame) - local unitTag = unitFrame.unitTag - unitFrame.hasBeenSlightlyImproved = true + local unitTag = unitFrame.unitTag + unitFrame.hasBeenSlightlyImproved = true - -- Display health bar text - local healthBarControl = unitFrame.healthBar.barControls[1] - unitFrame.siufHealthBarText = Siuf_CreateControl("SiufBarText", healthBarControl, "SiufGroupBarText") + -- Display health bar text + local healthBarControl = unitFrame.healthBar.barControls[1] + unitFrame.siufHealthBarText = Siuf_CreateControl("SiufBarText", healthBarControl, "SiufGroupBarText") - local healthPool, maxHealthPool = GetUnitPower(unitTag, POWERTYPE_HEALTH) - Siuf_UpdateGroupBarText(unitFrame.siufHealthBarText, healthPool, maxHealthPool) + local healthPool, maxHealthPool = GetUnitPower(unitTag, POWERTYPE_HEALTH) + Siuf_UpdateGroupBarText(unitFrame.siufHealthBarText, healthPool, maxHealthPool) - -- Display character class icon - unitFrame.siufClassIcon = Siuf_CreateControl("SiufClassIcon", unitFrame.frame, "SiufGroupClassIcon") - table.insert(unitFrame.fadeComponents, unitFrame.siufClassIcon) + -- Display character class icon + unitFrame.siufClassIcon = Siuf_CreateControl("SiufClassIcon", unitFrame.frame, "SiufGroupClassIcon") + table.insert(unitFrame.fadeComponents, unitFrame.siufClassIcon) - local classId = GetUnitClassId(unitTag) - local gender = GetUnitGender(unitTag) - local level = GetUnitLevel(unitTag) - local veteranRank = GetUnitVeteranRank(unitTag) - Siuf_UpdateGroupClassIcon(unitFrame.siufClassIcon, classId, gender, level, veteranRank) + local classId = GetUnitClassId(unitTag) + local gender = GetUnitGender(unitTag) + local level = GetUnitLevel(unitTag) + local championRank = GetUnitChampionPoints(unitTag) + Siuf_UpdateGroupClassIcon(unitFrame.siufClassIcon, classId, gender, level, championRank) - -- DEBUG: Display unit tag - -- unitFrame.siufTagText = Siuf_CreateControl("SiufTagText", unitFrame.frame, "SiufGroupTagText") - -- Siuf_UpdateGroupTagText(unitFrame.siufTagText, unitTag) + -- DEBUG: Display unit tag + -- unitFrame.siufTagText = Siuf_CreateControl("SiufTagText", unitFrame.frame, "SiufGroupTagText") + -- Siuf_UpdateGroupTagText(unitFrame.siufTagText, unitTag) - unitFrame:RefreshControls() + unitFrame:RefreshControls() + + end local function Siuf_ShouldImproveUnitFrame(unitFrame) - return (unitFrame and not unitFrame.hasBeenSlightlyImproved and string.find(unitFrame.unitTag, "group", 1, true) == 1 and IsUnitOnline(unitFrame.unitTag)) + return unitFrame and (not unitFrame.hasBeenSlightlyImproved) and IsUnitOnline(unitFrame.unitTag) and (GetGroupSize() <= 4) end local function Siuf_ShouldUpdateUnitFrame(unitFrame) - return (unitFrame and unitFrame.hasBeenSlightlyImproved and string.find(unitFrame.unitTag, "group", 1, true) == 1 and IsUnitOnline(unitFrame.unitTag)) + return unitFrame.hasBeenSlightlyImproved end -- -- -- +local function OnPowerUpdate(event, unitTag, powerPoolIndex, powerType, powerPool, powerPoolMax) + if ZO_Group_IsGroupUnitTag(unitTag) then + d(GetString(SI_SIUF_POWER_UPDATE), unitTag) + local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) + if Siuf_ShouldUpdateUnitFrame(unitFrame) then + local healthPool, maxHealthPool = GetUnitPower(unitTag, POWERTYPE_HEALTH) + Siuf_UpdateGroupBarText(unitFrame.siufHealthBarText, healthPool, maxHealthPool) + Siuf_handleUnitFrames() + end + end +end + +local function OnLevelUpdate(event, unitTag) + if ZO_Group_IsGroupUnitTag(unitTag) then + d(GetString(SI_SIUF_LEVEL_UPDATE), unitTag) + local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) + if Siuf_ShouldUpdateUnitFrame(unitFrame) then + local classId = GetUnitClassId(unitTag) + local gender = GetUnitGender(unitTag) + local level = GetUnitLevel(unitTag) + local championRank = GetUnitChampionPoints(unitTag) + Siuf_UpdateGroupClassIcon(unitFrame.siufClassIcon, classId, gender, level, championRank) + Siuf_handleUnitFrames() + end + end +end + +local function OnChampionPointUpdate(event, unitTag) + if ZO_Group_IsGroupUnitTag(unitTag) then + d(GetString(SI_SIUF_CP_UPDATE), unitTag) + local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) + if Siuf_ShouldUpdateUnitFrame(unitFrame) then + local classId = GetUnitClassId(unitTag) + local gender = GetUnitGender(unitTag) + local level = GetUnitLevel(unitTag) + local championRank = GetUnitChampionPoints(unitTag) + Siuf_UpdateGroupClassIcon(unitFrame.siufClassIcon, classId, gender, level, championRank) + end + end +end + local function OnUnitCreated(event, unitTag) - d("Unit created", unitTag) - local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) - if Siuf_ShouldImproveUnitFrame(unitFrame) then - Siuf_ImproveGroupUnitFrame(unitFrame) - end + if ZO_Group_IsGroupUnitTag(unitTag) then + d(GetString(SI_SIUF_UNIT_CREATED), unitTag) + + local pollCount = 0 + local pollLimit = 20 + local pollInterval = 100 + local pollGroupUnitFrame + + pollGroupUnitFrame = function() + local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) + if unitFrame then + if Siuf_ShouldImproveUnitFrame(unitFrame) then + Siuf_ImproveGroupUnitFrame(unitFrame) + end + else + if (pollCount < pollLimit) then + zo_callLater(pollGroupUnitFrame, pollInterval) + pollCount = pollCount + 1 + else + d(GetString(SI_SIUF_UNITFRAME_NOT_READY)) + end + end + end + + pollGroupUnitFrame() + + end + end -local function OnPowerUpdate(event, unitTag, powerPoolIndex, powerType, powerPool, powerPoolMax) - d("Power update", unitTag) - local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) - if Siuf_ShouldUpdateUnitFrame(unitFrame) then - local healthPool, maxHealthPool = GetUnitPower(unitTag, POWERTYPE_HEALTH) - Siuf_UpdateGroupBarText(unitFrame.siufHealthBarText, healthPool, maxHealthPool) - end +local function OnPlayerActivated() + if IsUnitGrouped("player") and (GetGroupSize() <= 4) then + local pollCount = 0 + local pollLimit = 10 + local pollInterval = 500 + local pollGroupUnitFrames + + pollGroupUnitFrames = function() + if (UNIT_FRAMES.groupSize > 0) then + for unitTag, unitFrame in pairs(UNIT_FRAMES.groupFrames) do + if (Siuf_ShouldImproveUnitFrame(unitFrame)) then + Siuf_ImproveGroupUnitFrame(unitFrame) + if nil == unitFrame then return false end + end + end + else + if (pollCount < pollLimit) then + zo_callLater(pollGroupUnitFrames, pollInterval) + pollCount = pollCount + 1 + else + d(GetString(SI_SIUF_UNITFRAME_NOT_READY)) + end + end + end + + pollGroupUnitFrames() + + end end -local function OnLevelUpdate(event, unitTag) - d("Level update", unitTag) - local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) - if Siuf_ShouldUpdateUnitFrame(unitFrame) then - local classId = GetUnitClassId(unitTag) - local gender = GetUnitGender(unitTag) - local level = GetUnitLevel(unitTag) - local veteranRank = GetUnitVeteranRank(unitTag) - Siuf_UpdateGroupClassIcon(unitFrame.siufClassIcon, classId, gender, level, veteranRank) - end -end - -local function OnVeteranRankUpdate(event, unitTag) - d("VR update", unitTag) - local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) - if Siuf_ShouldUpdateUnitFrame(unitFrame) then - local classId = GetUnitClassId(unitTag) - local gender = GetUnitGender(unitTag) - local level = GetUnitLevel(unitTag) - local veteranRank = GetUnitVeteranRank(unitTag) - Siuf_UpdateGroupClassIcon(unitFrame.siufClassIcon, classId, gender, level, veteranRank) - end -end - -local function OnPlayerActivated(event, ...) - for unitTag, unitFrame in pairs(UNIT_FRAMES.groupFrames) do - d(unitTag, Siuf_ShouldImproveUnitFrame(unitFrame)) - - if Siuf_ShouldImproveUnitFrame(unitFrame) then - Siuf_ImproveGroupUnitFrame(unitFrame) - end - end +local function OnGroupMemberConnectedStatus(event, unitTag) + if IsUnitOnline(unitTag) then + local unitFrame = ZO_UnitFrames_GetUnitFrame(unitTag) + if Siuf_ShouldImproveUnitFrame(unitFrame) then + Siuf_ImproveGroupUnitFrame(unitFrame) + end + end end +-- +-- +-- + +local function tryHideControl(control) + if nil == control then d("control is nil") return end + control:SetHidden(true) + d(control:GetName()) +end + +function Siuf_handleUnitFrames() + + if not IsUnitGrouped('player') then return end + + tryHideControl(ZO_GroupUnitFramegroup1RoleIcon) + tryHideControl(ZO_GroupUnitFramegroup2RoleIcon) + tryHideControl(ZO_GroupUnitFramegroup3RoleIcon) + tryHideControl(ZO_GroupUnitFramegroup4RoleIcon) + +end + +--[[ +SLASH_COMMANDS["/siuf"] = function() + Siuf_handleUnitFrames() +end +]]-- + local function OnAddOnLoaded(event, addOnName) if (addOnName == SIUF) then - EVENT_MANAGER:UnregisterForEvent(SIUF, EVENT_ADD_ON_LOADED) - - EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_PLAYER_ACTIVATED, OnPlayerActivated) - EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_UNIT_CREATED, OnUnitCreated) - EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_POWER_UPDATE, OnPowerUpdate) - EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_LEVEL_UPDATE, OnLevelUpdate) - EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_VETERAN_RANK_UPDATE, OnVeteranRankUpdate) - - local filters = - { - REGISTER_FILTER_UNIT_TAG_PREFIX, "group", - REGISTER_FILTER_POWER_TYPE, POWERTYPE_HEALTH, - } - EVENT_MANAGER:AddFilterForEvent(SIUF, EVENT_POWER_UPDATE, unpack(filters)) - end + + zo_callLater(function() Siuf_handleUnitFrames() end, 1000) + + EVENT_MANAGER:UnregisterForEvent(SIUF, EVENT_ADD_ON_LOADED) + + EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_UNIT_CREATED, OnUnitCreated) + EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_PLAYER_ACTIVATED, OnPlayerActivated) + EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_GROUP_MEMBER_CONNECTED_STATUS, OnGroupMemberConnectedStatus) + + EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_POWER_UPDATE, OnPowerUpdate) + EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_LEVEL_UPDATE, OnLevelUpdate) + EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_CHAMPION_POINT_UPDATE, OnChampionPointUpdate) + + local filters = + { + REGISTER_FILTER_UNIT_TAG_PREFIX, GetString(SI_SIUF_UNITFRAME_GROUP), + REGISTER_FILTER_POWER_TYPE, POWERTYPE_HEALTH, + } + EVENT_MANAGER:AddFilterForEvent(SIUF, EVENT_POWER_UPDATE, unpack(filters)) + end end EVENT_MANAGER:RegisterForEvent(SIUF, EVENT_ADD_ON_LOADED, OnAddOnLoaded) diff --git a/SlightlyImprovedUnitFrames.txt b/SlightlyImprovedUnitFrames.txt index ead558b..b46b6ff 100644 --- a/SlightlyImprovedUnitFrames.txt +++ b/SlightlyImprovedUnitFrames.txt @@ -1,9 +1,16 @@ -## APIVersion: 100013 +## APIVersion: 100017 100016 ## Title: SlightlyImprovedUnitFrames -## Description: ... -## Version: 0.2.0beta +## Description: Shows current pool, max pool and percentage on group unit frame health bars. Shows player's class icon with a tooltip that says the class name and player level. +## Version: 0.4.0 beta_250816 ## Author: haggen +## OptionalDependsOn: GroupRegenTracker ## License: CC-BY-NC-SA-4.0 +## This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. +## The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. All rights reserved. You can read the full terms at https://account.elderscrollsonline.com/add-on-terms + SlightlyImprovedUnitFrames.lua SlightlyImprovedUnitFrames.xml + +lang/en.lua +lang/$(language).lua \ No newline at end of file diff --git a/SlightlyImprovedUnitFrames.xml b/SlightlyImprovedUnitFrames.xml index d11aa21..5c462cf 100644 --- a/SlightlyImprovedUnitFrames.xml +++ b/SlightlyImprovedUnitFrames.xml @@ -1,16 +1,11 @@ - - - + - + InitializeTooltip(InformationTooltip, self, LEFT, 0, 0) diff --git a/lang/de.lua b/lang/de.lua new file mode 100644 index 0000000..93b9f83 --- /dev/null +++ b/lang/de.lua @@ -0,0 +1,6 @@ +SafeAddString(SI_SIUF_POWER_UPDATE , "Power aktualisiert"); +SafeAddString(SI_SIUF_LEVEL_UPDATE , "Level aktualisiert"); +SafeAddString(SI_SIUF_CP_UPDATE , "CP aktualisiert"); +SafeAddString(SI_SIUF_UNIT_CREATED , "Gruppe erstellt"); +SafeAddString(SI_SIUF_UNITFRAME_NOT_READY , "Das Gruppenfenster konnte in dieser Zeit nicht erstellt werden."); +SafeAddString(SI_SIUF_UNITFRAME_GROUP , "Gruppe"); \ No newline at end of file diff --git a/lang/en.lua b/lang/en.lua new file mode 100644 index 0000000..e6b3de5 --- /dev/null +++ b/lang/en.lua @@ -0,0 +1,6 @@ +ZO_CreateStringId("SI_SIUF_POWER_UPDATE" , "Power update"); +ZO_CreateStringId("SI_SIUF_LEVEL_UPDATE" , "Level update"); +ZO_CreateStringId("SI_SIUF_CP_UPDATE" , "CP update"); +ZO_CreateStringId("SI_SIUF_UNIT_CREATED" , "Unit created"); +ZO_CreateStringId("SI_SIUF_UNITFRAME_NOT_READY" , "Group unit frame was not ready in due time"); +ZO_CreateStringId("SI_SIUF_UNITFRAME_GROUP" , "group.."); \ No newline at end of file