buff: add buff frames

This commit is contained in:
shagu
2018-03-26 18:26:33 +02:00
parent cdb9d876a7
commit 8fb5f3a10d
5 changed files with 254 additions and 118 deletions
+3 -3
View File
@@ -710,13 +710,13 @@ function pfUI.api.GetColoredTimeString(remaining)
if not remaining then return "" end
if remaining > 99 * 60 * 60 then
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.daycolor)
return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60 / 60 / 24) .. "d"
return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60 / 60 / 24) .. "|rd"
elseif remaining > 99 * 60 then
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.hourcolor)
return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60 / 60) .. "h"
return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60 / 60) .. "|rh"
elseif remaining > 99 then
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.minutecolor)
return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60) .. "m"
return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60) .. "|rm"
elseif remaining <= 5 then
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.lowcolor)
return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining)
+16
View File
@@ -44,6 +44,15 @@ function pfUI:LoadConfig()
pfUI:UpdateConfig("global", nil, "autorepair", "0")
pfUI:UpdateConfig("gui", nil, "reloadmarker", "0")
pfUI:UpdateConfig("buffs", nil, "buffs", "1")
pfUI:UpdateConfig("buffs", nil, "debuffs", "1")
pfUI:UpdateConfig("buffs", nil, "weapons", "1")
pfUI:UpdateConfig("buffs", nil, "size", "24")
pfUI:UpdateConfig("buffs", nil, "spacing", "5")
pfUI:UpdateConfig("buffs", nil, "rowsize", "16")
pfUI:UpdateConfig("buffs", nil, "textinside", "0")
pfUI:UpdateConfig("buffs", nil, "fontsize", "-1")
pfUI:UpdateConfig("appearance", "border", "background", "0,0,0,1")
pfUI:UpdateConfig("appearance", "border", "color", "0.2,0.2,0.2,1")
pfUI:UpdateConfig("appearance", "border", "default", "3")
@@ -796,5 +805,12 @@ function pfUI:MigrateConfig()
end
end
-- migrating old buff settings (> 3.6.1)
if checkversion(3, 6, 1) then
pfUI_config.buffs.weapons = pfUI_config.global.hidewbuff == "1" and "0" or "1"
pfUI_config.buffs.buffs = pfUI_config.global.hidebuff == "1" and "0" or "1"
pfUI_config.buffs.debuffs = pfUI_config.global.hidebuff == "1" and "0" or "1"
end
pfUI_config.version = pfUI.version.string
end
+214 -112
View File
@@ -1,125 +1,227 @@
pfUI:RegisterModule("buff", function ()
pfUI.buff = CreateFrame("Frame")
-- Hide Blizz
BuffFrame:Hide()
BuffFrame:UnregisterAllEvents()
TemporaryEnchantFrame:Hide()
TemporaryEnchantFrame:UnregisterAllEvents()
local function RefreshBuffButton(buff)
buff.id = buff.gid - (buff.btype == "HELPFUL" and pfUI.buff.buffs.offset or 0)
buff.bid = GetPlayerBuff(buff.id-1, buff.btype)
-- detect weapon buffs
if buff.gid <= pfUI.buff.buffs.offset and buff.btype == "HELPFUL" then
local mh, mhtime, mhcharge, oh, ohtime, ohcharge = GetWeaponEnchantInfo()
if pfUI.buff.buffs.offset == 2 then
if buff.gid == 1 then
buff.mode = "MAINHAND"
else
buff.mode = "OFFHAND"
end
else
buff.mode = oh and "OFFHAND" or mh and "MAINHAND"
end
-- Set Weapon Texture and Border
if buff.mode == "MAINHAND" then
buff.texture:SetTexture(GetInventoryItemTexture("player", 16))
buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(GetInventoryItemQuality("player", 16) or 1))
elseif buff.mode == "OFFHAND" then
buff.texture:SetTexture(GetInventoryItemTexture("player", 17))
buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(GetInventoryItemQuality("player", 17) or 1))
end
elseif buff.bid >= 0 and (( buff.btype == "HARMFUL" and C.buffs.debuffs == "1" ) or ( buff.btype == "HELPFUL" and C.buffs.buffs == "1" )) then
-- Set Buff Texture and Border
buff.mode = buff.btype
buff.texture:SetTexture(GetPlayerBuffTexture(buff.bid))
CreateBackdrop(buff)
if buff.btype == "HARMFUL" then
local dtype = GetPlayerBuffDispelType(buff.bid)
if dtype == "Magic" then
buff.backdrop:SetBackdropBorderColor(0,1,1,1)
elseif dtype == "Poison" then
buff.backdrop:SetBackdropBorderColor(0,1,0,1)
elseif dtype == "Curse" then
buff.backdrop:SetBackdropBorderColor(1,0,1,1)
elseif dtype == "Disease" then
buff.backdrop:SetBackdropBorderColor(1,1,0,1)
else
buff.backdrop:SetBackdropBorderColor(1,0,0,1)
end
end
else
buff:Hide()
return
end
buff:Show()
end
local function CreateBuffButton(i, btype)
local buff = CreateFrame("Button", ( btype == "HELPFUL" and "pfBuffFrameBuff" or "pfDebuffFrameBuff" ) .. i, ( btype == "HARMFUL" and pfUI.buff.debuffs or pfUI.buff.buffs ))
buff.texture = buff:CreateTexture("BuffIcon" .. i, "BACKGROUND")
buff.texture:SetTexCoord(.07,.93,.07,.93)
buff.texture:SetAllPoints(buff)
buff.timer = buff:CreateFontString(nil, "OVERLAY", "GameFontNormal")
buff.timer:SetTextColor(1,1,1,1)
buff.timer:SetJustifyH("CENTER")
buff.timer:SetJustifyV("CENTER")
buff.stacks = buff:CreateFontString(nil, "OVERLAY", "GameFontNormal")
buff.stacks:SetTextColor(1,1,1,1)
buff.stacks:SetJustifyH("RIGHT")
buff.stacks:SetJustifyV("BOTTOM")
buff.stacks:SetAllPoints(buff)
buff.btype = btype
buff.gid = i
buff:SetScript("OnUpdate", function()
if not this.next then this.next = GetTime() + .1 end
if this.next > GetTime() then return end
this.next = GetTime() + .1
local timeleft = 0
local stacks = 0
if this.mode == this.btype then
timeleft = GetPlayerBuffTimeLeft(this.bid, this.btype)
stacks = GetPlayerBuffApplications(this.bid, this.btype)
elseif this.mode == "MAINHAND" then
local _, mhtime, mhcharge = GetWeaponEnchantInfo()
timeleft = mhtime/1000
stacks = mhcharge
elseif this.mode == "OFFHAND" then
local _, _, _, _, ohtime, ohcharge = GetWeaponEnchantInfo()
timeleft = ohtime/1000
charge = ohcharge
end
this.timer:SetText(timeleft > 0 and GetColoredTimeString(timeleft) or "")
this.stacks:SetText(stacks > 1 and stacks or "")
end)
buff:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
if this.mode == this.btype then
GameTooltip:SetPlayerBuff(GetPlayerBuff(this.bid, this.btype))
elseif this.mode == "MAINHAND" then
GameTooltip:SetInventoryItem("player", 16)
elseif this.mode == "OFFHAND" then
GameTooltip:SetInventoryItem("player", 17)
end
end)
buff:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
buff:SetScript("OnClick", function()
CancelPlayerBuff(GetPlayerBuff(this.bid, this.btype))
end)
CreateBackdrop(buff)
RefreshBuffButton(buff)
return buff
end
local function GetNumBuffs()
local mh, mhtime, mhcharge, oh, ohtime, ohcharge = GetWeaponEnchantInfo()
local offset = (mh and 1 or 0) + (oh and 1 or 0)
for i=1,32 do
local bid, untilCancelled = GetPlayerBuff(i-1, "HELPFUL")
if bid < 0 then
return i - 1 + offset
end
end
return 0 + offset
end
pfUI.buff = CreateFrame("Frame", "pfGlobalBuffFrame", UIParent)
pfUI.buff:RegisterEvent("PLAYER_AURAS_CHANGED")
pfUI.buff:RegisterEvent("UNIT_INVENTORY_CHANGED")
pfUI.buff:RegisterEvent("UNIT_AURA")
pfUI.buff:RegisterEvent("UNIT_MODEL_CHANGED")
pfUI.buff:SetScript("OnEvent", function ()
if event == "UNIT_AURA" and arg1 ~= "player" then return end
pfUI.buff:UpdateSkin()
end)
-- weapon enchant stacks
TempEnchant1.stacks = TempEnchant1:CreateFontString(nil, "OVERLAY", "GameFontNormal")
TempEnchant1.stacks:SetFont(pfUI.font_default, 14, "OUTLINE")
TempEnchant1.stacks:SetTextColor(1,1,1,1)
TempEnchant1.stacks:ClearAllPoints()
TempEnchant1.stacks:SetAllPoints(TempEnchant1)
TempEnchant1.stacks:SetJustifyH("RIGHT")
TempEnchant1.stacks:SetJustifyV("BOTTOM")
TempEnchant2.stacks = TempEnchant2:CreateFontString(nil, "OVERLAY", "GameFontNormal")
TempEnchant2.stacks:SetFont(pfUI.font_default, 14, "OUTLINE")
TempEnchant2.stacks:SetTextColor(1,1,1,1)
TempEnchant2.stacks:ClearAllPoints()
TempEnchant2.stacks:SetAllPoints(TempEnchant2)
TempEnchant2.stacks:SetJustifyH("RIGHT")
TempEnchant2.stacks:SetJustifyV("BOTTOM")
-- This hack is used to update the border again and again up to 10 seconds.
-- On a reload the item rarity can not be detected instantly. It requries
-- some seconds after the correct border color will be shown.
pfUI.buff.lastUpdate = 0
pfUI.buff.updateInterval = .05
pfUI.buff:SetScript("OnUpdate", function()
if pfUI.buff.lastUpdate + pfUI.buff.updateInterval < GetTime() then
pfUI.buff:UpdateSkin()
pfUI.buff.lastUpdate = GetTime()
pfUI.buff.updateInterval = pfUI.buff.updateInterval + pfUI.buff.updateInterval
pfUI.buff:SetScript("OnEvent", function()
if C.buffs.weapons == "1" then
local mh, mhtime, mhcharge, oh, ohtime, ohcharge = GetWeaponEnchantInfo()
pfUI.buff.buffs.offset = (mh and 1 or 0) + (oh and 1 or 0)
else
pfUI.buff.buffs.offset = 0
end
if pfUI.buff.updateInterval > 10 then
pfUI.buff:Hide()
for i=1,32 do
RefreshBuffButton(pfUI.buff.buffs.buttons[i])
end
for i=1,16 do
RefreshBuffButton(pfUI.buff.debuffs.buttons[i])
end
end)
function pfUI.buff:UpdateSkin()
-- buff positions
TemporaryEnchantFrame:ClearAllPoints()
TemporaryEnchantFrame:SetPoint("TOPRIGHT", pfUI.minimap or Minimap, "TOPLEFT", -25,0)
-- Buff Frame
pfUI.buff.buffs = CreateFrame("Frame", "pfBuffFrame", UIParent)
pfUI.buff.buffs.offset = 0
pfUI.buff.buffs.buttons = {}
for i=1,32 do
pfUI.buff.buffs.buttons[i] = CreateBuffButton(i, "HELPFUL")
end
if C.global.hidewbuff == "1" then
TemporaryEnchantFrame:Hide()
BuffFrame:SetPoint("TOPRIGHT", pfUI.minimap or Minimap, "TOPLEFT", -25,0)
-- Debuffs
pfUI.buff.debuffs = CreateFrame("Frame", "pfDebuffFrame", UIParent)
pfUI.buff.debuffs.buttons = {}
for i=1,16 do
pfUI.buff.debuffs.buttons[i] = CreateBuffButton(i, "HARMFUL")
end
-- config loading
function pfUI.buff:UpdateConfigBuffButton(buff)
local fontsize = C.buffs.fontsize == "-1" and C.global.font_size or C.buffs.fontsize
local rowcount = floor((buff.gid-1) / tonumber(C.buffs.rowsize))
buff:SetWidth(tonumber(C.buffs.size))
buff:SetHeight(tonumber(C.buffs.size))
buff:ClearAllPoints()
buff:SetPoint("TOPRIGHT", ( buff.btype == "HARMFUL" and pfUI.buff.debuffs or pfUI.buff.buffs ), "TOPRIGHT", -(buff.gid-1-rowcount*tonumber(C.buffs.rowsize))*(tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)), -(rowcount) * ((C.buffs.textinside == "1" and 0 or (fontsize*1.5))+tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
buff.timer:SetFont(pfUI.font_default, fontsize, "OUTLINE")
buff.stacks:SetFont(pfUI.font_default, fontsize+1, "OUTLINE")
buff.timer:SetHeight(fontsize * 1.3)
buff.timer:ClearAllPoints()
if C.buffs.textinside == "1" then
buff.timer:SetAllPoints(buff)
else
-- weapon enchants
for _,buff in pairs ({TempEnchant1,TempEnchant2}) do
local icon = _G[buff:GetName().."Icon"]
local border = _G[buff:GetName().."Border"]
local text = _G[buff:GetName().."Duration"]
text:SetPoint("TOP", buff, "BOTTOM", 0 , -C.appearance.border.default*2)
local _, _, mainhand, _, _, offhand = GetWeaponEnchantInfo()
if buff then
CreateBackdrop(buff)
icon:SetTexCoord(.08, .92, .08, .92)
border:Hide()
end
if buff:GetID() == 16 then
local link = GetInventoryItemLink("player", 16)
if not link then break end
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)")
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
if itemRarity then buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(itemRarity)) end
if mainhand and mainhand > 0 then
buff.stacks:SetText(mainhand)
buff.stacks:Show()
else
buff.stacks:Hide()
end
elseif buff:GetID() == 17 then
local link = GetInventoryItemLink("player", 17)
if not link then break end
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)")
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
if itemRarity then buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(itemRarity)) end
if offhand and offhand > 0 then
buff.stacks:SetText(offhand)
buff.stacks:Show()
else
buff.stacks:Hide()
end
end
end
end
if C.global.hidebuff == "1" then
BuffFrame:Hide()
else
-- buffs
for i=0,32 do
local buff = _G["BuffButton" .. i]
if buff then
local icon = _G[buff:GetName().."Icon"]
local border = _G[buff:GetName().."Border"]
local text = _G[buff:GetName().."Duration"]
if i < 8 and i > 0 then
buff:SetPoint("TOPRIGHT", _G["BuffButton" .. i-1], "TOPLEFT", -7, 0)
elseif i < 16 and i > 8 then
buff:SetPoint("TOPRIGHT", _G["BuffButton" .. i-1], "TOPLEFT", -7, 0)
elseif i > 16 then
buff:SetPoint("TOPRIGHT", _G["BuffButton" .. i-1], "TOPLEFT", -7, 0)
end
CreateBackdrop(buff)
text:SetPoint("TOP", buff, "BOTTOM", 0 , -C.appearance.border.default*2)
icon:SetTexCoord(.08, .92, .08, .92)
if border then
buff.backdrop:SetBackdropBorderColor(border:GetVertexColor())
border:Hide()
end
end
end
buff.timer:SetPoint("TOP", buff, "BOTTOM", 0, -3)
end
end
function pfUI.buff:UpdateConfig()
local fontsize = C.buffs.fontsize == "-1" and C.global.font_size or C.buffs.fontsize
pfUI.buff.buffs:SetWidth(tonumber(C.buffs.rowsize) * (tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
pfUI.buff.buffs:SetHeight(ceil(32/tonumber(C.buffs.rowsize)) * ((C.buffs.textinside == "1" and 0 or (fontsize*1.5))+tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
pfUI.buff.buffs:SetPoint("TOPRIGHT", pfUI.minimap or UIParent, "TOPLEFT", -2*tonumber(C.buffs.spacing), 0)
UpdateMovable(pfUI.buff.buffs)
pfUI.buff.debuffs:SetWidth(tonumber(C.buffs.rowsize) * (tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
pfUI.buff.debuffs:SetHeight(ceil(16/tonumber(C.buffs.rowsize)) * ((C.buffs.textinside == "1" and 0 or (fontsize*1.5))+tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
pfUI.buff.debuffs:SetPoint("TOPRIGHT", pfUI.buff.buffs, "BOTTOMRIGHT", 0, 0)
UpdateMovable(pfUI.buff.debuffs)
for i=1,32 do
pfUI.buff:UpdateConfigBuffButton(pfUI.buff.buffs.buttons[i])
end
for i=1,16 do
pfUI.buff:UpdateConfigBuffButton(pfUI.buff.debuffs.buttons[i])
end
pfUI.buff:GetScript("OnEvent")()
end
pfUI.buff:UpdateConfig()
end)
+20 -2
View File
@@ -948,8 +948,6 @@ pfUI:RegisterModule("gui", function ()
if not this.setup then
CreateConfig(nil, this, T["Enable Zone Text On Minimap Mouseover"], C.appearance.minimap, "mouseoverzone", "checkbox")
CreateConfig(nil, this, T["Coordinates Location"], C.appearance.minimap, "coordsloc", "dropdown", pfUI.gui.dropdowns.minimap_cords_position)
CreateConfig(nil, this, T["Disable Minimap Buffs"], C.global, "hidebuff", "checkbox")
CreateConfig(nil, this, T["Disable Minimap Weapon Buffs"], C.global, "hidewbuff", "checkbox")
CreateConfig(nil, this, T["Show PvP Icon"], C.unitframes.player, "showPVPMinimap", "checkbox")
CreateConfig(nil, this, T["Show Inactive Tracking"], C.appearance.minimap, "tracking_pulse", "checkbox")
CreateConfig(nil, this, T["Tracking Icon Size"], C.appearance.minimap, "tracking_size")
@@ -957,6 +955,26 @@ pfUI:RegisterModule("gui", function ()
end
end)
-- [[ Buffs ]]
pfUI.gui.tabs.buffs = pfUI.gui.tabs:CreateTabChild(T["Buffs"], nil, nil, nil, true)
pfUI.gui.tabs.buffs.tabs = CreateTabFrame(pfUI.gui.tabs.buffs, "TOP", true)
-- >> General
pfUI.gui.tabs.buffs.tabs.general = pfUI.gui.tabs.buffs.tabs:CreateTabChild(T["Buffs"], true)
pfUI.gui.tabs.buffs.tabs.general:SetScript("OnShow", function()
if not this.setup then
CreateConfig(update["buff"], this, T["Enable Buff Display"], C.buffs, "buffs", "checkbox")
CreateConfig(update["buff"], this, T["Enable Debuff Display"], C.buffs, "debuffs", "checkbox")
CreateConfig(update["buff"], this, T["Enable Weapon Buff Display"], C.buffs, "weapons", "checkbox")
CreateConfig(update["buff"], this, T["Buff Size"], C.buffs, "size")
CreateConfig(update["buff"], this, T["Buff Spacing"], C.buffs, "spacing")
CreateConfig(update["buff"], this, T["Number Of Buffs Per Row"], C.buffs, "rowsize")
CreateConfig(update["buff"], this, T["Show Duration Inside Buff"], C.buffs, "textinside", "checkbox")
CreateConfig(update["buff"], this, T["Buff Font Size"], C.buffs, "fontsize")
this.setup = true
end
end)
-- [[ Actionbar ]]
pfUI.gui.tabs.actionbar = pfUI.gui.tabs:CreateTabChild(T["Actionbar"], nil, nil, nil, true)
+1 -1
View File
@@ -2,7 +2,7 @@
## Title: |cff33ffccpf|cffffffffUI
## Author: Shagu
## Notes: A complete user interface replacement.
## Version: 3.6.1
## Version: 3.7.0
## SavedVariables: pfUI_profiles, pfUI_gold
## SavedVariablesPerCharacter: pfUI_config, pfUI_init, pfUI_playerDB