vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 Tooltip Wrangler
4  
5 - Allows the user to move the tooltips freely about the screen.
6 Works great with most other tooltip mod programs including AF_Tooltip and GypsyMod.
7  
8 ]]
9  
10 --------------------------------------------------------------------------------------------------
11 -- Localizable strings
12 --------------------------------------------------------------------------------------------------
13 TTW_LOCK = "lock"; -- must be lowercase; locks the window in position
14 TTW_UNLOCK = "unlock"; -- must be lowercase; unlocks the window so that it can be dragged
15 TTW_HELP = "help";
16 TTW_FOLLOWMOUSE = "mouse";
17 TTW_USETARGET = "target";
18 TTW_RESET = "reset";
19  
20 TTW_LOCKED = "Tooltip Wrangler: Locked in place.";
21 TTW_UNLOCKED = "Tooltip Wrangler: Unlocked. Position at will!";
22 TTW_INVALID = "Tooltip Wrangler: Invalid command. Type /ttw help for a list of valid commands.";
23 TTW_TARGET_MSG = "Tooltip Wrangler: Tooltips have been placed at the target.";
24 TTW_MOUSE_MSG = "Tooltip Wrangler: Tooltips have been placed at the cursor."
25 TTW_HELP_MSG = "Tooltip Wrangler: Below is a listing of valid commands \(use /ttw <command>\):\nmouse: Attach the tooltip to the mouse cursor.\ntarget: Drag the targeting window to place the tooltip.\nlock: Lock the tooltip in place \(hides the placement window\).\nunlock: Unlock the tooltip placement window \(Shows the placement window\).";
26  
27 --------------------------------------------------------------------------------------------------
28 -- Local Variables
29 --------------------------------------------------------------------------------------------------
30 TTW_TOPLEFT = 0;
31 TTW_TOPRIGHT = 1;
32 TTW_BOTTOMRIGHT = 2;
33 TTW_BOTTOMLEFT = 3;
34 TTW_TOP = 4;
35 TTW_BOTTOM = 5;
36 TTW_LEFT = 6;
37 TTW_RIGHT = 7;
38  
39 TTW_MOUSE = 0;
40 TTW_TARGET = 1;
41  
42 --------------------------------------------------------------------------------------------------
43 -- Internal functions
44 --------------------------------------------------------------------------------------------------
45  
46 function TTW_PositionTooltip(tooltip,parent)
47 anchorType = TTWState.AnchorType;
48  
49 if (anchorType == TTW_MOUSE) then
50 tooltip:SetOwner(parent, "ANCHOR_CURSOR");
51 else
52 local topPos,leftPos,bottomPos,rightPos;
53 topPos = TTW_RecticleFrame:GetTop();
54 leftPos = TTW_RecticleFrame:GetLeft();
55 bottomPos = TTW_RecticleFrame:GetBottom();
56 rightPos = TTW_RecticleFrame:GetRight();
57  
58 if (rightPos == nil) then
59 rightPos = 0;
60 end
61 if (leftPos == nil) then
62 leftPos = 0;
63 end
64 if (topPos == nil) then
65 topPos = 0;
66 end
67 if (bottomPos == nil) then
68 bottomPos = 0;
69 end
70  
71  
72 local xPos,yPos;
73 xPos = leftPos + ((rightPos-leftPos) / 2);
74 yPos = topPos + ((bottomPos - topPos) / 2);
75  
76 tooltip:ClearAllPoints();
77 tooltip:SetOwner(parent, "ANCHOR_NONE");
78  
79 anchor = TTWState.Anchor;
80  
81 if (anchor == TTW_TOPLEFT) then
82 anchor = "TOPLEFT";
83 xPos = xPos - 3;
84 yPos = yPos + 3;
85 elseif (anchor == TTW_TOPRIGHT) then
86 anchor = "TOPRIGHT";
87 xPos = xPos + 3;
88 yPos = yPos + 3;
89 elseif (anchor == TTW_BOTTOMRIGHT) then
90 anchor = "BOTTOMRIGHT";
91 xPos = xPos + 3;
92 yPos = yPos - 3;
93 elseif (anchor == TTW_TOP) then
94 anchor = "TOP";
95 xPos = xPos - 3;
96 yPos = yPos + 3;
97 elseif (anchor == TTW_BOTTOM) then
98 anchor = "BOTTOM";
99 xPos = xPos - 3;
100 yPos = yPos - 3;
101 elseif (anchor == TTW_LEFT) then
102 anchor = "LEFT";
103 xPos = xPos - 3;
104 elseif (anchor == TTW_RIGHT) then
105 anchor = "RIGHT";
106 xPos = xPos - 3;
107 else
108 anchor = "BOTTOMLEFT";
109 xPos = xPos - 3;
110 yPos = yPos - 3;
111 end
112  
113 local scale = UIParent:GetScale() / GameTooltip:GetEffectiveScale();
114 xPos = scale * xPos;
115 yPos = scale * yPos;
116  
117 tooltip:SetPoint(anchor, "UIParent", "BOTTOMLEFT", xPos, yPos);
118 end
119 end
120  
121 function TTW_Reset()
122 TTW_RecticleFrame:SetPoint("TOPLEFT","UIParent","TOPLEFT",200,-200);
123 end
124  
125 function TTW_SlashCommandHandler(msg)
126 if( msg ) then
127 local command = string.lower(msg);
128 if( command == TTW_LOCK ) then
129 if ( TTWState.AnchorType ~= TTW_MOUSE ) then
130 TTWState.Lock = 1;
131 TTW_RecticleFrame:Hide();
132 GameTooltip:Hide();
133 DEFAULT_CHAT_FRAME:AddMessage(TTW_LOCKED);
134 end
135 elseif( command == TTW_UNLOCK ) then
136 if ( TTWState.AnchorType ~= TTW_MOUSE ) then
137 TTWState.Lock = nil;
138 TTW_RecticleFrame:Show();
139 DEFAULT_CHAT_FRAME:AddMessage(TTW_UNLOCKED);
140 end
141 elseif( command == TTW_FOLLOWMOUSE ) then
142 TTWState.AnchorType = TTW_MOUSE;
143 TTW_RecticleFrame:Hide();
144 GameTooltip:Hide();
145 DEFAULT_CHAT_FRAME:AddMessage(TTW_MOUSE_MSG);
146 elseif ( command == TTW_USETARGET ) then
147 TTWState.AnchorType = TTW_TARGET;
148 TTW_RecticleFrame:Show();
149 DEFAULT_CHAT_FRAME:AddMessage(TTW_TARGET_MSG);
150 TTWState.Lock = nil;
151 DEFAULT_CHAT_FRAME:AddMessage(TTW_UNLOCKED);
152 elseif ( command == TTW_HELP or command=="" ) then
153 DEFAULT_CHAT_FRAME:AddMessage(TTW_HELP_MSG);
154 elseif ( command == TTW_RESET ) then
155 TTW_Reset();
156 else
157 DEFAULT_CHAT_FRAME:AddMessage(TTW_INVALID);
158 end
159 end
160 end
161  
162 function TTW_SetClickState(state)
163 if (state == TTW_TOPLEFT) then
164 TTW_AnchorTopLeftButton:SetButtonState("PUSHED",1);
165 TTW_AnchorTopRightButton:SetButtonState("NORMAL",0);
166 TTW_AnchorBottomRightButton:SetButtonState("NORMAL",0);
167 TTW_AnchorBottomLeftButton:SetButtonState("NORMAL",0);
168 TTW_AnchorTopButton:SetButtonState("NORMAL",0);
169 TTW_AnchorBottomButton:SetButtonState("NORMAL",0);
170 TTW_AnchorLeftButton:SetButtonState("NORMAL",0);
171 TTW_AnchorRightButton:SetButtonState("NORMAL",0);
172 elseif (state == TTW_TOPRIGHT) then
173 TTW_AnchorTopLeftButton:SetButtonState("NORMAL",0);
174 TTW_AnchorTopRightButton:SetButtonState("PUSHED",1);
175 TTW_AnchorBottomRightButton:SetButtonState("NORMAL",0);
176 TTW_AnchorBottomLeftButton:SetButtonState("NORMAL",0);
177 TTW_AnchorTopButton:SetButtonState("NORMAL",0);
178 TTW_AnchorBottomButton:SetButtonState("NORMAL",0);
179 TTW_AnchorLeftButton:SetButtonState("NORMAL",0);
180 TTW_AnchorRightButton:SetButtonState("NORMAL",0);
181 elseif (state == TTW_BOTTOMRIGHT) then
182 TTW_AnchorTopLeftButton:SetButtonState("NORMAL",0);
183 TTW_AnchorTopRightButton:SetButtonState("NORMAL",0);
184 TTW_AnchorBottomRightButton:SetButtonState("PUSHED",1);
185 TTW_AnchorBottomLeftButton:SetButtonState("NORMAL",0);
186 TTW_AnchorTopButton:SetButtonState("NORMAL",0);
187 TTW_AnchorBottomButton:SetButtonState("NORMAL",0);
188 TTW_AnchorLeftButton:SetButtonState("NORMAL",0);
189 TTW_AnchorRightButton:SetButtonState("NORMAL",0);
190 elseif (state == TTW_BOTTOMLEFT) then
191 TTW_AnchorTopLeftButton:SetButtonState("NORMAL",0);
192 TTW_AnchorTopRightButton:SetButtonState("NORMAL",0);
193 TTW_AnchorBottomRightButton:SetButtonState("NORMAL",0);
194 TTW_AnchorBottomLeftButton:SetButtonState("PUSHED",1);
195 TTW_AnchorTopButton:SetButtonState("NORMAL",0);
196 TTW_AnchorBottomButton:SetButtonState("NORMAL",0);
197 TTW_AnchorLeftButton:SetButtonState("NORMAL",0);
198 TTW_AnchorRightButton:SetButtonState("NORMAL",0);
199 elseif (state == TTW_TOP) then
200 TTW_AnchorTopLeftButton:SetButtonState("NORMAL",0);
201 TTW_AnchorTopRightButton:SetButtonState("NORMAL",0);
202 TTW_AnchorBottomRightButton:SetButtonState("NORMAL",0);
203 TTW_AnchorBottomLeftButton:SetButtonState("NORMAL",0);
204 TTW_AnchorTopButton:SetButtonState("PUSHED",1);
205 TTW_AnchorBottomButton:SetButtonState("NORMAL",0);
206 TTW_AnchorLeftButton:SetButtonState("NORMAL",0);
207 TTW_AnchorRightButton:SetButtonState("NORMAL",0);
208 elseif (state == TTW_BOTTOM) then
209 TTW_AnchorTopLeftButton:SetButtonState("NORMAL",0);
210 TTW_AnchorTopRightButton:SetButtonState("NORMAL",0);
211 TTW_AnchorBottomRightButton:SetButtonState("NORMAL",0);
212 TTW_AnchorBottomLeftButton:SetButtonState("NORMAL",0);
213 TTW_AnchorTopButton:SetButtonState("NORMAL",0);
214 TTW_AnchorBottomButton:SetButtonState("PUSHED",1);
215 TTW_AnchorLeftButton:SetButtonState("NORMAL",0);
216 TTW_AnchorRightButton:SetButtonState("NORMAL",0);
217 elseif (state == TTW_LEFT) then
218 TTW_AnchorTopLeftButton:SetButtonState("NORMAL",0);
219 TTW_AnchorTopRightButton:SetButtonState("NORMAL",0);
220 TTW_AnchorBottomRightButton:SetButtonState("NORMAL",0);
221 TTW_AnchorBottomLeftButton:SetButtonState("NORMAL",0);
222 TTW_AnchorTopButton:SetButtonState("NORMAL",0);
223 TTW_AnchorBottomButton:SetButtonState("NORMAL",0);
224 TTW_AnchorLeftButton:SetButtonState("PUSHED",1);
225 TTW_AnchorRightButton:SetButtonState("NORMAL",0);
226 elseif (state == TTW_RIGHT) then
227 TTW_AnchorTopLeftButton:SetButtonState("NORMAL",0);
228 TTW_AnchorTopRightButton:SetButtonState("NORMAL",0);
229 TTW_AnchorBottomRightButton:SetButtonState("NORMAL",0);
230 TTW_AnchorBottomLeftButton:SetButtonState("NORMAL",0);
231 TTW_AnchorTopButton:SetButtonState("NORMAL",0);
232 TTW_AnchorBottomButton:SetButtonState("NORMAL",0);
233 TTW_AnchorLeftButton:SetButtonState("NORMAL",0);
234 TTW_AnchorRightButton:SetButtonState("PUSHED",1);
235 end
236 end
237  
238  
239 --------------------------------------------------------------------------------------------------
240 -- Handler functions
241 --------------------------------------------------------------------------------------------------
242  
243 function TTW_TooltipOnLoad()
244 --RegisterForSave("TTWState");
245  
246 this:RegisterEvent("VARIABLES_LOADED");
247  
248 -- Register our slash command
249 SLASH_TTW1 = "/tooltipwrangler";
250 SLASH_TTW2 = "/ttw";
251 SlashCmdList["TTW"] = function(msg)
252 TTW_SlashCommandHandler(msg);
253 end
254  
255 if( DEFAULT_CHAT_FRAME ) then
256 DEFAULT_CHAT_FRAME:AddMessage("Tootip Wrangler: AddOn loaded");
257 end
258  
259 UIErrorsFrame:AddMessage("Tooltip Wrangler: AddOn loaded", 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME);
260 end
261  
262  
263 function TTW_TooltipOnEvent(event)
264 if( event == "VARIABLES_LOADED" ) then
265 if( not TTWState ) then
266 TTWState = { };
267 end
268  
269 if(TTWState.Lock==1) then
270 TTW_RecticleFrame:Hide();
271 GameTooltip:Hide();
272 DEFAULT_CHAT_FRAME:AddMessage(TTW_LOCKED);
273 else
274 TTW_RecticleFrame:Show();
275 DEFAULT_CHAT_FRAME:AddMessage(TTW_UNLOCKED);
276 end
277  
278 TTW_SetClickState(TTWState.Anchor);
279  
280 if (TTWState.AnchorType == TTW_MOUSE) then
281 TTW_RecticleFrame:Hide();
282 end
283  
284 GameTooltip_SetDefaultAnchor = TTW_PositionTooltip;
285 end
286 end
287  
288 function TTW_TooltipOnMouseDown()
289 GameTooltip:Hide();
290 TTW_RecticleFrame:StartMoving()
291 end
292  
293 function TTW_TooltipOnMouseUp()
294 TTW_RecticleFrame:StopMovingOrSizing()
295 end
296  
297 function TTW_AnchorTopLeftOnClick()
298 PlaySound("igMainMenuClose");
299 TTW_SetClickState(TTW_TOPLEFT);
300 TTWState.Anchor = TTW_TOPLEFT;
301 end
302  
303 function TTW_AnchorTopRightOnClick()
304 PlaySound("igMainMenuClose");
305 TTW_SetClickState(TTW_TOPRIGHT);
306 TTWState.Anchor = TTW_TOPRIGHT;
307 end
308  
309 function TTW_AnchorBottomRightOnClick()
310 PlaySound("igMainMenuClose");
311 TTW_SetClickState(TTW_BOTTOMRIGHT);
312 TTWState.Anchor = TTW_BOTTOMRIGHT;
313 end
314  
315 function TTW_AnchorBottomLeftOnClick()
316 PlaySound("igMainMenuClose");
317 TTW_SetClickState(TTW_BOTTOMLEFT);
318 TTWState.Anchor = TTW_BOTTOMLEFT;
319 end
320  
321 function TTW_AnchorTopOnClick()
322 PlaySound("igMainMenuClose");
323 TTW_SetClickState(TTW_TOP);
324 TTWState.Anchor = TTW_TOP;
325 end
326  
327 function TTW_AnchorBottomOnClick()
328 PlaySound("igMainMenuClose");
329 TTW_SetClickState(TTW_BOTTOM);
330 TTWState.Anchor = TTW_BOTTOM;
331 end
332  
333 function TTW_AnchorLeftOnClick()
334 PlaySound("igMainMenuClose");
335 TTW_SetClickState(TTW_LEFT);
336 TTWState.Anchor = TTW_LEFT;
337 end
338  
339 function TTW_AnchorRightOnClick()
340 PlaySound("igMainMenuClose");
341 TTW_SetClickState(TTW_RIGHT);
342 TTWState.Anchor = TTW_RIGHT;
343 end
344  
345 function TTW_ButtonTooltip()
346 if( this:GetCenter() < GetScreenWidth() / 2 ) then
347 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
348 else
349 GameTooltip:SetOwner(this, "ANCHOR_LEFT");
350 end
351  
352 if (this == TTW_AnchorTopLeftButton) then
353 GameTooltip:SetText("Anchor the \"Top Left\" corner of the\ntooltip to the center of the target.\n\(Right and Bottom edges will grow\)");
354 elseif (this == TTW_AnchorTopRightButton) then
355 GameTooltip:SetText("Anchor the \"Top Right\" corner of the\ntooltip to the center of the target.\n\(Left and Bottom edges will grow\)");
356 elseif (this == TTW_AnchorBottomRightButton) then
357 GameTooltip:SetText("Anchor the \"Bottom Right\" corner of the\ntooltip to the center of the target.\n\(Left and Top edges will grow\)");
358 elseif (this == TTW_AnchorBottomLeftButton) then
359 GameTooltip:SetText("Anchor the \"Bottom Left\" corner of the\ntooltip to the center of the target.\n\(Right and Top edges will grow\)");
360 elseif (this == TTW_AnchorTopButton) then
361 GameTooltip:SetText("Anchor the \"Top Center\" side of the\ntooltip to the center of the target.\n\(Bottom, Left and Right edges will grow\)");
362 elseif (this == TTW_AnchorBottomButton) then
363 GameTooltip:SetText("Anchor the \"Bottom Center\" side of the\ntooltip to the center of the target.\n\(Top, Left and Right edges will grow\)");
364 elseif (this == TTW_AnchorLeftButton) then
365 GameTooltip:SetText("Anchor the \"Left Center\" side of the\ntooltip to the center of the target.\n\(Top, Bottom and Right edges will grow\)");
366 elseif (this == TTW_AnchorRightButton) then
367 GameTooltip:SetText("Anchor the \"Right Center\" side of the\ntooltip to the center of the target.\n\(Top, Bottom and Left edges will grow\)");
368 end
369 end