Quantcast
Shift middle click an item for GetItemInfo - WoWInterface
Thread Tools Display Modes
02-20-14, 12:36 PM   #1
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
Shift middle click an item for GetItemInfo

I would like to be able to Shift Middle click an item in my bags and have it call GetItemInfo on that item, but I'm not sure where to start.

I've done some google-ing and can't find anything myself so any help would be great.
  Reply With Quote
02-20-14, 01:28 PM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
You could hook the OnClick event of the frames.


Lua Code:
  1. for container = 1, 5 do
  2.     for item = 1, 36 do
  3.         _G["ContainerFrame"..container.."Item"..item]:HookScript("OnClick", function(self, button)
  4.             if IsShiftKeyDown() and button == "MiddleButton" then
  5.                 print(GetItemInfo(GetContainerItemID(self:GetParent():GetID(), self:GetID())))
  6.             end
  7.         end)
  8.     end
  9. end

Another way doing it would be to hook Blizzards ContainerFrameItemButton_OnModifiedClick(self, button).

Like

Lua Code:
  1. hooksecurefunc("ContainerFrameItemButton_OnModifiedClick", function(self, button)
  2.             if IsShiftKeyDown() and button == "MiddleButton" and self:GetParent():GetID() <= 5 then
  3.                 print(GetItemInfo(GetContainerItemID(self:GetParent():GetID(), self:GetID())))
  4.             end
  5.         end)

I bet Phanx likes this one more because it's using only one hook and not 5x36. ;D

Last edited by Duugu : 02-20-14 at 01:47 PM.
  Reply With Quote
02-20-14, 01:46 PM   #3
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
That's exactly what I was looking for! Thanks a bunch ^.^

I do get one error though, it seems only left and right button are passed, for example in the script below...

Lua Code:
  1. for container = 1, 5 do
  2.         for item = 1, 36 do
  3.             _G["ContainerFrame"..container.."Item"..item]:HookScript("OnClick", function(self, button)
  4.                 print(button)
  5.                 if IsShiftKeyDown() and button == "MiddleButton" then
  6.                     print(GetItemInfo(GetContainerItemID(self:GetParent():GetID(), self:GetID())))
  7.                 end
  8.             end)
  9.         end
  10.     end

Only left and right clicks will print anything, this is not a huge deal as I can easily switch the keybinds though, just curious why that is.
  Reply With Quote
02-20-14, 01:49 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
I believe you need to call button:RegisterForClicks('MiddleButtonDown') if it's not already watching for that type of click.
  Reply With Quote
02-20-14, 01:52 PM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I'm not sure. Maybe the middle button is not registered.

I don't have a 3 button mouse available atm and can't test it.
Try to register for MiddleButtonDown:

Lua Code:
  1. for container = 1, 5 do
  2.         for item = 1, 36 do
  3.             _G["ContainerFrame"..container.."Item"..item]:RegisterForClicks("MiddleButtonDown")
  4.             _G["ContainerFrame"..container.."Item"..item]:HookScript("OnClick", function(self, button)
  5.                 print(button)
  6.                 if IsShiftKeyDown() and button == "MiddleButton" then
  7.                     print(GetItemInfo(GetContainerItemID(self:GetParent():GetID(), self:GetID())))
  8.                 end
  9.             end)
  10.         end
  11.     end

See http://www.wowwiki.com/API_Button_RegisterForClicks for reference.
  Reply With Quote
02-20-14, 01:56 PM   #6
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
Ah, you guys are correct!

Everything is working now, thank you so much for your help.
  Reply With Quote
02-20-14, 02:30 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Edit: I guess I should refresh the page before typing my reply when it's been sitting on the reply page for 2 hours because I got distracted by work, but oh well. Leaving this here anyway.

On its own, "calling GetItemInfo" won't actually do anything:

Code:
/run GetItemInfo(6948)
You need additional code to catch the return values and do something with those. Let's say, for the sake of example, that you want to print those values to the chat frame, in which case something like this would probably work:

Lua Code:
  1. hooksecurefunc("ContainerFrameItemButton_OnModifiedClick", function(self, button)
  2.     if button ~= "MiddleButton" or not IsShiftKeyDown() then
  3.         return
  4.     end
  5.     local name, link, rarity, level, minLevel, type, subType, stackCount, equipLoc, texture, sellPrice = GetItemInfo(GetContainerItemID(self:GetParent():GetId(), self:GetID())
  6.     print(format("|T%s:0|t %s", texture, link))
  7.     print("   Quality:", _G["ITEM_QUALITY"..rarity.."_DESC"])
  8.     print("   Item Type:", type)
  9.     print("   Item Subtype:", subType)
  10.     if strlen(equipLoc) > 0 then
  11.         print("   Equip Location:",  equipLoc)
  12.     end
  13.     if level > 1 then
  14.         print("   Item Level:", level)
  15.     end
  16.     if minLevel > 0 then
  17.         print("   Requires Level:", minLevel)
  18.     end
  19.     if sellPrice >= 10000 then
  20.         return format("|cffffd700%d|r%s |cffc7c7cf%d|r%s %d%s", abs(sellPrice / 10000), GOLD_AMOUNT_SYMBOL, abs(mod(sellPrice / 100, 100)), SILVER_AMOUNT_SYMBOL, abs(mod(sellPrice, 100)), COPPER_AMOUNT_SYMBOL)
  21.     elseif sellPrice >= 100 then
  22.         return format("|cffc7c7cf%d|r%s %d%s", abs(mod(sellPrice / 100, 100)), SILVER_AMOUNT_SYMBOL, abs(mod(sellPrice, 100)), COPPER_AMOUNT_SYMBOL)
  23.     else
  24.         return format("%d%s", abs(mod(sellPrice, 100)), COPPER_AMOUNT_SYMBOL)
  25.     end
  26. end)

You probably also need to tell the buttons to respond to middle-clicks, instead of just left- and right-clicks:

Lua Code:
  1. for i = 1, 13 do
  2.     for j = 1, 36 do
  3.         _G["ContainerFrame"..i.."Item"..j]::RegisterForClicks("AnyUp")
  4.     end
  5. end

If you're using a third-party bag addon that doesn't reuse the Blizzard item buttons, you'll need to modify its buttons and hook its click-handling function instead.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
02-20-14, 04:28 PM   #8
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
I had a problem that I wasn't aware of until just recently that I could not sell items normally which I resolved by reading the code you have submitted and registering clicks for AnyUp, the sell part was also very useful, I will definitely be using that. =D


Again, I appreciate the help, thank you.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Shift middle click an item for GetItemInfo

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off