Mercurial > wow > cyborg-mmo7
changeset 25:b7074b47cfc7
Simplified the object system of the WowObject-s.
author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
---|---|
date | Thu, 25 Apr 2013 01:30:46 +0000 |
parents | 6906d8ffd580 |
children | 92b62e33887b |
files | RatPageController.lua RatPageModel.lua WowObjects.lua |
diffstat | 3 files changed, 339 insertions(+), 313 deletions(-) [+] |
line wrap: on
line diff
--- a/RatPageController.lua Thu Apr 25 01:30:41 2013 +0000 +++ b/RatPageController.lua Thu Apr 25 01:30:46 2013 +0000 @@ -36,7 +36,7 @@ CyborgMMO_RatPageModel:SetObjectOnButton(slot.Id, CyborgMMO_RatPageModel:GetMode(), self:GetCursorObject()) if slotObject then - slotObject.Pickup() + slotObject:Pickup() end end @@ -48,8 +48,7 @@ function RatPageController_methods:GetCursorObject() local cursorObject = nil if GetCursorInfo() then - local type,detail,subdetail = GetCursorInfo() - cursorObject = CyborgMMO_WowObject.Create(type, detail, subdetail) + cursorObject = CyborgMMO_CreateWowObject(GetCursorInfo()) ClearCursor() end return cursorObject
--- a/RatPageModel.lua Thu Apr 25 01:30:41 2013 +0000 +++ b/RatPageModel.lua Thu Apr 25 01:30:46 2013 +0000 @@ -77,10 +77,10 @@ for mode=1,RAT7.MODES do for button=1,RAT7.BUTTONS do if self.data[mode][button] then - local object = CyborgMMO_WowObject.Create(self.data[mode][button].Type, self.data[mode][button].Detail, self.data[mode][button].Subdetail) + local object = CyborgMMO_CreateWowObject(self.data[mode][button].Type, self.data[mode][button].Detail, self.data[mode][button].Subdetail) self:SetObjectOnButtonNoUpdate(button, mode, object) else - local object = CyborgMMO_WowObject.Create("", "", "") + local object = CyborgMMO_CreateWowObject("", "", "") self:SetObjectOnButtonNoUpdate(button, mode, object) self.data[mode][button] = object end @@ -121,7 +121,7 @@ self.data[mode][button] = object if object then - object.SetBinding(CyborgMMO_WowCommands[((mode-1)*RAT7.BUTTONS)+button]) + object:SetBinding(CyborgMMO_WowCommands[((mode-1)*RAT7.BUTTONS)+button]) if("callback" == object.Type) then CyborgMMO_DPrint("trying to set texture") local slot = getglobal("CyborgMMO_MainPageSlotListSlot"..button) @@ -129,7 +129,7 @@ end else CyborgMMO_DPrint("clearing "..button) - CyborgMMO_WowObject.ClearBinding(CyborgMMO_WowCommands[((mode-1)*RAT7.BUTTONS)+button]) + CyborgMMO_ClearBinding(CyborgMMO_WowCommands[((mode-1)*RAT7.BUTTONS)+button]) end end
--- a/WowObjects.lua Thu Apr 25 01:30:41 2013 +0000 +++ b/WowObjects.lua Thu Apr 25 01:30:46 2013 +0000 @@ -18,67 +18,320 @@ --~ along with this program; if not, write to the Free Software --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -CyborgMMO_WowObject = { - new = function(type, detail, subdetail) - local self = {} - self.Texture = nil - self.Name = "NoName" - self.Type = type - self.Detail = detail - self.Subdetail = subdetail +------------------------------------------------------------------------------ - -- Methods -- - self.DoAction = function() - CyborgMMO_DPrint("Nothing To Do") +local WowObject_methods = {} +local WowObject_mt = {__index=WowObject_methods} + +local function WowObject(type, detail, subdetail) + local self = {} + + self.Texture = nil + self.Name = "NoName" + self.Type = type + self.Detail = detail + self.Subdetail = subdetail + + setmetatable(self, WowObject_mt) + + return self +end + +function WowObject_methods:DoAction() + CyborgMMO_DPrint("Nothing To Do") +end + +function WowObject_methods:Pickup() + CyborgMMO_DPrint("Pick up Item") +end + +function WowObject_methods:SetBinding(key) +end + +function WowObject_methods:PlaySound() + PlaySound("igAbilityIconDrop") +end + +------------------------------------------------------------------------------ + +local WowCallback_methods = setmetatable({}, {__index=WowObject_methods}) +local WowCallback_mt = {__index=WowCallback_methods} + +local function WowCallback(callbackName) + local self = WowObject("callback", callbackName, "") + + self.CallbackName = callbackName + self.Texture = "Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga" + + setmetatable(self, WowCallback_mt) + + return self +end + +function WowCallback_methods:SetTextures(buttonFrame) + CyborgMMO_DPrint("TextureName = "..self.CallbackName) + buttonFrame:SetNormalTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga") + buttonFrame:SetPushedTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Down.tga") + buttonFrame:SetHighlightTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Over.tga") +end + +function WowCallback_methods:DoAction() + local action = CyborgMMO_CallbackFactory:GetCallback(self.CallbackName) + CyborgMMO_DPrint("calling callback:- "..self.CallbackName) + action() +end + +function WowCallback_methods:PickupCallback() + local slot = nil + local observers = CyborgMMO_RatPageModel:GetAllObservers() + for i=1,#observers do + if MouseIsOver(observers[i]) then + slot = observers[i] + break end + end + slot:SetNormalTexture(slot.UnCheckedTexture) +end - self.Pickup = function() - CyborgMMO_DPrint("Pick up Item") - end +function WowCallback_methods:Pickup() + self:PlaySound() + ClearCursor() + self:PickupCallback() +end - self.SetBinding = function(key) - end +function WowCallback_methods:SetBinding(key) + local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function(...) return self:DoAction(...) end) + SetOverrideBindingClick(CyborgMMO_CallbackFactory.Frame, true, key, name, "LeftButton") +end - self.PlaySound = function() - PlaySound("igAbilityIconDrop") - end +------------------------------------------------------------------------------ - return self - end, +local WowItem_methods = setmetatable({}, {__index=WowObject_methods}) +local WowItem_mt = {__index=WowItem_methods} - ClearBinding = function(key) - SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, nil) - end, +local function WowItem(number, itemID) + local self = WowObject("item", number, itemID) - -- Static Methods -- - Create = function(objectType, detail, subdetail) - local object - if objectType == "item" then - object = CyborgMMO_WowItem.new(detail, subdetail) - elseif objectType == "macro" then - object = CyborgMMO_WowMacro.new(detail) - elseif objectType == "spell" then - object = CyborgMMO_WowSpell.new(objectType, detail, subdetail) - elseif objectType == "petaction" then - object = CyborgMMO_WowSpell.new(objectType, detail, subdetail) - elseif objectType == "merchant" then - object = CyborgMMO_SlotMerchant.new(detail, subdetail) - elseif objectType == "companion" then - object = CyborgMMO_WowCompanion.new(detail, subdetail) - elseif objectType == "equipmentset" then - object = CyborgMMO_WowEquipmentSet.new(objectType, detail, subdetail) - elseif objectType == "callback" then - object = CyborgMMO_WowCallback.new(detail) - else - object = CyborgMMO_WowObject.new(objectType, detail, subdetail) - end + self.Name, + self.Link, + self.Rarity, + self.Level, + self.MinLevel, + self.Type, + self.SubType, + self.StackCount, + self.EquipLoc, + self.Texture, + self.SellPrice = GetItemInfo(itemID) - return object - end, -} + setmetatable(self, WowItem_mt) -local CallbackCursor = nil + return self +end +function WowItem_methods:DoAction() + CyborgMMO_DPrint("Use Item") +end + +function WowItem_methods:Pickup() + self:PlaySound() + ClearCursor() +-- SetCursor(self.Texture) + return PickupItem(self.Link) +end + +function WowItem_methods:SetBinding(key) + SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "ITEM "..self.Name) +end + +------------------------------------------------------------------------------ + +local WowSpell_methods = setmetatable({}, {__index=WowObject_methods}) +local WowSpell_mt = {__index=WowSpell_methods} + +local function WowSpell(type, spellbookID, spellbook) + local self = WowObject(type, spellbookID, spellbook) + + self.SpellbookID = spellbookID + self.Spellbook = spellbook + self.Name,self.Rank = GetSpellBookItemName(spellbookID, spellbook) + self.Texture = GetSpellBookItemTexture(spellbookID, spellbook) + self.Type = type + + setmetatable(self, WowSpell_mt) + + return self +end + +function WowSpell_methods:DoAction() + CyborgMMO_DPrint("Cast Spell") +end + +function WowSpell_methods:Pickup() + self:PlaySound() + ClearCursor() +-- SetCursor(self.Texture) + return PickupSpellBookItem(self.SpellbookID, self.Spellbook) +end + +function WowSpell_methods:SetBinding(key) + CyborgMMO_DPrint("Binding to key "..key) + self.Key = key + SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, self.Key, self.Type.." "..self.Name) +end + +------------------------------------------------------------------------------ + +local WowMacro_methods = setmetatable({}, {__index=WowObject_methods}) +local WowMacro_mt = {__index=WowMacro_methods} + +local function WowMacro(index) + local self = WowObject("macro", index, nil) + + self.Name, + self.Texture, + self.Body, + self.isLocal = GetMacroInfo(index) + self.Index = index + + setmetatable(self, WowMacro_mt) + + return self +end + +function WowMacro_methods:DoAction() + CyborgMMO_DPrint("Use Item") +end + +function WowMacro_methods:Pickup() + self:PlaySound() + ClearCursor() +-- SetCursor(self.Texture) + return PickupMacro(self.Index) +end + +function WowMacro_methods:SetBinding(key) + self.Key = key + SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "MACRO "..self.Index) +end + +------------------------------------------------------------------------------ + +local WowCompanion_methods = setmetatable({}, {__index=WowObject_methods}) +local WowCompanion_mt = {__index=WowCompanion_methods} + +local function WowCompanion(index, SubType) + local self = WowObject("companion", index, SubType) + + self.Id, + self.Name, + self.SpellId, + self.Texture, + self.isSummoned = GetCompanionInfo(SubType, index) + self.SubType = SubType + self.index = index + + setmetatable(self, WowCompanion_mt) + + return self +end + +function WowCompanion_methods:DoAction() + if self.SubType == "MOUNT" and IsMounted() then + Dismount() + else + CallCompanion(self.SubType, self.index) + end +end + +function WowCompanion_methods:Pickup() + self:PlaySound() + return PickupCompanion(self.SubType, self.index) +end + +function WowCompanion_methods:SetBinding(key) + self.Key = key + local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function() self:DoAction() end) + SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") +-- SetOverrideBinding(hiddenModeChanger, true, key, "MACRO "..self.Index) +end + +------------------------------------------------------------------------------ + +local WowMerchant_methods = setmetatable({}, {__index=WowObject_methods}) +local WowMerchant_mt = {__index=WowMerchant_methods} + +local function WowMerchant(index) + local self = WowObject("merchant", index, nil) + + self.Name, + self.Texture, + self.Price, + self.Quantity, + self.NumAvailable, + self.IsUsable, + self.ExtendedCost = GetMerchantItemInfo(index) + self.Index = index + + setmetatable(self, WowMerchant_mt) + + return self +end + +function WowMerchant_methods:DoAction() + CyborgMMO_DPrint("Use Item") +end + +function WowMerchant_methods:Pickup() + self:PlaySound() + ClearCursor() +-- SetCursor(self.Texture) + return PickupMerchantItem(self.Index) +end + +function WowMerchant_methods:SetBinding(key) + self.Key = key + SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "MERCHANT "..self.Index) +end + +------------------------------------------------------------------------------ + +local WowEquipmentSet_methods = setmetatable({}, {__index=WowObject_methods}) +local WowEquipmentSet_mt = {__index=WowEquipmentSet_methods} + +local function WowEquipmentSet(objectType, name, index) + local self = WowObject(objectType, name, index) + + local texture,lessIndex = GetEquipmentSetInfoByName(name) + self.Texture = "Interface\\Icons\\"..texture + self.Name = name + self.Index = lessIndex + 1 + + setmetatable(self, WowEquipmentSet_mt) + + return self +end + +function WowEquipmentSet_methods:DoAction() + UseEquipmentSet(self.Name) +end + +function WowEquipmentSet_methods:Pickup() + self:PlaySound() + ClearCursor() +-- SetCursor(self.Texture) + return PickupEquipmentSetByName(self.Name) +end + +function WowEquipmentSet_methods:SetBinding(key) + self.Key = key + local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function() self:DoAction() end); + SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") +end + +------------------------------------------------------------------------------ + +-- this class is used by pre-defined icons in the corner of the Rat page CyborgMMO_CallbackIcons = { new = function(self) self.point, @@ -88,13 +341,13 @@ self.yOfs = self:GetPoint() -- self:SetPoint(self.point, self.relativeTo, self.relativePoint, self.xOfs, self.yOfs) self.strata = self:GetFrameStrata() - self.wowObject = CyborgMMO_WowCallback.new(string.gsub(self:GetName(), self:GetParent():GetName(), "",1)) - self.wowObject.SetTextures(self) + self.wowObject = WowCallback(string.gsub(self:GetName(), self:GetParent():GetName(), "",1)) + self.wowObject:SetTextures(self) self:RegisterForDrag("LeftButton","RightButton") self:SetResizable(false) self.OnClick = function() - self.wowObject.DoAction() + self.wowObject:DoAction() end self.DragStart = function() @@ -120,268 +373,35 @@ end, } -CyborgMMO_WowCallback = { - new = function(callbackName) - local self = CyborgMMO_WowObject.new("callback", callbackName, "") - self.CallbackName = callbackName - self.Texture = "Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga" +------------------------------------------------------------------------------ - self.SetTextures = function(buttonFrame) - CyborgMMO_DPrint("TextureName = "..self.CallbackName) - buttonFrame:SetNormalTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga") - buttonFrame:SetPushedTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Down.tga") - buttonFrame:SetHighlightTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Over.tga") - end +function CyborgMMO_CreateWowObject(type, ...) + local object - self.DoAction = function() - local action = CyborgMMO_CallbackFactory:GetCallback(self.CallbackName) - CyborgMMO_DPrint("calling callback:- "..self.CallbackName) - action() - end + if type == "item" then + object = WowItem(...) + elseif type == "macro" then + object = WowMacro(...) + elseif type == "spell" then + object = WowSpell(type, ...) + elseif type == "petaction" then + object = WowSpell(type, ...) + elseif type == "merchant" then + object = WowMerchant(...) + elseif type == "companion" then + object = WowCompanion(...) + elseif type == "equipmentset" then + object = WowEquipmentSet(type, ...) + elseif type == "callback" then + object = WowCallback(...) + else + object = WowObject(type, ...) + end - self.PickupCallback = function() - local slot = nil - local observers = CyborgMMO_RatPageModel:GetAllObservers() - for i=1,#observers do - if MouseIsOver(observers[i]) then - slot = observers[i] - break - end - end - slot:SetNormalTexture(slot.UnCheckedTexture) - end + return object +end - self.ClickHandler = function(self, button, down) - CyborgMMO_DPrint("click handler") - CallbackCursor:StopMoving() - CallbackCursor:Hide() - end +function CyborgMMO_ClearBinding(key) + SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, nil) +end - self.Pickup = function() - self.PlaySound() - ClearCursor() - self.PickupCallback() - end - - self.SetBinding = function(key) - local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(self.DoAction) - SetOverrideBindingClick(CyborgMMO_CallbackFactory.Frame, true, key, name, "LeftButton") - end - - return self - end, -} - --- WowItem Class -- -CyborgMMO_WowItem = { - new = function(number, itemID) - local self = CyborgMMO_WowObject.new("item", number, itemID) -- base class - -- Set all the item info. -- - self.Name, - self.Link, - self.Rarity, - self.Level, - self.MinLevel, - self.Type, - self.SubType, - self.StackCount, - self.EquipLoc, - self.Texture, - self.SellPrice = GetItemInfo(itemID) - - -- override method -- - self.DoAction = function() - CyborgMMO_DPrint("Use Item") - end - - -- override method -- - self.Pickup = function() - self.PlaySound() - ClearCursor() - -- SetCursor(self.Texture) - return PickupItem(self.Link) - end - - self.SetBinding = function(key) - SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "ITEM "..self.Name) - end - - return self - end, -} - --- WowSpell Class -- -CyborgMMO_WowSpell = { - new = function(type, spellbookID, spellbook) - local self = CyborgMMO_WowObject.new(type, spellbookID, spellbook) -- base class - self.SpellbookID = spellbookID - self.Spellbook = spellbook - self.Name,self.Rank = GetSpellBookItemName(spellbookID, spellbook) - self.Texture = GetSpellBookItemTexture(spellbookID, spellbook) - self.Type = type - - - -- override method -- - self.DoAction = function() - CyborgMMO_DPrint("Cast Spell") - end - - -- override method -- - self.Pickup = function() - self.PlaySound() - ClearCursor() - -- SetCursor(self.Texture) - return PickupSpellBookItem(self.SpellbookID, self.Spellbook) - end - - self.SetBinding = function(key) - CyborgMMO_DPrint("Binding to key "..key) - self.Key = key - SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, self.Key, self.Type.." "..self.Name) - end - - return self - end, -} - --- WowMacro Class -- -CyborgMMO_WowMacro = { - new = function(index) - local self = CyborgMMO_WowObject.new("macro", index, nil) -- base class - -- Set all the item info. -- - self.Name, - self.Texture, - self.Body, - self.isLocal = GetMacroInfo(index) - self.Index = index - - -- override method -- - self.DoAction = function() - CyborgMMO_DPrint("Use Item") - end - - -- override method -- - self.Pickup = function() - self.PlaySound() - ClearCursor() - -- SetCursor(self.Texture) - return PickupMacro(self.Index) - end - - self.SetBinding = function(key) - self.Key = key - SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "MACRO "..self.Index) - end - - return self - end, -} - --- WowCompanion Class -- -CyborgMMO_WowCompanion = { - new = function(index, SubType) - local self = CyborgMMO_WowObject.new("companion", index, SubType) -- base class - -- Set all the item info. -- - self.Id, - self.Name, - self.SpellId, - self.Texture, - self.isSummoned = GetCompanionInfo(SubType, index) - self.SubType = SubType - self.index = index - -- override method -- - self.DoAction = function() - if self.SubType == "MOUNT" and IsMounted() then - Dismount() - else - CallCompanion(self.SubType, self.index) - end - end - - -- override method -- - self.Pickup = function() - self.PlaySound() - return PickupCompanion(self.SubType, self.index) - end - - self.SetBinding = function(key) - self.Key = key - local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(self.DoAction) - SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") - -- SetOverrideBinding(hiddenModeChanger, true, key, "MACRO "..self.Index) - end - - return self - end, -} - --- WowMerchant Class -- -CyborgMMO_WowMerchant = { - new = function(index) - local self = CyborgMMO_WowObject.new("macro", index, nil) -- base class - -- Set all the item info. -- - self.Name, - self.Texture, - self.Price, - self.Quantity, - self.NumAvailable, - self.IsUsable, - self.ExtendedCost = GetMerchantItemInfo(index) - self.Index = index - - -- override method -- - self.DoAction = function() - CyborgMMO_DPrint("Use Item") - end - - -- override method -- - self.Pickup = function() - self.PlaySound() - ClearCursor() - -- SetCursor(self.Texture) - return PickupMerchantItem(self.Index) - end - - self.SetBinding = function(key) - self.Key = key - SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "MERCHANT "..self.Index) - end - - return self - end, -} - --- WowEquipmentSet Class -- -CyborgMMO_WowEquipmentSet = { - new = function(objectType, name, index) - local self = CyborgMMO_WowObject.new(objectType, name, index) -- base class - -- Set all the item info. -- - local texture,lessIndex = GetEquipmentSetInfoByName(name) - self.Texture = "Interface\\Icons\\"..texture - self.Name = name - self.Index = lessIndex + 1 - - -- override method -- - self.DoAction = function() - UseEquipmentSet(self.Name) - end - - -- override method -- - self.Pickup = function() - self.PlaySound() - ClearCursor() - -- SetCursor(self.Texture) - return PickupEquipmentSetByName(self.Name) - end - - self.SetBinding = function(key) - self.Key = key - local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(self.DoAction); - SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") - end - - return self - end, -} - --- End Of WowObjects --