Quantcast
WoWInterface - View Single Post - Getting item details on hover
View Single Post
08-05-20, 08:47 PM   #12
Walkerbo
A Wyrmkin Dreamwalker
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 55
Hi Fizzlemizz

Thanks for your code, it is much more legible and easier to follow than mine.

However, it still has the same issue, I have to /reload after logging in to get the keybinds to work.

After much gnashing of teeth, a few print statements and a hell of a lot of experimentation I ended up solving the problem by creating the button itself in a function and then having another frame to run the new function on the player entering the world.

My full solution;
Lua Code:
  1. local myTestingKeybindingItemName, myTestingKeybindingItemLink, myTestingKeybindingItemID
  2.  
  3. local function addItemToTable(itemLink)
  4.     if not myTestingKeybindingTableOfItems then
  5.         myTestingKeybindingTableOfItems = {}
  6.     end
  7.     local found
  8.     for k, v in pairs(myTestingKeybindingTableOfItems) do
  9.         if v == itemLink then
  10.             print("Item all ready listed")
  11.             found = true
  12.             break
  13.         end
  14.     end
  15.     if not found then
  16.         table.insert(myTestingKeybindingTableOfItems, 1, itemLink)
  17.         print("Item added to list",itemLink)
  18.     end
  19. end
  20.  
  21. SLASH_MYTEST1 = "/qwe"
  22. function SlashCmdList.MYTEST(msg, editbox)
  23.     if #myTestingKeybindingTableOfItems == 0 then
  24.         print("empty table")
  25.     else
  26.         for k, v in pairs(myTestingKeybindingTableOfItems) do
  27.             print("item", k, v)
  28.         end
  29.     end
  30. end
  31.  
  32. local function keybindingButtonSetUp()
  33.     print("*** keybinding setup function fired ***")
  34.     local myTestingKeybindingButton = CreateFrame("BUTTON", "WalkerbomyTest")
  35.     SetBindingClick("F5", "WalkerbomyTest", "b1")
  36.     SetBindingClick("G", "WalkerbomyTest", "b3")
  37.     myTestingKeybindingButton:SetScript("OnClick", function(self, button)
  38.         if button == "b1" then
  39.             addItemToTable(myTestingKeybindingItemLink)
  40.             print("F5 button clicked", myTestingKeybindingItemLink, myTestingKeybindingItemID)
  41.         elseif button == "b3" then
  42.             print("G button clicked")
  43.         end
  44.     end)
  45. end
  46.  
  47. GameTooltip:HookScript("OnTooltipSetItem", function(self)
  48.     myTestingKeybindingItemName, myTestingKeybindingItemLink = self:GetItem()
  49.     myTestingKeybindingItemID = tonumber(strmatch(myTestingKeybindingItemLink, "item:(%d+):"))
  50.     print("item under mouse",myTestingKeybindingItemLink)
  51. end)
  52.  
  53. local myTestingKeybindingFrame = CreateFrame("FRAME", "WalkerboFrame")
  54. myTestingKeybindingFrame:SetScript('OnEvent', function(self, event, ...)
  55.     if event == 'PLAYER_LOGIN' then
  56.         print("*** Addon Loaded ***")
  57.         keybindingButtonSetUp()
  58.     end
  59. end)
  60. myTestingKeybindingFrame:RegisterEvent('PLAYER_LOGIN')

There is probaly a more efficent way of achieveing the same result but for now I am happy just to have it working.

The next thing on my list is to have the keybindings show in the bindings menu so users can swap the bindings to a key of their choice.
If I fail at that I will probably be back.

Thank you all for the help
  Reply With Quote