vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Globals used for the TRADE_TARGET_ITEM_CHANGED workaround
2 EU_GetItemInfoReq = false;
3 EU_UpdateCount = 0;
4 EU_UpdateCountLimit = 15; -- Max number of OnUpdate cycles to check for an item
5  
6 -- Compatibility with Link Wrangler 1.39
7 function EasyUnlock_LinkWranglerCallback(frame, link)
8 local itemName = GetItemInfo(link);
9 EasyUnlock_AddTooltipInfo(frame, itemName);
10 end
11  
12 function EasyUnlock_OnLoad()
13 -- Register events
14 this:RegisterEvent("VARIABLES_LOADED");
15 this:RegisterEvent("TRADE_TARGET_ITEM_CHANGED");
16 this:RegisterEvent("LEARNED_SPELL_IN_TAB");
17 this:RegisterEvent("TRADE_SHOW");
18 this:RegisterEvent("UI_ERROR_MESSAGE");
19 end
20  
21 function EasyUnlock_OnUpdate(dt)
22 -- Button-does-not-always-enable-hack
23 if(EU_GetItemInfoReq) then
24 -- Check if the slot contains an item known to be a lockbox
25 local itemname, _, _, _, _, enchantment = GetTradeTargetItemInfo(7);
26 if(itemname) then
27 EU_GetItemInfoReq = false;
28 EU_UpdateCount = 0;
29 else
30 EU_UpdateCount = EU_UpdateCount + 1;
31 end
32  
33 if(EU_LOCKBOXES[itemname] and not enchantment) then
34 EasyUnlockUnlockButton:Enable();
35 else
36 EasyUnlockUnlockButton:Disable();
37 end
38  
39 -- Check if we haven't exceeded the checklimit
40 if(EU_UpdateCount > EU_UpdateCountLimit) then
41 EU_GetItemInfoReq = false;
42 EU_UpdateCount = 0;
43 end
44 end
45 end
46  
47 function EasyUnlock_Print(msg)
48 DEFAULT_CHAT_FRAME:AddMessage(msg, 1, 1, 0);
49 end
50  
51 function EasyUnlock_DoFrameCheck()
52 local _, class = UnitClass("player");
53 if(class == "ROGUE" and EasyUnlock_GetLockpickingLevel() and not EasyUnlock:IsShown()) then
54 -- Unhide frame
55 EasyUnlock:Show();
56  
57 -- Squeeze the 'trade' and 'cancel' buttons in TradeFrame so we can fit in our own button
58 TradeFrameTradeButton:SetWidth(56);
59 TradeFrameCancelButton:SetWidth(56);
60  
61 -- Fix the 'trade' button position
62 TradeFrameTradeButton:SetPoint("BOTTOMRIGHT","TradeFrame","BOTTOMRIGHT",-141,55);
63  
64 -- Change the anchor of the cancel button so it's positioned relative to our 'unlock' button
65 TradeFrameCancelButton:SetPoint("TOPLEFT","EasyUnlockUnlockButton","TOPRIGHT",-3,0);
66 end
67 end
68  
69 function EasyUnlock_OnEvent(event)
70 if(event == "VARIABLES_LOADED") then
71 if(IsAddOnLoaded("LinkWrangler")) then
72 if(LINK_WRANGLER_CALLER == nil) then
73 EasyUnlock_Print(EA_COMPAT_LW_UNSUPPORTED);
74 else
75 LINK_WRANGLER_CALLER['EasyUnlock'] = "EasyUnlock_LinkWranglerCallback";
76 end
77 end
78 elseif(event == "TRADE_TARGET_ITEM_CHANGED" and arg1 == 7) then
79 local itemname, _, _, _, _, enchantment = GetTradeTargetItemInfo(arg1);
80 EU_GetItemInfoReq = true; -- Sometimes GetTradeTargetItemInfo returns nil although an update event has been triggered -> Try to get iteminfo for X OnUpdate iterations
81 elseif(event == "LEARNED_SPELL_IN_TAB" and arg1 == 1) then
82 EasyUnlock_DoFrameCheck();
83 elseif(event == "TRADE_SHOW") then -- Seems to bug if frames are modified OnLoad
84 EasyUnlock_DoFrameCheck();
85 EasyUnlockUnlockButton:Disable();
86 elseif(event == "UI_ERROR_MESSAGE" and arg1 == SPELL_FAILED_NOT_MOUNTED and TradeFrame:IsShown()) then
87 -- Assume player clicked the unlock button
88 EasyUnlockUnlockButton:Enable();
89 EU_GetItemInfoReq = false;
90 end
91 end
92  
93 function EasyUnlockUnlockButton_OnClick()
94 -- Disable the button
95 EasyUnlockUnlockButton:Disable();
96  
97 -- Get the itemname
98 local itemname = GetTradeTargetItemInfo(7);
99  
100 if(not itemname) then return end
101  
102 -- Get our lockpicking level
103 local lockpickinglevel = EasyUnlock_GetLockpickingLevel();
104  
105 -- Can we open this box?
106 if(lockpickinglevel >= EU_LOCKBOXES[itemname]) then
107 -- We can open the box, so let's do that
108 CastSpellByName(EU_PICKLOCK_ABILITY);
109 ClickTargetTradeButton(7);
110 else
111 -- Can't open this box, send the receipent a whisper
112 local boxlink = GetTradeTargetItemLink(7);
113 local boxlevel = EU_LOCKBOXES[itemname];
114 local msg = format(EU_TOO_LOW_LOCKPICKING,boxlink,lockpickinglevel,boxlevel);
115 SendChatMessage(msg,"WHISPER",nil,UnitName("NPC"));
116 end
117 end
118  
119 function EasyUnlock_GetLockpickingLevel()
120 local numskills = GetNumSkillLines();
121 for i=1,numskills do
122 local skillname, _, _, skillrank = GetSkillLineInfo(i);
123 if(skillname == EU_SKILLTAB_LOCKPICKING) then
124 return skillrank;
125 end
126 end
127 -- Return 0 if no lockpicking level has been found
128 return 0;
129 end
130  
131 -- Checks whether a box is locked
132 function EasyUnlock_IsBoxLocked()
133 for i = 1, GameTooltip:NumLines() do
134 local tooltipline = getglobal("GameTooltipTextLeft"..i);
135 if(tooltipline and tooltipline:GetText() == EU_TOOLTIP_LOCKED) then return true; end
136 end
137 return false;
138 end
139  
140 -- This function will point to the original OnClick
141 local EasyUnlock_OldItemButton_OnClick = ContainerFrameItemButton_OnClick;
142  
143 function EasyUnlock_ItemButton_OnClick(button, ignoreShift)
144 local callold = true;
145 local itemLink = GetContainerItemLink(this:GetParent():GetID(), this:GetID());
146 if(button == "RightButton" and not (IsControlKeyDown() or IsShiftKeyDown() or IsAltKeyDown()) and itemLink) then
147 _, _, itemLink = string.find(itemLink, "(item:%d+:%d+:%d+:%d+)");
148 local itemName = GetItemInfo(itemLink);
149 if(EU_LOCKBOXES[itemName]) then
150 if(EasyUnlock_GetLockpickingLevel() >= EU_LOCKBOXES[itemName] and EasyUnlock_IsBoxLocked()) then
151 CastSpellByName(EU_PICKLOCK_ABILITY);
152 PickupContainerItem(this:GetParent():GetID(), this:GetID());
153 callold = false;
154 end
155 end
156 end
157 if(callold) then EasyUnlock_OldItemButton_OnClick(button, ignoreShift); end
158 end
159  
160 -- And this one hooks us
161 ContainerFrameItemButton_OnClick = EasyUnlock_ItemButton_OnClick;
162  
163 --
164 -- Tooltip stuff
165 --
166 function EasyUnlock_AddTooltipInfo(frame, itemname)
167 if(EU_LOCKBOXES[itemname]) then
168 local levelreq;
169 if(EU_LOCKBOXES[itemname] == 0) then
170 levelreq = "?";
171 else
172 levelreq = EU_LOCKBOXES[itemname];
173 end
174 local lockpickinglvl = EasyUnlock_GetLockpickingLevel();
175 if(levelreq == "?") then
176 -- Requirement unknown
177 local reqmsg = format(ITEM_REQ_SKILL, EU_SKILLTAB_LOCKPICKING.." ("..levelreq..")");
178 frame:AddLine(reqmsg,1,0.5,0);
179 elseif(levelreq <= lockpickinglvl) then
180 -- Lockpicking level is high enough
181 local reqmsg = format(ITEM_REQ_SKILL, EU_SKILLTAB_LOCKPICKING.." ("..levelreq..")");
182 frame:AddLine(reqmsg,0,1,0);
183 else
184 -- Lockpicking level is NOT high enough
185 local reqmsg = format(ITEM_REQ_SKILL, EU_SKILLTAB_LOCKPICKING.." ("..levelreq..")");
186 frame:AddLine(reqmsg,1,0,0);
187 end
188 -- Resize
189 frame:SetHeight(frame:GetHeight() + 14);
190 frame:SetWidth(190);
191 end
192 end
193  
194 function EasyUnlock_Tooltip_OnShow()
195 local parentFrame = this:GetParent();
196 local parentFrameName = parentFrame:GetName();
197 local itemName = getglobal(parentFrameName.."TextLeft1"):GetText()
198 EasyUnlock_AddTooltipInfo(parentFrame, itemName);
199 end