View Single Post
02-22-24, 09:45 AM   #18
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,897
You still don't say what you want to see when a link is clicked so, using the code you linked and guessing you just want to see the item tooltip when a link is clicked:

The item field added to each entry in addon.db is the (random because I don't know that acual) item ID that will be the link/tooltip (replacing the %s in each announce.enUS field).

db.lua file
Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.         name = "Emerald Mark of Mastery",
  5.         questID = 75612,
  6.         icon = "interface/icons/inv_mushroom_11",
  7.         item = 210399,
  8.         announce = {
  9.             enUS = "Awarded for outstanding service to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring \nOverlook in the Emerald Dream to receive powerful \nequipment for your efforts"
  10.         }
  11.     },
  12.     {
  13.         name = "Emerald Mark of Mastery",
  14.         questID = 75624,
  15.         icon = "interface/icons/inv_mushroom_11",
  16.         item = 20897,
  17.         announce = {
  18.             enUS = "Awarded for outstanding service to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring \nOverlook in the Emerald Dream to receive powerful \nequipment for your efforts"
  19.         }
  20.     },
  21.     {
  22.         name = "Emerald Mark of Mastery",
  23.         questID = 74352,
  24.         icon = "interface/icons/inv_mushroom_11",
  25.         item = 193440,
  26.         announce = {
  27.             enUS = "Awarded for outstanding service to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring \nOverlook in the Emerald Dream to receive powerful \nequipment for your efforts"
  28.         }
  29.     }
  30. }
  31. ---------------------------------------------------------------------------------------------------
  32. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  33. local function LoadItem(item)
  34.     for k, v in pairs(addon.db[item.dbID].announce) do -- replace the %s with the itemlink in eal locale in the .announce key
  35.         addon.db[item.dbID].announce[k] = format(v, item:GetItemLink())
  36.     end
  37. end
  38. for i, v in ipairs(addon.db) do
  39.     local item = Item:CreateFromItemID(v.item)
  40.     item.dbID = i
  41.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  42. end

Lua Code file:
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. -- function to show the item tooltip when a hyperlink is clicked
  4. local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- Show the hyperling tooltip when clicked
  5.     SetItemRef(link, text, nil, self);
  6. end
  7.  
  8. local CELL_WIDTH = 400
  9. local CELL_HEIGHT = 80
  10. local NUM_CELLS = 2
  11.  
  12. local data = {}
  13.  
  14. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  15.  
  16. -- Create the button here
  17. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  18.  
  19. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  20.     wipe(data)
  21.     for _, item in ipairs(addon.db) do
  22.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  23.     end
  24. end
  25.  
  26. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  27. f:SetPoint("CENTER")
  28. f:Hide()
  29. f:SetMovable(true)
  30. f:SetScript("OnMouseDown", f.StartMoving)
  31. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  32.  
  33. -- I added this OnHide script
  34. f:SetScript("OnHide", function()
  35.     btn:Show()
  36. end)
  37.  
  38. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  39. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  40. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  41.  
  42. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  43. f.scrollFrame.scrollChild:SetSize(100, 100)
  44. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  45. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  46.  
  47. local content = f.scrollFrame.scrollChild
  48. content.rows = {}
  49.  
  50. local function updateList()
  51.     for i = 1, #data do
  52.         if not content.rows[i] then
  53.             local button = CreateFrame("Button", nil, content)
  54.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  55.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  56.             button.columns = {}
  57.  
  58. ---------------------------------------------------------------------------------------------------
  59. -- code to make item links work
  60.             button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row
  61.             button:SetScript("OnHyperlinkClick", OnHyperlinkClick) -- What to do when a link is clicked
  62. ---------------------------------------------------------------------------------------------------
  63.  
  64.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  65.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  66.  
  67.             button.columns[2] = button:CreateTexture()
  68.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  69.  
  70.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  71.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  72.  
  73.             content.rows[i] = button
  74.         end
  75.  
  76.         content.rows[i].columns[1]:SetText(data[i][1])
  77.         content.rows[i].columns[2]:SetTexture(data[i][2])
  78.         content.rows[i].columns[3]:SetText(data[i][3])
  79.  
  80.         content.rows[i]:Show()
  81.     end
  82.  
  83.     for i = #data + 1, #content.rows do
  84.         content.rows[i]:Hide()
  85.     end
  86. end
  87.  
  88.  
  89. -- Set your button options here
  90. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  91. btn:SetPoint("CENTER")
  92. btn:SetSize(100, 40)
  93. btn:SetText("Click me")
  94. btn:SetMovable(true)
  95. btn:RegisterForDrag('LeftButton')
  96. btn:RegisterForClicks("AnyDown", "AnyUp")
  97. btn:SetUserPlaced(true)
  98. btn:SetScript('OnDragStart', function(self, button, down)
  99.     if button == "LeftButton" and IsShiftKeyDown() then
  100.         self:StartMoving()
  101.     end
  102. end)
  103. btn:SetScript('OnDragStop', function(self)
  104.     self:StopMovingOrSizing()
  105. end)
  106. btn:SetScript("OnMouseUp", function(self, button, ...)
  107.     if (button == "RightButton" and self:IsVisible()) then
  108.         self:Hide()
  109.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  110.         updateData()
  111.         updateList()
  112.         f:Show()
  113.     end
  114. end)
  115.  
  116. SLASH_HUBB1 = "/hubb"
  117. SlashCmdList["HUBB"] = function(msg)
  118.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  119.         btn:SetShown(not btn:IsShown()) -- show the button
  120.         return
  121.     end
  122.     updateData()
  123.     updateList()
  124.     f:Show()
  125. end

To show/hide the button:
Code:
/hubb btn
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-22-24 at 12:34 PM.
  Reply With Quote