vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 ----------------------------------------------------------
2 -- Add tooltip information to the existing GameTooltip
3 ----------------------------------------------------------
4 ----------------------------------------------------------
5 function QuestItem_AddTooltip(frame, name, link, quantity, itemCount)
6 --QuestItem_OldTooltip(frame, name, link, quality, itemCount);
7 if(QuestItem_Settings["Enabled"] == nil or QuestItem_Settings["Enabled"] == false) then
8 return;
9 end
10  
11 local tooltip = frame;
12 local embed = true;
13 if ( not tooltip ) then
14 return;
15 end
16  
17 local tooltipInfo = QuestItem_ScanTooltip(frame);
18 if ( tooltipInfo[1] ) then
19 -- Item not found in the database - look for it of it is a quest item
20 if(not QuestItems[name] or QuestItem_SearchString(QuestItems[name].QuestName, QUESTITEM_UNIDENTIFIED) ) then
21 -- Check if the item is a Quest Item
22 if(QuestItem_IsQuestItem(tooltip) ) then
23 local name = tooltipInfo[1].left;
24  
25 local QuestName, total, count, texture = QuestItem_FindQuest(name);
26 if(not QuestName) then
27 QuestItem_UpdateItem(name, QUESTITEM_UNIDENTIFIED, quantity, 0, 3)
28 else
29 QuestItem_UpdateItem(name, QuestName, count, total, 0)
30 end
31 end
32 end
33 -- Quest was found in the database
34 if(QuestItems[name]) then
35 -- There is data for the current player
36 if(QuestItems[name][UnitName("player")]) then
37 -- Total and Count is set, and is grater than 0 - don't want to display i.e 1/0
38 if( (QuestItems[name].Total and QuestItems[name].Total > 0) and (QuestItems[name][UnitName("player")].Count and QuestItems[name][UnitName("player")].Count > 0) ) then
39 tooltip:AddLine(QuestItems[name].QuestName .. " " .. QuestItems[name][UnitName("player")].Count .. "/" .. QuestItems[name].Total, 0.4, 0.5, 0.8);
40 else
41 tooltip:AddLine(QuestItems[name].QuestName, 0.4, 0.5, 0.8);
42 end
43  
44 -- Check status for quest - if it can't be found change status to abandoned/complete
45 if(QuestItems[name][UnitName("player")].QuestStatus ~= 0) then
46 if(not QuestItem_FindQuest(name)) then
47 QuestItems[name][UnitName("player")].QuestStatus = 1;
48 end
49 end
50 -- Do not display status on the quest if it is unidentified
51 if(not QuestItem_SearchString(QuestItems[name].QuestName, QUESTITEM_UNIDENTIFIED) ) then
52 -- Display quest status
53 if(QuestItems[name][UnitName("player")].QuestStatus == 0) then
54 tooltip:AddLine(QUESTITEM_QUESTACTIVE, 0, 1, 0);
55 elseif(QuestItems[name][UnitName("player")].QuestStatus == 1 or QuestItems[name][UnitName("player")].QuestStatus == 2) then
56 tooltip:AddLine(QUESTITEM_COMPLETEABANDONED, 0.7, 0.7, 07);
57 end
58 end
59 else
60 tooltip:AddLine(QuestItems[name].QuestName, 0.4, 0.5, 0.8);
61 end
62 tooltip:Show();
63 end
64 end
65 end
66  
67 local base_ContainerFrameItemButton_OnEnter;
68 local base_Chat_OnHyperlinkShow;
69 local base_GameTooltip_SetLootItem;
70 local base_ContainerFrame_Update;
71 local base_GameTooltip_SetInventoryItem;
72 local base_AIOI_ModifyItemTooltip;
73 local base_LootLinkItemButton_OnEnter;
74 local base_IMInv_ItemButton_OnEnter
75 local base_ItemsMatrixItemButton_OnEnter;
76 local base_ContainerFrameItemButton_OnClick;
77 local base_QuestItem_AIOI_ContainerFrameItemButton_OnClick;
78 local base_BankFrameItemButtonGeneric_OnClick;
79 local base_BankFrameItemButtonBag_OnClick;
80 --local base_EngInventory_ModifyItemTooltip;
81  
82 ----------------------------------
83 -- [[ Hook tooltip functions ]] --
84 ----------------------------------
85 function QuestItem_HookTooltip()
86 -- Hook in alternative Chat/Hyperlinking code
87 base_Chat_OnHyperlinkShow = ChatFrame_OnHyperlinkShow;
88 ChatFrame_OnHyperlinkShow = QuestItem_Chat_OnHyperlinkShow;
89  
90 -- ContainerFrame
91 base_ContainerFrameItemButton_OnEnter = ContainerFrameItemButton_OnEnter;
92 ContainerFrameItemButton_OnEnter = QuestItem_ContainerFrameItemButton_OnEnter;
93 base_ContainerFrame_Update = ContainerFrame_Update;
94 ContainerFrame_Update = QuestItem_ContainerFrameItemButton_Update;
95  
96 base_GameTooltip_SetLootItem = GameTooltip.SetLootItem;
97 GameTooltip.SetLootItem = QuestItem_GameTooltip_SetLootItem;
98  
99 base_GameTooltip_SetInventoryItem = GameTooltip.SetInventoryItem;
100 GameTooltip.SetInventoryItem = QuestItem_GameTooltip_SetInventoryItem;
101  
102 --[[ LootLink support - grabbed from Norganna's EnhTooltip ]]--
103 -- Hook the LootLink tooltip function
104 if(LootLinkItemButton_OnEnter ~= nil) then
105 base_LootLinkItemButton_OnEnter = LootLinkItemButton_OnEnter;
106 LootLinkItemButton_OnEnter = QuestItem_LootLinkItemButton_OnEnter;
107 QuestItem_Debug("Hooking to LootLink");
108 end
109  
110 --[[ AllInOneInventory support - grabbed from Norganna's EnhTooltip ]]--
111 if (AllInOneInventory_ModifyItemTooltip ~= nil) then
112 base_AIOI_ModifyItemTooltip = AllInOneInventory_ModifyItemTooltip;
113 AllInOneInventory_ModifyItemTooltip = QuestItem_AIOI_ModifyItemTooltip;
114 QuestItem_Debug("Hooking to AIOI");
115 end
116  
117 -- Hook click on inventory item
118 if(AllInOneInventoryFrameItemButton_OnClick ~= nil) then
119 base_ContainerFrameItemButton_OnClick = AllInOneInventoryFrameItemButton_OnClick;
120 AllInOneInventoryFrameItemButton_OnClick = QuestItem_ContainerFrameItemButton_OnClick;
121 else
122 base_ContainerFrameItemButton_OnClick = ContainerFrameItemButton_OnClick;
123 ContainerFrameItemButton_OnClick = QuestItem_ContainerFrameItemButton_OnClick;
124 end
125  
126 -- Hook bank item
127 base_BankFrameItemButtonGeneric_OnClick = BankFrameItemButtonGeneric_OnClick;
128 BankFrameItemButtonGeneric_OnClick = QuestItem_BankFrameItemButtonGeneric_OnClick;
129  
130 --base_BankFrameItemButtonBag_OnClick = BankFrameItemButtonBag_OnClick;
131 --BankFrameItemButtonBag_OnClick = QuestItem_BankFrameItemButtonBag_OnClick;
132  
133  
134 -- [[
135 if(EngInventory_ModifyItemTooltip ~= nil) then
136 base_EngInventory_ModifyItemTooltip = EngInventory_ModifyItemTooltip;
137 EngInventory_ModifyItemTooltip = QuestItem_AIOI_ModifyItemTooltip;
138 QuestItem_Debug("Hooking to EngInventory");
139 end
140 -- ]] --
141 end
142  
143 --[[ LootLink support - grabbed from Norganna's EnhTooltip ]]--
144 function QuestItem_getLootLinkLink(name)
145 local itemLink = ItemLinks[name];
146 if (itemLink and itemLink.c and itemLink.i and LootLink_CheckItemServer(itemLink, QuestItem_getLootLinkServer())) then
147 local item = string.gsub(itemLink.i, "(%d+):(%d+):(%d+):(%d+)", "%1:0:%3:%4");
148 local link = "|c"..itemLink.c.."|Hitem:"..item.."|h["..name.."]|h|r";
149 return link;
150 end
151 return nil;
152 end
153  
154 function QuestItem_getLootLinkServer()
155 return LootLinkState.ServerNamesToIndices[GetCVar("realmName")];
156 end
157  
158 --[[ LootLink support - grabbed from Norganna's EnhTooltip ]]--
159 function QuestItem_LootLinkItemButton_OnEnter()
160 base_LootLinkItemButton_OnEnter();
161  
162 local name = this:GetText();
163 local link = QuestItem_getLootLinkLink(name);
164 if (link) then
165 local quality = QuestItem_qualityFromLink(link);
166 QuestItem_AddTooltip(LootLinkTooltip, name, link, quality, 0)
167 end
168 end
169  
170 --------------------------------------------------
171 -- [[ Hook up with AllInOneInventory tooltip ]] --
172 --------------------------------------------------
173 function QuestItem_AIOI_ModifyItemTooltip(bag, slot, tooltipName, empty)
174 if(base_AIOI_ModifyItemTooltip ~= nil) then
175 base_AIOI_ModifyItemTooltip(bag, slot, tooltipName);
176 elseif(base_EngInventory_ModifyItemTooltip ~= nil) then
177 base_EngInventory_ModifyItemTooltip(bag, slot, tooltipName, nil);
178 end
179 local tooltip = getglobal(tooltipName);
180 if (not tooltip) then
181 tooltip = getglobal("GameTooltip");
182 end
183  
184 if (not tooltip) then
185 return false;
186 end
187  
188 local link = GetContainerItemLink(bag, slot);
189 local name = QuestItem_nameFromLink(link);
190 if (name) then
191 local texture, itemCount, locked, quality, readable = GetContainerItemInfo(bag, slot);
192 if (quality == nil) then
193 quality = QuestItem_qualityFromLink(link);
194 end
195 QuestItem_AddTooltip(GameTooltip, name, link, itemCount, 0)
196 end
197 end
198 --------------------------------------
199 -- [[ Set tooltip for bank items ]] --
200 --------------------------------------
201 function QuestItem_GameTooltip_SetInventoryItem(userData, unit, slot)
202 local hasItem, hasCooldown, repairCost = base_GameTooltip_SetInventoryItem(userData, unit, slot);
203 local link = GetInventoryItemLink(unit, slot);
204 if (link) then
205 local name = QuestItem_nameFromLink(link);
206 local quantity = GetInventoryItemCount(unit, slot);
207 local quality = GetInventoryItemQuality(unit, slot);
208 if (quality == nil)
209 then quality = QuestItem_qualityFromLink(link);
210 end
211 QuestItem_AddTooltip(GameTooltip, name, link, quality, quantity)
212 end
213 return hasItem, hasCooldown, repairCost;
214 end
215  
216 --------------------------------------
217 -- [[ Set tooltip for loot items ]] --
218 --------------------------------------
219 function QuestItem_GameTooltip_SetLootItem(this, slot)
220 base_GameTooltip_SetLootItem(this, slot);
221 local link = GetLootSlotLink(slot);
222 local name = QuestItem_nameFromLink(link);
223 if (name) then
224 local texture, item, quantity, quality = GetLootSlotInfo(slot);
225  
226 if (quality == nil) then
227 quality = QuestItem_qualityFromLink(link);
228 end
229  
230 QuestItem_AddTooltip(GameTooltip, name, link, quantity, quantity)
231 end
232 end
233  
234 ------------------------------------------------------
235 -- [[ QuestItem_ContainerFrameItemButton_OnEnter ]] --
236 ------------------------------------------------------
237 function QuestItem_ContainerFrameItemButton_OnEnter()
238 base_ContainerFrameItemButton_OnEnter();
239 local frameID = this:GetParent():GetID();
240 local buttonID = this:GetID();
241 local link = GetContainerItemLink(frameID, buttonID);
242 local name = QuestItem_nameFromLink(link);
243  
244 if (name) then
245 local texture, itemCount, locked, quality, readable = GetContainerItemInfo(frameID, buttonID);
246 if (quality==nil or quality==-1) then
247 quality = QuestItem_qualityFromLink(link);
248 end
249  
250 QuestItem_AddTooltip(GameTooltip, name, link, quantity, itemCount)
251 end
252 end
253  
254 ------------------------------------
255 -- Hook for click on container items
256 ------------------------------------
257 ------------------------------------
258 function QuestItem_ContainerFrameItemButton_OnClick(button, ignoreModifiers)
259 local executeBase = true;
260 if(QuestItem_Settings["AltOpen"] == true) then
261 if(button == "RightButton" and not ignoreModifiers and IsAltKeyDown()) then
262 local bag, slot;
263 -- Look for bag and slot id
264 if(AllInOneInventoryFrameItemButton_OnClick ~= nil) then
265 bag, slot = AllInOneInventory_GetIdAsBagSlot(this:GetID());
266 else
267 bag = this:GetParent():GetID();
268 slot = this:GetID();
269 end
270  
271 local link = GetContainerItemLink(bag, slot);
272 QuestItem_OpenLink(link);
273 end
274 end
275 -- Execute base method
276 if(executeBase) then
277 base_ContainerFrameItemButton_OnClick(button, ignoreModifiers);
278 end
279 end
280  
281 function QuestItem_OpenLink(link)
282 local name = QuestItem_nameFromLink(link);
283 -- Open questlog for quest
284 if(name) then
285 if(QuestItems[name] and QuestItems[name].QuestName) then
286 QuestItem_OpenQuestLog(QuestItems[name].QuestName);
287 executeBase = false;
288 end
289 end
290 end
291  
292 function QuestItem_BankFrameItemButtonGeneric_OnClick(button)
293 local executeBase = true;
294 if(QuestItem_Settings["AltOpen"] == true) then
295 if(button == "RightButton" and not ignoreModifiers and IsAltKeyDown()) then
296 local link = GetContainerItemLink(BANK_CONTAINER, this:GetID());
297 QuestItem_OpenLink(link);
298 executeBase = false;
299 end
300 end
301 if(executeBase) then
302 base_BankFrameItemButtonGeneric_OnClick(button, ignoreModifiers);
303 end
304 end
305  
306 function QuestItem_BankFrameItemButtonBag_OnClick(button)
307 --QuestItem_Debug(this:GetID());
308 end
309  
310  
311  
312 ----------------------------------------
313 -- [[ Set tooltip for linked items ]] --
314 ----------------------------------------
315 function QuestItem_Chat_OnHyperlinkShow(reference, link, button)
316 base_Chat_OnHyperlinkShow(reference, link, button);
317 if(button == "LeftButton") then
318 if (ItemRefTooltip:IsVisible()) then
319 local name = ItemRefTooltipTextLeft1:GetText();
320 if (name) then
321 local fabricatedLink = "|cff000000|H"..link.."|h["..name.."]|h|r";
322  
323 QuestItem_AddTooltip(ItemRefTooltip, name, fabricatedLink, -1, 1, 0);
324 end
325 end
326 end
327 end
328  
329 function QuestItem_ContainerFrameItemButton_Update(frame)
330 base_ContainerFrame_Update(frame);
331 end
332  
333 ----------------------------------
334 -- [[ QuestItem_NameFromLink ]] --
335 ----------------------------------
336 function QuestItem_nameFromLink(link)
337 local name;
338 if( not link ) then
339 return nil;
340 end
341 for name in string.gfind(link, "|c%x+|Hitem:%d+:%d+:%d+:%d+|h%[(.-)%]|h|r") do
342 return name;
343 end
344 return nil;
345 end
346  
347 ---------------------------
348 -- [[ qualityFromLink ]] --
349 ---------------------------
350 function QuestItem_qualityFromLink(link)
351 local color;
352 if (not link) then return nil; end
353 for color in string.gfind(link, "|c(%x+)|Hitem:%d+:%d+:%d+:%d+|h%[.-%]|h|r") do
354 if (color == "ffa335ee") then return 4;--[[ Epic ]] end
355 if (color == "ff0070dd") then return 3;--[[ Rare ]] end
356 if (color == "ff1eff00") then return 2;--[[ Uncommon ]] end
357 if (color == "ffffffff") then return 1;--[[ Common ]] end
358 if (color == "ff9d9d9d") then return 0;--[[ Poor ]] end
359 end
360 return -1;
361 end