diff --git a/api/unitframes.lua b/api/unitframes.lua index 28b33d88..4132b4ed 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -12,6 +12,26 @@ local uf_defaults = { debuffsize = "20", } +local pfValidUnits = {} +pfValidUnits["player"] = true +pfValidUnits["target"] = true +pfValidUnits["pet"] = true +pfValidUnits["mouseover"] = true + +pfValidUnits["player" .. "target"] = true +pfValidUnits["target" .. "target"] = true +pfValidUnits["pet" .. "target"] = true + +for i=1,4 do pfValidUnits["party" .. i] = true end +for i=1,4 do pfValidUnits["partypet" .. i] = true end +for i=1,40 do pfValidUnits["raid" .. i] = true end +for i=1,40 do pfValidUnits["raidpet" .. i] = true end + +for i=1,4 do pfValidUnits["party" .. i .. "target"] = true end +for i=1,4 do pfValidUnits["partypet" .. i .. "target"] = true end +for i=1,40 do pfValidUnits["raid" .. i .. "target"] = true end +for i=1,40 do pfValidUnits["raidpet" .. i .. "target"] = true end + function pfUI.uf:CreateUnitFrame(unit, id, config, tick) local fname if unit == "Party" then @@ -31,6 +51,13 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) local f = CreateFrame("Button", "pf" .. fname, UIParent) + if not pfValidUnits[unit .. id] then + f.unitname = unit + f.RegisterEvent = function() return end + unit = "mouseover" + id = "" + end + f.UpdateFrameSize = pfUI.uf.UpdateFrameSize f.GetColor = pfUI.uf.GetColor @@ -163,6 +190,27 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) end) f:SetScript("OnUpdate", function() + local unitname = ( this.label and UnitName(this.label) ) or "" + + if this.unitname and this.unitname ~= strlower(unitname) then + -- invalid focus frame + for unit, bool in pairs(pfValidUnits) do + local scan = UnitName(unit) or "" + if this.unitname == strlower(scan) then + this.label = unit + this.portrait.model.lastUnit = nil + this.instantRefresh = true + pfUI.uf:RefreshUnit(this, "all") + return + end + this.label = nil + this.instantRefresh = true + this.hp.bar:SetStatusBarColor(.2,.2,.2) + end + end + + if not this.label then return end + if this.tick and not this.lastTick then this.lastTick = GetTime() + this.tick end if this.lastTick and this.lastTick < GetTime() then this.lastTick = GetTime() + this.tick @@ -235,6 +283,7 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) end end) f:SetScript("OnEnter", function() + if not this.label then return end GameTooltip_SetDefaultAnchor(GameTooltip, this) GameTooltip:SetUnit(this.label .. this.id) GameTooltip:Show() @@ -243,6 +292,7 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) GameTooltip:FadeOut() end) f:SetScript("OnClick", function () + if not this.label then return end pfUI.uf:ClickAction(arg1) end) @@ -319,6 +369,8 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) f.buffs[i]:SetHeight(f.config.buffsize) f.buffs[i]:SetScript("OnEnter", function() + if not this:GetParent().label then return end + GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT") if this:GetParent().label == "player" then GameTooltip:SetPlayerBuff(GetPlayerBuff(id-1,"HELPFUL")) @@ -472,6 +524,8 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) end function pfUI.uf:RefreshUnit(unit, component) + if not unit.label then return end + local component = component or "" -- break early on misconfigured UF's if not unit.label then return end diff --git a/modules/focus.lua b/modules/focus.lua new file mode 100644 index 00000000..5effdfdf --- /dev/null +++ b/modules/focus.lua @@ -0,0 +1,10 @@ +pfUI:RegisterModule("focus", function () + -- do not go further on disabled UFs + if C.unitframes.disable == "1" then return end + + pfUI.uf.focus = pfUI.uf:CreateUnitFrame("Focus", nil, nil, .2) + pfUI.uf.focus:UpdateFrameSize() + pfUI.uf.focus:SetPoint("CENTER", UIParent, "CENTER", 0,0) + UpdateMovable(pfUI.uf.focus) + pfUI.uf.focus:Hide() +end) diff --git a/pfUI.lua b/pfUI.lua index e21dfd99..50b28307 100644 --- a/pfUI.lua +++ b/pfUI.lua @@ -17,6 +17,19 @@ function SlashCmdList.GM(msg, editbox) ToggleHelpFrame(1) end +SLASH_PFFOCUS1 = '/focus' +function SlashCmdList.PFFOCUS(msg) + if msg ~= "" then + pfUI.uf.focus:Show() + pfUI.uf.focus.unitname = strlower(msg) + elseif UnitName("target") then + pfUI.uf.focus:Show() + pfUI.uf.focus.unitname = strlower(UnitName("target")) + else + pfUI.uf.focus:Hide() + end +end + pfUI = CreateFrame("Frame",nil,UIParent) pfUI:RegisterEvent("ADDON_LOADED") diff --git a/pfUI.toc b/pfUI.toc index 6e8c7c23..374c54b4 100644 --- a/pfUI.toc +++ b/pfUI.toc @@ -40,6 +40,7 @@ modules\addons.lua modules\minimap.lua modules\panel.lua modules\player.lua +modules\focus.lua modules\target.lua modules\targettarget.lua modules\pet.lua