PageRenderTime 124ms CodeModel.GetById 60ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 1ms

/Core.lua

http://apheslootbrowser.googlecode.com/
Lua | 1374 lines | 1262 code | 73 blank | 39 comment | 246 complexity | 7ed1ab04370b4e0560c6ef1163959824 MD5 | raw file
   1local BInventory = AphesLootBrowserGetBabble("LibBabble-Inventory-3.0")
   2local BFaction = AphesLootBrowserGetBabble("LibBabble-Faction-3.0")
   3local L = LibStub("AceLocale-3.0"):GetLocale("AphesLootBrowser")
   4
   5local ALB = CreateFrame("Frame", "AphesLootBrowser", UIParent)
   6ALB:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
   7
   8ALB.droptext = {}
   9BINDING_HEADER_HEADERALB = L["AphesLootBrowser"]
  10BINDING_NAME_TOGGLEALB = L["show/hide ALB"]
  11
  12ALB_VERSION = 4.2
  13ALB_REVISION = 20
  14
  15
  16local tooltip = CreateFrame("GameTooltip", "ALB_Tooltip", UIParent, "GameTooltipTemplate")
  17tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
  18
  19
  20local unknownItems = {}
  21local queryall = false
  22
  23local VALORSOURCE = {
  24	"Zandalari: 140/instance (7/week)",
  25	"Heroic: 70/instance (daily)",
  26	"10-man raid: 70/boss",
  27	"25-man raid: 105/boss"
  28}
  29
  30local JUSTICESOURCE = {
  31	"Zandalari: 70/boss",
  32	"heroic: 70/boss",
  33	"normal: 140/instance (daily)",
  34}
  35
  36local TREESOURCE = {
  37	"Molten Front daily Quests",
  38}
  39
  40local GREY = "|cff999999"
  41local RED = "|cffff0000"
  42local WHITE = "|cffFFFFFF"
  43local GREEN = "|cff1eff00"
  44local PURPLE = "|cff9F3FFF"
  45local BLUE = "|cff0070dd"
  46
  47local ORANGE = "|cffFF8400"
  48local INDENT = "|TInterface\\OptionsFrame\\UI-OptionsFrame-NewFeatureIcon:0:0:0:-1|t  "
  49local HARDMODE = "|TInterface\\EncounterJournal\\UI-EJ-HeroicTextIcon:19:19:0:0|t "
  50local ALLIANCE = "|TInterface\\BattlefieldFrame\\Battleground-Alliance:22:22:0:0|t"
  51local HORDE = "|TInterface\\BattlefieldFrame\\Battleground-Horde:22:22:0:0|t"
  52local ALLIANCEICON = "Interface\\BattlefieldFrame\\Battleground-Alliance"
  53local HORDEICON = "Interface\\BattlefieldFrame\\Battleground-Horde"
  54
  55ALB.CLASSICON = {}
  56for i = 1, #CLASS_SORT_ORDER do
  57	ALB.CLASSICON[CLASS_SORT_ORDER[i]] = "|TInterface\\Addons\\AphesLootBrowser\\Icons\\"..CLASS_SORT_ORDER[i]..":22:22:0:0|t"
  58end
  59
  60local StatIcons = {
  61		[format("%s (%s)", _G.ITEM_MOD_SPELL_POWER_SHORT,_G.ITEM_MOD_HIT_RATING_SHORT)] = "|TInterface\\Icons\\Spell_Fire_Fireball02:30:30:0:0|t",
  62		[_G.ITEM_MOD_SPIRIT_SHORT] = "|TInterface\\Icons\\Spell_Holy_DivineSpirit:30:30:0:0|t",
  63		[_G.ITEM_MOD_SPELL_POWER_SHORT] = "|TInterface\\Icons\\Spell_Holy_Heal:30:30:0:0|t",
  64		[_G.DEFENSE] = "|TInterface\\Icons\\Ability_Warrior_DefensiveStance:30:30:0:0|t",
  65		[_G.ITEM_MOD_AGILITY_SHORT] = "|TInterface\\Icons\\Ability_Rogue_Rupture:30:30:0:0|t",
  66		[_G.ITEM_MOD_STRENGTH_SHORT] = "|TInterface\\Icons\\Ability_Warrior_OffensiveStance:30:30:0:0|t",
  67		["?"] = "|TInterface\\Icons\\INV_Misc_QuestionMark:30:30:0:0|t",
  68}
  69
  70local Sounds = {
  71	"Sound\\Character\\Human\\HumanVocalMale\\HumanMaleCheer01.wav",
  72	"Sound\\Character\\Dwarf\\DwarfVocalMale\\DwarfMaleCheer01.wav",
  73	"Sound\\Character\\Gnome\\GnomeVocalMale\\GnomeMaleCheer01.wav",
  74	"Sound\\Character\\NightElf\\NightElfVocalMale\\NightElfMaleCheer02.wav",
  75	"Sound\\Character\\Draenei\\DraeneiMaleCheer01.wav",
  76	"Sound\\Character\\Tauren\\TaurenVocalMale\\TaurenMaleCheer01.wav",
  77	"Sound\\Character\\Scourge\\ScourgeVocalMale\\UndeadMaleCheer02.wav",
  78	"Sound\\Character\\Troll\\TrollVocalMale\\TrollMaleCheer01.wav",
  79	"Sound\\Character\\Orc\\OrcVocalMale\\OrcMaleCheer01.wav",
  80	"Sound\\Character\\BloodElf\\BloodElfMaleCheer01.wav",	
  81	"Sound\\Character\\Human\\HumanVocalFemale\\HumanFemaleCheer01.wav",
  82	"Sound\\Character\\Dwarf\\DwarfVocalFemale\\DwarfFemaleCheer01.wav",
  83	"Sound\\Character\\Gnome\\GnomeVocalFemale\\GnomeFemaleCheer01.wav",
  84	"Sound\\Character\\NightElf\\NightElfVocalFemale\\NightElfFemaleCheer02.wav",
  85	"Sound\\Character\\Draenei\\DraeneiFemaleCheer01.wav",
  86	"Sound\\Character\\Tauren\\TaurenVocalFemale\\TaurenFemaleCheer02.wav",
  87	"Sound\\Character\\Scourge\\ScourgeVocalFemale\\UndeadFemaleCheer01.wav",
  88	"Sound\\Character\\Troll\\TrollVocalFemale\\TrollFemaleCheer01.wav",
  89	"Sound\\Character\\Orc\\OrcVocalFemale\\OrcFemaleCheer01.wav",
  90	"Sound\\Character\\BloodElf\\BloodElfFemaleCheer01.wav",
  91	}
  92
  93ALB_MENUORDER = {
  94	"Raid 25",
  95	"Raid 10",	
  96	"5heroic",
  97	"5normal",
  98	"ALB_Cata_Currency",
  99	"ALB_Cata_Rep",
 100	"ALB_Cata_Raids",
 101	"ALB_Cata_5Mans_hero",
 102	"ALB_Cata_5Mans_normal",
 103	"ALB_WotLK_Raids25",
 104	"ALB_WotLK_Raids10",
 105	"ALB_WotLK_5Mans_hero",
 106	"ALB_WotLK_5Mans_normal",
 107	"ALB_WotLK_Emblems",
 108	"ALB_WotLK_Tokens",
 109	"ALB_BC_5Mans_hero",
 110	"ALB_BC_5Mans_normal",
 111	"ALB_Original_5Mans",
 112	"ALB_WotLK_Crafting",
 113--[[	"ALB_WotLK_Reputation",
 114	"ALB_WotLK_TierSets10",
 115	"ALB_WotLK_TierSets10hero",
 116	"ALB_WotLK_TierSets25",
 117	"ALB_WotLK_TierSets25hero",
 118--]]
 119}
 120
 121
 122local ClassColor = {}
 123for class, color in pairs(RAID_CLASS_COLORS) do
 124	ClassColor[class] = string.format("%s%02x%02x%02x", "|cFF", color.r * 255, color.g * 255, color.b * 255)
 125end
 126
 127function ALB:pri(text)
 128	if text and tostring(text) then 
 129		text = format("%s%s %s", PURPLE, "ALB: |r", tostring(text))
 130		if ChatFrame3 and ChatFrame3:IsVisible() then
 131			ChatFrame3:AddMessage(tostring(text)) 
 132		else
 133			DEFAULT_CHAT_FRAME:AddMessage(tostring(text)) 
 134		end
 135	end
 136end
 137
 138function ALB:GetBossLocation(id)  --rename this function 
 139	local location, source = "", ""
 140	for instance, infos in pairs(ALB_Group) do
 141		for i = 1, #infos.sources do
 142			if infos.sources[i] == id then 
 143				location = infos.name
 144				source = instance
 145			end
 146		end
 147		if location ~= "" then break end
 148	end
 149	return location, source
 150end
 151
 152function ALB:GetItemGroup(id)
 153	local sourcetable = {}
 154	local cost = ALB:GetItemCost(id)
 155	if cost then table.insert(sourcetable, {text = cost}) end
 156	
 157	if id == 395 then
 158		for i = 1, #JUSTICESOURCE do
 159			table.insert(sourcetable, {text = JUSTICESOURCE[i]}) 
 160		end
 161		return sourcetable
 162	elseif id == 396 then
 163		for i = 1, #VALORSOURCE do
 164			table.insert(sourcetable, {text = VALORSOURCE[i]}) 
 165		end
 166		return sourcetable
 167	elseif id == 416 then
 168		for i = 1, #TREESOURCE do
 169			table.insert(sourcetable, {text = TREESOURCE[i]}) 
 170		end
 171		return sourcetable
 172	end
 173	
 174	local item, group, source
 175	for header, groups in pairs(ALB_Menu) do
 176		for g = 1, #groups do
 177			group = groups[g]
 178			local checkhm, checknorm = false, false
 179			for s = 1, #ALB_Group[group].sources do
 180				source = ALB_Group[group].sources[s]
 181				for i = 1, #ALB_Source[source].items do
 182					item = ALB_Source[source].items[i]
 183					if item == id and ALB_Source[source].type == "boss" then
 184						if ALB_Source[source].mode == "hardmode" then
 185							checkhm = true
 186						else
 187							checknorm = true
 188						end
 189					end
 190				end
 191			end
 192			if checkhm then
 193				table.insert(sourcetable, {text = format("%s %s %s", ALB:GetGroupName(group), ALB_Group[group].size, L["heroic"])})
 194			end
 195			if checknorm then
 196				table.insert(sourcetable, {text = format("%s %s", ALB:GetGroupName(group), ALB_Group[group].size)})
 197			end
 198		end		
 199	end
 200	return sourcetable
 201end
 202
 203function ALB:GetItemSource(id, wholetable, short)
 204	if not wholetable then
 205		local source = ALB:GetItemCost(id) or ""
 206		for sourceID, info in pairs(ALB_Source) do
 207			for i = 1, #info.items do
 208				if info.items[i] == id then 
 209					if short then return sourceID end					
 210					if ALB_Source[sourceID].type == "boss" 
 211					or ALB_Source[sourceID].type == "crafting" then
 212						if source ~= "" then 
 213							local size= strmatch(source, "^"..ALB_Source[sourceID].name.." (%d%d)")
 214							if size then					
 215								local hero = strmatch(source, "^"..ALB_Source[sourceID].name.." %d%d "..L["heroic"].."$")
 216								if hero then
 217									if ALB_Source[sourceID].mode == "heroic" then
 218										source = ALB_Source[sourceID].name .. " 10/25 "..L["heroic"]								
 219									else
 220										source = L["multiple"]; break 
 221									end
 222								else
 223									source = ALB_Source[sourceID].name .. " 10/25"
 224								end
 225							else	
 226								source = L["multiple"]; break 
 227							end
 228						else
 229							source = ALB_Source[sourceID].name .. " " .. ALB:BossTypeToText(ALB_Source[sourceID])
 230						end
 231					elseif ALB_Source[sourceID].type == "faction" then
 232						if source ~= "" then source = L["multiple"]; break end
 233						source = format("%s: %s", ALB_Source[sourceID].name, ALB_Source[sourceID].rep)
 234					elseif ALB_Source[sourceID].type == "currency" then
 235						if source ~= "" then break end
 236						source = format("%s: %s", ALB_Source[sourceID].name, ALB_Source[sourceID].info)
 237					elseif ALB_Source[sourceID].type == "token" then
 238						if source ~= "" then break end
 239						source = format("%s: %s", ALB_Source[sourceID].name, ALB_Source[sourceID].info)
 240					end
 241				end
 242			end
 243		end
 244		if source == "" then source = "?" end
 245		return source
 246	else
 247		local sourcetable = {}
 248		local cost = ALB:GetItemCost(id)
 249		if cost then table.insert(sourcetable, {text = cost, token=true}) end
 250		local item, group, source
 251		for header, groups in pairs(ALB_Menu) do
 252			for g = 1, #groups do
 253				group = groups[g]
 254				for s = 1, #ALB_Group[group].sources do
 255					source = ALB_Group[group].sources[s]
 256					for i = 1, #ALB_Source[source].items do
 257						item = ALB_Source[source].items[i]
 258						if item == id then 	
 259							if ALB_Source[source].type == "boss" then
 260								table.insert(sourcetable, {
 261									text = "|T".. ALB_Source[source].image .. ":20:40:0:0|t"..ALB_Source[source].name .. " " .. ALB:BossTypeToText(ALB_Source[source]),
 262									ExpandedHeaders = {header, group},
 263									SelectedInstance = source,
 264									})							
 265							elseif ALB_Source[source].type == "faction" then
 266								table.insert(sourcetable, {
 267									text = format("%s: %s", ALB_Source[source].name, ALB_Source[source].rep),
 268									ExpandedHeaders = {header, group},
 269									SelectedInstance = source,
 270									})							
 271							elseif ALB_Source[source].type == "currency" 
 272								or ALB_Source[source].type == "token" then
 273								table.insert(sourcetable, {
 274									text = format("%s: %s", ALB_Source[source].name, ALB_Source[source].info),
 275									ExpandedHeaders = {header, group},
 276									SelectedInstance = source,
 277									})	
 278							end
 279							
 280						end
 281					end
 282				end
 283			end		
 284		end
 285		return sourcetable
 286	end
 287end
 288
 289function ALB:BossTypeToText(tab)  -- rename this function
 290	if tab.type == "boss" then
 291		if tab.size > 5 then
 292			return tab.size .. 
 293				(tab.mode == "heroic" and " "..L["heroic"] or "")
 294		else
 295			return tab.mode == "heroic" and L["heroic"] or "normal"
 296		end
 297	elseif tab.type == "instance" then
 298		return tab.mode == "heroic" and L["heroic"] or ""
 299	elseif tab.type == "currency" then
 300		return tab.cost
 301	elseif tab.type == "crafting" then
 302		return format("(%s)", GetSpellInfo(tab.id))
 303	end	
 304	return " "
 305end
 306
 307function ALB:GetGroupName(GroupId)
 308	if ALB_Group[GroupId].type == "instance" then
 309		if ALB_Group[GroupId].size < 10 then
 310			return format("%s %s", ALB_Group[GroupId].name, ALB:BossTypeToText(ALB_Group[GroupId]))
 311		else
 312			return ALB_Group[GroupId].name or ALB_Group[GroupId].name
 313		end
 314	elseif ALB_Group[GroupId].type == "currency" then
 315		return ALB_Group[GroupId].name
 316	elseif ALB_Group[GroupId].type == "token" then
 317		return ALB_Group[GroupId].name
 318	elseif ALB_Group[GroupId].type == "faction" then
 319		return format("%s%s",
 320			ALB_Group[GroupId].horde and ALB_Group[GroupId].alliance and "  " or 
 321			ALB_Group[GroupId].alliance and ALLIANCE or
 322			ALB_Group[GroupId].horde and HORDE
 323			or "  ",
 324			ALB_Group[GroupId].name)
 325	elseif ALB_Group[GroupId].type == "set" then
 326		return ALB_Group[GroupId].name 
 327	elseif ALB_Group[GroupId].type == "crafting" then
 328		return ALB_Group[GroupId].name
 329	end
 330end
 331
 332function ALB:GetSourceName(source)
 333	if ALB_Source[source].type == "boss" then
 334		return format("%s%s", (ALB_Source[source].mode == "heroic") and HARDMODE or "", ALB_Source[source].name or "WTF")
 335	elseif ALB_Source[source].type == "currency" then
 336		return format("%s %s", ALB_Source[source].name, ALB_Source[source].info or ALB_Source[source].cost)
 337	elseif ALB_Source[source].type == "token" then
 338		return format("%s %s", ALB_Source[source].name, ALB_Source[source].info)
 339	elseif ALB_Source[source].type == "faction" then
 340		return format("%s %s", ALB_Source[source].name, ALB_Source[source].rep)
 341	elseif ALB_Source[source].type == "set" then
 342		return format("T%s %s %s", ALB_Source[source].tier, L[ALB_Source[source].version], ALB_Source[source].ilvl)
 343	elseif ALB_Source[source].type == "crafting" then
 344		return ALB_Source[source].name
 345	end
 346end
 347
 348function ALB:GetItemCost(itemId, detailed)
 349	if not detailed then
 350		
 351		local token1icon,token1name,token2icon,token2name 
 352		if itemId and ALB_Item[itemId] and ALB_Item[itemId].cost then
 353			token1icon = GetItemIcon(ALB_Item[itemId].cost[1]) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[itemId].cost[1])))
 354			
 355			if #ALB_Item[itemId].cost == 4 then
 356				token2icon = GetItemIcon(ALB_Item[itemId].cost[3]) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[itemId].cost[3])))				
 357				return format("%s |T%s:17:17:0:0|t+%s |T%s:17:17:0:0|t", ALB_Item[itemId].cost[2], token1icon, ALB_Item[itemId].cost[4], token2icon)
 358			else
 359				return format("%s |T%s:17:17:0:0|t", ALB_Item[itemId].cost[2], token1icon)
 360			end
 361		end
 362	elseif itemId and ALB_Item[itemId] and ALB_Item[itemId].cost then
 363		if #ALB_Item[itemId].cost == 4 then
 364			return ALB_Item[itemId].cost[2], ALB_Item[itemId].cost[1], ALB_Item[itemId].cost[4], ALB_Item[itemId].cost[3]
 365		else
 366			return ALB_Item[itemId].cost[2], ALB_Item[itemId].cost[1]
 367		end
 368	end
 369	return nil
 370end
 371
 372function ALB:GetCleverItemInfo(itemType, itemSubType, itemEquiploc, itemId)
 373	local itemtype, itemsubtype, itemequiploc, itemid = itemType, itemSubType, itemEquiploc, itemId
 374	local faction = ""
 375	if itemid and ALB_Item[itemid] and ALB_Item[itemid].faction then
 376		faction = ALB_Item[itemid].faction == "ALLIANCE" and ALLIANCE
 377				or ALB_Item[itemid].faction == "HORDE" and HORDE
 378	end
 379	if ALB_Item[itemid].class and ALB.CLASSICON[ALB_Item[itemid].class] then
 380		faction = faction .. ALB.CLASSICON[ALB_Item[itemid].class]
 381	end
 382	if itemtype == BInventory["Armor"] then
 383		if itemsubtype == BInventory["Miscellaneous"] or
 384				itemsubtype == BInventory["Shields"] or
 385				itemsubtype == BInventory["Librams"] or
 386				itemsubtype == BInventory["Idols"] or
 387				itemsubtype == BInventory["Totems"] then
 388			return format("%s %s", faction, _G[itemequiploc] or "")
 389		else
 390			return format("%s %s, %s", faction, _G[itemequiploc], itemsubtype)
 391		end
 392	elseif itemtype == BInventory["Weapon"] then
 393		if itemsubtype == BInventory["Daggers"] or
 394				itemsubtype == BInventory["Fist Weapons"] or
 395				itemsubtype == BInventory["One-Handed Axes"] or
 396				itemsubtype == BInventory["One-Handed Maces"] or
 397				itemsubtype == BInventory["One-Handed Swords"] then
 398			return  format("%s %s %s", faction, itemsubtype, (_G[itemequiploc] == INVTYPE_WEAPON and "" or " (".._G[itemequiploc]..")"))
 399		elseif itemsubtype == BInventory["Miscellaneous"] then
 400			return  format("%s %s (%s)", faction, itemtype, _G[itemequiploc])
 401		else
 402			return  format("%s %s", faction, itemsubtype)
 403		end
 404	elseif itemtype == BInventory["Quest"] then
 405		return  format("%s %s", faction, itemtype)
 406	elseif itemtype == "Money" then
 407		return CURRENCY
 408	else
 409		return  format("%s %s %s", faction, itemtype, itemtype == itemsubtype and "" or " ("..itemsubtype..")")
 410	end
 411	
 412end
 413
 414------------------------------------------------------------------------
 415-----------          Items n icons  stuff                -----------------
 416------------------------------------------------------------------------
 417
 418function ALB:ItemEnter()
 419	if not self:GetParent().id then return end	
 420	GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
 421	if self:GetParent().link then
 422		-- special case in compareframe: items with custom gems/enchants
 423		GameTooltip:SetHyperlink(
 424			"item:"..self:GetParent().id..":"..
 425			self:GetParent().enchant..":"..
 426			self:GetParent().gems[1]..":"..
 427			self:GetParent().gems[2]..":"..
 428			self:GetParent().gems[3]	)
 429		GameTooltip:AddLine("|n|T"..GetItemIcon(21191)..":25:25:0:0|t"..
 430			RED.." AphesLootBrowser:")
 431		GameTooltip:AddLine(INDENT..GREEN..L["shift-click to create a chat link."])
 432	elseif type(self:GetParent().id) == "number" then
 433		-- basically all itemicons 
 434		SetCursor("INSPECT_CURSOR")
 435		if self:GetParent().save then
 436			GameTooltip:SetHyperlink("item:"..self:GetParent().id)
 437			GameTooltip:AddLine("|n|T"..GetItemIcon(21191)..":25:25:0:0|t"..
 438				RED.." AphesLootBrowser:")
 439			GameTooltip:AddLine(INDENT..GREEN..L["right-click for options"])
 440		else
 441			GameTooltip:SetText(RED..L["unsave warning"])
 442			GameTooltip:AddLine("|r"..L["unsave details1"])
 443			GameTooltip:AddLine("|r"..L["unsave details2"])
 444			GameTooltip:AddLine("|n"..GREEN..L["right-click for options"])
 445		end
 446	elseif type(self:GetParent().id) == "string" then
 447		-- icons in compare menu
 448		GameTooltip:SetHyperlink(self:GetParent().id)
 449	end
 450	if IsShiftKeyDown() then GameTooltip_ShowCompareItem() end
 451	GameTooltip:Show()
 452end
 453
 454
 455local stats = {}
 456function ALB:DetailItemTooltip()
 457	if not (self.id or self:GetParent().id) then return end
 458	local ItemId = self.id or self:GetParent().id
 459	local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, _, itemEquipLoc, itemTexture = GetItemInfo(ItemId) 
 460	GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
 461	if ALB_Item[ItemId] and ALB_Item[ItemId].spell then
 462		GameTooltip:SetHyperlink("spell:"..ALB_Item[ItemId].spell)
 463		GameTooltip:AddLine(" ")
 464	end
 465	if itemName then 
 466		GameTooltip:AddLine(itemName, GetItemQualityColor(itemRarity))
 467		wipe(stats)
 468		GetItemStats(itemLink, stats)	
 469		local stattype = 
 470			stats.ITEM_MOD_SPIRIT_SHORT and _G.ITEM_MOD_SPIRIT_SHORT or
 471			stats.ITEM_MOD_INTELLECT_SHORT and stats.ITEM_MOD_HIT_RATING_SHORT and format("%s (%s)", _G.ITEM_MOD_SPELL_POWER_SHORT,_G.ITEM_MOD_HIT_RATING_SHORT) or
 472			stats.ITEM_MOD_INTELLECT_SHORT and _G.ITEM_MOD_SPELL_POWER_SHORT or
 473			(stats.ITEM_MOD_DEFENSE_SKILL_RATING_SHORT or stats.ITEM_MOD_DODGE_RATING_SHORT or stats.ITEM_MOD_PARRY_RATING_SHORT or stats.ITEM_MOD_BLOCK_RATING_SHORT) and _G.DEFENSE or
 474			stats.ITEM_MOD_AGILITY_SHORT and _G.ITEM_MOD_AGILITY_SHORT or
 475			stats.ITEM_MOD_STRENGTH_SHORT and _G.ITEM_MOD_STRENGTH_SHORT or "?"
 476		GameTooltip:AddDoubleLine(format("%s: %s", L["ilvl"], itemLevel), ALB:GetCleverItemInfo(itemType, itemSubType, itemEquipLoc, ItemId))
 477		if stattype then
 478			GameTooltip:AddLine(format("%s  %s%s|r", StatIcons[stattype], GREEN, stattype))
 479		end
 480		
 481		if IsAddOnLoaded("Pawn") then  --PAWN
 482			local scales = PawnGetAllScalesEx() 
 483			local item
 484			local value = 0
 485			if scales then
 486				item = PawnGetItemData(itemLink)
 487				GameTooltip:AddLine("|nPawn:")
 488				for i = 1, #scales do
 489					if scales[i].IsVisible then
 490						value = format("%.1f", select(2, PawnGetSingleValueFromItem(item, scales[i].Name)) or 0)
 491						UpgradeInfo = PawnIsItemAnUpgrade(item)
 492						local ThisUpgrade, WasUpgrade = true, false
 493						if UpgradeInfo then
 494							for _, ThisUpgrade in pairs(UpgradeInfo) do								
 495								if ThisUpgrade.ScaleName == scales[i].Name then
 496									WasUpgrade = true
 497									break
 498								end
 499							end
 500						end
 501						if WasUpgrade then
 502						GameTooltip:AddLine(format("      |cFF%s%s: %s    |TInterface\\AddOns\\Pawn\\Textures\\UpgradeArrow:0|t|r Upgrade",PawnCommon.Scales[scales[i].Name].Color ,scales[i].LocalizedName, value))
 503						else
 504						GameTooltip:AddLine(format("      |cFF%s%s: %s|r",PawnCommon.Scales[scales[i].Name].Color ,scales[i].LocalizedName, value))
 505						end
 506					end
 507				end
 508			end
 509		end
 510		
 511	else
 512		GameTooltip:AddLine(ALB_Item[ItemId] and ALB_Item[ItemId].name or format("item: %s", ItemId), GetItemQualityColor(0))
 513		GameTooltip:AddLine(format("%s: %s", L["ilvl"], ALB_Item[ItemId] and ALB_Item[ItemId].ilvl or "?"))
 514	end
 515	local sources = ALB:GetItemSource(ItemId, true)
 516	if sources and #sources > 1 then
 517		GameTooltip:AddLine(format("|n%s:|n", L["source"]))
 518		for i = 1, 4 do
 519			if sources[i] then GameTooltip:AddLine(format("    - %s",sources[i].text)) end
 520		end
 521		if sources[5] then GameTooltip:AddLine("  ... etc") end
 522	elseif sources[1] then
 523		GameTooltip:AddLine(format("|n%s: %s", L["source"], sources[1].text))
 524	end
 525	local cost1, token1, cost2, token2 = ALB:GetItemCost(ItemId, true)
 526	if cost1 then
 527	
 528		local token1icon = GetItemIcon(token1) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[ItemId].cost[1])))
 529		local token1name = GetItemInfo(token1) or GetCurrencyInfo(ALB_Item[ItemId].cost[1])
 530	
 531		GameTooltip:AddLine("|n|n")
 532		GameTooltip:AddLine(format("|T%s:17:17:0:0|t %s:", token1icon, token1name))
 533		sources = ALB:GetItemGroup(token1)
 534		if sources and #sources > 1 then
 535			for i = 1, 4 do
 536				if sources[i] then GameTooltip:AddLine(format("    - %s",sources[i].text)) end
 537			end
 538			if sources[5] then GameTooltip:AddLine("    ...") end
 539		elseif sources[1] then
 540			GameTooltip:AddLine(format("    %s", sources[1].text))
 541		end
 542		if cost2 and token2 ~= 34518 then
 543		
 544			local token2icon = GetItemIcon(token2) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[ItemId].cost[3])))
 545			local token2name = GetItemInfo(token2) or GetCurrencyInfo(ALB_Item[ItemId].cost[3])
 546		
 547			GameTooltip:AddLine(format("|n|T%s:17:17:0:0|t %s:", token2icon, token2name))
 548			sources = ALB:GetItemGroup(token2)
 549			if sources and #sources > 1 then
 550				for i = 1, 4 do
 551					if sources[i] then GameTooltip:AddLine(format("    - %s",sources[i].text)) end
 552				end
 553				if sources[5] then GameTooltip:AddLine("    ...") end
 554			elseif sources[1] then
 555				GameTooltip:AddLine(format("    %s", sources[1].text))
 556			end
 557		end		
 558	end	
 559	GameTooltip:Show()
 560end
 561
 562
 563local tooltip_timer = 0
 564function ALB:ItemTooltipUpdate(elapsed)
 565	if not (self == GameTooltip:GetOwner()) then return end
 566	tooltip_timer = tooltip_timer + elapsed
 567	if tooltip_timer > 1 then
 568		tooltip_timer = 0
 569		AphesLootBrowser.ItemEnter(self)
 570	end
 571end
 572
 573local function AddToNewWishlist(self, arg1, arg2)
 574	ALB.newWishItem = tonumber(arg1)
 575	ALB:CreateNewWishlist()
 576end
 577
 578local ItemMenu = {}
 579function ALB:ItemContextMenu(level)
 580	ItemMenu = UIDropDownMenu_CreateInfo()
 581	level = level or 1
 582	ItemMenu.arg1 = self.id or self:GetParent().id
 583	if level == 1 then
 584		ItemMenu.hasArrow = false
 585		if self:GetParent().save then
 586		-- if safe:
 587			-- 1 Detail 
 588			if not (ALBDetail and ALBDetail:IsVisible()) then
 589			ItemMenu.text = L["open in detail"]
 590			ItemMenu.func = AphesLootBrowser.LoadToDetailFrame
 591			UIDropDownMenu_AddButton(ItemMenu, level)
 592			end
 593			--2 Compare 
 594			if not (ALBCompare and ALBCompare:IsVisible()) then
 595			ItemMenu.text = L["add to compare"]
 596			ItemMenu.func = AphesLootBrowser.AddToCompare
 597			UIDropDownMenu_AddButton(ItemMenu, level)
 598			end
 599		-- else
 600		else
 601			--query
 602			ItemMenu.text = L["query server"]
 603			ItemMenu.func = AphesLootBrowser.QueryNextItem
 604			UIDropDownMenu_AddButton(ItemMenu, level)			
 605		end
 606		-- 3 Wishlist always
 607		ItemMenu.hasArrow = true
 608		ItemMenu.text = L["add to wishlist"]
 609		ItemMenu.func = nil
 610		UIDropDownMenu_AddButton(ItemMenu, level)	
 611	elseif level == 2 then		
 612		ItemMenu.text = NEW
 613		ItemMenu.func = AddToNewWishlist
 614		UIDropDownMenu_AddButton(ItemMenu, level)
 615		local listname, character
 616		for namecode, info in pairs(ALB_WISHLIST["#ME#"]) do
 617			listname, character = string.match(namecode, "(.+)@(.+)")
 618			if UnitName("player") == character then		
 619				ItemMenu.arg2 = listname
 620				ItemMenu.text = format("%q", listname)
 621				ItemMenu.func = AphesLootBrowser.AddToWishlist
 622				UIDropDownMenu_AddButton(ItemMenu, level)
 623			end
 624		end
 625	end
 626end
 627
 628function ALB:ItemClick(itemid, button, down)
 629	if not itemid then return end
 630	if type(itemid) == "number" then
 631		-- basically all itemicons 
 632		if button == "LeftButton" and (self:GetParent().save or self.save) then
 633			if IsModifiedClick("DRESSUP") then 
 634				DressUpItemLink(itemid)
 635			elseif IsModifiedClick("CHATLINK") then 
 636				ChatEdit_InsertLink(select(2, GetItemInfo(itemid)))
 637			end
 638		elseif button == "RightButton" then	
 639			local frame = self
 640			if not self:GetParent().id then frame = _G[self:GetName() .. "Icon"] end
 641			ToggleDropDownMenu(nil, nil, frame)
 642		end
 643	else
 644		-- special case in compareframe
 645		PickupItem(itemid)
 646	end
 647end
 648
 649function ALB:WishlistClick(itemid)
 650	if not itemid then return end
 651	ToggleDropDownMenu(nil, nil, self)
 652end
 653
 654function ALB.MainFrameLoad()
 655	ALBMainMenuBrowserText:SetText(L["browse"])
 656	ALBMainMenuSearchText:SetText(L["search"])
 657	ALBMainMenuDetailText:SetText(L["detail"])
 658	ALBMainMenuCompareText:SetText(L["compare"])
 659	ALBMainMenuWishlistText:SetText(L["wishlist"])
 660	ALBFrameOptions:SetText(L["options"])
 661	ALBMainMenuBrowserActive:Show()
 662	
 663	ALBMessageFrame:SetTimeVisible(2)
 664	
 665	ALBFrame:RegisterForDrag("LeftButton")
 666	tinsert(UISpecialFrames, "ALBFrame")			
 667end
 668
 669------------------------------------------------------------------------
 670-----------          Roll frame wishlist               -----------------
 671------------------------------------------------------------------------
 672local function OnRoll(f, event, id)
 673	if f.id ~= id then return end
 674	f.id = nil
 675	f:Hide()
 676end
 677
 678local RollWishFrames
 679local function CreateRollWishFrames()
 680	RollWishFrames = {}
 681	local f
 682	for i = 1, 4 do
 683		f = CreateFrame("Frame", "ALB"..i, _G["GroupLootFrame"..i], "RollWishFrame")
 684		f:SetScript("OnEvent", OnRoll)
 685		f:RegisterEvent("CANCEL_LOOT_ROLL")
 686		f.wish = _G["ALB"..i.."Wish"]
 687		f.wishframe = _G["ALB"..i.."Wishframe"]
 688		f.wishlist = _G["ALB"..i.."WishframeText"]
 689		f:Hide()
 690		table.insert(RollWishFrames, f)		
 691	end
 692end
 693
 694local function GetFrame(id)
 695	if not RollWishFrames then CreateRollWishFrames() end
 696	for _,f in ipairs(RollWishFrames) do
 697		if not f.id then return f end
 698	end
 699end
 700
 701function ALB:START_LOOT_ROLL(self, id, timer)
 702	if ALB_SETTINGS.RollFrameWishlists or ALB_SETTINGS.PlaySounds then 
 703		local itemid = tonumber(GetLootRollItemLink(id):match("item:(%d+):"))
 704		if not itemid then return end
 705		local f
 706		if ALB_SETTINGS.RollFrameWishlists then
 707			f = GetFrame(id)
 708			f.id = id
 709			f:Show()			
 710			f.wish:Hide()
 711			f.wishframe:Hide()
 712		end
 713		
 714		local wishlist = nil
 715		if ALB_WISHLIST then
 716			for listname, _ in pairs(ALB_WISHLIST) do
 717				for name, info in pairs(ALB_WISHLIST[listname]) do
 718					if name ~= "#sync#" then
 719						for i = 1, #info.list do
 720							if itemid == info.list[i] then
 721								local listname, character = string.match(name, "(.+)@(.+)")
 722								if UnitExists(character) then
 723									if not wishlist then wishlist = "    |cffff0000Wunschlisten:" end
 724									if character == UnitName("player") then 
 725										if ALB_SETTINGS.RollFrameWishlists then f.wish:Show() end
 726										PlaySoundFile(ALB_SETTINGS.PlaySound and Sounds[ALB_SETTINGS.Sound] or "")
 727									end
 728									character = (ALDclass and ALDclass[character] and ClassColor[ALDclass[character]]..character) or character
 729									wishlist = wishlist .. "|n   "..format("%s|r (%s)", character, listname)
 730								end
 731							end
 732						end
 733					end
 734				end
 735			end
 736		end
 737		if wishlist and ALB_SETTINGS.RollFrameWishlists then
 738			f.wishframe:Show()
 739			f.wishlist:SetText(wishlist)	
 740		end
 741	end
 742end
 743
 744ALB:RegisterEvent("START_LOOT_ROLL")
 745
 746------------------------------------------------------------------------
 747-----------           Tooltip hook                -----------------
 748------------------------------------------------------------------------
 749local function OnTooltipSetItem(frame, ...)
 750	if ALB_SETTINGS.ShowWishlistTooltips then
 751		local name, link = frame:GetItem()
 752		if link then
 753			local header = false
 754			local id = tonumber(link:match("item:(%d+):"))
 755			for _, lists in pairs(ALB_WISHLIST) do
 756				for name, info in pairs(lists) do
 757					if name ~= "#sync#" and info.list and type(info.list) == "table" then
 758						for i = 1, #info.list do
 759							if id == info.list[i] then
 760								if not header then
 761									frame:AddLine("|n|T"..GetItemIcon(21191)..":20:20:0:0|tALB:|n"..RED..L["wishlist"]..":|n")
 762									header = true
 763								end
 764								local listname, character = string.match(name, "(.+)@(.+)")
 765								character = (ALDclass and ALDclass[character] and ClassColor[ALDclass[character]]..character) or character
 766								frame:AddLine(INDENT..format("%s|r (%s)", character, listname))
 767							end
 768						end
 769					end
 770				end
 771			end
 772					
 773			local sources = ALB:GetItemSource(id, true)
 774			if #sources >0 then
 775				if not header then
 776					frame:AddLine("|n|T"..GetItemIcon(21191)..":20:20:0:0|tALB:|n")
 777					header = true
 778				end
 779				if #sources > 1 then
 780					frame:AddLine(format("%s:|n", RED..L["source"].."|r"))
 781					for i = 1, 4 do
 782						if sources[i] then frame:AddLine(format("    - %s",sources[i].text)) end
 783					end
 784					if sources[5] then frame:AddLine("  ... etc") end
 785				elseif sources[1] then
 786					frame:AddLine(format("|n%s: %s", L["source"], sources[1].text))
 787				end
 788			end
 789			
 790			frame:Show()
 791		end
 792	end
 793end
 794
 795local tip_funcs = {
 796		"SetAuctionItem", "SetAuctionSellItem", "SetAuctionCompareItem", "SetBagItem", "SetBuybackItem", "SetCraftItem", "SetGuildBankItem", "SetHyperlink",
 797		"SetHyperlinkCompareItem", "SetInboxItem", "SetInventoryItem", "SetLootItem", "SetLootRollItem", "SetMerchantCompareItem", "SetMerchantItem", "SetQuestItem", 
 798		"SetSendMailItem", "SetTradePlayerItem", "SetTradeSkillItem", "SetTradeTargetItem", "SetMerchantCostItem",}
 799		--"SetQuestLogItem"
 800	
 801for _,frame in pairs { GameTooltip, ShoppingTooltip1, ShoppingTooltip2, ShoppingTooltip3, 
 802				ItemRefTooltip, ItemRefShoppingTooltip1, ItemRefShoppingTooltip2, ItemRefShoppingTooltip3 } do
 803	for _,func in pairs(tip_funcs) do
 804		if frame and frame[func] then
 805			hooksecurefunc(frame, func, OnTooltipSetItem)
 806		end
 807	end
 808end
 809
 810------------------------------------------------------------------------
 811-----------           MAIN MENU  stuff                -----------------
 812------------------------------------------------------------------------
 813function ALB.MainMenuClick(self, button, down)
 814	PlaySound("igCharacterInfoTab")
 815	ALBMainMenuBrowserActive:Hide()
 816	ALBMainMenuSearchActive:Hide()
 817	ALBMainMenuDetailActive:Hide()
 818	ALBMainMenuCompareActive:Hide()
 819	ALBMainMenuWishlistActive:Hide()
 820	_G[self:GetName() .. "Active"]:Show()
 821	local id = self:GetID()
 822	ALBBrowser:Hide()
 823	CloseDropDownMenus()
 824	if ALBOptions then ALBOptions:Hide() end
 825	if ALBSearchFilterPopup and ALBSearchFilterPopup:IsVisible() then ALBSearchFilterPopupDelete:Click() end
 826	if ALBSearch then ALBSearch:Hide() end
 827	if ALBDetail then ALBDetail:Hide() end
 828	if ALBCompare then ALBCompare:Hide() end
 829	if ALBWishlist then ALBWishlist:Hide() end
 830	if id == 1 then
 831		ALBBrowser:Show()
 832	elseif id == 2 then
 833		if ALBSearch then ALBSearch:Show()
 834		else 
 835			CreateFrame("Frame", "ALBSearch", ALBFrame, "ALBSearch") 
 836		end
 837	elseif id == 3 then
 838		if ALBDetail then ALBDetail:Show()
 839		else 
 840			CreateFrame("Frame", "ALBDetail", ALBFrame, "ALBDetail") 
 841		end
 842	elseif id == 4 then
 843		if ALBCompare then ALBCompare:Show()
 844		else 
 845			CreateFrame("Frame", "ALBCompare", ALBFrame, "ALBCompare") 
 846		end
 847	elseif id == 5 then
 848		if ALBWishlist then ALBWishlist:Show()
 849		else 
 850			CreateFrame("Frame", "ALBWishlist", ALBFrame, "ALBWishlist") 
 851		end
 852	end
 853end
 854
 855----------------------
 856--  Minimap Button  --
 857----------------------
 858
 859local function moveButton(self)
 860	local centerX, centerY = Minimap:GetCenter()
 861	local x, y = GetCursorPosition()
 862	x, y = x / self:GetEffectiveScale() - centerX, y / self:GetEffectiveScale() - centerY
 863	centerX, centerY = math.abs(x), math.abs(y)
 864	centerX, centerY = (centerX / math.sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius, (centerY / sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius
 865	centerX = x < 0 and -centerX or centerX
 866	centerY = y < 0 and -centerY or centerY
 867	self:ClearAllPoints()
 868	self:SetPoint("CENTER", centerX, centerY)
 869end
 870
 871function ALB:CreateMinimapButton()
 872	local button = CreateFrame("Button", "ALBMinimapButton", Minimap, "ALB_MinimapButton")
 873	button:SetMovable(true)
 874	button:SetUserPlaced(true)
 875
 876	button:SetScript("OnMouseDown", function(self, button)
 877		if IsShiftKeyDown() or button == "RightButton" then
 878			self:SetScript("OnUpdate", moveButton)
 879		end
 880	end)
 881	button:SetScript("OnMouseUp", function(self)
 882		self:SetScript("OnUpdate", nil)
 883	end)
 884	button:SetScript("OnClick", function(self, button)
 885		if IsShiftKeyDown() or button == "RightButton" then return end
 886		ALB:ToggleWindow()
 887	end)
 888	button:SetScript("OnEnter", function(self)
 889		GameTooltip_SetDefaultAnchor(GameTooltip, self)
 890		GameTooltip:SetText(L["AphesLootBrowser"], 1, 1, 1)
 891		GameTooltip:AddLine(format(L["Version/Revision"], ALB_VERSION, ALB_REVISION))
 892		GameTooltip:AddLine(" ")
 893		GameTooltip:AddLine(GREEN..L["left-click to open/close ALB"])
 894		GameTooltip:AddLine(GREEN..L["right-click to move"])
 895		GameTooltip:Show()
 896	end)
 897	button:SetScript("OnLeave", function(self)
 898		GameTooltip:Hide()
 899	end)
 900	if not ALB_SETTINGS.ShowMinimapIcon then button:Hide() end
 901end
 902
 903function ALB:ToggleMinimapButton()
 904	ALB_SETTINGS.ShowMinimapIcon = not ALB_SETTINGS.ShowMinimapIcon
 905	if ALB_SETTINGS.ShowMinimapIcon then
 906		if ALBMinimapButton then ALBMinimapButton:Show()
 907		else ALB:CreateMinimapButton() end
 908	else
 909		if ALBMinimapButton then ALBMinimapButton:Hide() end
 910	end
 911end
 912
 913function ALB:PositionMinimapButton()
 914	ALB_SETTINGS.MinimapIconRadius = ALBOptionsMinimapRadius:GetValue()
 915	local centerX, centerY = Minimap:GetCenter()
 916	local x, y = ALBMinimapButton:GetCenter()
 917	x, y = x  - centerX, y  - centerY
 918	centerX, centerY = math.abs(x), math.abs(y)
 919	centerX, centerY = (centerX / math.sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius, (centerY / sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius
 920	centerX = x < 0 and -centerX or centerX
 921	centerY = y < 0 and -centerY or centerY
 922	ALBMinimapButton:ClearAllPoints()
 923	ALBMinimapButton:SetPoint("CENTER", centerX, centerY)
 924end
 925
 926------------------------------------------------------------------------
 927-----------           Data-Broker stuff                 -----------------
 928------------------------------------------------------------------------
 929LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("AphesLootBrowser", {
 930	type = "launcher",
 931	label = "ALB",
 932	OnClick = function(_, btn)
 933		ALB:ToggleWindow()	
 934	end,
 935	icon = "Interface\\Icons\\INV_Holiday_Christmas_Present_01",
 936	OnTooltipShow = function(tooltip)
 937		if not tooltip or not tooltip.AddLine then return end
 938		tooltip:SetText(L["AphesLootBrowser"])	
 939		tooltip:AddLine(format(L["Version/Revision"], ALB_VERSION, ALB_REVISION))	
 940		tooltip:AddLine(" ")
 941		tooltip:AddLine(GREEN..L["left-click to open/close ALB"])
 942	end,
 943})
 944
 945------------------------------------------------------------------------
 946-----------         OPTIONS                -----------------
 947------------------------------------------------------------------------
 948local function SoundChanged(self)
 949	for i = 1, 20 do
 950		_G["ALBOptionsRace"..i]:SetChecked(false)
 951		_G["ALBOptionsRace"..i.."Icon"]:SetDesaturated(1)
 952	end
 953	self:SetChecked(1)
 954	_G[self:GetName().."Icon"]:SetDesaturated(false)
 955	ALB_SETTINGS.Sound = self:GetID()
 956	PlaySoundFile(Sounds[self:GetID()])
 957end
 958
 959function ALB:OptionsShow()
 960	if not ALBOptions then
 961		CreateFrame("Frame", "ALBOptions", ALBFrame, "ALBOptions")
 962		ALBOptionsHeader:SetText(L["options"])
 963		ALBOptionsMinimapShowText:SetText(L["show minimap button"])
 964		ALBOptionsMinimapRadiusText:SetText(L["minimap radius"])
 965		ALBOptionsTooltipText:SetText(L["show wishlists in item tooltips"])
 966		ALBOptionsAskRaidSyncText:SetText(L["ask me to import raidmember's wishlists"])
 967		--ALBOptionsQueryAll:SetText(L["query server"])
 968		ALBOptionsVersion:SetText(L["ALB versions"])
 969		ALBOptionsMinimapShow:SetChecked(ALB_SETTINGS.ShowMinimapIcon)
 970		ALBOptionsMinimapRadius:SetValue(ALB_SETTINGS.MinimapIconRadius)
 971		ALBOptionsTooltip:SetChecked(ALB_SETTINGS.ShowWishlistTooltips)
 972		ALBOptionsAskRaidSync:SetChecked(ALB_SETTINGS.AskForRaidsync)
 973		ALBOptionsMinimapRadius:SetScript("OnValueChanged", AphesLootBrowser.PositionMinimapButton)
 974		if IsAddOnLoaded("AphesLootDingen") then
 975			ALBOptionsRollFrameWishlists:Disable()
 976			ALBOptionsRollFrameWishlists:SetChecked(nil)
 977			ALBOptionsRollFrameWishlistsText:SetText(format("%s(%s) %s", GREY, ADDON_DISABLED,L["show wishlists next to lootroll frames"]))
 978		else
 979			ALBOptionsRollFrameWishlists:SetChecked(ALB_SETTINGS.RollFrameWishlists)
 980			ALBOptionsRollFrameWishlistsText:SetText(L["show wishlists next to lootroll frames"])
 981		end
 982		ALBOptionsPlaySoundsText:SetText(L["Play sound when rolling for an item on your wishlist"])
 983		ALBOptionsPlaySounds:SetChecked(ALB_SETTINGS.PlaySounds)
 984		local f 
 985		local line, column = 1, 1
 986		for i = 1, 20 do
 987			f = CreateFrame("CheckButton", "ALBOptionsRace"..i, ALBOptions, "ClassButtonTemplate")
 988			f:SetPoint("TOPLEFT", i < 11 and 55 + (i * 33) or 55 + ((i- 10) * 33), i < 11 and -310 or -343)
 989			_G["ALBOptionsRace"..i.."Icon"]:SetTexCoord((column-1)*0.125, column*0.125, (line-1)*0.25 , line*0.25)
 990			f:SetChecked(i == ALB_SETTINGS.Sound)
 991			_G["ALBOptionsRace"..i.."Icon"]:SetDesaturated(i ~= ALB_SETTINGS.Sound)
 992			f:SetID(i)
 993			f:SetScript("OnClick", SoundChanged)
 994			column = column + 1
 995			if column > 5 then
 996				column = 1
 997				line = line + 1
 998			end
 999		end
1000	end
1001	ALBOptions:Show()
1002end
1003
1004function ALB:OptionsChanged()
1005	ALB_SETTINGS.ShowWishlistTooltips = ALBOptionsTooltip:GetChecked() and true or false
1006	ALB_SETTINGS.AskForRaidsync = ALBOptionsAskRaidSync:GetChecked() and true or false
1007	ALB_SETTINGS.RollFrameWishlists = ALBOptionsRollFrameWishlists:GetChecked() and true or false
1008	ALB_SETTINGS.PlaySounds = ALBOptionsPlaySounds:GetChecked() and true or false
1009	if self:GetName() == "ALBOptionsPlaySounds" and ALB_SETTINGS.PlaySounds then
1010		PlaySoundFile(Sounds[ALB_SETTINGS.Sound])
1011	end
1012end
1013
1014------------------------------------------------------------------------
1015-----------         Query ALLL items                 -----------------
1016------------------------------------------------------------------------
1017function ALB:QueryAllTooltip()
1018	GameTooltip:SetOwner(_G["ALBOptionsQueryAll"], "ANCHOR_RIGHT")
1019	GameTooltip:SetText(L["query server"])
1020	GameTooltip:AddLine("|n"..L["Queries the server for ALL unsave items."])
1021	GameTooltip:AddLine(L["This will take ages! But you can continue playing until..."])
1022	GameTooltip:AddLine(RED..L["You may be disconnected."])
1023	GameTooltip:Show()
1024end
1025
1026function ALB:QueryReallyAll()
1027	if queryall then return end
1028	queryall = true
1029	
1030	wipe(unknownItems)
1031	for id,_ in pairs(ALB_Item) do
1032		GetItemInfo(id)
1033	end			
1034		ALB:pri(L["All available itemlists loaded"])
1035		collectgarbage()
1036		local f = CreateFrame("Frame", "ALBFrame", UIParent, "ALB_Main")
1037		f:SetPoint("CENTER", UIParent)
1038		CreateFrame("Frame", "ALBBrowser", f, "ALBBrowser")
1039		AphesLootBrowser.UpdateInstanceList()	
1040	--end
1041end
1042
1043function ALB:InitQueryReallyAll()
1044	wipe(unknownItems)
1045	for id,_ in pairs(ALB_Item) do
1046		if not GetItemInfo(id) then
1047			table.insert(unknownItems, id)
1048		end
1049	end
1050	ALB:ToggleWindow()
1051	StaticPopupDialogs["ALBQueryAll"].text = format(L["Checking %s unsave items will take approximately %s."], #unknownItems, format("%s%s|r", RED, SecondsToTime(#unknownItems  * 5, false, true)))
1052	StaticPopup_Show ("ALBQueryAll")	
1053end
1054
1055------------------------------------------------------------------------
1056-----------          Synclinks in chat                 -----------------
1057------------------------------------------------------------------------ 
1058local function ChatLink(link, text, button)
1059	if link and type(link) == "string" and string.find(link, "ALB#(.+)") then
1060		local _,_, player = string.find(link, "ALB#(.+)")
1061		ALB:RequestWishlist(player)
1062		return
1063	end
1064	ALB.OriHook(link, text, button)
1065end
1066------------------------------------------------------------------------
1067-----------          Frame create                 -----------------
1068------------------------------------------------------------------------ 
1069
1070local function LoadAddons()
1071	local Addon = {
1072		"ALB_Cata_Rep",
1073		"ALB_Cata_Currency",
1074		}
1075	for i = 1, #Addon do
1076		if not IsAddOnLoaded(Addon[i]) then
1077			LoadAddOn(Addon[i])
1078		end
1079	end
1080	ALB:QueryReallyAll()
1081end
1082
1083function ALB:ToggleWindow()
1084	if _G.ALBEJTimer and _G.ALBEJTimer:IsShown() then return end
1085
1086	wipe(ALB.droptext)
1087	
1088	if ALDDB then
1089		local tab, itemid, day, boss
1090		tab = {}
1091		for i = 1, #ALDDB do
1092			itemid = tonumber(ALDDB[i].loot:match("item:(%d+):"))
1093			boss = ALB:GetItemSource(itemid, false, true)
1094			_,_, day = strfind(ALDDB[i].day, "(%d%d%d%d%d%d)%d%d%d%d")
1095			if boss and ALB_Source[boss] and ALB_Source[boss].type == "boss" then
1096				tab[boss] = tab[boss] or {}
1097				tab[boss].killdate = tab[boss].killdate or {}
1098				tab[boss].kills = tab[boss].kills or 0
1099				if not tab[boss].killdate[day] then
1100					tab[boss].killdate[day] = true
1101					tab[boss].kills = tab[boss].kills + 1
1102				end					
1103				tab[boss].items = tab[boss].items or {}
1104				tab[boss].items[itemid] = tab[boss].items[itemid] and tab[boss].items[itemid] + 1 or 1
1105			end			
1106		end		
1107		
1108		for boss, info in pairs(tab) do
1109			for id, count in pairs(info.items) do
1110				ALB.droptext[id] = count.."/"..info.kills.."  (".. floor(( ( count / info.kills ) * 100 )+0.5) .. "%)"
1111			end
1112		end
1113	end	
1114	if not _G.ALBFrame then
1115		LoadAddons()
1116	else
1117		if _G.ALBFrame:IsVisible() then 
1118			CloseDropDownMenus()
1119			_G.ALBFrame:Hide()
1120		else _G.ALBFrame:Show() end
1121	end
1122end
1123
1124local function Presets()
1125	ALB_SETTINGS = ALB_SETTINGS or {}
1126	ALB_SETTINGS.ShowMinimapIcon = tostring(ALB_SETTINGS.ShowMinimapIcon) == "nil" and true or ALB_SETTINGS.ShowMinimapIcon
1127	ALB_SETTINGS.MinimapIconRadius = ALB_SETTINGS.MinimapIconRadius or 80
1128	ALB_SETTINGS.ShowWishlistTooltips = tostring(ALB_SETTINGS.ShowWishlistTooltips) == "nil" and true or ALB_SETTINGS.ShowWishlistTooltips
1129	ALB_SETTINGS.AskForRaidsync = tostring(ALB_SETTINGS.AskForRaidsync) == "nil" and true or ALB_SETTINGS.AskForRaidsync
1130	ALB_SETTINGS.RollFrameWishlists = tostring(ALB_SETTINGS.RollFrameWishlists) == "nil" and true or ALB_SETTINGS.RollFrameWishlists
1131	ALB_SETTINGS.PlaySounds = ALB_SETTINGS.PlaySounds
1132	ALB_SETTINGS.Sound = tostring(ALB_SETTINGS.Sound) == "nil" and 13 or ALB_SETTINGS.Sound
1133end
1134
1135function ALB:ADDON_LOADED(self, addon)
1136	if addon ~= "AphesLootBrowser" then return end
1137	ALB:UnregisterEvent("ADDON_LOADED")
1138	Presets()
1139	ALB:CreateCompareTable()
1140	if not ALB_WISHLIST then 
1141		ALB_WISHLIST = {} 
1142		ALB_WISHLIST["#ME#"] = {}
1143	end
1144	ALB:CreateMinimapButton()
1145	ALB.OriHook = SetItemRef
1146	SetItemRef = ChatLink
1147--	hooksecurefunc("ChatFrame_OnHyperlinkShow", ChatLink)		
1148end
1149
1150function ALB:EJ_LOOT_DATA_RECIEVED(event, id)
1151	if id then
1152		ALB_Item[id] = {name =  GetItemInfo(id), ilvl = select(4, GetItemInfo(id))}
1153	end
1154end
1155
1156function ALB:Check_EJ_Loot()	
1157	local itemcount = 0	
1158	
1159	for u = 1, 2 do
1160	
1161	local instanceIndex = 1
1162	local isRaid = u == 2
1163	local instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
1164	local runs = 0
1165	
1166		while instanceId do
1167			EJ_SelectInstance(instanceId)			
1168			instanceName, instanceDesc, bild = EJ_GetInstanceInfo()			
1169			if isRaid then
1170				runs = 4				
1171			else
1172				runs = 2
1173			end
1174			
1175			for i = 1, runs do			
1176				local bossIndex = 1
1177				local name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)				
1178				while name and bossIndex < 25 do
1179					EJ_SelectEncounter(bossId)	
1180					EJ_SetDifficulty((i == 2 or i == 4), (i==1 or i==2))	
1181					
1182						for i = 1,EJ_GetNumLoot() do
1183							itemcount = itemcount + 1
1184						end
1185						
1186					bossIndex = bossIndex + 1
1187					name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)
1188				end
1189			
1190			end
1191			
1192			instanceIndex = instanceIndex + 1
1193			instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
1194		end
1195	end
1196	
1197	return itemcount
1198	
1199end
1200
1201function ALB:Gather_EJ_Loot()
1202	
1203	if not ALB_Item then ALB_Item = {} end
1204	if not ALB_Source then ALB_Source = {} end
1205	if not ALB_Menu then ALB_Menu = {} end
1206	if not ALB_Group then ALB_Group = {} end
1207	
1208	local itemcount = 0
1209	local check = true
1210	
1211	for u = 1, 2 do
1212	
1213	local instanceIndex = 1
1214	local isRaid = u == 2
1215	local instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
1216	local runs = 0
1217	
1218		while instanceId do
1219			EJ_SelectInstance(instanceId)
1220			
1221			instanceName, instanceDesc, bild = EJ_GetInstanceInfo()
1222			
1223			if isRaid then
1224			
1225				for num = 1, 2 do		
1226					local player = num == 1 and 10 or 25
1227					ALB_Menu["Raid "..player] = ALB_Menu["Raid "..player] or {}
1228					table.insert(ALB_Menu["Raid "..player], instanceName..player)
1229					
1230					ALB_Group[instanceName..player] = {
1231						name = instanceName,
1232						type = "instance",
1233						size = player,
1234						mode = "hardmode",
1235						instanceId = instanceId,
1236						sources = {},
1237						image = bild,
1238					}				
1239				end
1240				
1241				runs = 4
1242				
1243			else
1244				
1245				for num = 1, 2 do
1246					local mode = num == 1 and "normal" or "heroic"
1247					
1248					ALB_Menu["5"..mode] = ALB_Menu["5"..mode] or {}
1249					table.insert(ALB_Menu["5"..mode], instanceName.."5"..mode)			
1250					
1251					ALB_Group[instanceName.."5"..mode] = {
1252						name = instanceName,
1253						type = "instance",
1254						size = 5,
1255						mode = mode,
1256						instanceId = instanceId,
1257						sources = {},
1258						image = bild,
1259					}
1260				end
1261				runs = 2
1262			end
1263			
1264			for i = 1, runs do
1265			
1266				local bossIndex = 1
1267				local name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)
1268				
1269				while name and bossIndex < 25 do
1270					local size = (runs==2 and "5" or i<3 and "10" or "25")
1271					local version = (i==2 or i==4) and "heroic" or "normal"
1272					table.insert(ALB_Group[instanceName..size..(size == "5" and version or "")].sources, name..size..version)
1273					
1274					local _, _, _, _, bossImage = EJ_GetCreatureInfo(bossIndex, bossId)
1275					bossImage = bossImage or select(5,EJ_GetCreatureInfo(1, bossId, instanceId))
1276					bossImage = bossImage or "Interface\\EncounterJournal\\UI-EJ-BOSS-Default"
1277							
1278					EJ_SelectEncounter(bossId)	
1279					
1280					ALB_Source[name..size..version] = {
1281						name = name,
1282						type = "boss",
1283						bossId = bossId,
1284						instanceID = instanceId,
1285						size = tonumber(size),
1286						mode = (i==2 or i==4) and "heroic" or "normal",
1287						items = {},	
1288						image = bossImage,
1289					}
1290					
1291					--EJ_SetDifficulty(EncounterJournal.isHeroic, EncounterJournal.is10Man)
1292					EJ_SetDifficulty((i == 2 or i == 4), (i==1 or i==2))	
1293					
1294						for i = 1,EJ_GetNumLoot() do
1295							local iname, _, _, _, itemID = EJ_GetLootInfoByIndex(i)
1296							check = true
1297							for x = 1, #ALB_Source[name..size..version].items do
1298								if ALB_Source[name..size..version].items[x] == itemID then check = false end
1299							end
1300							if check then
1301								itemcount = itemcount + 1
1302								table.insert(ALB_Source[name..size..version].items, itemID)
1303								if iname ~= RETRIEVING_ITEM_INFO then
1304									ALB_Item[itemID] = {name = GetItemInfo(itemID), ilvl = select(4, GetItemInfo(itemID))}
1305								else
1306									ALB_Item[itemID] = {name = iname, ilvl = 0}
1307								end
1308							end
1309						end
1310						
1311					bossIndex = bossIndex + 1
1312					name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)
1313				end
1314			
1315			end
1316			
1317			instanceIndex = instanceIndex + 1
1318			instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
1319		end
1320	end
1321	
1322	return itemcount
1323	
1324end
1325
1326
1327function ALB:FirstLoad(self)
1328	local timer = CreateFrame("Frame", "ALBEJTimer", UIParent)
1329	timer:Hide()
1330	timer.time = 0
1331	timer.count = 0
1332	timer:SetScript("OnUpdate", function (this, elapsed)
1333			timer.time = timer.time + elapsed
1334			if timer.time > 1 then			
1335				timer.count = timer.count + 1
1336				timer.time = 0
1337				local count = ALB:Check_EJ_Loot()
1338				if count > 2850 then
1339					ALB:Gather_EJ_Loot()
1340					timer:Hide()
1341				end
1342			end
1343		end)
1344	timer:Show()
1345	
1346end
1347
1348StaticPopupDialogs["ALBQueryAll"] = {
1349	button1 = ACCEPT,
1350	button2 = CANCEL,
1351	sound = "JewelcraftingFinalize",
1352	whileDead = 1,
1353	hideOnEscape = 1,
1354	timeout = 0,
1355	OnAccept = function() ALB:QueryReallyAll() end,
1356	OnCancel = function() ALB:ToggleWindow() end
1357	}
1358
1359SLASH_APHESLOOTBROWSER1 = "/ALB"
1360SLASH_APHESLOOTBROWSER2 = "/AphesLootBrowser"
1361SlashCmdList["APHESLOOTBROWSER"] = function(arg) 
1362	ALB:ToggleWindow()
1363end
1364
1365SLASH_APHESLOOTBROWSERVERSIONCHECK1 = "/ALBversion"
1366SlashCmdList["APHESLOOTBROWSERVERSIONCHECK"] = function(arg) 
1367	ALB:CheckVersions()
1368end
1369
1370
1371
1372ALB:RegisterEvent("ADDON_LOADED")
1373--ALB:RegisterEvent("PLAYER_ALIVE")
1374ALB:RegisterEvent("EJ_LOOT_DATA_RECIEVED")