view CallbackFactory.lua @ 34:6ce173840e68

Reworked the whole "wow object" system: - Only save what is strictly necessary. - Save appropriate persistent information for all objects (like spellIDs instead of spellBook+spellIndex). - Fixed Battle Pets objects (non-combat pets in pre-MoP). - Fixed item objects. - Cleaned and simplified most objects implementation. - Moved the settings and button profile to the root of the saved data, rather than in a per-character sub-table (that data is already tagged as saved per character). This should fix most issues with objects changing without user interaction on diverse occasions. Old profiles are not converted to the new system. This will come soon. Some issues persist due to the asynchronous loading of some informations: - Pet icons are never properly loaded from saved data. - Items are not properly loaded the first time the UI is started (a "/reload ui" or disconnect/connect cycle fixes this problem).
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Thu, 25 Apr 2013 01:31:31 +0000
parents ea423ee3a8c1
children 2d6684c270b9
line wrap: on
line source
--~ Warcraft Plugin for Cyborg MMO7
--~ Filename: CalbackFactory.lua
--~ Description: Creates lua callbacks that can be executed from a user keycombination
--~ Copyright (C) 2012 Mad Catz Inc.
--~ Author: Christopher Hooks

--~ This program is free software; you can redistribute it and/or
--~ modify it under the terms of the GNU General Public License
--~ as published by the Free Software Foundation; either version 2
--~ of the License, or (at your option) any later version.

--~ This program is distributed in the hope that it will be useful,
--~ but WITHOUT ANY WARRANTY; without even the implied warranty of
--~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--~ GNU General Public License for more details.

--~ You should have received a copy of the GNU General Public License
--~ along with this program; if not, write to the Free Software
--~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

------------------------------------------------------------------------------

local CallbackFactory_methods = {}
local CallbackFactory_mt = {__index=CallbackFactory_methods}

local function CallbackFactory()
	local self = {}
	self.Frame = CreateFrame("Frame", "CallbackFactoryFrame", UIParent)
	self.Callbacks = {}
	self.Id = 1

	setmetatable(self, CallbackFactory_mt)

	return self
end

function CallbackFactory_methods:AddCallback(fn)
	local name = "Button"..self.Id
	self.Callbacks[name] = CreateFrame("Button", name, self.Frame)
	self.Callbacks[name]:SetScript("OnClick", fn)
	self.Id = self.Id + 1
	return self.Callbacks[name],self.Frame,name
end

function CallbackFactory_methods:RemoveCallback(name)
	self.Callbacks[name] = nil
end

local callbacks = {}

function CallbackFactory_methods:GetCallback(name)
	return callbacks[name]
end

------------------------------------------------------------------------------

function callbacks.Map()
	ToggleFrame(WorldMapFrame)
end

function callbacks.CharacterPage()
	ToggleCharacter("PaperDollFrame")
end

function callbacks.Spellbook()
	ToggleFrame(SpellBookFrame)
end

function callbacks.Macros()
	if MacroFrame and MacroFrame:IsShown() and MacroFrame:IsVisible() then
		HideUIPanel(MacroFrame)
	else
		ShowMacroFrame()
	end
end

function callbacks.QuestLog()
	ToggleFrame(QuestLogFrame)
end

function callbacks.Achievement()
	ToggleAchievementFrame()
end

function callbacks.Inventory()
	ToggleAllBags()
end

------------------------------------------------------------------------------

CyborgMMO_CallbackFactory = CallbackFactory()