Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Health Text hide if empty/full #37

Merged
merged 4 commits into from
Aug 29, 2024
Merged
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
1 change: 1 addition & 0 deletions Data/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const.OPTION_KIND = {
ICON = "icon",
ZOOM = "zoom",
SPELL_WIDTH = "spellWidth",
HIDE_IF_EMPTY_OR_FULL = "hideIfEmptyOrFull",
}

---@enum AURA_OPTION_KIND
Expand Down
11 changes: 8 additions & 3 deletions Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ end

---@param option Frame
---@param prevOptions Frame
function Builder:AnchorBelow(option, prevOptions)
option:SetPoint("TOPLEFT", prevOptions, 0, -self.spacingY)
---@param spacingY number?
function Builder:AnchorBelow(option, prevOptions, spacingY)
option:SetPoint("TOPLEFT", prevOptions, 0, -(spacingY or self.spacingY))
end

---@param option Frame
Expand Down Expand Up @@ -839,7 +840,7 @@ function Builder:CreateHealthFormatOptions(parent, widgetName)

---@class HealthFormatOptions: OptionsFrame
local f = CUF:CreateFrame(nil, parent, 1, 1, true, true)
f.optionHeight = 70
f.optionHeight = 100
f.id = "HealthFormatOptions"

f.formatDropdown = self:CreateDropdown(parent, widgetName, "Format", 200,
Expand All @@ -863,6 +864,10 @@ function Builder:CreateHealthFormatOptions(parent, widgetName)
SetEnabled(text == L["Custom"])
end)

f.hideIfEmptyOrFull = self:CreateCheckBox(f, widgetName, L["hideIfEmptyOrFull"],
const.OPTION_KIND.HIDE_IF_EMPTY_OR_FULL)
self:AnchorBelow(f.hideIfEmptyOrFull, f.formatEditBox, 35)

local function LoadPageDB()
SetEnabled(HandleWidgetOption(widgetName, const.OPTION_KIND.FORMAT) == const.HealthTextFormat.CUSTOM)
end
Expand Down
11 changes: 10 additions & 1 deletion Widgets/Texts/HealthText.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function W.UpdateHealthTextWidget(button, unit, setting, subSetting, ...)
widget:SetTextFormat(styleTable.textFormat)
widget:SetFormat(styleTable.format)
end
if not setting or setting == const.OPTION_KIND.HIDE_IF_EMPTY_OR_FULL then
widget.hideIfEmptyOrFull = styleTable.hideIfEmptyOrFull
end

if widget.enabled and button:IsVisible() then
widget.Update(button)
Expand Down Expand Up @@ -343,6 +346,7 @@ function W:CreateHealthText(button)

healthText.textFormat = ""
healthText._showingAbsorbs = false
healthText.hideIfEmptyOrFull = false

healthText.SetFormat = HealthText_SetFormat
healthText.SetTextFormat = HealthText_SetTextFormat
Expand All @@ -351,7 +355,12 @@ function W:CreateHealthText(button)
function healthText:UpdateValue()
local health, healthMax, totalAbsorbs = GetHealthInfo(self._owner.states.displayedUnit, self._showingAbsorbs)
if self.enabled and healthMax ~= 0 then
self:SetValue(health, healthMax, totalAbsorbs)
if self.hideIfEmptyOrFull and (health == 0 or health == healthMax) then
self:Hide()
else
self:SetValue(health, healthMax, totalAbsorbs)
self:Show()
end
end
end

Expand Down