mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-29 10:46:03 +00:00
233cd182cd
Improve inspect/character item display using Nampower APIs
363 lines
12 KiB
Lua
363 lines
12 KiB
Lua
local slots = {
|
|
"HeadSlot",
|
|
"NeckSlot",
|
|
"ShoulderSlot",
|
|
"BackSlot",
|
|
"ChestSlot",
|
|
"ShirtSlot",
|
|
"TabardSlot",
|
|
"WristSlot",
|
|
"HandsSlot",
|
|
"WaistSlot",
|
|
"LegsSlot",
|
|
"FeetSlot",
|
|
"Finger0Slot",
|
|
"Finger1Slot",
|
|
"Trinket0Slot",
|
|
"Trinket1Slot",
|
|
"MainHandSlot",
|
|
"SecondaryHandSlot",
|
|
"RangedSlot",
|
|
}
|
|
|
|
pfUI:RegisterSkin("Inspect", "tbc", function ()
|
|
local rawborder, border = GetBorderSize()
|
|
local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel()
|
|
|
|
HookAddonOrVariable("Blizzard_InspectUI", function()
|
|
CreateBackdrop(InspectFrame, nil, nil, .75)
|
|
CreateBackdropShadow(InspectFrame)
|
|
|
|
InspectFrame.backdrop:SetPoint("TOPLEFT", 10, -10)
|
|
InspectFrame.backdrop:SetPoint("BOTTOMRIGHT", -30, 72)
|
|
InspectFrame:SetHitRectInsets(10,30,10,72)
|
|
EnableMovable("InspectFrame", "Blizzard_InspectUI", INSPECTFRAME_SUBFRAMES)
|
|
|
|
SkinCloseButton(InspectFrameCloseButton, InspectFrame.backdrop, -6, -6)
|
|
|
|
InspectFrame:DisableDrawLayer("ARTWORK")
|
|
|
|
InspectNameText:ClearAllPoints()
|
|
InspectNameText:SetPoint("TOP", InspectFrame.backdrop, "TOP", 0, -10)
|
|
InspectGuildText:Show()
|
|
InspectGuildText:ClearAllPoints()
|
|
InspectGuildText:SetPoint("TOP", InspectLevelText, "BOTTOM", 0, -1)
|
|
|
|
for i = 1, 3 do
|
|
local tab = _G["InspectFrameTab"..i]
|
|
local lastTab = _G["InspectFrameTab"..(i-1)]
|
|
tab:ClearAllPoints()
|
|
if lastTab then
|
|
tab:SetPoint("LEFT", lastTab, "RIGHT", border*2 + 1, 0)
|
|
else
|
|
tab:SetPoint("TOPLEFT", InspectFrame.backdrop, "BOTTOMLEFT", bpad, -(border + (border == 1 and 1 or 2)))
|
|
end
|
|
SkinTab(tab)
|
|
end
|
|
|
|
do -- Character Tab
|
|
StripTextures(InspectPaperDollFrame)
|
|
|
|
EnableClickRotate(InspectModelFrame)
|
|
InspectModelRotateLeftButton:Hide()
|
|
InspectModelRotateRightButton:Hide()
|
|
|
|
for _, slot in pairs(slots) do
|
|
local frame = _G["Inspect"..slot]
|
|
SkinButton(frame, nil, nil, nil, _G["Inspect"..slot.."IconTexture"], true)
|
|
end
|
|
|
|
hooksecurefunc("InspectPaperDollFrame_OnShow", function()
|
|
local guild, title = GetGuildInfo(InspectFrame.unit)
|
|
local text = guild and format(TEXT(GUILD_TITLE_TEMPLATE), title, guild) or ""
|
|
InspectGuildText:SetText(text)
|
|
end)
|
|
|
|
local function RefreshTbcSlots()
|
|
local unit = InspectFrame.unit
|
|
local guid = unit and GetUnitGUID and GetUnitGUID(unit)
|
|
if not guid then return end
|
|
for _, slot in pairs(slots) do
|
|
local btn = _G["Inspect"..slot]
|
|
if btn then
|
|
local slotId = btn:GetID()
|
|
local npItem = GetEquippedItem and GetEquippedItem(guid, slotId)
|
|
if npItem and npItem.itemId and npItem.itemId > 0 then
|
|
local itemId = npItem.itemId
|
|
local displayInfoId = GetItemStatsField and GetItemStatsField(itemId, "displayInfoID")
|
|
local texName = displayInfoId and GetItemIconTexture and GetItemIconTexture(displayInfoId)
|
|
local tex = texName and ("Interface\\Icons\\" .. texName)
|
|
if tex then SetItemButtonTexture(btn, tex) end
|
|
local itemStats = GetItemStats and GetItemStats(itemId)
|
|
local quality = itemStats and itemStats.quality
|
|
if quality and quality > 0 then
|
|
btn:SetBackdropBorderColor(GetItemQualityColor(quality))
|
|
else
|
|
btn:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
|
end
|
|
else
|
|
btn:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local npDelayTbc = CreateFrame("Frame")
|
|
npDelayTbc:Hide()
|
|
npDelayTbc.elapsed = 0
|
|
npDelayTbc:SetScript("OnUpdate", function()
|
|
npDelayTbc.elapsed = npDelayTbc.elapsed + arg1
|
|
if npDelayTbc.elapsed >= 0.3 then
|
|
npDelayTbc:Hide()
|
|
npDelayTbc.elapsed = 0
|
|
RefreshTbcSlots()
|
|
end
|
|
end)
|
|
|
|
hooksecurefunc("InspectPaperDollItemSlotButton_Update", function(button)
|
|
npDelayTbc.elapsed = 0
|
|
npDelayTbc:Show()
|
|
end)
|
|
end
|
|
|
|
do -- PVP Tab
|
|
StripTextures(InspectPVPFrame)
|
|
end
|
|
|
|
do -- Talent Tab
|
|
StripTextures(InspectTalentFrame)
|
|
InspectTalentFrameCancelButton:Hide()
|
|
InspectTalentFrameCloseButton:Hide()
|
|
|
|
InspectTalentFrameSpentPoints:ClearAllPoints()
|
|
InspectTalentFrameSpentPoints:SetPoint("BOTTOMRIGHT", InspectTalentFrame, "BOTTOMRIGHT", 0, 83)
|
|
|
|
StripTextures(InspectTalentFrameScrollFrame)
|
|
SkinScrollbar(InspectTalentFrameScrollFrameScrollBar)
|
|
|
|
for i = 1, MAX_NUM_TALENTS do
|
|
local talent = _G["InspectTalentFrameTalent"..i]
|
|
if talent then
|
|
StripTextures(talent)
|
|
SkinButton(talent, nil, nil, nil, _G["InspectTalentFrameTalent"..i.."IconTexture"])
|
|
|
|
_G["InspectTalentFrameTalent"..i.."Rank"]:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
|
|
end
|
|
end
|
|
|
|
for i = 1, 3 do
|
|
local tab = _G["InspectTalentFrameTab"..i]
|
|
local lastTab = _G["InspectTalentFrameTab"..(i-1)]
|
|
tab:ClearAllPoints()
|
|
if lastTab then
|
|
tab:SetPoint("LEFT", lastTab, "RIGHT", border*2 + 1, 0)
|
|
else
|
|
tab:SetPoint("TOPLEFT", 70, -50)
|
|
end
|
|
SkinTab(tab)
|
|
end
|
|
end
|
|
end)
|
|
end)
|
|
|
|
pfUI:RegisterSkin("Inspect", "vanilla", function ()
|
|
local rawborder, border = GetBorderSize()
|
|
local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel()
|
|
|
|
HookAddonOrVariable("Blizzard_InspectUI", function()
|
|
CreateBackdrop(InspectFrame, nil, nil, .75)
|
|
CreateBackdropShadow(InspectFrame)
|
|
|
|
InspectFrame.backdrop:SetPoint("TOPLEFT", 10, -10)
|
|
InspectFrame.backdrop:SetPoint("BOTTOMRIGHT", -30, 72)
|
|
InspectFrame:SetHitRectInsets(10,30,10,72)
|
|
EnableMovable("InspectFrame", "Blizzard_InspectUI", INSPECTFRAME_SUBFRAMES)
|
|
|
|
SkinCloseButton(InspectFrameCloseButton, InspectFrame.backdrop, -6, -6)
|
|
|
|
InspectFrame:DisableDrawLayer("ARTWORK")
|
|
|
|
InspectNameText:ClearAllPoints()
|
|
InspectNameText:SetPoint("TOP", InspectFrame.backdrop, "TOP", 0, -10)
|
|
|
|
SkinTab(InspectFrameTab1)
|
|
InspectFrameTab1:ClearAllPoints()
|
|
InspectFrameTab1:SetPoint("TOPLEFT", InspectFrame.backdrop, "BOTTOMLEFT", bpad, -(border + (border == 1 and 1 or 2)))
|
|
SkinTab(InspectFrameTab2)
|
|
InspectFrameTab2:ClearAllPoints()
|
|
InspectFrameTab2:SetPoint("LEFT", InspectFrameTab1, "RIGHT", border*2 + 1, 0)
|
|
|
|
do -- Character Tab
|
|
StripTextures(InspectPaperDollFrame)
|
|
|
|
EnableClickRotate(InspectModelFrame)
|
|
InspectModelRotateLeftButton:Hide()
|
|
InspectModelRotateRightButton:Hide()
|
|
|
|
for _, slot in pairs(slots) do
|
|
local frame = _G["Inspect"..slot]
|
|
StripTextures(frame)
|
|
CreateBackdrop(frame)
|
|
SetAllPointsOffset(frame.backdrop, frame, 0)
|
|
HandleIcon(frame.backdrop, _G["Inspect"..slot.."IconTexture"])
|
|
|
|
-- Nampower-based tooltip via hyperlink
|
|
local funce = frame:GetScript("OnEnter")
|
|
frame:SetScript("OnEnter", function()
|
|
local unit = InspectFrame.unit
|
|
local guid = unit and GetUnitGUID and GetUnitGUID(unit)
|
|
local slotId = this:GetID()
|
|
local npItem = guid and GetEquippedItem and GetEquippedItem(guid, slotId)
|
|
if npItem and npItem.itemId and npItem.itemId > 0 then
|
|
local itemId = npItem.itemId
|
|
local enchantId = npItem.permanentEnchantId or 0
|
|
GameTooltip:SetOwner(this, "ANCHOR_TOPRIGHT")
|
|
GameTooltip:SetHyperlink("item:" .. itemId .. ":" .. enchantId .. ":0:0:0:0:0:0")
|
|
GameTooltip:Show()
|
|
elseif funce then
|
|
funce()
|
|
end
|
|
end)
|
|
frame:SetScript("OnLeave", function()
|
|
GameTooltip:Hide()
|
|
end)
|
|
end
|
|
|
|
-- cache: prefetched item data per guid, keyed by slot name
|
|
local npCache = {}
|
|
local npCacheGuid = nil
|
|
|
|
local function PrefetchTarget(unit)
|
|
if not unit then return end
|
|
if not CanInspect(unit) then return end
|
|
local guid = GetUnitGUID and GetUnitGUID(unit)
|
|
if not guid then return end
|
|
|
|
npCacheGuid = guid
|
|
npCache = {}
|
|
|
|
for i, vslot in pairs(slots) do
|
|
local slotId = GetInventorySlotInfo(vslot)
|
|
local npItem = GetEquippedItem and GetEquippedItem(guid, slotId)
|
|
local itemId = npItem and npItem.itemId and npItem.itemId > 0 and npItem.itemId
|
|
if itemId then
|
|
local enchantId = npItem.permanentEnchantId or 0
|
|
local displayInfoId = GetItemStatsField and GetItemStatsField(itemId, "displayInfoID")
|
|
local texName = displayInfoId and GetItemIconTexture and GetItemIconTexture(displayInfoId)
|
|
local tex = texName and ("Interface\\Icons\\" .. texName)
|
|
local itemStats = GetItemStats and GetItemStats(itemId)
|
|
local quality = itemStats and itemStats.quality
|
|
npCache[vslot] = { itemId=itemId, enchantId=enchantId, tex=tex, quality=quality }
|
|
else
|
|
npCache[vslot] = false
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
local npDelay = CreateFrame("Frame")
|
|
npDelay:Hide()
|
|
npDelay.elapsed = 0
|
|
|
|
local function UpdateSlots()
|
|
if not InspectFrame.unit then return end
|
|
|
|
-- check if all icons are ready, retry if not
|
|
local allReady = true
|
|
for i, vslot in pairs(slots) do
|
|
local d = npCache[vslot]
|
|
if d and not d.tex then
|
|
allReady = false
|
|
break
|
|
end
|
|
end
|
|
|
|
if not allReady then
|
|
npDelay.elapsed = 0
|
|
npDelay:Show()
|
|
return
|
|
end
|
|
|
|
-- guild text
|
|
local guild, title, rank = GetGuildInfo(InspectFrame.unit)
|
|
if guild then
|
|
InspectGuildText:SetPoint("TOP", InspectLevelText, "BOTTOM", 0, -1)
|
|
InspectGuildText:SetText(format(TEXT(GUILD_TITLE_TEMPLATE), title, guild))
|
|
InspectGuildText:Show()
|
|
else
|
|
InspectGuildText:SetText("")
|
|
InspectGuildText:Hide()
|
|
end
|
|
|
|
for i, vslot in pairs(slots) do
|
|
local frame = _G["Inspect" .. vslot]
|
|
local d = npCache[vslot]
|
|
|
|
if d then
|
|
SetItemButtonTexture(frame, d.tex)
|
|
frame.hasItem = 1
|
|
if d.quality and d.quality > 0 then
|
|
local r, g, b = GetItemQualityColor(d.quality)
|
|
frame.backdrop:SetBackdropBorderColor(r, g, b, 1)
|
|
else
|
|
frame.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
|
end
|
|
if ShaguScore then
|
|
if not frame.scoreText then
|
|
frame.scoreText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
|
frame.scoreText:SetFont(pfUI.font_default, 12, "OUTLINE")
|
|
frame.scoreText:SetPoint("TOPRIGHT", 0, 0)
|
|
end
|
|
local itemLevel = ShaguScore.Database[d.itemId] or 0
|
|
local score = d.quality and ShaguScore:Calculate(vslot, d.quality, itemLevel) or 0
|
|
if score and score > 0 then
|
|
local r, g, b = GetItemQualityColor(d.quality)
|
|
frame.scoreText:SetText(score)
|
|
frame.scoreText:SetTextColor(r, g, b)
|
|
else
|
|
frame.scoreText:SetText("")
|
|
end
|
|
end
|
|
else
|
|
CreateBackdrop(frame)
|
|
SetAllPointsOffset(frame.backdrop, frame, 0)
|
|
frame.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
|
if frame.scoreText then frame.scoreText:SetText("") end
|
|
end
|
|
end
|
|
end
|
|
|
|
npDelay:SetScript("OnUpdate", function()
|
|
npDelay.elapsed = npDelay.elapsed + arg1
|
|
if npDelay.elapsed >= 0.02 then
|
|
npDelay:Hide()
|
|
npDelay.elapsed = 0
|
|
PrefetchTarget(InspectFrame.unit)
|
|
UpdateSlots()
|
|
end
|
|
end)
|
|
|
|
-- item swap during inspect: re-prefetch and re-apply
|
|
hooksecurefunc("InspectPaperDollItemSlotButton_Update", function(button)
|
|
if not npDelay:IsShown() then
|
|
npDelay.elapsed = 0
|
|
npDelay:Show()
|
|
end
|
|
end)
|
|
|
|
-- on open: prefetch and apply immediately
|
|
hooksecurefunc("InspectPaperDollFrame_OnShow", function()
|
|
PrefetchTarget(InspectFrame.unit)
|
|
UpdateSlots()
|
|
end)
|
|
end
|
|
|
|
do -- Honor Tab
|
|
StripTextures(InspectHonorFrame)
|
|
|
|
CreateBackdrop(InspectHonorFrameProgressBar)
|
|
InspectHonorFrameProgressBar:SetStatusBarTexture(pfUI.media["img:bar"])
|
|
InspectHonorFrameProgressBar:SetHeight(24)
|
|
end
|
|
end)
|
|
end) |