mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-22 20:10:50 +00:00
update - read description
Improve inspect/character item display using Nampower APIs
This commit is contained in:
@@ -88,11 +88,21 @@ pfUI:RegisterSkin("Character", "vanilla:tbc", function ()
|
|||||||
|
|
||||||
local function RefreshCharacterSlot(slot)
|
local function RefreshCharacterSlot(slot)
|
||||||
local slotId = slot:GetID()
|
local slotId = slot:GetID()
|
||||||
local link = GetInventoryItemLink("player", slotId)
|
if slotId < 1 or slotId > 19 then return end
|
||||||
|
local npItem = GetEquippedItem and GetEquippedItem("player", slotId)
|
||||||
if slot and slot.backdrop then
|
if slot and slot.backdrop then
|
||||||
if link then
|
if npItem and npItem.itemId and npItem.itemId > 0 then
|
||||||
|
local itemId = npItem.itemId -- extract immediately, table is reused
|
||||||
|
|
||||||
|
-- icon via Nampower
|
||||||
|
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(slot, tex) end
|
||||||
|
|
||||||
local isBroken = GetInventoryItemBroken("player", slotId)
|
local isBroken = GetInventoryItemBroken("player", slotId)
|
||||||
local quality = GetInventoryItemQuality("player", slotId)
|
local itemStats = GetItemStats and GetItemStats(itemId)
|
||||||
|
local quality = itemStats and itemStats.quality
|
||||||
if isBroken then
|
if isBroken then
|
||||||
slot.backdrop:SetBackdropBorderColor(0.9, 0, 0, 1)
|
slot.backdrop:SetBackdropBorderColor(0.9, 0, 0, 1)
|
||||||
elseif quality and quality > 0 then
|
elseif quality and quality > 0 then
|
||||||
@@ -101,24 +111,25 @@ pfUI:RegisterSkin("Character", "vanilla:tbc", function ()
|
|||||||
else
|
else
|
||||||
slot.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
slot.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
slot.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
|
||||||
end
|
|
||||||
|
|
||||||
if ShaguScore and link then
|
if ShaguScore and quality then
|
||||||
local _, _, itemID = string.find(GetInventoryItemLink("player", slotId), "item:(%d+):%d+:%d+:%d+")
|
local itemLevel = ShaguScore.Database[itemId] or 0
|
||||||
local itemLevel = ShaguScore.Database[tonumber(itemID)] or 0
|
local itemSlot = itemStats and itemStats.inventoryType
|
||||||
local _, _, quality, _, _, _, _, _, itemSlot, _ = GetItemInfo(itemID)
|
local score = ShaguScore:Calculate(itemSlot, quality, itemLevel)
|
||||||
local score = ShaguScore:Calculate(itemSlot, quality, itemLevel)
|
if score and score > 0 then
|
||||||
if score and score > 0 and quality and quality > 0 then
|
local r, g, b = GetItemQualityColor(quality)
|
||||||
local r,g,b = GetItemQualityColor(quality)
|
slot.scoreText:SetText(score)
|
||||||
slot.scoreText:SetText(score)
|
slot.scoreText:SetTextColor(r, g, b, 1)
|
||||||
slot.scoreText:SetTextColor(r, g, b, 1)
|
else
|
||||||
|
slot.scoreText:SetText("")
|
||||||
|
slot.scoreText:SetTextColor(1, 1, 1, 1)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
slot.scoreText:SetText("")
|
slot.scoreText:SetText("")
|
||||||
slot.scoreText:SetTextColor(1, 1, 1, 1)
|
slot.scoreText:SetTextColor(1, 1, 1, 1)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
slot.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
||||||
slot.scoreText:SetText("")
|
slot.scoreText:SetText("")
|
||||||
slot.scoreText:SetTextColor(1, 1, 1, 1)
|
slot.scoreText:SetTextColor(1, 1, 1, 1)
|
||||||
end
|
end
|
||||||
@@ -174,6 +185,23 @@ pfUI:RegisterSkin("Character", "vanilla:tbc", function ()
|
|||||||
|
|
||||||
HandleIcon(frame.backdrop, _G["Character"..slotName.."IconTexture"])
|
HandleIcon(frame.backdrop, _G["Character"..slotName.."IconTexture"])
|
||||||
|
|
||||||
|
-- Nampower-backed tooltip via hyperlink
|
||||||
|
frame:SetScript("OnEnter", function()
|
||||||
|
local slotId = this:GetID()
|
||||||
|
if slotId < 1 or slotId > 19 then return end
|
||||||
|
local npItem = GetEquippedItem and GetEquippedItem("player", 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()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
frame:SetScript("OnLeave", function()
|
||||||
|
GameTooltip:Hide()
|
||||||
|
end)
|
||||||
|
|
||||||
if not frame.scoreText then
|
if not frame.scoreText then
|
||||||
frame.scoreText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
frame.scoreText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||||
frame.scoreText:SetFont(pfUI.font_default, 12, "OUTLINE")
|
frame.scoreText:SetFont(pfUI.font_default, 12, "OUTLINE")
|
||||||
|
|||||||
+155
-70
@@ -73,15 +73,50 @@ pfUI:RegisterSkin("Inspect", "tbc", function ()
|
|||||||
InspectGuildText:SetText(text)
|
InspectGuildText:SetText(text)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hooksecurefunc("InspectPaperDollItemSlotButton_Update", function(button)
|
local function RefreshTbcSlots()
|
||||||
local unit = InspectFrame.unit
|
local unit = InspectFrame.unit
|
||||||
local link = GetInventoryItemLink(unit, button:GetID())
|
local guid = unit and GetUnitGUID and GetUnitGUID(unit)
|
||||||
if link then
|
if not guid then return end
|
||||||
local quality = select(3, GetItemInfo(link))
|
for _, slot in pairs(slots) do
|
||||||
button:SetBackdropBorderColor(GetItemQualityColor(quality))
|
local btn = _G["Inspect"..slot]
|
||||||
else
|
if btn then
|
||||||
button:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
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
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -130,8 +165,6 @@ pfUI:RegisterSkin("Inspect", "vanilla", function ()
|
|||||||
local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel()
|
local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel()
|
||||||
|
|
||||||
HookAddonOrVariable("Blizzard_InspectUI", function()
|
HookAddonOrVariable("Blizzard_InspectUI", function()
|
||||||
local cache = {}
|
|
||||||
|
|
||||||
CreateBackdrop(InspectFrame, nil, nil, .75)
|
CreateBackdrop(InspectFrame, nil, nil, .75)
|
||||||
CreateBackdropShadow(InspectFrame)
|
CreateBackdropShadow(InspectFrame)
|
||||||
|
|
||||||
@@ -166,25 +199,86 @@ pfUI:RegisterSkin("Inspect", "vanilla", function ()
|
|||||||
StripTextures(frame)
|
StripTextures(frame)
|
||||||
CreateBackdrop(frame)
|
CreateBackdrop(frame)
|
||||||
SetAllPointsOffset(frame.backdrop, frame, 0)
|
SetAllPointsOffset(frame.backdrop, frame, 0)
|
||||||
|
|
||||||
HandleIcon(frame.backdrop, _G["Inspect"..slot.."IconTexture"])
|
HandleIcon(frame.backdrop, _G["Inspect"..slot.."IconTexture"])
|
||||||
|
|
||||||
|
-- Nampower-based tooltip via hyperlink
|
||||||
local funce = frame:GetScript("OnEnter")
|
local funce = frame:GetScript("OnEnter")
|
||||||
frame:SetScript("OnEnter", function()
|
frame:SetScript("OnEnter", function()
|
||||||
local bid = this:GetID()
|
local unit = InspectFrame.unit
|
||||||
if not GetInventoryItemLink(InspectFrame.unit, this:GetID()) and this.hasItem then
|
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:SetOwner(this, "ANCHOR_TOPRIGHT")
|
||||||
GameTooltip:SetHyperlink("item:"..cache[bid]["id"])
|
GameTooltip:SetHyperlink("item:" .. itemId .. ":" .. enchantId .. ":0:0:0:0:0:0")
|
||||||
GameTooltip:Show()
|
GameTooltip:Show()
|
||||||
else
|
elseif funce then
|
||||||
funce()
|
funce()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
frame:SetScript("OnLeave", function()
|
||||||
|
GameTooltip:Hide()
|
||||||
|
end)
|
||||||
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()
|
local function UpdateSlots()
|
||||||
if not InspectFrame.unit then return end
|
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)
|
local guild, title, rank = GetGuildInfo(InspectFrame.unit)
|
||||||
if guild then
|
if guild then
|
||||||
InspectGuildText:SetPoint("TOP", InspectLevelText, "BOTTOM", 0, -1)
|
InspectGuildText:SetPoint("TOP", InspectLevelText, "BOTTOM", 0, -1)
|
||||||
@@ -196,74 +290,65 @@ pfUI:RegisterSkin("Inspect", "vanilla", function ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
for i, vslot in pairs(slots) do
|
for i, vslot in pairs(slots) do
|
||||||
local id = GetInventorySlotInfo(vslot)
|
local frame = _G["Inspect" .. vslot]
|
||||||
local link = GetInventoryItemLink(InspectFrame.unit, id)
|
local d = npCache[vslot]
|
||||||
local slot = _G["Inspect" .. vslot]
|
|
||||||
local retry = false
|
|
||||||
|
|
||||||
if link and slot.hasItem then
|
if d then
|
||||||
local _, _, link = string.find(link, "(item:%d+:%d+:%d+:%d+)")
|
SetItemButtonTexture(frame, d.tex)
|
||||||
local _, _, quality = GetItemInfo(link)
|
frame.hasItem = 1
|
||||||
|
if d.quality and d.quality > 0 then
|
||||||
if not quality then
|
local r, g, b = GetItemQualityColor(d.quality)
|
||||||
retry = true
|
frame.backdrop:SetBackdropBorderColor(r, g, b, 1)
|
||||||
else
|
else
|
||||||
slot.backdrop:SetBackdropBorderColor(GetItemQualityColor(quality))
|
frame.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
||||||
|
end
|
||||||
if ShaguScore then
|
if ShaguScore then
|
||||||
if not slot.scoreText then
|
if not frame.scoreText then
|
||||||
slot.scoreText = slot:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
frame.scoreText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||||
slot.scoreText:SetFont(pfUI.font_default, 12, "OUTLINE")
|
frame.scoreText:SetFont(pfUI.font_default, 12, "OUTLINE")
|
||||||
slot.scoreText:SetPoint("TOPRIGHT", 0, 0)
|
frame.scoreText:SetPoint("TOPRIGHT", 0, 0)
|
||||||
end
|
end
|
||||||
|
local itemLevel = ShaguScore.Database[d.itemId] or 0
|
||||||
local r,g,b = GetItemQualityColor(quality)
|
local score = d.quality and ShaguScore:Calculate(vslot, d.quality, itemLevel) or 0
|
||||||
local _, _, itemID = string.find(link, "item:(%d+):%d+:%d+:%d+")
|
if score and score > 0 then
|
||||||
local itemLevel = ShaguScore.Database[tonumber(itemID)] or 0
|
local r, g, b = GetItemQualityColor(d.quality)
|
||||||
local score = ShaguScore:Calculate(vslot, quality, itemLevel)
|
frame.scoreText:SetText(score)
|
||||||
if score and score > 0 then
|
frame.scoreText:SetTextColor(r, g, b)
|
||||||
slot.scoreText:SetText(score)
|
else
|
||||||
slot.scoreText:SetTextColor(r, g, b)
|
frame.scoreText:SetText("")
|
||||||
else
|
|
||||||
slot.scoreText:SetText("")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif slot.hasItem then
|
|
||||||
retry = true
|
|
||||||
else
|
else
|
||||||
CreateBackdrop(slot)
|
CreateBackdrop(frame)
|
||||||
SetAllPointsOffset(slot.backdrop, slot, 0)
|
SetAllPointsOffset(frame.backdrop, frame, 0)
|
||||||
if slot.scoreText then
|
frame.backdrop:SetBackdropBorderColor(pfUI.cache.er, pfUI.cache.eg, pfUI.cache.eb, pfUI.cache.ea)
|
||||||
slot.scoreText:SetText("")
|
if frame.scoreText then frame.scoreText:SetText("") end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if retry == true and InspectFrame.unit then
|
|
||||||
QueueFunction(UpdateSlots)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
hooksecurefunc("InspectPaperDollItemSlotButton_Update", function(button)
|
npDelay:SetScript("OnUpdate", function()
|
||||||
local bid = button:GetID()
|
npDelay.elapsed = npDelay.elapsed + arg1
|
||||||
local link = GetInventoryItemLink(InspectFrame.unit, bid)
|
if npDelay.elapsed >= 0.02 then
|
||||||
if link then
|
npDelay:Hide()
|
||||||
local _,_,itemID = string.find(link, 'item:(%d+)')
|
npDelay.elapsed = 0
|
||||||
cache[bid] = cache[bid] or {}
|
PrefetchTarget(InspectFrame.unit)
|
||||||
cache[bid]["id"] = itemID
|
UpdateSlots()
|
||||||
cache[bid]["tex"] = GetInventoryItemTexture(InspectFrame.unit, button:GetID())
|
|
||||||
cache[bid]["count"] = GetInventoryItemCount(InspectFrame.unit, button:GetID())
|
|
||||||
cache[bid]["name"] = UnitName(InspectFrame.unit)
|
|
||||||
elseif cache[bid] and UnitName(InspectFrame.unit) == cache[bid].name then
|
|
||||||
-- restore cache information
|
|
||||||
SetItemButtonTexture(button, cache[bid]["tex"])
|
|
||||||
SetItemButtonCount(button, cache[bid]["count"])
|
|
||||||
button.hasItem = 1
|
|
||||||
end
|
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()
|
UpdateSlots()
|
||||||
QueueFunction(UpdateSlots)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user