--Credits AutoLootFix, Dugi
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("CVAR_UPDATE")
local LootAlertItems = {}
local twipe = table.wipe
local tinsert = table.insert
local inInstance, instanceType
local rarityThreshold = 3
local UpdateAutoLootStatus = function(value)
if tonumber(value) == 1 then
f:RegisterEvent("LOOT_OPENED")
f:RegisterEvent("CHAT_MSG_LOOT")
else
f:UnregisterEvent("LOOT_OPENED")
f:UnregisterEvent("CHAT_MSG_LOOT")
end
end
IsAutoLootKeyDown = function()
-- Possible values: ALT, CTRL, SHIFT, NONE
local key = InterfaceOptionsControlsPanelAutoLootKeyDropDown:GetValue()
if key ~= "NONE" then
if key == "CTRL" then key = "CONTROL" end
local first, rest = key:sub(1, 1), key:sub(2):lower()
return _G[("Is%s%sKeyDown"):format(first, rest)]()
end
end
local function GetItemIdFromLink(link)
return tonumber(link:match(".+|Hitem:([^:]+):.+"))
end
f:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
inInstance, instanceType = IsInInstance()
UpdateAutoLootStatus(GetCVar"autoLootDefault")
elseif event == "CVAR_UPDATE" then
local glStr, value = ...
if glStr == "AUTO_LOOT_DEFAULT_TEXT" then
UpdateAutoLootStatus(value)
end
elseif event == "LOOT_OPENED" then
twipe(LootAlertItems)
local numItems = GetNumLootItems()
for i = numItems, 1, -1 do
local lootLink = GetLootSlotLink(i)
local _, _, _, rarity, locked = GetLootSlotInfo(i)
if lootLink and rarity >= rarityThreshold then
local itemId = GetItemIdFromLink(lootLink)
tinsert(LootAlertItems, itemId)
end
--LootSlot(i)
end
if not IsAutoLootKeyDown() then
f:SetScript("OnUpdate", LootAlert_OnUpdate);
end
elseif (event=="CHAT_MSG_LOOT") then
local message, sender, language, channelString, target, flags, _, channelNumber, channelName, _, _ = ...
LootAlert(message)
end
end)
function LootAlert_OnUpdate(self, elapsed)
if not (inInstance and GetNumGroupMembers() > 0) then
if (ElvLootFrame:IsShown()) then
ElvLootFrame:Hide()
elseif (LootFrame:IsShown()) then
LootFrame:Hide()
end
end
self:SetScript("OnUpdate", nil);
end
local ITEMNAME = {
[LE_ITEM_QUALITY_COMMON] = "Common",
[LE_ITEM_QUALITY_UNCOMMON] = "Uncommon",
[LE_ITEM_QUALITY_EPIC] = "Epic",
[LE_ITEM_QUALITY_RARE] = "Rare",
[LE_ITEM_QUALITY_LEGENDARY] = "Legendary",
[LE_ITEM_QUALITY_HEIRLOOM] = "Heirloom"
}
local LOOT_SELF_REGEX = gsub(LOOT_ITEM_SELF, "%%s", "(.+)") --"You receive item: %s."
local LOOT_PUSHED_REGEX = gsub(LOOT_ITEM_PUSHED_SELF, "%%s", "(.+)") --"You receive loot: %s."
function LootAlert(message)
local itemLink = string.match(message, LOOT_PUSHED_REGEX) or string.match(message, LOOT_SELF_REGEX)
if itemLink then
local itemId = GetItemIdFromLink(itemLink)
local itemName,_,_,_,_, Type, subType = GetItemInfo(itemLink)
if tContains(LootAlertItems, itemId) then
if (instanceType ~= "raid" and GetNumGroupMembers() == 0) or GetLootMethod() == "personalloot" then
LootAlertFrame_ShowAlert(itemLink)
elseif subType == "Mount" or subType == "Companion Pets" or Type == "Recipe" then
LootAlertFrame_ShowAlert(itemLink)
end
end
end
end
function LootAlertFrame_ShowAlert(itemLink, quantity)
local frame;
for i=1, #LOOT_WON_ALERT_FRAMES do
local lootWon = LOOT_WON_ALERT_FRAMES[i];
if ( not lootWon:IsShown() ) then
frame = lootWon;
break;
end
end
if ( not frame ) then
frame = CreateFrame("Button", nil, UIParent, "LootWonAlertFrameTemplate");
table.insert(LOOT_WON_ALERT_FRAMES, frame);
end
LootAlertFrame_SetUp(frame, itemLink, quantity);
AlertFrame_AnimateIn(frame);
AlertFrame_FixAnchors();
end
local LOOTALERTFRAME={
Default = { bgOffsetX=0, bgOffsetY=0, labelOffsetX=7, labelOffsetY=3, labelText=YOU_WON_LABEL, glowAtlas="loottoast-glow"},
Horde = { bgOffsetX=-1, bgOffsetY=-1, labelOffsetX=7, labelOffsetY=3, labelText=YOU_EARNED_LABEL, pvpAtlas="loottoast-bg-horde", glowAtlas="loottoast-glow"},
Alliance = { bgOffsetX=-1, bgOffsetY=-1, labelOffsetX=7, labelOffsetY=3, labelText=YOU_EARNED_LABEL, pvpAtlas="loottoast-bg-alliance", glowAtlas="loottoast-glow"},
}
function LootAlertFrame_SetUp(self, itemLink, quantity)
local itemName, itemHyperLink, itemRarity, _, _, _, _, _, _, itemTexture = GetItemInfo(itemLink);
local windowInfo = LOOTALERTFRAME.Default;
if( showFactionBG ) then
local factionGroup = UnitFactionGroup("player");
windowInfo = LOOTALERTFRAME[factionGroup]
self.PvPBackground:SetAtlas(windowInfo.pvpAtlas, true);
self.PvPBackground:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
self.Background:Hide();
self.BGAtlas:Hide();
self.PvPBackground:Show();
else
if ( windowInfo.bgAtlas ) then
self.Background:Hide();
self.BGAtlas:Show();
self.BGAtlas:SetAtlas(windowInfo.bgAtlas);
self.BGAtlas:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
else
self.Background:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
self.Background:Show();
self.BGAtlas:Hide();
end
self.PvPBackground:Hide();
end
self.glow:SetAtlas(windowInfo.glowAtlas);
self.IconBorder:SetShown(not windowInfo.noIconBorder);
if ( windowInfo.iconUnderBG ) then
self.Icon:SetDrawLayer("BACKGROUND");
else
self.Icon:SetDrawLayer("BORDER");
end
local color = ITEM_QUALITY_COLORS[itemRarity];
local RarityText = ITEMNAME[itemRarity]
self.Label:SetText(format(RarityText, _G["ITEM_QUALITY"..itemRarity.."_DESC"]));
self.Label:SetVertexColor(color.r, color.g, color.b);
self.Label:SetPoint("TOPLEFT", self.Icon, "TOPRIGHT", windowInfo.labelOffsetX, windowInfo.labelOffsetY);
self.Icon:SetTexture(itemTexture);
self.ItemName:SetText(itemName);
self.ItemName:SetVertexColor(color.r, color.g, color.b);
self.IconBorder:SetTexCoord(unpack(LOOT_BORDER_QUALITY_COORDS[itemRarity] or LOOT_BORDER_QUALITY_COORDS[LE_ITEM_QUALITY_UNCOMMON]));
self.RollTypeIcon:Hide();
self.RollValue:Hide();
self.SpecIcon:Hide();
self.SpecRing:Hide();
self.hyperlink = itemHyperLink;
self:SetScript('OnClick', function()
if(IsModifiedClick()) then
ChatEdit_InsertLink(self.hyperlink);
else
--This doesn't work with ElvUI
local bag = SearchBagsForItemLink(self.hyperlink);
if (bag >= 0) then
OpenBag(bag);
end
end
end)
PlaySoundKitID(31578); --UI_EpicLoot_Toast
end