diff --git a/Bartender4.toc b/Bartender4.toc index 10c4622..8a7a1b1 100644 --- a/Bartender4.toc +++ b/Bartender4.toc @@ -20,7 +20,6 @@ ButtonStyle.lua Bar.lua ButtonBar.lua Button.lua -PetButton.xml ## Modules ## ActionBars.lua diff --git a/Options.lua b/Options.lua index 6c4ef4c..e53ed1a 100644 --- a/Options.lua +++ b/Options.lua @@ -14,108 +14,6 @@ do end end -local getProfilesOptionsTable -do - local defaultProfiles - --[[ Utility functions ]] - -- get exisiting profiles + some default entries - local tmpprofiles = {} - local function getProfileList(db, common, nocurrent) - -- clear old profile table - local profiles = {} - - -- copy existing profiles into the table - local curr = db:GetCurrentProfile() - for i,v in pairs(db:GetProfiles(tmpprofiles)) do if not (nocurrent and v == curr) then profiles[v] = v end end - - -- add our default profiles to choose from - for k,v in pairs(defaultProfiles) do - if (common or profiles[k]) and not (k == curr and nocurrent) then - profiles[k] = v - end - end - return profiles - end - - function getProfilesOptionsTable(db) - defaultProfiles = { - ["Default"] = "Default", - [db.keys.char] = "Char: " .. db.keys.char, - [db.keys.realm] = "Realm: " .. db.keys.realm, - [db.keys.class] = "Class: " .. UnitClass("player") - } - - local tbl = { - profiles = { - type = "group", - name = "Profiles", - desc = "Manage Profiles", - args = { - reset = { - order = 1, - type = "execute", - name = "Reset Profile", - desc = "Reset the current profile to the default", - func = function() db:ResetProfile() end, - }, - spacer1 = { - order = 2, - type = "header", - name = "Choose a Profile", - desc = "Set the active profile of this character.", - }, - new = { - name = "New", - type = "input", - order = 3, - get = function() return false end, - set = function(info, value) db:SetProfile(value) end, - }, - choose = { - name = "Current", - type = "select", - order = 4, - get = function() return db:GetCurrentProfile() end, - set = function(info, value) db:SetProfile(value) end, - values = function() return getProfileList(db, true) end, - }, - spacer2 = { - type = "header", - order = 5, - name = "Copy a Profile", - }, - copyfrom = { - order = 6, - type = "select", - name = "Copy From", - desc = "Copy the settings from another profile", - get = function() return false end, - set = function(info, value) db:CopyProfile(value) end, - values = function() return getProfileList(db, nil, true) end, - }, - spacer3 = { - type = "header", - order = 7, - name = "Delete a Profile", - }, - delete = { - order = 8, - type = "select", - name = "Delete a Profile", - desc = "Deletes a profile from the database.", - get = function() return false end, - set = function(info, value) db:DeleteProfile(value) end, - values = function() return getProfileList(db, nil, true) end, - confirm = true, - confirmText = "Are you sure you want to delete the selected profile?", - }, - }, - }, - } - return tbl - end -end - function Bartender4:SetupOptions() self.options = { type = "group", @@ -143,7 +41,7 @@ function Bartender4:SetupOptions() }, } - self.options.plugins.profiles = getProfilesOptionsTable(Bartender4.db) + self.options.plugins.profiles = { profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) } LibStub("AceConfig-3.0"):RegisterOptionsTable("Bartender4", self.options, "bttest") diff --git a/PetBar.lua b/PetBar.lua index f2335a0..9dc17e2 100644 --- a/PetBar.lua +++ b/PetBar.lua @@ -33,11 +33,25 @@ function PetBarMod:OnEnable() end self.bar.buttons = buttons + -- TODO: real positioning self.bar:ClearSetPoint("CENTER") - self.bar:ApplyConfig() + self.bar:SetScript("OnEvent", PetBar.OnEvent) + self.bar:RegisterEvent("PLAYER_CONTROL_LOST") + self.bar:RegisterEvent("PLAYER_CONTROL_GAINED") + self.bar:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED") + self.bar:RegisterEvent("UNIT_PET") + self.bar:RegisterEvent("UNIT_FLAGS") + self.bar:RegisterEvent("UNIT_AURA") + self.bar:RegisterEvent("PET_BAR_UPDATE") + self.bar:RegisterEvent("PET_BAR_UPDATE_COOLDOWN") + self.bar:RegisterEvent("PET_BAR_SHOWGRID") + self.bar:RegisterEvent("PET_BAR_HIDEGRID") + self.bar:SetAttribute("unit", "pet") RegisterUnitWatch(self.bar, false) + + self.bar:ApplyConfig() end end @@ -49,9 +63,10 @@ end function PetBarMod:CreatePetButton(id) local name = "BT4PetButton" .. id - local button = setmetatable(CreateFrame("CheckButton", name, self.bar, "Bartender4PetButtonTemplate"), PetButton_MT) - button:SetAttribute("type", "pet") - button:SetAttribute("action", id) + local button = setmetatable(CreateFrame("CheckButton", name, self.bar, "PetActionButtonTemplate"), PetButton_MT) + button:SetID(id) + button:UnregisterAllEvents() + button:SetScript("OnEvent", nil) button.id = id button.flash = _G[name .. "Flash"] button.cooldown = _G[name .. "Cooldown"] @@ -116,6 +131,12 @@ function PetButtonPrototype:Update() self.icon:Hide() self:SetNormalTexture("Interface\\Buttons\\UI-Quickslot") end + self:UpdateCooldown() +end + +function PetButtonPrototype:UpdateCooldown() + local start, duration, enable = GetPetActionCooldown(self.id) + CooldownFrame_SetTimer(self.cooldown, start, duration, enable) end function PetButtonPrototype:ClearSetPoint(...) @@ -123,6 +144,21 @@ function PetButtonPrototype:ClearSetPoint(...) self:SetPoint(...) end +function PetBar:OnEvent(event, arg1) + if event == "PET_BAR_UPDATE" or + (event == "UNIT_PET" and arg1 == "player") or + ((event == "UNIT_FLAGS" or event == "UNIT_AURA") and arg1 == "pet") or + event == "PLAYER_CONTROL_LOST" or event == "PLAYER_CONTROL_GAINED" or event == "PLAYER_FARSIGHT_FOCUS_CHANGED" + then + self:ForAll("Update") + elseif event == "PET_BAR_UPDATE_COOLDOWN" then + self:ForAll("UpdateCooldown") + elseif event == "PET_BAR_SHOWGRID" then + self:ForAll("ShowGrid") + elseif event == "PET_BAR_HIDEGRID" then + self:ForAll("HideGrid") + end +end function PetBar:ApplyConfig() ButtonBar.ApplyConfig(self) diff --git a/PetButton.xml b/PetButton.xml deleted file mode 100644 index ad1c22b..0000000 --- a/PetButton.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -