View Single Post
02-22-24, 12:02 AM   #15
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 122
Originally Posted by Fizzlemizz View Post
I'm not sure what you mean by "stopped being pressed", or the whole sentence really?.

You removed the option to show/hide the button from the slash command (or at least didn't copy the SlashCmdList["HUBB"] = function(msg) code from my example.

Your latest code contains a function GetItemLinkById I have no idea what it is or where it's from but it's not Blizz and it's not defined in anything you've posted so colour me confused that it works at all.
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {format(item.announce[GetLocale()], GetItemLink(id)), item.icon, item.name})
  18.     end
  19. end
  20. local function GetItemLink(id)
  21.     local item = Item:CreateFromItemID(id)
  22.     local itemLink = item:GetItemLink()
  23.  
  24.     return itemLink
  25. end
  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.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  59.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  60.  
  61.             button.columns[2] = button:CreateTexture()
  62.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  63.  
  64.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  65.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  66.  
  67.             content.rows[i] = button
  68.         end
  69.  
  70.         content.rows[i].columns[1]:SetText(data[i][1])
  71.         content.rows[i].columns[2]:SetTexture(data[i][2])
  72.         content.rows[i].columns[3]:SetText(data[i][3])
  73.  
  74.         content.rows[i]:Show()
  75.     end
  76.  
  77.     for i = #data + 1, #content.rows do
  78.         content.rows[i]:Hide()
  79.     end
  80. end
  81.  
  82.  
  83. -- Set your button options here
  84. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  85. btn:SetPoint("CENTER")
  86. btn:SetSize(100, 40)
  87. btn:SetText("Click me")
  88. btn:SetMovable(true)
  89. btn:RegisterForDrag('LeftButton')
  90. btn:RegisterForClicks("AnyDown", "AnyUp")
  91. btn:SetUserPlaced(true)
  92. btn:SetScript('OnDragStart', function(self, button, down)
  93.     if button == "LeftButton" and IsShiftKeyDown() then
  94.         self:StartMoving()
  95.     end
  96. end)
  97. btn:SetScript('OnDragStop', function(self)
  98.     self:StopMovingOrSizing()
  99. end)
  100. btn:SetScript("OnMouseUp", function(self, button, ...)
  101.     if (button == "RightButton" and self:IsVisible()) then
  102.         self:Hide()
  103.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  104.         updateData()
  105.         updateList()
  106.         f:Show()
  107.     end
  108. end)
  109.  
  110. SLASH_HUBB1 = "/hubb"
  111. SlashCmdList["HUBB"] = function(msg)
  112.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  113.         btn:SetShown(not btn:IsShown()) -- show the button
  114.         return
  115.     end
  116.     updateData()
  117.     updateList()
  118.     f:Show()
  119. end

I was assured that it would work in GetItemLinkById. But it looks like we just didn't understand each other.
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. -- name and icon (and link) set by LoadItem() when the item is cached.
  8. addon.db = {
  9.     {
  10. --        name = "Emerald Mark of Mastery",
  11.         questID = 75612,
  12. --        icon = "interface/icons/inv_mushroom_11",
  13.         item = 6218,
  14.         announce = {
  15.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  16.         }
  17.     },
  18.     {
  19. --        name = "Emerald Mark of Mastery",
  20.         questID = 75624,
  21. --        icon = "interface/icons/inv_mushroom_11",
  22.         item = 20897,
  23.         announce = {
  24.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts\n\nAwarded for outstanding service to (clickable link to the item) Dragonkind. Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  25.         }
  26.     },
  27.     {
  28. --        name = "Emerald Mark of Mastery",
  29.         questID = 74352,
  30.         item = 193440,
  31. --        icon = "interface/icons/inv_mushroom_11",
  32.         announce = {
  33.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  34.         }
  35.     }
  36. }
  37.  
  38. local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- function to print the link when clicked
  39.     print("You just clickled:", text)
  40. end
  41.  
  42. local function OnHyperlinkEnter(self, link, text, region, left, bottom, width, height) -- function to display the hyperlink on mouse over
  43.     GameTooltip:SetOwner(self, "ANCHOR_CURSOR_RIGHT")
  44.     GameTooltip:SetHyperlink(link)
  45.     GameTooltip:Show()
  46. end
  47.  
  48. local function OnHyperlinkLeave(self) -- function to hide the hyperlink on mouse exit
  49.     GameTooltip:Hide()
  50. end
  51.  
  52. local function LoadItem(item) -- adds the item to the bd overwriting the icon, name ans sedtting the itemlink keys
  53.     addon.db[item.dbID].name = item:GetItemName()
  54.     addon.db[item.dbID].icon = "|T"..item:GetItemIcon()..":20:20|t" -- make icon size 20x20
  55.     addon.db[item.dbID].itemlink = item:GetItemLink()
  56.  
  57.  
  58. print(addon.db[item.dbID].name, addon.db[item.dbID].icon, addon.db[item.dbID].itemlink)
  59.  
  60. end
  61.  
  62. for i, v in ipairs(addon.db) do -- Get the item information and call LoadItem when it's returned from the server and cached
  63.     local item = Item:CreateFromItemID(v.item)
  64.     item.dbID = i
  65.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  66. end
  67.  
  68. local data = {}
  69.  
  70. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  71. f.Title = f:CreateFontString()
  72. f.Title:SetFontObject(GameFontNormal)
  73. f.Title:SetPoint("TOP", 0, -5)
  74. f.Title:SetText(addonName)
  75. -- Create the button here
  76. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  77.  
  78. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  79.     wipe(data)
  80.     for _, item in ipairs(addon.db) do
  81.         tinsert(data, {text=item.announce[GetLocale()], icon=item.icon, name=item.name, link=item.itemlink})
  82.     end
  83. end
  84.  
  85. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  86. f:SetPoint("CENTER")
  87. f:Hide()
  88. f:SetMovable(true)
  89. f:SetScript("OnMouseDown", f.StartMoving)
  90. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  91.  
  92.  
  93. -- I added this OnHide script
  94. f:SetScript("OnHide", function()
  95.     btn:Show()
  96. end)
  97.  
  98. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  99. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  100. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  101.  
  102. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  103. f.scrollFrame.scrollChild:SetSize(100, 100)
  104. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  105. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  106.  
  107. local content = f.scrollFrame.scrollChild
  108. content.rows = {}
  109.  
  110. local function updateList()
  111.     for i = 1, #data do
  112.         if not content.rows[i] then
  113.             local button = CreateFrame("Button", nil, content)
  114.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  115.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  116.             button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row
  117.             button:SetScript("OnHyperlinkClick", OnHyperlinkClick)
  118.             button:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)
  119.             button:SetScript("OnHyperlinkLeave", OnHyperlinkLeave)
  120.            
  121.             button.columns = {}
  122.  
  123.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  124.             button.columns[1]:SetJustifyH("LEFT")
  125.             button.columns[1]:SetJustifyV("TOP")
  126. --            button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  127.             button.columns[1]:SetPoint("TOPLEFT")
  128.             button.columns[1]:SetPoint("BOTTOMRIGHT", button, "BOTTOMLEFT", 140, 0)
  129.  
  130. -- Replaced the icon texture with the icon embedded in the description string.
  131. --            button.columns[2] = button:CreateTexture()
  132. --            button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  133. --            button.columns[2]:SetPoint("LEFT", button.columns[1], "RIGHT")
  134.  
  135.             button.columns[2] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  136.             button.columns[2]:SetJustifyH("LEFT")
  137.             button.columns[2]:SetJustifyV("TOP")
  138. --            button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  139.             button.columns[2]:SetPoint("TOPLEFT", button.columns[1], "TOPRIGHT", 5, 0)
  140.             button.columns[2]:SetPoint("BOTTOMRIGHT", button)
  141.  
  142.             content.rows[i] = button
  143.         end
  144.  
  145.         content.rows[i].columns[1]:SetText(data[i].name)
  146. --        content.rows[i].columns[2]:SetTexture(data[i][2])
  147.         content.rows[i].columns[2]:SetText(format(data[i].text, data[i].icon, data[i].link)) -- insert the icon and hyperlink into the text
  148.  
  149.         content.rows[i]:Show()
  150.     end
  151.  
  152.     for i = #data + 1, #content.rows do
  153.         content.rows[i]:Hide()
  154.     end
  155. end
  156.  
  157.  
  158. -- Set your button options here
  159. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  160. btn:SetPoint("CENTER")
  161. btn:SetSize(100, 40)
  162. btn:SetText("Click me")
  163. btn:SetMovable(true)
  164. btn:RegisterForDrag('LeftButton')
  165. btn:RegisterForClicks("AnyDown", "AnyUp")
  166. btn:SetUserPlaced(true)
  167. btn:SetScript('OnDragStart', function(self, button, down)
  168.     if button == "LeftButton" and IsShiftKeyDown() then
  169.         self:StartMoving()
  170.     end
  171. end)
  172. btn:SetScript('OnDragStop', function(self)
  173.     self:StopMovingOrSizing()
  174. end)
  175. btn:SetScript("OnMouseUp", function(self, button, ...)
  176.     if (button == "RightButton" and self:IsVisible()) then
  177.         self:Hide()
  178.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  179.         updateData()
  180.         updateList()
  181.         f:Show()
  182.     end
  183. end)
  184.  
  185. SLASH_HUBB1 = "/hubb"
  186. SlashCmdList["HUBB"] = function(msg)
  187.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  188.         btn:SetShown(not btn:IsShown()) -- show the button
  189.         return
  190.     end
  191.     updateData()
  192.     updateList()
  193.     f:Show()
  194. end

Your code works 100%. But it displays the items in the chat, rather than displaying a table. And it is the table that I need.


An example where instead of {item:194701} there is a link to the item.
  Reply With Quote