madcatzinc@13: --~ Warcraft Plugin for Cyborg MMO7 madcatzinc@0: --~ Filename: RatPageController.lua madcatzinc@0: --~ Description: Controller logic for the RatPage madcatzinc@0: --~ Copyright (C) 2012 Mad Catz Inc. madcatzinc@0: --~ Author: Christopher Hooks madcatzinc@0: madcatzinc@0: --~ This program is free software; you can redistribute it and/or madcatzinc@0: --~ modify it under the terms of the GNU General Public License madcatzinc@0: --~ as published by the Free Software Foundation; either version 2 madcatzinc@0: --~ of the License, or (at your option) any later version. madcatzinc@0: madcatzinc@0: --~ This program is distributed in the hope that it will be useful, madcatzinc@0: --~ but WITHOUT ANY WARRANTY; without even the implied warranty of madcatzinc@0: --~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the madcatzinc@0: --~ GNU General Public License for more details. madcatzinc@0: madcatzinc@0: --~ You should have received a copy of the GNU General Public License madcatzinc@0: --~ along with this program; if not, write to the Free Software madcatzinc@0: --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. madcatzinc@0: madcatzinc@18: ------------------------------------------------------------------------------ madcatzinc@0: madcatzinc@18: local RatPageController_methods = {} madcatzinc@18: local RatPageController_mt = {__index=RatPageController_methods} madcatzinc@0: madcatzinc@18: local function RatPageController() madcatzinc@18: local self = {} madcatzinc@18: -- CyborgMMO_RatPageModel:SetMode(1) madcatzinc@18: setmetatable(self, RatPageController_mt) madcatzinc@18: return self madcatzinc@18: end madcatzinc@18: madcatzinc@18: function RatPageController_methods:SlotClicked(slot) madcatzinc@18: local slotObject = nil madcatzinc@18: slotObject = CyborgMMO_RatPageModel:GetObjectOnButton(slot.Id) madcatzinc@18: CyborgMMO_RatPageModel:SetObjectOnButton(slot.Id, CyborgMMO_RatPageModel:GetMode(), self:GetCursorObject()) madcatzinc@18: madcatzinc@18: if slotObject then madcatzinc@25: slotObject:Pickup() madcatzinc@18: end madcatzinc@18: end madcatzinc@18: madcatzinc@18: function RatPageController_methods:ModeClicked(mode) madcatzinc@18: CyborgMMO_DPrint("Setting mode "..tostring(mode.Id)) madcatzinc@18: CyborgMMO_RatPageModel:SetMode(mode.Id) madcatzinc@18: end madcatzinc@18: madcatzinc@18: function RatPageController_methods:GetCursorObject() madcatzinc@34: local type,a,b,c = GetCursorInfo() madcatzinc@34: ClearCursor() jerome@65: jerome@65: -- special case for unknown mounts (do it here since we're sure the cursor is free) jerome@65: if type=='mount' then jerome@65: local mountID = a jerome@65: -- if the mount is unknown jerome@65: if mountID~=0xFFFFFFF and not CyborgMMO_MountMap[mountID] and not CyborgMMO_LocalMountMap[mountID] then jerome@65: -- build a reverse index of known mount spells jerome@65: local reverse = {} jerome@65: for mount,spell in pairs(CyborgMMO_MountMap) do reverse[spell] = mount end jerome@65: for mount,spell in pairs(CyborgMMO_LocalMountMap) do reverse[spell] = mount end jerome@65: -- iterate over mount journal jerome@65: for i=1,C_MountJournal.GetNumMounts() do jerome@65: local _,spell = C_MountJournal.GetMountInfo(i) jerome@65: -- if the mount has no known mount ID jerome@65: if not reverse[spell] then jerome@65: -- pickup the mount jerome@65: C_MountJournal.Pickup(i) jerome@65: -- get the mount id from the cursor jerome@65: local _,mount = GetCursorInfo() jerome@65: ClearCursor() jerome@65: -- save that to avoid spamming the cursor too often jerome@65: if mount then jerome@65: CyborgMMO_LocalMountMap[mount] = spell jerome@65: reverse[spell] = mount jerome@65: end jerome@65: end jerome@65: end jerome@65: end jerome@65: end jerome@65: madcatzinc@34: if type=='item' then madcatzinc@34: local id,link = a,b madcatzinc@34: return CyborgMMO_CreateWowObject('item', id) madcatzinc@34: elseif type=='spell' then madcatzinc@34: local index,book,id = a,b,c madcatzinc@34: return CyborgMMO_CreateWowObject('spell', id) madcatzinc@34: elseif type=='macro' then madcatzinc@34: local index = a madcatzinc@34: local name = GetMacroInfo(index) madcatzinc@34: return CyborgMMO_CreateWowObject('macro', name) madcatzinc@34: elseif type=='companion' then madcatzinc@34: local index,subtype = a,b madcatzinc@34: local spellID = select(3, GetCompanionInfo(subtype, index)) madcatzinc@34: return CyborgMMO_CreateWowObject('companion', spellID) madcatzinc@34: elseif type=='battlepet' then madcatzinc@34: local petID = a madcatzinc@34: return CyborgMMO_CreateWowObject('battlepet', petID) jerome@65: elseif type=='mount' then jerome@65: local mountID = a jerome@65: return CyborgMMO_CreateWowObject('mount', mountID) madcatzinc@49: elseif type=='equipmentset' then madcatzinc@49: local name = a madcatzinc@49: return CyborgMMO_CreateWowObject('equipmentset', name) madcatzinc@34: elseif type=='petaction' then madcatzinc@34: return nil madcatzinc@34: elseif type=='money' then madcatzinc@34: return nil madcatzinc@34: elseif type=='merchant' then madcatzinc@34: return nil madcatzinc@34: elseif type==nil then madcatzinc@34: return nil madcatzinc@34: else madcatzinc@34: CyborgMMO_DPrint("unexpected cursor info:", type, a, b, c) madcatzinc@34: return nil madcatzinc@18: end madcatzinc@18: end madcatzinc@18: madcatzinc@18: function RatPageController_methods:CallbackDropped(callbackObject) madcatzinc@18: local slot = nil madcatzinc@18: local observers = CyborgMMO_RatPageModel:GetAllObservers() madcatzinc@18: for i=1,#observers do madcatzinc@18: if MouseIsOver(observers[i]) then madcatzinc@18: slot = observers[i] madcatzinc@18: break madcatzinc@0: end madcatzinc@18: end madcatzinc@18: if slot then madcatzinc@18: CyborgMMO_RatPageModel:SetObjectOnButton(slot.Id, CyborgMMO_RatPageModel:GetMode(), callbackObject.wowObject) madcatzinc@18: end madcatzinc@18: end madcatzinc@0: madcatzinc@18: ------------------------------------------------------------------------------ madcatzinc@0: madcatzinc@18: CyborgMMO_RatPageController = RatPageController() madcatzinc@13: