Thread Tools Display Modes
02-23-24, 12:24 AM   #21
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Fizzlemizz View Post
That looks OK.

The only thing is that you have a deDE for a only one entry in addon.db where
Code:
tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
will cause an error if the entry is missing in any single entry for the users locale return from GetLocale().

Have Fun!
That is, if the player’s game client is in French, and my addon does not support lines with frFR, then the player will have an error?
  Reply With Quote
02-23-24, 12:52 AM   #22
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
If french (frFR) didn't exists then

Code:
tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
would be the same as
Code:
tinsert(data, {item.announce["frFR"], item.icon, item.name})
which in the end would be
Code:
tinsert(data, {nil, item.icon, item.name})
Inserting nil will cause tinsert to error.

You could use something like the following that will test if the users locale announce field is in addon.db and if not, default to using the enUS text.
Lua Code:
  1. local locale = GetLocale() -- get the current locale eg. "frFR"
  2. local function updateData()
  3.     wipe(data)
  4.     for _, item in ipairs(addon.db) do
  5.         local announceText = item.announce[locale] or item.announce.enUS -- default to enUS if the locale text doesn't exist.
  6.         tinsert(data, {announceText, item.icon, item.name})
  7.     end
  8. end

This assumes there will be a enUS field in EVERY announce table.

You could of course, if you prefer, default to .frFR or .deDE whichever locale oocures in every entry.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-23-24 at 08:40 AM.
  Reply With Quote
02-23-24, 10:37 PM   #23
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Fizzlemizz View Post
Lua Code:
  1. local locale = GetLocale() -- get the current locale eg. "frFR"
  2. local function updateData()
  3.     wipe(data)
  4.     for _, item in ipairs(addon.db) do
  5.         local announceText = item.announce[locale] or item.announce.enUS -- default to enUS if the locale text doesn't exist.
  6.         tinsert(data, {announceText, item.icon, item.name})
  7.     end
  8. end
Yes, this option is ideal (after all, I don’t know what languages the players who install the addon speak, but many speak English)

Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.         name = {
  5.             enUS = "Herb-Infused Water",
  6.             deDE = "Mit Kräutern aromatisiertes Wasser"
  7.         },
  8.         questID = 75612,
  9.         icon = "interface/icons/inv_mushroom_11",
  10.         item = 210399,
  11.         item = 210400,
  12.         item = 210401,
  13.         item = 210402,
  14.         item = 210403,
  15.         item = 210404,
  16.         announce = {
  17.              enUS = "Awarded for %ss outstanding service %sss to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring \nOverlook in the Emerald %ssss Dream to receive powerful \nequipment for your efforts",
  18.         }
  19.     },
  20.     {
  21.         name = "Emerald Mark of Mastery",
  22.         questID = 75624,
  23.         icon = "interface/icons/inv_mushroom_11",
  24.         item = 20897,
  25.         announce = {
  26.              enUS = "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"
  27.         }
  28.     },
  29.     {
  30.         name = "Emerald Mark of Mastery",
  31.         questID = 74352,
  32.         icon = "interface/icons/inv_mushroom_11",
  33.         item = 193440,
  34.         announce = {
  35.              enUS = "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"
  36.         }
  37.     }
  38. }
  39. ---------------------------------------------------------------------------------------------------
  40. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  41. local function LoadItem(item)
  42.     for k, v in pairs(addon.db[item.dbID].announce) do -- replace the %s with the itemlink in eal locale in the .announce key
  43.         addon.db[item.dbID].announce[k] = format(v, item:GetItemLink())
  44.     end
  45. end
  46. for i, v in ipairs(addon.db) do
  47.     local item = Item:CreateFromItemID(v.item)
  48.     item.dbID = i
  49.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  50. end
During the creation of the addon, a question arose. One link to a item in the text is missing; you need to insert 2,3 or more links into one text. As I understand it, you need to set different variables, for example %ss or %sss or %d, so that each one is tied to a specific position of the link to the item.

Last edited by Hubb777 : 02-23-24 at 10:53 PM.
  Reply With Quote
02-23-24, 11:55 PM   #24
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Code:
/run print(format("%s %s %s", "Replace", "with", text"))
Each %s is replaced left-to-right with the corresponding argument after the text string ("Replace", "with", text"). There are tokens other than %s various data types/formatting see the docs for format for more information.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-24-24, 12:07 AM   #25
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Fizzlemizz View Post
Code:
/run print(format("%s %s %s", "Replace", "with", text"))
Each %s is replaced left-to-right with the corresponding argument after the text string ("Replace", "with", text"). There are tokens other than %s various data types/formatting see the docs for format for more information.
Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.         name = {
  5.             enUS = "Herb-Infused Water",
  6.         },
  7.         questID = 75612,
  8.         icon = "interface/icons/inv_mushroom_11",
  9.         item = 210399, 210400, 210401,
  10.         announce = {
  11.              enUS = format("Awarded for %s outstanding service %s to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring"),
  12.         }
  13.     },
  14.     {
  15.         name = "Emerald Mark of Mastery",
  16.         questID = 74352,
  17.         icon = "interface/icons/inv_mushroom_11",
  18.         item = 193440, 193441, 193442,
  19.         announce = {
  20.              enUS = format("Awarded for %s outstanding service to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the %s Wellspring)"
  21.         }
  22.     }
  23. }
  24. ---------------------------------------------------------------------------------------------------
  25. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  26. local function LoadItem(item)
  27.     for k, v in pairs(addon.db[item.dbID].announce) do -- replace the %s with the itemlink in eal locale in the .announce key
  28.         addon.db[item.dbID].announce[k] = format(v, item:GetItemLink())
  29.     end
  30. end
  31. for i, v in ipairs(addon.db) do
  32.     local item = Item:CreateFromItemID(v.item)
  33.     item.dbID = i
  34.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  35. end

I tried this but it didn't work
  Reply With Quote
02-24-24, 01:15 AM   #26
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
This makes it a bit more complicated as you're getting mutiple items for each row so you have to have them all cached before you can do the format().

I have to head out so I'll look at it in the morning.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-24-24, 01:37 AM   #27
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Fizzlemizz View Post
This makes it a bit more complicated as you're getting mutiple items for each row so you have to have them all cached before you can do the format().

I have to head out so I'll look at it in the morning.
Thank you very much, good luck in your business. Maybe this code will help you
Lua Code:
  1. local Item = Class('Item', Reward)
  2.  
  3. function Item:Initialize(attrs)
  4.     Reward.Initialize(self, attrs)
  5.  
  6.     if not self.item then
  7.         error('Item() reward requires an item id to be set')
  8.     end
  9.     self.itemLink = L['retrieving']
  10.     self.itemIcon = 'Interface\\Icons\\Inv_misc_questionmark'
  11.     local item = _G.Item:CreateFromItemID(self.item)
  12.     if not item:IsItemEmpty() then
  13.         item:ContinueOnItemLoad(function()
  14.             self.itemLink = item:GetItemLink()
  15.             self.itemIcon = item:GetItemIcon()
  16.         end)
  17.     end
  18. end
  19.  
  20. function Item:Prepare() ns.PrepareLinks(self.note) end
  21.  
  22. function Item:IsObtained()
  23.     if self.quest then return C_QuestLog.IsQuestFlaggedCompleted(self.quest) end
  24.     if self.bag then return ns.PlayerHasItem(self.item) end
  25.     return true
  26. end
  27.  
  28. function Item:GetText()
  29.     local text = self.itemLink
  30.     if self.type then -- mount, pet, toy, etc
  31.         text = text .. ' (' .. self.type .. ')'
  32.     end
  33.     if self.count then
  34.         text = text .. string.format(' (%sx)', BreakUpLargeNumbers(self.count))
  35.     end
  36.     if self.note then -- additional info
  37.         text = text .. ' (' .. ns.RenderLinks(self.note, true) .. ')'
  38.     end
  39.     return Icon(self.itemIcon) .. text
  40. end
  41.  
  42. function Item:GetStatus()
  43.     if self.bag then
  44.         local collected = ns.PlayerHasItem(self.item)
  45.         return collected and Green(L['completed']) or Red(L['incomplete'])
  46.     elseif self.status then
  47.         return format('(%s)', self.status)
  48.     elseif self.quest then
  49.         local completed = C_QuestLog.IsQuestFlaggedCompleted(self.quest)
  50.         return completed and Green(L['completed']) or Red(L['incomplete'])
  51.     elseif self.weekly then
  52.         local completed = C_QuestLog.IsQuestFlaggedCompleted(self.weekly)
  53.         return completed and Green(L['weekly']) or Red(L['weekly'])
  54.     end
  55. end


And an additional question. - https://www.wowinterface.com/forums/...t=59795&page=2

In the last topic you helped me make a timer.
I plan to make another addon in the future that also uses this timer. The problem is that if a player installs 2 of these addons, the timer will not work correctly. I thought it was enough to fix ZAMROTimer to ZAMRO1Timer, but it looks like something else needs to be done?

Last edited by Hubb777 : 02-24-24 at 02:53 AM.
  Reply With Quote
02-24-24, 02:46 AM   #28
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Double check that you have no common non local functions or variables. These would overwrite each other and thus cause one to not work properly.

If you can't see anything like this in both addons then, perhaps you can describe what you are seeing happen ? And if you don't have bugsack or buggrabber installed to catch any errors it might be worth doing to help pinpoint where it's breaking.


Looking at the last code block Fizzle posted in that thread, just changing the frame name should be enough to make it work.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
02-24-24, 02:51 AM   #29
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Xrystal View Post
Double check that you have no common non local functions or variables. These would overwrite each other and thus cause one to not work properly.

If you can't see anything like this in both addons then, perhaps you can describe what you are seeing happen ? And if you don't have bugsack or buggrabber installed to catch any errors it might be worth doing to help pinpoint where it's breaking.


Looking at the last code block Fizzle posted in that thread, just changing the frame name should be enough to make it work.
My second timer starts flickering periodically and at this moment data from the first timer appears there.
  Reply With Quote
02-24-24, 05:31 AM   #30
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Did you make sure that each display has it's own location ?

You will need to adjust the anchor if you want them both displayed at the same time.

If you notice in Fizzle's example code:

Lua Code:
  1. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)

If both addons have the same anchor point their information will overlay each other on the screen.
If you notice there is a frame_x and frame_y value there. If you are using the same code for your addon you can have each addon have different frame_x/frame_y values so that the frame will not overlay each other.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
02-24-24, 07:02 AM   #31
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Xrystal View Post
Did you make sure that each display has it's own location ?

You will need to adjust the anchor if you want them both displayed at the same time.

If you notice in Fizzle's example code:

Lua Code:
  1. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)

If both addons have the same anchor point their information will overlay each other on the screen.
If you notice there is a frame_x and frame_y value there. If you are using the same code for your addon you can have each addon have different frame_x/frame_y values so that the frame will not overlay each other.
I'm a newbie so would appreciate a visual example based on my code
Lua Code:
  1. local addonName, addon = ...
  2. local Backdrop = {
  3.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  4. }
  5.  
  6. local frame_x = 0    
  7. local frame_y = -200    
  8. f = CreateFrame("Button", "ZAMTimer", UIParent, "BackdropTemplate")
  9. f:SetWidth(255)                                          
  10. f:SetHeight(30)
  11. f:SetBackdrop(Backdrop)
  12. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  13. f.text:SetTextHeight(15)
  14. f.text:SetPoint("CENTER")
  15. f:SetClampedToScreen(true)
  16. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  17. f:EnableMouse(true)
  18. f:SetMovable(true)
  19. f:RegisterForDrag("LeftButton")
  20. f:RegisterForClicks("AnyUp")
  21. f:Show()
  22. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  23. f:SetScript("OnDragStart",function(this)
  24.     this:StartMoving()
  25. end)
  26. f:SetScript("OnDragStop",function(this)  
  27.     this:StopMovingOrSizing()
  28.     frame_x,frame_y = this:GetRIGHT()
  29.     frame_x = frame_x - GetScreenWidth() / 2
  30.     frame_y = frame_y - GetScreenHeight() / 2
  31.     this:ClearAllPoints()
  32.     this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  33. end)
  34. -- first %s is replaced by the color. The second is replaced by the time. |r resets the color back to default
  35. local Localizations = {
  36.     enUS = {
  37.         Waiting = "|c1C7BCEFFResearchers Under Fire:\nbefore the start: %s%s|r",
  38.         Running = "|cFF35BE21Researchers Under Fire:\n%s%s until completion|r",
  39.     },
  40. }
  41.  
  42. local locale = GetLocale()
  43. local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
  44.  
  45. ------------------------------------------------------------------------------------------------------
  46. -- These might be converted to Saved Variables so each character can determine
  47. -- wether or not to play a sound, the alert times and colors and sound to play.
  48. -- If so then most of the code below will have to move into an event handler for
  49. -- the PLAYER_LOGIN or PLAYER_ENTERING_WORLD event.
  50. local useColor = true
  51. local useSound = true
  52. local alert1 = 600 -- Alarm 1 set to 10 minutes before event
  53. local alert1Color = "|cffffff00" -- Yellow
  54. local alert2 = 300 -- Alarm 2 set to 5 minutes before event
  55. local alert2Color = "|cffff0000" -- Red
  56. local soundKit = 32585 -- Alarm sound
  57. ------------------------------------------------------------------------------------------------------
  58.  
  59. local function printTime(timetotrun, inevent)
  60.     local hideSeconds = timetotrun >= 120
  61.     local msg = L.Waiting
  62.     local msgColor = "|cffffffff"
  63.     if inevent then
  64.         msg = L.Running
  65.     else
  66.         if useColor and timetotrun <= alert2 then
  67.             msgColor = alert2Color
  68.         elseif timetotrun <= alert1 then
  69.             if useSound and not ZAMTimer.Alerted then
  70.                 ZAMTimer.Alerted = true
  71.                 PlaySound(soundKit, "Master")
  72.             end
  73.             if useColor then
  74.                 msgColor = alert1Color
  75.             end
  76.         end
  77.     end
  78.     f.text:SetText(format(msg, msgColor, SecondsToTime(timetotrun, hideSeconds)))
  79. end
  80.  
  81. regionEventStartTime = {
  82.     [1] = { -- eu
  83.         starttime = 1708756200,
  84.         eventDuration = 1500,
  85.         eventIntervalInSeconds = 3600,
  86.         enable = true,
  87.         datablock = {}
  88.     },
  89. }
  90.  
  91. local inEvent, timeToRun
  92. local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
  93. local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
  94. local startTime = regionEventStartTime[1].starttime -- Start time from the table
  95. local serverTime = GetServerTime()
  96. local timeToEvent = (startTime - serverTime) % waitTime -- Remaining time before next event starts
  97.  
  98. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  99.     inEvent = true
  100.     timeToRun = eventTime - (waitTime - timeToEvent)
  101. else                    -- Otherwise, set the ticker timer to time to next event
  102.     inEvent = false
  103.     timeToRun = timeToEvent
  104. end
  105. local ticker = C_Timer.NewTicker(1, function()
  106.     if timeToRun > 0 then
  107.         timeToRun = timeToRun - 1
  108.         printTime(timeToRun, inEvent)
  109.         return
  110.     end
  111.     ZAMTimer.Alerted = false
  112.     if inEvent then -- The event just finished
  113.         inEvent = false
  114.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  115.     else  -- Waiting for the next event just expired
  116.         inEvent = true
  117.         timeToRun = eventTime -- And the event is running
  118.     end
  119.     printTime(timeToRun, inEvent)
  120. end)
  121. printTime(timeToRun, inEvent)
  Reply With Quote
02-24-24, 08:44 AM   #32
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Assuming you have the same file in each of the addons. Simply changing the frame name on line 8 as well as setting f to be local not global ( that would mess things up there ) and the frame_x and frame_y values on lines 6 and 7 might be all you need to do. Assuming the rest of the code does what the addon was designed to do.

So..

Addon 1

Lua Code:
  1. local frame_x = 0    
  2. local frame_y = -200    
  3. local f = CreateFrame("Button", "ZAMTimer1", UIParent, "BackdropTemplate")

Addon 2
Lua Code:
  1. local frame_x = 0    
  2. local frame_y = -250    
  3. local f = CreateFrame("Button", "ZAMTimer2", UIParent, "BackdropTemplate")

Although I see you have the frame dragging code set up to re-arrange as needed. So, the above should work well enough to make both frames separate and accessible and not overidden by the other one.

I think having the f - CreateFrame line not be local was the main issue.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
02-24-24, 11:32 AM   #33
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Probably best to make separate threads for each question as the code is getting pretty messy even for just one (hopefully Xrystal has answered your timer question).

Having multiple item links and locales in your addon.db texts complicates things because the order you want the links to display might be different in german to the order displayed in french and might be different again for english.

This requires identifying the order each link needs to be in for every locale text. With that in mind, the structure of addon.db needs to change so this is one way you could do it (my german in non-existant so it didn't even try):

NOTE: the number if items in each itemOrder should be the same as the number of %s tokens that are in the corresponding text field.
(This is probably overkill as it's replacing all the locale texts and you probably only need the ones that will be actually be used but that depends on what the end addon requires so...)

Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.         name = {
  5.             enUS = "Herb-Infused Water",
  6.             deDE = "Mit Kräutern aromatisiertes Wasser"
  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 = "Emerald Mark of Mastery",
  33.         questID = 75624,
  34.         icon = "interface/icons/inv_mushroom_11",
  35.         announce = {
  36.             enUS = { -- the text to display for english
  37.                 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",
  38.                 itemOrder = { -- the order to display the items in english
  39.                     20897,
  40.                 },
  41.             },
  42.             deDE = { -- the text to display for german
  43.                 text = "Only one %s in this entry",
  44.                 itemOrder = { -- the order to display the items in german
  45.                     20897,
  46.                 },
  47.             },
  48.         }
  49.     },
  50. }
  51. ---------------------------------------------------------------------------------------------------
  52. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  53.  
  54. local itemList = {} -- table to save the itsmID to
  55.  
  56. for index, v in ipairs(addon.db) do -- get/save every itmeID in addon.db announce
  57.    for k, itemID in pairs(v.announce.enUS.itemOrder) do -- assumes all announce entries will use all the same itemIDs
  58.       if not itemList[itemID] then
  59.          itemList[itemID] = true
  60.       end
  61.    end
  62. end
  63.  
  64. local function FormatTexts() -- fill addon.db with the item links
  65.    for index, v in ipairs(addon.db) do
  66.       for locale, settings in pairs(v.announce) do
  67.          local order = {}  
  68.          for i, link in ipairs(settings.itemOrder) do -- get the links in order from addon.db
  69.             order[i] = itemList[link] -- and save them into a tmporary table
  70.          end
  71.          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.)
  72.       end
  73.    end
  74.  
  75. end
  76.  
  77. local function LoadItem(item) -- Get the links for all the saved itemIDs
  78.    if item then
  79.       itemList[item:GetItemID()] = item:GetItemLink()
  80.    end
  81.    local key = next(itemList, item and item.Next or nil)
  82.    if not key then -- when we have all the links for all the items
  83.       FormatTexts() -- Run FormatTexts() to do the text replacements
  84.       return
  85.    end
  86.    local nextItem = Item:CreateFromItemID(key)
  87.    nextItem.Next = key
  88.    nextItem:ContinueOnItemLoad(function() LoadItem(nextItem) end)
  89. end
  90. LoadItem()
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-24-24 at 02:21 PM.
  Reply With Quote
02-24-24, 10:21 PM   #34
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Fizzlemizz View Post
Probably best to make separate threads for each question as the code is getting pretty messy even for just one (hopefully Xrystal has answered your timer question).

Having multiple item links and locales in your addon.db texts complicates things because the order you want the links to display might be different in german to the order displayed in french and might be different again for english.

This requires identifying the order each link needs to be in for every locale text. With that in mind, the structure of addon.db needs to change so this is one way you could do it (my german in non-existant so it didn't even try):

NOTE: the number if items in each itemOrder should be the same as the number of %s tokens that are in the corresponding text field.
(This is probably overkill as it's replacing all the locale texts and you probably only need the ones that will be actually be used but that depends on what the end addon requires so...)

Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.         name = {
  5.             enUS = "Herb-Infused Water",
  6.             deDE = "Mit Kräutern aromatisiertes Wasser"
  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 = "Emerald Mark of Mastery",
  33.         questID = 75624,
  34.         icon = "interface/icons/inv_mushroom_11",
  35.         announce = {
  36.             enUS = { -- the text to display for english
  37.                 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",
  38.                 itemOrder = { -- the order to display the items in english
  39.                     20897,
  40.                 },
  41.             },
  42.             deDE = { -- the text to display for german
  43.                 text = "Only one %s in this entry",
  44.                 itemOrder = { -- the order to display the items in german
  45.                     20897,
  46.                 },
  47.             },
  48.         }
  49.     },
  50. }
  51. ---------------------------------------------------------------------------------------------------
  52. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  53.  
  54. local itemList = {} -- table to save the itsmID to
  55.  
  56. for index, v in ipairs(addon.db) do -- get/save every itmeID in addon.db announce
  57.    for k, itemID in pairs(v.announce.enUS.itemOrder) do -- assumes all announce entries will use all the same itemIDs
  58.       if not itemList[itemID] then
  59.          itemList[itemID] = true
  60.       end
  61.    end
  62. end
  63.  
  64. local function FormatTexts() -- fill addon.db with the item links
  65.    for index, v in ipairs(addon.db) do
  66.       for locale, settings in pairs(v.announce) do
  67.          local order = {}  
  68.          for i, link in ipairs(settings.itemOrder) do -- get the links in order from addon.db
  69.             order[i] = itemList[link] -- and save them into a tmporary table
  70.          end
  71.          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.)
  72.       end
  73.    end
  74.  
  75. end
  76.  
  77. local function LoadItem(item) -- Get the links for all the saved itemIDs
  78.    if item then
  79.       itemList[item:GetItemID()] = item:GetItemLink()
  80.    end
  81.    local key = next(itemList, item and item.Next or nil)
  82.    if not key then -- when we have all the links for all the items
  83.       FormatTexts() -- Run FormatTexts() to do the text replacements
  84.       return
  85.    end
  86.    local nextItem = Item:CreateFromItemID(key)
  87.    nextItem.Next = key
  88.    nextItem:ContinueOnItemLoad(function() LoadItem(nextItem) end)
  89. end
  90. LoadItem()
Hello thank you very much. After this, the table call button stopped working.

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] or item.announce.enUS -- default to enUS if the locale text doesn't exist.
  24.         tinsert(data, {announceText, item.icon, item.name})
  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("LEFT", (0) * CELL_WIDTH, 0)
  68.  
  69.             button.columns[2] = button:CreateTexture()
  70.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  71.  
  72.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  73.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  74.  
  75.             content.rows[i] = button
  76.         end
  77.  
  78.         content.rows[i].columns[1]:SetText(data[i][1])
  79.         content.rows[i].columns[2]:SetTexture(data[i][2])
  80.         content.rows[i].columns[3]:SetText(data[i][3])
  81.  
  82.         content.rows[i]:Show()
  83.     end
  84.  
  85.     for i = #data + 1, #content.rows do
  86.         content.rows[i]:Hide()
  87.     end
  88. end
  89.  
  90.  
  91. -- Set your button options here
  92. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  93. btn:SetPoint("CENTER")
  94. btn:SetSize(100, 40)
  95. btn:SetText("Rewards")
  96. btn:SetMovable(true)
  97. btn:RegisterForDrag('LeftButton')
  98. btn:RegisterForClicks("AnyDown", "AnyUp")
  99. btn:SetUserPlaced(true)
  100. btn:SetScript('OnDragStart', function(self, button, down)
  101.     if button == "LeftButton" and IsShiftKeyDown() then
  102.         self:StartMoving()
  103.     end
  104. end)
  105. btn:SetScript('OnDragStop', function(self)
  106.     self:StopMovingOrSizing()
  107. end)
  108. btn:SetScript("OnMouseUp", function(self, button, ...)
  109.     if (button == "RightButton" and self:IsVisible()) then
  110.         self:Hide()
  111.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  112.         updateData()
  113.         updateList()
  114.         f:Show()
  115.     end
  116. end)
  117.  
  118. SLASH_HUBB1 = "/hubb"
  119. SlashCmdList["HUBB"] = function(msg)
  120.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  121.         btn:SetShown(not btn:IsShown()) -- show the button
  122.         return
  123.     end
  124.     updateData()
  125.     updateList()
  126.     f:Show()
  127. end
  Reply With Quote
02-25-24, 12:16 AM   #35
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
At some point along the line the addon .db table go messed up and the name field in the first first entry became a table instead of a string.

The 2 files

data (addon.db)
Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.         name = "Emerald Mark of Mastery",
  5.         questID = 75612,
  6.         icon = "interface/icons/inv_mushroom_11",
  7.         announce = {
  8.              enUS = { -- the text to display for english
  9.                  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",
  10.                  itemOrder = { -- the order to display the items in english
  11.                      210399,
  12.                      210400,
  13.                      210401,
  14.                      210402,
  15.                  },
  16.              },
  17.              deDE = { -- the text to display for german
  18.                  text = "The items %s might be %s in a different %s order of items %s in german",
  19.                  itemOrder = { -- the order to display the items in german
  20.                      210401,
  21.                      210402,
  22.                      210399,
  23.                      210400,
  24.                  },
  25.              },
  26.         },
  27.     },
  28.     {
  29.         name = "Emerald Mark of Mastery",
  30.         questID = 75624,
  31.         icon = "interface/icons/inv_mushroom_11",
  32.         announce = {
  33.             enUS = { -- the text to display for english
  34.                 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",
  35.                 itemOrder = { -- the order to display the items in english
  36.                     20897,
  37.                 },
  38.             },
  39.             deDE = { -- the text to display for german
  40.                 text = "Only one %s in this entry",
  41.                 itemOrder = { -- the order to display the items in german
  42.                     20897,
  43.                 },
  44.             },
  45.         }
  46.     },
  47. }
  48. ---------------------------------------------------------------------------------------------------
  49. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  50.  
  51. local itemList = {} -- table to save the itsmID to
  52.  
  53. for index, v in ipairs(addon.db) do -- get/save every itmeID in addon.db announce
  54.    for k, itemID in pairs(v.announce.enUS.itemOrder) do -- assumes all announce entries will use all the same itemIDs
  55.       if not itemList[itemID] then
  56.          itemList[itemID] = true
  57.       end
  58.    end
  59. end
  60.  
  61. local function FormatTexts() -- fill addon.db with the item links
  62.    for index, v in ipairs(addon.db) do
  63.       for locale, settings in pairs(v.announce) do
  64.          local order = {}  
  65.          for i, link in ipairs(settings.itemOrder) do -- get the links in order from addon.db
  66.             order[i] = itemList[link] -- and save them into a tmporary table
  67.          end
  68.          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.)
  69.       end
  70.    end
  71.  
  72. end
  73.  
  74. local function LoadItem(item) -- Get the links for all the saved itemIDs
  75.    if item then
  76.       itemList[item:GetItemID()] = item:GetItemLink()
  77.    end
  78.    local key = next(itemList, item and item.Next or nil)
  79.    if not key then -- when we have all the links for all the items
  80.       FormatTexts() -- Run FormatTexts() to do the text replacements
  81.       return
  82.    end
  83.    local nextItem = Item:CreateFromItemID(key)
  84.    nextItem.Next = key
  85.    nextItem:ContinueOnItemLoad(function() LoadItem(nextItem) end)
  86. end
  87. LoadItem()

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

Last edited by Fizzlemizz : 02-25-24 at 12:21 AM.
  Reply With Quote
02-25-24, 12:27 AM   #36
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Yes it works. Thank you very much. And the last question (with your help I have already figured out a lot)
I replaced
Lua Code:
  1. name = "Emerald Mark of Mastery",
on
Lua Code:
  1. name = {
  2.             enUS = "Herb-Infused Water",
  3.             deDE = "Mit Kräutern aromatisiertes Wasser"
  4.         },
and the button stopped working =(
  Reply With Quote
02-25-24, 12:52 AM   #37
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
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: 111
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
02-25-24, 01:19 AM   #39
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Missing commas, mayube this time.

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. }
  54.     ---------------------------------------------------------------------------------------------------
  55. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  56.  
  57. local itemList = {} -- table to save the itsmID to
  58.  
  59. for index, v in ipairs(addon.db) do -- get/save every itmeID in addon.db announce
  60.    for k, itemID in pairs(v.announce.enUS.itemOrder) do -- assumes all announce entries will use all the same itemIDs
  61.       if not itemList[itemID] then
  62.          itemList[itemID] = true
  63.       end
  64.    end
  65. end
  66.  
  67. local function FormatTexts() -- fill addon.db with the item links
  68.    for index, v in ipairs(addon.db) do
  69.       for locale, settings in pairs(v.announce) do
  70.          local order = {}  
  71.          for i, link in ipairs(settings.itemOrder) do -- get the links in order from addon.db
  72.             order[i] = itemList[link] -- and save them into a tmporary table
  73.          end
  74.          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.)
  75.       end
  76.    end
  77.  
  78. end
  79.  
  80. local function LoadItem(item) -- Get the links for all the saved itemIDs
  81.    if item then
  82.       itemList[item:GetItemID()] = item:GetItemLink()
  83.    end
  84.    local key = next(itemList, item and item.Next or nil)
  85.    if not key then -- when we have all the links for all the items
  86.       FormatTexts() -- Run FormatTexts() to do the text replacements
  87.       return
  88.    end
  89.    local nextItem = Item:CreateFromItemID(key)
  90.    nextItem.Next = key
  91.    nextItem:ContinueOnItemLoad(function() LoadItem(nextItem) end)
  92. end
  93. LoadItem()

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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-25-24, 01:29 AM   #40
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 111
Originally Posted by Fizzlemizz View Post
Missing commas, mayube this time.

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. }
  54.     ---------------------------------------------------------------------------------------------------
  55. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  56.  
  57. local itemList = {} -- table to save the itsmID to
  58.  
  59. for index, v in ipairs(addon.db) do -- get/save every itmeID in addon.db announce
  60.    for k, itemID in pairs(v.announce.enUS.itemOrder) do -- assumes all announce entries will use all the same itemIDs
  61.       if not itemList[itemID] then
  62.          itemList[itemID] = true
  63.       end
  64.    end
  65. end
  66.  
  67. local function FormatTexts() -- fill addon.db with the item links
  68.    for index, v in ipairs(addon.db) do
  69.       for locale, settings in pairs(v.announce) do
  70.          local order = {}  
  71.          for i, link in ipairs(settings.itemOrder) do -- get the links in order from addon.db
  72.             order[i] = itemList[link] -- and save them into a tmporary table
  73.          end
  74.          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.)
  75.       end
  76.    end
  77.  
  78. end
  79.  
  80. local function LoadItem(item) -- Get the links for all the saved itemIDs
  81.    if item then
  82.       itemList[item:GetItemID()] = item:GetItemLink()
  83.    end
  84.    local key = next(itemList, item and item.Next or nil)
  85.    if not key then -- when we have all the links for all the items
  86.       FormatTexts() -- Run FormatTexts() to do the text replacements
  87.       return
  88.    end
  89.    local nextItem = Item:CreateFromItemID(key)
  90.    nextItem.Next = key
  91.    nextItem:ContinueOnItemLoad(function() LoadItem(nextItem) end)
  92. end
  93. LoadItem()

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
It also didn't work. The button is not pressed.


Lua Code:
  1. 1x ZamTEST/table.lua:78: bad argument #1 to 'SetText' (Usage: self:SetText([text]))
  2. [string "=[C]"]: in function `SetText'
  3. [string "@ZamTEST/table.lua"]:78: in function <ZamTEST/table.lua:52>
  4. [string "@ZamTEST/table.lua"]:113: in function <ZamTEST/table.lua:108>
  5.  
  6. Locals:
  7. (*temporary) = FontString {
  8. 0 = <userdata>
  9. }
  10. (*temporary) = <table> {
  11. itemOrder = <table> {
  12. }
  13. text = "Awarded for %s outstanding service %s to Dragonkind.
  14. %s
  15. Bring it to Theozhaklos the Curious at the Wellspring
  16. Overlook in the Emerald %s Dream to receive powerful
  17. equipment for your efforts"
  18. }
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Save location via SavedVariables


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off