- added LibDataBroker support

- added option to hide the bar entirely (ticket 5) and option to hide the bar when in combat
- added short description to the config page explaining the functionality in the mod and how to get support/request features
- made all slash commands print something back to the user so they know what they changed
This commit is contained in:
parnic
2010-09-12 20:25:17 +00:00
parent 2945e6326d
commit a5f5958c5e
3 changed files with 186 additions and 7 deletions

View File

@ -13,6 +13,7 @@ local CanProspect = false
local DisenchantId = 13262
local DisenchantTypes = {babbleInv["Armor"], babbleInv["Weapon"]}
local CanDisenchant = false
-- item rarity must meet or surpass this to be considered for disenchantability (is that a word?)
local RARITY_UNCOMMON = 2
@ -31,6 +32,8 @@ local BREAKABLE_HERB = 1
local BREAKABLE_ORE = 2
local BREAKABLE_DE = 3
local _G = _G
Breakables.optionsFrame = {}
function Breakables:OnInitialize()
@ -42,12 +45,31 @@ function Breakables:OnInitialize()
maxBreakablesToShow = 5,
showSoulbound = false,
hideEqManagerItems = true,
hide = false,
hideInCombat = false,
}
}
self.db = LibStub("AceDB-3.0"):New("BreakablesDB", self.defaults)
self.settings = self.db.profile
self:RegisterChatCommand("brk", "OnSlashCommand")
self:InitLDB()
end
function Breakables:InitLDB()
local LDB = LibStub and LibStub("LibDataBroker-1.1", true)
if (LDB) then
local ldbButton = LDB:NewDataObject("Breakables", {
type = "launcher",
text = "Breakables",
icon = "Interface\\Icons\\ability_warrior_sunder",
OnClick = function(_, msg)
self:OnSlashCommand()
end,
})
end
end
function Breakables:OnEnable()
@ -62,6 +84,9 @@ function Breakables:OnEnable()
if CanMill or CanProspect or CanDisenchant then
self:CreateButtonFrame()
if self.settings.hide and self.buttonFrame then
self.buttonFrame:Hide()
end
else
self:UnregisterAllEvents()
end
@ -94,12 +119,15 @@ end
function Breakables:OnEnterCombat()
self.bCombat = true
if self.settings.hideInCombat then
self.buttonFrame:Hide()
end
end
function Breakables:OnLeaveCombat()
self.bCombat = false
if self.bPendingUpdate then
if self.bPendingUpdate or self.settings.hideInCombat then
self.bPendingUpdate = false
self:FindBreakables()
end
@ -124,6 +152,35 @@ function Breakables:GetOptions()
handler = Breakables,
type = "group",
args = {
intro = {
type = "description",
fontSize = "small",
name = [[Thanks for using |cff33ff99Breakables|r! Use |cffffff78/brk|r to open this menu or |cffffff78/breakables|r to access the same options on the command line.
Hold shift and drag the profession button to move the breakables bar around. If you have any feature requests or problems, please email |cff33ff99breakables@parnic.com|r or visit the |cffffff78curse.com|r or |cffffff78wowinterface.com|r page and leave a comment.]],
order = 0,
},
hideAlways = {
type = "toggle",
name = "Hide bar",
desc = "This will completely hide the breakables bar whether you have anything to break down or not. Note that you can toggle this in a macro using the /breakables command as well.",
get = function(info)
return self.settings.hide
end,
set = function(info, v)
self.settings.hide = v
if info.uiType == "cmd" then
print("|cff33ff99Breakables|r: set |cffffff78maxBreakables|r to " .. tostring(self.settings.hide))
end
if v then
self.buttonFrame:Hide()
else
self.buttonFrame:Show()
self:FindBreakables()
end
end,
order = 1
},
hideNoBreakables = {
type = "toggle",
name = "Hide if no breakables",
@ -133,9 +190,27 @@ function Breakables:GetOptions()
end,
set = function(info, v)
self.settings.hideIfNoBreakables = v
if info.uiType == "cmd" then
print("|cff33ff99Breakables|r: set |cffffff78hideIfNoBreakables|r to " .. tostring(self.settings.hideIfNoBreakables))
end
self:FindBreakables()
end,
order = 1,
order = 2,
},
hideInCombat = {
type = "toggle",
name = "Hide during combat",
desc = "Whether or not to hide the breakables bar when you enter combat and show it again when leaving combat.",
get = function(info)
return self.settings.hideInCombat
end,
set = function(info, v)
self.settings.hideInCombat = v
if info.uiType == "cmd" then
print("|cff33ff99Breakables|r: set |cffffff78hideInCombat|r to " .. tostring(self.settings.hideInCombat))
end
end,
order = 3,
},
maxBreakables = {
type = 'range',
@ -149,9 +224,12 @@ function Breakables:GetOptions()
end,
set = function(info, v)
self.settings.maxBreakablesToShow = v
if info.uiType == "cmd" then
print("|cff33ff99Breakables|r: set |cffffff78maxBreakables|r to " .. tostring(self.settings.maxBreakablesToShow))
end
self:FindBreakables()
end,
order = 2,
order = 4,
},
},
}
@ -166,11 +244,14 @@ function Breakables:GetOptions()
end,
set = function(info, v)
self.settings.showSoulbound = v
if info.uiType == "cmd" then
print("|cff33ff99Breakables|r: set |cffffff78showSoulbound|r to " .. tostring(self.settings.showSoulbound))
end
self:FindBreakables()
end,
order = 3,
order = 20,
}
opts.args.hideSoulboundIfInEquipmentManager = {
opts.args.hideEqManagerItems = {
type = "toggle",
name = "Hide Eq. Mgr items",
desc = "Whether or not to hide items that are part of an equipment set in the game's equipment manager.",
@ -179,15 +260,18 @@ function Breakables:GetOptions()
end,
set = function(info, v)
self.settings.hideEqManagerItems = v
if info.uiType == "cmd" then
print("|cff33ff99Breakables|r: set |cffffff78hideEqManagerItems|r to " .. tostring(self.settings.hideEqManagerItems))
end
self:FindBreakables()
end,
hidden = function()
return not self.settings.showSoulbound
end,
order = 4,
order = 21,
}
end
return opts
end
@ -240,6 +324,10 @@ function Breakables:OnMouseUp()
end
function Breakables:FindBreakables()
if self.settings.hide then
return
end
if self.bCombat then
self.bPendingUpdate = true
return

View File

@ -9,5 +9,6 @@
## X-Compatible-With: 40000
embeds.xml
LibDataBroker-1.1.lua
Breakables.lua

90
LibDataBroker-1.1.lua Normal file
View File

@ -0,0 +1,90 @@
assert(LibStub, "LibDataBroker-1.1 requires LibStub")
assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibDataBroker-1.1 requires CallbackHandler-1.0")
local lib, oldminor = LibStub:NewLibrary("LibDataBroker-1.1", 4)
if not lib then return end
oldminor = oldminor or 0
lib.callbacks = lib.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
lib.attributestorage, lib.namestorage, lib.proxystorage = lib.attributestorage or {}, lib.namestorage or {}, lib.proxystorage or {}
local attributestorage, namestorage, callbacks = lib.attributestorage, lib.namestorage, lib.callbacks
if oldminor < 2 then
lib.domt = {
__metatable = "access denied",
__index = function(self, key) return attributestorage[self] and attributestorage[self][key] end,
}
end
if oldminor < 3 then
lib.domt.__newindex = function(self, key, value)
if not attributestorage[self] then attributestorage[self] = {} end
if attributestorage[self][key] == value then return end
attributestorage[self][key] = value
local name = namestorage[self]
if not name then return end
callbacks:Fire("LibDataBroker_AttributeChanged", name, key, value, self)
callbacks:Fire("LibDataBroker_AttributeChanged_"..name, name, key, value, self)
callbacks:Fire("LibDataBroker_AttributeChanged_"..name.."_"..key, name, key, value, self)
callbacks:Fire("LibDataBroker_AttributeChanged__"..key, name, key, value, self)
end
end
if oldminor < 2 then
function lib:NewDataObject(name, dataobj)
if self.proxystorage[name] then return end
if dataobj then
assert(type(dataobj) == "table", "Invalid dataobj, must be nil or a table")
self.attributestorage[dataobj] = {}
for i,v in pairs(dataobj) do
self.attributestorage[dataobj][i] = v
dataobj[i] = nil
end
end
dataobj = setmetatable(dataobj or {}, self.domt)
self.proxystorage[name], self.namestorage[dataobj] = dataobj, name
self.callbacks:Fire("LibDataBroker_DataObjectCreated", name, dataobj)
return dataobj
end
end
if oldminor < 1 then
function lib:DataObjectIterator()
return pairs(self.proxystorage)
end
function lib:GetDataObjectByName(dataobjectname)
return self.proxystorage[dataobjectname]
end
function lib:GetNameByDataObject(dataobject)
return self.namestorage[dataobject]
end
end
if oldminor < 4 then
local next = pairs(attributestorage)
function lib:pairs(dataobject_or_name)
local t = type(dataobject_or_name)
assert(t == "string" or t == "table", "Usage: ldb:pairs('dataobjectname') or ldb:pairs(dataobject)")
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
assert(attributestorage[dataobj], "Data object not found")
return next, attributestorage[dataobj], nil
end
local ipairs_iter = ipairs(attributestorage)
function lib:ipairs(dataobject_or_name)
local t = type(dataobject_or_name)
assert(t == "string" or t == "table", "Usage: ldb:ipairs('dataobjectname') or ldb:ipairs(dataobject)")
local dataobj = self.proxystorage[dataobject_or_name] or dataobject_or_name
assert(attributestorage[dataobj], "Data object not found")
return ipairs_iter, attributestorage[dataobj], 0
end
end