tercio@0: LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") tercio@1: _G.HotCorners = LibHotCorners tercio@0: local LibHotCorners = LibHotCorners tercio@0: tercio@0: local LBD = LibStub ("LibDataBroker-1.1") tercio@0: tercio@0: local debug = false tercio@0: local tinsert = tinsert tercio@0: tercio@0: local default_db = { tercio@0: profile = { tercio@0: is_enabled = true, tercio@0: topleft_enabled = true, tercio@1: topleft_quickfunc = false, tercio@0: clicks = {}, tercio@0: disabled = {} tercio@0: }, tercio@0: } tercio@0: tercio@1: LibHotCorners.RegistredQuickFunctions = {} tercio@1: LibHotCorners.QuickFunctions = {topleft = false} tercio@1: Tercio@7: LibHotCorners.LastItemButtonClick = GetTime() Tercio@7: tercio@0: function LibHotCorners:OnEnable() tercio@0: tercio@0: end tercio@0: tercio@0: function LibHotCorners:OnDisable() tercio@0: tercio@0: end tercio@0: tercio@2: LibHotCorners.ItemButtons = {} tercio@2: LibHotCorners.ItemOnInventory = {} tercio@2: tercio@0: local refresh_topleft = function() tercio@0: LibHotCorners ["topleft"].is_enabled = LibHotCorners.db.profile.topleft_enabled tercio@0: end tercio@0: tercio@0: local OptionsTable = { tercio@0: name = "HotCorners", tercio@0: type = "group", tercio@0: args = { tercio@0: Enabled = { tercio@0: type = "toggle", tercio@0: name = "Enabled", tercio@0: desc = "Enable or Disable this addon.", tercio@0: order = 1, tercio@0: get = function() return LibHotCorners.db.profile.is_enabled end, tercio@0: set = function (self, val) LibHotCorners.db.profile.is_enabled = not LibHotCorners.db.profile.is_enabled; --[[ do something]] end, tercio@0: }, tercio@0: TopLeftEnabled = { tercio@0: type = "toggle", tercio@0: name = "Top Left", tercio@0: desc = "Enable or Disable the Top Left bar.", tercio@0: order = 2, tercio@0: get = function() return LibHotCorners.db.profile.topleft_enabled end, tercio@0: set = function (self, val) LibHotCorners.db.profile.topleft_enabled = not LibHotCorners.db.profile.topleft_enabled; refresh_topleft() end, tercio@0: }, tercio@1: QuickClickFunc = { tercio@1: type = "select", tercio@1: name = "Quick Click", tercio@1: desc = "Select the behavior when clicking over the absolute topleft corner.", tercio@1: values = function() tercio@1: local options = {} tercio@1: for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do tercio@1: options [quickfunc.name] = quickfunc.name tercio@1: end tercio@1: return options tercio@1: end, tercio@1: get = function() return LibHotCorners.db.profile.topleft_quickfunc or "" end, tercio@1: set = function (self, funcname) tercio@1: LibHotCorners.db.profile.topleft_quickfunc = funcname; tercio@1: for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do tercio@1: if (quickfunc.name == funcname) then tercio@1: LibHotCorners.QuickFunctions.topleft = quickfunc.func tercio@1: break tercio@1: end tercio@1: end tercio@1: end, tercio@1: order = 4, tercio@1: } tercio@0: } tercio@0: } tercio@0: tercio@0: function LibHotCorners:OnInitialize() tercio@0: tercio@0: --declarar primeiro o db usando a global que é declarada no toc. tercio@0: self.db = LibStub ("AceDB-3.0"):New ("HotCornersDB", default_db, true) tercio@0: tercio@0: --declara agora as opções da tab raiz tercio@0: LibStub("AceConfig-3.0"):RegisterOptionsTable ("HotCorners", OptionsTable) tercio@0: LibHotCorners.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("HotCorners", "HotCorners") tercio@0: --sub tab tercio@0: LibStub ("AceConfig-3.0"):RegisterOptionsTable ("HotCorners-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db)) tercio@0: LibHotCorners.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("HotCorners-Profiles", "Profiles", "HotCorners") tercio@0: tercio@0: LibHotCorners ["topleft"].is_enabled = self.db.topleft_enabled tercio@0: refresh_topleft() tercio@0: tercio@0: SLASH_HOTCORNER1, SLASH_HOTCORNER2 = "/hotcorners", "/hotcorner" tercio@0: function SlashCmdList.HOTCORNER (msg, editbox) tercio@0: HotCornersOpenOptions (self); tercio@0: end tercio@0: tercio@0: for name, dataobj in LBD:DataObjectIterator() do tercio@0: if (dataobj.type and dataobj.icon and dataobj.OnClick) then tercio@0: LibHotCorners:RegisterHotCornerButton (name, "TopLeft", nil, name .. "HotCornerLauncher", dataobj.icon, dataobj.OnTooltipShow, dataobj.OnClick, nil, nil, dataobj.OnEnter, dataobj.OnLeave) tercio@0: end tercio@0: end tercio@0: for k, v in pairs (LBD.attributestorage) do tercio@0: --print (k, v) tercio@0: --print ("----------------") tercio@0: --vardump (v) tercio@0: end tercio@0: tercio@0: end tercio@0: tercio@0: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@0: --> main function tercio@0: tercio@0: LibHotCorners.embeds = LibHotCorners.embeds or {} tercio@0: local embed_functions = { tercio@0: "RegisterHotCornerButton", tercio@0: "HideHotCornerButton", tercio@0: } tercio@0: tercio@0: function LibHotCorners:Embed (target) tercio@0: for k, v in pairs (embed_functions) do tercio@0: target[v] = self[v] tercio@0: end tercio@0: self.embeds [target] = true tercio@0: return target tercio@0: end tercio@0: tercio@0: local CallbackHandler = LibStub:GetLibrary ("CallbackHandler-1.0") tercio@0: LibHotCorners.callbacks = LibHotCorners.callbacks or CallbackHandler:New (LibHotCorners) tercio@0: tercio@0: LibHotCorners.topleft = LibHotCorners.topleft or {widgets = {}, quickclick = false, is_enabled = false, map = {}} tercio@0: LibHotCorners.bottomleft = {} tercio@0: LibHotCorners.topright = {} tercio@0: LibHotCorners.bottomright = {} tercio@0: tercio@0: local function test (corner) tercio@0: assert (corner == "topleft" or corner == "bottomleft" or corner == "topright" or corner == "bottomright", "LibHotCorners:RegisterAddon expects a corner on #1 argument.") tercio@0: end tercio@0: tercio@1: function LibHotCorners:AddQuickFunction (quickfunc, corner) tercio@1: tercio@1: local current_quickfunc = LibHotCorners.db.profile [corner .. "_quickfunc"] or "" tercio@1: tercio@1: --> passed only one table tercio@1: if (quickfunc.name) then tercio@1: --> check if already exists tercio@1: local already_exists = false tercio@1: for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do tercio@1: if (registred.name == quickfunc.name) then tercio@1: registred.func = quickfunc.func tercio@1: if (current_quickfunc == quickfunc.name) then tercio@1: LibHotCorners.QuickFunctions [corner] = quickfunc.func tercio@1: end tercio@1: already_exists = true tercio@1: break tercio@1: end tercio@1: end tercio@1: --> add table tercio@1: if (not already_exists) then tercio@1: table.insert (LibHotCorners.RegistredQuickFunctions, quickfunc) tercio@1: if (current_quickfunc == quickfunc.name) then tercio@1: LibHotCorners.QuickFunctions [corner] = quickfunc.func tercio@1: end tercio@1: end tercio@1: --> check if there is a quickfunc to be use tercio@1: if (current_quickfunc == "") then tercio@1: LibHotCorners.db.profile [corner .. "_quickfunc"] = quickfunc.name tercio@1: LibHotCorners.QuickFunctions [corner] = quickfunc.func tercio@1: end tercio@1: else tercio@1: --> passed a table of tables tercio@1: for _, this_quickfunc in ipairs (quickfunc) do tercio@1: --> check if already exists tercio@1: local already_exists = false tercio@1: for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do tercio@1: if (registred.name == this_quickfunc.name) then tercio@1: registred.func = this_quickfunc.func tercio@1: if (current_quickfunc == this_quickfunc.name) then tercio@1: LibHotCorners.QuickFunctions [corner] = this_quickfunc.func tercio@1: end tercio@1: already_exists = true tercio@1: break tercio@1: end tercio@1: end tercio@1: --> add table tercio@1: if (not already_exists) then tercio@1: table.insert (LibHotCorners.RegistredQuickFunctions, this_quickfunc) tercio@1: if (current_quickfunc == this_quickfunc.name) then tercio@1: LibHotCorners.QuickFunctions [corner] = this_quickfunc.func tercio@1: end tercio@1: end tercio@1: --> check if there is a quickfunc to be use tercio@1: if (current_quickfunc == "") then tercio@1: LibHotCorners.db.profile [corner .. "_quickfunc"] = this_quickfunc.name tercio@1: LibHotCorners.QuickFunctions [corner] = this_quickfunc.func tercio@1: current_quickfunc = this_quickfunc.name tercio@1: end tercio@1: end tercio@1: end tercio@1: tercio@1: end tercio@1: tercio@1: function LibHotCorners:RegisterHotCornerButton (name, corner, optionstable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install) tercio@0: corner = string.lower (corner) tercio@0: test (corner) tercio@0: tercio@1: optionstable = optionstable or {hide = false} tercio@1: tercio@0: if (is_install) then tercio@0: --> overwrite if already exists a widget tercio@0: for i, widget in ipairs (LibHotCorners [corner]) do tercio@0: if (widget.name == name) then tercio@0: table.remove (LibHotCorners [corner], i) tercio@1: 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}) tercio@1: if (quickfunc) then tercio@1: LibHotCorners:AddQuickFunction (quickfunc, corner) tercio@1: end tercio@0: return LibHotCorners [corner].map [name] tercio@0: end tercio@0: end tercio@1: --> add tercio@1: 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}) tercio@0: LibHotCorners [corner].map [name] = #LibHotCorners [corner] tercio@1: if (quickfunc) then tercio@1: LibHotCorners:AddQuickFunction (quickfunc, corner) tercio@1: end tercio@0: return LibHotCorners [corner].map [name] tercio@0: else tercio@1: --> check if already exists tercio@1: for i, widget in ipairs (LibHotCorners [corner]) do tercio@1: if (widget.name == name) then tercio@1: return tercio@0: end tercio@0: end tercio@1: --> add tercio@1: table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave}) tercio@1: LibHotCorners [corner].map [name] = #LibHotCorners [corner] tercio@1: if (quickfunc) then tercio@1: LibHotCorners:AddQuickFunction (quickfunc, corner) tercio@0: end tercio@1: return LibHotCorners [corner].map [name] tercio@0: end tercio@0: end tercio@0: tercio@0: function LibHotCorners:HideHotCornerButton (name, corner, value) tercio@0: tercio@0: corner = string.lower (corner) tercio@0: test (corner) tercio@0: tercio@0: local corner_table = LibHotCorners [corner] tercio@0: local addon_table = corner_table [corner_table.map [name]] tercio@0: tercio@1: if (addon_table) then tercio@1: addon_table.optionstable.hide = value tercio@1: end tercio@0: tercio@0: LibHotCorners [corner].is_enabled = false tercio@0: tercio@1: for index, button_table in ipairs (corner_table) do tercio@1: if (not button_table.optionstable.hide) then tercio@0: LibHotCorners [corner].is_enabled = true tercio@0: break tercio@0: end tercio@0: end tercio@0: tercio@0: return true tercio@0: end tercio@0: tercio@0: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@0: --> data broker stuff tercio@0: function LibHotCorners:DataBrokerCallback (event, name, dataobj) tercio@0: if (not name or not dataobj or not dataobj.type) then tercio@0: return tercio@0: end tercio@0: if (dataobj.icon and dataobj.OnClick) then tercio@0: LibHotCorners:RegisterHotCornerButton (name, "TopLeft", nil, name .. "HotCornerLauncher", dataobj.icon, dataobj.OnTooltipShow, dataobj.OnClick, nil, nil, dataobj.OnEnter, dataobj.OnLeave) tercio@0: end tercio@0: end tercio@0: LBD.RegisterCallback (LibHotCorners, "DataBrokerCallback") tercio@0: tercio@0: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@0: --> scripts tercio@0: tercio@0: --> background (window mode fix) tercio@0: function HotCornersBackgroundOnEnter (self) tercio@0: if (LibHotCornersTopLeft and LibHotCornersTopLeft:IsShown()) then tercio@0: if (LibHotCornersTopLeft:GetWidth() > 2) then tercio@2: HotCornersOnLeave (LibHotCornersTopLeft, true) tercio@0: end tercio@0: end tercio@0: self:EnableMouse (false) tercio@0: end tercio@0: tercio@0: --> set size tercio@0: local function set_size (self) tercio@0: if (self.position == "topleft" or self.position == "topright") then tercio@0: self:SetSize (40, GetScreenHeight()) tercio@0: else tercio@0: self:SetSize (GetScreenWidth(), 40) tercio@0: end tercio@0: end tercio@0: tercio@0: --> show tooltip tercio@0: local show_tooltip = function (self) tercio@2: if (self.table and self.table.tooltip) then tercio@0: if (type (self.table.tooltip) == "function") then tercio@0: GameTooltip:SetOwner (self, "ANCHOR_RIGHT") tercio@0: self.table.tooltip (GameTooltip) tercio@0: GameTooltip:Show() tercio@0: elseif (type (self.table.tooltip) == "string") then tercio@0: GameTooltip:SetOwner (self, "ANCHOR_RIGHT") tercio@0: GameTooltip:AddLine (self.table.tooltip) tercio@0: GameTooltip:Show() tercio@0: end tercio@2: elseif (self.table and self.table.onenter) then tercio@0: self.table.onenter (self) tercio@2: elseif (self.isItem) then tercio@2: GameTooltip:SetOwner (self, "ANCHOR_BOTTOMRIGHT") tercio@2: GameTooltip:SetHyperlink (self.itemtable[4]) tercio@2: GameTooltip:Show() tercio@0: end tercio@0: end tercio@0: tercio@0: --> corner frame on enter tercio@0: local more_clicked = function (t1, t2) tercio@0: return t1[1] > t2[1] tercio@0: end tercio@0: tercio@2: LibHotCorners.BackPackItemList = { tercio@2: tercio@2: --> alchemy Tercio@7: Tercio@7: --MOP tercio@2: [76086] = true, -- Flask of Falling Leaves tercio@2: [76084] = true, -- Flask of Spring Blossoms tercio@2: [76085] = true, -- Flask of the Warm Sun tercio@2: [76087] = true, -- Flask of the Earth tercio@2: [76088] = true, -- Flask of Winter's Bite tercio@2: tercio@2: [76081] = true, -- Elixir of Mirrors tercio@2: [76079] = true, -- Elixir of Peace tercio@2: [76080] = true, -- Elixir of Perfection tercio@2: [76078] = true, -- Elixir of the Rapids tercio@2: [76077] = true, -- Elixir of Weaponry tercio@2: [70676] = true, -- Mad Hozen Elixir tercio@2: [76075] = true, -- Mantid Elixir tercio@2: [76083] = true, -- Monk's Elixir tercio@2: tercio@2: [76094] = true, -- Alchemist's Rejuvenation tercio@2: [96096] = true, -- Darkwater Potion tercio@2: [75218] = true, -- Electrified Oil tercio@2: [76097] = true, -- Master Healing Potion tercio@2: [76098] = true, -- Master Mana Potion tercio@2: [76092] = true, -- Potion of Focus tercio@2: [76093] = true, -- Potion of the Jade Serpent tercio@2: [76095] = true, -- Potion of Mogu Power tercio@2: [76090] = true, -- Potion of the Mountains tercio@2: [76091] = true, -- Greater Potion of Luck tercio@2: [76089] = true, -- Virmen's Bite Tercio@7: Tercio@7: --WOD Tercio@7: [118704] = true, --Pure Rage Potion Tercio@7: [109156] = true, --Greater Draenic Strength Flask Tercio@7: [109160] = true, --Greater Draenic Stamina Flask Tercio@7: [109155] = true, --Greater Draenic Intellect Flask Tercio@7: [109153] = true, --Greater Draenic Agility Flask Tercio@7: [118711] = true, --Draenic Water Walking Elixir Tercio@7: [116271] = true, --Draenic Water Breathing Elixir Tercio@7: [116266] = true, --Draenic Swiftness Potion Tercio@7: [109219] = true, --Draenic Strength Potion Tercio@7: [109148] = true, --Draenic Strength Flask Tercio@7: [109152] = true, --Draenic Stamina Flask Tercio@7: [109226] = true, --Draenic Rejuvenation Potion Tercio@7: [109222] = true, --Draenic Mana Potion Tercio@7: [116276] = true, --Draenic Living Action Potion Tercio@7: [116268] = true, --Draenic Invisibility Potion Tercio@7: [109218] = true, --Draenic Intellect Potion Tercio@7: [109147] = true, --Draenic Intellect Flask Tercio@7: [109221] = true, --Draenic Channeled Mana Potion Tercio@7: [109220] = true, --Draenic Armor Potion Tercio@7: [109217] = true, --Draenic Agility Potion Tercio@7: [109145] = true, --Draenic Agility Flask Tercio@7: [112090] = true, --Transmorphic Tincture Tercio@7: tercio@2: --> cooking Tercio@7: --WOD Tercio@7: [111449] = true, --Blackrock Barbecue Tercio@7: [111433] = true, --Blackrock Ham Tercio@7: [111436] = true, --Braised Riverbeast Tercio@7: [122348] = true, --Buttered Sturgeon Tercio@7: [111453] = true, --Calamari Crepes Tercio@7: [111438] = true, --Clefthoof Sausages Tercio@7: [126935] = true, --Fancy Darkmoon Feast Tercio@7: [111444] = true, --Fat Sleeper Cakes Tercio@7: [111457] = true, --Feast of Blood Tercio@7: [111458] = true, --Feast of the Waters Tercio@7: [111445] = true, --Fiery Calamari Tercio@7: [111450] = true, --Frosty Stew Tercio@7: [111454] = true, --Gorgrond Chowder Tercio@7: [111441] = true, --Grilled Gulper Tercio@7: [111456] = true, --Grilled Saberfish Tercio@7: [111431] = true, --Hearty Elekk Steak Tercio@7: [122346] = true, --Jumbo Sea Dog Tercio@7: [126934] = true, --Lemon Herb Filet Tercio@7: [111434] = true, --Pan-Seared Talbuk Tercio@7: [122345] = true, --Pickled Eel Tercio@7: [111437] = true, --Rylak Crepes Tercio@7: [111455] = true, --Saberfish Broth Tercio@7: [122344] = true, --Salty Squid Roll Tercio@7: [111446] = true, --Skulker Chowder Tercio@7: [111452] = true, --Sleeper Surprise Tercio@7: [122343] = true, --Sleeper Sushi Tercio@7: [111439] = true, --Steamed Scorpion Tercio@7: [111442] = true, --Sturgeon Stew Tercio@7: [126936] = true, --Sugar-Crusted Fish Feast Tercio@7: [111447] = true, --Talador Surf and Turf Tercio@7: [122347] = true, --Whiptail Fillet Tercio@7: --[] = true, -- Tercio@7: --MOP Tercio@7: --Way of the Grill: Strength tercio@2: [74642] = true, -- Charbroiled Tiger Steak tercio@2: [74645] = true, -- Eternal Blossom Fish tercio@2: [74646] = true, -- Black Pepper Ribs and Shrimp tercio@2: tercio@2: --Way of the Oven: Stamina tercio@2: [74654] = true, -- Wildfowl Roast tercio@2: [74655] = true, -- Twin Fish Platter tercio@2: [74656] = true, -- Chun Tian Spring Rolls tercio@2: tercio@2: --Way of the Pot: Intellect tercio@2: tercio@2: [74644] = true, -- Swirling Mist Soup tercio@2: [74649] = true, -- Braised Turtle tercio@2: [74650] = true, -- Mogu Fish Stew tercio@2: tercio@2: --Way of the Steamer: Spirit tercio@2: tercio@2: [74651] = true, -- Shrimp Dumplings tercio@2: [74652] = true, -- Fire Spirit Salmon tercio@2: [74653] = true, -- Steamed Crab Surprise tercio@2: tercio@2: --Way of the Wok: Agility tercio@2: tercio@2: [74643] = true, -- Sauteed Carrots tercio@2: [74647] = true, -- Valley Stir Fry tercio@2: [74648] = true, -- Sea Mist Rice Noodles tercio@2: tercio@2: --Way of the Brew: Headaches and Grandeur tercio@2: tercio@2: [74626] = true, -- Ginseng Tea tercio@2: [74637] = true, -- Jade Witch Brew tercio@2: [74638] = true, -- Mad Brewer's Breakfast tercio@2: tercio@2: --General Cooking tercio@2: tercio@2: [74641] = true, -- Fish Cake tercio@2: [74636] = true, -- Golden Carp Consomme tercio@2: [86070] = true, -- Wildfowl Ginseng Soup tercio@2: [86069] = true, -- Rice Pudding tercio@2: [86074] = true, -- Spicy Vegetable Chips tercio@2: [86073] = true, -- Spicy Salmon tercio@2: tercio@2: --5.4 Recipes tercio@2: tercio@2: [145308] = true, -- Mango Ice tercio@2: [145309] = true, -- Farmer's Delight tercio@2: [145311] = true, -- Fluffy Silkfeather Omelet tercio@2: [145310] = true, -- Stuffed Lushrooms tercio@2: [145307] = true, -- Spiced Blossom Soup tercio@2: [145305] = true, -- Seasoned Pomfruit Slices tercio@2: tercio@2: --Cart Kits tercio@2: [101630] = true, -- Noodle Cart Kit tercio@2: [101661] = true, -- Deluxe Noodle Cart Kit tercio@2: [101662] = true, -- Pandaren Treasure Noodle Cart Kit tercio@2: tercio@2: [101618] = true, -- Pandaren Treasure Noodle Soup tercio@2: [101617] = true, -- Deluxe Noodle Soup tercio@2: [101616] = true, -- Noodle Soup tercio@2: } tercio@2: tercio@0: function HotCornersOnEnter (self) tercio@0: tercio@0: if (not LibHotCorners.db.profile.is_enabled) then tercio@0: return tercio@0: end tercio@0: tercio@0: if (not LibHotCorners.db.profile [self.position .. "_enabled"]) then tercio@0: return tercio@0: end tercio@0: tercio@2: if (self:GetWidth() < 1.1 and self:GetHeight() < 1.1) then tercio@2: --print ("abrindo...") tercio@2: end tercio@2: tercio@0: set_size (self) tercio@0: tercio@0: HotCornersBackgroundFrame:EnableMouse (true) tercio@2: self.item_frame:Show() tercio@0: tercio@0: local i = 1 tercio@0: tercio@0: local sort = {} tercio@0: local clicks = LibHotCorners.db.profile.clicks tercio@0: for index, button_table in ipairs (LibHotCorners [self.position]) do tercio@0: tinsert (sort, {clicks [button_table.name] or 0, button_table}) tercio@0: end tercio@0: table.sort (sort, more_clicked) tercio@0: tercio@0: local last_button tercio@0: tercio@0: local disabled = LibHotCorners.db.profile.disabled tercio@0: tercio@0: for index, button_table in ipairs (sort) do tercio@0: button_table = button_table [2] tercio@0: if (not button_table.widget) then tercio@0: LibHotCorners:CreateAddonWidget (self, button_table, index, self.position) tercio@0: end tercio@0: tercio@0: button_table.widget:ClearAllPoints() tercio@0: tercio@1: if (not disabled [button_table.name] and not button_table.optionstable.hide) then tercio@0: if (self.position == "topleft" or self.position == "topright") then tercio@2: tercio@0: local y = i * 35 * -1 tercio@2: --button_table.widget:SetPoint ("topleft", self, "topleft", 4, y) tercio@0: button_table.widget.y = y tercio@2: HotCornersStartAnimOnShow (button_table.widget, "y") tercio@2: tercio@2: else --bottom left / bottom right tercio@0: local x = i * 35 tercio@0: button_table.widget:SetPoint ("topleft", self, "topleft", x, -4) tercio@0: button_table.widget.x = x tercio@0: end tercio@0: tercio@0: button_table.widget:Show() tercio@0: last_button = button_table.widget tercio@0: tercio@0: i = i + 1 tercio@0: else tercio@0: button_table.widget:Hide() tercio@0: end tercio@0: end tercio@0: tercio@0: local OptionsButton = LibHotCorners [self.position].optionsbutton tercio@0: local y = i * 35 * -1 tercio@0: OptionsButton:SetPoint ("top", self, "top", 0, y) tercio@0: OptionsButton:Show() tercio@0: tercio@2: --item frame tercio@2: LibHotCorners:RefereshItems (self) tercio@2: tercio@3: self.AnimOnShow:Play() tercio@3: HotCornersInfosFrame:Show() tercio@3: HotCornersInfosFrame:SetAlpha (0) tercio@3: HotCornersInfosFrame.AnimOnShow:Play() tercio@3: tercio@3: --update repair tercio@3: local percent, items = 0, 0 tercio@3: for i = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do tercio@3: local durability, maxdurability = GetInventoryItemDurability (i) tercio@3: if (durability and maxdurability) then tercio@3: local p = durability / maxdurability * 100 tercio@3: percent = percent + p tercio@3: items = items + 1 tercio@3: end tercio@3: end tercio@3: tercio@3: if (items == 0) then tercio@3: HotCornersInfosFrame.repairText:SetText ("-- %") tercio@3: end tercio@3: tercio@3: percent = percent / items tercio@3: HotCornersInfosFrame.repairText:SetText (math.floor (percent) .. "%") tercio@3: tercio@3: --update date tercio@3: HotCornersInfosFrame.clockText:SetText (date ("%H:%M")) tercio@3: HotCornersInfosFrame.dayText:SetText (date ("%A\n%B %d")) tercio@3: tercio@3: --update money tercio@3: local money = GetMoney() tercio@3: HotCornersInfosFrame.goldText:SetText (math.floor (money / 100 / 100)) tercio@3: HotCornersInfosFrame.silverText:SetText (math.floor ((money / 100) % 100)) tercio@3: HotCornersInfosFrame.bronzeText:SetText (math.floor (money % 100)) tercio@3: tercio@3: --HotCornersInfosFrame.clockText:SetText (date ("%A %B %d %H:%M:%S %Y")) tercio@3: tercio@0: end tercio@0: tercio@2: function LibHotCorners:RefereshItems (self) tercio@2: Tercio@7: if (HotCornersItemUsed and LibHotCorners.LastItemButtonClick < GetTime() and not self) then Tercio@7: for _, button in pairs (LibHotCorners.ItemButtons) do Tercio@7: if (not button.itemtable[6]) then --> isn't a profession cooldown Tercio@7: button.cooldown:SetCooldown (GetTime(), 1.5) Tercio@7: end Tercio@7: end Tercio@7: HotCornersItemUsed = nil Tercio@7: LibHotCorners.LastItemButtonClick = GetTime()+1.5 Tercio@7: end Tercio@7: tercio@2: if (not self) then tercio@2: return LibHotCorners:ScheduleTimer ("RefereshItems", 1, LibHotCornersTopLeft) tercio@2: end tercio@2: tercio@2: if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then tercio@2: for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do tercio@2: itemTable [1] = 0 tercio@2: end tercio@2: tercio@2: for bagID = 0, 4 do tercio@2: local numItems = GetContainerNumSlots (bagID) tercio@2: for slot = 1, numItems do tercio@2: local itemId = GetContainerItemID (bagID, slot) tercio@2: if (LibHotCorners.BackPackItemList [itemId]) then tercio@2: local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo (bagID, slot) tercio@2: if (not LibHotCorners.ItemOnInventory [itemId]) then tercio@2: LibHotCorners.ItemOnInventory [itemId] = {itemCount, texture, quality, itemLink, itemId} tercio@2: else tercio@2: LibHotCorners.ItemOnInventory [itemId] [1] = LibHotCorners.ItemOnInventory [itemId] [1] + itemCount tercio@2: end tercio@2: end tercio@2: end tercio@2: end tercio@2: tercio@2: local index = 1 tercio@2: for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do tercio@2: local itemCount, texture, quality, itemLink = unpack (itemTable) tercio@2: tercio@2: local item_button = LibHotCorners:GetItemButton (index, self) tercio@2: if (item_button) then tercio@2: item_button:SetNormalTexture (texture) tercio@2: item_button:SetHighlightTexture (texture) tercio@2: item_button:SetPushedTexture (texture) tercio@2: tercio@2: item_button.item_count:SetText (itemCount or 0) Tercio@7: item_button:SetAttribute ("macrotext", "/use " .. GetItemInfo (itemId) .. ";\n/script HotCornersItemUsed=GetTime(); HotCorners:RefereshItems()") tercio@2: tercio@2: item_button.itemtable = itemTable tercio@2: tercio@2: if (not item_button:IsShown() or item_button:GetAlpha() < 1) then tercio@2: HotCornersStartAnimOnShow (item_button, "item_topleft") tercio@2: end tercio@2: end Tercio@7: index = index + 1 tercio@2: end Tercio@7: Tercio@7: LibHotCorners:RefereshProfessions (self, index) tercio@2: tercio@2: end tercio@2: --/run local itemid=GetContainerItemID (0, 1);print (itemid) tercio@2: --UseContainerItem(bagID, slot[, onSelf]) Tercio@7: end Tercio@7: Tercio@7: local get_profession = function (icon) Tercio@7: if (icon:find ("Trade_Engineering")) then Tercio@7: return "en" Tercio@7: elseif (icon:find ("Trade_LeatherWorking")) then Tercio@7: return "lw" Tercio@7: elseif (icon:find ("Trade_Tailoring")) then Tercio@7: return "tl" Tercio@7: elseif (icon:find ("Trade_Engraving")) then Tercio@7: return "ec" Tercio@7: elseif (icon:find ("Trade_BlackSmithing")) then Tercio@7: return "bs" Tercio@7: elseif (icon:find ("Trade_Alchemy")) then Tercio@7: return "al" Tercio@7: elseif (icon:find ("INV_Misc_Gem_01")) then Tercio@7: return "jc" Tercio@7: elseif (icon:find ("INV_Inscription_Tradeskill01")) then Tercio@7: return "in" Tercio@7: end Tercio@7: end Tercio@7: local secrets_index = { Tercio@7: ["tl"] = 176058, --tailoring Tercio@7: ["ec"] = 177043, --enchanting Tercio@7: ["lw"] = 176089, --letherwork Tercio@7: ["en"] = 177054, --engeener Tercio@7: ["bs"] = 176090, --blacksmith Tercio@7: ["al"] = 175880, --alchemy Tercio@7: ["jc"] = 176087, --jewelcraft Tercio@7: ["in"] = 177045, --inscription Tercio@7: } Tercio@7: local secrets_icons = { Tercio@7: ["tl"] = "inv_misc_book_03", --tailoring Tercio@7: ["ec"] = "inv_misc_book_08", --enchant Tercio@7: ["al"] = "inv_misc_book_08", -- alchemy Tercio@7: ["bs"] = "inv_misc_book_11", --bs Tercio@7: ["en"] = "inv_misc_book_08", --engeener Tercio@7: ["in"] = "inv_misc_book_08", --inscritp Tercio@7: ["jc"] = "inv_misc_book_10", --jc Tercio@7: ["lw"] = "inv_misc_book_09", --lw Tercio@7: } Tercio@7: Tercio@7: function LibHotCorners:RefereshProfessions (self, index) Tercio@7: Tercio@7: index = index + 1 Tercio@7: Tercio@7: local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions() Tercio@7: Tercio@7: if (prof1) then Tercio@7: local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier, specializationIndex, specializationOffset = GetProfessionInfo (prof1) Tercio@7: local prof = get_profession (icon) Tercio@7: local secrets_spellID = secrets_index [prof] Tercio@7: if (secrets_spellID) then Tercio@7: local name, _, texture = GetSpellInfo (secrets_spellID) Tercio@7: texture = "Interface\\Icons\\" .. secrets_icons [prof] Tercio@7: local item_button = LibHotCorners:GetItemButton (index, self) Tercio@7: if (item_button) then Tercio@7: item_button:SetNormalTexture (texture) Tercio@7: item_button:SetHighlightTexture (texture) Tercio@7: item_button:SetPushedTexture (texture) Tercio@7: Tercio@7: item_button:SetAttribute ("macrotext", "/cast " .. name .. ";\n/script HotCornersItemUsed=GetTime(); HotCorners:RefereshItems()") Tercio@7: Tercio@7: item_button.itemtable = {false, false, false, GetSpellLink (secrets_spellID), false, true} Tercio@7: Tercio@7: local start, duration = GetSpellCooldown (secrets_spellID) Tercio@7: if (start and start > 0) then Tercio@7: item_button.cooldown:SetCooldown (start, duration) Tercio@7: else Tercio@7: item_button.item_count:SetText (1) Tercio@7: end Tercio@7: Tercio@7: if (not item_button:IsShown() or item_button:GetAlpha() < 1) then Tercio@7: HotCornersStartAnimOnShow (item_button, "item_topleft") Tercio@7: end Tercio@7: end Tercio@7: index = index + 1 Tercio@7: end Tercio@7: end Tercio@7: Tercio@7: if (prof2) then Tercio@7: local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier, specializationIndex, specializationOffset = GetProfessionInfo (prof2) Tercio@7: local prof = get_profession (icon) Tercio@7: local secrets_spellID = secrets_index [prof] Tercio@7: if (secrets_spellID) then Tercio@7: local name, _, texture = GetSpellInfo (secrets_spellID) Tercio@7: texture = "Interface\\Icons\\" .. secrets_icons [prof] Tercio@7: local item_button = LibHotCorners:GetItemButton (index, self) Tercio@7: if (item_button) then Tercio@7: item_button:SetNormalTexture (texture) Tercio@7: item_button:SetHighlightTexture (texture) Tercio@7: item_button:SetPushedTexture (texture) Tercio@7: Tercio@7: item_button:SetAttribute ("macrotext", "/cast " .. name .. ";\n/script HotCornersItemUsed=GetTime(); HotCorners:RefereshItems()") Tercio@7: Tercio@7: item_button.itemtable = {false, false, false, GetSpellLink (secrets_spellID), false, true} Tercio@7: Tercio@7: local start, duration = GetSpellCooldown (secrets_spellID) Tercio@7: if (start and start > 0) then Tercio@7: item_button.cooldown:SetCooldown (start, duration) Tercio@7: else Tercio@7: item_button.item_count:SetText (1) Tercio@7: end Tercio@7: Tercio@7: if (not item_button:IsShown() or item_button:GetAlpha() < 1) then Tercio@7: HotCornersStartAnimOnShow (item_button, "item_topleft") Tercio@7: end Tercio@7: end Tercio@7: index = index + 1 Tercio@7: end Tercio@7: end Tercio@7: Tercio@7: end tercio@2: tercio@2: function LibHotCorners:GetItemButton (index, parent) tercio@2: local button = LibHotCorners.ItemButtons [index] tercio@2: if (not button) then tercio@2: button = CreateFrame ("button", "HotCornersItemButton" .. index, parent.item_frame, "HotCornersUseItemButtonTemplate") tercio@2: button.isItem = true tercio@2: tercio@2: if (parent.position == "topleft") then tercio@2: local x = (index-1) * 33 tercio@2: button:SetPoint ("topleft", parent.item_frame, "topleft", x, -2) tercio@2: button.x = x tercio@2: elseif (parent.position == "topright") then tercio@2: local x = (index-1) * 33 tercio@2: button:SetPoint ("topright", parent.item_frame, "topright", -x, -2) tercio@2: end tercio@2: tercio@2: LibHotCorners.ItemButtons [index] = button tercio@2: end tercio@2: return button tercio@2: end tercio@2: tercio@0: --> corner frame on leave tercio@2: function HotCornersOnLeave (self, from_background) tercio@2: if (not from_background) then tercio@2: return tercio@2: end tercio@2: tercio@0: self:SetSize (1, 1) tercio@0: for index, button_table in ipairs (LibHotCorners [self.position]) do tercio@1: if (button_table.widget) then tercio@1: button_table.widget:Hide() tercio@1: end tercio@0: end tercio@2: for _, button in pairs (LibHotCorners.ItemButtons) do tercio@2: button:Hide() tercio@2: end tercio@2: tercio@0: local OptionsButton = LibHotCorners [self.position].optionsbutton tercio@0: OptionsButton:Hide() tercio@2: tercio@2: self.item_frame:Hide() tercio@3: HotCornersInfosFrame:Hide() tercio@0: end tercio@0: tercio@0: --> quick corner on click tercio@0: function HotCornersOnQuickClick (self, button) tercio@0: local parent_position = self:GetParent().position tercio@1: local func = LibHotCorners.QuickFunctions [parent_position] tercio@1: if (func) then tercio@1: func (self, button) tercio@0: end tercio@0: end tercio@0: tercio@0: --> options button onenter tercio@0: function HotCornersOptionsButtonOnEnter (self) tercio@0: set_size (self:GetParent()) tercio@0: for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do tercio@0: if (not LibHotCorners.db.profile.disabled [button_table.name]) then tercio@0: button_table.widget:Show() tercio@0: end tercio@0: end tercio@0: self:Show() tercio@0: end tercio@0: tercio@0: function HotCornersOpenOptions (self) tercio@0: InterfaceOptionsFrame_OpenToCategory ("HotCorners") tercio@0: InterfaceOptionsFrame_OpenToCategory ("HotCorners") tercio@0: end tercio@0: tercio@0: function HotCornersSetEnabled (state) tercio@0: LibHotCorners.db.profile.is_enabled = state tercio@0: end tercio@0: tercio@0: --> options button onleave tercio@0: function HotCornersOptionsButtonOnLeave (self) tercio@0: self:GetParent():GetScript("OnLeave")(self:GetParent()) tercio@0: end tercio@0: tercio@0: --> button onenter tercio@0: function HotCornersButtonOnEnter (self) tercio@2: --set_size (self:GetParent()) tercio@2: --for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do tercio@2: -- if (not LibHotCorners.db.profile.disabled [button_table.name] and button_table.widget) then tercio@2: -- button_table.widget:Show() tercio@2: -- end tercio@2: --end tercio@0: show_tooltip (self) tercio@2: --local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton tercio@2: --OptionsButton:Show() tercio@0: end tercio@0: tercio@0: --> button onleave tercio@0: function HotCornersButtonOnLeave (self) tercio@0: GameTooltip:Hide() tercio@2: if (self.table and self.table.onleave) then tercio@0: self.table.onleave (self) tercio@0: end tercio@2: --self:GetParent():GetScript("OnLeave")(self:GetParent()) tercio@2: --local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton tercio@2: --OptionsButton:Hide() tercio@0: end tercio@0: tercio@0: --> button onmousedown tercio@0: function HotCornersButtonOnMouseDown (self, button) tercio@2: if (self.isItem) then tercio@2: if (self:GetParent():GetParent().position == "topleft") then tercio@2: self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -3) tercio@2: end tercio@0: else tercio@2: if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then tercio@2: self:SetPoint ("topleft", self:GetParent(), "topleft", 5, self.y - 1) tercio@2: else tercio@2: self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -6) tercio@2: end tercio@0: end tercio@0: end tercio@0: tercio@0: --> button onmouseup tercio@0: function HotCornersButtonOnMouseUp (self, button) tercio@2: if (self.isItem) then tercio@2: if (self:GetParent():GetParent().position == "topleft") then tercio@2: self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -2) tercio@2: end tercio@0: else tercio@2: if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then tercio@2: self:SetPoint ("topleft", self:GetParent(), "topleft", 4, self.y) tercio@2: else tercio@2: self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -4) tercio@2: end tercio@2: if (self.table.click) then tercio@2: local clicks = LibHotCorners.db.profile.clicks tercio@2: clicks [self.table.name] = clicks [self.table.name] or 0 tercio@2: clicks [self.table.name] = clicks [self.table.name] + 1 tercio@2: self.table.click (self, button) tercio@2: end tercio@0: end tercio@2: end tercio@2: tercio@2: --> start show animation tercio@2: function HotCornersStartAnimOnShow (button, axis) tercio@2: if (axis == "y") then tercio@2: --button:SetPoint ("topleft", button:GetParent(), "topleft", -32, button.y) tercio@2: button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y) tercio@2: button.AnimOnShow:Play() tercio@2: tercio@2: elseif (axis == "item_topleft") then tercio@2: button:Show() tercio@2: button.AnimOnShow:Play() tercio@2: tercio@0: end tercio@0: end tercio@2: tercio@2: --> on start / finish show animation tercio@2: function HotCornersAnimOnShowStarted (button) tercio@2: tercio@2: end tercio@2: function HotCornersAnimOnShowFinished (button) tercio@2: --button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y) tercio@2: button:Show() tercio@2: --button:SetPoint ("topleft", button:GetParent(), "topleft", -4, button.y) tercio@2: end tercio@0: tercio@0: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@0: --> create top left corner tercio@0: tercio@0: local TopLeftCorner = CreateFrame ("Frame", "LibHotCornersTopLeft", nil, "HotCornersFrameCornerTemplate") tercio@0: TopLeftCorner:SetPoint ("topleft", UIParent, "topleft", 0, 0) tercio@0: TopLeftCorner.position = "topleft" tercio@0: tercio@0: --fast corner button tercio@0: local QuickClickButton = CreateFrame ("button", "LibHotCornersTopLeftFastButton", TopLeftCorner, "HotCornersQuickCornerButtonTemplate") tercio@0: tercio@0: --options button tercio@0: local OptionsButton = CreateFrame ("button", "LibHotCornersTopLeftOptionsButton", TopLeftCorner, "HotCornersOptionsButtonTemplate") tercio@0: tercio@0: if (debug) then tercio@0: QuickClickButton:SetSize (20, 20) tercio@0: QuickClickButton:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]], tile = true, tileSize = 40}) tercio@0: QuickClickButton:SetBackdropColor (1, 0, 0, 1) tercio@0: end tercio@0: tercio@0: LibHotCorners.topleft.quickbutton = QuickClickButton tercio@0: LibHotCorners.topleft.optionsbutton = OptionsButton tercio@0: tercio@0: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@0: --> buttons tercio@0: tercio@0: function LibHotCorners:CreateAddonWidget (frame, button_table, index, side) tercio@0: tercio@0: --> create the button tercio@0: local button = CreateFrame ("button", "LibHotCorners" .. side .. button_table.fname, frame, "HotCornersButtonTemplate") tercio@0: tercio@0: --> write some attributes tercio@0: button.index = index tercio@0: button.table = button_table tercio@0: button.parent = frame tercio@0: button_table.widget = button tercio@0: tercio@0: --> set the icon tercio@0: button:SetNormalTexture (button_table.icon) tercio@0: button:SetHighlightTexture (button_table.icon) tercio@0: tercio@0: if (string.lower (button_table.icon):find ([[\icons\]])) then tercio@0: button:GetNormalTexture():SetTexCoord (0.078125, 0.9375, 0.078125, 0.9375) tercio@0: button:GetHighlightTexture():SetTexCoord (0.078125, 0.9375, 0.078125, 0.9375) tercio@0: end tercio@0: tercio@0: return button tercio@0: end