Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 193 additions & 97 deletions SlightlyImprovedUnitFrames.lua
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -11,147 +11,243 @@ 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

--
--
--

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)
13 changes: 10 additions & 3 deletions SlightlyImprovedUnitFrames.txt
Original file line number Diff line number Diff line change
@@ -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
11 changes: 3 additions & 8 deletions SlightlyImprovedUnitFrames.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<!--
SlightlyImprovedUnitFrames 0.2.0beta
Licensed under CC-BY-NC-SA-4.0
-->

<GuiXml>
<Font name="SiufBarFont" font="$(MEDIUM_FONT)|16|soft-shadow-thick"/>
<Font name="SiufBarFontSmall" font="$(MEDIUM_FONT)|13|soft-shadow-thick"/>
<Font name="SiufBarFontSmall" font="$(MEDIUM_FONT)|16|soft-shadow-thick"/>
<Font name="SiufGroupFrameFont" font="$(BOLD_FONT)|14|soft-shadow-thin"/>

<Controls>
<Label name="SiufGroupBarText" font="SiufBarFontSmall" layer="3" tier="2" level="1" virtual="true">
<Anchor point="TOP" relativePoint="BOTTOM" offsetY="-13" />
<Anchor point="TOP" relativePoint="BOTTOMLEFT" offsetX="65" offsetY="3" />
</Label>

<Label name="SiufGroupLevelText" font="SiufGroupFrameFont" color="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_NORMAL" virtual="true">
Expand All @@ -22,7 +17,7 @@ Licensed under CC-BY-NC-SA-4.0
</Label>

<Texture name="SiufGroupClassIcon" mouseEnabled="true" layer="OVERLAY" virtual="true">
<Anchor point="LEFT" />
<Anchor point="LEFT" offsetX="0" offsetY="0"/>
<Dimensions x="32" y="32"/>
<OnMouseEnter>
InitializeTooltip(InformationTooltip, self, LEFT, 0, 0)
Expand Down
Loading