mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-25 21:40:49 +00:00
improvements for druid mana bar
improvements for druid mana bar
This commit is contained in:
+7
-2
@@ -218,8 +218,13 @@ function pfUI:LoadConfig()
|
|||||||
pfUI:UpdateConfig("unitframes", nil, "rangecheck", "0")
|
pfUI:UpdateConfig("unitframes", nil, "rangecheck", "0")
|
||||||
pfUI:UpdateConfig("unitframes", nil, "buffdetect", "0")
|
pfUI:UpdateConfig("unitframes", nil, "buffdetect", "0")
|
||||||
pfUI:UpdateConfig("unitframes", nil, "druidmanabar", "1")
|
pfUI:UpdateConfig("unitframes", nil, "druidmanabar", "1")
|
||||||
pfUI:UpdateConfig("unitframes", nil, "druidmanaheight", "2")
|
pfUI:UpdateConfig("unitframes", nil, "druidmanaheight", "10")
|
||||||
pfUI:UpdateConfig("unitframes", nil, "druidmanatext", "0")
|
pfUI:UpdateConfig("unitframes", nil, "druidmanawidth", "-1")
|
||||||
|
pfUI:UpdateConfig("unitframes", nil, "druidmanaoffx", "0")
|
||||||
|
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, "druidmanacolor", ".25,.25,1,1")
|
||||||
pfUI:UpdateConfig("unitframes", nil, "rangechecki", "4")
|
pfUI:UpdateConfig("unitframes", nil, "rangechecki", "4")
|
||||||
pfUI:UpdateConfig("unitframes", nil, "combowidth", "6")
|
pfUI:UpdateConfig("unitframes", nil, "combowidth", "6")
|
||||||
pfUI:UpdateConfig("unitframes", nil, "comboheight", "6")
|
pfUI:UpdateConfig("unitframes", nil, "comboheight", "6")
|
||||||
|
|||||||
+6
-1
@@ -1986,7 +1986,12 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
|||||||
CreateConfig(nil, T["Druid Settings"], nil, nil, "header")
|
CreateConfig(nil, T["Druid Settings"], nil, nil, "header")
|
||||||
CreateConfig(nil, T["Show Druid Mana Bar"], C.unitframes, "druidmanabar", "checkbox", nil, nil, nil, nil, "vanilla" )
|
CreateConfig(nil, T["Show Druid Mana Bar"], C.unitframes, "druidmanabar", "checkbox", nil, nil, nil, nil, "vanilla" )
|
||||||
CreateConfig(nil, T["Druid Mana Bar Height"], C.unitframes, "druidmanaheight", nil, nil, nil, nil, nil, "vanilla" )
|
CreateConfig(nil, T["Druid Mana Bar Height"], C.unitframes, "druidmanaheight", nil, nil, nil, nil, nil, "vanilla" )
|
||||||
CreateConfig(nil, T["Druid Mana Bar Text"], C.unitframes, "druidmanatext", "checkbox", nil, nil, nil, nil, "vanilla" )
|
CreateConfig(nil, T["Druid Mana Bar Width (-1 = auto)"], C.unitframes, "druidmanawidth", nil, nil, nil, nil, nil, "vanilla" )
|
||||||
|
CreateConfig(nil, T["Druid Mana Bar X-Offset"], C.unitframes, "druidmanaoffx", nil, nil, nil, nil, nil, "vanilla" )
|
||||||
|
CreateConfig(nil, T["Druid Mana Bar Y-Offset"], C.unitframes, "druidmanaoffy", nil, nil, nil, nil, nil, "vanilla" )
|
||||||
|
CreateConfig(nil, T["Druid Mana Bar Spacing"], C.unitframes, "druidmanaspace", nil, nil, nil, nil, nil, "vanilla" )
|
||||||
|
CreateConfig(nil, T["Druid Mana Bar Texture"], C.unitframes, "druidmanatexture", "dropdown", pfUI.gui.dropdowns.uf_bartexture, nil, nil, nil, "vanilla" )
|
||||||
|
CreateConfig(nil, T["Druid Mana Bar Color"], C.unitframes, "druidmanacolor", "color", nil, nil, nil, nil, "vanilla" )
|
||||||
|
|
||||||
CreateConfig(nil, T["SuperWoW Settings"], nil, nil, "header")
|
CreateConfig(nil, T["SuperWoW Settings"], nil, nil, "header")
|
||||||
CreateConfig(nil, T["Track Group on Minimap"], C.unitframes, "track_group", "checkbox", nil, nil, nil, nil, "vanilla" )
|
CreateConfig(nil, T["Track Group on Minimap"], C.unitframes, "track_group", "checkbox", nil, nil, nil, nil, "vanilla" )
|
||||||
|
|||||||
+136
-258
@@ -493,78 +493,106 @@ pfUI:RegisterModule("nampower", "vanilla", function ()
|
|||||||
-- Druid Secondary Mana Bar
|
-- Druid Secondary Mana Bar
|
||||||
-- Shows base mana when druid is in shapeshift form (Bear/Cat uses Rage/Energy)
|
-- Shows base mana when druid is in shapeshift form (Bear/Cat uses Rage/Energy)
|
||||||
-- Uses Nampower's GetUnitField to get base mana values
|
-- Uses Nampower's GetUnitField to get base mana values
|
||||||
-- Controlled by "Show Druid Mana Bar" setting in GUI
|
-- Fully self-contained: uses its own config settings from C.unitframes.druidmana*
|
||||||
local _, playerClass = UnitClass("player")
|
local _, playerClass = UnitClass("player")
|
||||||
|
|
||||||
if GetUnitField and pfUI.uf and pfUI.uf.player and playerClass == "DRUID" and pfUI_config.unitframes.druidmanabar == "1" then
|
if GetUnitField and pfUI.uf and playerClass == "DRUID" and pfUI_config.unitframes.druidmanabar == "1" then
|
||||||
local rawborder, default_border = GetBorderSize("unitframes")
|
local rawborder, default_border = GetBorderSize("unitframes")
|
||||||
local config = pfUI.uf.player.config
|
local DC = C.unitframes -- druid mana config lives here as druidmana* keys
|
||||||
|
|
||||||
-- Create secondary mana bar below the power bar
|
-- Shared helper: create a druid mana bar on a unit frame
|
||||||
local playerMana = CreateFrame("StatusBar", "pfPlayerSecondaryMana", pfUI.uf.player)
|
local function CreateDruidManaBar(parent, unit)
|
||||||
playerMana:SetFrameStrata(pfUI.uf.player:GetFrameStrata())
|
if not parent then return nil end
|
||||||
playerMana:SetFrameLevel(pfUI.uf.player:GetFrameLevel() + 5)
|
|
||||||
playerMana:SetStatusBarTexture(pfUI.media[config.pbartexture])
|
|
||||||
|
|
||||||
-- Mana color
|
|
||||||
local manacolor = config.defcolor == "0" and config.manacolor or C.unitframes.manacolor
|
|
||||||
local r, g, b, a = pfUI.api.strsplit(",", manacolor)
|
|
||||||
playerMana:SetStatusBarColor(r, g, b, a)
|
|
||||||
|
|
||||||
-- Use SAME size as normal power bar
|
|
||||||
local width = config.pwidth ~= "-1" and config.pwidth or config.width
|
|
||||||
local height = config.pheight
|
|
||||||
playerMana:SetWidth(width)
|
|
||||||
playerMana:SetHeight(height)
|
|
||||||
playerMana:SetPoint("TOPLEFT", pfUI.uf.player.power, "BOTTOMLEFT", 0, -2*default_border - (config.pspace or 0))
|
|
||||||
playerMana:SetPoint("TOPRIGHT", pfUI.uf.player.power, "BOTTOMRIGHT", 0, -2*default_border - (config.pspace or 0))
|
|
||||||
playerMana:Hide()
|
|
||||||
|
|
||||||
CreateBackdrop(playerMana)
|
local parentConfig = parent.config
|
||||||
CreateBackdropShadow(playerMana)
|
|
||||||
|
|
||||||
-- Text overlay - same font settings as power bar
|
-- Read own config values
|
||||||
local fontname = pfUI.font_unit
|
local dmHeight = tonumber(DC.druidmanaheight) or 10
|
||||||
local fontsize = tonumber(pfUI_config.global.font_unit_size)
|
local dmWidth = DC.druidmanawidth or "-1"
|
||||||
local fontstyle = pfUI_config.global.font_unit_style
|
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"
|
||||||
|
|
||||||
if config.customfont == "1" then
|
local bar = CreateFrame("StatusBar", "pfDruidMana_" .. unit, parent)
|
||||||
fontname = pfUI.media[config.customfont_name]
|
bar:SetFrameStrata(parent:GetFrameStrata())
|
||||||
fontsize = tonumber(config.customfont_size)
|
bar:SetFrameLevel(parent:GetFrameLevel() + 5)
|
||||||
fontstyle = config.customfont_style
|
bar:SetStatusBarTexture(pfUI.media[dmTexture] or dmTexture)
|
||||||
|
|
||||||
|
-- Bar color from own config
|
||||||
|
local manacolor = DC.druidmanacolor or ".25,.25,1,1"
|
||||||
|
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
|
end
|
||||||
|
|
||||||
playerMana.text = playerMana:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
-- Shared helper: update druid mana bar values and text
|
||||||
playerMana.text:SetFontObject(GameFontWhite)
|
local function UpdateDruidManaBar(bar, unit)
|
||||||
playerMana.text:SetFont(fontname, fontsize, fontstyle)
|
if not UnitExists(unit) then
|
||||||
playerMana.text:SetPoint("CENTER", playerMana, "CENTER", 0, 0)
|
bar:Hide()
|
||||||
|
return
|
||||||
-- Set text color like normal power bar (mana = type 0)
|
end
|
||||||
local tr, tg, tb = 1, 1, 1
|
|
||||||
if config["powercolor"] == "1" then
|
local powerType = UnitPowerType(unit)
|
||||||
tr = ManaBarColor[0].r
|
|
||||||
tg = ManaBarColor[0].g
|
|
||||||
tb = ManaBarColor[0].b
|
|
||||||
end
|
|
||||||
if C.unitframes.pastel == "1" then
|
|
||||||
tr, tg, tb = (tr + .75) * .5, (tg + .75) * .5, (tb + .75) * .5
|
|
||||||
end
|
|
||||||
playerMana.text:SetTextColor(tr, tg, tb, 1)
|
|
||||||
|
|
||||||
-- Update function
|
|
||||||
local function UpdatePlayerSecondaryMana()
|
|
||||||
local powerType = UnitPowerType("player")
|
|
||||||
|
|
||||||
-- Only show when NOT using mana (i.e., in Bear/Cat form)
|
-- Only show when NOT using mana (i.e., in Bear/Cat form)
|
||||||
if powerType == 0 then
|
if powerType == 0 then
|
||||||
playerMana:Hide()
|
bar:Hide()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get base mana using Nampower's GetUnitField
|
-- Get base mana using Nampower's GetUnitField
|
||||||
local baseMana, baseMaxMana
|
local baseMana, baseMaxMana
|
||||||
local _, guid = UnitExists("player")
|
local _, guid = UnitExists(unit)
|
||||||
|
|
||||||
if guid then
|
if guid then
|
||||||
baseMana = GetUnitField(guid, "power1")
|
baseMana = GetUnitField(guid, "power1")
|
||||||
baseMaxMana = GetUnitField(guid, "maxPower1")
|
baseMaxMana = GetUnitField(guid, "maxPower1")
|
||||||
@@ -575,220 +603,70 @@ pfUI:RegisterModule("nampower", "vanilla", function ()
|
|||||||
if baseMaxMana then baseMaxMana = math.floor(baseMaxMana) end
|
if baseMaxMana then baseMaxMana = math.floor(baseMaxMana) end
|
||||||
|
|
||||||
if type(baseMana) ~= "number" or type(baseMaxMana) ~= "number" or baseMaxMana == 0 then
|
if type(baseMana) ~= "number" or type(baseMaxMana) ~= "number" or baseMaxMana == 0 then
|
||||||
playerMana:Hide()
|
bar:Hide()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update bar
|
-- Update bar
|
||||||
playerMana:SetMinMaxValues(0, baseMaxMana)
|
bar:SetMinMaxValues(0, baseMaxMana)
|
||||||
playerMana:SetValue(baseMana)
|
bar:SetValue(baseMana)
|
||||||
|
|
||||||
-- Update text based on power text config
|
-- Always show current/max
|
||||||
local textConfig = config.txtpowercenter or config.txtpowerright or config.txtpowerleft
|
bar.text:SetText(string.format("%s/%s", Abbreviate(baseMana), Abbreviate(baseMaxMana)))
|
||||||
|
|
||||||
if not textConfig or textConfig == "" or textConfig == "none" then
|
|
||||||
playerMana.text:SetText("")
|
|
||||||
elseif textConfig == "power" then
|
|
||||||
playerMana.text:SetText(Abbreviate(baseMana))
|
|
||||||
elseif textConfig == "powermax" then
|
|
||||||
playerMana.text:SetText(Abbreviate(baseMaxMana))
|
|
||||||
elseif textConfig == "powerperc" then
|
|
||||||
local perc = math.ceil(baseMana / baseMaxMana * 100)
|
|
||||||
playerMana.text:SetText(perc)
|
|
||||||
elseif textConfig == "powermiss" then
|
|
||||||
local miss = math.ceil(baseMana - baseMaxMana)
|
|
||||||
playerMana.text:SetText(miss == 0 and "0" or Abbreviate(miss))
|
|
||||||
elseif textConfig == "powerdyn" then
|
|
||||||
local perc = math.ceil(baseMana / baseMaxMana * 100)
|
|
||||||
if perc == 100 then
|
|
||||||
playerMana.text:SetText(Abbreviate(baseMana))
|
|
||||||
else
|
|
||||||
playerMana.text:SetText(string.format("%s - %s%%", Abbreviate(baseMana), perc))
|
|
||||||
end
|
|
||||||
elseif textConfig == "powerminmax" then
|
|
||||||
playerMana.text:SetText(string.format("%s/%s", Abbreviate(baseMana), Abbreviate(baseMaxMana)))
|
|
||||||
else
|
|
||||||
-- Default: show dynamic
|
|
||||||
local perc = math.ceil(baseMana / baseMaxMana * 100)
|
|
||||||
if perc == 100 then
|
|
||||||
playerMana.text:SetText(Abbreviate(baseMana))
|
|
||||||
else
|
|
||||||
playerMana.text:SetText(string.format("%s - %s%%", Abbreviate(baseMana), perc))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
playerMana:Show()
|
bar:Show()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register events
|
-- ===== Player Druid Mana Bar =====
|
||||||
playerMana:RegisterEvent("UNIT_MANA")
|
if pfUI.uf.player then
|
||||||
playerMana:RegisterEvent("UNIT_MAXMANA")
|
local playerMana = CreateDruidManaBar(pfUI.uf.player, "player")
|
||||||
playerMana:RegisterEvent("UNIT_DISPLAYPOWER")
|
|
||||||
playerMana:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
|
if playerMana then
|
||||||
playerMana:RegisterEvent("PLAYER_LOGOUT")
|
playerMana:RegisterEvent("UNIT_MANA")
|
||||||
playerMana:SetScript("OnEvent", function()
|
playerMana:RegisterEvent("UNIT_MAXMANA")
|
||||||
if event == "PLAYER_LOGOUT" then
|
playerMana:RegisterEvent("UNIT_DISPLAYPOWER")
|
||||||
this:UnregisterAllEvents()
|
playerMana:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
|
||||||
this:SetScript("OnEvent", nil)
|
playerMana:RegisterEvent("PLAYER_LOGOUT")
|
||||||
return
|
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
|
||||||
if arg1 == nil or arg1 == "player" then
|
|
||||||
UpdatePlayerSecondaryMana()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Initial update
|
|
||||||
UpdatePlayerSecondaryMana()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Target Secondary Mana Bar (shows when target is a druid in shapeshift form)
|
|
||||||
if GetUnitField and pfUI.uf and pfUI.uf.target and pfUI_config.unitframes.druidmanabar == "1" then
|
|
||||||
local rawborder, default_border = GetBorderSize("unitframes")
|
|
||||||
local config = pfUI.uf.target.config
|
|
||||||
|
|
||||||
-- Create secondary mana bar below the power bar
|
|
||||||
local targetMana = CreateFrame("StatusBar", "pfTargetSecondaryMana", pfUI.uf.target)
|
|
||||||
targetMana:SetFrameStrata(pfUI.uf.target:GetFrameStrata())
|
|
||||||
targetMana:SetFrameLevel(pfUI.uf.target:GetFrameLevel() + 5)
|
|
||||||
targetMana:SetStatusBarTexture(pfUI.media[config.pbartexture])
|
|
||||||
|
|
||||||
-- Mana color
|
|
||||||
local manacolor = config.defcolor == "0" and config.manacolor or C.unitframes.manacolor
|
|
||||||
local r, g, b, a = pfUI.api.strsplit(",", manacolor)
|
|
||||||
targetMana:SetStatusBarColor(r, g, b, a)
|
|
||||||
|
|
||||||
-- Use SAME size as normal power bar
|
|
||||||
local width = config.pwidth ~= "-1" and config.pwidth or config.width
|
|
||||||
local height = config.pheight
|
|
||||||
targetMana:SetWidth(width)
|
|
||||||
targetMana:SetHeight(height)
|
|
||||||
targetMana:SetPoint("TOPLEFT", pfUI.uf.target.power, "BOTTOMLEFT", 0, -2*default_border - (config.pspace or 0))
|
|
||||||
targetMana:SetPoint("TOPRIGHT", pfUI.uf.target.power, "BOTTOMRIGHT", 0, -2*default_border - (config.pspace or 0))
|
|
||||||
targetMana:Hide()
|
|
||||||
|
|
||||||
CreateBackdrop(targetMana)
|
|
||||||
CreateBackdropShadow(targetMana)
|
|
||||||
|
|
||||||
-- Text overlay
|
|
||||||
local fontname = pfUI.font_unit
|
|
||||||
local fontsize = tonumber(pfUI_config.global.font_unit_size)
|
|
||||||
local fontstyle = pfUI_config.global.font_unit_style
|
|
||||||
|
|
||||||
if config.customfont == "1" then
|
|
||||||
fontname = pfUI.media[config.customfont_name]
|
|
||||||
fontsize = tonumber(config.customfont_size)
|
|
||||||
fontstyle = config.customfont_style
|
|
||||||
end
|
end
|
||||||
|
|
||||||
targetMana.text = targetMana:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
-- ===== Target Druid Mana Bar =====
|
||||||
targetMana.text:SetFontObject(GameFontWhite)
|
if pfUI.uf.target then
|
||||||
targetMana.text:SetFont(fontname, fontsize, fontstyle)
|
local targetMana = CreateDruidManaBar(pfUI.uf.target, "target")
|
||||||
targetMana.text:SetPoint("CENTER", targetMana, "CENTER", 0, 0)
|
|
||||||
|
if targetMana then
|
||||||
-- Set text color
|
targetMana:RegisterEvent("UNIT_MANA")
|
||||||
local tr, tg, tb = 1, 1, 1
|
targetMana:RegisterEvent("UNIT_MAXMANA")
|
||||||
if config["powercolor"] == "1" then
|
targetMana:RegisterEvent("UNIT_DISPLAYPOWER")
|
||||||
tr = ManaBarColor[0].r
|
targetMana:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||||
tg = ManaBarColor[0].g
|
targetMana:RegisterEvent("PLAYER_LOGOUT")
|
||||||
tb = ManaBarColor[0].b
|
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
|
||||||
if C.unitframes.pastel == "1" then
|
|
||||||
tr, tg, tb = (tr + .75) * .5, (tg + .75) * .5, (tb + .75) * .5
|
|
||||||
end
|
|
||||||
targetMana.text:SetTextColor(tr, tg, tb, 1)
|
|
||||||
|
|
||||||
-- Update function
|
|
||||||
local function UpdateTargetSecondaryMana()
|
|
||||||
if not UnitExists("target") then
|
|
||||||
targetMana:Hide()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local powerType = UnitPowerType("target")
|
|
||||||
|
|
||||||
-- Only show if target is NOT using mana
|
|
||||||
if powerType == 0 then
|
|
||||||
targetMana:Hide()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Get base mana using Nampower's GetUnitField
|
|
||||||
local baseMana, baseMaxMana
|
|
||||||
local _, guid = UnitExists("target")
|
|
||||||
|
|
||||||
if guid then
|
|
||||||
baseMana = GetUnitField(guid, "power1")
|
|
||||||
baseMaxMana = GetUnitField(guid, "maxPower1")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Round down power values
|
|
||||||
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
|
|
||||||
targetMana:Hide()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Update bar
|
|
||||||
targetMana:SetMinMaxValues(0, baseMaxMana)
|
|
||||||
targetMana:SetValue(baseMana)
|
|
||||||
|
|
||||||
-- Update text
|
|
||||||
local textConfig = config.txtpowercenter or config.txtpowerright or config.txtpowerleft
|
|
||||||
|
|
||||||
if not textConfig or textConfig == "" or textConfig == "none" then
|
|
||||||
targetMana.text:SetText("")
|
|
||||||
elseif textConfig == "power" then
|
|
||||||
targetMana.text:SetText(Abbreviate(baseMana))
|
|
||||||
elseif textConfig == "powermax" then
|
|
||||||
targetMana.text:SetText(Abbreviate(baseMaxMana))
|
|
||||||
elseif textConfig == "powerperc" then
|
|
||||||
local perc = math.ceil(baseMana / baseMaxMana * 100)
|
|
||||||
targetMana.text:SetText(perc)
|
|
||||||
elseif textConfig == "powermiss" then
|
|
||||||
local miss = math.ceil(baseMana - baseMaxMana)
|
|
||||||
targetMana.text:SetText(miss == 0 and "0" or Abbreviate(miss))
|
|
||||||
elseif textConfig == "powerdyn" then
|
|
||||||
local perc = math.ceil(baseMana / baseMaxMana * 100)
|
|
||||||
if perc == 100 then
|
|
||||||
targetMana.text:SetText(Abbreviate(baseMana))
|
|
||||||
else
|
|
||||||
targetMana.text:SetText(string.format("%s - %s%%", Abbreviate(baseMana), perc))
|
|
||||||
end
|
|
||||||
elseif textConfig == "powerminmax" then
|
|
||||||
targetMana.text:SetText(string.format("%s/%s", Abbreviate(baseMana), Abbreviate(baseMaxMana)))
|
|
||||||
else
|
|
||||||
-- Default: show dynamic
|
|
||||||
local perc = math.ceil(baseMana / baseMaxMana * 100)
|
|
||||||
if perc == 100 then
|
|
||||||
targetMana.text:SetText(Abbreviate(baseMana))
|
|
||||||
else
|
|
||||||
targetMana.text:SetText(string.format("%s - %s%%", Abbreviate(baseMana), perc))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
targetMana:Show()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Register events
|
|
||||||
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
|
|
||||||
UpdateTargetSecondaryMana()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Initial update
|
|
||||||
UpdateTargetSecondaryMana()
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user