view HotCorners.lua @ 25:ac501d71c890 tip

Added tag v8.2.0.024 for changeset 389dcaeebc47
author Tercioo
date Fri, 28 Jun 2019 20:07:27 -0300
parents fc72b86a3b66
children
line wrap: on
line source
LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
_G.HotCorners = LibHotCorners
local LibHotCorners = LibHotCorners

local LBD = LibStub ("LibDataBroker-1.1")

local debug = false
local tinsert = tinsert

local default_db = {
	profile = {
		is_enabled = true,
		topleft_enabled = true,
		topleft_quickfunc = false,
		clicks = {}, 
		disabled = {}
	},
}

LibHotCorners.RegistredQuickFunctions = {}
LibHotCorners.QuickFunctions = {topleft = false}

LibHotCorners.LastItemButtonClick = GetTime()

function LibHotCorners:OnEnable()
	
end

function LibHotCorners:OnDisable()
	
end

LibHotCorners.ItemButtons = {}
LibHotCorners.ItemOnInventory = {}

local refresh_topleft = function()
	LibHotCorners ["topleft"].is_enabled = LibHotCorners.db.profile.topleft_enabled
end

local OptionsTable = {
	name = "HotCorners",
	type = "group",
	args = {
		Enabled = {
			type = "toggle",
			name = "Enabled",
			desc = "Enable or Disable this addon.",
			order = 1,
			get = function() return LibHotCorners.db.profile.is_enabled end,
			set = function (self, val) LibHotCorners.db.profile.is_enabled = not LibHotCorners.db.profile.is_enabled; --[[ do something]] end,
		},
		TopLeftEnabled = {
			type = "toggle",
			name = "Top Left",
			desc = "Enable or Disable the Top Left bar.",
			order = 2,
			get = function() return LibHotCorners.db.profile.topleft_enabled end,
			set = function (self, val) LibHotCorners.db.profile.topleft_enabled = not LibHotCorners.db.profile.topleft_enabled; refresh_topleft() end,
		},
		QuickClickFunc = {
			type = "select",
			name = "Quick Click",
			desc = "Select the behavior when clicking over the absolute topleft corner.",
			values = function()
					local options = {}
					for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do
						options [quickfunc.name] = quickfunc.name
					end
					return options
				end,
			get = function() return LibHotCorners.db.profile.topleft_quickfunc or "" end,
			set = function (self, funcname) 
						LibHotCorners.db.profile.topleft_quickfunc = funcname;
						for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do
							if (quickfunc.name == funcname) then
								LibHotCorners.QuickFunctions.topleft = quickfunc.func
								break
							end
						end
				end,
			order = 4,
		}
	}
}

function LibHotCorners:OnInitialize()

	--declarar primeiro o db usando a global que é declarada no toc.
  	self.db = LibStub ("AceDB-3.0"):New ("HotCornersDB", default_db, true)
	
	--declara agora as opções da tab raiz
	LibStub("AceConfig-3.0"):RegisterOptionsTable ("HotCorners", OptionsTable)
	LibHotCorners.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("HotCorners", "HotCorners")
	--sub tab
	LibStub ("AceConfig-3.0"):RegisterOptionsTable ("HotCorners-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db))
	LibHotCorners.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("HotCorners-Profiles", "Profiles", "HotCorners")

	LibHotCorners ["topleft"].is_enabled = self.db.topleft_enabled
	refresh_topleft()
	
	SLASH_HOTCORNER1, SLASH_HOTCORNER2 = "/hotcorners", "/hotcorner"
	function SlashCmdList.HOTCORNER (msg, editbox)
		HotCornersOpenOptions (self);
	end
	
	for name, dataobj in LBD:DataObjectIterator() do
		if (dataobj.type and dataobj.icon and dataobj.OnClick) then
			LibHotCorners:RegisterHotCornerButton (name, "TopLeft", nil, name .. "HotCornerLauncher", dataobj.icon, dataobj.OnTooltipShow, dataobj.OnClick, nil, nil, dataobj.OnEnter, dataobj.OnLeave)
		end
	end
	for k, v in pairs (LBD.attributestorage) do 
		--print (k, v)
		--print ("----------------")
		--vardump (v)
	end
	
end

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> main function

	LibHotCorners.embeds = LibHotCorners.embeds or {}
	local embed_functions = {
		"RegisterHotCornerButton",
		"HideHotCornerButton",
	}
	
	function LibHotCorners:Embed (target)
		for k, v in pairs (embed_functions) do
			target[v] = self[v]
		end
		self.embeds [target] = true
		return target
	end

	local CallbackHandler = LibStub:GetLibrary ("CallbackHandler-1.0")
	LibHotCorners.callbacks = LibHotCorners.callbacks or CallbackHandler:New (LibHotCorners)

	LibHotCorners.topleft = LibHotCorners.topleft or {widgets = {}, quickclick = false, is_enabled = false, map = {}}
	LibHotCorners.bottomleft = {}
	LibHotCorners.topright = {}
	LibHotCorners.bottomright = {}

	local function test (corner)
		assert (corner == "topleft" or corner == "bottomleft" or corner == "topright" or corner == "bottomright", "LibHotCorners:RegisterAddon expects a corner on #1 argument.")
	end
	
	function LibHotCorners:AddQuickFunction (quickfunc, corner)

		local current_quickfunc = LibHotCorners.db.profile [corner .. "_quickfunc"] or ""
	
		--> passed only one table
		if (quickfunc.name) then
			--> check if already exists
			local already_exists = false
			for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do
				if (registred.name == quickfunc.name) then
					registred.func = quickfunc.func
					if (current_quickfunc == quickfunc.name) then
						LibHotCorners.QuickFunctions [corner] = quickfunc.func
					end
					already_exists = true
					break
				end
			end
			--> add table
			if (not already_exists) then
				table.insert (LibHotCorners.RegistredQuickFunctions, quickfunc)
				if (current_quickfunc == quickfunc.name) then
					LibHotCorners.QuickFunctions [corner] = quickfunc.func
				end
			end
			--> check if there is a quickfunc to be use
			if (current_quickfunc == "") then
				LibHotCorners.db.profile [corner .. "_quickfunc"] = quickfunc.name
				LibHotCorners.QuickFunctions [corner] = quickfunc.func
			end
		else
			--> passed a table of tables
			for _, this_quickfunc in ipairs (quickfunc) do
				--> check if already exists
				local already_exists = false
				for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do
					if (registred.name == this_quickfunc.name) then
						registred.func = this_quickfunc.func
						if (current_quickfunc == this_quickfunc.name) then
							LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
						end
						already_exists = true
						break
					end
				end
				--> add table
				if (not already_exists) then
					table.insert (LibHotCorners.RegistredQuickFunctions, this_quickfunc)
					if (current_quickfunc == this_quickfunc.name) then
						LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
					end
				end
				--> check if there is a quickfunc to be use
				if (current_quickfunc == "") then
					LibHotCorners.db.profile [corner .. "_quickfunc"] = this_quickfunc.name
					LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
					current_quickfunc = this_quickfunc.name
				end
			end
		end

	end
	
	function LibHotCorners:RegisterHotCornerButton (name, corner, optionstable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install)
		corner = string.lower (corner)
		test (corner)

		optionstable = optionstable or {hide = false}
		
		if (is_install) then
			--> overwrite if already exists a widget
			for i, widget in ipairs (LibHotCorners [corner]) do
				if (widget.name == name) then
					table.remove (LibHotCorners [corner], i)
					table.insert (LibHotCorners [corner], i, {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
					if (quickfunc) then
						LibHotCorners:AddQuickFunction (quickfunc, corner)
					end
					return LibHotCorners [corner].map [name]
				end
			end
			--> add
			table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
			LibHotCorners [corner].map [name] = #LibHotCorners [corner]
			if (quickfunc) then
				LibHotCorners:AddQuickFunction (quickfunc, corner)
			end
			return LibHotCorners [corner].map [name]
		else
			--> check if already exists
			for i, widget in ipairs (LibHotCorners [corner]) do
				if (widget.name == name) then
					return
				end
			end
			--> add
			table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave})
			LibHotCorners [corner].map [name] = #LibHotCorners [corner]
			if (quickfunc) then
				LibHotCorners:AddQuickFunction (quickfunc, corner)
			end
			return LibHotCorners [corner].map [name]
		end
	end
	
	function LibHotCorners:HideHotCornerButton (name, corner, value)
		
		corner = string.lower (corner)
		test (corner)
		
		local corner_table = LibHotCorners [corner]
		local addon_table = corner_table [corner_table.map [name]]
		
		if (addon_table) then
			addon_table.optionstable.hide = value
		end

		LibHotCorners [corner].is_enabled = false
		
		for index, button_table in ipairs (corner_table) do
			if (not button_table.optionstable.hide) then
				LibHotCorners [corner].is_enabled = true
				break
			end
		end
		
		return true
	end
	
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> data broker stuff
	function LibHotCorners:DataBrokerCallback (event, name, dataobj)
		if (not name or not dataobj or not dataobj.type) then
			return
		end
		if (dataobj.icon and dataobj.OnClick) then
			LibHotCorners:RegisterHotCornerButton (name, "TopLeft", nil, name .. "HotCornerLauncher", dataobj.icon, dataobj.OnTooltipShow, dataobj.OnClick, nil, nil, dataobj.OnEnter, dataobj.OnLeave)
		end
	end
	LBD.RegisterCallback (LibHotCorners, "DataBrokerCallback")
	
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> scripts

	--> background (window mode fix)
	function HotCornersBackgroundOnEnter (self)
		if (LibHotCornersTopLeft and LibHotCornersTopLeft:IsShown()) then
			if (LibHotCornersTopLeft:GetWidth() > 2) then
				HotCornersOnLeave (LibHotCornersTopLeft, true)
			end
		end
		self:EnableMouse (false)
	end

	--> set size
		local function set_size (self)
			if (self.position == "topleft" or self.position == "topright") then
				self:SetSize (40, GetScreenHeight())
			else
				self:SetSize (GetScreenWidth(), 40)
			end
		end
		
	--> show tooltip
		local show_tooltip = function (self)
			if (self.table and self.table.tooltip) then
				if (type (self.table.tooltip) == "function") then
					GameTooltip:SetOwner (self, "ANCHOR_RIGHT")
					self.table.tooltip (GameTooltip)
					GameTooltip:Show()
				elseif (type (self.table.tooltip) == "string") then
					GameTooltip:SetOwner (self, "ANCHOR_RIGHT")
					GameTooltip:AddLine (self.table.tooltip)
					GameTooltip:Show()
				end
			elseif (self.table and self.table.onenter) then
				self.table.onenter (self)
			elseif (self.isItem) then
				GameTooltip:SetOwner (self, "ANCHOR_BOTTOMRIGHT")
				GameTooltip:SetHyperlink (self.itemtable[4])
				GameTooltip:Show()
			end
		end
		
	--> corner frame on enter
		local more_clicked = function (t1, t2)
			return t1[1] > t2[1]
		end

		LibHotCorners.BackPackItemList = {

			--> hearthstones
				[140192] = true, -- Dalaran Hearthstone
				--[110560] = true, -- Garrison Hearthstone
				[6948] = true, -- Innkeeper Hearthstone
				
			--> good items
				
				
			--> alchemy
			
				--MOP
				[76086] = true, -- Flask of Falling Leaves
				[76084] = true, -- Flask of Spring Blossoms
				[76085] = true, -- Flask of the Warm Sun
				[76087] = true, -- Flask of the Earth
				[76088] = true, -- Flask of Winter's Bite
			
				[76081] = true, -- Elixir of Mirrors
				[76079] = true, -- Elixir of Peace
				[76080] = true, -- Elixir of Perfection
				[76078] = true, --  Elixir of the Rapids
				[76077] = true, -- Elixir of Weaponry
				[70676] = true, -- Mad Hozen Elixir
				[76075] = true, -- Mantid Elixir
				[76083] = true, -- Monk's Elixir
			
				[76094] = true, -- Alchemist's Rejuvenation
				[96096] = true, -- Darkwater Potion
				[75218] = true, -- Electrified Oil
				[76097] = true, -- Master Healing Potion
				[76098] = true, -- Master Mana Potion
				[76092] = true, -- Potion of Focus
				[76093] = true, -- Potion of the Jade Serpent
				[76095] = true, -- Potion of Mogu Power
				[76090] = true, -- Potion of the Mountains
				[76091] = true, -- Greater Potion of Luck
				[76089] = true, -- Virmen's Bite
				
				--WOD
				[118704] = true, --Pure Rage Potion
				[109156] = true, --Greater Draenic Strength Flask
				[109160] = true, --Greater Draenic Stamina Flask
				[109155] = true, --Greater Draenic Intellect Flask
				[109153] = true, --Greater Draenic Agility Flask
				[118711] = true, --Draenic Water Walking Elixir
				[116271] = true, --Draenic Water Breathing Elixir
				[116266] = true, --Draenic Swiftness Potion
				[109219] = true, --Draenic Strength Potion
				[109148] = true, --Draenic Strength Flask
				[109152] = true, --Draenic Stamina Flask
				[109226] = true, --Draenic Rejuvenation Potion
				[109222] = true, --Draenic Mana Potion
				[116276] = true, --Draenic Living Action Potion
				[116268] = true, --Draenic Invisibility Potion
				[109218] = true, --Draenic Intellect Potion
				[109147] = true, --Draenic Intellect Flask
				[109221] = true, --Draenic Channeled Mana Potion
				[109220] = true, --Draenic Armor Potion
				[109217] = true, --Draenic Agility Potion
				[109145] = true, --Draenic Agility Flask
				[112090] = true, --Transmorphic Tincture

			--> cooking
				--WOD
				[111449] = true, --Blackrock Barbecue
				[111433] = true, --Blackrock Ham
				[111436] = true, --Braised Riverbeast
				[122348] = true, --Buttered Sturgeon
				[111453] = true, --Calamari Crepes
				[111438] = true, --Clefthoof Sausages
				[126935] = true, --Fancy Darkmoon Feast
				[111444] = true, --Fat Sleeper Cakes
				[111457] = true, --Feast of Blood
				[111458] = true, --Feast of the Waters
				[111445] = true, --Fiery Calamari
				[111450] = true, --Frosty Stew
				[111454] = true, --Gorgrond Chowder
				[111441] = true, --Grilled Gulper
				[111456] = true, --Grilled Saberfish
				[111431] = true, --Hearty Elekk Steak
				[122346] = true, --Jumbo Sea Dog
				[126934] = true, --Lemon Herb Filet
				[111434] = true, --Pan-Seared Talbuk
				[122345] = true, --Pickled Eel
				[111437] = true, --Rylak Crepes
				[111455] = true, --Saberfish Broth
				[122344] = true, --Salty Squid Roll
				[111446] = true, --Skulker Chowder
				[111452] = true, --Sleeper Surprise
				[122343] = true, --Sleeper Sushi
				[111439] = true, --Steamed Scorpion
				[111442] = true, --Sturgeon Stew
				[126936] = true, --Sugar-Crusted Fish Feast
				[111447] = true, --Talador Surf and Turf
				[122347] = true, --Whiptail Fillet
				--[] = true, --
				--MOP
				--Way of the Grill: Strength
				[74642] = true, -- Charbroiled Tiger Steak
				[74645] = true, -- Eternal Blossom Fish
				[74646] = true, -- Black Pepper Ribs and Shrimp

				--Way of the Oven: Stamina
				[74654] = true, -- Wildfowl Roast
				[74655] = true, -- Twin Fish Platter
				[74656] = true, -- Chun Tian Spring Rolls

				--Way of the Pot: Intellect

				[74644] = true, -- Swirling Mist Soup
				[74649] = true, -- Braised Turtle
				[74650] = true, -- Mogu Fish Stew

				--Way of the Steamer: Spirit

				[74651] = true, -- Shrimp Dumplings
				[74652] = true, -- Fire Spirit Salmon
				[74653] = true, -- Steamed Crab Surprise

				--Way of the Wok: Agility

				[74643] = true, -- Sauteed Carrots
				[74647] = true, -- Valley Stir Fry
				[74648] = true, -- Sea Mist Rice Noodles

				--Way of the Brew: Headaches and Grandeur

				[74626] = true, -- Ginseng Tea
				[74637] = true, -- Jade Witch Brew
				[74638] = true, -- Mad Brewer's Breakfast

				--General Cooking
			
				[74641] = true, -- Fish Cake
				[74636] = true, -- Golden Carp Consomme
				[86070] = true, -- Wildfowl Ginseng Soup
				[86069] = true, -- Rice Pudding
				[86074] = true, -- Spicy Vegetable Chips
				[86073] = true, -- Spicy Salmon
			
				--5.4 Recipes
			
				[145308] = true, -- Mango Ice
				[145309] = true, -- Farmer's Delight
				[145311] = true, -- Fluffy Silkfeather Omelet
				[145310] = true, -- Stuffed Lushrooms
				[145307] = true, -- Spiced Blossom Soup
				[145305] = true, -- Seasoned Pomfruit Slices
			
				--Cart Kits
				[101630] = true, -- Noodle Cart Kit
				[101661] = true, -- Deluxe Noodle Cart Kit
				[101662] = true, -- Pandaren Treasure Noodle Cart Kit
				
				[101618] = true, -- Pandaren Treasure Noodle Soup
				[101617] = true, -- Deluxe Noodle Soup
				[101616] = true, -- Noodle Soup

			--LEGION
				[188028] = true, --Potion of the Old War
				[188027] = true, --Potion of Deadly Grace
				[188029] = true, --Unbending Potion
				[188017] = true, --Ancient Mana Potion
				[188030] = true, --Leytorrent Potion
				[229206] = true, --Potion of Prolongued Power

		}
		
		function HotCornersOnEnter (self)
			
			if (not LibHotCorners.db.profile.is_enabled) then
				return
			end
			
			if (not LibHotCorners.db.profile [self.position .. "_enabled"]) then
				return
			end
	
			if (self:GetWidth() < 1.1 and self:GetHeight() < 1.1) then
				--print ("abrindo...")
			end
	
			set_size (self)
			
			HotCornersBackgroundFrame:EnableMouse (true)
			self.item_frame:Show()
			
			local i = 1
			
			local sort = {}
			local clicks = LibHotCorners.db.profile.clicks
			for index, button_table in ipairs (LibHotCorners [self.position]) do 
				tinsert (sort, {clicks [button_table.name] or 0, button_table})
			end
			table.sort (sort, more_clicked)
			
			local last_button
			
			local disabled = LibHotCorners.db.profile.disabled
			
			for index, button_table in ipairs (sort) do 
				button_table = button_table [2]
				if (not button_table.widget) then
					LibHotCorners:CreateAddonWidget (self, button_table, index, self.position)
				end
				
				button_table.widget:ClearAllPoints()
				
				if (not disabled [button_table.name] and not button_table.optionstable.hide) then
					if (self.position == "topleft" or self.position == "topright") then
						
						local y = i * 35 * -1
						--button_table.widget:SetPoint ("topleft", self, "topleft", 4, y)
						button_table.widget.y = y
						HotCornersStartAnimOnShow (button_table.widget, "y")
						
					else --bottom left /  bottom right
						local x = i * 35
						button_table.widget:SetPoint ("topleft", self, "topleft", x, -4)
						button_table.widget.x = x
					end

					button_table.widget:Show()
					last_button = button_table.widget
					
					i = i + 1
				else
					button_table.widget:Hide()
				end
			end
			
			local OptionsButton = LibHotCorners [self.position].optionsbutton
			local y = i * 35 * -1
			OptionsButton:SetPoint ("top", self, "top", 0, y)
			OptionsButton:Show()
			
			--item frame
			LibHotCorners:RefereshItems (self)
			
			--self.AnimOnShow:Play()
			HotCornersInfosFrame:Show()
			HotCornersInfosFrame:SetAlpha (0)
			--HotCornersInfosFrame.AnimOnShow:Play()
			
			--update repair
			local percent, items = 0, 0
			for i = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do
				local durability, maxdurability = GetInventoryItemDurability (i)
				if (durability and maxdurability) then
					local p = durability / maxdurability * 100
					percent = percent + p
					items = items + 1
				end
			end
			
			if (items == 0) then
				HotCornersInfosFrame.repairText:SetText ("-- %")
			end
			
			percent = percent / items
			HotCornersInfosFrame.repairText:SetText (math.floor (percent) .. "%")
			
			--update date
			HotCornersInfosFrame.clockText:SetText (date ("%H:%M"))
			HotCornersInfosFrame.dayText:SetText (date ("%A\n%B %d"))
			
			--update money
			local money = GetMoney()
			HotCornersInfosFrame.goldText:SetText (math.floor (money / 100 / 100))
			HotCornersInfosFrame.silverText:SetText (math.floor ((money / 100) % 100))
			HotCornersInfosFrame.bronzeText:SetText (math.floor (money % 100))
			
			--HotCornersInfosFrame.clockText:SetText (date ("%A %B %d %H:%M:%S %Y"))
			
		end

	function LibHotCorners:RefereshItems (self)
		
		if (HotCornersItemUsed and LibHotCorners.LastItemButtonClick < GetTime() and not self) then
			for _, button in pairs (LibHotCorners.ItemButtons) do
				if (not button.itemtable[6]) then --> isn't a profession cooldown
					button.cooldown:SetCooldown (GetTime(), 1.5)
				end
			end
			HotCornersItemUsed = nil
			LibHotCorners.LastItemButtonClick = GetTime()+1.5
		end
		
		if (not self) then
			return LibHotCorners:ScheduleTimer ("RefereshItems", 1, LibHotCornersTopLeft)
		end
		
		if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
		
			--update the icon
			for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do
				itemTable [1] = 0
			end
		
			for bagID = 0, 4 do
				local numItems = GetContainerNumSlots (bagID)
				for slot = 1, numItems do
					local itemId = GetContainerItemID (bagID, slot)
					if (LibHotCorners.BackPackItemList [itemId]) then
						local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo (bagID, slot)
						if (not LibHotCorners.ItemOnInventory [itemId]) then
							LibHotCorners.ItemOnInventory [itemId] = {itemCount, texture, quality, itemLink, itemId}
						else
							LibHotCorners.ItemOnInventory [itemId] [1] = LibHotCorners.ItemOnInventory [itemId] [1] + itemCount
						end
					end
				end
			end
			
			local index = 1
			for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do
				local itemCount, texture, quality, itemLink = unpack (itemTable)
				
				local item_button = LibHotCorners:GetItemButton (index, self)
				if (item_button) then

					item_button:SetNormalTexture (texture)
					item_button:SetHighlightTexture (texture)
					item_button:SetPushedTexture (texture)

					itemCount = itemCount or 0
					if (itemCount > 1) then
						item_button.item_count:SetText (itemCount or 0)
						item_button.bg_item_count:Show()
					else
						item_button.item_count:SetText ("")
						item_button.bg_item_count:Hide()
					end
					
					if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
						item_button:SetAttribute ("macrotext", "/use " .. GetItemInfo (itemId) .. ";\n/script HotCornersItemUsed=GetTime(); HotCorners:RefereshItems()")
						item_button:GetNormalTexture():SetDesaturated (false)
						--item_button:Enable()
					else
						item_button:GetNormalTexture():SetDesaturated (true)
						--item_button:Disable()
					end
					
					item_button.itemtable = itemTable
					
					if (not item_button:IsShown() or item_button:GetAlpha() < 1) then
	--						HotCornersStartAnimOnShow (item_button, "item_topleft")
					end
					
					if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
						item_button:Show()
					end
				end
				index = index + 1
			end

			LibHotCorners:RefereshProfessions (self, index)

		end
		
		--/run local itemid=GetContainerItemID (0, 1);print (itemid)
		--UseContainerItem(bagID, slot[, onSelf])
	end
	
	local get_profession = function (icon)
		if (icon:find ("Trade_Engineering")) then
			return "en"
		elseif (icon:find ("Trade_LeatherWorking")) then
			return "lw"
		elseif (icon:find ("Trade_Tailoring")) then
			return "tl"
		elseif (icon:find ("Trade_Engraving")) then
			return "ec"
		elseif (icon:find ("Trade_BlackSmithing")) then
			return "bs"
		elseif (icon:find ("Trade_Alchemy")) then
			return "al"
		elseif (icon:find ("INV_Misc_Gem_01")) then
			return "jc"
		elseif (icon:find ("INV_Inscription_Tradeskill01")) then
			return "in"
		end
	end
	local secrets_index = {
		["tl"] = 176058, --tailoring
		["ec"] = 177043, --enchanting
		["lw"] = 176089, --letherwork
		["en"] = 177054, --engeener
		["bs"] = 176090, --blacksmith
		["al"] = 175880, --alchemy
		["jc"] = 176087, --jewelcraft
		["in"] = 177045, --inscription
	}
	local secrets_icons = {
		["tl"] = "inv_misc_book_03", --tailoring
		["ec"] = "inv_misc_book_08", --enchant
		["al"] = "inv_misc_book_08", -- alchemy
		["bs"] = "inv_misc_book_11", --bs
		["en"] = "inv_misc_book_08", --engeener
		["in"] = "inv_misc_book_08", --inscritp
		["jc"] = "inv_misc_book_10", --jc
		["lw"] = "inv_misc_book_09", --lw
	}
	
	function LibHotCorners:RefereshProfessions (self, index)
		
		index = index + 1
		
		local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions()

		if (prof1) then
			local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier, specializationIndex, specializationOffset = GetProfessionInfo (prof1)
			local prof = get_profession (icon)
			local secrets_spellID = secrets_index [prof]
			if (secrets_spellID) then
				local name, _, texture = GetSpellInfo (secrets_spellID)
				texture = "Interface\\Icons\\" .. secrets_icons [prof]
				local item_button = LibHotCorners:GetItemButton (index, self)
				if (item_button) then
					item_button:SetNormalTexture (texture)
					item_button:SetHighlightTexture (texture)
					item_button:SetPushedTexture (texture)

					item_button:SetAttribute ("macrotext", "/cast " .. name .. ";\n/script HotCornersItemUsed=GetTime(); HotCorners:RefereshItems()")
					
					item_button.itemtable = {false, false, false, GetSpellLink (secrets_spellID), false, true}
					
					local start, duration = GetSpellCooldown (secrets_spellID)
					if (start and start > 0) then
						item_button.cooldown:SetCooldown (start, duration)
					else
						item_button.item_count:SetText (1)
					end
					
					if (not item_button:IsShown() or item_button:GetAlpha() < 1) then
--						HotCornersStartAnimOnShow (item_button, "item_topleft")
					end
				end
				index = index + 1
			end
		end
		
		if (prof2) then
			local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier, specializationIndex, specializationOffset = GetProfessionInfo (prof2)
			local prof = get_profession (icon)
			local secrets_spellID = secrets_index [prof]
			if (secrets_spellID) then
				local name, _, texture = GetSpellInfo (secrets_spellID)
				texture = "Interface\\Icons\\" .. secrets_icons [prof]
				local item_button = LibHotCorners:GetItemButton (index, self)
				if (item_button) then
					item_button:SetNormalTexture (texture)
					item_button:SetHighlightTexture (texture)
					item_button:SetPushedTexture (texture)

					item_button:SetAttribute ("macrotext", "/cast " .. name .. ";\n/script HotCornersItemUsed=GetTime(); HotCorners:RefereshItems()")
					
					item_button.itemtable = {false, false, false, GetSpellLink (secrets_spellID), false, true}
					
					local start, duration = GetSpellCooldown (secrets_spellID)
					if (start and start > 0) then
						item_button.cooldown:SetCooldown (start, duration)
					else
						item_button.item_count:SetText (1)
					end
					
					if (not item_button:IsShown() or item_button:GetAlpha() < 1) then
--						HotCornersStartAnimOnShow (item_button, "item_topleft")
					end
				end
				index = index + 1
			end
		end
		
	end
		
	function LibHotCorners:GetItemButton (index, parent)
		local button = LibHotCorners.ItemButtons [index]
		if (not button) then
			button = CreateFrame ("button", "HotCornersItemButton" .. index, parent.item_frame, "HotCornersUseItemButtonTemplate")
			button.isItem = true
			
			if (parent.position == "topleft") then
				local x = (index-1) * 33
				button:SetPoint ("topleft", parent.item_frame, "topleft", x, -2)
				button.x = x
			elseif (parent.position == "topright") then
				local x = (index-1) * 33
				button:SetPoint ("topright", parent.item_frame, "topright", -x, -2)
			end
			
			LibHotCorners.ItemButtons [index] = button
		end
		return button
	end
		
	--> corner frame on leave
		function HotCornersOnLeave (self, from_background)
			if (not from_background) then
				return
			end
			
			self:SetSize (1, 1)
			for index, button_table in ipairs (LibHotCorners [self.position]) do 
				if (button_table.widget) then
					button_table.widget:Hide()
				end
			end
			for _, button in pairs (LibHotCorners.ItemButtons) do 
				button:Hide()
			end
			
			local OptionsButton = LibHotCorners [self.position].optionsbutton
			OptionsButton:Hide()
			
			self.item_frame:Hide()
			HotCornersInfosFrame:Hide()
		end
		
	--> quick corner on click
		function HotCornersOnQuickClick (self, button)
			local parent_position = self:GetParent().position
			local func = LibHotCorners.QuickFunctions [parent_position]
			if (func) then
				func (self, button)
			end
		end

	--> options button onenter
		function HotCornersOptionsButtonOnEnter (self)
			set_size (self:GetParent())
			for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do 
				if (not LibHotCorners.db.profile.disabled [button_table.name]) then
					button_table.widget:Show()
				end
			end
			self:Show()
		end
		
		function HotCornersOpenOptions (self)
			InterfaceOptionsFrame_OpenToCategory ("HotCorners")
			InterfaceOptionsFrame_OpenToCategory ("HotCorners")
		end
		
		function HotCornersSetEnabled (state)
			LibHotCorners.db.profile.is_enabled = state
		end
	
	--> options button onleave
		function HotCornersOptionsButtonOnLeave (self)
			self:GetParent():GetScript("OnLeave")(self:GetParent())
		end
	
	--> button onenter
		function HotCornersButtonOnEnter (self)
			--set_size (self:GetParent())
			--for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do 
			--	if (not LibHotCorners.db.profile.disabled [button_table.name] and button_table.widget) then
			--		button_table.widget:Show()
			--	end
			--end
			show_tooltip (self)
			--local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton
			--OptionsButton:Show()
		end
	
	--> button onleave
		function HotCornersButtonOnLeave (self)
			GameTooltip:Hide()
			if (self.table and self.table.onleave) then
				self.table.onleave (self)
			end
			--self:GetParent():GetScript("OnLeave")(self:GetParent())
			--local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton
			--OptionsButton:Hide()
		end

	--> button onmousedown
		function HotCornersButtonOnMouseDown (self, button)
			if (self.isItem) then
				if (self:GetParent():GetParent().position == "topleft") then
					self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -3)
				end
			else
				if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then
					self:SetPoint ("topleft", self:GetParent(), "topleft", 5, self.y - 1)
				else
					self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -6)
				end
			end
		end
		
	--> button onmouseup
		function HotCornersButtonOnMouseUp (self, button)
			if (self.isItem) then
				if (self:GetParent():GetParent().position == "topleft") then
					self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -2)
				end
			else
				if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then
					self:SetPoint ("topleft", self:GetParent(), "topleft", 4, self.y)
				else
					self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -4)
				end
				if (self.table.click) then
					local clicks = LibHotCorners.db.profile.clicks
					clicks [self.table.name] = clicks [self.table.name] or 0
					clicks [self.table.name] = clicks [self.table.name] + 1
					self.table.click (self, button)
				end
			end
		end
	
	--> start show animation
		function HotCornersStartAnimOnShow (button, axis)
			if (axis == "y") then
				--button:SetPoint ("topleft", button:GetParent(), "topleft", -32, button.y)
				button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y)
				--button.AnimOnShow:Play()
				button:Show()
				button:SetAlpha (1)
				
			elseif (axis == "item_topleft") then
				--button.AnimOnShow:Play()
				button:Show()
				button:SetAlpha (1)
			end
		end
		
	--> on start / finish show animation
		function HotCornersAnimOnShowStarted (button)
			
		end
		function HotCornersAnimOnShowFinished (button)
			--button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y)
			button:Show()
			--button:SetPoint ("topleft", button:GetParent(), "topleft", -4, button.y)
		end

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> create top left corner

	local TopLeftCorner = CreateFrame ("Frame", "LibHotCornersTopLeft", nil, "HotCornersFrameCornerTemplate")
	TopLeftCorner:SetPoint ("topleft", UIParent, "topleft", 0, 0)
	TopLeftCorner.position = "topleft"
	
	--fast corner button
	local QuickClickButton = CreateFrame ("button", "LibHotCornersTopLeftFastButton", TopLeftCorner, "HotCornersQuickCornerButtonTemplate")
	
	--options button
	local OptionsButton = CreateFrame ("button", "LibHotCornersTopLeftOptionsButton", TopLeftCorner, "HotCornersOptionsButtonTemplate")
	
	if (debug) then
		QuickClickButton:SetSize (20, 20)
		QuickClickButton:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]], tile = true, tileSize = 40})
		QuickClickButton:SetBackdropColor (1, 0, 0, 1)
	end
	
	LibHotCorners.topleft.quickbutton = QuickClickButton
	LibHotCorners.topleft.optionsbutton = OptionsButton

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> buttons 

	function LibHotCorners:CreateAddonWidget (frame, button_table, index, side)
	
		--> create the button
		local button = CreateFrame ("button", "LibHotCorners" .. side .. button_table.fname, frame, "HotCornersButtonTemplate")
		
		--> write some attributes
		button.index = index
		button.table = button_table
		button.parent = frame
		button_table.widget = button
		
		--> set the icon
		button:SetNormalTexture (button_table.icon)
		button:SetHighlightTexture (button_table.icon)
	
		if (string.lower (button_table.icon):find ([[\icons\]]) or string.lower (button_table.icon):find ([[\ICONS\]]) or string.lower (button_table.icon):find ([[\Icons\]])) then
			button:GetNormalTexture():SetTexCoord (0.078125, 0.9375, 0.078125, 0.9375)
			button:GetHighlightTexture():SetTexCoord (0.078125, 0.9375, 0.078125, 0.9375)
		end
		
		button:SetNormalTexture (button_table.icon)
		button:SetHighlightTexture (button_table.icon)
		
		button.Icon = button:CreateTexture (nil, "overlay")
		button.Icon:SetTexture (button_table.icon)
		button.Icon:SetSize (32, 32)
		button.Icon:SetPoint ("center", button, "center", 0, 0)
		
		--print (button:GetName())
		--print (1, button:GetAlpha())
		
		return button
	end