vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 QuickLoot: easier, faster looting
4 copyright 2004 by Telo
5  
6 - Automatically positions the most relevant part of the loot window under your cursor
7  
8 ]]
9  
10 --------------------------------------------------------------------------------------------------
11 -- Configuration variables
12 --------------------------------------------------------------------------------------------------
13  
14 QuickLoot_AutoHide = 1; -- set to 1 if you want the window to auto-hide when there's no loot
15 QuickLoot_OnScreen = 1; -- set to 1 if you want the window to remain completly on screen
16 QuickLoot_MoveOnce = 1; -- set to 1 if you want the window to only move once
17  
18 --------------------------------------------------------------------------------------------------
19 -- Local variables
20 --------------------------------------------------------------------------------------------------
21  
22 -- Function hooks
23 local originalLootFrame_OnEvent;
24 local originalLootFrame_Update;
25  
26 --------------------------------------------------------------------------------------------------
27 -- Internal functions
28 --------------------------------------------------------------------------------------------------
29  
30 -- Basically, what this function does is ensure that the LootFrame window is not placed outside the screen
31 local function LootFrame_SetLootFramePoint(x, y)
32 if (QuickLoot_OnScreen) then
33 local screenWidth = GetScreenWidth();
34 if (UIParent:GetWidth() > screenWidth) then
35 screenWidth = UIParent:GetWidth();
36 end
37 local screenHeight = GetScreenHeight();
38  
39 -- LootFrame is set to 256 wide in the xml file, but is actually only 191 wide
40 -- This is based on calculation envolving the offset on the close button:
41 -- The height is always 256, which is the correct number.
42 local windowWidth = 191;
43 local windowHeight = 256;
44  
45 if ( (x + windowWidth) > screenWidth ) then
46 x = screenWidth - windowWidth;
47 end
48 if ( y > screenHeight ) then
49 y = screenHeight;
50 end
51 if ( x < 0 ) then
52 x = 0;
53 end
54 if ( (y - windowHeight) < 0 ) then
55 y = windowHeight;
56 end
57 --Print("wWith: "..windowWidth..", wHeight: "..windowHeight..", X: "..x..", Y: "..y..", sWidth: "..screenWidth..", sHeight: "..screenHeight);
58 end
59  
60 LootFrame:ClearAllPoints();
61 LootFrame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT", x, y);
62 end
63  
64 function LootFrame_ItemUnderCursor()
65 local index;
66 local x, y = GetCursorPosition();
67 local scale = LootFrame:GetEffectiveScale();
68  
69 x = x / scale;
70 y = y / scale;
71  
72 LootFrame:ClearAllPoints();
73  
74 for index = 1, LOOTFRAME_NUMBUTTONS, 1 do
75 local button = getglobal("LootButton"..index);
76 if( button:IsVisible() ) then
77 x = x - 42;
78 y = y + 56 + (40 * index);
79 LootFrame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT", x, y);
80 return;
81 end
82 end
83  
84 if( LootFrameDownButton:IsVisible() ) then
85 -- If down arrow, position on it
86 x = x - 158;
87 y = y + 223;
88 else
89 if( QuickLoot_AutoHide and GetNumLootItems() == 0 ) then
90 HideUIPanel(LootFrame);
91 return
92 end
93 -- Otherwise, position on close box
94 x = x - 173;
95 y = y + 25;
96 end
97  
98 LootFrame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT", x, y);
99 end
100  
101 local function QuickLoot_LootFrame_OnEvent(event)
102 originalLootFrame_OnEvent(event);
103 if ( event == "VARIABLES_LOADED" ) then
104 if ( UltimateUI_RegisterConfiguration ) then
105 QuickLoot_RegisterUltimateUI()
106 end
107 end
108 if ( event == "LOOT_SLOT_CLEARED" ) then
109 if ( QuickLoot_MoveOnce ~= 1 ) then
110 LootFrame_ItemUnderCursor();
111 end
112 end
113 if ( event == "LOOT_OPENED" ) then
114 local lootItems = GetNumLootItems();
115 if ( lootItems == 0 ) then
116 if( QuickLoot_AutoHide ) then
117 CloseLoot();
118 local info = ChatTypeInfo["LOOT"];
119 ChatFrame1:AddMessage(ERR_LOOT_NONE, info.r, info.g, info.b, info.id);
120 end
121 elseif ( QuickLoot_MoveOnce == 1 ) then
122 LootFrame_ItemUnderCursor();
123 end
124 end
125 end
126  
127 local function QuickLoot_LootFrame_Update()
128 originalLootFrame_Update();
129 if ( QuickLoot_MoveOnce ~= 1 ) then
130 LootFrame_ItemUnderCursor();
131 end
132 end
133  
134 function QuickLoot_RegisterUltimateUI()
135 UltimateUI_RegisterConfiguration(
136 "UUI_QUICKLOOT",
137 "SECTION",
138 ULTIMATEUI_CONFIG_QLOOT_HEADER,
139 ULTIMATEUI_CONFIG_QLOOT_HEADER_INFO
140 );
141 UltimateUI_RegisterConfiguration(
142 "UUI_QUICKLOOT_HEADER",
143 "SEPARATOR",
144 ULTIMATEUI_CONFIG_QLOOT_HEADER,
145 ULTIMATEUI_CONFIG_QLOOT_HEADER_INFO
146 );
147 UltimateUI_RegisterConfiguration(
148 "UUI_QUICKLOOT_ONOFF",
149 "CHECKBOX",
150 TEXT(ULTIMATEUI_CONFIG_QLOOT),
151 TEXT(ULTIMATEUI_CONFIG_QLOOT_INFO),
152 QuickLoot_Enable,
153 1
154 );
155 UltimateUI_RegisterConfiguration(
156 "UUI_QUICKLOOT_HIDE",
157 "CHECKBOX",
158 TEXT(ULTIMATEUI_CONFIG_QLOOT_HIDE),
159 TEXT(ULTIMATEUI_CONFIG_QLOOT_HIDE_INFO),
160 QuickLoot_Hide_Enable,
161 1
162 );
163 UltimateUI_RegisterConfiguration(
164 "UUI_QUICKLOOT_ONSCREEN",
165 "CHECKBOX",
166 TEXT(ULTIMATEUI_CONFIG_QLOOT_ONSCREEN),
167 TEXT(ULTIMATEUI_CONFIG_QLOOT_ONSCREEN_INFO),
168 QuickLoot_OnScreen_Enable,
169 1
170 );
171 UltimateUI_RegisterConfiguration(
172 "UUI_QUICKLOOT_MOVE_ONCE",
173 "CHECKBOX",
174 TEXT(ULTIMATEUI_CONFIG_QLOOT_MOVE_ONCE),
175 TEXT(ULTIMATEUI_CONFIG_QLOOT_MOVE_ONCE_INFO),
176 QuickLoot_MoveOnce_Enable,
177 1
178 );
179 end
180  
181 --------------------------------------------------------------------------------------------------
182 -- OnFoo functions
183 --------------------------------------------------------------------------------------------------
184 function QuickLoot_OnLoad()
185 this:RegisterEvent("VARIABLES_LOADED");
186 this:RegisterEvent("LOOT_SLOT_CLEARED");
187 this:RegisterEvent("LOOT_OPENED");
188  
189 -- Hook the LootFrame_OnEvent function
190 originalLootFrame_OnEvent = LootFrame_OnEvent;
191 LootFrame_OnEvent = QuickLoot_LootFrame_OnEvent;
192  
193 -- Hook the LootFrame_Update function
194 originalLootFrame_Update = LootFrame_Update;
195 LootFrame_Update = QuickLoot_LootFrame_Update;
196  
197 -- Don't treat the LootFrame as a UI panel
198 UIPanelWindows["LootFrame"] = nil;
199  
200 if ( not QuickLoot_RegisterUltimateUI() ) then
201 SlashCmdList["QUICKLOOTSLASH"] = QuickLoot_ChatCommandHandler;
202 SLASH_QUICKLOOTSLASH1 = "/quickloot";
203 end
204 end
205  
206 function QuickLoot_Enable(toggle)
207 if ( toggle == 1 ) then
208 QuickLoot_Enabled = 1;
209 else
210 QuickLoot_Enabled = 0;
211 end
212 end
213  
214 function QuickLoot_Hide_Enable(toggle)
215 if ( toggle == 1 ) then
216 QuickLoot_AutoHide = 1;
217 else
218 QuickLoot_AutoHide = nil;
219 end
220 end
221  
222 function QuickLoot_OnScreen_Enable(toggle)
223 if ( toggle == 1 ) then
224 QuickLoot_OnScreen = 1;
225 else
226 QuickLoot_OnScreen = nil;
227 end
228 end
229  
230 function QuickLoot_MoveOnce_Enable(toggle)
231 if ( toggle == 1 ) then
232 QuickLoot_MoveOnce = 1;
233 else
234 QuickLoot_MoveOnce = nil;
235 end
236 end
237  
238 function QuickLoot_ChatCommandHandler(msg)
239 if ( ( not msg ) or ( strlen(msg) <= 0) ) then
240 QuickLoot_Print(QUICKLOOT_CHAT_COMMAND_USAGE);
241 return
242 end
243 local command = string.lower(msg);
244 local varName = nil;
245 local varText = nil;
246 if ( command == "enable" ) then
247 varName = "QuickLoot_Enabled";
248 varText = QUICKLOOT_CHAT_COMMAND_ENABLE;
249 elseif ( command == "autohide" ) then
250 varName = "QuickLoot_AutoHide";
251 varText = QUICKLOOT_CHAT_COMMAND_HIDE;
252 elseif ( command == "onscreen" ) then
253 varName = "QuickLoot_OnScreen";
254 varText = QUICKLOOT_CHAT_COMMAND_ONSCREEN;
255 elseif ( strfind(command, "once") ) then
256 varName = "QuickLoot_MoveOnce";
257 varText = QUICKLOOT_CHAT_COMMAND_MOVE_ONCE;
258 end
259 if ( varName ) then
260 local oldValue = getglobal(varName);
261 local newValue = nil;
262 if ( ( not curValue ) or ( curValue == 0 ) ) then
263 newValue = 1;
264 else
265 newValue = 0;
266 end
267 if ( newValue == 1 ) then
268 setglobal(varName, 1);
269 if ( varText ) then
270 QuickLoot_Print(varText..QUICKLOOT_CHAT_STATE_ENABLED);
271 end
272 else
273 setglobal(varName, nil);
274 if ( varText ) then
275 QuickLoot_Print(varText..QUICKLOOT_CHAT_STATE_DISABLED);
276 end
277 end
278 else
279 QuickLoot_Print(QUICKLOOT_CHAT_COMMAND_USAGE);
280 return
281 end
282 end
283  
284 function QuickLoot_Print(msg)
285 if ( ( msg ) and ( strlen(msg) > 0 ) ) then
286 if( Print ) then
287 Print(msg);
288 return;
289 end
290 if ( DEFAULT_CHAT_FRAME ) then
291 DEFAULT_CHAT_FRAME:AddMessage(msg, 1, 1, 0);
292 end
293 end
294 end
295