A Flamescale Wyrmkin
Join Date: Jan 2024
Posts: 122
|
Originally Posted by Fizzlemizz
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:
local addonName, addon = ... local CELL_WIDTH = 400 local CELL_HEIGHT = 80 local NUM_CELLS = 2 local data = {} local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset") -- Create the button here local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate") local function updateData() --commented out because addon.db hasn't been created... in the code at least wipe(data) for _, item in ipairs(addon.db) do tinsert(data, {format(item.announce[GetLocale()], GetItemLinkById(id)), item.icon, item.name}) end end local function GetItemLinkById(id) local item = Item:CreateFromItemID(id) local itemLink = item:GetItemLink() return itemLink end f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600) f:SetPoint("CENTER") f:Hide() f:SetMovable(true) f:SetScript("OnMouseDown", f.StartMoving) f:SetScript("OnMouseUp", f.StopMovingOrSizing) -- I added this OnHide script f:SetScript("OnHide", function() btn:Show() end) f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate") f.scrollFrame:SetPoint("TOPLEFT", 12, -32) f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8) f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame) f.scrollFrame.scrollChild:SetSize(100, 100) f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5) f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild) local content = f.scrollFrame.scrollChild content.rows = {} local function updateList() for i = 1, #data do if not content.rows[i] then local button = CreateFrame("Button", nil, content) button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT) button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT) button.columns = {} button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight") button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0) button.columns[2] = button:CreateTexture() button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0) button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight") button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0) content.rows[i] = button end content.rows[i].columns[1]:SetText(data[i][1]) content.rows[i].columns[2]:SetTexture(data[i][2]) content.rows[i].columns[3]:SetText(data[i][3]) content.rows[i]:Show() end for i = #data + 1, #content.rows do content.rows[i]:Hide() end end -- Set your button options here local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate") btn:SetPoint("CENTER") btn:SetSize(100, 40) btn:SetText("Click me") btn:SetMovable(true) btn:RegisterForDrag('LeftButton') btn:RegisterForClicks("AnyDown", "AnyUp") btn:SetUserPlaced(true) btn:SetScript('OnDragStart', function(self, button, down) if button == "LeftButton" and IsShiftKeyDown() then self:StartMoving() end end) btn:SetScript('OnDragStop', function(self) self:StopMovingOrSizing() end) btn:SetScript("OnMouseUp", function(self, button, ...) if (button == "RightButton" and self:IsVisible()) then self:Hide() elseif button == "LeftButton" and not IsShiftKeyDown() then updateData() updateList() f:Show() end end) SLASH_HUBB1 = "/hubb" SlashCmdList["HUBB"] = function(msg) updateData() updateList() f:Show() end
db.lua
Lua Code:
local addonName, addon = ... addon.db = { { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(200106)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194730)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } }, { name = "Emerald Mark of Mastery", icon = "interface/icons/inv_mushroom_11", announce = { enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701)) } } }
Last edited by Hubb777 : 02-21-24 at 11:16 PM.
|