A Flamescale Wyrmkin
Join Date: Jan 2024
Posts: 131
|
Originally Posted by Fizzlemizz
Missing commas, mayube this time.
Lua Code:
local addonName, addon = ... addon.db = { { name = { enUS = "Emerald Mark of Mastery", deDE = "German for Emerald Mark of Mastery", }, questID = 75612, icon = "interface/icons/inv_mushroom_11", announce = { enUS = { -- the text to display for english text = "Awarded for %s outstanding service %s to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring \nOverlook in the Emerald %s Dream to receive powerful \nequipment for your efforts", itemOrder = { -- the order to display the items in english 210399, 210400, 210401, 210402, }, }, deDE = { -- the text to display for german text = "The items %s might be %s in a different %s order of items %s in german", itemOrder = { -- the order to display the items in german 210401, 210402, 210399, 210400, }, }, }, }, { name = { enUS = "Name number 2", deDE = "German for Name number 2", }, questID = 75624, icon = "interface/icons/inv_mushroom_11", announce = { enUS = { -- the text to display for english text = "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", itemOrder = { -- the order to display the items in english 20897, }, }, deDE = { -- the text to display for german text = "Only one %s in this entry", itemOrder = { -- the order to display the items in german 20897, }, }, } }, } --------------------------------------------------------------------------------------------------- -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function local itemList = {} -- table to save the itsmID to for index, v in ipairs(addon.db) do -- get/save every itmeID in addon.db announce for k, itemID in pairs(v.announce.enUS.itemOrder) do -- assumes all announce entries will use all the same itemIDs if not itemList[itemID] then itemList[itemID] = true end end end local function FormatTexts() -- fill addon.db with the item links for index, v in ipairs(addon.db) do for locale, settings in pairs(v.announce) do local order = {} for i, link in ipairs(settings.itemOrder) do -- get the links in order from addon.db order[i] = itemList[link] -- and save them into a tmporary table end settings.text = format(settings.text, unpack(order)) -- replace %s with the ordered item links (unpack(table) returns a number keyed tables entries in order eg. order[1], order[2], order[3] etc.) end end end local function LoadItem(item) -- Get the links for all the saved itemIDs if item then itemList[item:GetItemID()] = item:GetItemLink() end local key = next(itemList, item and item.Next or nil) if not key then -- when we have all the links for all the items FormatTexts() -- Run FormatTexts() to do the text replacements return end local nextItem = Item:CreateFromItemID(key) nextItem.Next = key nextItem:ContinueOnItemLoad(function() LoadItem(nextItem) end) end LoadItem()
Lua Code:
local addonName, addon = ... -- function to show the item tooltip when a hyperlink is clicked local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- Show the hyperling tooltip when clicked SetItemRef(link, text, nil, self); end 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 locale = GetLocale() -- get the current locale eg. "frFR" local function updateData() wipe(data) for _, item in ipairs(addon.db) do local announceText = item.announce[locale].text or item.announce.enUS.text -- default to enUS if the locale text doesn't exist. tinsert(data, {announceText, item.icon, item.name[locale] or item.name.enUS}) end 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 = {} --------------------------------------------------------------------------------------------------- -- code to make item links work button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row button:SetScript("OnHyperlinkClick", OnHyperlinkClick) -- What to do when a link is clicked --------------------------------------------------------------------------------------------------- button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight") button.columns[1]:SetPoint("TOPLEFT", (0) * CELL_WIDTH, 0) button.columns[1]:SetPoint("BOTTOMRIGHT", button, "BOTTOMLEFT", 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("Rewards") 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) if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn btn:SetShown(not btn:IsShown()) -- show the button return end updateData() updateList() f:Show() end
|
It also didn't work. The button is not pressed.
Lua Code:
1x ZamTEST/table.lua:78: bad argument #1 to 'SetText' (Usage: self:SetText([text])) [string "=[C]"]: in function `SetText' [string "@ZamTEST/table.lua"]:78: in function <ZamTEST/table.lua:52> [string "@ZamTEST/table.lua"]:113: in function <ZamTEST/table.lua:108> Locals: (*temporary) = FontString { 0 = <userdata> } (*temporary) = <table> { itemOrder = <table> { } text = "Awarded for %s outstanding service %s to Dragonkind. %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald %s Dream to receive powerful equipment for your efforts" }
|