Skip to content

Commit baafa27

Browse files
committed
Add equipped items
1 parent 8263a2e commit baafa27

File tree

1 file changed

+93
-25
lines changed

1 file changed

+93
-25
lines changed

modules/character.lua

Lines changed: 93 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ local labelRows = {
1313
big = true,
1414
offset = 1.5,
1515
type = 'characterName',
16+
tooltip = true,
17+
customTooltip = function(button, altData, labelRow)
18+
PermoksAccountManager:CustomEquippedItemsTooltip_OnEnter(button, altData, labelRow)
19+
end,
1620
data = function(alt_data)
1721
return PermoksAccountManager:CreateCharacterString(alt_data.name, alt_data.specInfo)
1822
end,
@@ -214,7 +218,7 @@ local function GearScoreGetEnchantInfo(ItemLink, ItemEquipLoc)
214218
for v in string.gmatch(ItemSubString, "[^:]+") do
215219
tinsert(ItemSubStringTable, v)
216220
end
217-
221+
218222
ItemSubString = ItemSubStringTable[2] .. ":" .. ItemSubStringTable[3], ItemSubStringTable[2]
219223
local StringStart, _ = string.find(ItemSubString, ":")
220224
ItemSubString = string.sub(ItemSubString, StringStart + 1)
@@ -228,24 +232,27 @@ end
228232

229233
local function GearScoreGetQuality(ItemScore)
230234
ItemScore = tonumber(ItemScore)
231-
if (not ItemScore) then
232-
return 0, 0, 0, "Trash"
233-
end
235+
if (not ItemScore) then
236+
return 0, 0, 0, "Trash"
237+
end
234238

235239
if (ItemScore > 5999) then
236-
ItemScore = 5999
237-
end
238-
239-
for i = 0,6 do
240-
if ((ItemScore > i * 1000) and (ItemScore <= ((i + 1) * 1000))) then
241-
local Red = gsQuality[( i + 1 ) * 1000].Red["A"] + (((ItemScore - gsQuality[( i + 1 ) * 1000].Red["B"])*gsQuality[( i + 1 ) * 1000].Red["C"])*gsQuality[( i + 1 ) * 1000].Red["D"])
242-
local Blue = gsQuality[( i + 1 ) * 1000].Green["A"] + (((ItemScore - gsQuality[( i + 1 ) * 1000].Green["B"])*gsQuality[( i + 1 ) * 1000].Green["C"])*gsQuality[( i + 1 ) * 1000].Green["D"])
243-
local Green = gsQuality[( i + 1 ) * 1000].Blue["A"] + (((ItemScore - gsQuality[( i + 1 ) * 1000].Blue["B"])*gsQuality[( i + 1 ) * 1000].Blue["C"])*gsQuality[( i + 1 ) * 1000].Blue["D"])
240+
ItemScore = 5999
241+
end
242+
243+
for i = 0, 6 do
244+
if ((ItemScore > i * 1000) and (ItemScore <= ((i + 1) * 1000))) then
245+
local Red = gsQuality[(i + 1) * 1000].Red["A"] +
246+
(((ItemScore - gsQuality[(i + 1) * 1000].Red["B"]) * gsQuality[(i + 1) * 1000].Red["C"]) * gsQuality[(i + 1) * 1000].Red["D"])
247+
local Blue = gsQuality[(i + 1) * 1000].Green["A"] +
248+
(((ItemScore - gsQuality[(i + 1) * 1000].Green["B"]) * gsQuality[(i + 1) * 1000].Green["C"]) * gsQuality[(i + 1) * 1000].Green["D"])
249+
local Green = gsQuality[(i + 1) * 1000].Blue["A"] +
250+
(((ItemScore - gsQuality[(i + 1) * 1000].Blue["B"]) * gsQuality[(i + 1) * 1000].Blue["C"]) * gsQuality[(i + 1) * 1000].Blue["D"])
244251
-- we swap up blue and green because for some reason the coloring of level power works like that
245-
return Red, Blue, Green, gsQuality[( i + 1 ) * 1000].Description
246-
end
247-
end
248-
return 0.1, 0.1, 0.1, "Trash"
252+
return Red, Blue, Green, gsQuality[(i + 1) * 1000].Description
253+
end
254+
end
255+
return 0.1, 0.1, 0.1, "Trash"
249256
end
250257

251258
local function GearScoreGetItemScore(ItemLink)
@@ -254,7 +261,7 @@ local function GearScoreGetItemScore(ItemLink)
254261
local PVPScore = 0
255262
local GearScore = 0
256263

257-
if not (ItemLink) then
264+
if not (ItemLink) then
258265
return 0, 0
259266
end
260267

@@ -281,11 +288,12 @@ local function GearScoreGetItemScore(ItemLink)
281288
if (gsItemTypes[ItemEquipLoc]) then
282289
if (ItemLevel > 120) then
283290
Table = gsFormula["A"]
284-
else
291+
else
285292
Table = gsFormula["B"]
286293
end
287294
if (ItemRarity >= 2) and (ItemRarity <= 4) then
288-
GearScore = floor(((ItemLevel - Table[ItemRarity].A) / Table[ItemRarity].B) * gsItemTypes[ItemEquipLoc].SlotMOD * Scale * QualityScale)
295+
GearScore = floor(((ItemLevel - Table[ItemRarity].A) / Table[ItemRarity].B) *
296+
gsItemTypes[ItemEquipLoc].SlotMOD * Scale * QualityScale)
289297

290298
if (ItemLevel == 187.05) then
291299
ItemLevel = 0
@@ -426,7 +434,7 @@ local function UpdateGeneralData(charInfo)
426434
-- Gear Score and Item Level
427435
local gearScore, ilvl = GearScoreGetScore(UnitName('player'), 'player')
428436
local red, green, blue = GearScoreGetQuality(gearScore)
429-
437+
430438
charInfo.gearScore = gearScore
431439
charInfo.gearScoreRed = red
432440
charInfo.gearScoreGreen = green
@@ -463,12 +471,45 @@ local function UpdateILevel(charInfo)
463471
end
464472
end
465473

474+
local function UpdateEquip(charInfo, ...)
475+
local equipmentSlot, isEmpty = ...
476+
477+
charInfo.equippedItems = charInfo.equippedItems or {}
478+
479+
if isEmpty then
480+
charInfo.equippedItems[equipmentSlot] = nil
481+
else
482+
local itemLink = GetInventoryItemLink("player", equipmentSlot)
483+
if itemLink then
484+
local itemID = GetInventoryItemID("player", equipmentSlot)
485+
local itemName, _, itemQuality, _, _, _, _, _, itemEquipLoc = C_Item.GetItemInfo(itemLink)
486+
487+
charInfo.equippedItems[equipmentSlot] = {
488+
itemTexture = GetInventoryItemTexture("player", equipmentSlot),
489+
itemLevel = C_Item.GetDetailedItemLevelInfo(itemLink),
490+
itemName = itemName,
491+
itemQuality = itemQuality,
492+
itemID = itemID,
493+
itemLink = itemLink,
494+
itemSlot = _G[itemEquipLoc],
495+
}
496+
else
497+
charInfo.equippedItems[equipmentSlot] = nil
498+
end
499+
end
500+
end
501+
502+
local function UpdateCharacterEquip(charInfo)
503+
for equipmentSlot = 1, 18 do
504+
UpdateEquip(charInfo, equipmentSlot)
505+
end
506+
end
507+
466508
local function UpdateMythicScore(charInfo)
467509
if not PermoksAccountManager.isRetail then return end
468510

469511
C_MythicPlus.RequestMapInfo()
470512
charInfo.mythicScore = C_ChallengeMode.GetOverallDungeonScore()
471-
472513
end
473514

474515
local function UpdateMythicPlusHistory(charInfo)
@@ -481,7 +522,7 @@ local function UpdatePlayerSpecialization(charInfo)
481522
elseif GetTalentTabInfo then
482523
local primaryTalentTree = GetPrimaryTalentTree()
483524
if primaryTalentTree then
484-
charInfo.specInfo = {GetTalentTabInfo(primaryTalentTree)}
525+
charInfo.specInfo = { GetTalentTabInfo(primaryTalentTree) }
485526
end
486527
end
487528
end
@@ -503,6 +544,7 @@ local function Update(charInfo)
503544
UpdateLocation(charInfo)
504545
else
505546
UpdateILevel(charInfo)
547+
UpdateCharacterEquip(charInfo)
506548
UpdatePlayerSpecialization(charInfo)
507549
UpdateMythicScore(charInfo)
508550
UpdateMythicPlusHistory(charInfo)
@@ -593,6 +635,7 @@ local payload = {
593635
events = {
594636
['PLAYER_MONEY'] = UpdateGold,
595637
['PLAYER_AVG_ITEM_LEVEL_UPDATE'] = UpdateILevel,
638+
['PLAYER_EQUIPMENT_CHANGED'] = { UpdateILevel, UpdateEquip },
596639
['PLAYER_SPECIALIZATION_CHANGED'] = UpdatePlayerSpecialization,
597640
['CHALLENGE_MODE_MAPS_UPDATE'] = { UpdateMythicScore, UpdateMythicPlusHistory },
598641
['BAG_UPDATE_DELAYED'] = { UpdateGeneralData, UpdateKeystones },
@@ -643,7 +686,8 @@ function PermoksAccountManager:HighestKeyTooltip_OnEnter(button, alt_data)
643686
local runPerDungeon = {}
644687
for _, info in ipairs(alt_data.mythicPlusHistory) do
645688
runPerDungeon[info.mapChallengeModeID] = runPerDungeon[info.mapChallengeModeID] or {}
646-
runPerDungeon[info.mapChallengeModeID][info.level] = (runPerDungeon[info.mapChallengeModeID][info.level] or 0) + 1
689+
runPerDungeon[info.mapChallengeModeID][info.level] = (runPerDungeon[info.mapChallengeModeID][info.level] or 0) +
690+
1
647691

648692
tinsert(runs, info.level)
649693
end
@@ -654,14 +698,14 @@ function PermoksAccountManager:HighestKeyTooltip_OnEnter(button, alt_data)
654698
if i == 1 or i == 4 or i == 8 then
655699
runs[i] = string.format('|cff00f7ff+%d|r', runs[i])
656700
else
657-
runs[i] = "+"..runs[i]
701+
runs[i] = "+" .. runs[i]
658702
end
659703
end
660704

661705
local tooltip = LibQTip:Acquire(addonName .. 'Tooltip', 2, 'LEFT', 'LEFT')
662706
button.tooltip = tooltip
663707
tooltip:SetBackdropColor(0, 0, 0, 1)
664-
tooltip:AddLine('Vault Keys:',table.concat(runs, ', ', 1, (min(#runs, 8))))
708+
tooltip:AddLine('Vault Keys:', table.concat(runs, ', ', 1, (min(#runs, 8))))
665709
tooltip:AddLine('')
666710
tooltip:AddSeparator(2, 1, 1, 1)
667711

@@ -681,3 +725,27 @@ function PermoksAccountManager:HighestKeyTooltip_OnEnter(button, alt_data)
681725
tooltip:SmartAnchorTo(button)
682726
tooltip:Show()
683727
end
728+
729+
local equipmentSlotOrdered = {1, 2, 3, 15, 5, 4, 19, 9, 10, 6, 7, 8, 11, 12, 13, 14, 16, 17, 18}
730+
731+
function PermoksAccountManager:CustomEquippedItemsTooltip_OnEnter(button, altData, labelRow)
732+
if not altData or not altData.equippedItems then
733+
return
734+
end
735+
736+
local tooltip = LibQTip:Acquire(addonName .. 'Tooltip', 2, 'LEFT', 'LEFT')
737+
button.tooltip = tooltip
738+
tooltip:SetBackdropColor(0, 0, 0, 1)
739+
tooltip:AddHeader('Equipment:')
740+
tooltip:AddSeparator(2, 1, 1, 1)
741+
742+
for _, equipmentSlot in ipairs(equipmentSlotOrdered) do
743+
local item = altData.equippedItems[equipmentSlot]
744+
if item then
745+
tooltip:AddLine(string.format("%s:", item.itemSlot), string.format("|T%d:0|t|c%s[%s]|r [%d]", item.itemTexture, ITEM_QUALITY_COLORS[item.itemQuality].color:GenerateHexColor(), item.itemName, item.itemLevel))
746+
end
747+
end
748+
749+
tooltip:SmartAnchorTo(button)
750+
tooltip:Show()
751+
end

0 commit comments

Comments
 (0)