vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- |
2 | -- EquipCompare by Legorol |
||
3 | -- Version: 2.9.7 |
||
4 | -- Email: legorol@cosmosui.org |
||
5 | -- |
||
6 | -- Equipment comparison tooltips, not just at the merchant. If you hover over |
||
7 | -- any item in places like your bag, quest reward page or loot window, you |
||
8 | -- get a comparison tooltip showing the item of that type that you currently |
||
9 | -- have equipped. |
||
10 | -- |
||
11 | -- Usage: |
||
12 | -- To get usage information, type /equipcompare help in-game. |
||
13 | -- |
||
14 | -- Cosmos version: $Revision: 1984 $ |
||
15 | -- Last changed on: $Date: 2005-06-29 19:15:40 +0100 (Wed, 29 Jun 2005) $ |
||
16 | -- Last changed by: $LastChangedBy: legorol $ |
||
17 | -- |
||
18 | -- Development Change Notes: |
||
19 | -- 2.9.7 |
||
20 | -- * Satellite support, legacy Sky support |
||
21 | -- * CV support extended for CV2.0, as well as retained legacy support |
||
22 | -- * Traditional Chinese localization added |
||
23 | -- 2.9.6 |
||
24 | -- * Nuked SlotIDToSlotName table |
||
25 | -- * Replaced all hardcoded slot IDs instead with strings referring to the slot |
||
26 | -- To be used with GetInventorySlotInfo to look up the ID |
||
27 | -- 2.9.5 |
||
28 | -- nothing, version numbers were getting ugly |
||
29 | -- 2.9.4k |
||
30 | -- * fix for string.find nil bug: turns out GetMouseFocus():GetName() can |
||
31 | -- return nil, presumably if focus is on world frame |
||
32 | -- 2.9.4 |
||
33 | -- * Removed CLEAR_TOOLTIP registration and instead added OnTooltipCleared hook |
||
34 | -- 2.9.3 |
||
35 | -- * Some patch 1.7 compatible updates |
||
36 | -- * Changed the way Blizzard's Shopping tooltips are disabled |
||
37 | -- * Fixed a very minor bug involving the interacion of slash commands and |
||
38 | -- Khaos options |
||
39 | -- 2.9.2 |
||
40 | -- * Load message dependent on whether running Cosmos or Standalone |
||
41 | -- 2.9.1 |
||
42 | -- * Added WeaponButton slots to exclusion list |
||
43 | -- * ShoppingTooltip overtake less aggressive, only happens over Merchant/Auction frames |
||
44 | -- 2.9 |
||
45 | -- * Added API: EC_RegisterExclusion, EC_UnregisterExclusion |
||
46 | -- * Added ability to not show comparison tooltips over registered components |
||
47 | -- * Initial Khaos support (not used for slash-command registration yet) |
||
48 | -- * Sky support for slash-command registration |
||
49 | -- * CharactersViewer minimum version increased to 55 |
||
50 | -- * Minor bugfixes in CV minimum version checking code |
||
51 | -- * Minor bugfixes when toggling Alt-mode |
||
52 | -- * Tidying up of the registrations and variable synching between Cosmos/Khaos<->EC |
||
53 | -- (Cosmos/Khaos do call my handlers once they have loaded, so no need to grab |
||
54 | -- the info from them.) |
||
55 | -- 2.8 |
||
56 | -- * Added API: EC_RegisterTooltip, EC_UnregisterTooltip, EC_GetComparisonAnchor(), |
||
57 | -- EquipCompare_RequestShift, EquipCompare_CancelShift |
||
58 | -- * Various changes to support the API |
||
59 | -- * Always override shopping tooltip |
||
60 | -- * Shifting up as an option |
||
61 | -- * GC reductions |
||
62 | -- * Crossbows/Thrown weapons at last |
||
63 | -- 2.7.1 |
||
64 | -- * Memory leak reduction |
||
65 | -- * Partial French localization for new settings (Sasmiraa) |
||
66 | -- * Feedback on slash commands |
||
67 | -- 2.7: |
||
68 | -- * Added option to disable CV integration |
||
69 | -- * Alt-key mode. |
||
70 | -- * Usage text broken up into loop instead of using new-lines |
||
71 | -- 2.6.4: |
||
72 | -- * Split localization files (sarf) |
||
73 | -- * German text fixes (StarDust) |
||
74 | -- * CV-selected player name obtained via global index variable |
||
75 | -- 2.6.2: |
||
76 | -- * German localization |
||
77 | -- * Added version ID in various places |
||
78 | -- * Tooltip widens if the "Currently Equipped" label is long |
||
79 | -- * Learnt a lot about how tooltips lay out their contents |
||
80 | -- * Neater way of adding a label, no need for invisible dummy line anymore! This |
||
81 | -- means that AddLine can be called on the tooltip even after AddLabel. |
||
82 | -- 2.6.1: |
||
83 | -- * French localization |
||
84 | -- * Minor hange in localization scheme, only so that bonus type names |
||
85 | -- are more prominently visible to those translating. |
||
86 | -- * Typo in ShowComparisonTooltip : "parent == GameToolTip" should be |
||
87 | -- small t in tip! D'oh! |
||
88 | -- 2.6: |
||
89 | -- * Have a mode in which hold Ctrl to make comparison tooltips show |
||
90 | -- 2.5: |
||
91 | -- * Introduced private comparison tooltip, lots of modifications related to this |
||
92 | -- * Added the Equipped in: slot labels |
||
93 | -- * Some tooltip placement improvements: with leftAlign, get Main Hand on left |
||
94 | -- * Core logic improvements: e.g. CLEAR_TOOLTIP only enables Recheck, but doesn't Hide |
||
95 | -- * ItemRef tooltips stick |
||
96 | -- * Charactersviewer comparisons are shown for PaperDollFrame |
||
97 | -- 2.1.1: |
||
98 | -- * Fixed a bug introduced in 2.1 causing 2nd comparison tooltip not to appear correctly |
||
99 | -- Learned that I need to anchor a tooltip before calling SetInventoryItem, even if later |
||
100 | -- I change its points. |
||
101 | -- * 2H weapons show shield as well now |
||
102 | -- 2.1: |
||
103 | -- * fix potential bug in overriding AH or Merchant tips (HideTip call wasn't actually done) |
||
104 | -- * tooltip now stands for object rather than string |
||
105 | -- * tooltip arrangement improvements |
||
106 | -- |
||
107 | -- Development Todo: |
||
108 | -- * If you view an off-hand item, and you have 2H item equipped, show it. |
||
109 | -- * If the current target tooltip doesn't create comparisons, then allow |
||
110 | -- others to do so. |
||
111 | -- * Review leftAlign placement policy |
||
112 | -- * Review main/off-hand showing policy |
||
113 | -- * Refactoring |
||
114 | -- * Modernise Khaos registration, base Cosmos on it |
||
115 | -- |
||
116 | |||
117 | -- |
||
118 | -- Global variables |
||
119 | -- |
||
120 | |||
121 | -- Configuration settings |
||
122 | -- Default values when neither Khaos nor Cosmos are present |
||
123 | EquipCompare_Enabled = true; |
||
124 | EquipCompare_ControlMode = false; |
||
125 | EquipCompare_UseCV = true; |
||
126 | EquipCompare_AltMode = false; |
||
127 | EquipCompare_Shiftup = false; |
||
128 | |||
129 | -- Values for private use |
||
130 | EquipCompare_Recheck = true; |
||
131 | EquipCompare_Protected = false; |
||
132 | EquipCompare_CharactersViewer = false; |
||
133 | EquipCompare_TargetTooltip = nil; |
||
134 | EquipCompare_Alignment = nil; |
||
135 | EquipCompare_ShiftupObject = nil; |
||
136 | EquipCompare_ShiftupSide = nil; |
||
137 | EquipCompare_ShiftupMargin = 0; |
||
138 | EquipCompare_TooltipList = nil; |
||
139 | EquipCompare_BarList = nil; |
||
140 | EquipCompare_CVFrame = nil; |
||
141 | |||
142 | -- Data |
||
143 | INVTYPE_WEAPON_OTHER = INVTYPE_WEAPON.."_other"; |
||
144 | INVTYPE_FINGER_OTHER = INVTYPE_FINGER.."_other"; |
||
145 | INVTYPE_TRINKET_OTHER = INVTYPE_TRINKET.."_other"; |
||
146 | |||
147 | EquipCompare_ItemTypes = { |
||
148 | [INVTYPE_2HWEAPON] = "MainHandSlot", -- Two-Hand |
||
149 | [INVTYPE_BODY] = "ShirtSlot", -- Shirt |
||
150 | [INVTYPE_CHEST] = "ChestSlot", -- Chest |
||
151 | [INVTYPE_CLOAK] = "BackSlot", -- Back |
||
152 | [INVTYPE_FEET] = "FeetSlot", -- Feet |
||
153 | [INVTYPE_FINGER] = "Finger0Slot", -- Finger |
||
154 | [INVTYPE_FINGER_OTHER] = "Finger1Slot", -- Finger_other |
||
155 | [INVTYPE_HAND] = "HandsSlot", -- Hands |
||
156 | [INVTYPE_HEAD] = "HeadSlot", -- Head |
||
157 | [INVTYPE_HOLDABLE] = "SecondaryHandSlot", -- Held In Off-hand |
||
158 | [INVTYPE_LEGS] = "LegsSlot", -- Legs |
||
159 | [INVTYPE_NECK] = "NeckSlot", -- Neck |
||
160 | [INVTYPE_RANGED] = "RangedSlot", -- Ranged |
||
161 | [INVTYPE_RELIC] = "RangedSlot", -- Relic |
||
162 | [INVTYPE_ROBE] = "ChestSlot", -- Chest |
||
163 | [INVTYPE_SHIELD] = "SecondaryHandSlot", -- Off Hand |
||
164 | [INVTYPE_SHOULDER] = "ShoulderSlot", -- Shoulder |
||
165 | [INVTYPE_TABARD] = "TabardSlot", -- Tabard |
||
166 | [INVTYPE_TRINKET] = "Trinket0Slot", -- Trinket |
||
167 | [INVTYPE_TRINKET_OTHER] = "Trinket1Slot", -- Trinket_other |
||
168 | [INVTYPE_WAIST] = "WaistSlot", -- Waist |
||
169 | [INVTYPE_WEAPON] = "MainHandSlot", -- One-Hand |
||
170 | [INVTYPE_WEAPON_OTHER] = "SecondaryHandSlot", -- One-Hand_other |
||
171 | [INVTYPE_WEAPONMAINHAND] = "MainHandSlot", -- Main Hand |
||
172 | [INVTYPE_WEAPONOFFHAND] = "SecondaryHandSlot", -- Off Hand |
||
173 | [INVTYPE_WRIST] = "WristSlot", -- Wrist |
||
174 | [INVTYPE_WAND] = "RangedSlot", -- Wand |
||
175 | |||
176 | -- Inventory types not defined in GlobalStrings.lua |
||
177 | [INVTYPE_GUN] = "RangedSlot", -- Gun |
||
178 | [INVTYPE_GUNPROJECTILE] = "AmmoSlot", -- Projectile |
||
179 | [INVTYPE_BOWPROJECTILE] = "AmmoSlot", -- Projectile |
||
180 | [INVTYPE_CROSSBOW] = "RangedSlot", -- Crossbow |
||
181 | [INVTYPE_THROWN] = "RangedSlot", -- Thrown |
||
182 | }; |
||
183 | |||
184 | -- |
||
185 | -- Public API |
||
186 | -- |
||
187 | |||
188 | --[[ |
||
189 | success = EquipCompare_RegisterTooltip(object, priority) |
||
190 | |||
191 | Call this to register a tooltip object that you would like EquipCompare |
||
192 | to show comparison tooltips for. |
||
193 | |||
194 | Arguments: |
||
195 | * object: [Reference] The object to register with EquipeCompare |
||
196 | * priority (optional): [String] Permitted values are "high" and "low". |
||
197 | If not present, defaults to "low". Specifies whether you would like |
||
198 | to show comparison tooltips for this object in preference to the |
||
199 | game's main tooltip, if both are showing. |
||
200 | Returns: |
||
201 | * success: [Boolean] True if the registration was successful or the |
||
202 | object is already registered, false otherwise. |
||
203 | Note: |
||
204 | GameTooltip and ItemRefTooltip are registered by default. You only |
||
205 | need to register your own custom tooltips using this function. It is |
||
206 | permissible to call this function multiple times with the same object, |
||
207 | but it will result in a single registration. |
||
208 | ]] |
||
209 | function EquipCompare_RegisterTooltip(object, priority) |
||
210 | local i; |
||
211 | |||
212 | if ( not priority ) then |
||
213 | priority = "low"; |
||
214 | end |
||
215 | if ( not object or priority ~= "high" and priority ~= "low" ) then |
||
216 | return false; |
||
217 | end |
||
218 | |||
219 | if ( not EquipCompare_TooltipList ) then |
||
220 | EquipCompare_InitializeTooltipList(); |
||
221 | end |
||
222 | |||
223 | for i = 1, table.getn(EquipCompare_TooltipList) do |
||
224 | if ( EquipCompare_TooltipList[i] == object ) then |
||
225 | return true; |
||
226 | end |
||
227 | end |
||
228 | |||
229 | if ( priority == "high" ) then |
||
230 | table.insert(EquipCompare_TooltipList, 1, object); |
||
231 | else |
||
232 | table.insert(EquipCompare_TooltipList, object); |
||
233 | end |
||
234 | |||
235 | local oldHandler = object:GetScript("OnTooltipCleared"); |
||
236 | object:SetScript("OnTooltipCleared", function(a1,a2,a3,a4,a5) |
||
237 | local r1,r2,r3,r4,r5; |
||
238 | if ( oldHandler ) then |
||
239 | r1,r2,r3,r4,r5 = oldHandler(a1,a2,a3,a4,a5); |
||
240 | end |
||
241 | EquipCompare_PostClearTooltip(); |
||
242 | return r1,r2,r3,r4,r5; |
||
243 | end); |
||
244 | |||
245 | return true; |
||
246 | end |
||
247 | |||
248 | --[[ |
||
249 | success = EquipCompare_UnregisterTooltip(object) |
||
250 | |||
251 | Call this to unregister a tooltip object that you would no longer like |
||
252 | EquipCompare to show comparison tooltips for. |
||
253 | |||
254 | Arguments: |
||
255 | * object: [Reference] The object to unregister with EquipeCompare |
||
256 | Returns: |
||
257 | * success: [Boolean] True if the object was successfully unregistered, |
||
258 | false otherwise (for example because the object was not found in the |
||
259 | list of registered tooltips). |
||
260 | Note: |
||
261 | You will not be able to unregister GameTooltip and ItemRefTooltip, |
||
262 | and will receive a return value of false if you try. You should only |
||
263 | use this function to unregister your custom tooltips. |
||
264 | ]] |
||
265 | function EquipCompare_UnregisterTooltip(object) |
||
266 | local i; |
||
267 | |||
268 | if ( not object or not EquipCompare_TooltipList ) then |
||
269 | return false; |
||
270 | end |
||
271 | |||
272 | for i = 1, table.getn(EquipCompare_TooltipList) do |
||
273 | if ( EquipCompare_TooltipList[i] == object ) then |
||
274 | table.remove(EquipCompare_TooltipList, i); |
||
275 | return true; |
||
276 | end |
||
277 | end |
||
278 | |||
279 | return false; |
||
280 | end |
||
281 | |||
282 | --[[ |
||
283 | success = EquipCompare_RegisterExclusion(pattern) |
||
284 | |||
285 | Call this to register an object or set of objects which, when you hover |
||
286 | over it or them, you don't want EquipCompare to show comparison tooltips. |
||
287 | |||
288 | Arguments: |
||
289 | * pattern: [String] A standard Lua regexp pattern. Any object whose name |
||
290 | matches this pattern will not show comparison tooltips when hovered |
||
291 | over. Example: "^ActionButton", which avoids comparison tooltips when |
||
292 | hovering over any action bar buttons. |
||
293 | Returns: |
||
294 | * success: [Boolean] True if the pattern was successfully registered, |
||
295 | or if it has been registered before. |
||
296 | Note: |
||
297 | It is permissible to call this function multiple times with the exact |
||
298 | same pattern. It will however result in a single registration for that |
||
299 | pattern. The following patterns are registered by EquipCompare by |
||
300 | default: "^Character.*Slot","^CharactersViewer_Frame","^CVCharacterFrame", |
||
301 | "^TempEnchant","^MultiBar","^ActionButton" |
||
302 | |||
303 | ]] |
||
304 | function EquipCompare_RegisterExclusion(barname) |
||
305 | local i; |
||
306 | |||
307 | if ( type(barname) ~= "string" ) then |
||
308 | return false; |
||
309 | end |
||
310 | |||
311 | if ( not EquipCompare_BarList ) then |
||
312 | EquipCompare_InitializeBarList(); |
||
313 | end |
||
314 | |||
315 | for i = 1, table.getn(EquipCompare_BarList) do |
||
316 | if ( EquipCompare_BarList[i] == barname ) then |
||
317 | return true; |
||
318 | end |
||
319 | end |
||
320 | |||
321 | table.insert(EquipCompare_BarList, barname); |
||
322 | return true; |
||
323 | end |
||
324 | |||
325 | --[[ |
||
326 | success = EquipCompare_UnregisterExclusion(pattern) |
||
327 | |||
328 | Call this to unregister an exclusion pattern registered with |
||
329 | EquipCompare_RegisterExclusion. Use a standard Lua regular |
||
330 | expression pattern to specify the name(s) of the object(s). |
||
331 | |||
332 | Arguments: |
||
333 | * pattern: [String] The exact same pattern that was registered. |
||
334 | Returns: |
||
335 | * success: [Boolean] True if the pattern was successfully unregistered, |
||
336 | false if some error occurred, e.g. it wasn't in the registered list. |
||
337 | |||
338 | ]] |
||
339 | function EquipCompare_UnregisterExclusion(barname) |
||
340 | local i; |
||
341 | |||
342 | if ( type(barname) ~= "string" or not EquipCompare_BarList ) then |
||
343 | return false; |
||
344 | end |
||
345 | |||
346 | for i = 1, table.getn(EquipCompare_BarList) do |
||
347 | if ( EquipCompare_BarList[i] == barname ) then |
||
348 | table.remove(EquipCompare_BarList, i); |
||
349 | return true; |
||
350 | end |
||
351 | end |
||
352 | |||
353 | return false; |
||
354 | end |
||
355 | |||
356 | --[[ |
||
357 | object, alignment = EquipCompare_GetComparisonAnchor() |
||
358 | |||
359 | Call this when you need to know which side the comparison tooltips are on, |
||
360 | or would be on, relative to the object that EquipCompare currently prefers |
||
361 | to attach comparison tooltips to. |
||
362 | |||
363 | Returns: |
||
364 | * object: [Reference] The object (e.g. GameTooltip or ItemRefTooltip) that |
||
365 | EC currently is attaching to or would be attaching to if it was |
||
366 | displaying comparison tooltips. Set to nil if EC can't see any object to |
||
367 | attach to. |
||
368 | * alignment: [String] "left" or "right", depending on which side the |
||
369 | comparison tooltips are showing or would show up on for that object. |
||
370 | Set to nil if EC wouldn't show comparison tooltips for the object at the |
||
371 | moment. |
||
372 | ]] |
||
373 | function EquipCompare_GetComparisonAnchor() |
||
374 | EquipCompare_CheckCompare(); |
||
375 | if ( EquipCompare_ControlMode and not IsControlKeyDown() ) then |
||
376 | EquipCompare_HideTips(); |
||
377 | end |
||
378 | return EquipCompare_TargetTooltip, EquipCompare_Alignment; |
||
379 | end |
||
380 | |||
381 | --[[ |
||
382 | EquipCompare_RequestShift(object, side, margin) |
||
383 | |||
384 | Call this when you want to request EquipCompare to shift its tooltips if |
||
385 | necessary to make space under and to the side of an object, for example because |
||
386 | you want to occupy that space. |
||
387 | |||
388 | Arguments: |
||
389 | * object: [Reference] The object you are requesting a shift around |
||
390 | (e.g. GameTooltip or ItemRefTooltip). |
||
391 | * side: [String] Indicates which side under the object you need space. |
||
392 | Takes value "left" or "right". |
||
393 | * margin: [Integer] Indicates how much space in game-pixels you need. |
||
394 | Note: |
||
395 | It is permissible to call EquipCompare_RequestShift multiple types, even |
||
396 | without corresponding calls to EquipCompare_CancelShift(), for example, |
||
397 | to change the object or the margin. It is always the last call that |
||
398 | takes effect. |
||
399 | ]] |
||
400 | function EquipCompare_RequestShift(object, side, margin) |
||
401 | -- error checking |
||
402 | if ( side ~= "left" and side ~= "right" or type(margin) ~= "number" ) then |
||
403 | EquipCompare_ShiftupObject = nil; |
||
404 | EquipCompare_ShiftupSide = nil; |
||
405 | EquipCompare_ShiftupMargin = 0; |
||
406 | return; |
||
407 | end |
||
408 | |||
409 | EquipCompare_ShiftupObject = object; |
||
410 | EquipCompare_ShiftupSide = side; |
||
411 | EquipCompare_ShiftupMargin = margin; |
||
412 | |||
413 | EquipCompare_Recheck = true; |
||
414 | EquipCompare_OnUpdate(); |
||
415 | end |
||
416 | |||
417 | --[[ |
||
418 | EquipCompare_CancelShift(object) |
||
419 | |||
420 | Call this when you no longer require EquipCompare to make space under |
||
421 | and to the side of an object. |
||
422 | |||
423 | Arguments: |
||
424 | * object: [Reference] The object you no longer need space around. |
||
425 | Note: |
||
426 | It is permissible to call this function multiple times, even without |
||
427 | corresponding calls to EquipCompare_RequestShift(). It is also |
||
428 | permissible to call this with a different object that you called |
||
429 | EquipCompare_RequestShift() with, or an object that EquipCompare |
||
430 | is not actually attaching to. |
||
431 | ]] |
||
432 | function EquipCompare_CancelShift(object) |
||
433 | if ( object == EquipCompare_ShiftupObject ) then |
||
434 | EquipCompare_Recheck = true; |
||
435 | end |
||
436 | |||
437 | EquipCompare_ShiftupObject = nil; |
||
438 | EquipCompare_ShiftupSide = nil; |
||
439 | EquipCompare_ShiftupMargin = 0; |
||
440 | |||
441 | EquipCompare_OnUpdate(); |
||
442 | end |
||
443 | |||
444 | -- |
||
445 | -- Some local functions that are used throughout |
||
446 | -- |
||
447 | |||
448 | -- CharactersViewer compatibility check |
||
449 | |||
450 | local function IsCharactersViewer() |
||
451 | if ( EquipCompare_UseCV and CharactersViewer and CharactersViewer.version and |
||
452 | type(CharactersViewer.version.number) == "number" and |
||
453 | type(CharactersViewer_Tooltip_SetInventoryItem)=="function" ) then |
||
454 | if ( CharactersViewer.version.number >= 150 and CVCharacterFrame ) then |
||
455 | EquipCompare_CVFrame = CVCharacterFrame; |
||
456 | return true; |
||
457 | elseif ( CharactersViewer.version.number >= 55 and CharactersViewer_Frame ) then |
||
458 | EquipCompare_CVFrame = CharactersViewer_Frame; |
||
459 | return true; |
||
460 | end |
||
461 | end |
||
462 | return false; |
||
463 | end |
||
464 | |||
465 | -- Registration and configuration |
||
466 | |||
467 | function EquipCompare_Register_Khaos() |
||
468 | -- Note: Default to disabled if Khaos is present |
||
469 | Khaos.registerOptionSet ( |
||
470 | "tooltip", |
||
471 | { |
||
472 | id = "EquipCompareConfigSet"; |
||
473 | text = EQUIPCOMPARE_COSMOS_SECTION; |
||
474 | helptext = EQUIPCOMPARE_COSMOS_SECTION_INFO; |
||
475 | difficulty = 1; |
||
476 | callback = EquipCompare_Toggle; |
||
477 | default = false; |
||
478 | options = { |
||
479 | { |
||
480 | id = "EquipCompareOptionHeader"; |
||
481 | type = K_HEADER; |
||
482 | difficulty = 1; |
||
483 | text = EQUIPCOMPARE_COSMOS_HEADER; |
||
484 | helptext = EQUIPCOMPARE_COSMOS_HEADER_INFO; |
||
485 | },{ |
||
486 | id = "EquipCompareOptionControlMode"; |
||
487 | type = K_TEXT; |
||
488 | difficulty = 3; |
||
489 | text = EQUIPCOMPARE_COSMOS_CONTROLMODE; |
||
490 | helptext = EQUIPCOMPARE_COSMOS_CONTROLMODE_INFO; |
||
491 | callback = function(state) EquipCompare_ToggleControl(state.checked); end; |
||
492 | feedback = function(state) |
||
493 | if (state.checked) then |
||
494 | return EQUIPCOMPARE_TOGGLECONTROL_ON; |
||
495 | else |
||
496 | return EQUIPCOMPARE_TOGGLECONTROL_OFF; |
||
497 | end |
||
498 | end; |
||
499 | check = true; |
||
500 | default = { checked = false; }; |
||
501 | disabled = { checked = false; }; |
||
502 | },{ |
||
503 | id = "EquipCompareOptionCVIntegration"; |
||
504 | type = K_TEXT; |
||
505 | difficulty = 2; |
||
506 | text = EQUIPCOMPARE_COSMOS_CVMODE; |
||
507 | helptext = EQUIPCOMPARE_COSMOS_CVMODE_INFO; |
||
508 | callback = function(state) EquipCompare_ToggleCV(state.checked); end; |
||
509 | feedback = function(state) |
||
510 | if (state.checked) then |
||
511 | return EQUIPCOMPARE_TOGGLECV_ON; |
||
512 | else |
||
513 | return EQUIPCOMPARE_TOGGLECV_OFF; |
||
514 | end |
||
515 | end; |
||
516 | check = true; |
||
517 | default = { checked = true; }; |
||
518 | disabled = { checked = false; }; |
||
519 | },{ |
||
520 | id = "EquipCompareOptionAltMode"; |
||
521 | type = K_TEXT; |
||
522 | difficulty = 3; |
||
523 | text = EQUIPCOMPARE_COSMOS_ALTMODE; |
||
524 | helptext = EQUIPCOMPARE_COSMOS_ALTMODE_INFO; |
||
525 | callback = function(state) EquipCompare_ToggleAlt(state.checked); end; |
||
526 | feedback = function(state) |
||
527 | if (state.checked) then |
||
528 | return EQUIPCOMPARE_TOGGLEALT_ON; |
||
529 | else |
||
530 | return EQUIPCOMPARE_TOGGLEALT_OFF; |
||
531 | end |
||
532 | end; |
||
533 | check = true; |
||
534 | default = { checked = false; }; |
||
535 | disabled = { checked = false; }; |
||
536 | },{ |
||
537 | id = "EquipCompareOptionShiftupMode"; |
||
538 | type = K_TEXT; |
||
539 | difficulty = 2; |
||
540 | text = EQUIPCOMPARE_COSMOS_SHIFTUP; |
||
541 | helptext = EQUIPCOMPARE_COSMOS_SHIFTUP_INFO; |
||
542 | callback = function(state) EquipCompare_ToggleShiftup(state.checked); end; |
||
543 | feedback = function(state) |
||
544 | if (state.checked) then |
||
545 | return EQUIPCOMPARE_SHIFTUP_ON; |
||
546 | else |
||
547 | return EQUIPCOMPARE_SHIFTUP_OFF; |
||
548 | end |
||
549 | end; |
||
550 | check = true; |
||
551 | default = { checked = false; }; |
||
552 | disabled = { checked = false; }; |
||
553 | } |
||
554 | } |
||
555 | } |
||
556 | ) |
||
557 | end |
||
558 | |||
559 | function EquipCompare_Register_Cosmos() |
||
560 | -- Note: Default to disabled if Cosmos is present |
||
561 | Cosmos_RegisterConfiguration( |
||
562 | "COS_EQC", |
||
563 | "SECTION", |
||
564 | EQUIPCOMPARE_COSMOS_SECTION, |
||
565 | EQUIPCOMPARE_COSMOS_SECTION_INFO |
||
566 | ); |
||
567 | Cosmos_RegisterConfiguration( |
||
568 | "COS_EQC_SEPARATOR", |
||
569 | "SEPARATOR", |
||
570 | EQUIPCOMPARE_COSMOS_HEADER, |
||
571 | EQUIPCOMPARE_COSMOS_HEADER_INFO |
||
572 | |||
573 | ); |
||
574 | Cosmos_RegisterConfiguration( |
||
575 | "COS_EQC_ENABLED", |
||
576 | "CHECKBOX", |
||
577 | EQUIPCOMPARE_COSMOS_ENABLE, |
||
578 | EQUIPCOMPARE_COSMOS_ENABLE_INFO, |
||
579 | EquipCompare_Toggle, |
||
580 | |||
581 | ); |
||
582 | Cosmos_RegisterConfiguration( |
||
583 | "COS_EQC_CONTROLMODE", |
||
584 | "CHECKBOX", |
||
585 | EQUIPCOMPARE_COSMOS_CONTROLMODE, |
||
586 | EQUIPCOMPARE_COSMOS_CONTROLMODE_INFO, |
||
587 | EquipCompare_ToggleControl, |
||
588 | |||
589 | ); |
||
590 | Cosmos_RegisterConfiguration( |
||
591 | "COS_EQC_CVMODE", |
||
592 | "CHECKBOX", |
||
593 | EQUIPCOMPARE_COSMOS_CVMODE, |
||
594 | EQUIPCOMPARE_COSMOS_CVMODE_INFO, |
||
595 | EquipCompare_ToggleCV, |
||
596 | 1 |
||
597 | ); |
||
598 | Cosmos_RegisterConfiguration( |
||
599 | "COS_EQC_ALTMODE", |
||
600 | "CHECKBOX", |
||
601 | EQUIPCOMPARE_COSMOS_ALTMODE, |
||
602 | EQUIPCOMPARE_COSMOS_ALTMODE_INFO, |
||
603 | EquipCompare_ToggleAlt, |
||
604 | |||
605 | ); |
||
606 | Cosmos_RegisterConfiguration( |
||
607 | "COS_EQC_SHIFTUP", |
||
608 | "CHECKBOX", |
||
609 | EQUIPCOMPARE_COSMOS_SHIFTUP, |
||
610 | EQUIPCOMPARE_COSMOS_SHIFTUP_INFO, |
||
611 | EquipCompare_ToggleShiftup, |
||
612 | |||
613 | ); |
||
614 | end |
||
615 | |||
616 | -- |
||
617 | -- XML Event handlers |
||
618 | -- |
||
619 | |||
620 | function EquipCompare_OnLoad() |
||
621 | -- Hook into various methods of ShoppingTooltips |
||
622 | EquipCompare_SetupHooks(); |
||
623 | |||
624 | -- Initialize lists |
||
625 | EquipCompare_InitializeTooltipList(); |
||
626 | EquipCompare_InitializeBarList(); |
||
627 | |||
628 | -- GUI configuration registration |
||
629 | -- Check for Khaos. If available, register with it. |
||
630 | if ( Khaos ) then |
||
631 | EquipCompare_Register_Khaos(); |
||
632 | elseif ( Cosmos_RegisterConfiguration ) then |
||
633 | -- Check for Cosmos. If available, register with it. |
||
634 | EquipCompare_Register_Cosmos() |
||
635 | end |
||
636 | |||
637 | -- Slash command registration - for now, don't use Khaos |
||
638 | -- If Satellite is present, use it to register slash commands |
||
639 | if ( Satellite ) then |
||
640 | Satellite.registerSlashCommand { |
||
641 | id = "EquipCompare"; |
||
642 | commands = { "/equipcompare", "/eqc" }; |
||
643 | onExecute = EquipCompare_SlashCommand; |
||
644 | helpText = EQUIPCOMPARE_COSMOS_SLASH_DESC; |
||
645 | } |
||
646 | -- If legacy Sky is present, use it to register slash commands |
||
647 | elseif ( Sky and Sky.registerSlashCommand ) then |
||
648 | Sky.registerSlashCommand { |
||
649 | id = "EquipCompare"; |
||
650 | commands = { "/equipcompare", "/eqc" }; |
||
651 | onExecute = EquipCompare_SlashCommand; |
||
652 | helpText = EQUIPCOMPARE_COSMOS_SLASH_DESC; |
||
653 | } |
||
654 | -- If Cosmos allows chat command registration, do so |
||
655 | elseif ( Cosmos_RegisterChatCommand ) then |
||
656 | local comlist = { "/equipcompare", "/eqc" }; |
||
657 | local desc = EQUIPCOMPARE_COSMOS_SLASH_DESC; |
||
658 | local id = "EQUIPCOMPARE"; |
||
659 | local func = EquipCompare_SlashCommand |
||
660 | Cosmos_RegisterChatCommand ( id, comlist, func, desc, CSM_CHAINNONE ); |
||
661 | else |
||
662 | -- otherwise, just register slash commands manually |
||
663 | SlashCmdList["EQUIPCOMPARE"] = EquipCompare_SlashCommand; |
||
664 | SLASH_EQUIPCOMPARE1 = "/equipcompare"; |
||
665 | SLASH_EQUIPCOMPARE2 = "/eqc"; |
||
666 | end |
||
667 | |||
668 | -- Check to see if CharactersViewer is installed, has the right version |
||
669 | -- and has the required interface. If so, enable support for it. |
||
670 | if ( IsCharactersViewer() ) then |
||
671 | EquipCompare_CharactersViewer = true; |
||
672 | end |
||
673 | |||
674 | -- Welcome! |
||
675 | if ( not Khaos and not Cosmos_RegisterChatCommand ) then |
||
676 | ChatFrame1:AddMessage(EQUIPCOMPARE_GREETING); |
||
677 | end |
||
678 | end |
||
679 | |||
680 | function EquipCompare_OnEvent() |
||
681 | end |
||
682 | |||
683 | function EquipCompare_PostClearTooltip() |
||
684 | if ( not EquipCompare_Protected ) then |
||
685 | EquipCompare_Recheck = true; |
||
686 | end |
||
687 | end |
||
688 | |||
689 | local lastAltState = "undefined"; |
||
690 | |||
691 | -- This function is called on every OnUpdate. This is the only way to detect if a |
||
692 | -- game tooltip has been displayed, without overriding FrameXML files or hooking |
||
693 | -- millions of functions. |
||
694 | -- So that this function doesn't hog resources, the EquipCompare_Recheck flag is |
||
695 | -- set to false, until the game tooltip changes. |
||
696 | function EquipCompare_OnUpdate() |
||
697 | if ( not EquipCompare_Enabled ) then |
||
698 | return; |
||
699 | end |
||
700 | |||
701 | if ( EquipCompare_ControlMode and not IsControlKeyDown() ) then |
||
702 | if (EquipCompare_TargetTooltip) then |
||
703 | EquipCompare_Recheck = true; |
||
704 | EquipCompare_TargetTooltip = nil; |
||
705 | EquipCompare_HideTips(); |
||
706 | end |
||
707 | return; |
||
708 | end |
||
709 | |||
710 | if ( EquipCompare_AltMode and lastAltState ~= IsAltKeyDown() ) then |
||
711 | local changed; |
||
712 | lastAltState = IsAltKeyDown(); |
||
713 | if ( lastAltState ) then |
||
714 | if ( IsCharactersViewer() ) then |
||
715 | EquipCompare_CharactersViewer = true; |
||
716 | changed = true; |
||
717 | end |
||
718 | else |
||
719 | if ( EquipCompare_CharactersViewer ) then |
||
720 | EquipCompare_CharactersViewer = false; |
||
721 | changed = true; |
||
722 | end |
||
723 | end |
||
724 | if ( changed ) then |
||
725 | EquipCompare_Recheck = true; |
||
726 | EquipCompare_TargetTooltip = nil; |
||
727 | EquipCompare_HideTips(); |
||
728 | end |
||
729 | end |
||
730 | |||
731 | -- If we currently have a target that has since become |
||
732 | -- hidden, hide the comparison tooltips too. |
||
733 | if ( EquipCompare_TargetTooltip and |
||
734 | not EquipCompare_TargetTooltip:IsVisible() ) then |
||
735 | EquipCompare_Recheck = true; |
||
736 | EquipCompare_TargetTooltip = nil; |
||
737 | EquipCompare_HideTips(); |
||
738 | end |
||
739 | |||
740 | if ( not EquipCompare_Recheck ) then |
||
741 | return; |
||
742 | end |
||
743 | |||
744 | EquipCompare_CheckCompare(); |
||
745 | end |
||
746 | |||
747 | -- |
||
748 | -- Other functions |
||
749 | -- |
||
750 | |||
751 | function EquipCompare_SetupHooks() |
||
752 | EquipCompare_old_SetAuctionCompareItem1 = ShoppingTooltip1.SetAuctionCompareItem; |
||
753 | EquipCompare_old_SetAuctionCompareItem2 = ShoppingTooltip2.SetAuctionCompareItem; |
||
754 | |||
755 | ShoppingTooltip1.SetAuctionCompareItem = function(a1,a2,a3,a4,a5) |
||
756 | if ( EquipCompare_Enabled ) then |
||
757 | return false; |
||
758 | else |
||
759 | return EquipCompare_old_SetAuctionCompareItem1(a1,a2,a3,a4,a5); |
||
760 | end |
||
761 | end |
||
762 | ShoppingTooltip2.SetAuctionCompareItem = function(a1,a2,a3,a4,a5) |
||
763 | if ( EquipCompare_Enabled ) then |
||
764 | return false; |
||
765 | else |
||
766 | return EquipCompare_old_SetAuctionCompareItem2(a1,a2,a3,a4,a5); |
||
767 | end |
||
768 | end |
||
769 | |||
770 | EquipCompare_old_SetMerchantCompareItem1 = ShoppingTooltip1.SetMerchantCompareItem; |
||
771 | EquipCompare_old_SetMerchantCompareItem2 = ShoppingTooltip2.SetMerchantCompareItem; |
||
772 | |||
773 | ShoppingTooltip1.SetMerchantCompareItem = function(a1,a2,a3,a4,a5) |
||
774 | if ( EquipCompare_Enabled ) then |
||
775 | return false; |
||
776 | else |
||
777 | return EquipCompare_old_SetMerchantCompareItem1(a1,a2,a3,a4,a5); |
||
778 | end |
||
779 | end |
||
780 | ShoppingTooltip2.SetMerchantCompareItem = function(a1,a2,a3,a4,a5) |
||
781 | if ( EquipCompare_Enabled ) then |
||
782 | return false; |
||
783 | else |
||
784 | return EquipCompare_old_SetMerchantCompareItem2(a1,a2,a3,a4,a5); |
||
785 | end |
||
786 | end |
||
787 | end |
||
788 | |||
789 | local function EquipCompare_EmptyFunction() end; |
||
790 | |||
791 | function EquipCompare_InitializeTooltipList() |
||
792 | if ( not EquipCompare_TooltipList ) then |
||
793 | EquipCompare_TooltipList = {}; |
||
794 | end |
||
795 | EquipCompare_RegisterTooltip(ItemRefTooltip, "high"); |
||
796 | EquipCompare_RegisterTooltip(LootLinkTooltip); |
||
797 | EquipCompare_RegisterTooltip(GameTooltip, "low"); |
||
798 | end |
||
799 | |||
800 | function EquipCompare_InitializeBarList() |
||
801 | if ( not EquipCompare_BarList ) then |
||
802 | EquipCompare_BarList = {}; |
||
803 | end |
||
804 | EquipCompare_RegisterExclusion("^Character.*Slot"); |
||
805 | EquipCompare_RegisterExclusion("^CharactersViewer_Frame"); |
||
806 | EquipCompare_RegisterExclusion("^CVCharacterFrame"); |
||
807 | EquipCompare_RegisterExclusion("^TempEnchant"); |
||
808 | EquipCompare_RegisterExclusion("^MultiBar"); |
||
809 | EquipCompare_RegisterExclusion("^ActionButton"); |
||
810 | EquipCompare_RegisterExclusion("^WeaponButton.*Slot"); |
||
811 | end |
||
812 | |||
813 | local showedTip = false; |
||
814 | |||
815 | function EquipCompare_SlashCommand(msg) |
||
816 | local setlevel = false; |
||
817 | if (not msg or msg == "") then |
||
818 | -- toggle |
||
819 | EquipCompare_Toggle(not EquipCompare_Enabled); |
||
820 | if (EquipCompare_Enabled) then |
||
821 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLE_ON); |
||
822 | else |
||
823 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLE_OFF); |
||
824 | end |
||
825 | if (not showedTip) then |
||
826 | showedTip = true; |
||
827 | ChatFrame1:AddMessage(EQUIPCOMPARE_HELPTIP); |
||
828 | end |
||
829 | setlevel = true; |
||
830 | elseif (msg == "on") then |
||
831 | -- turn on |
||
832 | EquipCompare_Toggle(true); |
||
833 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLE_ON); |
||
834 | setlevel = true; |
||
835 | elseif (msg == "off") then |
||
836 | -- turn off |
||
837 | EquipCompare_Toggle(false); |
||
838 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLE_OFF); |
||
839 | setlevel = true; |
||
840 | elseif (msg == "control") then |
||
841 | -- toggle Control Key Mode |
||
842 | EquipCompare_ToggleControl(not EquipCompare_ControlMode); |
||
843 | if (EquipCompare_ControlMode) then |
||
844 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLECONTROL_ON); |
||
845 | else |
||
846 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLECONTROL_OFF); |
||
847 | end |
||
848 | elseif (msg == "cv") then |
||
849 | -- toggle CharactersViewer integration |
||
850 | EquipCompare_ToggleCV(not EquipCompare_UseCV); |
||
851 | if (EquipCompare_UseCV) then |
||
852 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLECV_ON); |
||
853 | else |
||
854 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLECV_OFF); |
||
855 | end |
||
856 | elseif (msg == "alt") then |
||
857 | -- toggle Alt Key Mode |
||
858 | EquipCompare_ToggleAlt(not EquipCompare_AltMode); |
||
859 | if (EquipCompare_AltMode) then |
||
860 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLEALT_ON); |
||
861 | else |
||
862 | ChatFrame1:AddMessage(EQUIPCOMPARE_TOGGLEALT_OFF); |
||
863 | end |
||
864 | elseif (msg == "shift") then |
||
865 | -- toggle Alt Key Mode |
||
866 | EquipCompare_ToggleShiftup(not EquipCompare_Shiftup); |
||
867 | if (EquipCompare_Shiftup) then |
||
868 | ChatFrame1:AddMessage(EQUIPCOMPARE_SHIFTUP_ON); |
||
869 | else |
||
870 | ChatFrame1:AddMessage(EQUIPCOMPARE_SHIFTUP_OFF); |
||
871 | end |
||
872 | else |
||
873 | -- usage |
||
874 | for i, s in EQUIPCOMPARE_USAGE_TEXT do |
||
875 | ChatFrame1:AddMessage(s); |
||
876 | end |
||
877 | end |
||
878 | -- update Khaos configuration settings |
||
879 | if ( Khaos ) then |
||
880 | -- Note: only do the set enabling if that's what was changed, |
||
881 | -- since enabling the set causes all the callbacks to be run. |
||
882 | if (setlevel) then |
||
883 | Khaos.setSetEnabled("EquipCompareConfigSet", EquipCompare_Enabled); |
||
884 | else |
||
885 | Khaos.setSetKey("EquipCompareConfigSet", "EquipCompareOptionControlMode", |
||
886 | { checked = EquipCompare_ControlMode }); |
||
887 | Khaos.setSetKey("EquipCompareConfigSet", "EquipCompareOptionCVIntegration", |
||
888 | { checked = EquipCompare_UseCV }); |
||
889 | Khaos.setSetKey("EquipCompareConfigSet", "EquipCompareOptionAltMode", |
||
890 | { checked = EquipCompare_AltMode }); |
||
891 | Khaos.setSetKey("EquipCompareConfigSet", "EquipCompareOptionShiftupMode", |
||
892 | { checked = EquipCompare_ShiftupMode }); |
||
893 | end |
||
894 | Khaos.refresh(); |
||
895 | -- update Cosmos configuration settings |
||
896 | elseif ( Cosmos_RegisterConfiguration ) then |
||
897 | local newvalue; |
||
898 | -- Enabled check box |
||
899 | if ( EquipCompare_Enabled ) then |
||
900 | newvalue = 1; |
||
901 | else |
||
902 | newvalue = 0; |
||
903 | end |
||
904 | Cosmos_UpdateValue("COS_EQC_ENABLED", CSM_CHECKONOFF, newvalue); |
||
905 | |||
906 | -- Control mode check box |
||
907 | if ( EquipCompare_ControlMode ) then |
||
908 | newvalue = 1; |
||
909 | else |
||
910 | newvalue = 0; |
||
911 | end |
||
912 | Cosmos_UpdateValue("COS_EQC_CONTROLMODE", CSM_CHECKONOFF, newvalue); |
||
913 | |||
914 | -- CV integration check box |
||
915 | if ( EquipCompare_UseCV ) then |
||
916 | newvalue = 1; |
||
917 | else |
||
918 | newvalue = 0; |
||
919 | end |
||
920 | Cosmos_UpdateValue("COS_EQC_CVMODE", CSM_CHECKONOFF, newvalue); |
||
921 | |||
922 | -- Alt mode check box |
||
923 | if ( EquipCompare_AltMode ) then |
||
924 | newvalue = 1; |
||
925 | else |
||
926 | newvalue = 0; |
||
927 | end |
||
928 | Cosmos_UpdateValue("COS_EQC_ALTMODE", CSM_CHECKONOFF, newvalue); |
||
929 | |||
930 | -- Shift up check box |
||
931 | if ( EquipCompare_Shiftup ) then |
||
932 | newvalue = 1; |
||
933 | else |
||
934 | newvalue = 0; |
||
935 | end |
||
936 | Cosmos_UpdateValue("COS_EQC_SHIFTUP", CSM_CHECKONOFF, newvalue); |
||
937 | |||
938 | -- Save and synchronize the new values |
||
939 | CosmosMaster_Save() |
||
940 | end |
||
941 | end |
||
942 | |||
943 | function EquipCompare_Toggle(toggle) |
||
944 | -- workaround, as Cosmos sends a 0 when it wants to turn us off |
||
945 | if ( toggle == 0 ) then toggle = false; end |
||
946 | -- turn on |
||
947 | if ( toggle and not EquipCompare_Enabled ) then |
||
948 | EquipCompare_Enabled = true; |
||
949 | EquipCompare_Recheck = true; |
||
950 | -- In case Blizzard's ShoppingTooltips are visible, hide them |
||
951 | ShoppingTooltip1:Hide(); |
||
952 | ShoppingTooltip2:Hide(); |
||
953 | end |
||
954 | -- turn off |
||
955 | if ( not toggle and EquipCompare_Enabled ) then |
||
956 | EquipCompare_Enabled = false; |
||
957 | EquipCompare_HideTips(); |
||
958 | end |
||
959 | end |
||
960 | |||
961 | function EquipCompare_ToggleControl(toggle) |
||
962 | -- workaround, as Cosmos sends a 0 when it wants to turn us off |
||
963 | if ( toggle == 0 ) then toggle = false; end |
||
964 | -- turn on |
||
965 | if ( toggle ) then |
||
966 | EquipCompare_ControlMode = true; |
||
967 | end |
||
968 | -- turn off |
||
969 | if ( not toggle ) then |
||
970 | EquipCompare_ControlMode = false; |
||
971 | end |
||
972 | end |
||
973 | |||
974 | function EquipCompare_ToggleCV(toggle) |
||
975 | -- workaround, as Cosmos sends a 0 when it wants to turn us off |
||
976 | if ( toggle == 0 ) then toggle = false; end |
||
977 | -- turn on |
||
978 | if ( toggle ) then |
||
979 | EquipCompare_UseCV = true; |
||
980 | if ( IsCharactersViewer() ) then |
||
981 | if ( EquipCompare_AltMode ) then |
||
982 | EquipCompare_CharactersViewer = lastAltState; |
||
983 | else |
||
984 | EquipCompare_CharactersViewer = true; |
||
985 | end |
||
986 | else |
||
987 | EquipCompare_CharactersViewer = false; |
||
988 | end |
||
989 | end |
||
990 | -- turn off |
||
991 | if ( not toggle ) then |
||
992 | EquipCompare_UseCV = false; |
||
993 | EquipCompare_CharactersViewer = false; |
||
994 | end |
||
995 | end |
||
996 | |||
997 | function EquipCompare_ToggleAlt(toggle) |
||
998 | -- workaround, as Cosmos sends a 0 when it wants to turn us off |
||
999 | if ( toggle == 0 ) then toggle = false; end |
||
1000 | -- turn on |
||
1001 | if ( toggle ) then |
||
1002 | EquipCompare_AltMode = true; |
||
1003 | end |
||
1004 | -- turn off |
||
1005 | if ( not toggle ) then |
||
1006 | EquipCompare_AltMode = false; |
||
1007 | if ( IsCharactersViewer() ) then |
||
1008 | EquipCompare_CharactersViewer = true; |
||
1009 | EquipCompare_Recheck = true; |
||
1010 | end |
||
1011 | end |
||
1012 | end |
||
1013 | |||
1014 | function EquipCompare_ToggleShiftup(toggle) |
||
1015 | -- workaround, as Cosmos sends a 0 when it wants to turn us off |
||
1016 | if ( toggle == 0 ) then toggle = false; end |
||
1017 | -- turn on |
||
1018 | if ( toggle ) then |
||
1019 | EquipCompare_Shiftup = true; |
||
1020 | end |
||
1021 | -- turn off |
||
1022 | if ( not toggle ) then |
||
1023 | EquipCompare_Shiftup = false; |
||
1024 | end |
||
1025 | EquipCompare_Recheck = true; |
||
1026 | end |
||
1027 | |||
1028 | function EquipCompare_HideTips() |
||
1029 | ComparisonTooltip1:Hide(); |
||
1030 | ComparisonTooltip2:Hide(); |
||
1031 | end |
||
1032 | |||
1033 | -- |
||
1034 | -- Local functions for ShowCompare() |
||
1035 | -- |
||
1036 | |||
1037 | -- Add a label at the top of the tooltip saying "Currently Equipped" |
||
1038 | local function AddLabel(tooltip, slot) |
||
1039 | local tLabel, tLabel1; |
||
1040 | |||
1041 | if (not tooltip or not tooltip:IsVisible()) then |
||
1042 | return; |
||
1043 | end |
||
1044 | |||
1045 | tLabel = getglobal(tooltip:GetName().."TextLeft0"); |
||
1046 | tLabel:SetText(EQUIPCOMPARE_EQUIPPED_LABEL); |
||
1047 | tLabel:SetTextColor(0.5, 0.5, 0.5); |
||
1048 | tLabel:Show(); |
||
1049 | |||
1050 | tLabel1 = getglobal(tooltip:GetName().."TextLeft1"); |
||
1051 | if ( tLabel:IsVisible() and tLabel1:IsVisible() ) then |
||
1052 | if ( tLabel:GetWidth() > tLabel1:GetWidth() ) then |
||
1053 | tLabel1:SetWidth(tLabel:GetWidth()); |
||
1054 | tooltip:Show(); |
||
1055 | end |
||
1056 | end |
||
1057 | end |
||
1058 | |||
1059 | -- Display a comparison tooltip and set its contents to currently equipped item |
||
1060 | -- occupying slotid |
||
1061 | local function ShowComparisonTooltip(parent, slotid) |
||
1062 | local leftAlign, donePlacing; |
||
1063 | local left, right, i; |
||
1064 | |||
1065 | -- Set contents of tooltip. |
||
1066 | |||
1067 | -- Note: you can't set a tooltip's contents before specifying at least |
||
1068 | -- one point. Hence anchor it to whatever, even if you later change |
||
1069 | -- its placement. |
||
1070 | ComparisonTooltip1:SetOwner(parent, "ANCHOR_LEFT"); |
||
1071 | if ( EquipCompare_CharactersViewer ) then |
||
1072 | CharactersViewer_Tooltip_SetInventoryItem(ComparisonTooltip1, slotid); |
||
1073 | else |
||
1074 | ComparisonTooltip1:SetInventoryItem("player", slotid); |
||
1075 | end |
||
1076 | AddLabel(ComparisonTooltip1, slotid); |
||
1077 | |||
1078 | if ( not ComparisonTooltip1:IsVisible() ) then |
||
1079 | return; |
||
1080 | end; |
||
1081 | |||
1082 | -- Set placement of tooltip |
||
1083 | |||
1084 | leftAlign = false; |
||
1085 | if ( parent == GameTooltip and GetMouseFocus() ) then |
||
1086 | local mfocus = GetMouseFocus():GetName(); |
||
1087 | if ( mfocus and string.find(mfocus,"^ContainerFrame.*Item") ) then |
||
1088 | leftAlign = true; |
||
1089 | end |
||
1090 | end |
||
1091 | |||
1092 | donePlacing = true; |
||
1093 | repeat |
||
1094 | ComparisonTooltip1:ClearAllPoints(); |
||
1095 | if (leftAlign) then |
||
1096 | ComparisonTooltip1:SetPoint("TOPRIGHT", parent:GetName(), "TOPLEFT", 0, -10); |
||
1097 | else |
||
1098 | ComparisonTooltip1:SetPoint("TOPLEFT", parent:GetName(), "TOPRIGHT", 0, -10); |
||
1099 | end |
||
1100 | |||
1101 | local left = ComparisonTooltip1:GetLeft(); |
||
1102 | local right = ComparisonTooltip1:GetRight(); |
||
1103 | |||
1104 | if ( left and right ) then |
||
1105 | left, right = left - (right-left), right + (right-left); |
||
1106 | end |
||
1107 | |||
1108 | -- If the comparison tooltip would be off the screen, place it on other |
||
1109 | -- side instead. Only perform this check once to avoid endless loop. |
||
1110 | if ( donePlacing ) then |
||
1111 | if ( left and left<0 ) then |
||
1112 | leftAlign = false; |
||
1113 | donePlacing = false; |
||
1114 | elseif ( right and right>UIParent:GetRight() ) then |
||
1115 | leftAlign = true; |
||
1116 | donePlacing = false; |
||
1117 | end |
||
1118 | else |
||
1119 | donePlacing = true; |
||
1120 | end |
||
1121 | until donePlacing; |
||
1122 | |||
1123 | return leftAlign; |
||
1124 | end |
||
1125 | |||
1126 | function EquipCompare_CheckCompare() |
||
1127 | local tooltip = nil; |
||
1128 | local i = 1; |
||
1129 | |||
1130 | if ( not EquipCompare_TooltipList ) then |
||
1131 | EquipCompare_InitializeTooltipList(); |
||
1132 | end |
||
1133 | |||
1134 | -- Check which tooltip we are intersted in, in order of priority |
||
1135 | repeat |
||
1136 | tooltip = EquipCompare_TooltipList[i]; |
||
1137 | if ( not tooltip:IsVisible() ) then |
||
1138 | tooltip = nil; |
||
1139 | end |
||
1140 | i = i + 1; |
||
1141 | until tooltip or i > table.getn(EquipCompare_TooltipList) |
||
1142 | |||
1143 | EquipCompare_TargetTooltip = tooltip; |
||
1144 | EquipCompare_Alignment = nil; |
||
1145 | |||
1146 | if ( tooltip ) then |
||
1147 | EquipCompare_ShowCompare(tooltip); |
||
1148 | end |
||
1149 | end |
||
1150 | |||
1151 | local function GetSlotID(slotName) |
||
1152 | if (slotName) then |
||
1153 | return GetInventorySlotInfo(slotName); |
||
1154 | end |
||
1155 | end |
||
1156 | |||
1157 | function EquipCompare_ShowCompare(tooltip) |
||
1158 | -- |
||
1159 | -- Main code of EquipCompare_ShowCompare starts here |
||
1160 | -- |
||
1161 | |||
1162 | local OverrideTooltips = nil; |
||
1163 | local ttext, itype, slotid, other, leftAlign; |
||
1164 | local i, cvplayer; |
||
1165 | local shift, comptipclose, comptipfar, point, relative; |
||
1166 | local mfocus; |
||
1167 | |||
1168 | -- Start processing |
||
1169 | |||
1170 | EquipCompare_Recheck = false; |
||
1171 | EquipCompare_HideTips(); |
||
1172 | |||
1173 | -- In some cases it is desirable to override the restrictions on showing |
||
1174 | -- comparison tooltips, and show them anyway. Check for that here. |
||
1175 | |||
1176 | if ( EquipCompare_CharactersViewer ) then |
||
1177 | cvplayer = CharactersViewer.index; |
||
1178 | if ( cvplayer == nil ) then |
||
1179 | cvplayer = UnitName("player"); |
||
1180 | end |
||
1181 | if ( UnitName("player") ~= cvplayer ) then |
||
1182 | OverrideTooltips = true; |
||
1183 | end |
||
1184 | if ( EquipCompare_CVFrame:IsVisible() and |
||
1185 | MouseIsOver(EquipCompare_CVFrame) and tooltip == GameTooltip ) then |
||
1186 | OverrideTooltips = false; |
||
1187 | end |
||
1188 | end |
||
1189 | |||
1190 | -- Special checks when we are attaching to GameTooltip. For some frames, we do |
||
1191 | -- not want to provide comparison tooltips. |
||
1192 | if ( tooltip == GameTooltip ) then |
||
1193 | if ( GetMouseFocus() ) then |
||
1194 | mfocus = GetMouseFocus():GetName(); |
||
1195 | end |
||
1196 | if ( not OverrideTooltips and mfocus ) then |
||
1197 | for i=1, table.getn(EquipCompare_BarList) do |
||
1198 | if ( string.find(mfocus, EquipCompare_BarList[i]) ) then |
||
1199 | return; |
||
1200 | end |
||
1201 | end |
||
1202 | end |
||
1203 | end |
||
1204 | |||
1205 | -- Infer the type of the item from one of the 2nd to 5th line of its tooltip description |
||
1206 | -- Match this type against the appropriate slot |
||
1207 | slotid = nil; |
||
1208 | i = 2; |
||
1209 | repeat |
||
1210 | ttext = getglobal(tooltip:GetName().."TextLeft"..i); |
||
1211 | if ( ttext and ttext:IsVisible() ) then |
||
1212 | itype = ttext:GetText(); |
||
1213 | if ( itype ) then |
||
1214 | slotid = GetSlotID(EquipCompare_ItemTypes[itype]); |
||
1215 | end |
||
1216 | end |
||
1217 | i = i + 1; |
||
1218 | until (slotid or i > 5) |
||
1219 | |||
1220 | if ( slotid ) then |
||
1221 | -- Whilst we are in the process of displaying additional tooltips, we don't |
||
1222 | -- want to reset the EquipCompare_Recheck flag. This protection is necessary |
||
1223 | -- because calling SetOwner or SetxxxItem on any tooltip causes a |
||
1224 | -- CLEAR_TOOLTIP event. |
||
1225 | EquipCompare_Protected = true; |
||
1226 | |||
1227 | -- In case money line is visible on GameTooltip, must protect it by overriding |
||
1228 | -- GameTooltip_ClearMoney. This is because calling SetOwner or SetxxxItem on |
||
1229 | -- any tooltip causes money line of GameTooltip to be cleared. |
||
1230 | local oldFunction = GameTooltip_ClearMoney; |
||
1231 | GameTooltip_ClearMoney = EquipCompare_EmptyFunction; |
||
1232 | |||
1233 | -- Display a comparison tooltip and set its contents to currently equipped item |
||
1234 | leftAlign = ShowComparisonTooltip(tooltip, slotid); |
||
1235 | |||
1236 | other = false; |
||
1237 | -- If this is an item that can go into multiple slots, display additional |
||
1238 | -- tooltips as appropriate |
||
1239 | if ( itype == INVTYPE_FINGER ) then |
||
1240 | other = GetSlotID(EquipCompare_ItemTypes[INVTYPE_FINGER_OTHER]); |
||
1241 | end |
||
1242 | if ( itype == INVTYPE_TRINKET ) then |
||
1243 | other = GetSlotID(EquipCompare_ItemTypes[INVTYPE_TRINKET_OTHER]); |
||
1244 | end |
||
1245 | if ( itype == INVTYPE_WEAPON ) then |
||
1246 | other = GetSlotID(EquipCompare_ItemTypes[INVTYPE_WEAPON_OTHER]); |
||
1247 | end |
||
1248 | |||
1249 | if ( itype == INVTYPE_2HWEAPON ) then |
||
1250 | other = GetSlotID(EquipCompare_ItemTypes[INVTYPE_SHIELD]); |
||
1251 | end |
||
1252 | |||
1253 | if ( other ) then |
||
1254 | if ( ComparisonTooltip1:IsVisible() ) then |
||
1255 | -- First set the contents of the 2nd tooltip. |
||
1256 | -- Note that we must use either at least an anchor or SetPoint |
||
1257 | -- to be able to set the contents. |
||
1258 | ComparisonTooltip2:SetOwner(ComparisonTooltip1, "ANCHOR_LEFT"); |
||
1259 | if ( EquipCompare_CharactersViewer ) then |
||
1260 | CharactersViewer_Tooltip_SetInventoryItem(ComparisonTooltip2, other); |
||
1261 | else |
||
1262 | ComparisonTooltip2:SetInventoryItem("player", other); |
||
1263 | end |
||
1264 | AddLabel(ComparisonTooltip2, other); |
||
1265 | |||
1266 | if ( ComparisonTooltip2:IsVisible() ) then |
||
1267 | -- Now place it in its rightful place |
||
1268 | ComparisonTooltip2:ClearAllPoints(); |
||
1269 | if ( leftAlign ) then |
||
1270 | ComparisonTooltip1:ClearAllPoints(); |
||
1271 | ComparisonTooltip2:SetPoint("TOPRIGHT", tooltip:GetName(), "TOPLEFT", 0, -10); |
||
1272 | ComparisonTooltip1:SetPoint("TOPRIGHT", "ComparisonTooltip2", "TOPLEFT", 0, 0); |
||
1273 | else |
||
1274 | ComparisonTooltip2:SetPoint("TOPLEFT", "ComparisonTooltip1", "TOPRIGHT", 0, 0); |
||
1275 | end |
||
1276 | end |
||
1277 | else |
||
1278 | ShowComparisonTooltip(tooltip, other); |
||
1279 | end |
||
1280 | end |
||
1281 | |||
1282 | -- Record side of alignment |
||
1283 | if ( leftAlign ) then |
||
1284 | EquipCompare_Alignment = "left"; |
||
1285 | else |
||
1286 | EquipCompare_Alignment = "right"; |
||
1287 | end |
||
1288 | |||
1289 | -- If shifting upwards is set by user or requested by an AddOn, deal with it here |
||
1290 | if ( ComparisonTooltip1:IsVisible() and ( EquipCompare_Shiftup or |
||
1291 | ( EquipCompare_ShiftupObject == tooltip and EquipCompare_ShiftupSide == |
||
1292 | EquipCompare_Alignment and EquipCompare_ShiftupMargin > 0 ) ) ) then |
||
1293 | |||
1294 | if ( leftAlign ) then |
||
1295 | if ( ComparisonTooltip2:IsVisible() ) then |
||
1296 | comptipclose = ComparisonTooltip2; |
||
1297 | comptipfar = ComparisonTooltip1; |
||
1298 | else |
||
1299 | comptipclose = ComparisonTooltip1; |
||
1300 | comptipfar = ComparisonTooltip2; |
||
1301 | end |
||
1302 | point = "TOPRIGHT"; |
||
1303 | relative = "TOPLEFT"; |
||
1304 | else |
||
1305 | comptipclose = ComparisonTooltip1; |
||
1306 | comptipfar = ComparisonTooltip2; |
||
1307 | point = "TOPLEFT"; |
||
1308 | relative = "TOPRIGHT"; |
||
1309 | end |
||
1310 | |||
1311 | shift = comptipclose:GetHeight()+10 - tooltip:GetHeight(); |
||
1312 | if ( shift > 0 ) then |
||
1313 | comptipclose:ClearAllPoints(); |
||
1314 | comptipclose:SetPoint(point, tooltip:GetName(), relative, 0, -10+shift); |
||
1315 | else |
||
1316 | shift = 0; |
||
1317 | end |
||
1318 | |||
1319 | if ( comptipfar:IsVisible() and ( EquipCompare_Shiftup or |
||
1320 | EquipCompare_ShiftupMargin > comptipclose:GetWidth() ) ) then |
||
1321 | shift = comptipfar:GetHeight()+10 - tooltip:GetHeight() - shift; |
||
1322 | if ( shift > 0 ) then |
||
1323 | comptipfar:ClearAllPoints(); |
||
1324 | comptipfar:SetPoint(point, comptipclose:GetName(), relative, 0, shift); |
||
1325 | end |
||
1326 | end |
||
1327 | end |
||
1328 | |||
1329 | -- Restore GameTooltip_ClearMoney overriding. |
||
1330 | GameTooltip_ClearMoney = oldFunction; |
||
1331 | |||
1332 | EquipCompare_Protected = false; |
||
1333 | end |
||
1334 | end |