view CallbackFactory.lua @ 4:d186f8cd5000

Renamed functions to avoid conflicts
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Mon, 28 May 2012 15:54:52 +0000
parents bf9220814fb5
children 6cb9a2936580
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.

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

		self.AddCallback = function(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

		self.RemoveCallback = function(name)
			self.Callbacks[name] = nil
		end
		
		self.GetCallback = function(callbackName)
			local callback = nil
			if("Map" == callbackName) then
				callback = self.ToggleMap;
			elseif("CharacterPage" == callbackName) then
				callback = self.ToggleCharacterPage;
			elseif("Spellbook" == callbackName) then
				callback = self.ToggleSpellbook;
			elseif("Macros" == callbackName) then
				callback = self.ToggleMacros;
			elseif("QuestLog" == callbackName) then
				callback = self.ToggleQuests;
			elseif("Achievement" == callbackName) then
				callback = self.ToggleAchievements;
			elseif("Inventory" == callbackName) then
				callback = self.ToggleBags; 
			end;
			return callback;
		end


		self.ToggleMap = function()
			ToggleFrame(WorldMapFrame)
		end

		self.ToggleCharacterPage = function()
			ToggleCharacter("PaperDollFrame")
		end

		self.ToggleSpellbook = function()
			ToggleFrame(SpellBookFrame)
			if(SpellBookFrame:IsShown()) then
				SpellbookMicroButton:SetButtonState("PUSHED", 1);
			else
				SpellbookMicroButton:SetButtonState("NORMAL");
			end
		end

		self.ToggleMacros = function()
			if(MacroFrame:IsShown() and MacroFrame:IsVisible()) then
				HideUIPanel(MacroFrame);
			else
				ShowMacroFrame();
			end
		end

		self.ToggleQuests = function()
			ToggleFrame(QuestLogFrame);
			if ( QuestLogFrame:IsShown() ) then
				QuestLogMicroButton:SetButtonState("PUSHED", 1);
			else
				QuestLogMicroButton:SetButtonState("NORMAL");
			end
		end

		self.ToggleAchievements = function()
			ToggleAchievementFrame();
			if ( AchievementFrame and AchievementFrame:IsShown() ) then
				AchievementMicroButton:SetButtonState("PUSHED", 1);
			else
				if ( ( HasCompletedAnyAchievement() or IsInGuild() ) and CanShowAchievementUI() ) then
					AchievementMicroButton:Enable();
					AchievementMicroButton:SetButtonState("NORMAL");
				else
					AchievementMicroButton:Disable();
				end
			end
		end

		self.ToggleBags = function()
			ToggleAllBags();
		end
		return self;
	end,

	m_Instance = nil,

	Instance = function()
		if(nil == CyborgMMO_CallbackFactory.m_Instance) then
			CyborgMMO_CallbackFactory.m_Instance = CyborgMMO_CallbackFactory.new();
		end
		return CyborgMMO_CallbackFactory.m_Instance;
	end


}