Mercurial > wow > cyborg-mmo7
comparison CallbackFactory.lua @ 0:bf9220814fb5
The first version of the Cyborg MMO7 addon for warcraft
author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
---|---|
date | Tue, 24 Jan 2012 17:14:21 +0000 |
parents | |
children | d186f8cd5000 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf9220814fb5 |
---|---|
1 --~ Warcraft Plugin for Cyborg MMO7 | |
2 --~ Filename: CalbackFactory.lua | |
3 --~ Description: Creates lua callbacks that can be executed from a user keycombination | |
4 --~ Copyright (C) 2012 Mad Catz Inc. | |
5 --~ Author: Christopher Hooks | |
6 | |
7 --~ This program is free software; you can redistribute it and/or | |
8 --~ modify it under the terms of the GNU General Public License | |
9 --~ as published by the Free Software Foundation; either version 2 | |
10 --~ of the License, or (at your option) any later version. | |
11 | |
12 --~ This program is distributed in the hope that it will be useful, | |
13 --~ but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 --~ GNU General Public License for more details. | |
16 | |
17 --~ You should have received a copy of the GNU General Public License | |
18 --~ along with this program; if not, write to the Free Software | |
19 --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | |
21 CallbackFactory = { | |
22 new = function() | |
23 local self = {} | |
24 self.Frame = CreateFrame("Frame","CallbackFactoryFrame", UIParent); | |
25 self.Callbacks = {} | |
26 self.Id = 1; | |
27 | |
28 self.AddCallback = function(fn) | |
29 local name = "Button"..self.Id | |
30 self.Callbacks[name] = CreateFrame("Button", name, self.Frame) | |
31 self.Callbacks[name]:SetScript("OnClick", fn); | |
32 self.Id = self.Id + 1; | |
33 return self.Callbacks[name], self.Frame, name; | |
34 end | |
35 | |
36 self.RemoveCallback = function(name) | |
37 self.Callbacks[name] = nil | |
38 end | |
39 | |
40 return self; | |
41 end, | |
42 | |
43 m_Instance = nil, | |
44 | |
45 Instance = function() | |
46 if(nil == CallbackFactory.m_Instance) then | |
47 CallbackFactory.m_Instance = CallbackFactory.new(); | |
48 end | |
49 return CallbackFactory.m_Instance; | |
50 end | |
51 | |
52 } | |
53 | |
54 | |
55 GetCallback = function(callbackName) | |
56 local callback = nil | |
57 if("Map" == callbackName) then | |
58 callback = ToggleMap; | |
59 elseif("CharacterPage" == callbackName) then | |
60 callback = ToggleCharacterPage; | |
61 elseif("Spellbook" == callbackName) then | |
62 callback = ToggleSpellbook; | |
63 elseif("Macros" == callbackName) then | |
64 callback = ToggleMacros; | |
65 elseif("QuestLog" == callbackName) then | |
66 callback = ToggleQuests; | |
67 elseif("Achievement" == callbackName) then | |
68 callback = ToggleAchievements; | |
69 elseif("Inventory" == callbackName) then | |
70 callback = ToggleBags; | |
71 end; | |
72 return callback; | |
73 end | |
74 | |
75 | |
76 ToggleMap = function() | |
77 ToggleFrame(WorldMapFrame) | |
78 end | |
79 | |
80 ToggleCharacterPage = function() | |
81 ToggleCharacter("PaperDollFrame") | |
82 end | |
83 | |
84 ToggleSpellbook = function() | |
85 ToggleFrame(SpellBookFrame) | |
86 if(SpellBookFrame:IsShown()) then | |
87 SpellbookMicroButton:SetButtonState("PUSHED", 1); | |
88 else | |
89 SpellbookMicroButton:SetButtonState("NORMAL"); | |
90 end | |
91 | |
92 end | |
93 | |
94 ToggleMacros = function() | |
95 if(MacroFrame:IsShown() and MacroFrame:IsVisible()) then | |
96 HideUIPanel(MacroFrame); | |
97 else | |
98 ShowMacroFrame(); | |
99 end | |
100 end | |
101 | |
102 ToggleQuests = function() | |
103 ToggleFrame(QuestLogFrame); | |
104 if ( QuestLogFrame:IsShown() ) then | |
105 QuestLogMicroButton:SetButtonState("PUSHED", 1); | |
106 else | |
107 QuestLogMicroButton:SetButtonState("NORMAL"); | |
108 end | |
109 end | |
110 | |
111 ToggleAchievements = function() | |
112 ToggleAchievementFrame(); | |
113 if ( AchievementFrame and AchievementFrame:IsShown() ) then | |
114 AchievementMicroButton:SetButtonState("PUSHED", 1); | |
115 else | |
116 if ( ( HasCompletedAnyAchievement() or IsInGuild() ) and CanShowAchievementUI() ) then | |
117 AchievementMicroButton:Enable(); | |
118 AchievementMicroButton:SetButtonState("NORMAL"); | |
119 else | |
120 AchievementMicroButton:Disable(); | |
121 end | |
122 end | |
123 end | |
124 | |
125 ToggleBags = function() | |
126 ToggleAllBags(); | |
127 end |