View Single Post
09-10-12, 08:23 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The problem is that you are initializing your DB before the user's saved DB is actually loaded, so it's always resetting to defaults, and ignoring whatever the user had saved before.

Using AceAddon is massive overkill for something so small.

Using AceDB is probably also overkill for something so simple. Unless you plan to add a large number of complex options that users are likely to want to share between some characters but not others and take a long time to set up, I'd avoid using AceDB. For shared settings, use SavedVariables. For per-character settings, use SavedVariablesPerCharacter.

I'd go with something like this:

Code:
local f = CreateFrame("Frame", "MaggzAutoLog")

f.dataObject = {
    type = "launcher",
    icon = "Interface\\Addons\\MaggzAutoLog\\disabled",
    label = "MaggzAutoLog",
    OnClick = function(self, button)
        if button == "RightButton" then
            LOGSTATE() -- Where is this function defined?
        else
			-- No need to do "if X then ... end" followed by "if Y then ... end".
			-- Use a simple "if X then ... else ... end" instead.
            if LoggingCombat() then
                disablelogging() -- Where is this function defined?
            else
                enablelogging() -- Where is this function defined?
            end
        end
    end,
    OnTooltipShow = function(tooltip)
		tooltip:AddLine("|cff00FF00MaggzAutoLog|r")
		tooltip:AddLine("hold left mouse button to drag")
			-- What are you dragging? This is the tooltip for an icon
			-- on your Broker display; you're not dragging it anywhere.
		tooltip:AddLine("right click to enable/disable logging")
		if LoggingCombat() then
			tooltip:AddLine("Logging |cff00FF00Enabled|r")
		else
			tooltip:AddLine("Logging |cffFF0000Disabled|r")
		end
	end,
}

f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
	MaggzAutoLogDB = MaggzAutoLogDB or {}
	MaggzAutoLogDB.LDBIconStorage = MaggzAutoLogDB.LDBIconStorage or {}

	LibStub("LibDataBroker-1.1"):NewDataObject("MaggzAutoLogDB", f.dataObject)
	LibStub("LibDBIcon-1.0"):Register("MaggzAutoLog", f.dataObject, MaggzAutoLogDB.LDBIconStorage)
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote