madcatzinc@13
|
1 --~ Warcraft Plugin for Cyborg MMO7
|
madcatzinc@0
|
2 --~ Filename: RatPageController.lua
|
madcatzinc@0
|
3 --~ Description: Controller logic for the RatPage
|
madcatzinc@0
|
4 --~ Copyright (C) 2012 Mad Catz Inc.
|
madcatzinc@0
|
5 --~ Author: Christopher Hooks
|
madcatzinc@0
|
6
|
madcatzinc@0
|
7 --~ This program is free software; you can redistribute it and/or
|
madcatzinc@0
|
8 --~ modify it under the terms of the GNU General Public License
|
madcatzinc@0
|
9 --~ as published by the Free Software Foundation; either version 2
|
madcatzinc@0
|
10 --~ of the License, or (at your option) any later version.
|
madcatzinc@0
|
11
|
madcatzinc@0
|
12 --~ This program is distributed in the hope that it will be useful,
|
madcatzinc@0
|
13 --~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
madcatzinc@0
|
14 --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
madcatzinc@0
|
15 --~ GNU General Public License for more details.
|
madcatzinc@0
|
16
|
madcatzinc@0
|
17 --~ You should have received a copy of the GNU General Public License
|
madcatzinc@0
|
18 --~ along with this program; if not, write to the Free Software
|
madcatzinc@0
|
19 --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
madcatzinc@0
|
20
|
madcatzinc@18
|
21 ------------------------------------------------------------------------------
|
madcatzinc@0
|
22
|
madcatzinc@18
|
23 local RatPageController_methods = {}
|
madcatzinc@18
|
24 local RatPageController_mt = {__index=RatPageController_methods}
|
madcatzinc@0
|
25
|
madcatzinc@18
|
26 local function RatPageController()
|
madcatzinc@18
|
27 local self = {}
|
madcatzinc@18
|
28 -- CyborgMMO_RatPageModel:SetMode(1)
|
madcatzinc@18
|
29 setmetatable(self, RatPageController_mt)
|
madcatzinc@18
|
30 return self
|
madcatzinc@18
|
31 end
|
madcatzinc@18
|
32
|
madcatzinc@18
|
33 function RatPageController_methods:SlotClicked(slot)
|
madcatzinc@18
|
34 local slotObject = nil
|
madcatzinc@18
|
35 slotObject = CyborgMMO_RatPageModel:GetObjectOnButton(slot.Id)
|
madcatzinc@18
|
36 CyborgMMO_RatPageModel:SetObjectOnButton(slot.Id, CyborgMMO_RatPageModel:GetMode(), self:GetCursorObject())
|
madcatzinc@18
|
37
|
madcatzinc@18
|
38 if slotObject then
|
madcatzinc@25
|
39 slotObject:Pickup()
|
madcatzinc@18
|
40 end
|
madcatzinc@18
|
41 end
|
madcatzinc@18
|
42
|
madcatzinc@18
|
43 function RatPageController_methods:ModeClicked(mode)
|
madcatzinc@18
|
44 CyborgMMO_DPrint("Setting mode "..tostring(mode.Id))
|
madcatzinc@18
|
45 CyborgMMO_RatPageModel:SetMode(mode.Id)
|
madcatzinc@18
|
46 end
|
madcatzinc@18
|
47
|
madcatzinc@18
|
48 function RatPageController_methods:GetCursorObject()
|
madcatzinc@34
|
49 local type,a,b,c = GetCursorInfo()
|
madcatzinc@34
|
50 ClearCursor()
|
jerome@65
|
51
|
jerome@65
|
52 -- special case for unknown mounts (do it here since we're sure the cursor is free)
|
jerome@65
|
53 if type=='mount' then
|
jerome@65
|
54 local mountID = a
|
jerome@65
|
55 -- if the mount is unknown
|
jerome@65
|
56 if mountID~=0xFFFFFFF and not CyborgMMO_MountMap[mountID] and not CyborgMMO_LocalMountMap[mountID] then
|
jerome@65
|
57 -- build a reverse index of known mount spells
|
jerome@65
|
58 local reverse = {}
|
jerome@65
|
59 for mount,spell in pairs(CyborgMMO_MountMap) do reverse[spell] = mount end
|
jerome@65
|
60 for mount,spell in pairs(CyborgMMO_LocalMountMap) do reverse[spell] = mount end
|
jerome@65
|
61 -- iterate over mount journal
|
jerome@65
|
62 for i=1,C_MountJournal.GetNumMounts() do
|
jerome@65
|
63 local _,spell = C_MountJournal.GetMountInfo(i)
|
jerome@65
|
64 -- if the mount has no known mount ID
|
jerome@65
|
65 if not reverse[spell] then
|
jerome@65
|
66 -- pickup the mount
|
jerome@65
|
67 C_MountJournal.Pickup(i)
|
jerome@65
|
68 -- get the mount id from the cursor
|
jerome@65
|
69 local _,mount = GetCursorInfo()
|
jerome@65
|
70 ClearCursor()
|
jerome@65
|
71 -- save that to avoid spamming the cursor too often
|
jerome@65
|
72 if mount then
|
jerome@65
|
73 CyborgMMO_LocalMountMap[mount] = spell
|
jerome@65
|
74 reverse[spell] = mount
|
jerome@65
|
75 end
|
jerome@65
|
76 end
|
jerome@65
|
77 end
|
jerome@65
|
78 end
|
jerome@65
|
79 end
|
jerome@65
|
80
|
madcatzinc@34
|
81 if type=='item' then
|
madcatzinc@34
|
82 local id,link = a,b
|
madcatzinc@34
|
83 return CyborgMMO_CreateWowObject('item', id)
|
madcatzinc@34
|
84 elseif type=='spell' then
|
madcatzinc@34
|
85 local index,book,id = a,b,c
|
madcatzinc@34
|
86 return CyborgMMO_CreateWowObject('spell', id)
|
madcatzinc@34
|
87 elseif type=='macro' then
|
madcatzinc@34
|
88 local index = a
|
madcatzinc@34
|
89 local name = GetMacroInfo(index)
|
madcatzinc@34
|
90 return CyborgMMO_CreateWowObject('macro', name)
|
madcatzinc@34
|
91 elseif type=='battlepet' then
|
madcatzinc@34
|
92 local petID = a
|
madcatzinc@34
|
93 return CyborgMMO_CreateWowObject('battlepet', petID)
|
jerome@65
|
94 elseif type=='mount' then
|
jerome@65
|
95 local mountID = a
|
jerome@65
|
96 return CyborgMMO_CreateWowObject('mount', mountID)
|
madcatzinc@49
|
97 elseif type=='equipmentset' then
|
madcatzinc@49
|
98 local name = a
|
madcatzinc@49
|
99 return CyborgMMO_CreateWowObject('equipmentset', name)
|
madcatzinc@34
|
100 elseif type=='petaction' then
|
madcatzinc@34
|
101 return nil
|
madcatzinc@34
|
102 elseif type=='money' then
|
madcatzinc@34
|
103 return nil
|
madcatzinc@34
|
104 elseif type=='merchant' then
|
madcatzinc@34
|
105 return nil
|
madcatzinc@34
|
106 elseif type==nil then
|
madcatzinc@34
|
107 return nil
|
madcatzinc@34
|
108 else
|
madcatzinc@34
|
109 CyborgMMO_DPrint("unexpected cursor info:", type, a, b, c)
|
madcatzinc@34
|
110 return nil
|
madcatzinc@18
|
111 end
|
madcatzinc@18
|
112 end
|
madcatzinc@18
|
113
|
madcatzinc@18
|
114 function RatPageController_methods:CallbackDropped(callbackObject)
|
madcatzinc@18
|
115 local slot = nil
|
madcatzinc@18
|
116 local observers = CyborgMMO_RatPageModel:GetAllObservers()
|
madcatzinc@18
|
117 for i=1,#observers do
|
madcatzinc@18
|
118 if MouseIsOver(observers[i]) then
|
madcatzinc@18
|
119 slot = observers[i]
|
madcatzinc@18
|
120 break
|
madcatzinc@0
|
121 end
|
madcatzinc@18
|
122 end
|
madcatzinc@18
|
123 if slot then
|
madcatzinc@18
|
124 CyborgMMO_RatPageModel:SetObjectOnButton(slot.Id, CyborgMMO_RatPageModel:GetMode(), callbackObject.wowObject)
|
madcatzinc@18
|
125 end
|
madcatzinc@18
|
126 end
|
madcatzinc@0
|
127
|
madcatzinc@18
|
128 ------------------------------------------------------------------------------
|
madcatzinc@0
|
129
|
madcatzinc@18
|
130 CyborgMMO_RatPageController = RatPageController()
|
madcatzinc@13
|
131
|