mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-27 18:06:02 +00:00
Move druid mana bar into the unit frame, off nampower
The druid secondary mana bar (shown while shapeshifted into a form that uses energy/rage) lived in nampower.lua and read base mana through nampower's GetUnitField. Extract it into the unit frame proper and drive it with ClassicAPI instead: - Create pfDruidMana_<unit> as f.druidmana in CreateUnitFrame (player and target), lay it out in UpdateConfig from the existing C.unitframes.druidmana* keys, and update it in a new pfUI.uf:UpdateDruidMana driven by the frame's own base-refresh pass (UNIT_MANA / UNIT_DISPLAYPOWER). No separate event frames, no nampower dependency. - Read mana via UnitPower(unit, 0) / UnitPowerMax(unit, 0), the ClassicAPI slot getters that return the mana pool regardless of the active power, so it works while in Cat/Bear form. - Add a "Show Druid Mana Bar Text" toggle (druidmanatext) so the current/max readout can be hidden while keeping the bar; config default, GUI checkbox, and locale stubs. - Remove the now-dead block from nampower.lua.
This commit is contained in:
@@ -231,6 +231,7 @@ function pfUI:LoadConfig()
|
||||
pfUI:UpdateConfig("unitframes", nil, "druidmanaoffy", "0")
|
||||
pfUI:UpdateConfig("unitframes", nil, "druidmanaspace", "-3")
|
||||
pfUI:UpdateConfig("unitframes", nil, "druidmanatexture", "Interface\\AddOns\\pfUI\\img\\bar")
|
||||
pfUI:UpdateConfig("unitframes", nil, "druidmanatext", "1")
|
||||
|
||||
pfUI:UpdateConfig("unitframes", nil, "combowidth", "6")
|
||||
pfUI:UpdateConfig("unitframes", nil, "comboheight", "6")
|
||||
|
||||
@@ -529,6 +529,50 @@ function pfUI.uf:UpdateConfig()
|
||||
fontstyle = C.global.font_unit_style
|
||||
end
|
||||
|
||||
-- Druid secondary mana bar: texture/color/size/position below the power bar,
|
||||
-- using its own C.unitframes.druidmana* config. Values are read in
|
||||
-- UpdateDruidMana; here we only lay it out.
|
||||
if f.druidmana then
|
||||
local DC = C.unitframes
|
||||
local dmTexture = DC.druidmanatexture or "Interface\\AddOns\\pfUI\\img\\bar"
|
||||
f.druidmana:SetStatusBarTexture(pfUI.media[dmTexture] or dmTexture)
|
||||
f.druidmana:SetFrameLevel(f:GetFrameLevel() + 5)
|
||||
|
||||
local manacolor = f.config.defcolor == "0" and f.config.manacolor or C.unitframes.manacolor
|
||||
f.druidmana:SetStatusBarColor(GetStringColor(manacolor))
|
||||
|
||||
local dmHeight = tonumber(DC.druidmanaheight) or 10
|
||||
local dmWidth = DC.druidmanawidth or "-1"
|
||||
local dmOffX = tonumber(DC.druidmanaoffx) or 0
|
||||
local dmOffY = tonumber(DC.druidmanaoffy) or 0
|
||||
local dmSpace = tonumber(DC.druidmanaspace) or -3
|
||||
local dmSpacing = -2 * default_border - dmSpace
|
||||
|
||||
f.druidmana:SetHeight(dmHeight)
|
||||
f.druidmana:ClearAllPoints()
|
||||
local w = dmWidth ~= "-1" and tonumber(dmWidth) or nil
|
||||
if w then
|
||||
f.druidmana:SetWidth(w)
|
||||
f.druidmana:SetPoint("TOP", f.power, "BOTTOM", dmOffX, dmSpacing + dmOffY)
|
||||
else
|
||||
f.druidmana:SetPoint("TOPLEFT", f.power, "BOTTOMLEFT", dmOffX, dmSpacing + dmOffY)
|
||||
f.druidmana:SetPoint("TOPRIGHT", f.power, "BOTTOMRIGHT", dmOffX, dmSpacing + dmOffY)
|
||||
end
|
||||
|
||||
if not f.druidmana._hasbd then
|
||||
CreateBackdrop(f.druidmana, default_border)
|
||||
CreateBackdropShadow(f.druidmana)
|
||||
f.druidmana._hasbd = true
|
||||
end
|
||||
|
||||
local tr, tg, tb = ManaBarColor[0].r, ManaBarColor[0].g, ManaBarColor[0].b
|
||||
if C.unitframes.pastel == "1" then
|
||||
tr, tg, tb = (tr + .75) * .5, (tg + .75) * .5, (tb + .75) * .5
|
||||
end
|
||||
f.druidmana.text:SetFont(fontname, fontsize, fontstyle)
|
||||
f.druidmana.text:SetTextColor(tr, tg, tb, 1)
|
||||
end
|
||||
|
||||
f.portrait.tex:SetAllPoints(f.portrait)
|
||||
f.portrait.tex:SetTexCoord(.1, .9, .1, .9)
|
||||
f.portrait.model:SetAllPoints(f.portrait)
|
||||
@@ -1644,6 +1688,18 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick)
|
||||
f.power = CreateFrame("Frame",nil, f)
|
||||
f.power.bar = CreateStatusBar(nil, f.power)
|
||||
|
||||
-- Druid secondary mana bar: shows base mana (read via ClassicAPI
|
||||
-- UnitPower(unit, 0), which works regardless of the active power) while
|
||||
-- shapeshifted into a form that uses energy/rage. Player + target only;
|
||||
-- styled/positioned in UpdateConfig, driven in UpdateDruidMana.
|
||||
if C.unitframes.druidmanabar == "1" and (f.label == "player" or f.label == "target") then
|
||||
f.druidmana = CreateFrame("StatusBar", "pfDruidMana_" .. f.label .. f.id, f)
|
||||
f.druidmana.text = f.druidmana:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
||||
f.druidmana.text:SetPoint("CENTER", f.druidmana, "CENTER", 0, 0)
|
||||
f.druidmana.text:SetJustifyH("CENTER")
|
||||
f.druidmana:Hide()
|
||||
end
|
||||
|
||||
f.glow = CreateFrame("Frame", nil, f)
|
||||
f.combat = CreateFrame("Frame", nil, f.hp.bar)
|
||||
f.combat.tex = f.combat:CreateTexture(nil, "OVERLAY")
|
||||
@@ -1853,6 +1909,32 @@ function pfUI.uf:RefreshIndicators(unit)
|
||||
end
|
||||
end
|
||||
|
||||
-- Druid secondary mana bar update. Reads base mana with ClassicAPI
|
||||
-- UnitPower(unit, 0)/UnitPowerMax(unit, 0), which return the mana slot
|
||||
-- regardless of the unit's active power -- so it works while shapeshifted,
|
||||
-- with no nampower/GetUnitField dependency. Shown only while off mana
|
||||
-- (Cat=energy, Bear=rage); non-player frames only for druid units.
|
||||
function pfUI.uf:UpdateDruidMana(unit)
|
||||
local bar = unit.druidmana
|
||||
local unitstr = unit.label .. unit.id
|
||||
if not UnitExists(unitstr) then bar:Hide() return end
|
||||
if unit.label ~= "player" then
|
||||
local _, cls = UnitClass(unitstr)
|
||||
if cls ~= "DRUID" then bar:Hide() return end
|
||||
end
|
||||
if UnitPowerType(unitstr) == 0 then bar:Hide() return end
|
||||
local mana, maxmana = UnitPower(unitstr, 0), UnitPowerMax(unitstr, 0)
|
||||
if not maxmana or maxmana == 0 then bar:Hide() return end
|
||||
bar:SetMinMaxValues(0, maxmana)
|
||||
bar:SetValue(mana)
|
||||
if C.unitframes.druidmanatext == "1" then
|
||||
bar.text:SetText(pfUI.api.Abbreviate(mana) .. "/" .. pfUI.api.Abbreviate(maxmana))
|
||||
else
|
||||
bar.text:SetText("")
|
||||
end
|
||||
bar:Show()
|
||||
end
|
||||
|
||||
function pfUI.uf:RefreshUnit(unit, component)
|
||||
-- break early on misconfigured UF's
|
||||
if not unit.label then return end
|
||||
@@ -2399,6 +2481,8 @@ function pfUI.uf:RefreshUnit(unit, component)
|
||||
end
|
||||
end
|
||||
|
||||
if unit.druidmana then pfUI.uf:UpdateDruidMana(unit) end
|
||||
|
||||
pfUI.uf:RefreshUnitState(unit)
|
||||
end
|
||||
end
|
||||
|
||||
Vendored
+1
@@ -704,6 +704,7 @@ pfUI_translation["deDE"] = {
|
||||
["Show Description"] = nil,
|
||||
["Show Dispel Indicators"] = nil,
|
||||
["Show Druid Mana Bar"] = nil,
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = nil,
|
||||
["Show Empty Buttons"] = nil,
|
||||
["Show FPS and Latency Colors"] = nil,
|
||||
|
||||
Vendored
+1
@@ -713,6 +713,7 @@ pfUI_translation["enUS"] = {
|
||||
["Show Description"] = nil,
|
||||
["Show Dispel Indicators"] = nil,
|
||||
["Show Druid Mana Bar"] = nil,
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = nil,
|
||||
["Show Empty Buttons"] = nil,
|
||||
["Show FPS and Latency Colors"] = nil,
|
||||
|
||||
Vendored
+1
@@ -704,6 +704,7 @@ pfUI_translation["esES"] = {
|
||||
["Show Description"] = "Mostrar descripción",
|
||||
["Show Dispel Indicators"] = "Mostrar indicadores para disipar",
|
||||
["Show Druid Mana Bar"] = nil,
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = "Mostrar la duración dentro del beneficios",
|
||||
["Show Empty Buttons"] = "Mostrar botones vacíos",
|
||||
["Show FPS and Latency Colors"] = "Mostrar FPS y colores de latencia",
|
||||
|
||||
Vendored
+1
@@ -704,6 +704,7 @@ pfUI_translation["frFR"] = {
|
||||
["Show Description"] = "Afficher les descriptions",
|
||||
["Show Dispel Indicators"] = "Afficher les indicateurs de dissipation",
|
||||
["Show Druid Mana Bar"] = nil,
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = "Afficher la durée à l'intérieur des améliorations",
|
||||
["Show Empty Buttons"] = "Afficher les boutons vides",
|
||||
["Show FPS and Latency Colors"] = nil,
|
||||
|
||||
Vendored
+1
@@ -704,6 +704,7 @@ pfUI_translation["koKR"] = {
|
||||
["Show Description"] = nil,
|
||||
["Show Dispel Indicators"] = nil,
|
||||
["Show Druid Mana Bar"] = nil,
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = nil,
|
||||
["Show Empty Buttons"] = nil,
|
||||
["Show FPS and Latency Colors"] = nil,
|
||||
|
||||
Vendored
+1
@@ -704,6 +704,7 @@ pfUI_translation["ruRU"] = {
|
||||
["Show Description"] = "Показать описание",
|
||||
["Show Dispel Indicators"] = "Показать индикаторы рассеивания",
|
||||
["Show Druid Mana Bar"] = nil,
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = "Показать продолжительность внутри баффа",
|
||||
["Show Empty Buttons"] = "Показать пустые кнопки",
|
||||
["Show FPS and Latency Colors"] = "Показать частоту кадров и задержку в цвете",
|
||||
|
||||
Vendored
+1
@@ -704,6 +704,7 @@ pfUI_translation["zhCN"] = {
|
||||
["Show Description"] = "显示描述",
|
||||
["Show Dispel Indicators"] = "显示驱散指示器",
|
||||
["Show Druid Mana Bar"] = "显示德鲁伊法力条",
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = "显示持续时间在Buff里面",
|
||||
["Show Empty Buttons"] = "显示空按钮",
|
||||
["Show FPS and Latency Colors"] = "显示帧数以及延迟颜色",
|
||||
|
||||
Vendored
+1
@@ -704,6 +704,7 @@ pfUI_translation["zhTW"] = {
|
||||
["Show Description"] = nil,
|
||||
["Show Dispel Indicators"] = nil,
|
||||
["Show Druid Mana Bar"] = nil,
|
||||
["Show Druid Mana Bar Text"] = nil,
|
||||
["Show Duration Inside Buff"] = "顯示持續時間在Buff裏面",
|
||||
["Show Empty Buttons"] = nil,
|
||||
["Show FPS and Latency Colors"] = nil,
|
||||
|
||||
@@ -2143,6 +2143,7 @@ pfUI:RegisterModule("gui", function ()
|
||||
|
||||
CreateConfig(nil, T["Druid Settings"], nil, nil, "header")
|
||||
CreateConfig(nil, T["Show Druid Mana Bar"], C.unitframes, "druidmanabar", "checkbox", nil, nil, nil, nil)
|
||||
CreateConfig(nil, T["Show Druid Mana Bar Text"], C.unitframes, "druidmanatext", "checkbox", nil, nil, nil, nil)
|
||||
CreateConfig(nil, T["Druid Mana Bar Height"], C.unitframes, "druidmanaheight", nil, nil, nil, nil, nil)
|
||||
CreateConfig(nil, T["Druid Mana Bar Width (-1 = auto)"], C.unitframes, "druidmanawidth", nil, nil, nil, nil, nil)
|
||||
CreateConfig(nil, T["Druid Mana Bar X-Offset"], C.unitframes, "druidmanaoffx", nil, nil, nil, nil, nil)
|
||||
|
||||
@@ -162,191 +162,4 @@ pfUI:RegisterModule("nampower", function ()
|
||||
end, true)
|
||||
end
|
||||
|
||||
-- Druid Secondary Mana Bar
|
||||
-- Shows base mana when druid is in shapeshift form (Bear/Cat uses Rage/Energy)
|
||||
-- Uses Nampower's GetUnitField to get base mana values
|
||||
-- Fully self-contained: uses its own config settings from C.unitframes.druidmana*
|
||||
if GetUnitField and pfUI.uf and pfUI_config.unitframes.druidmanabar == "1" then
|
||||
local rawborder, default_border = GetBorderSize("unitframes")
|
||||
local DC = C.unitframes -- druid mana config lives here as druidmana* keys
|
||||
|
||||
-- Shared helper: create a druid mana bar on a unit frame
|
||||
local function CreateDruidManaBar(parent, unit)
|
||||
if not parent then return nil end
|
||||
|
||||
local parentConfig = parent.config
|
||||
|
||||
-- Read own config values
|
||||
local dmHeight = tonumber(DC.druidmanaheight) or 10
|
||||
local dmWidth = DC.druidmanawidth or "-1"
|
||||
local dmOffX = tonumber(DC.druidmanaoffx) or 0
|
||||
local dmOffY = tonumber(DC.druidmanaoffy) or 0
|
||||
local dmSpace = tonumber(DC.druidmanaspace) or -3
|
||||
local dmTexture = DC.druidmanatexture or "Interface\\AddOns\\pfUI\\img\\bar"
|
||||
|
||||
local bar = CreateFrame("StatusBar", "pfDruidMana_" .. unit, parent)
|
||||
bar:SetFrameStrata(parent:GetFrameStrata())
|
||||
bar:SetFrameLevel(parent:GetFrameLevel() + 5)
|
||||
bar:SetStatusBarTexture(pfUI.media[dmTexture] or dmTexture)
|
||||
|
||||
-- Bar color: use same manacolor logic as the normal power bar
|
||||
local manacolor = parentConfig.defcolor == "0" and parentConfig.manacolor or C.unitframes.manacolor
|
||||
local r, g, b, a = pfUI.api.strsplit(",", manacolor)
|
||||
bar:SetStatusBarColor(tonumber(r) or .25, tonumber(g) or .25, tonumber(b) or 1, tonumber(a) or 1)
|
||||
|
||||
-- Size: own width/height, fallback to parent power bar width if -1
|
||||
local width = dmWidth ~= "-1" and tonumber(dmWidth) or nil
|
||||
if width then
|
||||
bar:SetWidth(width)
|
||||
end
|
||||
bar:SetHeight(dmHeight)
|
||||
|
||||
-- Position below the power bar with own spacing + offsets
|
||||
local spacing = -2 * default_border - dmSpace
|
||||
if width then
|
||||
-- Fixed width: use single point with offset
|
||||
bar:SetPoint("TOP", parent.power, "BOTTOM", dmOffX, spacing + dmOffY)
|
||||
else
|
||||
-- Auto width: anchor to both sides of power bar
|
||||
bar:SetPoint("TOPLEFT", parent.power, "BOTTOMLEFT", dmOffX, spacing + dmOffY)
|
||||
bar:SetPoint("TOPRIGHT", parent.power, "BOTTOMRIGHT", dmOffX, spacing + dmOffY)
|
||||
end
|
||||
bar:Hide()
|
||||
|
||||
CreateBackdrop(bar)
|
||||
CreateBackdropShadow(bar)
|
||||
|
||||
-- Font settings (same logic as power bar)
|
||||
local fontname = pfUI.font_unit
|
||||
local fontsize = tonumber(pfUI_config.global.font_unit_size)
|
||||
local fontstyle = pfUI_config.global.font_unit_style
|
||||
|
||||
if parentConfig.customfont == "1" then
|
||||
fontname = pfUI.media[parentConfig.customfont_name]
|
||||
fontsize = tonumber(parentConfig.customfont_size)
|
||||
fontstyle = parentConfig.customfont_style
|
||||
end
|
||||
|
||||
-- Text color (always mana-colored)
|
||||
local tr, tg, tb = ManaBarColor[0].r, ManaBarColor[0].g, ManaBarColor[0].b
|
||||
if C.unitframes.pastel == "1" then
|
||||
tr, tg, tb = (tr + .75) * .5, (tg + .75) * .5, (tb + .75) * .5
|
||||
end
|
||||
|
||||
-- Single center text showing current/max
|
||||
bar.text = bar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
||||
bar.text:SetFontObject(GameFontWhite)
|
||||
bar.text:SetFont(fontname, fontsize, fontstyle)
|
||||
bar.text:SetPoint("CENTER", bar, "CENTER", 0, 0)
|
||||
bar.text:SetJustifyH("CENTER")
|
||||
bar.text:SetTextColor(tr, tg, tb, 1)
|
||||
|
||||
return bar
|
||||
end
|
||||
|
||||
-- Shared helper: update druid mana bar values and text
|
||||
local function UpdateDruidManaBar(bar, unit)
|
||||
if not UnitExists(unit) then
|
||||
bar:Hide()
|
||||
return
|
||||
end
|
||||
|
||||
-- For non-player units, only show if the target is a Druid
|
||||
if unit ~= "player" then
|
||||
local _, unitClass = UnitClass(unit)
|
||||
if unitClass ~= "DRUID" then
|
||||
bar:Hide()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local powerType = UnitPowerType(unit)
|
||||
|
||||
-- Only show when NOT using mana (i.e., in Bear/Cat form)
|
||||
if powerType == 0 then
|
||||
bar:Hide()
|
||||
return
|
||||
end
|
||||
|
||||
-- Get base mana using Nampower's GetUnitField
|
||||
local baseMana, baseMaxMana
|
||||
local guid = UnitGUID(unit)
|
||||
|
||||
if guid then
|
||||
baseMana = GetUnitField(guid, "power1")
|
||||
baseMaxMana = GetUnitField(guid, "maxPower1")
|
||||
end
|
||||
|
||||
-- Round down power values (Nampower can return decimals)
|
||||
if baseMana then baseMana = math.floor(baseMana) end
|
||||
if baseMaxMana then baseMaxMana = math.floor(baseMaxMana) end
|
||||
|
||||
if type(baseMana) ~= "number" or type(baseMaxMana) ~= "number" or baseMaxMana == 0 then
|
||||
bar:Hide()
|
||||
return
|
||||
end
|
||||
|
||||
-- Update bar
|
||||
bar:SetMinMaxValues(0, baseMaxMana)
|
||||
bar:SetValue(baseMana)
|
||||
|
||||
-- Always show current/max
|
||||
bar.text:SetText(string.format("%s/%s", Abbreviate(baseMana), Abbreviate(baseMaxMana)))
|
||||
|
||||
bar:Show()
|
||||
end
|
||||
|
||||
-- ===== Player Druid Mana Bar =====
|
||||
local _, playerClass = UnitClass("player")
|
||||
if pfUI.uf.player and playerClass == "DRUID" then
|
||||
local playerMana = CreateDruidManaBar(pfUI.uf.player, "player")
|
||||
|
||||
if playerMana then
|
||||
playerMana:RegisterEvent("UNIT_MANA")
|
||||
playerMana:RegisterEvent("UNIT_MAXMANA")
|
||||
playerMana:RegisterEvent("UNIT_DISPLAYPOWER")
|
||||
playerMana:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
|
||||
playerMana:RegisterEvent("PLAYER_LOGOUT")
|
||||
playerMana:SetScript("OnEvent", function()
|
||||
if event == "PLAYER_LOGOUT" then
|
||||
this:UnregisterAllEvents()
|
||||
this:SetScript("OnEvent", nil)
|
||||
return
|
||||
end
|
||||
if arg1 == nil or arg1 == "player" then
|
||||
UpdateDruidManaBar(playerMana, "player")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Initial update
|
||||
UpdateDruidManaBar(playerMana, "player")
|
||||
end
|
||||
end
|
||||
|
||||
-- ===== Target Druid Mana Bar =====
|
||||
if pfUI.uf.target then
|
||||
local targetMana = CreateDruidManaBar(pfUI.uf.target, "target")
|
||||
|
||||
if targetMana then
|
||||
targetMana:RegisterEvent("UNIT_MANA")
|
||||
targetMana:RegisterEvent("UNIT_MAXMANA")
|
||||
targetMana:RegisterEvent("UNIT_DISPLAYPOWER")
|
||||
targetMana:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||
targetMana:RegisterEvent("PLAYER_LOGOUT")
|
||||
targetMana:SetScript("OnEvent", function()
|
||||
if event == "PLAYER_LOGOUT" then
|
||||
this:UnregisterAllEvents()
|
||||
this:SetScript("OnEvent", nil)
|
||||
return
|
||||
end
|
||||
if event == "PLAYER_TARGET_CHANGED" or arg1 == nil or arg1 == "target" then
|
||||
UpdateDruidManaBar(targetMana, "target")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Initial update
|
||||
UpdateDruidManaBar(targetMana, "target")
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user