View Single Post
02-25-24, 01:02 AM   #38
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 131
Originally Posted by Fizzlemizz View Post
Because the original table wasn't set up with localised names, we were just dealing with the announce texts.

To add localise names you woud have to convert ALL the name entried to tables:

Data
Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.         name = {
  5.             enUS = "Emerald Mark of Mastery",
  6.             deDE = "German for Emerald Mark of Mastery",
  7.         }
  8.         questID = 75612,
  9.         icon = "interface/icons/inv_mushroom_11",
  10.         announce = {
  11.              enUS = { -- the text to display for english
  12.                  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",
  13.                  itemOrder = { -- the order to display the items in english
  14.                      210399,
  15.                      210400,
  16.                      210401,
  17.                      210402,
  18.                  },
  19.              },
  20.              deDE = { -- the text to display for german
  21.                  text = "The items %s might be %s in a different %s order of items %s in german",
  22.                  itemOrder = { -- the order to display the items in german
  23.                      210401,
  24.                      210402,
  25.                      210399,
  26.                      210400,
  27.                  },
  28.              },
  29.         },
  30.     },
  31.     {
  32.         name = {
  33.             enUS = "Name number 2",
  34.             deDE = "German for Name number 2",
  35.         }
  36.         questID = 75624,
  37.         icon = "interface/icons/inv_mushroom_11",
  38.         announce = {
  39.             enUS = { -- the text to display for english
  40.                 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",
  41.                 itemOrder = { -- the order to display the items in english
  42.                     20897,
  43.                 },
  44.             },
  45.             deDE = { -- the text to display for german
  46.                 text = "Only one %s in this entry",
  47.                 itemOrder = { -- the order to display the items in german
  48.                     20897,
  49.                 },
  50.             },
  51.         }
  52.     },
  53. }

And change the tinsert line in the updateData() function to reflect the change

Code
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. -- function to show the item tooltip when a hyperlink is clicked
  4. local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- Show the hyperling tooltip when clicked
  5.     SetItemRef(link, text, nil, self);
  6. end
  7.  
  8. local CELL_WIDTH = 400
  9. local CELL_HEIGHT = 80
  10. local NUM_CELLS = 2
  11.  
  12. local data = {}
  13.  
  14. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  15.  
  16. -- Create the button here
  17. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  18.  
  19. local locale = GetLocale() -- get the current locale eg. "frFR"
  20. local function updateData()
  21.     wipe(data)
  22.     for _, item in ipairs(addon.db) do
  23.         local announceText = item.announce[locale].text or item.announce.enUS.text -- default to enUS if the locale text doesn't exist.
  24.         tinsert(data, {announceText, item.icon, item.name[locale] or item.name.enUS})
  25.     end
  26. end
  27.  
  28. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  29. f:SetPoint("CENTER")
  30. f:Hide()
  31. f:SetMovable(true)
  32. f:SetScript("OnMouseDown", f.StartMoving)
  33. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  34.  
  35. -- I added this OnHide script
  36. f:SetScript("OnHide", function()
  37.     btn:Show()
  38. end)
  39.  
  40. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  41. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  42. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  43.  
  44. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  45. f.scrollFrame.scrollChild:SetSize(100, 100)
  46. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  47. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  48.  
  49. local content = f.scrollFrame.scrollChild
  50. content.rows = {}
  51.  
  52. local function updateList()
  53.     for i = 1, #data do
  54.         if not content.rows[i] then
  55.             local button = CreateFrame("Button", nil, content)
  56.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  57.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  58.             button.columns = {}
  59.  
  60. ---------------------------------------------------------------------------------------------------
  61. -- code to make item links work
  62.             button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row
  63.             button:SetScript("OnHyperlinkClick", OnHyperlinkClick) -- What to do when a link is clicked
  64. ---------------------------------------------------------------------------------------------------
  65.  
  66.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  67.             button.columns[1]:SetPoint("TOPLEFT", (0) * CELL_WIDTH, 0)
  68.             button.columns[1]:SetPoint("BOTTOMRIGHT", button, "BOTTOMLEFT", CELL_WIDTH, 0)
  69.  
  70.             button.columns[2] = button:CreateTexture()
  71.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  72.  
  73.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  74.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  75.  
  76.             content.rows[i] = button
  77.         end
  78.  
  79.         content.rows[i].columns[1]:SetText(data[i][1])
  80.         content.rows[i].columns[2]:SetTexture(data[i][2])
  81.         content.rows[i].columns[3]:SetText(data[i][3])
  82.  
  83.         content.rows[i]:Show()
  84.     end
  85.  
  86.     for i = #data + 1, #content.rows do
  87.         content.rows[i]:Hide()
  88.     end
  89. end
  90.  
  91.  
  92. -- Set your button options here
  93. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  94. btn:SetPoint("CENTER")
  95. btn:SetSize(100, 40)
  96. btn:SetText("Rewards")
  97. btn:SetMovable(true)
  98. btn:RegisterForDrag('LeftButton')
  99. btn:RegisterForClicks("AnyDown", "AnyUp")
  100. btn:SetUserPlaced(true)
  101. btn:SetScript('OnDragStart', function(self, button, down)
  102.     if button == "LeftButton" and IsShiftKeyDown() then
  103.         self:StartMoving()
  104.     end
  105. end)
  106. btn:SetScript('OnDragStop', function(self)
  107.     self:StopMovingOrSizing()
  108. end)
  109. btn:SetScript("OnMouseUp", function(self, button, ...)
  110.     if (button == "RightButton" and self:IsVisible()) then
  111.         self:Hide()
  112.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  113.         updateData()
  114.         updateList()
  115.         f:Show()
  116.     end
  117. end)
  118.  
  119. SLASH_HUBB1 = "/hubb"
  120. SlashCmdList["HUBB"] = function(msg)
  121.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  122.         btn:SetShown(not btn:IsShown()) -- show the button
  123.         return
  124.     end
  125.     updateData()
  126.     updateList()
  127.     f:Show()
  128. end
I used your example but it still didn't work
  Reply With Quote