完成焦点等开发

This commit is contained in:
rucky
2026-03-31 18:03:23 +08:00
parent c7dd0f4848
commit 6e18269bfd
34 changed files with 6803 additions and 542 deletions

View File

@@ -682,6 +682,41 @@ function SFrames.FloatingTooltip:FormatLines(tooltip)
end
end
--------------------------------------------------------------------------
-- Armor & Resistances for non-player units
--------------------------------------------------------------------------
if not UnitIsPlayer(unit) and UnitExists(unit) then
local armor = UnitResistance(unit, 0) or 0
if armor > 0 then
tooltip:AddLine(" ")
tooltip:AddLine(string.format("护甲: %d", armor), 0.78, 0.61, 0.43)
end
local resInfo = {
{ 2, "火焰", 1.0, 0.3, 0.3 },
{ 3, "自然", 0.3, 1.0, 0.3 },
{ 4, "冰霜", 0.3, 0.3, 1.0 },
{ 5, "暗影", 0.6, 0.2, 0.9 },
{ 6, "奥术", 1.0, 1.0, 1.0 },
{ 1, "神圣", 1.0, 0.9, 0.5 },
}
local hasRes = false
local resLine = ""
for i = 1, table.getn(resInfo) do
local ri = resInfo[i]
local val = UnitResistance(unit, ri[1]) or 0
if val > 0 then
if hasRes then resLine = resLine .. " " end
resLine = resLine .. ri[2] .. ":" .. val
hasRes = true
end
end
if hasRes then
if armor <= 0 then tooltip:AddLine(" ") end
tooltip:AddLine("抗性: " .. resLine, 0.7, 0.7, 0.75)
end
end
--------------------------------------------------------------------------
-- Target of mouseover (all units)
--------------------------------------------------------------------------
@@ -817,7 +852,7 @@ local function IC_AppendItemLevel(tooltip, link)
end
--------------------------------------------------------------------------------
-- Sell Price Infrastructure
-- Sell Price Infrastructure (GetItemInfo API + runtime cache)
--------------------------------------------------------------------------------
local function IC_GetItemIdFromLink(link)
if not link then return nil end
@@ -835,26 +870,44 @@ end
local function IC_GetSellPrice(itemId)
if not itemId then return nil end
if NanamiSellPriceDB then
local price = NanamiSellPriceDB[itemId]
if price and price > 0 then return price end
end
if ShaguTweaks and ShaguTweaks.SellValueDB then
local price = ShaguTweaks.SellValueDB[itemId]
if price and price > 0 then return price end
end
-- Runtime cache (persisted in SavedVariables)
if SFramesGlobalDB and SFramesGlobalDB.sellPriceCache then
local price = SFramesGlobalDB.sellPriceCache[itemId]
if price and price > 0 then return price end
end
-- Fallback: aux addon
if aux and aux.account_data and aux.account_data.merchant_sell then
local price = aux.account_data.merchant_sell[itemId]
if price and price > 0 then return price end
end
-- Fallback: ShaguTweaks
if ShaguTweaks and ShaguTweaks.SellValueDB then
local price = ShaguTweaks.SellValueDB[itemId]
if price and price > 0 then return price end
end
return nil
end
local function IC_TryGetItemInfoSellPrice(link)
---------------------------------------------------------------------------
-- GetItemInfo API: query sell price and learn/cache it
-- Returns: sellPrice (copper) or nil
---------------------------------------------------------------------------
local function IC_QueryAndLearnPrice(link)
if not link then return nil end
local r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11 = GetItemInfo(link)
if r11 and type(r11) == "number" and r11 > 0 then
return r11
local itemId = IC_GetItemIdFromLink(link)
-- Check cache first
local cached = IC_GetSellPrice(itemId)
if cached then return cached end
-- Query via GetItemInfo (11th return = sellPrice)
local name, _, quality, ilvl, minLvl, itemType, subType, stackCount, equipLoc, texture, sellPrice = GetItemInfo(link)
if name then
DEFAULT_CHAT_FRAME:AddMessage(
"|cff88ccff[Nanami-SellPrice]|r GetItemInfo(" .. (itemId or "?") .. ") = "
.. (name or "nil") .. ", sellPrice=" .. tostring(sellPrice or "nil"))
end
if sellPrice and type(sellPrice) == "number" and sellPrice > 0 then
if itemId then IC_CacheSellPrice(itemId, sellPrice) end
return sellPrice
end
return nil
end
@@ -880,12 +933,7 @@ local function IC_AddSellPrice(tooltip, link, count)
if not link then return end
if tooltip._nanamiSellPriceAdded then return end
if MerchantFrame and MerchantFrame:IsShown() then return end
local itemId = IC_GetItemIdFromLink(link)
local price = IC_GetSellPrice(itemId)
if not price then
price = IC_TryGetItemInfoSellPrice(link)
if price and itemId then IC_CacheSellPrice(itemId, price) end
end
local price = IC_QueryAndLearnPrice(link)
if price and price > 0 then
count = count or 1
if count < 1 then count = 1 end
@@ -954,7 +1002,7 @@ function IC:HookTooltips()
orig_SetTooltipMoney(frame, money, a1, a2, a3)
end
if IC_PendingBagLink and money and money > 0 then
if frame == GameTooltip or frame == SFramesScanTooltip then
if frame == GameTooltip then
local itemId = IC_GetItemIdFromLink(IC_PendingBagLink)
local count = IC_PendingBagCount or 1
if count < 1 then count = 1 end
@@ -966,7 +1014,8 @@ function IC:HookTooltips()
end
---------------------------------------------------------------------------
-- MERCHANT_SHOW: proactively scan all bag items to cache sell prices.
-- MERCHANT_SHOW: proactively scan all bag items to learn sell prices
-- via GetItemInfo API and cache them.
---------------------------------------------------------------------------
local scanFrame = CreateFrame("Frame")
scanFrame:RegisterEvent("MERCHANT_SHOW")
@@ -976,26 +1025,7 @@ function IC:HookTooltips()
for slot = 1, numSlots do
local link = GetContainerItemLink(bag, slot)
if link then
local itemId = IC_GetItemIdFromLink(link)
if itemId and not IC_GetSellPrice(itemId) then
local infoPrice = IC_TryGetItemInfoSellPrice(link)
if infoPrice then
IC_CacheSellPrice(itemId, infoPrice)
elseif SFramesScanTooltip then
local _, cnt = GetContainerItemInfo(bag, slot)
cnt = cnt or 1
IC_PendingBagLink = link
IC_PendingBagCount = cnt
pcall(function()
SFramesScanTooltip:SetOwner(UIParent, "ANCHOR_NONE")
SFramesScanTooltip:ClearLines()
SFramesScanTooltip:SetBagItem(bag, slot)
SFramesScanTooltip:Hide()
end)
IC_PendingBagLink = nil
IC_PendingBagCount = nil
end
end
IC_QueryAndLearnPrice(link)
end
end
end
@@ -1248,11 +1278,7 @@ function IC:HookTooltips()
if itemStr then
ItemRefTooltip._nanamiSellPriceAdded = nil
local itemId = IC_GetItemIdFromLink(itemStr)
local price = IC_GetSellPrice(itemId)
if not price then
price = IC_TryGetItemInfoSellPrice(itemStr)
if price and itemId then IC_CacheSellPrice(itemId, price) end
end
local price = IC_QueryAndLearnPrice(itemStr)
if price and price > 0 and not ItemRefTooltip.hasMoney then
SetTooltipMoney(ItemRefTooltip, price)
ItemRefTooltip:Show()