Thread Tools Display Modes
06-19-15, 12:13 AM   #1
Voxxel
A Chromatic Dragonspawn
Join Date: Mar 2009
Posts: 193
Question LF addon/script to simplify item usage

Hey there,

I wonder if there's any (probably chat) addon available that can alter the item link usage to set a mod key to actually USE the item?

For example, the chat entry is "You receive loot: [Stout Augment Rune]."

Normally, if you click on the link it brings up the tooltip of the item. I want to set up a key like "right-click" or holding down alt/shift/etc while clicking that actually /use the item you clicked on instead of showing its tooltip.

Is that possible with a script or do you know any addon that can do this? It seems pretty basic but I didn't find any addon/modules so far.
  Reply With Quote
06-19-15, 03:26 AM   #2
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
Pretty sure hyperlink clicks do not count as hardware events, could be wrong, but if not, actually using items would be tricky and probably require a secondary action.
  Reply With Quote
06-19-15, 11:39 AM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Clicking your mouse button is a hardware event. However, chat hyperlinks are not secure code like an action button, bag slot, etc. is. This is not feasible to implement.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-19-15, 01:16 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
There's probably a way to create SecureActionButtons that overlay the dynamic buttons that make up the hyperlinks, but I'm not sure if it's possible to tell what buttons are for what hyperlinks. It also wouldn't be very stable considering you can't set/change attributes of protected frames while in combat.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
06-20-15, 12:14 PM   #5
Voxxel
A Chromatic Dragonspawn
Join Date: Mar 2009
Posts: 193
I see the problems, thanks for your time anyway!
  Reply With Quote
06-20-15, 12:22 PM   #6
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
It's doable, I started writing an example and ended up with rather more than I intended.

This isn't polished and I can't guarantee it won't have issues, but in the interest of time I'll post it here so you can paste it into http://addon.bool.no and have it generate an addon for you.

Lua Code:
  1. local Button = CreateFrame('Button', nil, nil, 'SecureActionButtonTemplate,SecureHandlerStateTemplate')
  2. Button:Hide()
  3. Button:RegisterForClicks('AnyDown')
  4. Button:SetFrameStrata('TOOLTIP')
  5.  
  6. Button:SetNormalTexture('interface/icons/inv_mushroom_11')
  7. local Icon = Button:GetNormalTexture()
  8. Icon:ClearAllPoints()
  9. Icon:SetPoint('CENTER')
  10. Icon:SetSize(24, 24)
  11.  
  12. Button:SetAttribute('type2', 'item')
  13. Button:RegisterForDrag('LeftButton')
  14. Button:SetScript('OnDragStart', function(self)
  15.     self.MouseDown = false
  16.     self:Hide()
  17.     PickupItem(self.link)
  18. end)
  19.  
  20. Button:HookScript('OnMouseDown', function(self)
  21.     self.MouseDown = true
  22.     GameTooltip:Hide()
  23. end)
  24.  
  25. Button:HookScript('OnMouseUp', function(self, Button)
  26.     self.MouseDown = false
  27.     if not MouseIsOver(self) then
  28.         self:Hide()
  29.     elseif Button ~= 'RightButton' then
  30.         DEFAULT_CHAT_FRAME:GetScript('OnHyperlinkClick')(DEFAULT_CHAT_FRAME, self.link, self.text, Button)
  31.     end
  32. end)
  33.  
  34. RegisterStateDriver(Button, 'combat', '[combat]combat;')
  35. Button:SetAttribute('_onstate-combat', 'if newstate == "combat" then self:Hide() end')
  36.  
  37. Button:SetScript('OnLeave', function(self) if not InCombatLockdown() and not self.MouseDown then self:Hide() end GameTooltip:Hide() end)
  38.  
  39. DEFAULT_CHAT_FRAME:HookScript('OnHyperlinkEnter', function(self, link, text)
  40.     local HyperlinkButton = GetMouseFocus()
  41.     Button.link, Button.text, Button.button = link, text, HyperlinkButton
  42.     local linkType = strsplit(':', link, 2)
  43.    
  44.     if linkType == 'item' then
  45.         GameTooltip:SetOwner(HyperlinkButton, 'ANCHOR_RIGHT')
  46.         GameTooltip:SetHyperlink(link)
  47.         GameTooltip:Show()
  48.     end
  49.    
  50.     if InCombatLockdown() or not link or not HyperlinkButton then return end
  51.    
  52.     if linkType == 'item' then
  53.         Icon:SetTexture(GetItemIcon(link) or 'interface/Icons/inv_mushroom_11')
  54.         local left, bottom, width, height = HyperlinkButton:GetRect()
  55.         local scale = HyperlinkButton:GetEffectiveScale()
  56.         Button:ClearAllPoints()
  57.         Button:SetPoint('BOTTOMLEFT', nil, left * scale, bottom * scale)
  58.         Button:SetSize(width * scale, height * scale)
  59.         Button:SetAttribute('item2', link)
  60.         Button:Show()
  61.     end
  62. end)
  63.  
  64. DEFAULT_CHAT_FRAME:HookScript('OnHyperlinkLeave', function(self, link, text)
  65.     if not Button:IsShown() then
  66.         GameTooltip:Hide()
  67.     end
  68. end)
  69.  
  70. DEFAULT_CHAT_FRAME:HookScript('OnMessageScrollChanged', function(self)
  71.     if not Button:IsShown() then return end
  72.     if not Button.button or (not (MouseIsOver(Button.button) and MouseIsOver(Button)) and not Button.MouseDown) then
  73.         Button:Hide()
  74.     end
  75. end)
  Reply With Quote
06-22-15, 01:55 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by semlar View Post
Code:
local left, bottom, width, height = HyperlinkButton:GetRect()
local scale = HyperlinkButton:GetEffectiveScale()
Button:ClearAllPoints()
Button:SetPoint('BOTTOMLEFT', nil, left * scale, bottom * scale)
Button:SetSize(width * scale, height * scale)
You should be able to simplify this with Region:SetAllPoints().
Code:
Button:ClearAllPoints();
Button:SetAllPoints(HyperlinkButton);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
06-22-15, 04:28 PM   #8
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by SDPhantom View Post
You should be able to simplify this with Region:SetAllPoints().
Code:
Button:ClearAllPoints();
Button:SetAllPoints(HyperlinkButton);
You can't anchor a secure frame to an unsecure frame like that.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » LF addon/script to simplify item usage


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