Optimize Item Colors refresh allocations
This commit is contained in:
+55
-85
@@ -44,6 +44,34 @@ local inspectSlots = {
|
|||||||
"MainHandSlot", "SecondaryHandSlot", "RangedSlot", "TabardSlot",
|
"MainHandSlot", "SecondaryHandSlot", "RangedSlot", "TabardSlot",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- These option/color tables are immutable and reused across refreshes. Item
|
||||||
|
-- frames can update very frequently on 1.12, so avoid creating short-lived
|
||||||
|
-- Lua tables for every visible slot on every event.
|
||||||
|
local emptyOptions = {}
|
||||||
|
local defaultColor = { r = .5, g = .5, b = .46 }
|
||||||
|
local equipmentOptions = {
|
||||||
|
default = { r = .5, g = .5, b = .5 },
|
||||||
|
borderMin = 0,
|
||||||
|
glowMin = 2,
|
||||||
|
}
|
||||||
|
local bagOptions = { borderMin = 0, glowMin = 2 }
|
||||||
|
local bankOptions = { borderMin = 2, glowMin = 2 }
|
||||||
|
local weaponOptions = {
|
||||||
|
default = { r = .2, g = .2, b = .2 },
|
||||||
|
borderMin = 0,
|
||||||
|
glowMin = 2,
|
||||||
|
}
|
||||||
|
local transparentOptions = { borderMin = 2, glowMin = 2, defaultAlpha = 0 }
|
||||||
|
local icon14Options = {
|
||||||
|
borderInset = 2, glowInset = 14, borderMin = 2, glowMin = 2,
|
||||||
|
defaultAlpha = 0,
|
||||||
|
}
|
||||||
|
local icon12Options = {
|
||||||
|
borderInset = 2, glowInset = 12, borderMin = 2, glowMin = 2,
|
||||||
|
defaultAlpha = 0,
|
||||||
|
}
|
||||||
|
local lootOptions = { borderMin = 1, glowMin = 2, defaultAlpha = 0 }
|
||||||
|
|
||||||
local function Quality(itemID)
|
local function Quality(itemID)
|
||||||
if not itemID then return end
|
if not itemID then return end
|
||||||
return API.GetItemQualityByID(itemID)
|
return API.GetItemQualityByID(itemID)
|
||||||
@@ -51,8 +79,8 @@ end
|
|||||||
|
|
||||||
local function IsQuestItem(itemID)
|
local function IsQuestItem(itemID)
|
||||||
if not itemID then return false end
|
if not itemID then return false end
|
||||||
local _, _, _, _, _, itemType = API.GetItemInfo(itemID)
|
local _, _, _, _, _, classID = API.GetItemInfoInstant(itemID)
|
||||||
return itemType == "Quest"
|
return classID == 12
|
||||||
end
|
end
|
||||||
|
|
||||||
local function NormalizeInsets(inset)
|
local function NormalizeInsets(inset)
|
||||||
@@ -84,9 +112,9 @@ end
|
|||||||
|
|
||||||
local function SetVisualColor(button, itemID, opts)
|
local function SetVisualColor(button, itemID, opts)
|
||||||
if not button then return end
|
if not button then return end
|
||||||
opts = opts or {}
|
opts = opts or emptyOptions
|
||||||
|
|
||||||
local default = opts.default or { r = .5, g = .5, b = .46 }
|
local default = opts.default or defaultColor
|
||||||
local quality = Quality(itemID)
|
local quality = Quality(itemID)
|
||||||
local quest = opts.quest ~= false and IsQuestItem(itemID)
|
local quest = opts.quest ~= false and IsQuestItem(itemID)
|
||||||
local r, g, b
|
local r, g, b
|
||||||
@@ -157,11 +185,7 @@ function Engine:Install()
|
|||||||
for slotID, slotName in pairs(paperdollSlots) do
|
for slotID, slotName in pairs(paperdollSlots) do
|
||||||
local button = _G["Character" .. slotName]
|
local button = _G["Character" .. slotName]
|
||||||
if button then
|
if button then
|
||||||
SetVisualColor(button, API.GetInventoryItemID("player", slotID), {
|
SetVisualColor(button, API.GetInventoryItemID("player", slotID), equipmentOptions)
|
||||||
default = { r = .5, g = .5, b = .5 },
|
|
||||||
borderMin = 0,
|
|
||||||
glowMin = 2,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -170,11 +194,7 @@ function Engine:Install()
|
|||||||
for slotID, slotName in pairs(inspectSlots) do
|
for slotID, slotName in pairs(inspectSlots) do
|
||||||
local button = _G["Inspect" .. slotName]
|
local button = _G["Inspect" .. slotName]
|
||||||
if button then
|
if button then
|
||||||
SetVisualColor(button, API.GetInventoryItemID("target", slotID), {
|
SetVisualColor(button, API.GetInventoryItemID("target", slotID), equipmentOptions)
|
||||||
default = { r = .5, g = .5, b = .5 },
|
|
||||||
borderMin = 0,
|
|
||||||
glowMin = 2,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -190,10 +210,7 @@ function Engine:Install()
|
|||||||
for slot = 1, MAX_CONTAINER_ITEMS do
|
for slot = 1, MAX_CONTAINER_ITEMS do
|
||||||
local button = _G[name .. "Item" .. slot]
|
local button = _G[name .. "Item" .. slot]
|
||||||
if button and button:IsShown() then
|
if button and button:IsShown() then
|
||||||
SetVisualColor(button, API.GetContainerItemID(id, button:GetID()), {
|
SetVisualColor(button, API.GetContainerItemID(id, button:GetID()), bagOptions)
|
||||||
borderMin = 0,
|
|
||||||
glowMin = 2,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -204,10 +221,7 @@ function Engine:Install()
|
|||||||
local button = _G["CharacterBag" .. bag .. "Slot"]
|
local button = _G["CharacterBag" .. bag .. "Slot"]
|
||||||
if button then
|
if button then
|
||||||
local inventorySlot = bag + 20
|
local inventorySlot = bag + 20
|
||||||
SetVisualColor(button, API.GetInventoryItemID("player", inventorySlot), {
|
SetVisualColor(button, API.GetInventoryItemID("player", inventorySlot), bagOptions)
|
||||||
borderMin = 0,
|
|
||||||
glowMin = 2,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -216,10 +230,7 @@ function Engine:Install()
|
|||||||
for slot = 1, 28 do
|
for slot = 1, 28 do
|
||||||
local button = _G["BankFrameItem" .. slot]
|
local button = _G["BankFrameItem" .. slot]
|
||||||
if button then
|
if button then
|
||||||
SetVisualColor(button, API.GetContainerItemID(-1, slot), {
|
SetVisualColor(button, API.GetContainerItemID(-1, slot), bankOptions)
|
||||||
borderMin = 2,
|
|
||||||
glowMin = 2,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -227,14 +238,8 @@ function Engine:Install()
|
|||||||
local function RefreshWeapons()
|
local function RefreshWeapons()
|
||||||
local mainID = API.GetInventoryItemID("player", TempEnchant1:GetID())
|
local mainID = API.GetInventoryItemID("player", TempEnchant1:GetID())
|
||||||
local offID = API.GetInventoryItemID("player", TempEnchant2:GetID())
|
local offID = API.GetInventoryItemID("player", TempEnchant2:GetID())
|
||||||
SetVisualColor(TempEnchant1, mainID, {
|
SetVisualColor(TempEnchant1, mainID, weaponOptions)
|
||||||
default = { r = .2, g = .2, b = .2 },
|
SetVisualColor(TempEnchant2, offID, weaponOptions)
|
||||||
borderMin = 0, glowMin = 2,
|
|
||||||
})
|
|
||||||
SetVisualColor(TempEnchant2, offID, {
|
|
||||||
default = { r = .2, g = .2, b = .2 },
|
|
||||||
borderMin = 0, glowMin = 2,
|
|
||||||
})
|
|
||||||
if TempEnchant1Border then TempEnchant1Border:SetAlpha(0) end
|
if TempEnchant1Border then TempEnchant1Border:SetAlpha(0) end
|
||||||
if TempEnchant2Border then TempEnchant2Border:SetAlpha(0) end
|
if TempEnchant2Border then TempEnchant2Border:SetAlpha(0) end
|
||||||
end
|
end
|
||||||
@@ -253,7 +258,7 @@ function Engine:Install()
|
|||||||
local index = startIndex + i - 1
|
local index = startIndex + i - 1
|
||||||
local itemID
|
local itemID
|
||||||
if index <= GetMerchantNumItems() then itemID = API.GetMerchantItemID(index) end
|
if index <= GetMerchantNumItems() then itemID = API.GetMerchantItemID(index) end
|
||||||
SetVisualColor(button, itemID, { borderMin = 2, glowMin = 2, defaultAlpha = 0 })
|
SetVisualColor(button, itemID, transparentOptions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -261,16 +266,14 @@ function Engine:Install()
|
|||||||
if buybackButton then
|
if buybackButton then
|
||||||
local count = GetNumBuybackItems()
|
local count = GetNumBuybackItems()
|
||||||
local itemID = count > 0 and API.GetBuybackItemID(count) or nil
|
local itemID = count > 0 and API.GetBuybackItemID(count) or nil
|
||||||
SetVisualColor(buybackButton, itemID, { borderMin = 2, glowMin = 2, defaultAlpha = 0 })
|
SetVisualColor(buybackButton, itemID, transparentOptions)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local perPage = MERCHANT_ITEMS_PER_PAGE or 10
|
local perPage = MERCHANT_ITEMS_PER_PAGE or 10
|
||||||
for i = 1, perPage do
|
for i = 1, perPage do
|
||||||
local button = _G["MerchantItem" .. i .. "ItemButton"]
|
local button = _G["MerchantItem" .. i .. "ItemButton"]
|
||||||
if button then
|
if button then
|
||||||
SetVisualColor(button, API.GetBuybackItemID(i), {
|
SetVisualColor(button, API.GetBuybackItemID(i), transparentOptions)
|
||||||
borderMin = 2, glowMin = 2, defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -290,19 +293,13 @@ function Engine:Install()
|
|||||||
local detail = _G["QuestDetailItem" .. i]
|
local detail = _G["QuestDetailItem" .. i]
|
||||||
local detailIcon = _G["QuestDetailItem" .. i .. "IconTexture"]
|
local detailIcon = _G["QuestDetailItem" .. i .. "IconTexture"]
|
||||||
if detail and detailIcon then
|
if detail and detailIcon then
|
||||||
ApplyIconButton(detail, detailIcon, itemID, {
|
ApplyIconButton(detail, detailIcon, itemID, icon14Options)
|
||||||
borderInset = 2, glowInset = 14, borderMin = 2, glowMin = 2,
|
|
||||||
defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local reward = _G["QuestRewardItem" .. i]
|
local reward = _G["QuestRewardItem" .. i]
|
||||||
local rewardIcon = _G["QuestRewardItem" .. i .. "IconTexture"]
|
local rewardIcon = _G["QuestRewardItem" .. i .. "IconTexture"]
|
||||||
if reward and rewardIcon then
|
if reward and rewardIcon then
|
||||||
ApplyIconButton(reward, rewardIcon, itemID, {
|
ApplyIconButton(reward, rewardIcon, itemID, icon14Options)
|
||||||
borderInset = 2, glowInset = 14, borderMin = 2, glowMin = 2,
|
|
||||||
defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -315,10 +312,7 @@ function Engine:Install()
|
|||||||
local button = _G["QuestLogItem" .. i]
|
local button = _G["QuestLogItem" .. i]
|
||||||
local icon = _G["QuestLogItem" .. i .. "IconTexture"]
|
local icon = _G["QuestLogItem" .. i .. "IconTexture"]
|
||||||
if button and icon then
|
if button and icon then
|
||||||
ApplyIconButton(button, icon, itemID, {
|
ApplyIconButton(button, icon, itemID, icon14Options)
|
||||||
borderInset = 2, glowInset = 14, borderMin = 2, glowMin = 2,
|
|
||||||
defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -342,13 +336,7 @@ function Engine:Install()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if button and icon then
|
if button and icon then
|
||||||
ApplyIconButton(button, icon, itemID, {
|
ApplyIconButton(button, icon, itemID, icon12Options)
|
||||||
borderInset = 2,
|
|
||||||
glowInset = 12,
|
|
||||||
borderMin = 2,
|
|
||||||
glowMin = 2,
|
|
||||||
defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -358,9 +346,7 @@ function Engine:Install()
|
|||||||
if openButton then
|
if openButton then
|
||||||
local mailID = InboxFrame and InboxFrame.openMailID
|
local mailID = InboxFrame and InboxFrame.openMailID
|
||||||
local itemID = mailID and mailID > 0 and API.GetInboxItemID(mailID) or nil
|
local itemID = mailID and mailID > 0 and API.GetInboxItemID(mailID) or nil
|
||||||
SetVisualColor(openButton, itemID, {
|
SetVisualColor(openButton, itemID, transparentOptions)
|
||||||
borderMin = 2, glowMin = 2, defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -369,14 +355,10 @@ function Engine:Install()
|
|||||||
local player = _G["TradePlayerItem" .. i .. "ItemButton"]
|
local player = _G["TradePlayerItem" .. i .. "ItemButton"]
|
||||||
local target = _G["TradeRecipientItem" .. i .. "ItemButton"]
|
local target = _G["TradeRecipientItem" .. i .. "ItemButton"]
|
||||||
if player then
|
if player then
|
||||||
SetVisualColor(player, API.GetTradePlayerItemID(i), {
|
SetVisualColor(player, API.GetTradePlayerItemID(i), transparentOptions)
|
||||||
borderMin = 2, glowMin = 2, defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
if target then
|
if target then
|
||||||
SetVisualColor(target, API.GetTradeTargetItemID(i), {
|
SetVisualColor(target, API.GetTradeTargetItemID(i), transparentOptions)
|
||||||
borderMin = 2, glowMin = 2, defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -388,9 +370,7 @@ function Engine:Install()
|
|||||||
|
|
||||||
local output = _G.TradeSkillSkillIcon
|
local output = _G.TradeSkillSkillIcon
|
||||||
if output then
|
if output then
|
||||||
SetVisualColor(output, API.GetTradeSkillItemID(id), {
|
SetVisualColor(output, API.GetTradeSkillItemID(id), transparentOptions)
|
||||||
borderMin = 2, glowMin = 2, defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local num = GetTradeSkillNumReagents(id) or 0
|
local num = GetTradeSkillNumReagents(id) or 0
|
||||||
@@ -398,10 +378,7 @@ function Engine:Install()
|
|||||||
local button = _G["TradeSkillReagent" .. i]
|
local button = _G["TradeSkillReagent" .. i]
|
||||||
local icon = _G["TradeSkillReagent" .. i .. "IconTexture"]
|
local icon = _G["TradeSkillReagent" .. i .. "IconTexture"]
|
||||||
if button and icon then
|
if button and icon then
|
||||||
ApplyIconButton(button, icon, API.GetTradeSkillReagentItemID(id, i), {
|
ApplyIconButton(button, icon, API.GetTradeSkillReagentItemID(id, i), icon12Options)
|
||||||
borderInset = 2, glowInset = 12, borderMin = 2, glowMin = 2,
|
|
||||||
defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -416,9 +393,7 @@ function Engine:Install()
|
|||||||
local name = GetCraftInfo(id)
|
local name = GetCraftInfo(id)
|
||||||
local link = name and ShaguTweaks.GetItemLinkByName and ShaguTweaks.GetItemLinkByName(name)
|
local link = name and ShaguTweaks.GetItemLinkByName and ShaguTweaks.GetItemLinkByName(name)
|
||||||
local itemID = link and API.GetItemIDFromLink(link)
|
local itemID = link and API.GetItemIDFromLink(link)
|
||||||
SetVisualColor(output, itemID, {
|
SetVisualColor(output, itemID, transparentOptions)
|
||||||
borderMin = 2, glowMin = 2, defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local num = GetCraftNumReagents(id) or 0
|
local num = GetCraftNumReagents(id) or 0
|
||||||
@@ -426,10 +401,7 @@ function Engine:Install()
|
|||||||
local button = _G["CraftReagent" .. i]
|
local button = _G["CraftReagent" .. i]
|
||||||
local icon = _G["CraftReagent" .. i .. "IconTexture"]
|
local icon = _G["CraftReagent" .. i .. "IconTexture"]
|
||||||
if button and icon then
|
if button and icon then
|
||||||
ApplyIconButton(button, icon, API.GetCraftReagentItemID(id, i), {
|
ApplyIconButton(button, icon, API.GetCraftReagentItemID(id, i), icon12Options)
|
||||||
borderInset = 2, glowInset = 12, borderMin = 2, glowMin = 2,
|
|
||||||
defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -446,9 +418,7 @@ function Engine:Install()
|
|||||||
local slot = startSlot + buttonIndex - 1
|
local slot = startSlot + buttonIndex - 1
|
||||||
local itemID = slot <= numLoot and API.GetLootSlotItemID(slot) or nil
|
local itemID = slot <= numLoot and API.GetLootSlotItemID(slot) or nil
|
||||||
if button then
|
if button then
|
||||||
SetVisualColor(button, itemID, {
|
SetVisualColor(button, itemID, lootOptions)
|
||||||
borderMin = 1, glowMin = 2, defaultAlpha = 0,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -547,7 +517,7 @@ function Engine:Install()
|
|||||||
if event == "LOOT_CLOSED" then
|
if event == "LOOT_CLOSED" then
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
local button = _G["LootButton" .. i]
|
local button = _G["LootButton" .. i]
|
||||||
if button then SetVisualColor(button, nil, { borderMin = 1, glowMin = 2, defaultAlpha = 0 }) end
|
if button then SetVisualColor(button, nil, lootOptions) end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ShaguTweaks.QueueFunction(RefreshLoot)
|
ShaguTweaks.QueueFunction(RefreshLoot)
|
||||||
|
|||||||
Reference in New Issue
Block a user