tercio@0: tercio@0: LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") 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@0: quickfunc = false, tercio@0: clicks = {}, tercio@0: disabled = {} tercio@0: }, tercio@0: } tercio@0: 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@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@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: "QuickHotCornerEnable" 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@0: function LibHotCorners:RegisterHotCornerButton (name, corner, savedtable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install) tercio@0: corner = string.lower (corner) tercio@0: test (corner) tercio@0: 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@0: table.insert (LibHotCorners [corner], i, {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true}) tercio@0: return LibHotCorners [corner].map [name] tercio@0: end tercio@0: end tercio@0: tercio@0: table.insert (LibHotCorners [corner], {name = name, fname = fname, savedtable = savedtable, 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@0: return LibHotCorners [corner].map [name] tercio@0: else tercio@0: tinsert (LibHotCorners [corner], {name = name, fname = fname, savedtable = savedtable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave}) tercio@0: LibHotCorners [corner].map [name] = #LibHotCorners [corner] tercio@0: return LibHotCorners [corner].map [name] tercio@0: end tercio@0: end tercio@0: tercio@0: function LibHotCorners:QuickHotCornerEnable (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@0: addon_table.savedtable [corner .. "_quickclick"] = value tercio@0: tercio@0: if (value and addon_table.quickfunc) then tercio@0: corner_table.quickfunc = addon_table.quickfunc tercio@0: else tercio@0: local got = false tercio@0: for index, button_table in ipairs (corner_table) do tercio@0: if (button_table.savedtable.quickclick) then tercio@0: corner_table.quickfunc = button_table.quickfunc tercio@0: got = true tercio@0: break tercio@0: end tercio@0: end tercio@0: tercio@0: if (not got) then tercio@0: corner_table.quickfunc = nil tercio@0: end 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@0: addon_table.savedtable.hide = value tercio@0: tercio@0: --print (LibHotCorners, corner) tercio@0: LibHotCorners [corner].is_enabled = false tercio@0: tercio@0: for index, button_table in ipairs (corner_table) do tercio@0: if (not button_table.savedtable.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@0: HotCornersOnLeave (LibHotCornersTopLeft) 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@0: if (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@0: elseif (self.table.onenter) then tercio@0: self.table.onenter (self) 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@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@0: set_size (self) tercio@0: tercio@0: HotCornersBackgroundFrame:EnableMouse (true) 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@0: if (not disabled [button_table.name]) then tercio@0: if (self.position == "topleft" or self.position == "topright") then tercio@0: local y = i * 35 * -1 tercio@0: button_table.widget:SetPoint ("topleft", self, "topleft", 4, y) tercio@0: button_table.widget.y = y tercio@0: else 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@0: end tercio@0: tercio@0: --> corner frame on leave tercio@0: function HotCornersOnLeave (self) tercio@0: self:SetSize (1, 1) tercio@0: for index, button_table in ipairs (LibHotCorners [self.position]) do tercio@0: button_table.widget:Hide() tercio@0: end tercio@0: local OptionsButton = LibHotCorners [self.position].optionsbutton tercio@0: OptionsButton: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@0: if (LibHotCorners [parent_position].quickfunc) then tercio@0: LibHotCorners [parent_position].quickfunc (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@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: show_tooltip (self) tercio@0: local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton tercio@0: OptionsButton:Show() tercio@0: end tercio@0: tercio@0: --> button onleave tercio@0: function HotCornersButtonOnLeave (self) tercio@0: GameTooltip:Hide() tercio@0: if (self.table.onleave) then tercio@0: self.table.onleave (self) tercio@0: end tercio@0: self:GetParent():GetScript("OnLeave")(self:GetParent()) tercio@0: local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton tercio@0: OptionsButton:Hide() tercio@0: end tercio@0: tercio@0: --> button onmousedown tercio@0: function HotCornersButtonOnMouseDown (self, button) tercio@0: if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then tercio@0: self:SetPoint ("topleft", self:GetParent(), "topleft", 5, self.y - 1) tercio@0: else tercio@0: self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -6) tercio@0: end tercio@0: end tercio@0: tercio@0: --> button onmouseup tercio@0: function HotCornersButtonOnMouseUp (self, button) tercio@0: if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then tercio@0: self:SetPoint ("topleft", self:GetParent(), "topleft", 4, self.y) tercio@0: else tercio@0: self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -4) tercio@0: end tercio@0: if (self.table.click) then tercio@0: local clicks = LibHotCorners.db.profile.clicks tercio@0: clicks [self.table.name] = clicks [self.table.name] or 0 tercio@0: clicks [self.table.name] = clicks [self.table.name] + 1 tercio@0: self.table.click (self, button) tercio@0: end tercio@0: 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