Mercurial > wow > reagentmaker
comparison SecureMenu.lua @ 40:5a6091dddf69
Disable actions on buttons with not enough reagents (external frame), and warn the user
author | contrebasse |
---|---|
date | Fri, 29 Apr 2011 23:58:43 +0200 |
parents | 71e8b39f056e |
children | 4e6492b19f4c |
comparison
equal
deleted
inserted
replaced
39:71e8b39f056e | 40:5a6091dddf69 |
---|---|
187 | 187 |
188 local function menuCraftItem() | 188 local function menuCraftItem() |
189 action(itemID,reagentIndex,IsShiftKeyDown()) | 189 action(itemID,reagentIndex,IsShiftKeyDown()) |
190 end | 190 end |
191 | 191 |
192 local function WarnNotMakable(btn) | |
193 A.Error("You do not have enough ["..btn.itemNameString.."] to craft ["..TitleText:GetText().."]") | |
194 end | |
195 | |
196 -- Update counts and button actions | |
192 function MenuFrame.updateCounts() | 197 function MenuFrame.updateCounts() |
193 local anyMakable | 198 local anyMakable |
194 for i=1,numActiveEntries do | 199 for i=1,numActiveEntries do |
195 btn = menuEntries[i] | 200 btn = menuEntries[i] |
196 local itemCount = GetItemCount(btn.reagentID) | 201 local itemCount = GetItemCount(btn.reagentID) |
197 | 202 |
198 local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) | 203 local numMakable = math.floor(itemCount/(btn.reagentsForOneRecipe or 1)) |
199 btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) | 204 btn.countDetail:SetText(itemCount.."/"..(btn.reagentsForOneRecipe or 1)) |
200 | 205 |
201 if numMakable>0 then | 206 if numMakable>0 then |
207 -- Set action | |
208 if type(action)=="function" then | |
209 btn:SetScript("PreClick",btn.action) | |
210 btn:SetAttribute("type", nil) | |
211 btn:SetAttribute("macrotext", nil) | |
212 else --if type(action)=="string" then | |
213 btn:SetScript("PreClick",nil) | |
214 btn:SetAttribute("type", "macro") | |
215 btn:SetAttribute("macrotext", btn.action..btn.itemNameString) | |
216 end -- if | |
217 | |
202 anyMakable = true | 218 anyMakable = true |
203 btn.countDetail:SetTextColor(1, 1, 1, 1) | 219 btn.countDetail:SetTextColor(1, 1, 1, 1) |
204 btn.icon:SetVertexColor(1,1,1); | 220 btn.icon:SetVertexColor(1,1,1); |
205 btn.itemName:SetTextColor(1,1,1,1) | 221 btn.itemName:SetTextColor(1,1,1,1) |
206 else | 222 else |
207 -- Do not disable the button, to be able to show the tooltip | 223 -- Do not disable the button, to be able to show the tooltip |
224 -- Disable only the effects | |
225 btn:SetScript("PreClick",WarnNotMakable) | |
226 btn:SetAttribute("type", nil) | |
227 btn:SetAttribute("macrotext", nil) | |
228 | |
208 btn.countDetail:SetTextColor(1, 0.1, 0.1, 1) | 229 btn.countDetail:SetTextColor(1, 0.1, 0.1, 1) |
209 btn.icon:SetVertexColor(0.5, 0.5, 0.5) | 230 btn.icon:SetVertexColor(0.5, 0.5, 0.5) |
210 btn.itemName:SetTextColor(1,1,1,0.5) | 231 btn.itemName:SetTextColor(1,1,1,0.5) |
211 end | 232 end |
212 | 233 |
263 btn.itemID = itemID | 284 btn.itemID = itemID |
264 btn.reagentID = reagent[1] | 285 btn.reagentID = reagent[1] |
265 btn.reagentLink = link | 286 btn.reagentLink = link |
266 btn.reagentsForOneRecipe = reagent[2] | 287 btn.reagentsForOneRecipe = reagent[2] |
267 btn.spellLink = spellLink | 288 btn.spellLink = spellLink |
268 | 289 btn.action = action |
269 -- Set action | 290 btn.itemNameString = name |
270 if type(action)=="function" then | |
271 btn:SetScript("PreClick",action) | |
272 btn:SetAttribute("type", nil) | |
273 btn:SetAttribute("macrotext", nil) | |
274 else --if type(action)=="string" then | |
275 btn:SetScript("PreClick",nil) | |
276 btn:SetAttribute("type", "macro") | |
277 btn:SetAttribute("macrotext", action..name) | |
278 end -- if | |
279 | 291 |
280 btn:Show() | 292 btn:Show() |
281 | 293 |
282 -- Increase the entry number | 294 -- Increase the entry number |
283 numActiveEntries = numActiveEntries + 1 | 295 numActiveEntries = numActiveEntries + 1 |
338 MenuFrame:SetHeight(89 + numActiveEntries*(MENU_ENTRY_HEIGHT+2)) | 350 MenuFrame:SetHeight(89 + numActiveEntries*(MENU_ENTRY_HEIGHT+2)) |
339 | 351 |
340 MenuFrame:ClearAllPoints() | 352 MenuFrame:ClearAllPoints() |
341 MenuFrame:SetPoint("TOPLEFT",TradeSkillFrame,"TOPRIGHT",-2,14) | 353 MenuFrame:SetPoint("TOPLEFT",TradeSkillFrame,"TOPRIGHT",-2,14) |
342 | 354 |
355 -- Update counts and set actions | |
343 MenuFrame.updateCounts() | 356 MenuFrame.updateCounts() |
344 | 357 |
345 MenuFrame:Show() | 358 MenuFrame:Show() |
346 | 359 |
347 if not MenuFrame.state then | 360 if not MenuFrame.state then |