Mercurial > wow > cyborg-mmo7
comparison WowObjects.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: WowObjects.lua | |
3 --~ Description: Warcraft in game object models | |
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 WowObject = { | |
22 new = function(type, detail, subdetail) | |
23 local self = {}; | |
24 self.Texture = nil; | |
25 self.Name = "NoName"; | |
26 self.Type = type; | |
27 self.Detail = detail; | |
28 self.Subdetail = subdetail; | |
29 | |
30 | |
31 -- Methods -- | |
32 self.DoAction = function() | |
33 msg("Nothing To Do"); | |
34 end | |
35 | |
36 self.Pickup = function() | |
37 msg("Pick up Item"); | |
38 end | |
39 | |
40 self.SetBinding = function(key) | |
41 end | |
42 | |
43 self.PlaySound = function() | |
44 PlaySound("igAbilityIconDrop"); | |
45 end | |
46 | |
47 return self; | |
48 end, | |
49 | |
50 ClearBinding = function(key) | |
51 local buttonFrame, parentFrame, name = CallbackFactory.Instance().AddCallback(WowObject.DoNothing); | |
52 if(1 ~= SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")) then | |
53 msg("Failed to bind companion to button click"); | |
54 end | |
55 end, | |
56 | |
57 DoNothing = function() | |
58 end, | |
59 | |
60 Load = function(object) | |
61 if("item" == type) then | |
62 object = WowItem.Load(Object) | |
63 elseif("macro" == type) then | |
64 object = WowMacro.Load(object) | |
65 elseif("spell" == type) then | |
66 object = WowSpell.Load(object) | |
67 elseif("petaction" == type) then | |
68 object = WowSpell.Load(object) | |
69 --elseif("merchant"== type) then | |
70 --object = SlotMerchant.new(detail,subdetail) | |
71 elseif("companion" == type) then | |
72 object = WowCompanion.Load(object) | |
73 elseif("equipmentset" == type) then | |
74 object = WowEquipmentSet.Load(object) | |
75 else | |
76 object = WowObject.new(type,detail, subdetail) | |
77 end | |
78 return object; | |
79 end, | |
80 | |
81 -- Static Methods -- | |
82 Create = function(objectType, detail, subdetail) | |
83 local object; | |
84 if("item" == objectType) then | |
85 object = WowItem.new(detail,subdetail) | |
86 elseif("macro" == objectType) then | |
87 object = WowMacro.new(detail) | |
88 elseif("spell" == objectType) then | |
89 object = WowSpell.new(objectType, detail,subdetail) | |
90 elseif("petaction" == objectType) then | |
91 object = WowSpell.new(objectType, detail,subdetail) | |
92 elseif("merchant"== objectType) then | |
93 object = SlotMerchant.new(detail,subdetail) | |
94 elseif("companion" == objectType) then | |
95 object = WowCompanion.new(detail,subdetail) | |
96 elseif("equipmentset" == objectType) then | |
97 object = WowEquipmentSet.new(objectType,detail,subdetail) | |
98 elseif("callback" == objectType) then | |
99 object = WowCallback.new(detail); | |
100 else | |
101 object = WowObject.new(objectType,detail, subdetail) | |
102 end | |
103 | |
104 return object; | |
105 end | |
106 } | |
107 | |
108 local CallbackCursor = nil; | |
109 | |
110 CallbackIcons = { | |
111 new = function(self) | |
112 self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs = self:GetPoint(); | |
113 --self:SetPoint(self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs); | |
114 self.strata = self:GetFrameStrata(); | |
115 self.wowObject = WowCallback.new(self:GetName()); | |
116 self.wowObject.SetTextures(self); | |
117 self:RegisterForDrag("LeftButton","RightButton") | |
118 self:SetResizable(false); | |
119 | |
120 self.OnClick = function() | |
121 self.wowObject.DoAction(); | |
122 end | |
123 | |
124 | |
125 self.DragStart = function() | |
126 self:SetMovable(true); | |
127 self:StartMoving(); | |
128 self.isMoving = true; | |
129 self:SetFrameStrata("TOOLTIP") | |
130 end | |
131 | |
132 self.DragStop = function() | |
133 | |
134 self:SetFrameStrata(self.strata); | |
135 self.isMoving = false; | |
136 self:SetMovable(false); | |
137 self:StopMovingOrSizing(); | |
138 | |
139 self:ClearAllPoints(); | |
140 self:SetPoint(self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs); | |
141 local x, y = GetCursorPosition(); | |
142 RatPageController.Instance().CallbackDropped(self) | |
143 end | |
144 | |
145 return self; | |
146 end | |
147 } | |
148 | |
149 WowCallback = { | |
150 new = function(callbackName) | |
151 local self = WowObject.new("callback", callbackName, ""); | |
152 self.CallbackName = callbackName; | |
153 self.Texture = "Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga" | |
154 | |
155 self.SetTextures = function(buttonFrame) | |
156 buttonFrame:SetNormalTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga") | |
157 buttonFrame:SetPushedTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Down.tga") | |
158 buttonFrame:SetHighlightTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Over.tga") | |
159 end | |
160 | |
161 self.DoAction = function() | |
162 local action = GetCallback(self.CallbackName) | |
163 msg("calling callback:- "..self.CallbackName); | |
164 action(); | |
165 | |
166 end | |
167 | |
168 self.PickupCallback = function() | |
169 | |
170 local slot = nil; | |
171 local observers = RatPageModel.Instance().GetAllObservers(); | |
172 for i = 1, (# observers) do | |
173 if(MouseIsOver(observers[i])) then | |
174 slot = observers[i]; | |
175 break; | |
176 end | |
177 end | |
178 slot:SetNormalTexture(slot.UnCheckedTexture) | |
179 end | |
180 | |
181 | |
182 self.ClickHandler = function(self, button, down) | |
183 msg("click handler"); | |
184 CallbackCursor:StopMoving(); | |
185 CallbackCursor:Hide(); | |
186 | |
187 if("LeftButton" == button) then | |
188 else | |
189 | |
190 end | |
191 end | |
192 | |
193 self.Pickup = function() | |
194 self.PlaySound() | |
195 ClearCursor(); | |
196 self.PickupCallback(); | |
197 | |
198 end | |
199 | |
200 | |
201 self.SetBinding = function(key) | |
202 local buttonFrame, parentFrame, name = CallbackFactory.Instance().AddCallback(self.DoAction); | |
203 if(1 ~= SetOverrideBindingClick(CallbackFactory.Instance().Frame, true, key, name, "LeftButton")) then | |
204 msg("Failed to Bind modeChange"); | |
205 end | |
206 end | |
207 | |
208 return self; | |
209 end | |
210 } | |
211 | |
212 -- WowItem Class -- | |
213 | |
214 WowItem = { | |
215 new = function(number, itemID) | |
216 local self = WowObject.new("item", number, itemID); -- base class | |
217 -- Set all the item info. -- | |
218 self.Name, | |
219 self.Link, | |
220 self.Rarity, | |
221 self.Level, | |
222 self.MinLevel, | |
223 self.Type, | |
224 self.SubType, | |
225 self.StackCount, | |
226 self.EquipLoc, | |
227 self.Texture, | |
228 self.SellPrice = GetItemInfo(itemID); | |
229 | |
230 -- override method -- | |
231 self.DoAction = function() | |
232 msg("Use Item"); | |
233 end | |
234 | |
235 -- override method -- | |
236 self.Pickup = function() | |
237 self.PlaySound() | |
238 ClearCursor(); | |
239 --SetCursor(self.Texture); | |
240 return PickupItem(self.Link); | |
241 end | |
242 | |
243 self.SetBinding = function(key) | |
244 SetOverrideBinding(CallbackFactory.Instance().Frame, true, key, "ITEM "..self.Name); | |
245 end | |
246 | |
247 return self; | |
248 end, | |
249 } | |
250 | |
251 -- WowSpell Class -- | |
252 | |
253 WowSpell = { | |
254 new = function(type, spellbookID, spellbook) | |
255 local self = WowObject.new(type, spellbookID, spellbook) -- base class | |
256 self.SpellbookID = spellbookID; | |
257 self.Spellbook = spellbook; | |
258 self.Name, self.Rank = GetSpellBookItemName(spellbookID, spellbook); | |
259 self.Texture = GetSpellBookItemTexture(spellbookID, spellbook); | |
260 self.Type = type; | |
261 | |
262 | |
263 -- override method -- | |
264 self.DoAction = function() | |
265 msg("Cast Spell"); | |
266 end | |
267 | |
268 -- override method -- | |
269 self.Pickup = function() | |
270 self.PlaySound() | |
271 ClearCursor(); | |
272 --SetCursor(self.Texture); | |
273 return PickupSpellBookItem(self.SpellbookID, self.Spellbook); | |
274 end | |
275 | |
276 self.SetBinding = function(key) | |
277 msg("Binding to key "..key) | |
278 self.Key = key | |
279 SetOverrideBinding(CallbackFactory.Instance().Frame, true, self.Key, self.Type.." "..self.Name); | |
280 end | |
281 | |
282 return self; | |
283 | |
284 end, | |
285 | |
286 Load = function(object) | |
287 local o = WowSpell.new(object.Type, object.Detail, object.Subdetail); | |
288 o.Name = object.Name; | |
289 o.Texture = object.Texture; | |
290 return o; | |
291 end | |
292 } | |
293 | |
294 -- WowMacro Class -- | |
295 | |
296 WowMacro = { | |
297 new = function(index) | |
298 local self = WowObject.new("macro", index, nil); -- base class | |
299 -- Set all the item info. -- | |
300 self.Name, | |
301 self.Texture, | |
302 self.Body, | |
303 self.isLocal = GetMacroInfo(index); | |
304 self.Index = index; | |
305 | |
306 -- override method -- | |
307 self.DoAction = function() | |
308 msg("Use Item"); | |
309 end | |
310 | |
311 -- override method -- | |
312 self.Pickup = function() | |
313 self.PlaySound() | |
314 ClearCursor(); | |
315 --SetCursor(self.Texture); | |
316 return PickupMacro(self.Index); | |
317 end | |
318 | |
319 self.SetBinding = function(key) | |
320 self.Key = key; | |
321 SetOverrideBinding(CallbackFactory.Instance().Frame, true, key, "MACRO "..self.Index); | |
322 end | |
323 | |
324 return self; | |
325 end, | |
326 } | |
327 | |
328 | |
329 -- WowCompanion Class -- | |
330 | |
331 WowCompanion = { | |
332 new = function(index, SubType) | |
333 local self = WowObject.new("companion", index, SubType); -- base class | |
334 -- Set all the item info. -- | |
335 self.Id, self.Name, self.SpellId, self.Texture, self.isSummoned = GetCompanionInfo(SubType, index); | |
336 self.SubType = SubType; | |
337 self.index = index; | |
338 -- override method -- | |
339 self.DoAction = function() | |
340 if((self.SubType == "MOUNT") and IsMounted()) then | |
341 Dismount(); | |
342 else | |
343 CallCompanion(self.SubType, self.index); | |
344 end | |
345 end | |
346 | |
347 -- override method -- | |
348 self.Pickup = function() | |
349 self.PlaySound() | |
350 return PickupCompanion(self.SubType, self.index); | |
351 end | |
352 | |
353 self.SetBinding = function(key) | |
354 self.Key = key | |
355 local buttonFrame, parentFrame, name = CallbackFactory.Instance().AddCallback(self.DoAction); | |
356 if(1 ~= SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")) then | |
357 msg("Failed to bind companion to button click"); | |
358 end | |
359 --SetOverrideBinding(hiddenModeChanger, true, key, "MACRO "..self.Index); | |
360 end | |
361 | |
362 return self; | |
363 end, | |
364 | |
365 Load = function(object) | |
366 local o = WowCompanion.new(object.index, object.SubType); | |
367 return o; | |
368 end | |
369 } | |
370 | |
371 -- WowMerchant Class -- | |
372 WowMerchant = { | |
373 new = function(index) | |
374 local self = WowObject.new("macro", index, nil); -- base class | |
375 -- Set all the item info. -- | |
376 self.Name, | |
377 self.Texture, | |
378 self.Price, | |
379 self.Quantity, | |
380 self.NumAvailable, | |
381 self.IsUsable, | |
382 self.ExtendedCost = GetMerchantItemInfo(index); | |
383 self.Index = index; | |
384 | |
385 -- override method -- | |
386 self.DoAction = function() | |
387 msg("Use Item"); | |
388 end | |
389 | |
390 -- override method -- | |
391 self.Pickup = function() | |
392 self.PlaySound() | |
393 ClearCursor(); | |
394 --SetCursor(self.Texture); | |
395 return PickupMerchantItem(self.Index); | |
396 end | |
397 | |
398 self.SetBinding = function(key) | |
399 self.Key = key | |
400 SetOverrideBinding(CallbackFactory.Instance().Frame, true, key, "MERCHANT "..self.Index); | |
401 end | |
402 | |
403 return self; | |
404 end, | |
405 } | |
406 | |
407 -- WowEquipmentSet Class -- | |
408 WowEquipmentSet = { | |
409 new = function(objectType, name, index) | |
410 local self = WowObject.new(objectType, name, index); -- base class | |
411 -- Set all the item info. -- | |
412 texture, lessIndex = GetEquipmentSetInfoByName(name); | |
413 self.Texture = "Interface\\Icons\\"..texture; | |
414 self.Name = name | |
415 self.Index = lessIndex+1; | |
416 | |
417 -- override method -- | |
418 self.DoAction = function() | |
419 UseEquipmentSet(self.Name); | |
420 end | |
421 | |
422 -- override method -- | |
423 self.Pickup = function() | |
424 self.PlaySound() | |
425 ClearCursor(); | |
426 --SetCursor(self.Texture); | |
427 return PickupEquipmentSetByName(self.Name); | |
428 end | |
429 | |
430 self.SetBinding = function(key) | |
431 self.Key = key | |
432 local buttonFrame, parentFrame, name = CallbackFactory.Instance().AddCallback(self.DoAction); | |
433 if(1 ~= SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton")) then | |
434 msg("Failed to bind companion to button click"); | |
435 end | |
436 end | |
437 | |
438 return self; | |
439 end, | |
440 } | |
441 | |
442 | |
443 -- End Of WowObjects -- |