Compare commits

..

2 Commits

2 changed files with 276 additions and 109 deletions

View File

@@ -16,6 +16,50 @@ local DEFAULT_AMIBIS_CHAR_DB = {
overrideSpec = nil,
}
local TOP_UPGRADES_COUNT = 3
local UPGRADE_STAT_KEYS = {
["PRIEST"] = {
["Discipline"] = { "healing", "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Holy"] = { "healing", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Shadow"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
},
["DRUID"] = {
["Balance"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Restoration"] = { "healing", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
},
["PALADIN"] = {
["Holy"] = { "healing", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
},
["SHAMAN"] = {
["Elemental"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Restoration"] = { "healing", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
},
["MAGE"] = {
["Arcane"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Fire"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Frost"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
},
["WARLOCK"] = {
["Affliction"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Demonology"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
["Destruction"] = { "spellDamage", "spellPower", "intellect", "spirit", "mp5", "haste", "crit" },
},
}
local DEFAULT_UPGRADE_STAT_KEYS = { "spellPower", "intellect", "spirit", "mp5", "haste", "crit" }
local function GetUpgradeStatKeys(class, spec)
if class and UPGRADE_STAT_KEYS[class] and UPGRADE_STAT_KEYS[class][spec] then
return UPGRADE_STAT_KEYS[class][spec]
end
return DEFAULT_UPGRADE_STAT_KEYS
end
function Amibis:GetStatKeysForSpec(class, spec)
return GetUpgradeStatKeys(class, spec)
end
local function InitializeDB()
if not AmibisDB then
AmibisDB = CopyTable(DEFAULT_AMIBIS_DB)
@@ -139,6 +183,11 @@ local STAT_MAP = {
["ITEM_MOD_HEALING_SHORT"] = "healing",
}
local MAX_AGGREGATE_STATS = {
healing = true,
spellDamage = true,
}
function Amibis:ScanItemStats(itemID)
if not itemID then return nil end
@@ -152,8 +201,16 @@ function Amibis:ScanItemStats(itemID)
local result = {}
for wowKey, ourKey in pairs(STAT_MAP) do
if stats[wowKey] then
result[ourKey] = (result[ourKey] or 0) + stats[wowKey]
local value = stats[wowKey]
if value then
if MAX_AGGREGATE_STATS[ourKey] then
local current = result[ourKey]
if not current or value > current then
result[ourKey] = value
end
else
result[ourKey] = (result[ourKey] or 0) + value
end
end
end
@@ -202,7 +259,7 @@ function Amibis:CompareGear()
slots = {},
bisCount = 0,
totalSlots = 0,
biggestUpgrade = nil,
topUpgrades = {},
}
end
@@ -210,7 +267,7 @@ function Amibis:CompareGear()
local slots = {}
local bisCount = 0
local totalSlots = 0
local biggestUpgrade = nil
local allUpgrades = {}
for slotName, bisItem in pairs(bisList) do
totalSlots = totalSlots + 1
@@ -222,47 +279,48 @@ function Amibis:CompareGear()
bisCount = bisCount + 1
end
local itemLevelDiff = nil
if equippedItem and not isBIS then
local equippedILvl = GetItemInfo(equippedItem.itemID) and select(4, GetItemInfo(equippedItem.itemID))
local bisILvl = GetItemInfo(bisItem.itemID) and select(4, GetItemInfo(bisItem.itemID))
if equippedILvl and bisILvl then
itemLevelDiff = bisILvl - equippedILvl
end
end
if not isBIS and equippedItem then
if not biggestUpgrade or (itemLevelDiff and biggestUpgrade.itemLevelDiff and itemLevelDiff > biggestUpgrade.itemLevelDiff) then
biggestUpgrade = {
slot = slotName,
equipped = equippedItem,
bis = bisItem,
itemLevelDiff = itemLevelDiff,
}
elseif not biggestUpgrade then
biggestUpgrade = {
slot = slotName,
equipped = equippedItem,
bis = bisItem,
itemLevelDiff = itemLevelDiff,
}
end
elseif not isBIS and not biggestUpgrade then
biggestUpgrade = {
slot = slotName,
equipped = nil,
bis = bisItem,
itemLevelDiff = nil,
}
end
table.insert(slots, {
slotName = slotName,
equipped = equippedItem,
bis = bisItem,
isBIS = isBIS,
itemLevelDiff = itemLevelDiff,
})
if not isBIS then
local statDiffs = {}
local score = 0
local equippedStats = (equippedItem and self:ScanItemStats(equippedItem.itemID)) or {}
local bisStats = self:ScanItemStats(bisItem.itemID) or {}
local upgradeStatKeys = GetUpgradeStatKeys(class, spec)
for _, statKey in ipairs(upgradeStatKeys) do
local diff = (bisStats[statKey] or 0) - (equippedStats[statKey] or 0)
if diff > 0 then
statDiffs[statKey] = diff
score = score + diff
end
end
table.insert(allUpgrades, {
slot = slotName,
equipped = equippedItem,
bis = bisItem,
statDiffs = statDiffs,
score = score,
})
end
end
table.sort(allUpgrades, function(a, b)
if a.score ~= b.score then
return a.score > b.score
end
return a.slot < b.slot
end)
local topUpgrades = {}
for i = 1, math.min(TOP_UPGRADES_COUNT, #allUpgrades) do
table.insert(topUpgrades, allUpgrades[i])
end
table.sort(slots, function(a, b)
@@ -307,7 +365,7 @@ function Amibis:CompareGear()
slots = slots,
bisCount = bisCount,
totalSlots = totalSlots,
biggestUpgrade = biggestUpgrade,
topUpgrades = topUpgrades,
equippedStats = equippedStats,
bisStats = bisStats,
statsComplete = statsComplete,

View File

@@ -17,7 +17,6 @@ local COLOR_EMPTY = { 0.6, 0.6, 0.6 }
local MainFrame = nil
local TitleText = nil
local SummaryText = nil
local UpgradeText = nil
local ScrollFrame = nil
local SlotRows = {}
local MAX_VISIBLE_ROWS = 17
@@ -26,7 +25,7 @@ local ROW_SPACING = 24
local function CreateMainFrame()
local frame = CreateFrame("Frame", "AmibisMainFrame", UIParent, "BackdropTemplate")
frame:SetSize(480, 680)
frame:SetSize(640, 680)
frame:SetFrameStrata("MEDIUM")
frame:SetFrameLevel(10)
@@ -113,13 +112,7 @@ local function CreateSummaryBar(parent, anchor)
summaryText:SetPoint("LEFT", bar, "LEFT", 8, 0)
summaryText:SetTextColor(0.8, 0.8, 0.8, 1)
local upgradeText = bar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
upgradeText:SetPoint("BOTTOMLEFT", bar, "TOPLEFT", 8, 2)
upgradeText:SetPoint("BOTTOMRIGHT", bar, "TOPRIGHT", -8, 2)
upgradeText:SetJustifyH("LEFT")
upgradeText:SetTextColor(COLOR_UPGRADE[1], COLOR_UPGRADE[2], COLOR_UPGRADE[3], 1)
return bar, summaryText, upgradeText
return bar, summaryText
end
local function CreateColumnHeaders(parent, anchor)
@@ -165,8 +158,8 @@ local function CreateColumnHeaders(parent, anchor)
enchantHeader:SetTextColor(0.7, 0.7, 0.7, 1)
local sourceHeader = header:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
sourceHeader:SetPoint("LEFT", enchantHeader, "RIGHT", 5, 0)
sourceHeader:SetPoint("RIGHT", header, "RIGHT", -8, 0)
sourceHeader:SetWidth(70)
sourceHeader:SetJustifyH("RIGHT")
sourceHeader:SetText("Source")
sourceHeader:SetTextColor(0.7, 0.7, 0.7, 1)
@@ -209,15 +202,14 @@ local function CreateSlotRows(parent, anchor)
row.enchantText:SetJustifyH("LEFT")
row.sourceText = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
row.sourceText:SetPoint("LEFT", row.enchantText, "RIGHT", 5, 0)
row.sourceText:SetPoint("RIGHT", row, "RIGHT", -8, 0)
row.sourceText:SetWidth(70)
row.sourceText:SetJustifyH("RIGHT")
row.sourceText:SetWordWrap(true)
row:SetScript("OnEnter", function(self)
if self.bisLink then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetHyperlink(self.bisLink)
pcall(GameTooltip.SetHyperlink, GameTooltip, self.bisLink)
GameTooltip:Show()
end
end)
@@ -245,22 +237,72 @@ local StatsPanel = nil
local StatsPanelTitle = nil
local StatLabels = {}
local StatValues = {}
local UpgradeLabels = {}
local STAT_DISPLAY = {
{ key = "healing", label = "+Healing" },
{ key = "spellPower", label = "+Spell Power" },
{ key = "intellect", label = "Intellect" },
{ key = "spirit", label = "Spirit" },
{ key = "mp5", label = "MP5" },
{ key = "haste", label = "Haste" },
{ key = "crit", label = "Crit" },
local STAT_LABELS = {
healing = "+Healing",
spellDamage = "+Spell Damage",
spellPower = "+Spell Power",
intellect = "Intellect",
spirit = "Spirit",
mp5 = "MP5",
haste = "Haste",
crit = "Crit",
}
local STAT_DISPLAY_NAME = {
healing = "healing",
spellDamage = "spell damage",
spellPower = "spell power",
intellect = "intellect",
spirit = "spirit",
mp5 = "mp5",
haste = "haste",
crit = "crit",
}
local STATS_COL_W = 60
local STATS_LABEL_W = 80
local STATS_CURRENT_X = STATS_LABEL_W + 16
local STATS_BIS_X = STATS_CURRENT_X + STATS_COL_W
local STATS_DIFF_X = STATS_BIS_X + STATS_COL_W
local currentStatKeys = {}
local function GetStatDisplayName(key)
return STAT_DISPLAY_NAME[key] or key
end
local function FormatUpgradeEntry(idx, upgrade)
local text = string.format("%d. %s: ", idx, upgrade.slot)
if not upgrade.equipped then
return text .. "|cff888888(empty slot)|r"
end
if not next(upgrade.statDiffs) then
return text .. "|cff888888(no stat gain)|r"
end
local sorted = {}
for statKey, diff in pairs(upgrade.statDiffs) do
table.insert(sorted, { key = statKey, diff = diff })
end
table.sort(sorted, function(a, b) return a.diff > b.diff end)
local parts = {}
local maxShow = math.min(2, #sorted)
for i = 1, maxShow do
table.insert(parts, string.format("+%d %s", sorted[i].diff, GetStatDisplayName(sorted[i].key)))
end
return text .. table.concat(parts, ", ")
end
local function CreateStatsPanel(parent, anchor)
local panel = CreateFrame("Frame", nil, parent, "BackdropTemplate")
panel:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -8)
panel:SetPoint("TOPRIGHT", anchor, "BOTTOMRIGHT", 0, -8)
panel:SetHeight(#STAT_DISPLAY * 16 + 24)
panel:SetHeight(24)
panel:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
@@ -277,70 +319,109 @@ local function CreateStatsPanel(parent, anchor)
title:SetTextColor(1, 0.82, 0, 1)
StatsPanelTitle = title
local colW = 60
local labelW = 80
local currentX = labelW + 16
local bisX = currentX + colW
local diffX = bisX + colW
local currentLabel = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
currentLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", currentX, -4)
currentLabel:SetWidth(colW)
currentLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", STATS_CURRENT_X, -4)
currentLabel:SetWidth(STATS_COL_W)
currentLabel:SetJustifyH("CENTER")
currentLabel:SetText("Current")
currentLabel:SetTextColor(0.7, 0.7, 0.7, 1)
local bisLabel = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
bisLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", bisX, -4)
bisLabel:SetWidth(colW)
bisLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", STATS_BIS_X, -4)
bisLabel:SetWidth(STATS_COL_W)
bisLabel:SetJustifyH("CENTER")
bisLabel:SetText("BIS")
bisLabel:SetTextColor(0.7, 0.7, 0.7, 1)
local diffLabel = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
diffLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", diffX, -4)
diffLabel:SetWidth(colW)
diffLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", STATS_DIFF_X, -4)
diffLabel:SetWidth(STATS_COL_W)
diffLabel:SetJustifyH("CENTER")
diffLabel:SetText("Diff")
diffLabel:SetTextColor(0.7, 0.7, 0.7, 1)
for i, stat in ipairs(STAT_DISPLAY) do
local y = -(i - 1) * 16 - 22
local separator = panel:CreateTexture(nil, "ARTWORK")
separator:SetTexture("Interface\\Buttons\\WHITE8x8")
separator:SetVertexColor(0.2, 0.2, 0.2, 1)
separator:SetPoint("TOPLEFT", panel, "TOPLEFT", 290, 4)
separator:SetPoint("BOTTOMLEFT", panel, "BOTTOMLEFT", 290, -4)
separator:SetWidth(1)
local upgradesTitle = panel:CreateFontString(nil, "OVERLAY", "GameFontNormal")
upgradesTitle:SetPoint("TOPLEFT", panel, "TOPLEFT", 300, -4)
upgradesTitle:SetText("Top Upgrades")
upgradesTitle:SetTextColor(1, 0.82, 0, 1)
for i = 1, 3 do
local y = -22 - (i - 1) * 16
local label = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
label:SetPoint("TOPLEFT", panel, "TOPLEFT", 300, y)
label:SetWidth(320)
label:SetJustifyH("LEFT")
label:SetText("")
label:SetTextColor(COLOR_UPGRADE[1], COLOR_UPGRADE[2], COLOR_UPGRADE[3], 1)
UpgradeLabels[i] = label
end
StatsPanel = panel
return panel
end
local function RebuildStatRows(panel, statKeys)
for _, vals in pairs(StatValues) do
vals.label:Hide()
vals.current:Hide()
vals.bis:Hide()
vals.diff:Hide()
end
StatLabels = {}
StatValues = {}
for i, statKey in ipairs(statKeys) do
local y = -22 - (i - 1) * 16
local labelText = STAT_LABELS[statKey] or statKey
local label = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
label:SetPoint("TOPLEFT", panel, "TOPLEFT", 8, y)
label:SetWidth(labelW)
label:SetWidth(STATS_LABEL_W)
label:SetJustifyH("RIGHT")
label:SetText(stat.label)
label:SetText(labelText)
label:SetTextColor(0.6, 0.6, 0.6, 1)
local current = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
current:SetPoint("TOPLEFT", panel, "TOPLEFT", currentX, y)
current:SetWidth(colW)
current:SetPoint("TOPLEFT", panel, "TOPLEFT", STATS_CURRENT_X, y)
current:SetWidth(STATS_COL_W)
current:SetJustifyH("CENTER")
current:SetText("0")
current:SetTextColor(1, 0.5, 0.5, 1)
local bis = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
bis:SetPoint("TOPLEFT", panel, "TOPLEFT", bisX, y)
bis:SetWidth(colW)
bis:SetPoint("TOPLEFT", panel, "TOPLEFT", STATS_BIS_X, y)
bis:SetWidth(STATS_COL_W)
bis:SetJustifyH("CENTER")
bis:SetText("0")
bis:SetTextColor(0, 1, 0, 1)
local diff = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
diff:SetPoint("TOPLEFT", panel, "TOPLEFT", diffX, y)
diff:SetWidth(colW)
diff:SetPoint("TOPLEFT", panel, "TOPLEFT", STATS_DIFF_X, y)
diff:SetWidth(STATS_COL_W)
diff:SetJustifyH("CENTER")
diff:SetText("0")
diff:SetTextColor(1, 1, 1, 1)
StatLabels[stat.key] = label
StatValues[stat.key] = { current = current, bis = bis, diff = diff }
StatLabels[statKey] = label
StatValues[statKey] = { current = current, bis = bis, diff = diff }
end
StatsPanel = panel
return panel
panel:SetHeight(#statKeys * 16 + 24)
end
local function StatKeysEqual(a, b)
if #a ~= #b then return false end
for i, key in ipairs(a) do
if b[i] ~= key then return false end
end
return true
end
local function InitializeUI()
@@ -350,9 +431,8 @@ local function InitializeUI()
local titleBar, title = CreateTitleBar(MainFrame)
TitleText = title
local summaryBar, summary, upgrade = CreateSummaryBar(MainFrame, titleBar)
local summaryBar, summary = CreateSummaryBar(MainFrame, titleBar)
SummaryText = summary
UpgradeText = upgrade
local header = CreateColumnHeaders(MainFrame, summaryBar)
local slotContainer = CreateSlotRows(MainFrame, header)
@@ -398,7 +478,11 @@ function ns.UI.RefreshUI()
if not data.hasBISList then
SummaryText:SetText(string.format("|cffff6666No BIS list available for %s %s in %s|r", data.class, data.spec or "Unknown", data.phase))
UpgradeText:SetText("")
for i = 1, 3 do
if UpgradeLabels[i] then
UpgradeLabels[i]:SetText("")
end
end
for i = 1, MAX_VISIBLE_ROWS do
SlotRows[i].slotText:SetText("")
SlotRows[i].equippedText:SetText("")
@@ -412,17 +496,6 @@ function ns.UI.RefreshUI()
SummaryText:SetText(string.format("BIS: %d/%d slots", data.bisCount, data.totalSlots))
if data.biggestUpgrade then
local bu = data.biggestUpgrade
if bu.equipped then
UpgradeText:SetText(string.format("Biggest upgrade: %s -> %s (%s)", bu.equipped.name, bu.bis.name, bu.bis.source))
else
UpgradeText:SetText(string.format("Empty slot: %s -> %s (%s)", bu.slot, bu.bis.name, bu.bis.source))
end
else
UpgradeText:SetText("|cff00ff00All slots are BIS!|r")
end
for i = 1, MAX_VISIBLE_ROWS do
local row = SlotRows[i]
local slotData = data.slots[i]
@@ -492,14 +565,20 @@ function ns.UI.RefreshUI()
end
if data.equippedStats and data.bisStats then
local statKeys = Amibis:GetStatKeysForSpec(data.class, data.spec)
if not StatKeysEqual(currentStatKeys, statKeys) then
RebuildStatRows(StatsPanel, statKeys)
currentStatKeys = statKeys
end
if not data.statsComplete then
if StatsPanelTitle then
StatsPanelTitle:SetText("Stats Comparison |cff888888(loading...)|r")
end
for _, stat in ipairs(STAT_DISPLAY) do
local vals = StatValues[stat.key]
for _, statKey in ipairs(statKeys) do
local vals = StatValues[statKey]
if vals then
local current = data.equippedStats[stat.key] or 0
local current = data.equippedStats[statKey] or 0
vals.current:SetText(current)
vals.bis:SetText("|cff888888...|r")
vals.diff:SetText("")
@@ -525,11 +604,11 @@ function ns.UI.RefreshUI()
if StatsPanelTitle then
StatsPanelTitle:SetText("Stats Comparison")
end
for _, stat in ipairs(STAT_DISPLAY) do
local vals = StatValues[stat.key]
for _, statKey in ipairs(statKeys) do
local vals = StatValues[statKey]
if vals then
local current = data.equippedStats[stat.key] or 0
local bis = data.bisStats[stat.key] or 0
local current = data.equippedStats[statKey] or 0
local bis = data.bisStats[statKey] or 0
local diff = bis - current
vals.current:SetText(current)
@@ -548,6 +627,36 @@ function ns.UI.RefreshUI()
end
end
end
if not data.statsComplete then
if UpgradeLabels[1] then
UpgradeLabels[1]:SetText("|cff888888Loading...|r")
end
for i = 2, 3 do
if UpgradeLabels[i] then
UpgradeLabels[i]:SetText("")
end
end
elseif data.topUpgrades and #data.topUpgrades > 0 then
for i = 1, 3 do
if UpgradeLabels[i] then
if data.topUpgrades[i] then
UpgradeLabels[i]:SetText(FormatUpgradeEntry(i, data.topUpgrades[i]))
else
UpgradeLabels[i]:SetText("")
end
end
end
else
if UpgradeLabels[1] then
UpgradeLabels[1]:SetText("|cff00ff00All slots are BIS!|r")
end
for i = 2, 3 do
if UpgradeLabels[i] then
UpgradeLabels[i]:SetText("")
end
end
end
end
end