compat: initial layout of client abstraction api

This commit is contained in:
shagu
2018-11-01 14:55:29 +01:00
parent 6e98880a84
commit 5dfe5a4899
21 changed files with 289 additions and 252 deletions
+7 -47
View File
@@ -3,6 +3,10 @@ pfUI.api = { }
-- load pfUI environment
setfenv(1, pfUI:GetEnvironment())
-- Client API shortcuts
gfind = string.gmatch or string.gfind
mod = math.mod or mod
-- [ strsplit ]
-- Splits a string using a delimiter.
-- 'delimiter' [string] characters that will be interpreted as delimiter
@@ -110,11 +114,11 @@ end
-- 'f' [float] the number to breakdown.
-- returns: [int],[float] whole and fractional part.
function pfUI.api.modf(f)
if math.modf then return math.modf(f) end
if modf then return modf(f) end
if f > 0 then
return math.floor(f), math.mod(f,1)
return math.floor(f), mod(f,1)
end
return math.ceil(f), math.mod(f,1)
return math.ceil(f), mod(f,1)
end
-- [ SanitizePattern ]
@@ -283,47 +287,6 @@ do -- create a scope so we don't have to worry about upvalue collisions
end
end
-- [ hooksecurefunc ]
-- Hooks a global function and injects custom code
-- 'name' [string] name of the function that should 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.hooksecurefunc(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(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
pfUI.hooks[tostring(func)]["old"](a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
pfUI.hooks[tostring(func)]["new"](a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
end
else
pfUI.hooks[tostring(func)]["function"] = function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
pfUI.hooks[tostring(func)]["new"](a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
pfUI.hooks[tostring(func)]["old"](a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
end
end
_G[name] = pfUI.hooks[tostring(func)]["function"]
end
-- [ HookScript ]
-- Sets a function to be called automatically after the original function is called
-- 'f' [frame] the frame that should get a function hook
-- 'script' [string] the name of the function that should be hooked
-- 'func' [function] the function that should run after the original one
function pfUI.api.HookScript(f, script, func)
local prev = f:GetScript(script)
f:SetScript(script, function()
if prev then prev() end
func()
end)
end
-- [ HookAddonOrVariable ]
-- Sets a function to be called automatically once an addon gets loaded
-- 'addon' [string] addon or variable name
@@ -903,6 +866,3 @@ function pfUI.api.GetColorGradient(perc)
gradientcolors[perc].b,
gradientcolors[perc].h
end
-- [ shortcuts ]
pfUI.api.gfind = string.gfind
-71
View File
@@ -1,71 +0,0 @@
if pfUI.client < 20000 then return end
message("TBC compat module loaded. Good Luck!")
-- load pfUI environment
setfenv(1, pfUI:GetEnvironment())
-- the "MiniMapTrackingFrame" is called "MiniMapTracking"
pfUI.api.MiniMapTrackingFrame = _G.MiniMapTracking
pfUI.api.UIOptionsFrame = _G.InterfaceOptionsFrame
-- tbc name of the friendlist button has changed
for i=1, FRIENDS_TO_DISPLAY do
_G["FriendsFrameFriendButton"..i.."ButtonTextNameLocation"] = _G["FriendsFrameFriendButton"..i.."ButtonTextLocation"]
end
-- gfind got replaced by gmatch
pfUI.api.gfind = string.gmatch
-- blacklist pfUI functions
pfUI.api.hooksecurefunc = _G.hooksecurefunc
-- tbc removed the offset of -1
function pfUI.api.GetPlayerBuff(id, btype)
return _G.GetPlayerBuff(id+1, btype)
end
-- tbc uses a "Cooldown" frametype
function pfUI.api.CreateFrame(f, n, p, t)
if f == "Model" and t == "CooldownFrameTemplate" then
return _G.CreateFrame("Cooldown", n, p, t)
elseif f == "LootButton" then
local ret = _G.CreateFrame("Button", n, p, t)
ret.SetSlot = ret.SetID
return ret
else
return _G.CreateFrame(f, n, p, t)
end
end
-- fake vanilla UnitBuff return values
function pfUI.api.UnitBuff(unitstr, i)
local name, rank, icon, count = _G.UnitBuff(unitstr, i)
return icon, count
end
-- fake vanilla UnitDebuff return values
function pfUI.api.UnitDebuff(unitstr, i)
local name, rank, texture, stacks, dtype, duration, timeLeft = _G.UnitDebuff(unitstr, i)
return texture, stacks, dtype
end
-- use native UnitDebuff instead of libdebuff emulation
pfUI.api.libdebuff = {
["UnitDebuff"] = function(self, unit, i)
return _G.UnitDebuff(unit, i)
end
}
-- blacklist unrequired modules
pfUI.module.autoshift = true
pfUI.module.itemclick = true
-- the function GetContainerNumSlots returns numbers for keyrings in tbc
function pfUI.api.GetContainerNumSlots(bag)
if bag == -2 and pfUI.bag and not pfUI.bag.showKeyring then
return 0
else
return _G.GetContainerNumSlots(bag)
end
end
+15 -15
View File
@@ -376,7 +376,7 @@ function pfUI.uf:UpdateConfig()
f.buffs[i].stacks:SetShadowColor(0, 0, 0)
f.buffs[i].stacks:SetShadowOffset(0.8, -0.8)
f.buffs[i].stacks:SetTextColor(1,1,.5)
f.buffs[i].cd = f.buffs[i].cd or CreateFrame("Model", nil, f.buffs[i])
f.buffs[i].cd = f.buffs[i].cd or CreateFrame(COOLDOWN_FRAME_TYPE, nil, f.buffs[i])
f.buffs[i].cd.pfCooldownType = "ALL"
f.buffs[i]:RegisterForClicks("RightButtonUp")
@@ -403,7 +403,7 @@ function pfUI.uf:UpdateConfig()
if f:GetName() == "pfPlayer" then
f.buffs[i]:SetScript("OnUpdate", function()
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .4 end
local timeleft = GetPlayerBuffTimeLeft(GetPlayerBuff(this:GetID()-1,"HELPFUL"))
local timeleft = GetPlayerBuffTimeLeft(GetPlayerBuff(PLAYER_BUFF_START_ID+this:GetID(),"HELPFUL"))
CooldownFrame_SetTimer(this.cd, GetTime(), timeleft, 1)
end)
end
@@ -414,13 +414,13 @@ function pfUI.uf:UpdateConfig()
GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
if parent.label == "player" then
GameTooltip:SetPlayerBuff(GetPlayerBuff(id-1,"HELPFUL"))
GameTooltip:SetPlayerBuff(GetPlayerBuff(PLAYER_BUFF_START_ID+id,"HELPFUL"))
else
GameTooltip:SetUnitBuff(parent.label .. parent.id, id)
end
if IsShiftKeyDown() then
local texture = parent.label == "player" and GetPlayerBuffTexture(GetPlayerBuff(id-1,"HELPFUL")) or UnitBuff(parent.label .. parent.id, id)
local texture = parent.label == "player" and GetPlayerBuffTexture(GetPlayerBuff(PLAYER_BUFF_START_ID+id,"HELPFUL")) or UnitBuff(parent.label .. parent.id, id)
local playerlist = ""
local first = true
@@ -463,7 +463,7 @@ function pfUI.uf:UpdateConfig()
f.buffs[i]:SetScript("OnClick", function()
if this:GetParent().label == "player" then
CancelPlayerBuff(GetPlayerBuff(id-1,"HELPFUL"))
CancelPlayerBuff(GetPlayerBuff(PLAYER_BUFF_START_ID+id,"HELPFUL"))
end
end)
end
@@ -493,7 +493,7 @@ function pfUI.uf:UpdateConfig()
f.debuffs[i].stacks:SetShadowColor(0, 0, 0)
f.debuffs[i].stacks:SetShadowOffset(0.8, -0.8)
f.debuffs[i].stacks:SetTextColor(1,1,.5)
f.debuffs[i].cd = f.debuffs[i].cd or CreateFrame("Model", nil, f.debuffs[i])
f.debuffs[i].cd = f.debuffs[i].cd or CreateFrame(COOLDOWN_FRAME_TYPE, nil, f.debuffs[i])
f.debuffs[i].cd.pfCooldownType = "ALL"
f.debuffs[i]:RegisterForClicks("RightButtonUp")
@@ -505,7 +505,7 @@ function pfUI.uf:UpdateConfig()
if f:GetName() == "pfPlayer" then
f.debuffs[i]:SetScript("OnUpdate", function()
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .4 end
local timeleft = GetPlayerBuffTimeLeft(GetPlayerBuff(this:GetID()-1,"HARMFUL"))
local timeleft = GetPlayerBuffTimeLeft(GetPlayerBuff(PLAYER_BUFF_START_ID+this:GetID(),"HARMFUL"))
CooldownFrame_SetTimer(this.cd, GetTime(), timeleft, 1)
end)
end
@@ -514,7 +514,7 @@ function pfUI.uf:UpdateConfig()
if not this:GetParent().label then return end
GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
if this:GetParent().label == "player" then
GameTooltip:SetPlayerBuff(GetPlayerBuff(id-1,"HARMFUL"))
GameTooltip:SetPlayerBuff(GetPlayerBuff(PLAYER_BUFF_START_ID+id,"HARMFUL"))
else
GameTooltip:SetUnitDebuff(this:GetParent().label .. this:GetParent().id, id)
end
@@ -526,7 +526,7 @@ function pfUI.uf:UpdateConfig()
f.debuffs[i]:SetScript("OnClick", function()
if this:GetParent().label == "player" then
CancelPlayerBuff(GetPlayerBuff(id-1,"HARMFUL"))
CancelPlayerBuff(GetPlayerBuff(PLAYER_BUFF_START_ID+id,"HARMFUL"))
end
end)
end
@@ -1061,8 +1061,8 @@ function pfUI.uf:RefreshUnit(unit, component)
for i=1, unit.config.bufflimit do
local texture, stacks
if unit.label == "player" then
stacks = GetPlayerBuffApplications(GetPlayerBuff(i-1,"HELPFUL"))
texture = GetPlayerBuffTexture(GetPlayerBuff(i-1,"HELPFUL"))
stacks = GetPlayerBuffApplications(GetPlayerBuff(PLAYER_BUFF_START_ID+i,"HELPFUL"))
texture = GetPlayerBuffTexture(GetPlayerBuff(PLAYER_BUFF_START_ID+i,"HELPFUL"))
else
texture, stacks = UnitBuff(unitstr, i)
end
@@ -1120,9 +1120,9 @@ function pfUI.uf:RefreshUnit(unit, component)
local texture, stacks, dtype
if unit.label == "player" then
texture = GetPlayerBuffTexture(GetPlayerBuff(i-1, "HARMFUL"))
stacks = GetPlayerBuffApplications(GetPlayerBuff(i-1, "HARMFUL"))
dtype = GetPlayerBuffDispelType(GetPlayerBuff(i-1, "HARMFUL"))
texture = GetPlayerBuffTexture(GetPlayerBuff(PLAYER_BUFF_START_ID+i, "HARMFUL"))
stacks = GetPlayerBuffApplications(GetPlayerBuff(PLAYER_BUFF_START_ID+i, "HARMFUL"))
dtype = GetPlayerBuffDispelType(GetPlayerBuff(PLAYER_BUFF_START_ID+i, "HARMFUL"))
else
texture, stacks, dtype = UnitDebuff(unitstr, i)
end
@@ -1143,7 +1143,7 @@ function pfUI.uf:RefreshUnit(unit, component)
unit.debuffs[i]:Show()
if unit:GetName() == "pfPlayer" then
local timeleft = GetPlayerBuffTimeLeft(GetPlayerBuff(unit.debuffs[i]:GetID() - 1, "HARMFUL"),"HARMFUL")
local timeleft = GetPlayerBuffTimeLeft(GetPlayerBuff(PLAYER_BUFF_START_ID+unit.debuffs[i]:GetID(), "HARMFUL"),"HARMFUL")
CooldownFrame_SetTimer(unit.debuffs[i].cd, GetTime(), timeleft, 1)
elseif libdebuff then
local name, rank, texture, stacks, dtype, duration, timeleft = libdebuff:UnitDebuff(unitstr, i)