View Single Post
02-21-24, 10:26 AM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
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

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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-21-24 at 02:28 PM.
  Reply With Quote