diff --git a/Addon.lua b/Addon.lua index f4ad493..c19a001 100644 --- a/Addon.lua +++ b/Addon.lua @@ -11,6 +11,14 @@ local ns = select(2, ...) local ShowUIPanel = LibStub('LibShowUIPanel-1.0').ShowUIPanel +---@class UI +---@field BaseItem UI.BaseItem +---@field GearItem UI.GearItem +---@field GearFrame UI.GearFrame +---@field GemItem UI.GemItem +---@field EnchantItem UI.EnchantItem +---@field InspectFrame UI.InspectFrame +---@field InspectGearFrame UI.InspectGearFrame ns.UI = {} ns.L = LibStub('AceLocale-3.0'):GetLocale('tdInspect') diff --git a/Core/Inspect.lua b/Core/Inspect.lua index 4d02953..8d07a39 100644 --- a/Core/Inspect.lua +++ b/Core/Inspect.lua @@ -132,6 +132,14 @@ function Inspect:SetUnit(unit, name) end end +function Inspect:GetUnitName() + if self.unit then + return ns.UnitName(self.unit) + else + return Ambiguate(self.unitName, 'none') + end +end + function Inspect:Clear() ClearInspectPlayer() self.unitName = nil @@ -177,6 +185,73 @@ function Inspect:IsItemEquipped(itemId) end end +local function GetSlotItemLevel(slot) + local itemId = Inspect:GetItemLink(slot) + if not itemId then + return 0 + end + + local itemLevel = select(4, GetItemInfo(itemId)) + if itemLevel then + return itemLevel + end +end + +local function GetMainhandItemLevel(slot) + local itemId = Inspect:GetItemLink(slot) + if not itemId then + return 0 + end + local itemLevel, _, _, _, _, itemEquipLoc = select(4, GetItemInfo(itemId)) + if itemEquipLoc == 'INVTYPE_2HWEAPON' then + return itemLevel * 2 + end + return itemLevel +end + +local function GetRangedItemLevel(slot) + if UnitClassBase('player') ~= 'HUNTER' then + return 0, true + end + return GetSlotItemLevel(slot) +end + +local SLOTS = { + [INVSLOT_HEAD] = GetSlotItemLevel, + [INVSLOT_NECK] = GetSlotItemLevel, + [INVSLOT_SHOULDER] = GetSlotItemLevel, + [INVSLOT_CHEST] = GetSlotItemLevel, + [INVSLOT_WAIST] = GetSlotItemLevel, + [INVSLOT_LEGS] = GetSlotItemLevel, + [INVSLOT_FEET] = GetSlotItemLevel, + [INVSLOT_WRIST] = GetSlotItemLevel, + [INVSLOT_HAND] = GetSlotItemLevel, + [INVSLOT_FINGER1] = GetSlotItemLevel, + [INVSLOT_FINGER2] = GetSlotItemLevel, + [INVSLOT_TRINKET1] = GetSlotItemLevel, + [INVSLOT_TRINKET2] = GetSlotItemLevel, + [INVSLOT_BACK] = GetSlotItemLevel, + [INVSLOT_MAINHAND] = GetMainhandItemLevel, + [INVSLOT_OFFHAND] = GetSlotItemLevel, + [INVSLOT_RANGED] = GetRangedItemLevel, +} + +function Inspect:GetItemLevel() + local total, count = 0, 0 + + for slot, f in pairs(SLOTS) do + local itemLevel, ignore = f(slot) + if not itemLevel then + return + end + if not ignore then + count = count + 1 + total = total + itemLevel + end + end + return total / count +end + -- @build>2@ local GEM_COLORS = { [Enum.ItemGemSubclass.Red] = {Enum.ItemGemSubclass.Red}, @@ -226,40 +301,23 @@ end -- @end-build>2@ function Inspect:GetEquippedSetItems(id) - local count = 0 local items = {} - local overrideNames = {} - local slotItems = ns.ItemSets[id].slots - + local count = 0 for slot = 1, 18 do local link = self:GetItemLink(slot) if link then local name, _, _, _, _, _, _, _, equipLoc, _, _, _, _, _, _, setId = GetItemInfo(link) if name and setId and setId == id then - local baseName local itemId = ns.ItemLinkToId(link) - if equipLoc == 'INVTYPE_ROBE' then equipLoc = 'INVTYPE_CHEST' end - - local isBaseItem = slotItems[equipLoc][itemId] - if not isBaseItem then - local baseItemId = next(slotItems[equipLoc]) - baseName = GetItemInfo(baseItemId) - if baseName then - overrideNames[baseName] = name - end - items[name] = (items[name] or 0) + 1 - end - + items[equipLoc] = itemId count = count + 1 - baseName = baseName or name - items[baseName] = (items[baseName] or 0) + 1 end end end - return count, items, overrideNames + return count, items end function Inspect:GetUnitClassFileName() @@ -302,6 +360,17 @@ function Inspect:GetUnitLevel() end end +function Inspect:GetDataSource() + if self.db.proto then + if self.db.proto.tdInspect then + return 'tdInspect' + elseif self.db.proto.TalentEmu then + return 'TalentEmu' + end + end + return 'Blizzard' +end + function Inspect:GetNumTalentGroups() return self.db.numGroups or 0 end @@ -399,11 +468,11 @@ function Inspect:Query(unit, name) if queryEquip or queryTalent or queryGlyph or queryRune then local co = coroutine.create(function() - local me = self:IsCharacterHasProto('tdInspect') - local ala = self:IsCharacterHasProto('TalentEmu') + local unitName = self.unitName + local me = self:IsCharacterHasProto(unitName, 'tdInspect') + local ala = self:IsCharacterHasProto(unitName, 'TalentEmu') - - self:ClearCharacterProto(self.unitName, 'tdInspect') + self:ClearCharacterProto(unitName, 'tdInspect') self:SendCommMessage(PROTO_PREFIX, Serializer:Serialize('Q', queryTalent, queryEquip, PROTO_VERSION, queryGlyph, queryRune), 'WHISPER', self.unitName) @@ -411,11 +480,11 @@ function Inspect:Query(unit, name) sleep(1) end - if self:IsCharacterHasProto('tdInspect') then + if self:IsCharacterHasProto(unitName, 'tdInspect') then return end - self:ClearCharacterProto(self.unitName, 'TalentEmu') + self:ClearCharacterProto(unitName, 'TalentEmu') self:SendCommMessage(ALA_PREFIX, ns.Ala:PackQuery(queryEquip, queryTalent, queryGlyph, queryRune), 'WHISPER', self.unitName) @@ -423,7 +492,7 @@ function Inspect:Query(unit, name) sleep(1) end - if self:IsCharacterHasProto('TalentEmu') then + if self:IsCharacterHasProto(unitName, 'TalentEmu') then return end @@ -510,6 +579,12 @@ end function Inspect:UpdateCharacter(sender, data) local name = ns.GetFullName(sender) + + if self:IsCharacterHasProto(name, 'tdInspect') and self.userCache[name] and self.userCache[name].timestamp and + time() - self.userCache[name].timestamp < 5 then + return + end + local db = self:BuildCharacterDb(name) if data.class then diff --git a/Tooltip/FixItemSet.lua b/Tooltip/FixItemSet.lua index 2f75bc7..9243328 100644 --- a/Tooltip/FixItemSet.lua +++ b/Tooltip/FixItemSet.lua @@ -29,13 +29,14 @@ function ns.FixItemSets(tip, id) return end - local equippedCount, itemNames, overrideNames = ns.Inspect:GetEquippedSetItems(setId) + local equippedCount, equippedSetItems = ns.Inspect:GetEquippedSetItems(setId) local setNameLinePattern = '^(' .. setName .. '.+)(%d+)/(%d+)(.+)$' local setLine local firstBonusLine - local inSetLine = true local bonus = ns.ItemSets[setId].bouns + local slots = ns.ItemSets[setId].slots + local setLineFinished = false for i = 2, tip:NumLines() do local textLeft = tip:GetFontStringLeft(i) @@ -47,26 +48,31 @@ function ns.FixItemSets(tip, id) setLine = i textLeft:SetText(prefix .. equippedCount .. '/' .. maxCount .. suffix) end - elseif inSetLine then + elseif setLine and not setLineFinished then local line = text:trim() + local setSlotIndex = i - setLine + local slotItem = slots[setSlotIndex] - if line == '' then - inSetLine = false + if not slotItem or line == '' then + setLineFinished = true else - local n = itemNames[line] - if n and n > 0 then - local overrideName = overrideNames[line] - if overrideName and line ~= overrideName then - textLeft:SetText(text:sub(1, #text - #line) .. overrideName) - end + local item = equippedSetItems[slotItem.slot] + local hasItem = item + if not item then + item = slotItem.itemId + end - textLeft:SetTextColor(1, 1, 0.6) - itemNames[line] = n > 1 and n - 1 or nil - else - textLeft:SetTextColor(0.5, 0.5, 0.5) + local name = GetItemInfo(item) + if name then + textLeft:SetText(' ' .. name) + if hasItem then + textLeft:SetTextColor(1, 1, 0.6) + else + textLeft:SetTextColor(0.5, 0.5, 0.5) + end end end - else + elseif setLineFinished then local summary, count = MatchBonus(text) if summary then if not firstBonusLine then