Quantcast
WoWInterface - View Single Post - Getting item details on hover
View Single Post
08-20-20, 07:22 PM   #17
Walkerbo
A Wyrmkin Dreamwalker
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 56
Hi all

As promised I am posting my working code here for other novices like myself.

Toc
Lua Code:
  1. ## Title: AAA |cffff0000 Testing Ground
  2. ## Interface: 80300
  3. ## Notes: |cffff0000 Testing Ground
  4. ## Version: AAA
  5. ## Date: Friday 21 August 2020
  6. ## SavedVariables: TableOfItems
Lua
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. local function keybindingButtonSetUp()
  22.     print('*** keybinding setup function fired ***')
  23.     local myTestingKeybindingButton = CreateFrame('BUTTON', 'WalkerbomyTest')
  24.     SetBindingClick('CTRL-\[', 'WalkerbomyTest', 'b1')
  25.     SetBindingClick('CTRL-\]', 'WalkerbomyTest', 'b2')
  26.     SetBindingClick('CTRL-\\', 'WalkerbomyTest', 'b3')
  27.     SetBindingClick('SHIFT-\[', 'WalkerbomyTest', 'b4')
  28.     SetBindingClick('SHIFT-\]', 'WalkerbomyTest', 'b5')
  29.     SetBindingClick('SHIFT-\\', 'WalkerbomyTest', 'b6')
  30.     myTestingKeybindingButton:SetScript(
  31.         'OnClick',
  32.         function(self, button)
  33.             if button == 'b1' then
  34.                 print('CTRL-\[ button clicked', myTestingKeybindingItemLink)
  35.                 addItemToTable(myTestingKeybindingItemLink)
  36.             elseif button == 'b2' then
  37.                 print('CTRL-\] button clicked', myTestingKeybindingItemLink)
  38.             elseif button == 'b3' then
  39.                 print('CTRL-\\ button clicked', myTestingKeybindingItemLink)
  40.             elseif button == 'b4' then
  41.                 print('SHIFT-\] button clicked', myTestingKeybindingItemLink)
  42.             elseif button == 'b5' then
  43.                 print('SHIFT-\\ button clicked', myTestingKeybindingItemLink)
  44.             elseif button == 'b6' then
  45.                 print('SHIFT-\] button clicked', myTestingKeybindingItemLink)
  46.             end
  47.         end
  48.     )
  49. end
  50.  
  51. SLASH_MYTEST1 = '/qwe'
  52. function SlashCmdList.MYTEST(msg, editbox)
  53.     if #myTestingKeybindingTableOfItems == 0 then
  54.         print('empty table')
  55.     else
  56.         for k, v in pairs(myTestingKeybindingTableOfItems) do
  57.             print('item', k, v)
  58.         end
  59.     end
  60. end
  61.  
  62. SLASH_MYTESTC1 = '/asd'
  63. function SlashCmdList.MYTESTC(msg, editbox)
  64.     myTestingKeybindingTableOfItems = {}
  65.     print('List cleared')
  66. end
  67.  
  68. GameTooltip:HookScript(
  69.     'OnTooltipSetItem',
  70.     function(self)
  71.         myTestingKeybindingItemName, myTestingKeybindingItemLink = self:GetItem()
  72.         myTestingKeybindingItemID = tonumber(strmatch(myTestingKeybindingItemLink, 'item:(%d+):'))
  73.     end
  74. )
  75.  
  76. local myTestingKeybindingFrame = CreateFrame('FRAME', 'WalkerboFrame')
  77. myTestingKeybindingFrame:SetScript(
  78.     'OnEvent',
  79.     function(self, event, ...)
  80.         if event == 'PLAYER_LOGIN' then
  81.             print('*** Addon Loaded ***')
  82.             keybindingButtonSetUp()
  83.         end
  84.     end
  85. )
  86. myTestingKeybindingFrame:RegisterEvent('PLAYER_LOGIN')

I will now start working out how to add these keybindings to the in-game keybinding UI.

Thanks to you all for your help, it is most appreciated.
  Reply With Quote