Mercurial > wow > cyborg-mmo7
comparison WowObjects.lua @ 34:6ce173840e68
Reworked the whole "wow object" system:
- Only save what is strictly necessary.
- Save appropriate persistent information for all objects (like spellIDs instead of spellBook+spellIndex).
- Fixed Battle Pets objects (non-combat pets in pre-MoP).
- Fixed item objects.
- Cleaned and simplified most objects implementation.
- Moved the settings and button profile to the root of the saved data, rather than in a per-character sub-table (that data is already tagged as saved per character).
This should fix most issues with objects changing without user interaction on diverse occasions.
Old profiles are not converted to the new system. This will come soon.
Some issues persist due to the asynchronous loading of some informations:
- Pet icons are never properly loaded from saved data.
- Items are not properly loaded the first time the UI is started (a "/reload ui" or disconnect/connect cycle fixes this problem).
author | madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09 |
---|---|
date | Thu, 25 Apr 2013 01:31:31 +0000 |
parents | 1c0af1810e06 |
children | d12a5a7d2be5 |
comparison
equal
deleted
inserted
replaced
33:1c0af1810e06 | 34:6ce173840e68 |
---|---|
24 local WowObject_mt = {__index=WowObject_methods} | 24 local WowObject_mt = {__index=WowObject_methods} |
25 | 25 |
26 local function WowObject(type, detail, subdetail) | 26 local function WowObject(type, detail, subdetail) |
27 local self = {} | 27 local self = {} |
28 | 28 |
29 self.Texture = nil | 29 self.type = type |
30 self.Name = "NoName" | 30 self.detail = detail |
31 self.Type = type | 31 self.subdetail = subdetail |
32 self.Detail = detail | |
33 self.Subdetail = subdetail | |
34 | 32 |
35 setmetatable(self, WowObject_mt) | 33 setmetatable(self, WowObject_mt) |
36 | 34 |
37 return self | 35 return self |
36 end | |
37 | |
38 function WowObject_methods:SaveData() | |
39 return { | |
40 type = self.type, | |
41 detail = self.detail, | |
42 subdetail = self.subdetail, | |
43 } | |
38 end | 44 end |
39 | 45 |
40 function WowObject_methods:DoAction() | 46 function WowObject_methods:DoAction() |
41 CyborgMMO_DPrint("Nothing To Do") | 47 CyborgMMO_DPrint("Nothing To Do") |
42 end | 48 end |
46 end | 52 end |
47 | 53 |
48 function WowObject_methods:SetBinding(key) | 54 function WowObject_methods:SetBinding(key) |
49 end | 55 end |
50 | 56 |
51 function WowObject_methods:PlaySound() | |
52 PlaySound("igAbilityIconDrop") | |
53 end | |
54 | |
55 ------------------------------------------------------------------------------ | 57 ------------------------------------------------------------------------------ |
56 | 58 |
57 local WowCallback_methods = setmetatable({}, {__index=WowObject_methods}) | 59 local WowCallback_methods = setmetatable({}, {__index=WowObject_methods}) |
58 local WowCallback_mt = {__index=WowCallback_methods} | 60 local WowCallback_mt = {__index=WowCallback_methods} |
59 | 61 |
60 local function WowCallback(callbackName) | 62 local function WowCallback(callbackName) |
61 local self = WowObject("callback", callbackName, "") | 63 local self = WowObject("callback", callbackName, "") |
62 | 64 |
63 self.CallbackName = callbackName | 65 self.callbackName = callbackName |
64 self.Texture = "Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga" | 66 self.texture = "Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.callbackName.."Unselected.tga" |
65 | 67 |
66 setmetatable(self, WowCallback_mt) | 68 setmetatable(self, WowCallback_mt) |
67 | 69 |
68 return self | 70 return self |
69 end | 71 end |
70 | 72 |
71 function WowCallback_methods:SetTextures(buttonFrame) | 73 function WowCallback_methods:SetTextures(buttonFrame) |
72 CyborgMMO_DPrint("TextureName = "..self.CallbackName) | 74 buttonFrame:SetNormalTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.callbackName.."Unselected.tga") |
73 buttonFrame:SetNormalTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Unselected.tga") | 75 buttonFrame:SetPushedTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.callbackName.."Down.tga") |
74 buttonFrame:SetPushedTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Down.tga") | 76 buttonFrame:SetHighlightTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.callbackName.."Over.tga") |
75 buttonFrame:SetHighlightTexture("Interface\\AddOns\\CyborgMMO7\\Graphics\\"..self.CallbackName.."Over.tga") | |
76 end | 77 end |
77 | 78 |
78 function WowCallback_methods:DoAction() | 79 function WowCallback_methods:DoAction() |
79 local action = CyborgMMO_CallbackFactory:GetCallback(self.CallbackName) | 80 local action = CyborgMMO_CallbackFactory:GetCallback(self.callbackName) |
80 CyborgMMO_DPrint("calling callback:- "..self.CallbackName) | |
81 action() | 81 action() |
82 end | 82 end |
83 | 83 |
84 function WowCallback_methods:PickupCallback() | 84 function WowCallback_methods:PickupCallback() |
85 local slot = nil | 85 local slot = nil |
92 end | 92 end |
93 slot:SetNormalTexture(slot.UnCheckedTexture) | 93 slot:SetNormalTexture(slot.UnCheckedTexture) |
94 end | 94 end |
95 | 95 |
96 function WowCallback_methods:Pickup() | 96 function WowCallback_methods:Pickup() |
97 self:PlaySound() | 97 PlaySound("igAbilityIconDrop") |
98 ClearCursor() | 98 ClearCursor() |
99 self:PickupCallback() | 99 self:PickupCallback() |
100 end | 100 end |
101 | 101 |
102 function WowCallback_methods:SetBinding(key) | 102 function WowCallback_methods:SetBinding(key) |
107 ------------------------------------------------------------------------------ | 107 ------------------------------------------------------------------------------ |
108 | 108 |
109 local WowItem_methods = setmetatable({}, {__index=WowObject_methods}) | 109 local WowItem_methods = setmetatable({}, {__index=WowObject_methods}) |
110 local WowItem_mt = {__index=WowItem_methods} | 110 local WowItem_mt = {__index=WowItem_methods} |
111 | 111 |
112 local function WowItem(number, itemID) | 112 local function WowItem(itemID) |
113 local self = WowObject("item", number, itemID) | 113 local self = WowObject("item", itemID) |
114 | 114 |
115 self.Name, | 115 self.itemID = itemID |
116 self.Link, | 116 self.texture = select(10, GetItemInfo(itemID)) -- :FIXME: this may fail too early in the session (like when loading saved data) |
117 self.Rarity, | |
118 self.Level, | |
119 self.MinLevel, | |
120 self.Type, | |
121 self.SubType, | |
122 self.StackCount, | |
123 self.EquipLoc, | |
124 self.Texture, | |
125 self.SellPrice = GetItemInfo(itemID) | |
126 | 117 |
127 setmetatable(self, WowItem_mt) | 118 setmetatable(self, WowItem_mt) |
128 | 119 |
129 return self | 120 return self |
130 end | 121 end |
131 | 122 |
132 function WowItem_methods:DoAction() | |
133 CyborgMMO_DPrint("Use Item") | |
134 end | |
135 | |
136 function WowItem_methods:Pickup() | 123 function WowItem_methods:Pickup() |
137 self:PlaySound() | 124 -- PlaySound("igAbilityIconDrop") |
138 ClearCursor() | 125 ClearCursor() |
139 -- SetCursor(self.Texture) | 126 -- SetCursor(self.texture) |
140 return PickupItem(self.Link) | 127 return PickupItem(self.itemID) |
141 end | 128 end |
142 | 129 |
143 function WowItem_methods:SetBinding(key) | 130 function WowItem_methods:SetBinding(key) |
144 SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "ITEM "..self.Name) | 131 local name = GetItemInfo(self.itemID) |
132 SetOverrideBindingItem(CyborgMMO_CallbackFactory.Frame, true, key, name) | |
145 end | 133 end |
146 | 134 |
147 ------------------------------------------------------------------------------ | 135 ------------------------------------------------------------------------------ |
148 | 136 |
149 local WowSpell_methods = setmetatable({}, {__index=WowObject_methods}) | 137 local WowSpell_methods = setmetatable({}, {__index=WowObject_methods}) |
150 local WowSpell_mt = {__index=WowSpell_methods} | 138 local WowSpell_mt = {__index=WowSpell_methods} |
151 | 139 |
152 local function WowSpell(spellbookID, spellbook) | 140 local function WowSpell(spellID) |
153 local self = WowObject("spell", spellbookID, spellbook) | 141 local self = WowObject("spell", spellID) |
154 | 142 |
155 self.SpellbookID = spellbookID | 143 self.spellID = spellID |
156 self.Spellbook = spellbook | 144 self.texture = GetSpellTexture(spellID) |
157 self.Name,self.Rank = GetSpellBookItemName(spellbookID, spellbook) | |
158 self.Texture = GetSpellBookItemTexture(spellbookID, spellbook) | |
159 | 145 |
160 setmetatable(self, WowSpell_mt) | 146 setmetatable(self, WowSpell_mt) |
161 | 147 |
162 return self | 148 return self |
163 end | 149 end |
165 function WowSpell_methods:DoAction() | 151 function WowSpell_methods:DoAction() |
166 CyborgMMO_DPrint("Cast Spell") | 152 CyborgMMO_DPrint("Cast Spell") |
167 end | 153 end |
168 | 154 |
169 function WowSpell_methods:Pickup() | 155 function WowSpell_methods:Pickup() |
170 self:PlaySound() | 156 -- PlaySound("igAbilityIconDrop") |
171 ClearCursor() | 157 ClearCursor() |
172 -- SetCursor(self.Texture) | 158 -- SetCursor(self.texture) |
173 return PickupSpellBookItem(self.SpellbookID, self.Spellbook) | 159 -- return PickupSpellBookItem(self.SpellbookID, self.Spellbook) |
160 return PickupSpell(self.spellID) | |
174 end | 161 end |
175 | 162 |
176 function WowSpell_methods:SetBinding(key) | 163 function WowSpell_methods:SetBinding(key) |
177 CyborgMMO_DPrint("Binding to key "..key) | 164 -- CyborgMMO_DPrint("Binding to key "..key) |
178 self.Key = key | 165 local name = GetSpellInfo(self.spellID) |
179 SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, self.Key, self.Type.." "..self.Name) | 166 CyborgMMO_DPrint("binding spell:", self.spellID, name) |
167 SetOverrideBindingSpell(CyborgMMO_CallbackFactory.Frame, true, key, name) | |
180 end | 168 end |
181 | 169 |
182 ------------------------------------------------------------------------------ | 170 ------------------------------------------------------------------------------ |
183 | 171 |
184 local WowMacro_methods = setmetatable({}, {__index=WowObject_methods}) | 172 local WowMacro_methods = setmetatable({}, {__index=WowObject_methods}) |
185 local WowMacro_mt = {__index=WowMacro_methods} | 173 local WowMacro_mt = {__index=WowMacro_methods} |
186 | 174 |
187 local function WowMacro(index) | 175 local function WowMacro(name) |
188 local self = WowObject("macro", index, nil) | 176 local self = WowObject("macro", name) |
189 | 177 |
190 self.Name, | 178 self.name = name |
191 self.Texture, | 179 self.texture = select(2, GetMacroInfo(name)) |
192 self.Body, | |
193 self.isLocal = GetMacroInfo(index) | |
194 self.Index = index | |
195 | 180 |
196 setmetatable(self, WowMacro_mt) | 181 setmetatable(self, WowMacro_mt) |
197 | 182 |
198 return self | 183 return self |
199 end | 184 end |
201 function WowMacro_methods:DoAction() | 186 function WowMacro_methods:DoAction() |
202 CyborgMMO_DPrint("Use Item") | 187 CyborgMMO_DPrint("Use Item") |
203 end | 188 end |
204 | 189 |
205 function WowMacro_methods:Pickup() | 190 function WowMacro_methods:Pickup() |
206 self:PlaySound() | 191 -- PlaySound("igAbilityIconDrop") |
207 ClearCursor() | 192 ClearCursor() |
208 -- SetCursor(self.Texture) | 193 -- SetCursor(self.texture) |
209 return PickupMacro(self.Index) | 194 return PickupMacro(self.name) |
210 end | 195 end |
211 | 196 |
212 function WowMacro_methods:SetBinding(key) | 197 function WowMacro_methods:SetBinding(key) |
213 self.Key = key | 198 SetOverrideBindingMacro(CyborgMMO_CallbackFactory.Frame, true, key, self.name) |
214 SetOverrideBinding(CyborgMMO_CallbackFactory.Frame, true, key, "MACRO "..self.Index) | |
215 end | 199 end |
216 | 200 |
217 ------------------------------------------------------------------------------ | 201 ------------------------------------------------------------------------------ |
218 | 202 |
219 local WowCompanion_methods = setmetatable({}, {__index=WowObject_methods}) | 203 local WowCompanion_methods = setmetatable({}, {__index=WowObject_methods}) |
220 local WowCompanion_mt = {__index=WowCompanion_methods} | 204 local WowCompanion_mt = {__index=WowCompanion_methods} |
221 | 205 |
222 local function WowCompanion(index, SubType) | 206 local function WowCompanion(spellID) |
223 local self = WowObject("companion", index, SubType) | 207 local self = WowObject("companion", spellID) |
224 | 208 CyborgMMO_DPrint("creating companion binding:", type, spellID) |
225 self.Id, | 209 |
226 self.Name, | 210 self.spellID = spellID |
227 self.SpellId, | 211 self.texture = select(3, GetSpellInfo(spellID)) |
228 self.Texture, | |
229 self.isSummoned = GetCompanionInfo(SubType, index) | |
230 self.SubType = SubType | |
231 self.index = index | |
232 | 212 |
233 setmetatable(self, WowCompanion_mt) | 213 setmetatable(self, WowCompanion_mt) |
234 | 214 |
235 return self | 215 return self |
236 end | 216 end |
237 | 217 |
218 local function IdentifyCompanion(spellID) | |
219 for _,subtype in ipairs{'MOUNT', 'CRITTER'} do | |
220 for index=1,GetNumCompanions(subtype) do | |
221 local spellID2,_,active = select(3, GetCompanionInfo(subtype, index)) | |
222 if spellID2 == spellID then | |
223 return subtype,index,active | |
224 end | |
225 end | |
226 end | |
227 end | |
228 | |
238 function WowCompanion_methods:DoAction() | 229 function WowCompanion_methods:DoAction() |
239 if self.SubType == "MOUNT" and IsMounted() then | 230 local subtype,index,active = IdentifyCompanion(self.spellID) |
231 -- if subtype == "MOUNT" and IsMounted() then | |
232 if subtype == "MOUNT" and active then | |
240 Dismount() | 233 Dismount() |
241 else | 234 elseif subtype and index then |
242 CallCompanion(self.SubType, self.index) | 235 CallCompanion(subtype, index) |
243 end | 236 end |
244 end | 237 end |
245 | 238 |
246 function WowCompanion_methods:Pickup() | 239 function WowCompanion_methods:Pickup() |
247 self:PlaySound() | 240 -- PlaySound("igAbilityIconDrop") |
248 return PickupCompanion(self.SubType, self.index) | 241 local subtype,index = IdentifyCompanion(self.spellID) |
242 if subtype and index then | |
243 return PickupCompanion(subtype, index) | |
244 end | |
249 end | 245 end |
250 | 246 |
251 function WowCompanion_methods:SetBinding(key) | 247 function WowCompanion_methods:SetBinding(key) |
252 self.Key = key | |
253 local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function() self:DoAction() end) | 248 local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function() self:DoAction() end) |
254 SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") | 249 SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") |
255 -- SetOverrideBinding(hiddenModeChanger, true, key, "MACRO "..self.Index) | |
256 end | 250 end |
257 | 251 |
258 ------------------------------------------------------------------------------ | 252 ------------------------------------------------------------------------------ |
259 | 253 |
260 local WowEquipmentSet_methods = setmetatable({}, {__index=WowObject_methods}) | 254 local WowEquipmentSet_methods = setmetatable({}, {__index=WowObject_methods}) |
261 local WowEquipmentSet_mt = {__index=WowEquipmentSet_methods} | 255 local WowEquipmentSet_mt = {__index=WowEquipmentSet_methods} |
262 | 256 |
263 local function WowEquipmentSet(objectType, name, index) | 257 local function WowEquipmentSet(name) |
264 local self = WowObject(objectType, name, index) | 258 local self = WowObject("equipmentset", name) |
265 | 259 |
266 local texture,lessIndex = GetEquipmentSetInfoByName(name) | 260 self.name = name |
267 self.Texture = "Interface\\Icons\\"..texture | 261 local texture = GetEquipmentSetInfoByName(name) |
268 self.Name = name | 262 self.texture = "Interface\\Icons\\"..texture |
269 self.Index = lessIndex + 1 | |
270 | 263 |
271 setmetatable(self, WowEquipmentSet_mt) | 264 setmetatable(self, WowEquipmentSet_mt) |
272 | 265 |
273 return self | 266 return self |
274 end | 267 end |
275 | 268 |
276 function WowEquipmentSet_methods:DoAction() | 269 function WowEquipmentSet_methods:DoAction() |
277 UseEquipmentSet(self.Name) | 270 UseEquipmentSet(self.name) |
278 end | 271 end |
279 | 272 |
280 function WowEquipmentSet_methods:Pickup() | 273 function WowEquipmentSet_methods:Pickup() |
281 self:PlaySound() | 274 -- PlaySound("igAbilityIconDrop") |
282 ClearCursor() | 275 ClearCursor() |
283 -- SetCursor(self.Texture) | 276 -- SetCursor(self.texture) |
284 return PickupEquipmentSetByName(self.Name) | 277 return PickupEquipmentSetByName(self.Name) |
285 end | 278 end |
286 | 279 |
287 function WowEquipmentSet_methods:SetBinding(key) | 280 function WowEquipmentSet_methods:SetBinding(key) |
288 self.Key = key | 281 local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function() self:DoAction() end) |
289 local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function() self:DoAction() end); | 282 SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") |
283 end | |
284 | |
285 ------------------------------------------------------------------------------ | |
286 | |
287 local WowBattlePet_methods = setmetatable({}, {__index=WowObject_methods}) | |
288 local WowBattlePet_mt = {__index=WowBattlePet_methods} | |
289 | |
290 local function WowBattlePet(petID) | |
291 local self = WowObject("battlepet", petID) | |
292 CyborgMMO_DPrint("creating battle pet binding:", petID) | |
293 | |
294 self.petID = petID | |
295 self.texture = select(9, C_PetJournal.GetPetInfoByPetID(petID)) -- :FIXME: this may fail too early in the session (like when loading saved data) | |
296 | |
297 setmetatable(self, WowBattlePet_mt) | |
298 | |
299 return self | |
300 end | |
301 | |
302 --[[ | |
303 local function IdentifyPet(petID) | |
304 local creatureID = select(11, C_PetJournal.GetPetInfoByPetID(petID)) | |
305 for index=1,GetNumCompanions('CRITTER') do | |
306 local creatureID2,_,spellID = GetCompanionInfo('CRITTER', index) | |
307 if creatureID2 == creatureID then | |
308 return spellID | |
309 end | |
310 end | |
311 end | |
312 --]] | |
313 | |
314 function WowBattlePet_methods:DoAction() | |
315 -- PlaySound("igMainMenuOptionCheckBoxOn") | |
316 C_PetJournal.SummonPetByGUID(self.petID) | |
317 end | |
318 | |
319 function WowBattlePet_methods:Pickup() | |
320 -- PlaySound("igAbilityIconDrop") | |
321 return C_PetJournal.PickupPet(self.petID) | |
322 end | |
323 | |
324 function WowBattlePet_methods:SetBinding(key) | |
325 local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory:AddCallback(function() self:DoAction() end) | |
290 SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") | 326 SetOverrideBindingClick(parentFrame, true, key, name, "LeftButton") |
291 end | 327 end |
292 | 328 |
293 ------------------------------------------------------------------------------ | 329 ------------------------------------------------------------------------------ |
294 | 330 |
338 | 374 |
339 function CyborgMMO_CreateWowObject(type, ...) | 375 function CyborgMMO_CreateWowObject(type, ...) |
340 local object | 376 local object |
341 | 377 |
342 if type == "item" then | 378 if type == "item" then |
343 object = WowItem(...) | 379 -- :KLUDGE: if the item is not in the cache, return an empty WowObject |
380 local id = ... | |
381 if not GetItemInfo(id) then | |
382 object = WowObject() | |
383 else | |
384 object = WowItem(...) | |
385 end | |
344 elseif type == "macro" then | 386 elseif type == "macro" then |
345 object = WowMacro(...) | 387 object = WowMacro(...) |
346 elseif type == "spell" then | 388 elseif type == "spell" then |
347 object = WowSpell(...) | 389 object = WowSpell(...) |
348 elseif type == "companion" then | 390 elseif type == "companion" then |
349 object = WowCompanion(...) | 391 object = WowCompanion(...) |
350 elseif type == "equipmentset" then | 392 elseif type == "equipmentset" then |
351 object = WowEquipmentSet(type, ...) | 393 object = WowEquipmentSet(...) |
394 elseif type == "battlepet" then | |
395 object = WowBattlePet(...) | |
352 elseif type == "callback" then | 396 elseif type == "callback" then |
353 object = WowCallback(...) | 397 object = WowCallback(...) |
354 else | 398 else |
355 object = WowObject(type, ...) | 399 object = WowObject(type, ...) |
356 end | 400 end |