WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Shift middle click an item for GetItemInfo (https://www.wowinterface.com/forums/showthread.php?t=48964)

Spawnova 02-20-14 12:36 PM

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.

Duugu 02-20-14 01:28 PM

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

Spawnova 02-20-14 01:46 PM

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.

semlar 02-20-14 01:49 PM

I believe you need to call button:RegisterForClicks('MiddleButtonDown') if it's not already watching for that type of click.

Duugu 02-20-14 01:52 PM

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.

Spawnova 02-20-14 01:56 PM

Ah, you guys are correct!

Everything is working now, thank you so much for your help. :D

Phanx 02-20-14 02:30 PM

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. :p

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.

Spawnova 02-20-14 04:28 PM

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. :)


All times are GMT -6. The time now is 10:37 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI