View Single Post
02-21-24, 11:11 PM   #13
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Originally Posted by Fizzlemizz View Post
I've created this as an all-in-one example including an example addon.db where I've replaced the item name, icon and added the link for some random items (got rid of the icon texture in the frame as it's in the text, but but it's up to you how you organise the stuff).

Added two %s to each enUS string which gets replaced by the icon (size set to 20x20) and hyperlink when the text is set.

Again, Example Code so, how you get/display the information for your addon will depend on the what/when of the addons workings.

Added a check in the slash command so if you type /hubb btn it will toggle the button
Hi. I did it a little differently. But for some reason, the button and the slash command stopped being pressed.
table.lua
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()], GetItemLinkById(id)), item.icon, item.name})
  18.     end
  19. end
  20. local function GetItemLinkById(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.     updateData()
  113.     updateList()
  114.     f:Show()
  115. end

db.lua
Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.  name = "Emerald Mark of Mastery",
  5.   icon = "interface/icons/inv_mushroom_11",
  6.   announce = {
  7.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(200106))
  8.         }
  9.     },
  10.     {
  11.  name = "Emerald Mark of Mastery",
  12.   icon = "interface/icons/inv_mushroom_11",
  13.   announce = {
  14.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194730))
  15.         }
  16.     },
  17.     {
  18.  name = "Emerald Mark of Mastery",
  19.   icon = "interface/icons/inv_mushroom_11",
  20.   announce = {
  21.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  22.         }
  23.     },
  24.     {
  25.  name = "Emerald Mark of Mastery",
  26.   icon = "interface/icons/inv_mushroom_11",
  27.   announce = {
  28.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  29.         }
  30.     },
  31.     {
  32.  name = "Emerald Mark of Mastery",
  33.   icon = "interface/icons/inv_mushroom_11",
  34.   announce = {
  35.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  36.         }
  37.     },
  38.     {
  39.  name = "Emerald Mark of Mastery",
  40.   icon = "interface/icons/inv_mushroom_11",
  41.   announce = {
  42.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  43.         }
  44.     },
  45.     {
  46.  name = "Emerald Mark of Mastery",
  47.   icon = "interface/icons/inv_mushroom_11",
  48.   announce = {
  49.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  50.         }
  51.     },
  52.     {
  53.  name = "Emerald Mark of Mastery",
  54.   icon = "interface/icons/inv_mushroom_11",
  55.   announce = {
  56.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  57.         }
  58.     },
  59.     {
  60.  name = "Emerald Mark of Mastery",
  61.   icon = "interface/icons/inv_mushroom_11",
  62.   announce = {
  63.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  64.         }
  65.     },
  66.     {
  67.  name = "Emerald Mark of Mastery",
  68.   icon = "interface/icons/inv_mushroom_11",
  69.   announce = {
  70.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  71.         }
  72.     },
  73.     {
  74.  name = "Emerald Mark of Mastery",
  75.   icon = "interface/icons/inv_mushroom_11",
  76.   announce = {
  77.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  78.         }
  79.     },
  80.     {
  81.  name = "Emerald Mark of Mastery",
  82.   icon = "interface/icons/inv_mushroom_11",
  83.   announce = {
  84.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  85.         }
  86.     },
  87.     {
  88.  name = "Emerald Mark of Mastery",
  89.   icon = "interface/icons/inv_mushroom_11",
  90.   announce = {
  91.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  92.         }
  93.     },
  94.     {
  95.  name = "Emerald Mark of Mastery",
  96.   icon = "interface/icons/inv_mushroom_11",
  97.   announce = {
  98.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  99.         }
  100.     },
  101.     {
  102.  name = "Emerald Mark of Mastery",
  103.   icon = "interface/icons/inv_mushroom_11",
  104.   announce = {
  105.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  106.         }
  107.     },
  108.     {
  109.  name = "Emerald Mark of Mastery",
  110.   icon = "interface/icons/inv_mushroom_11",
  111.   announce = {
  112.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  113.         }
  114.     },
  115.     {
  116.  name = "Emerald Mark of Mastery",
  117.   icon = "interface/icons/inv_mushroom_11",
  118.   announce = {
  119.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  120.         }
  121.     },
  122.     {
  123.  name = "Emerald Mark of Mastery",
  124.   icon = "interface/icons/inv_mushroom_11",
  125.   announce = {
  126.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  127.         }
  128.     }
  129. }

Last edited by Hubb777 : 02-21-24 at 11:16 PM.
  Reply With Quote