api: restructure

This commit is contained in:
shagu
2017-02-26 20:39:52 +01:00
parent 5a60812786
commit a25b440507
4 changed files with 5 additions and 3 deletions
+528
View File
@@ -0,0 +1,528 @@
local _G = getfenv(0)
pfUI.api = { }
-- [ strsplit ]
-- Splits a string using a delimiter.
-- 'delimiter' [string] characters that will be interpreted as delimiter
-- characters (bytes) in the string.
-- 'subject' [string] String to split.
-- return: [list] a list of strings.
function pfUI.api.strsplit(delimiter, subject)
local delimiter, fields = delimiter or ":", {}
local pattern = string.format("([^%s]+)", delimiter)
string.gsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)
return unpack(fields)
end
-- [ strvertical ]
-- Creates vertical text using linebreaks. Multibyte char friendly.
-- 'str' [string] String to columnize.
-- return: [string] the string tranformed to a column.
function pfUI.api.strvertical(str)
local _, len = string.gsub(str,"[^\128-\193]", "")
if (len == string.len(str)) then
return string.gsub(str, "(.)", "%1\n")
else
return string.gsub(str,"([%z\1-\127\194-\244][\128-\191]*)", "%1\n")
end
end
-- [ round ]
-- Rounds a float number into specified places after comma.
-- 'input' [float] the number that should be rounded.
-- 'places' [int] amount of places after the comma.
-- returns: [float] rounded number.
function pfUI.api.round(input, places)
if not places then places = 0 end
if type(input) == "number" and type(places) == "number" then
local pow = 1
for i = 1, places do pow = pow * 10 end
return floor(input * pow + 0.5) / pow
end
end
-- [ Hook ]
-- Hooks a global function and injects custom code
-- 'name' [string] name of the function that shold be hooked
-- 'func' [function] function containing the custom code
-- 'append' [bool] optional variable, used to append custom
-- code instead of prepending it
function pfUI.api.Hook(name, func, append)
if not _G[name] then return end
pfUI.hooks[tostring(func)] = {}
pfUI.hooks[tostring(func)]["old"] = _G[name]
pfUI.hooks[tostring(func)]["new"] = func
if append then
pfUI.hooks[tostring(func)]["function"] = function(...)
pfUI.hooks[tostring(func)]["old"](unpack(arg))
pfUI.hooks[tostring(func)]["new"](unpack(arg))
end
else
pfUI.hooks[tostring(func)]["function"] = function(...)
pfUI.hooks[tostring(func)]["new"](unpack(arg))
pfUI.hooks[tostring(func)]["old"](unpack(arg))
end
end
_G[name] = pfUI.hooks[tostring(func)]["function"]
end
-- [ Create Gold String ]
-- Transforms a amount of copper into a fully fledged gold string
-- 'money' [int] the amount of coppy (GetMoney())
-- return: [string] a colorized string which is split into
-- gold,silver and copper values.
function pfUI.api.CreateGoldString(money)
local gold = floor(money/ 100 / 100)
local silver = floor(mod((money/100),100))
local copper = floor(mod(money,100))
local string = ""
if gold > 0 then string = string .. "|cffffffff" .. gold .. "|cffffd700g" end
if silver > 0 then string = string .. "|cffffffff " .. silver .. "|cffc7c7cfs" end
string = string .. "|cffffffff " .. copper .. "|cffeda55fc"
return string
end
-- [ Copy Table ]
-- By default a table assignment only will be a reference instead of a copy.
-- This is used to create a replicate of the actual table.
-- 'src' [table] the table that should be copied.
-- return: [table] the replicated table.
function pfUI.api.CopyTable(src)
local lookup_table = {}
local function _copy(src)
if type(src) ~= "table" then
return src
elseif lookup_table[src] then
return lookup_table[src]
end
local new_table = {}
lookup_table[src] = new_table
for index, value in pairs(src) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(src))
end
return _copy(src)
end
-- [ Update Movable ]
-- Loads and update the configured position of the specified frame.
-- It also creates an entry in the movables table.
-- 'frame' [frame] the frame that should be updated.
function pfUI.api:UpdateMovable(frame)
local name = frame:GetName()
if pfUI_config.global.offscreen == "0" then
frame:SetClampedToScreen(true)
end
if not pfUI.movables[name] then
pfUI.movables[name] = true
table.insert(pfUI.movables, name)
end
if pfUI_config["position"][frame:GetName()] then
if pfUI_config["position"][frame:GetName()]["scale"] then
frame:SetScale(pfUI_config["position"][frame:GetName()].scale)
end
if pfUI_config["position"][frame:GetName()]["xpos"] then
frame:ClearAllPoints()
frame:SetPoint("TOPLEFT", pfUI_config["position"][frame:GetName()].xpos, pfUI_config["position"][frame:GetName()].ypos)
end
end
end
-- [ SetAutoPoint ]
-- Automatically places the frame according to screen position of the parent.
-- 'frame' [frame] the frame that should be moved.
-- 'parent' [frame] the frame's anchor point
-- 'spacing' [number] the padding that should be used between the
-- frame and its parent frame
function pfUI.api:SetAutoPoint(frame, parent, spacing)
--[[
a b max
+-----------------+
| 1 | 2 | 3 |
|-----+-----+-----| c
| 4 | 5 | 6 |
|-----+-----+-----| d
| 7 | 8 | 9 |
+-----------------+
0
]]--
local a = GetScreenWidth() / 3
local b = GetScreenWidth() / 3 * 2
local c = GetScreenHeight() / 3 * 2
local d = GetScreenHeight() / 3
local x, y = parent:GetCenter()
local off = spacing or 0
frame:ClearAllPoints()
if x < a and y > c then
-- TOPLEFT
frame:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -off)
elseif x > a and x < b and y > c then
-- TOP
frame:SetPoint("TOP", parent, "BOTTOM", 0, -off)
elseif x > b and y > c then
-- TOPRIGHT
frame:SetPoint("TOPRIGHT", parent, "BOTTOMRIGHT", 0, -off)
elseif x < a and y > d and y < c then
-- LEFT
frame:SetPoint("LEFT", parent, "RIGHT", off, 0)
elseif x > a and x < b and y > d and y < c then
-- CENTER
frame:SetPoint("BOTTOM", parent, "TOP", 0, off)
elseif x > b and y > d and y < c then
-- RIGHT
frame:SetPoint("RIGHT", parent, "LEFT", -off, 0)
elseif x < a and y < d then
-- BOTTOMLEFT
frame:SetPoint("BOTTOMLEFT", parent, "TOPLEFT", 0, off)
elseif x > a and x < b and y < d then
-- BOTTOM
frame:SetPoint("BOTTOM", parent, "TOP", 0, off)
elseif x > b and y < d then
-- BOTTOMRIGHT
frame:SetPoint("BOTTOMRIGHT", parent, "TOPRIGHT", 0, off)
end
end
-- [ Create Backdrop ]
-- Creates a pfUI compatible frame as backdrop element
-- 'f' [frame] the frame which should get a backdrop.
-- 'inset' [int] backdrop inset, defaults to border size.
-- 'legacy' [bool] use legacy backdrop instead of creating frames.
-- 'transp' [bool] force default transparency of 0.8.
function pfUI.api:CreateBackdrop(f, inset, legacy, transp)
-- use default inset if nothing is given
local border = inset
if not border then
border = tonumber(pfUI_config.appearance.border.default)
end
-- bg and edge colors
if not pfUI.cache.br then
local br, bg, bb, ba = pfUI.api.strsplit(",", pfUI_config.appearance.border.background)
local er, eg, eb, ea = pfUI.api.strsplit(",", pfUI_config.appearance.border.color)
pfUI.cache.br, pfUI.cache.bg, pfUI.cache.bb, pfUI.cache.ba = br, bg, bb, ba
pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea = er, eg, eb, ea
end
local br, bg, bb, ba = pfUI.cache.br, pfUI.cache.bg, pfUI.cache.bb, pfUI.cache.ba
local er, eg, eb, ea = pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea
if transp then ba = transp end
-- use legacy backdrop handling
if legacy then
f:SetBackdrop(pfUI.backdrop)
f:SetBackdropColor(br, bg, bb, ba)
f:SetBackdropBorderColor(er, eg, eb , ea)
return
end
-- increase clickable area if available
if f.SetHitRectInsets then
f:SetHitRectInsets(-border,-border,-border,-border)
end
-- use new backdrop behaviour
if not f.backdrop then
f:SetBackdrop(nil)
local border = tonumber(border) - 1
local backdrop = pfUI.backdrop
if border < 1 then backdrop = pfUI.backdrop_small end
local b = CreateFrame("Frame", nil, f)
b:SetPoint("TOPLEFT", f, "TOPLEFT", -border, border)
b:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", border, -border)
local level = f:GetFrameLevel()
if level < 1 then
--f:SetFrameLevel(level + 1)
b:SetFrameLevel(level)
else
b:SetFrameLevel(level - 1)
end
f.backdrop = b
b:SetBackdrop(backdrop)
end
local b = f.backdrop
b:SetBackdropColor(br, bg, bb, ba)
b:SetBackdropBorderColor(er, eg, eb , ea)
end
-- [ Skin Button ]
-- Applies pfUI skin to buttons:
-- 'button' [frame/string] the button that should be skinned.
-- 'cr' [int] mouseover color (red), defaults to classcolor.
-- 'cg' [int] mouseover color (green), defaults to classcolor.
-- 'cb' [int] mouseover color (blue), defaults to classcolor.
function pfUI.api:SkinButton(button, cr, cg, cb)
local b = getglobal(button)
if not b then b = button end
if not cr or not cg or not cb then
_, class = UnitClass("player")
local color = RAID_CLASS_COLORS[class]
cr, cg, cb = color.r , color.g, color.b
end
pfUI.api:CreateBackdrop(b, nil, true)
b:SetNormalTexture(nil)
b:SetHighlightTexture(nil)
b:SetPushedTexture(nil)
b:SetDisabledTexture(nil)
local funce = b:GetScript("OnEnter")
local funcl = b:GetScript("OnLeave")
b:SetScript("OnEnter", function()
if funce then funce() end
pfUI.api:CreateBackdrop(b, nil, true)
b:SetBackdropBorderColor(cr,cg,cb,1)
end)
b:SetScript("OnLeave", function()
if funcl then funcl() end
pfUI.api:CreateBackdrop(b, nil, true)
end)
b:SetFont(pfUI.font_default, pfUI_config.global.font_size, "OUTLINE")
end
-- [ Question Dialog ]
-- Creates a pfUI user dialog popup:
-- 'text' [string] text that will be displayed.
-- 'yes' [function] function that is triggered on 'Okay' button.
-- 'no' [function] function that is triggered on 'Cancel' button.
-- 'editbox' [bool] if set, a inputfield will be shown. it can be.
-- accessed with "GetParent().input".
function pfUI.api:CreateQuestionDialog(text, yes, no, editbox)
-- do not allow multiple instances of question dialogs
if pfQuestionDialog and pfQuestionDialog:IsShown() then
pfQuestionDialog:Hide()
pfQuestionDialog = nil
return
end
if not text then text = "Are you sure?" end
local border = tonumber(pfUI_config.appearance.border.default)
local padding = 15
-- frame
local question = CreateFrame("Frame", "pfQuestionDialog", UIParent)
question:ClearAllPoints()
question:SetPoint("CENTER", 0, 0)
question:SetFrameStrata("TOOLTIP")
question:SetMovable(true)
question:EnableMouse(true)
question:SetScript("OnMouseDown",function()
this:StartMoving()
end)
question:SetScript("OnMouseUp",function()
this:StopMovingOrSizing()
end)
pfUI.api:CreateBackdrop(question)
-- text
question.text = question:CreateFontString("Status", "LOW", "GameFontNormal")
question.text:SetFontObject(GameFontWhite)
question.text:SetPoint("TOPLEFT", question, "TOPLEFT", padding, -padding)
question.text:SetPoint("TOPRIGHT", question, "TOPRIGHT", -padding, -padding)
question.text:SetText(text)
-- editbox
if editbox then
question.input = CreateFrame("EditBox", "pfQuestionDialogEdit", question)
pfUI.api:CreateBackdrop(question.input)
question.input:SetTextColor(.2,1,.8,1)
question.input:SetJustifyH("CENTER")
question.input:SetAutoFocus(false)
question.input:SetPoint("TOPLEFT", question.text, "BOTTOMLEFT", border, -padding)
question.input:SetPoint("TOPRIGHT", question.text, "BOTTOMRIGHT", -border, -padding)
question.input:SetHeight(20)
question.input:SetFontObject(GameFontNormal)
question.input:SetScript("OnEscapePressed", function() this:ClearFocus() end)
end
-- buttons
question.yes = CreateFrame("Button", "pfQuestionDialogYes", question, "UIPanelButtonTemplate")
pfUI.api:SkinButton(question.yes)
question.yes:SetWidth(100)
question.yes:SetHeight(20)
question.yes:SetText("Yes")
question.yes:SetScript("OnClick", function()
if yes then yes() end
this:GetParent():Hide()
end)
if question.input then
question.yes:SetPoint("TOPLEFT", question.input, "BOTTOMLEFT", -border, -padding)
else
question.yes:SetPoint("TOPLEFT", question.text, "BOTTOMLEFT", 0, -padding)
end
question.no = CreateFrame("Button", "pfQuestionDialogNo", question, "UIPanelButtonTemplate")
pfUI.api:SkinButton(question.no)
question.no:SetWidth(85)
question.no:SetHeight(20)
question.no:SetText("No")
question.no:SetScript("OnClick", function()
if no then no() end
this:GetParent():Hide()
end)
if question.input then
question.no:SetPoint("TOPRIGHT", question.input, "BOTTOMRIGHT", border, -padding)
else
question.no:SetPoint("TOPRIGHT", question.text, "BOTTOMRIGHT", 0, -padding)
end
question.close = CreateFrame("Button", "pfQuestionDialogClose", question)
question.close:SetPoint("TOPRIGHT", -border, -border)
pfUI.api:CreateBackdrop(question.close)
question.close:SetHeight(10)
question.close:SetWidth(10)
question.close.texture = question.close:CreateTexture("pfQuestionDialogCloseTex")
question.close.texture:SetTexture("Interface\\AddOns\\pfUI\\img\\close")
question.close.texture:ClearAllPoints()
question.close.texture:SetAllPoints(question.close)
question.close.texture:SetVertexColor(1,.25,.25,1)
question.close:SetScript("OnEnter", function ()
this.backdrop:SetBackdropBorderColor(1,.25,.25,1)
end)
question.close:SetScript("OnLeave", function ()
pfUI.api:CreateBackdrop(this)
end)
question.close:SetScript("OnClick", function()
this:GetParent():Hide()
end)
-- resize window
local textspace = question.text:GetHeight() + padding
local inputspace = 0
if question.input then inputspace = question.input:GetHeight() + padding end
local buttonspace = question.no:GetHeight() + padding
question:SetHeight(textspace + inputspace + buttonspace + padding)
local width = 200
if question.text:GetStringWidth() > 200 then width = question.text:GetStringWidth() end
question:SetWidth( width + 2*padding)
end
-- [ Bar Layout Options ] --
-- 'barsize' size of bar in number of buttons
-- returns: array of options as strings for pfUI.gui.bar
function pfUI.api:BarLayoutOptions(barsize)
assert(barsize > 0 and barsize <= NUM_ACTIONBAR_BUTTONS,"BarLayoutOptions: barsize "..tostring(barsize).." is invalid")
local options = {}
for i,layout in ipairs(pfGridmath[barsize]) do
options[i] = string.format("%d x %d",layout[1],layout[2])
end
return options
end
-- [ Bar Layout Formfactor ] --
-- 'option' string option as used in pfUI_config.bars[bar].option
-- returns: integer formfactor
local formfactors = {} -- we'll use memoization so we only compute once, then lookup.
setmetatable(formfactors, {__mode = "v"}) -- weak table so values not referenced are collected on next gc
function pfUI.api:BarLayoutFormfactor(option)
if formfactors[option] then
return formfactors[option]
else
for barsize,_ in ipairs(pfGridmath) do
local options = pfUI.api:BarLayoutOptions(barsize)
for i,opt in ipairs(options) do
if opt == option then
formfactors[option] = i
return formfactors[option]
end
end
end
end
end
-- [ Bar Layout Size ] --
-- 'bar' frame reference,
-- 'barsize' integer number of buttons,
-- 'formfactor' string formfactor in cols x rows
function pfUI.api:BarLayoutSize(bar,barsize,formfactor,iconsize,bordersize)
assert(barsize > 0 and barsize <= NUM_ACTIONBAR_BUTTONS,"BarLayoutSize: barsize "..tostring(barsize).." is invalid")
local formfactor = pfUI.api:BarLayoutFormfactor(formfactor)
local cols, rows = unpack(pfGridmath[barsize][formfactor])
local width = (iconsize + bordersize*3) * cols - bordersize
local height = (iconsize + bordersize*3) * rows - bordersize
bar._size = {width,height}
return bar._size
end
-- [ Bar Button Anchor ] --
-- 'button' frame reference
-- 'basename' name of button frame without index
-- 'buttonindex' index number of button on bar
-- 'formfactor' string formfactor in cols x rows
function pfUI.api:BarButtonAnchor(button,basename,buttonindex,barsize,formfactor,iconsize,bordersize)
assert(barsize > 0 and barsize <= NUM_ACTIONBAR_BUTTONS,"BarButtonAnchor: barsize "..tostring(barsize).." is invalid")
local formfactor = pfUI.api:BarLayoutFormfactor(formfactor)
local parent = button:GetParent()
local cols, rows = unpack(pfGridmath[barsize][formfactor])
if buttonindex == 1 then
button._anchor = {"TOPLEFT", parent, "TOPLEFT", bordersize, -bordersize}
else
local col = buttonindex-((math.ceil(buttonindex/cols)-1)*cols)
button._anchor = col==1 and {"TOP",getglobal(basename..(buttonindex-cols)),"BOTTOM",0,-(bordersize*3)} or {"LEFT",getglobal(basename..(buttonindex-1)),"RIGHT",(bordersize*3),0}
end
return button._anchor
end
-- [ Create Autohide ] --
-- 'frame' the frame that should be hidden
function pfUI.api:CreateAutohide(frame)
if not frame then return end
frame.hover = CreateFrame("Frame", frame:GetName() .. "Autohide", frame)
frame.hover:SetParent(frame)
frame.hover:SetAllPoints(frame)
frame.hover.parent = frame
frame.hover:RegisterEvent("PLAYER_LEAVING_WORLD")
frame.hover:SetScript("OnEvent", function()
this:Hide()
end)
frame.hover:SetScript("OnUpdate", function()
if MouseIsOver(this, 10, -10, -10, 10) then
this.activeTo = GetTime() + tonumber(pfUI_config.bars.hide_time)
this.parent:SetAlpha(1)
elseif this.activeTo then
if this.activeTo < GetTime() and this.parent:GetAlpha() > 0 then
this.parent:SetAlpha(this.parent:GetAlpha() - 0.1)
end
else
this.activeTo = GetTime() + tonumber(pfUI_config.bars.hide_time)
end
end)
end
+242
View File
@@ -0,0 +1,242 @@
function pfUI:UpdateConfig(group, subgroup, entry, value)
-- check for missing config groups
if not pfUI_config[group] then
pfUI_config[group] = {}
end
-- update config
if not subgroup and entry and value and not pfUI_config[group][entry] then
pfUI_config[group][entry] = value
end
-- check for missing config subgroups
if subgroup and not pfUI_config[group][subgroup] then
pfUI_config[group][subgroup] = {}
end
-- update config in subgroup
if subgroup and entry and value and not pfUI_config[group][subgroup][entry] then
pfUI_config[group][subgroup][entry] = value
end
end
function pfUI:LoadConfig()
-- MODULE SUBGROUP ENTRY VALUE
pfUI:UpdateConfig("global", nil, "profile", "default")
pfUI:UpdateConfig("global", nil, "pixelperfect", "0")
pfUI:UpdateConfig("global", nil, "offscreen", "0")
pfUI:UpdateConfig("global", nil, "font_size", "12")
pfUI:UpdateConfig("global", nil, "font_default", "Myriad-Pro")
pfUI:UpdateConfig("global", nil, "font_square", "Homespun")
pfUI:UpdateConfig("global", nil, "font_combat", "Continuum")
pfUI:UpdateConfig("global", nil, "force_region", "1")
pfUI:UpdateConfig("global", nil, "errors_limit", "1")
pfUI:UpdateConfig("global", nil, "errors_hide", "0")
pfUI:UpdateConfig("global", nil, "hidebuff", "0")
pfUI:UpdateConfig("global", nil, "hidewbuff", "0")
pfUI:UpdateConfig("global", nil, "twentyfour", "1")
pfUI:UpdateConfig("appearance", "border", "background", "0,0,0,1")
pfUI:UpdateConfig("appearance", "border", "color", "0.3,0.3,0.3,1")
pfUI:UpdateConfig("appearance", "border", "default", "3")
pfUI:UpdateConfig("appearance", "border", "actionbars", "-1")
pfUI:UpdateConfig("appearance", "border", "unitframes", "-1")
pfUI:UpdateConfig("appearance", "border", "groupframes", "-1")
pfUI:UpdateConfig("appearance", "border", "raidframes", "-1")
pfUI:UpdateConfig("appearance", "border", "panels", "-1")
pfUI:UpdateConfig("appearance", "border", "chat", "-1")
pfUI:UpdateConfig("appearance", "border", "bags", "-1")
pfUI:UpdateConfig("appearance", "cd", "mincolor", ".2,1,1,1")
pfUI:UpdateConfig("appearance", "cd", "hourcolor", ".2,.5,1,1")
pfUI:UpdateConfig("appearance", "cd", "daycolor", ".2,.2,1,1")
pfUI:UpdateConfig("appearance", "cd", "threshold", "2")
pfUI:UpdateConfig("appearance", "castbar", "castbarcolor", ".7,.7,.9,.8")
pfUI:UpdateConfig("appearance", "castbar", "channelcolor", ".9,.9,.7,.8")
pfUI:UpdateConfig("appearance", "loot", "autoresize", "1")
pfUI:UpdateConfig("appearance", "infight", "screen", "0")
pfUI:UpdateConfig("appearance", "infight", "common", "1")
pfUI:UpdateConfig("appearance", "infight", "group", "0")
pfUI:UpdateConfig("appearance", "bags", "borderlimit", "1")
pfUI:UpdateConfig("appearance", "bags", "borderonlygear", "0")
pfUI:UpdateConfig("appearance", "minimap", "mouseoverzone", "0")
pfUI:UpdateConfig("unitframes", nil, "disable", "0")
pfUI:UpdateConfig("unitframes", nil, "pastel", "1")
pfUI:UpdateConfig("unitframes", nil, "custom", "0")
pfUI:UpdateConfig("unitframes", nil, "customcolor", ".2,.2,.2,1")
pfUI:UpdateConfig("unitframes", nil, "animation_speed", "5")
pfUI:UpdateConfig("unitframes", nil, "portraitalpha", "0.1")
pfUI:UpdateConfig("unitframes", nil, "portraittexture", "1")
pfUI:UpdateConfig("unitframes", nil, "buff_size", "20")
pfUI:UpdateConfig("unitframes", nil, "debuff_size", "20")
pfUI:UpdateConfig("unitframes", nil, "layout", "default")
pfUI:UpdateConfig("unitframes", nil, "globalclick", "0")
pfUI:UpdateConfig("unitframes", "player", "portrait", "bar")
pfUI:UpdateConfig("unitframes", "player", "width", "200")
pfUI:UpdateConfig("unitframes", "player", "height", "50")
pfUI:UpdateConfig("unitframes", "player", "pheight", "10")
pfUI:UpdateConfig("unitframes", "player", "pspace", "-3")
pfUI:UpdateConfig("unitframes", "player", "showPVPMinimap", "0")
pfUI:UpdateConfig("unitframes", "player", "showPVP", "0")
pfUI:UpdateConfig("unitframes", "player", "buffs", "top")
pfUI:UpdateConfig("unitframes", "player", "energy", "1")
pfUI:UpdateConfig("unitframes", "target", "portrait", "bar")
pfUI:UpdateConfig("unitframes", "target", "animation", "0")
pfUI:UpdateConfig("unitframes", "target", "width", "200")
pfUI:UpdateConfig("unitframes", "target", "height", "50")
pfUI:UpdateConfig("unitframes", "target", "pheight", "10")
pfUI:UpdateConfig("unitframes", "target", "pspace", "-3")
pfUI:UpdateConfig("unitframes", "target", "buffs", "top")
pfUI:UpdateConfig("unitframes", "group", "portrait", "off")
pfUI:UpdateConfig("unitframes", "group", "pspace", "-3")
pfUI:UpdateConfig("unitframes", "group", "hide_in_raid", "0")
pfUI:UpdateConfig("unitframes", "group", "clickcast", "0")
pfUI:UpdateConfig("unitframes", "group", "raid_buffs", "0")
pfUI:UpdateConfig("unitframes", "group", "raid_debuffs", "0")
pfUI:UpdateConfig("unitframes", "raid", "invert_healthbar", "0")
pfUI:UpdateConfig("unitframes", "raid", "pspace", "-3")
pfUI:UpdateConfig("unitframes", "raid", "show_missing", "0")
pfUI:UpdateConfig("unitframes", "raid", "clickcast", "")
pfUI:UpdateConfig("unitframes", "raid", "clickcast_shift", "")
pfUI:UpdateConfig("unitframes", "raid", "clickcast_alt", "")
pfUI:UpdateConfig("unitframes", "raid", "clickcast_ctrl", "")
pfUI:UpdateConfig("unitframes", "raid", "buffs_buffs", "0")
pfUI:UpdateConfig("unitframes", "raid", "buffs_hots", "0")
pfUI:UpdateConfig("unitframes", "raid", "buffs_procs", "0")
pfUI:UpdateConfig("unitframes", "raid", "buffs_classonly", "0")
pfUI:UpdateConfig("unitframes", "raid", "debuffs_enable", "0")
pfUI:UpdateConfig("unitframes", "raid", "debuffs_class", "0")
pfUI:UpdateConfig("unitframes", "ttarget", "portrait", "bar")
pfUI:UpdateConfig("unitframes", "ttarget", "pspace", "-3")
pfUI:UpdateConfig("unitframes", "pet", "portrait", "bar")
pfUI:UpdateConfig("unitframes", "pet", "pspace", "-3")
pfUI:UpdateConfig("bars", nil, "icon_size", "20")
pfUI:UpdateConfig("bars", nil, "background", "1")
pfUI:UpdateConfig("bars", nil, "glowrange", "1")
pfUI:UpdateConfig("bars", nil, "rangecolor", "1,0.1,0.1,1")
pfUI:UpdateConfig("bars", nil, "hunterbar", "1")
pfUI:UpdateConfig("bars", nil, "hide_time", "1")
pfUI:UpdateConfig("bars", nil, "hide_actionmain", "0")
pfUI:UpdateConfig("bars", nil, "hide_bottomleft", "0")
pfUI:UpdateConfig("bars", nil, "hide_bottomright", "0")
pfUI:UpdateConfig("bars", nil, "hide_right", "0")
pfUI:UpdateConfig("bars", nil, "hide_tworight", "0")
pfUI:UpdateConfig("bars", nil, "hide_shapeshift", "0")
pfUI:UpdateConfig("bars", nil, "hide_pet", "0")
pfUI:UpdateConfig("bars", "actionmain", "formfactor", "12 x 1")
pfUI:UpdateConfig("bars", "bottomleft", "formfactor", "12 x 1")
pfUI:UpdateConfig("bars", "bottomright", "formfactor", "6 x 2")
pfUI:UpdateConfig("bars", "right", "formfactor", "6 x 2")
pfUI:UpdateConfig("bars", "tworight", "formfactor", "1 x 12")
pfUI:UpdateConfig("bars", "shapeshift", "formfactor", "10 x 1")
pfUI:UpdateConfig("bars", "pet", "formfactor", "10 x 1")
pfUI:UpdateConfig("panel", "left", "left", "guild")
pfUI:UpdateConfig("panel", "left", "center", "durability")
pfUI:UpdateConfig("panel", "left", "right", "friends")
pfUI:UpdateConfig("panel", "right", "left", "fps")
pfUI:UpdateConfig("panel", "right", "center", "time")
pfUI:UpdateConfig("panel", "right", "right", "gold")
pfUI:UpdateConfig("panel", "other", "minimap", "zone")
pfUI:UpdateConfig("panel", "micro", "enable", "0")
pfUI:UpdateConfig("panel", "xp", "showalways", "0")
pfUI:UpdateConfig("castbar", "player", "hide_blizz", "1")
pfUI:UpdateConfig("castbar", "player", "hide_pfui", "0")
pfUI:UpdateConfig("castbar", "target", "hide_pfui", "0")
pfUI:UpdateConfig("tooltip", nil, "position", "bottom")
pfUI:UpdateConfig("tooltip", nil, "extguild", "1")
pfUI:UpdateConfig("tooltip", nil, "alpha", "0.8")
pfUI:UpdateConfig("tooltip", "compare", "showalways", "0")
pfUI:UpdateConfig("tooltip", "vendor", "showalways", "0")
pfUI:UpdateConfig("chat", "text", "input_width", "0")
pfUI:UpdateConfig("chat", "text", "input_height", "0")
pfUI:UpdateConfig("chat", "text", "time", "0")
pfUI:UpdateConfig("chat", "text", "timeformat", "%H:%M:%S")
pfUI:UpdateConfig("chat", "text", "timebracket", "[]")
pfUI:UpdateConfig("chat", "text", "timecolor", ".8,.8,.8,1")
pfUI:UpdateConfig("chat", "text", "classcolor", "1")
pfUI:UpdateConfig("chat", "left", "width", "380")
pfUI:UpdateConfig("chat", "left", "height", "180")
pfUI:UpdateConfig("chat", "right", "enable", "0")
pfUI:UpdateConfig("chat", "right", "alwaysshow", "0")
pfUI:UpdateConfig("chat", "right", "width", "380")
pfUI:UpdateConfig("chat", "right", "height", "180")
pfUI:UpdateConfig("chat", "global", "tabdock", "1")
pfUI:UpdateConfig("chat", "global", "custombg", "0")
pfUI:UpdateConfig("chat", "global", "background", ".2,.2,.2,.5")
pfUI:UpdateConfig("chat", "global", "border", ".4,.4,.4,.5")
pfUI:UpdateConfig("chat", "global", "whispermod", "1")
pfUI:UpdateConfig("chat", "global", "whisper", "1,.6,1,1")
pfUI:UpdateConfig("chat", "global", "sticky", "1")
pfUI:UpdateConfig("chat", "global", "fadeout", "0")
pfUI:UpdateConfig("chat", "global", "fadetime", "300")
pfUI:UpdateConfig("nameplates", nil, "showcastbar", "1")
pfUI:UpdateConfig("nameplates", nil, "spellname", "0")
pfUI:UpdateConfig("nameplates", nil, "showdebuffs", "0")
pfUI:UpdateConfig("nameplates", nil, "clickthrough", "0")
pfUI:UpdateConfig("nameplates", nil, "rightclick", "1")
pfUI:UpdateConfig("nameplates", nil, "clickthreshold", "0.5")
pfUI:UpdateConfig("nameplates", nil, "enemyclassc", "1")
pfUI:UpdateConfig("nameplates", nil, "friendclassc", "1")
pfUI:UpdateConfig("nameplates", nil, "raidiconsize", "16")
pfUI:UpdateConfig("nameplates", nil, "players", "0")
pfUI:UpdateConfig("nameplates", nil, "showhp", "0")
pfUI:UpdateConfig("nameplates", nil, "vpos", "-10")
pfUI:UpdateConfig("thirdparty", "dpsmate", "enable", "1")
pfUI:UpdateConfig("thirdparty", "wim", "enable", "1")
pfUI:UpdateConfig("thirdparty", "healcomm", "enable", "1")
pfUI:UpdateConfig("thirdparty", "cleanup", "enable", "1")
pfUI:UpdateConfig("thirdparty", "ktm", "enable", "1")
pfUI:UpdateConfig("position", nil, nil, nil)
pfUI:UpdateConfig("disabled", nil, nil, nil)
end
function pfUI:MigrateConfig()
-- config version
local major, minor, fix = pfUI.api.strsplit(".", tostring(pfUI_config.version))
local major = tonumber(major) or 0
local minor = tonumber(minor) or 0
local fix = tonumber(fix) or 0
-- migrating to new fonts (1.5 -> 1.6)
if major <= 1 and minor <= 5 then
-- migrate font_default
if pfUI_config.global.font_default == "arial" then
pfUI_config.global.font_default = "Myriad-Pro"
elseif pfUI_config.global.font_default == "homespun" then
pfUI_config.global.font_default = "Homespun"
elseif pfUI_config.global.font_default == "diediedie" then
pfUI_config.global.font_default = "DieDieDie"
end
-- migrate font_square
if pfUI_config.global.font_square == "arial" then
pfUI_config.global.font_square = "Myriad-Pro"
elseif pfUI_config.global.font_square == "homespun" then
pfUI_config.global.font_square = "Homespun"
elseif pfUI_config.global.font_square == "diediedie" then
pfUI_config.global.font_square = "DieDieDie"
end
-- migrate font_combat
if pfUI_config.global.font_combat == "arial" then
pfUI_config.global.font_combat = "Myriad-Pro"
elseif pfUI_config.global.font_combat == "homespun" then
pfUI_config.global.font_combat = "Homespun"
elseif pfUI_config.global.font_combat == "diediedie" then
pfUI_config.global.font_combat = "DieDieDie"
end
end
pfUI_config.version = pfUI.version.string
end
+621
View File
@@ -0,0 +1,621 @@
pfUI.uf = CreateFrame("Frame",nil,UIParent)
function pfUI.uf:AddIcon(frame, pos, icon)
local iconsize = 10
if not frame.hp then return end
local frame = frame.hp.bar
if pos > floor(frame:GetWidth() / iconsize) then return end
if not frame.icon then frame.icon = {} end
for i=1,6 do
if not frame.icon[i] then
frame.icon[i] = CreateFrame("Frame", frame)
frame.icon[i]:SetPoint("TOPLEFT", frame, "TOPLEFT", (i-1)*iconsize, 0)
frame.icon[i]:SetWidth(iconsize)
frame.icon[i]:SetHeight(iconsize)
frame.icon[i]:SetAlpha(.7)
frame.icon[i]:SetParent(frame)
frame.icon[i].tex = frame.icon[i]:CreateTexture("OVERLAY")
frame.icon[i].tex:SetAllPoints(frame.icon[i])
frame.icon[i].tex:SetTexCoord(.08, .92, .08, .92)
end
end
frame.icon[pos].tex:SetTexture(icon)
pfUI.api:CreateBackdrop(frame.icon[pos], nil, true)
frame.icon[pos]:Show()
end
function pfUI.uf:HideIcon(frame, pos)
if not frame or not frame.hp or not frame.hp.bar then return end
local frame = frame.hp.bar
if frame.icon and frame.icon[pos] then
frame.icon[pos]:Hide()
end
end
function pfUI.uf:SetupDebuffFilter()
if pfUI.uf.debuffs then return end
local _, myclass = UnitClass("player")
pfUI.uf.debuffs = {}
if pfUI_config.unitframes.raid.debuffs_enable == "1" then
if myclass == "PALADIN" or myclass == "PRIEST" or myclass == "WARLOCK" or pfUI_config.unitframes.raid.debuffs_class ~= "1" then
table.insert(pfUI.uf.debuffs, "magic")
end
if myclass == "DRUID" or myclass == "PALADIN" or myclass == "SHAMAN" or pfUI_config.unitframes.raid.debuffs_class ~= "1" then
table.insert(pfUI.uf.debuffs, "poison")
end
if myclass == "PRIEST" or myclass == "PALADIN" or myclass == "SHAMAN" or pfUI_config.unitframes.raid.debuffs_class ~= "1" then
table.insert(pfUI.uf.debuffs, "disease")
end
if myclass == "DRUID" or myclass == "MAGE" or pfUI_config.unitframes.raid.debuffs_class ~= "1" then
table.insert(pfUI.uf.debuffs, "curse")
end
end
end
function pfUI.uf:SetupBuffFilter()
if pfUI.uf.buffs then return end
local _, myclass = UnitClass("player")
pfUI.uf.buffs = {}
-- [[ DRUID ]]
if myclass == "DRUID" and pfUI_config.unitframes.raid.buffs_buffs == "1" then
-- Gift of the Wild
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_nature_regeneration")
-- Thorns
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_nature_thorns")
end
if (pfUI_config.unitframes.raid.buffs_classonly ~= "1" or myclass == "DRUID") and pfUI_config.unitframes.raid.buffs_hots == "1" then
-- Regrowth
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_nature_resistnature")
-- Rejuvenation
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_nature_rejuvenation")
end
-- [[ PRIEST ]]
if myclass == "PRIEST" and pfUI_config.unitframes.raid.buffs_buffs == "1" then
-- Prayer Of Fortitude"
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_wordfortitude")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_prayeroffortitude")
-- Prayer of Spirit
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_divinespirit")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_prayerofspirit")
-- Shadow Protection
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_shadow_antishadow")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_prayerofshadowprotection")
-- Fear Ward
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_excorcism")
end
if (pfUI_config.unitframes.raid.buffs_classonly ~= "1" or myclass == "PRIEST") and pfUI_config.unitframes.raid.buffs_hots == "1" then
-- Renew
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_renew")
end
if (pfUI_config.unitframes.raid.buffs_classonly ~= "1" or myclass == "PRIEST") and pfUI_config.unitframes.raid.buffs_procs == "1" then
-- Inspiration
table.insert(pfUI.uf.buffs, "interface\\icons\\inv_shield_06")
end
-- [[ PALADIN ]]
if myclass == "PALADIN" and pfUI_config.unitframes.raid.buffs_buffs == "1" then
-- Blessing of Salvation
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_greaterblessingofsalvation")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_sealofsalvation")
-- Blessing of Wisdom
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_sealofwisdom")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_greaterblessingofwisdom")
-- Blessing of Sanctuary
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_nature_lightningshield")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_greaterblessingofsanctuary")
-- Blessing of Kings
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_magic_magearmor")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_magic_greaterblessingofkings")
-- Blessing of Might
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_fistofjustice")
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_holy_greaterblessingofkings")
end
-- [[ SHAMAN ]]
if (pfUI_config.unitframes.raid.buffs_classonly ~= "1" or myclass == "SHAMAN") and pfUI_config.unitframes.raid.buffs_procs == "1" then
-- Ancestral Fortitude
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_nature_undyingstrength")
-- Healing Way
table.insert(pfUI.uf.buffs, "interface\\icons\\spell_nature_healingway")
end
-- [[ WARRIOR ]]
if myclass == "WARRIOR" and pfUI_config.unitframes.raid.buffs_buffs == "1" then
-- Battle Shout
table.insert(pfUI.uf.buffs, "interface\\icons\\ability_warrior_battleshout")
end
end
function pfUI.uf:ClickAction(button)
local label = this.label or ""
local id = this.id or ""
local unitstr = label .. id
if SpellIsTargeting() and button == "RightButton" then
SpellStopTargeting()
return
end
if SpellIsTargeting() and button == "LeftButton" then
SpellTargetUnit(unitstr)
elseif CursorHasItem() then
DropItemOnUnit(unitstr)
end
-- dropdown menues
if button == "RightButton" then
if label == "player" then
ToggleDropDownMenu(1, nil, pfUI.uf.player.Dropdown,"cursor")
if UnitIsPartyLeader("player") then
UIDropDownMenu_AddButton({text = "Reset Instances", func = ResetInstances, notCheckable = 1}, 1)
end
elseif label == "target" then
ToggleDropDownMenu(1, nil, TargetFrameDropDown, "cursor")
elseif label == "pet" then
ToggleDropDownMenu(1, nil, PetFrameDropDown, "cursor")
elseif label == "party" then
ToggleDropDownMenu(1, nil, getglobal("PartyMemberFrame" .. this.id .. "DropDown"), "cursor")
elseif label == "raid" then
ToggleDropDownMenu(1, nil, getglobal("RaidMemberFrame" .. this.id .. "DropDown"), "cursor")
FriendsDropDown.initialize = RaidFrameDropDown_Initialize
FriendsDropDown.displayMode = "MENU"
ToggleDropDownMenu(1, nil, FriendsDropDown, "cursor")
end
else
-- drop food on petframe
if label == "pet" and CursorHasItem() then
local _, playerClass = UnitClass("player")
if playerClass == "HUNTER" then
DropItemOnUnit("pet")
return
end
end
-- prevent TargetLastTarget if target was target
local tswitch = UnitIsUnit(unitstr, "target")
-- default click
TargetUnit(unitstr)
-- break here if party frame and no clickcast is activated
if label == "party" and pfUI_config.unitframes.group.clickcast == "0" and pfUI_config.unitframes.globalclick == "0" then
return
end
-- break here for non-party and non-raid frames without clickcast
if label ~= "raid" and label ~= "party" and pfUI_config.unitframes.globalclick == "0" then
return
end
-- clickcast: shift modifier
if IsShiftKeyDown() then
if pfUI_config.unitframes.raid.clickcast_shift ~= "" then
CastSpellByName(pfUI_config.unitframes.raid.clickcast_shift)
pfUI.uf.target.noanim = "yes"
if not tswitch then TargetLastTarget() end
return
end
-- clickcast: alt modifier
elseif IsAltKeyDown() then
if pfUI_config.unitframes.raid.clickcast_alt ~= "" then
CastSpellByName(pfUI_config.unitframes.raid.clickcast_alt)
pfUI.uf.target.noanim = "yes"
if not tswitch then TargetLastTarget() end
return
end
-- clickcast: ctrl modifier
elseif IsControlKeyDown() then
if pfUI_config.unitframes.raid.clickcast_ctrl ~= "" then
CastSpellByName(pfUI_config.unitframes.raid.clickcast_ctrl)
pfUI.uf.target.noanim = "yes"
if not tswitch then TargetLastTarget() end
return
end
-- clickcast: default
else
if pfUI_config.unitframes.raid.clickcast ~= "" then
CastSpellByName(pfUI_config.unitframes.raid.clickcast)
pfUI.uf.target.noanim = "yes"
if not tswitch then TargetLastTarget() end
return
end
end
end
end
function pfUI.uf:RefreshUnit(unit)
if not unit.cache then unit.cache = {} end
if not unit.id then unit.id = "" end
unit.cache.hp = UnitHealth(unit.label..unit.id)
unit.cache.hpmax = UnitHealthMax(unit.label..unit.id)
unit.cache.power = UnitMana(unit.label .. unit.id)
unit.cache.powermax = UnitManaMax(unit.label .. unit.id)
if this.label == "target" and MobHealth3 then
unit.cache.hp, unit.cache.hpmax = MobHealth3:GetUnitHealth(this.label)
end
unit.hp.bar:SetMinMaxValues(0, unit.cache.hpmax)
unit.power.bar:SetMinMaxValues(0, unit.cache.powermax)
pfUI.uf:SetupDebuffFilter()
if table.getn(pfUI.uf.debuffs) > 0 and
((pfUI_config.unitframes.group.raid_debuffs == "1" and this.label == "party") or
this.label == "raid")
then
local infected = false
for i=1,32 do
local _,_,dtype = UnitDebuff(unit.label .. unit.id, i)
if dtype then
for _, filter in pairs(pfUI.uf.debuffs) do
if filter == string.lower(dtype) then
if dtype == "Magic" then
if not unit.hp.bar.magic then
unit.hp.bar.magic = CreateFrame("Frame", unit.hp.bar)
unit.hp.bar.magic:SetAllPoints(unit)
unit.hp.bar.magic:SetParent(unit.hp.bar)
unit.hp.bar.magic.tex = unit.hp.bar.magic:CreateTexture("OVERLAY")
unit.hp.bar.magic.tex:SetAllPoints(unit.hp.bar.magic)
unit.hp.bar.magic.tex:SetTexture(.2,.8,.8,.4)
end
unit.hp.bar.magic:Show()
infected = true
elseif dtype == "Poison" then
if not unit.hp.bar.poison then
unit.hp.bar.poison = CreateFrame("Frame", unit.hp.bar)
unit.hp.bar.poison:SetAllPoints(unit)
unit.hp.bar.poison:SetParent(unit.hp.bar)
unit.hp.bar.poison.tex = unit.hp.bar.poison:CreateTexture("OVERLAY")
unit.hp.bar.poison.tex:SetAllPoints(unit.hp.bar.poison)
unit.hp.bar.poison.tex:SetTexture(.2,.8,.2,.4)
end
unit.hp.bar.poison:Show()
infected = true
elseif dtype == "Curse" then
if not unit.hp.bar.curse then
unit.hp.bar.curse = CreateFrame("Frame", unit.hp.bar)
unit.hp.bar.curse:SetAllPoints(unit)
unit.hp.bar.curse:SetParent(unit.hp.bar)
unit.hp.bar.curse.tex = unit.hp.bar.curse:CreateTexture("OVERLAY")
unit.hp.bar.curse.tex:SetAllPoints(unit.hp.bar.curse)
unit.hp.bar.curse.tex:SetTexture(.8,.2,.8,.4)
end
unit.hp.bar.curse:Show()
infected = true
elseif dtype == "Disease" then
if not unit.hp.bar.disease then
unit.hp.bar.disease = CreateFrame("Frame", unit.hp.bar)
unit.hp.bar.disease:SetAllPoints(unit)
unit.hp.bar.disease:SetParent(unit.hp.bar)
unit.hp.bar.disease.tex = unit.hp.bar.disease:CreateTexture("OVERLAY")
unit.hp.bar.disease.tex:SetAllPoints(unit.hp.bar.disease)
unit.hp.bar.disease.tex:SetTexture(.8,.8,.2,.4)
end
unit.hp.bar.disease:Show()
infected = true
end
end
end
end
end
if infected == false then
if unit.hp.bar.magic then unit.hp.bar.magic:Hide() end
if unit.hp.bar.poison then unit.hp.bar.poison:Hide() end
if unit.hp.bar.curse then unit.hp.bar.curse:Hide() end
if unit.hp.bar.disease then unit.hp.bar.disease:Hide() end
end
end
pfUI.uf:SetupBuffFilter()
if table.getn(pfUI.uf.buffs) > 0 and
((pfUI_config.unitframes.group.raid_buffs == "1" and this.label == "party") or
this.label == "raid")
then
local active = {}
for i=1,32 do
local texture = UnitBuff(unit.label .. unit.id,i)
if texture then
-- match filter
for _, filter in pairs(pfUI.uf.buffs) do
if filter == string.lower(texture) then
table.insert(active, texture)
break
end
end
-- add icons for every found buff
for pos, icon in pairs(active) do
pfUI.uf:AddIcon(this, pos, icon)
end
end
end
-- hide unued icon slots
for pos=table.getn(active)+1, 6 do
pfUI.uf:HideIcon(this, pos)
end
end
_, class = UnitClass(unit.label..unit.id)
local color = RAID_CLASS_COLORS[class]
local r, g, b = .2, .2, .2
if pfUI_config.unitframes.custom == "1" and color then
local cr, cg, cb, ca = pfUI.api.strsplit(",", pfUI_config.unitframes.customcolor)
cr, cg, cb = tonumber(cr), tonumber(cg), tonumber(cb)
unit.hp.bar:SetStatusBarColor(cr, cg, cb)
if pfUI_config.unitframes.pastel == "1" then
r, g, b = (color.r + .5) * .5, (color.g + .5) * .5, (color.b + .5) * .5
else
r, g, b = color.r, color.g, color.b
end
elseif color then
if pfUI_config.unitframes.pastel == "1" then
r, g, b = (color.r + .5) * .5, (color.g + .5) * .5, (color.b + .5) * .5
else
r, g, b = color.r, color.g, color.b
end
unit.hp.bar:SetStatusBarColor(r, g, b)
end
unit.caption:SetTextColor(r,g,b)
local p = ManaBarColor[UnitPowerType(unit.label..unit.id)]
local pr, pg, pb = 0, 0, 0
if p then pr, pg, pb = p.r + .5, p.g +.5, p.b +.5 end
unit.power.bar:SetStatusBarColor(pr, pg, pb)
if UnitName(unit.label..unit.id) then
if this.label == "raid" and unit.cache.hpmax ~= unit.cache.hp and pfUI_config.unitframes.raid.show_missing == "1" then
unit.caption:SetText("-" .. unit.cache.hpmax - unit.cache.hp)
unit.caption:SetTextColor(1,.3,.3)
else
unit.caption:SetText(UnitName(unit.label..unit.id))
if pfUI_config.unitframes.custom ~= "1" then
unit.caption:SetTextColor(1,1,1)
end
end
unit.caption:SetAllPoints(unit.hp.bar)
end
end
function pfUI.uf:CreatePortrait(frame, pos, spacing)
if not frame then return end
if pos == "off" then return end
local default_border = pfUI_config.appearance.border.default
if pfUI_config.appearance.border.unitframes ~= "-1" then
default_border = pfUI_config.appearance.border.unitframes
end
local unit = frame.label
local id = frame.id or ""
local unitstr = unit .. id
frame.portrait = CreateFrame("Frame", "pfPortrait" .. unitstr, frame)
frame.portrait:RegisterEvent("UNIT_PORTRAIT_UPDATE")
frame.portrait:RegisterEvent("UNIT_MODEL_CHANGED")
frame.portrait:RegisterEvent("PLAYER_ENTERING_WORLD")
frame.portrait:RegisterEvent("PLAYER_TARGET_CHANGED")
frame.portrait:RegisterEvent("PARTY_MEMBERS_CHANGED")
frame.portrait.base = frame
frame.portrait.pos = pos
frame.portrait.tex = frame.portrait:CreateTexture("pfPortraitTexture" .. unitstr, "OVERLAY")
frame.portrait.tex:SetAllPoints(frame.portrait)
frame.portrait.tex:SetTexCoord(.1, .9, .1, .9)
frame.portrait.model = CreateFrame("PlayerModel", "pfPortraitModel" .. unitstr, frame.portrait)
frame.portrait.model:SetFrameStrata("LOW")
frame.portrait.model:SetAllPoints(frame.portrait)
frame.portrait:SetScript("OnEvent", function()
local unit = this.base.label
local id = this.base.id or ""
local unitstr = unit .. id
if event == "PLAYER_ENTERING_WORLD" or
( event == "PARTY_MEMBERS_CHANGED" and this.base.label and this.base.label == "party" ) or
( unitstr == "target" and event == "PLAYER_TARGET_CHANGED" ) or
( unitstr == "targettarget" and event == "PLAYER_TARGET_CHANGED" ) or
( arg1 and arg1 == unitstr ) then
pfUI.uf:UpdatePortrait()
end
end)
frame.portrait:SetScript("OnShow", function()
pfUI.uf:UpdatePortrait()
end)
if pos == "bar" then
frame.portrait:SetParent(frame.hp.bar)
frame.portrait:SetAllPoints(frame.hp.bar)
frame.portrait:SetAlpha(pfUI_config.unitframes.portraitalpha)
elseif pos == "left" then
frame.portrait:SetWidth(frame:GetHeight())
frame.portrait:SetHeight(frame:GetHeight())
frame:SetWidth(frame:GetWidth() + default_border*2 + spacing + frame.portrait:GetWidth())
frame.portrait:SetPoint("LEFT", frame, "LEFT", 0, 0)
frame.hp:ClearAllPoints()
frame.hp:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, 0)
frame.power:ClearAllPoints()
frame.power:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 0)
pfUI.api:CreateBackdrop(frame.portrait)
elseif pos == "right" then
frame.portrait:SetWidth(frame:GetHeight())
frame.portrait:SetHeight(frame:GetHeight())
frame:SetWidth(frame:GetWidth() + default_border*2 + spacing + frame.portrait:GetWidth())
frame.portrait:SetPoint("RIGHT", frame, "RIGHT", 0, 0)
frame.hp:ClearAllPoints()
frame.hp:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
frame.power:ClearAllPoints()
frame.power:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, 0)
pfUI.api:CreateBackdrop(frame.portrait)
end
end
function pfUI.uf:UpdatePortrait()
local unit = this.base.label
local id = this.base.id or ""
local unitstr = unit .. id
local name = UnitName(unitstr) or ""
if not UnitIsVisible(unitstr) or not UnitIsConnected(unitstr) then
if this.pos == "bar" then
this.tex:Hide()
this.model:Hide()
elseif pfUI_config.unitframes.portraittexture == "1" then
this.tex:Show()
this.model:Hide()
SetPortraitTexture(this.tex, unitstr)
else
this.tex:Hide()
this.model:Show()
this.model:SetModelScale(4.25)
this.model:SetPosition(0, 0, -1)
this.model:SetModel("Interface\\Buttons\\talktomequestionmark.mdx")
end
else
this.tex:Hide()
this.model:Show()
this.model:SetUnit(unitstr)
this.model:SetCamera(0)
end
end
function pfUI.uf:CreateUnit(unit)
unit:RegisterEvent("UNIT_AURA")
unit:RegisterEvent("UNIT_HEALTH")
unit:RegisterEvent("UNIT_MAXHEALTH")
unit:RegisterEvent("UNIT_DISPLAYPOWER")
unit:RegisterEvent("UNIT_MANA")
unit:RegisterEvent("UNIT_MAXMANA")
unit:RegisterEvent("UNIT_RAGE")
unit:RegisterEvent("UNIT_MAXRAGE")
unit:RegisterEvent("UNIT_ENERGY")
unit:RegisterEvent("UNIT_MAXENERGY")
unit:RegisterEvent("UNIT_FOCUS")
unit:RegisterEvent("RAID_ROSTER_UPDATE")
unit:RegisterEvent("PARTY_MEMBERS_CHANGED")
unit:SetScript("OnShow", function ()
pfUI.uf:RefreshUnit(this)
end)
unit:SetScript("OnEvent", function ()
if this.label == "party" and event == "PARTY_MEMBERS_CHANGED" then
pfUI.uf:RefreshUnit(this)
end
if this.label == "raid" and event == "RAID_ROSTER_UPDATE" then
pfUI.uf:RefreshUnit(this)
end
if arg1 and arg1 == this.label .. this.id then
pfUI.uf:RefreshUnit(this)
end
end)
unit:SetScript("OnClick", function ()
pfUI.uf:ClickAction(arg1)
end)
unit:SetScript("OnEnter", function()
GameTooltip_SetDefaultAnchor(GameTooltip, this)
GameTooltip:SetUnit(this.label .. this.id)
GameTooltip:Show()
end)
unit:SetScript("OnLeave", function()
GameTooltip:FadeOut()
end)
unit:SetScript("OnUpdate", function ()
if CheckInteractDistance(this.label .. this.id, 4) or not UnitName(this.label .. this.id) then
this:SetAlpha(1)
else
this:SetAlpha(.5)
end
if UnitIsConnected(this.label .. this.id) then
if not this.cache then return end
local hpDisplay = this.hp.bar:GetValue()
local hpReal = this.cache.hp
local hpDiff = abs(hpReal - hpDisplay)
if this.label == "raid" and pfUI_config.unitframes.raid.invert_healthbar == "1" then
hpDisplay = this.hp.bar:GetValue()
hpReal = this.cache.hpmax - this.cache.hp
hpDiff = abs(hpReal - hpDisplay)
end
if hpDisplay < hpReal then
this.hp.bar:SetValue(hpDisplay + ceil(hpDiff / pfUI_config.unitframes.animation_speed))
elseif hpDisplay > hpReal then
this.hp.bar:SetValue(hpDisplay - ceil(hpDiff / pfUI_config.unitframes.animation_speed))
else
this.hp.bar:SetValue(hpReal)
end
local powerDisplay = this.power.bar:GetValue()
local powerReal = this.cache.power
local powerDiff = abs(powerReal - powerDisplay)
if powerDisplay < powerReal then
this.power.bar:SetValue(powerDisplay + ceil(powerDiff / pfUI_config.unitframes.animation_speed))
elseif powerDisplay > powerReal then
this.power.bar:SetValue(powerDisplay - ceil(powerDiff / pfUI_config.unitframes.animation_speed))
else
this.power.bar:SetValue(this.cache.power)
end
else
this.hp.bar:SetMinMaxValues(0, 100)
this.power.bar:SetMinMaxValues(0, 100)
this.hp.bar:SetValue(0)
this.power.bar:SetValue(0)
end
end)
end