WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Save location via SavedVariables (https://www.wowinterface.com/forums/showthread.php?t=59800)

Hubb777 02-19-24 10:32 PM

Save location via SavedVariables
 
Code
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData()
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  18.     end
  19. end
  20.  
  21. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  22. f:SetPoint("CENTER")
  23. f:Hide()
  24. f:SetMovable(true)
  25. f:SetScript("OnMouseDown", f.StartMoving)
  26. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  27.  
  28. -- I added this OnHide script
  29. f:SetScript("OnHide", function()
  30.     btn:Show()
  31. end)
  32.  
  33. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  34. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  35. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  36.  
  37. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  38. f.scrollFrame.scrollChild:SetSize(100, 100)
  39. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  40. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  41.  
  42. local content = f.scrollFrame.scrollChild
  43. content.rows = {}
  44.  
  45. local function updateList()
  46.     for i = 1, #data do
  47.         if not content.rows[i] then
  48.             local button = CreateFrame("Button", nil, content)
  49.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  50.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  51.             button.columns = {}
  52.  
  53.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  54.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  55.  
  56.             button.columns[2] = button:CreateTexture()
  57.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  58.  
  59.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  60.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  61.  
  62.             content.rows[i] = button
  63.         end
  64.  
  65.         content.rows[i].columns[1]:SetText(data[i][1])
  66.         content.rows[i].columns[2]:SetTexture(data[i][2])
  67.         content.rows[i].columns[3]:SetText(data[i][3])
  68.  
  69.         content.rows[i]:Show()
  70.     end
  71.  
  72.     for i = #data + 1, #content.rows do
  73.         content.rows[i]:Hide()
  74.     end
  75. end
  76.  
  77.  
  78. -- Set your button options here
  79.  
  80. btn:SetPoint("CENTER")
  81. btn:SetSize(100, 40)
  82. btn:SetText("Click me")
  83. btn:SetScript("OnClick", function(self, button, ...)
  84. btn:SetMovable(true)
  85. btn:RegisterForDrag('LeftButton')
  86. btn:SetScript('OnDragStart', btn.StartMoving)
  87. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  88.     if (button == "RightButton" and btn:IsVisible()) then
  89.         btn:Hide()
  90.     end
  91.  
  92.     updateData()
  93.     updateList()
  94.     f:Show()
  95. end)
  96. btn:RegisterForClicks("AnyUp")
  97.  
  98. SLASH_HUBB1 = "/hubb"
  99. SlashCmdList["HUBB"] = function(msg)
  100.     updateData()
  101.     updateList()
  102.     f:Show()
  103. end

A separate code is just a button

Lua Code:
  1. btn:SetPoint("CENTER")
  2. btn:SetSize(100, 40)
  3. btn:SetText("Click me")
  4. btn:SetScript("OnClick", function(self, button, ...)
  5. btn:SetMovable(true)
  6. btn:RegisterForDrag('LeftButton')
  7. btn:SetScript('OnDragStart', btn.StartMoving)
  8. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  9.     if (button == "RightButton" and btn:IsVisible()) then
  10.         btn:Hide()
  11.     end
  12.  
  13.     updateData()
  14.     updateList()
  15.     f:Show()
  16. end)
  17. btn:RegisterForClicks("AnyUp")

At the moment, the button returns to the center when using the command /reload

Did I redo it correctly?
Lua Code:
  1. btn:RegisterEvent("ADDON_LOADED")
  2. btn:RegisterEvent("PLAYER_LOGOUT")
  3. btn:SetScript("OnEvent", function(self, event, arg1)
  4.     if event == "ADDON_LOADED" and arg1 == "HaveWeMet" then
  5. end
  6. btn:SetPoint("CENTER")
  7. btn:SetSize(100, 40)
  8. btn:SetText("Click me")
  9. btn:SetScript("OnClick", function(self, button, ...)
  10. btn:SetMovable(true)
  11. btn:RegisterForDrag('LeftButton')
  12. btn:SetScript('OnDragStart', btn.StartMoving)
  13. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  14.     if (button == "RightButton" and btn:IsVisible()) then
  15.         btn:Hide()
  16.     end
  17.  
  18.     updateData()
  19.     updateList()
  20.     f:Show()
  21. end)
  22. btn:RegisterForClicks("AnyUp")

Fizzlemizz 02-19-24 10:40 PM

Blizz. will save the frame but if the user removes the addon for any reason, it will reset to the default location if they decide to install the addon again.
Lua Code:
  1. btn:SetPoint("CENTER")
  2. btn:SetSize(100, 40)
  3. btn:SetText("Click me")
  4. btn:SetScript("OnClick", function(self, button, ...)
  5. btn:SetMovable(true)
  6. btn:RegisterForDrag('LeftButton')
  7. btn:SetUserPlaced(true) -- Only works if the frame is created before the PLAYER_LOGIN event

Hubb777 02-19-24 10:51 PM

Quote:

Originally Posted by Fizzlemizz (Post 343369)
Blizz. will save the frame but if the user removes the addon for any reason, it will reset to the default location if they decide to install the addon again.
Lua Code:
  1. btn:SetPoint("CENTER")
  2. btn:SetSize(100, 40)
  3. btn:SetText("Click me")
  4. btn:SetScript("OnClick", function(self, button, ...)
  5. btn:SetMovable(true)
  6. btn:RegisterForDrag('LeftButton')
  7. btn:SetUserPlaced(true) -- Only works if the frame is created before the PLAYER_LOGIN event

after the /reload command, the button returns to its place. It doesn't work

Fizzlemizz 02-20-24 12:04 AM

I missed the CreateFrame code for btn in the original post

For Blizz to save the position, the frame has to have a unique name.
Lua Code:
  1. local btn = CreateFrame("Button", addonName.."MovingButton", UIParent, "UIPanelButtonTemplate")

Hubb777 02-20-24 12:31 AM

Quote:

Originally Posted by Fizzlemizz (Post 343371)
I missed the CreateFrame code for btn in the original post

For Blizz to save the position, the frame has to have a unique name.
Lua Code:
  1. local btn = CreateFrame("Button", addonName.."MovingButton", UIParent, "UIPanelButtonTemplate")

And it didn't work again. The button after /reload returned to the center

Lua Code:
  1. local btn = CreateFrame("Button", addonName.."MovingButton", UIParent, "UIPanelButtonTemplate")
  2. btn:SetPoint("CENTER")
  3. btn:SetSize(100, 40)
  4. btn:SetText("Click me")
  5. btn:SetScript("OnClick", function(self, button, ...)
  6. btn:SetMovable(true)
  7. btn:RegisterForDrag('LeftButton')
  8. btn:SetUserPlaced(true) -- Only works if the frame is created before the PLAYER_LOGIN event
  9. btn:SetScript('OnDragStart', btn.StartMoving)
  10. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  11.     if (button == "RightButton" and btn:IsVisible()) then
  12.         btn:Hide()
  13.     end
  14.  
  15.     updateData()
  16.     updateList()
  17.     f:Show()
  18. end)
  19. btn:RegisterForClicks("AnyUp")

Fizzlemizz 02-20-24 01:05 AM

I have no idea what code you're testing so, as a standalone example of a button that can be dragged and saved.

Lua Code:
  1. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  2. btn:SetPoint("CENTER")
  3. btn:SetSize(100, 40)
  4. btn:SetText("Click me")
  5. btn:SetScript("OnClick", function(self, button, ...) print("I've been clicked!") end)
  6. btn:SetMovable(true)
  7. btn:RegisterForDrag('LeftButton')
  8. btn:SetUserPlaced(true) -- Only works if the frame is created before the PLAYER_LOGIN event
  9. btn:SetScript('OnDragStart', btn.StartMoving)
  10. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  11. btn:RegisterForClicks("AnyUp")

You will have to move the pieces into your addon. Possibly just the btn:SetUserPlaced(true) and giving the button a name.

Hubb777 02-20-24 03:37 AM

Quote:

Originally Posted by Fizzlemizz (Post 343373)
I have no idea what code you're testing so, as a standalone example of a button that can be dragged and saved.

Lua Code:
  1. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  2. btn:SetPoint("CENTER")
  3. btn:SetSize(100, 40)
  4. btn:SetText("Click me")
  5. btn:SetScript("OnClick", function(self, button, ...) print("I've been clicked!") end)
  6. btn:SetMovable(true)
  7. btn:RegisterForDrag('LeftButton')
  8. btn:SetUserPlaced(true) -- Only works if the frame is created before the PLAYER_LOGIN event
  9. btn:SetScript('OnDragStart', btn.StartMoving)
  10. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  11. btn:RegisterForClicks("AnyUp")

You will have to move the pieces into your addon. Possibly just the btn:SetUserPlaced(true) and giving the button a name.

I tried to do this, but in the end the button disappeared from the screen. Below is the full code

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData()
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  18.     end
  19. end
  20.  
  21. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  22. f:SetPoint("CENTER")
  23. f:Hide()
  24. f:SetMovable(true)
  25. f:SetScript("OnMouseDown", f.StartMoving)
  26. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  27.  
  28. -- I added this OnHide script
  29. f:SetScript("OnHide", function()
  30.     btn:Show()
  31. end)
  32.  
  33. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  34. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  35. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  36.  
  37. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  38. f.scrollFrame.scrollChild:SetSize(100, 100)
  39. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  40. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  41.  
  42. local content = f.scrollFrame.scrollChild
  43. content.rows = {}
  44.  
  45. local function updateList()
  46.     for i = 1, #data do
  47.         if not content.rows[i] then
  48.             local button = CreateFrame("Button", nil, content)
  49.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  50.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  51.             button.columns = {}
  52.  
  53.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  54.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  55.  
  56.             button.columns[2] = button:CreateTexture()
  57.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  58.  
  59.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  60.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  61.  
  62.             content.rows[i] = button
  63.         end
  64.  
  65.         content.rows[i].columns[1]:SetText(data[i][1])
  66.         content.rows[i].columns[2]:SetTexture(data[i][2])
  67.         content.rows[i].columns[3]:SetText(data[i][3])
  68.  
  69.         content.rows[i]:Show()
  70.     end
  71.  
  72.     for i = #data + 1, #content.rows do
  73.         content.rows[i]:Hide()
  74.     end
  75. end
  76.  
  77.  
  78. -- Set your button options here
  79. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  80. btn:SetPoint("CENTER")
  81. btn:SetSize(100, 40)
  82. btn:SetText("Click me")
  83. btn:SetScript("OnClick", function(self, button, ...)
  84. btn:SetMovable(true)
  85. btn:RegisterForDrag('LeftButton')
  86. btn:SetUserPlaced(true)
  87. btn:SetScript('OnDragStart', btn.StartMoving)
  88. btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
  89.     if (button == "RightButton" and btn:IsVisible()) then
  90.         btn:Hide()
  91.     end
  92.  
  93.     updateData()
  94.     updateList()
  95.     f:Show()
  96. end)
  97. btn:RegisterForClicks("AnyUp")
  98.  
  99. SLASH_HUBB1 = "/hubb"
  100. SlashCmdList["HUBB"] = function(msg)
  101.     updateData()
  102.     updateList()
  103.     f:Show()
  104. end

Fizzlemizz 02-20-24 08:53 AM

Some of that code is completely broken so I assumed you were posting example code and would make changes to the real code. You should be getting errors from BugGrabber/Bugsack . Install them if you haven't yet.

Code:

btn:SetScript("OnClick:, function(self, button, ...)
Is an unfinished script handler, no end) .

Whereas
Code:

btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
Is finished but then the next few lines look like they are supposed to be part of the OnDragStop script but end up being incomplete (it has an end with no function(...) to start the block and a ) after the end with no SetScript to start the bracket pair.

Here is the code with a print to fill in the OnClick, a fix that may or may not be what you intend for the OnDragStop script and I commented out the updateData() because addon.db isn't created in the code shown. Add it back if it is in another .lua file but the code as is should at least work for demonstrating the SetUserPlaced() saving the button position.
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  18.     end
  19. end
  20.  
  21. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  22. f:SetPoint("CENTER")
  23. f:Hide()
  24. f:SetMovable(true)
  25. f:SetScript("OnMouseDown", f.StartMoving)
  26. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  27.  
  28. -- I added this OnHide script
  29. f:SetScript("OnHide", function()
  30.     btn:Show()
  31. end)
  32.  
  33. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  34. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  35. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  36.  
  37. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  38. f.scrollFrame.scrollChild:SetSize(100, 100)
  39. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  40. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  41.  
  42. local content = f.scrollFrame.scrollChild
  43. content.rows = {}
  44.  
  45. local function updateList()
  46.     for i = 1, #data do
  47.         if not content.rows[i] then
  48.             local button = CreateFrame("Button", nil, content)
  49.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  50.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  51.             button.columns = {}
  52.  
  53.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  54.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  55.  
  56.             button.columns[2] = button:CreateTexture()
  57.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  58.  
  59.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  60.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  61.  
  62.             content.rows[i] = button
  63.         end
  64.  
  65.         content.rows[i].columns[1]:SetText(data[i][1])
  66.         content.rows[i].columns[2]:SetTexture(data[i][2])
  67.         content.rows[i].columns[3]:SetText(data[i][3])
  68.  
  69.         content.rows[i]:Show()
  70.     end
  71.  
  72.     for i = #data + 1, #content.rows do
  73.         content.rows[i]:Hide()
  74.     end
  75. end
  76.  
  77.  
  78. -- Set your button options here
  79. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  80. btn:SetPoint("CENTER")
  81. btn:SetSize(100, 40)
  82. btn:SetText("Click me")
  83. btn:SetScript("OnClick", function(self, button, ...) print("Hi!") end)
  84.  
  85. btn:SetMovable(true)
  86. btn:RegisterForDrag('LeftButton')
  87. btn:SetUserPlaced(true)
  88. btn:SetScript('OnDragStart', btn.StartMoving)
  89. btn:SetScript('OnDragStop', function(self)
  90.     self:StopMovingOrSizing()
  91.     if (button == "RightButton" and self:IsVisible()) then
  92.         self:Hide()
  93.     end
  94.  
  95. --      updateData()  --commented out because addon.db hasn't been created... in the code at least
  96.     updateList()
  97.     f:Show()
  98. end)
  99. btn:RegisterForClicks("AnyUp")
  100.  
  101. SLASH_HUBB1 = "/hubb"
  102. SlashCmdList["HUBB"] = function(msg)
  103.     updateData()
  104.     updateList()
  105.     f:Show()
  106. end

Hubb777 02-20-24 11:41 PM

Quote:

Originally Posted by Fizzlemizz (Post 343378)
Some of that code is completely broken so I assumed you were posting example code and would make changes to the real code. You should be getting errors from BugGrabber/Bugsack . Install them if you haven't yet.

Code:

btn:SetScript("OnClick:, function(self, button, ...)
Is an unfinished script handler, no end) .

Whereas
Code:

btn:SetScript('OnDragStop', btn.StopMovingOrSizing)
Is finished but then the next few lines look like they are supposed to be part of the OnDragStop script but end up being incomplete (it has an end with no function(...) to start the block and a ) after the end with no SetScript to start the bracket pair.

Here is the code with a print to fill in the OnClick, a fix that may or may not be what you intend for the OnDragStop script and I commented out the updateData() because addon.db isn't created in the code shown. Add it back if it is in another .lua file but the code as is should at least work for demonstrating the SetUserPlaced() saving the button position.

Just like I said before. I took your other advice (in another forum thread), but since my knowledge of LUA is low, I probably didn't copy everything.

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  18.     end
  19. end
  20.  
  21. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  22. f:SetPoint("CENTER")
  23. f:Hide()
  24. f:SetMovable(true)
  25. f:SetScript("OnMouseDown", f.StartMoving)
  26. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  27.  
  28. -- I added this OnHide script
  29. f:SetScript("OnHide", function()
  30.     btn:Show()
  31. end)
  32.  
  33. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  34. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  35. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  36.  
  37. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  38. f.scrollFrame.scrollChild:SetSize(100, 100)
  39. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  40. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  41.  
  42. local content = f.scrollFrame.scrollChild
  43. content.rows = {}
  44.  
  45. local function updateList()
  46.     for i = 1, #data do
  47.         if not content.rows[i] then
  48.             local button = CreateFrame("Button", nil, content)
  49.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  50.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  51.             button.columns = {}
  52.  
  53.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  54.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  55.  
  56.             button.columns[2] = button:CreateTexture()
  57.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  58.  
  59.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  60.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  61.  
  62.             content.rows[i] = button
  63.         end
  64.  
  65.         content.rows[i].columns[1]:SetText(data[i][1])
  66.         content.rows[i].columns[2]:SetTexture(data[i][2])
  67.         content.rows[i].columns[3]:SetText(data[i][3])
  68.  
  69.         content.rows[i]:Show()
  70.     end
  71.  
  72.     for i = #data + 1, #content.rows do
  73.         content.rows[i]:Hide()
  74.     end
  75. end
  76.  
  77.  
  78. -- Set your button options here
  79. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  80. btn:SetPoint("CENTER")
  81. btn:SetSize(100, 40)
  82. btn:SetText("Click me")
  83. btn:SetScript("OnClick", function(self, button, ...)end)
  84.  
  85. btn:SetMovable(true)
  86. btn:RegisterForDrag('LeftButton')
  87. btn:SetUserPlaced(true)
  88. btn:SetScript('OnDragStart', btn.StartMoving)
  89. btn:SetScript('OnDragStop', function(self)
  90.     self:StopMovingOrSizing()
  91.     if (button == "RightButton" and self:IsVisible()) then
  92.         self:Hide()
  93.     end
  94.  
  95.     updateData()
  96.     updateList()
  97.     f:Show()
  98. end)
  99. btn:RegisterForClicks("AnyUp")
  100.  
  101. SLASH_HUBB1 = "/hubb"
  102. SlashCmdList["HUBB"] = function(msg)
  103.     updateData()
  104.     updateList()
  105.     f:Show()
  106. end

This code almost works. It saves the position of the button
But the button does not display the table if I press the left mouse button. But if I press the left mouse button and shift and try to move the button, the table window turns on. What could be the problem?

Fizzlemizz 02-21-24 12:31 AM

Programs are stupid. You have to tell them exactly what you want. Maybe something like: (Left buton down, shift-key down = drag. right button = hide button. left button no shift-key toggle show/hide the frame (f))

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  18.     end
  19. end
  20.  
  21. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  22. f:SetPoint("CENTER")
  23. f:Hide()
  24. f:SetMovable(true)
  25. f:SetScript("OnMouseDown", f.StartMoving)
  26. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  27.  
  28. -- I added this OnHide script
  29. f:SetScript("OnHide", function()
  30.     btn:Show()
  31. end)
  32.  
  33. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  34. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  35. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  36.  
  37. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  38. f.scrollFrame.scrollChild:SetSize(100, 100)
  39. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  40. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  41.  
  42. local content = f.scrollFrame.scrollChild
  43. content.rows = {}
  44.  
  45. local function updateList()
  46.     for i = 1, #data do
  47.         if not content.rows[i] then
  48.             local button = CreateFrame("Button", nil, content)
  49.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  50.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  51.             button.columns = {}
  52.  
  53.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  54.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  55.  
  56.             button.columns[2] = button:CreateTexture()
  57.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  58.  
  59.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  60.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  61.  
  62.             content.rows[i] = button
  63.         end
  64.  
  65.         content.rows[i].columns[1]:SetText(data[i][1])
  66.         content.rows[i].columns[2]:SetTexture(data[i][2])
  67.         content.rows[i].columns[3]:SetText(data[i][3])
  68.  
  69.         content.rows[i]:Show()
  70.     end
  71.  
  72.     for i = #data + 1, #content.rows do
  73.         content.rows[i]:Hide()
  74.     end
  75. end
  76.  
  77.  
  78. -- Set your button options here
  79. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  80. btn:SetPoint("CENTER")
  81. btn:SetSize(100, 40)
  82. btn:SetText("Click me")
  83. btn:SetMovable(true)
  84. btn:RegisterForDrag('LeftButton')
  85. btn:RegisterForClicks("AnyDown", "AnyUp")
  86. btn:SetUserPlaced(true)
  87. btn:SetScript('OnDragStart', function(self, button, down)
  88.     if button == "LeftButton" and IsShiftKeyDown() then
  89.         self:StartMoving()
  90.     end
  91. end)
  92. btn:SetScript('OnDragStop', function(self)
  93.     self:StopMovingOrSizing()
  94. end)
  95. btn:SetScript("OnMouseUp", function(self, button, ...)
  96.     if (button == "RightButton" and self:IsVisible()) then
  97.         self:Hide()
  98.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  99.         updateData()
  100.         updateList()
  101.         f:Show()
  102.     end
  103. end)
  104.  
  105. SLASH_HUBB1 = "/hubb"
  106. SlashCmdList["HUBB"] = function(msg)
  107.     updateData()
  108.     updateList()
  109.     f:Show()
  110. end

You possibly want a way to get the button back after it's hidden other than a /reaload but may not, it's not clear?

Hubb777 02-21-24 12:42 AM

Yes, it worked. The code works completely as intended. Thank you very much. I couldn't have done it without you.
Quote:

Originally Posted by Fizzlemizz (Post 343387)
You possibly want a way to get the button back after it's hidden other than a /reaload but may not, it's not clear?

And how to do it?

If I solve the problem - how do I insert a link to an item in the text that is in the table, I will be able to make my first addon.
https://www.wowinterface.com/forums/...ad.php?t=59796

Fizzlemizz 02-21-24 10:26 AM

I've created this as an all-in-one example including an example addon.db where I've replaced the item name, icon and added the link for some random items (got rid of the icon texture in the frame as it's in the text, but but it's up to you how you organise the stuff).

Added two %s to each enUS string which gets replaced by the icon (size set to 20x20) and hyperlink when the text is set.

Again, Example Code so, how you get/display the information for your addon will depend on the what/when of the addons workings.

Added a check in the slash command so if you type /hubb btn it will toggle the button

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. -- name and icon (and link) set by LoadItem() when the item is cached.
  8. addon.db = {
  9.     {
  10. --        name = "Emerald Mark of Mastery",
  11.         questID = 75612,
  12. --        icon = "interface/icons/inv_mushroom_11",
  13.         item = 6218,
  14.         announce = {
  15.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  16.         }
  17.     },
  18.     {
  19. --        name = "Emerald Mark of Mastery",
  20.         questID = 75624,
  21. --        icon = "interface/icons/inv_mushroom_11",
  22.         item = 20897,
  23.         announce = {
  24.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts\n\nAwarded for outstanding service to (clickable link to the item) Dragonkind. Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  25.         }
  26.     },
  27.     {
  28. --        name = "Emerald Mark of Mastery",
  29.         questID = 74352,
  30.         item = 193440,
  31. --        icon = "interface/icons/inv_mushroom_11",
  32.         announce = {
  33.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  34.         }
  35.     }
  36. }
  37.  
  38. local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- function to print the link when clicked
  39.     print("You just clickled:", text)
  40. end
  41.  
  42. local function OnHyperlinkEnter(self, link, text, region, left, bottom, width, height) -- function to display the hyperlink on mouse over
  43.     GameTooltip:SetOwner(self, "ANCHOR_CURSOR_RIGHT")
  44.     GameTooltip:SetHyperlink(link)
  45.     GameTooltip:Show()
  46. end
  47.  
  48. local function OnHyperlinkLeave(self) -- function to hide the hyperlink on mouse exit
  49.     GameTooltip:Hide()
  50. end
  51.  
  52. local function LoadItem(item) -- adds the item to the bd overwriting the icon, name ans sedtting the itemlink keys
  53.     addon.db[item.dbID].name = item:GetItemName()
  54.     addon.db[item.dbID].icon = "|T"..item:GetItemIcon()..":20:20|t" -- make icon size 20x20
  55.     addon.db[item.dbID].itemlink = item:GetItemLink()
  56.  
  57.  
  58. print(addon.db[item.dbID].name, addon.db[item.dbID].icon, addon.db[item.dbID].itemlink)
  59.  
  60. end
  61.  
  62. for i, v in ipairs(addon.db) do -- Get the item information and call LoadItem when it's returned from the server and cached
  63.     local item = Item:CreateFromItemID(v.item)
  64.     item.dbID = i
  65.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  66. end
  67.  
  68. local data = {}
  69.  
  70. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  71. f.Title = f:CreateFontString()
  72. f.Title:SetFontObject(GameFontNormal)
  73. f.Title:SetPoint("TOP", 0, -5)
  74. f.Title:SetText(addonName)
  75. -- Create the button here
  76. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  77.  
  78. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  79.     wipe(data)
  80.     for _, item in ipairs(addon.db) do
  81.         tinsert(data, {text=item.announce[GetLocale()], icon=item.icon, name=item.name, link=item.itemlink})
  82.     end
  83. end
  84.  
  85. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  86. f:SetPoint("CENTER")
  87. f:Hide()
  88. f:SetMovable(true)
  89. f:SetScript("OnMouseDown", f.StartMoving)
  90. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  91.  
  92.  
  93. -- I added this OnHide script
  94. f:SetScript("OnHide", function()
  95.     btn:Show()
  96. end)
  97.  
  98. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  99. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  100. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  101.  
  102. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  103. f.scrollFrame.scrollChild:SetSize(100, 100)
  104. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  105. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  106.  
  107. local content = f.scrollFrame.scrollChild
  108. content.rows = {}
  109.  
  110. local function updateList()
  111.     for i = 1, #data do
  112.         if not content.rows[i] then
  113.             local button = CreateFrame("Button", nil, content)
  114.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  115.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  116.             button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row
  117.             button:SetScript("OnHyperlinkClick", OnHyperlinkClick)
  118.             button:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)
  119.             button:SetScript("OnHyperlinkLeave", OnHyperlinkLeave)
  120.            
  121.             button.columns = {}
  122.  
  123.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  124.             button.columns[1]:SetJustifyH("LEFT")
  125.             button.columns[1]:SetJustifyV("TOP")
  126. --            button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  127.             button.columns[1]:SetPoint("TOPLEFT")
  128.             button.columns[1]:SetPoint("BOTTOMRIGHT", button, "BOTTOMLEFT", 140, 0)
  129.  
  130. -- Replaced the icon texture with the icon embedded in the description string.
  131. --            button.columns[2] = button:CreateTexture()
  132. --            button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  133. --            button.columns[2]:SetPoint("LEFT", button.columns[1], "RIGHT")
  134.  
  135.             button.columns[2] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  136.             button.columns[2]:SetJustifyH("LEFT")
  137.             button.columns[2]:SetJustifyV("TOP")
  138. --            button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  139.             button.columns[2]:SetPoint("TOPLEFT", button.columns[1], "TOPRIGHT", 5, 0)
  140.             button.columns[2]:SetPoint("BOTTOMRIGHT", button)
  141.  
  142.             content.rows[i] = button
  143.         end
  144.  
  145.         content.rows[i].columns[1]:SetText(data[i].name)
  146. --        content.rows[i].columns[2]:SetTexture(data[i][2])
  147.         content.rows[i].columns[2]:SetText(format(data[i].text, data[i].icon, data[i].link)) -- insert the icon and hyperlink into the text
  148.  
  149.         content.rows[i]:Show()
  150.     end
  151.  
  152.     for i = #data + 1, #content.rows do
  153.         content.rows[i]:Hide()
  154.     end
  155. end
  156.  
  157.  
  158. -- Set your button options here
  159. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  160. btn:SetPoint("CENTER")
  161. btn:SetSize(100, 40)
  162. btn:SetText("Click me")
  163. btn:SetMovable(true)
  164. btn:RegisterForDrag('LeftButton')
  165. btn:RegisterForClicks("AnyDown", "AnyUp")
  166. btn:SetUserPlaced(true)
  167. btn:SetScript('OnDragStart', function(self, button, down)
  168.     if button == "LeftButton" and IsShiftKeyDown() then
  169.         self:StartMoving()
  170.     end
  171. end)
  172. btn:SetScript('OnDragStop', function(self)
  173.     self:StopMovingOrSizing()
  174. end)
  175. btn:SetScript("OnMouseUp", function(self, button, ...)
  176.     if (button == "RightButton" and self:IsVisible()) then
  177.         self:Hide()
  178.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  179.         updateData()
  180.         updateList()
  181.         f:Show()
  182.     end
  183. end)
  184.  
  185. SLASH_HUBB1 = "/hubb"
  186. SlashCmdList["HUBB"] = function(msg)
  187.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  188.         btn:SetShown(not btn:IsShown()) -- show the button
  189.         return
  190.     end
  191.     updateData()
  192.     updateList()
  193.     f:Show()
  194. end

Hubb777 02-21-24 11:11 PM

Quote:

Originally Posted by Fizzlemizz (Post 343394)
I've created this as an all-in-one example including an example addon.db where I've replaced the item name, icon and added the link for some random items (got rid of the icon texture in the frame as it's in the text, but but it's up to you how you organise the stuff).

Added two %s to each enUS string which gets replaced by the icon (size set to 20x20) and hyperlink when the text is set.

Again, Example Code so, how you get/display the information for your addon will depend on the what/when of the addons workings.

Added a check in the slash command so if you type /hubb btn it will toggle the button

Hi. I did it a little differently. But for some reason, the button and the slash command stopped being pressed.
table.lua
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {format(item.announce[GetLocale()], GetItemLinkById(id)), item.icon, item.name})
  18.     end
  19. end
  20. local function GetItemLinkById(id)
  21.     local item = Item:CreateFromItemID(id)
  22.     local itemLink = item:GetItemLink()
  23.  
  24.     return itemLink
  25. end
  26. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  27. f:SetPoint("CENTER")
  28. f:Hide()
  29. f:SetMovable(true)
  30. f:SetScript("OnMouseDown", f.StartMoving)
  31. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  32.  
  33. -- I added this OnHide script
  34. f:SetScript("OnHide", function()
  35.     btn:Show()
  36. end)
  37.  
  38. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  39. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  40. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  41.  
  42. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  43. f.scrollFrame.scrollChild:SetSize(100, 100)
  44. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  45. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  46.  
  47. local content = f.scrollFrame.scrollChild
  48. content.rows = {}
  49.  
  50. local function updateList()
  51.     for i = 1, #data do
  52.         if not content.rows[i] then
  53.             local button = CreateFrame("Button", nil, content)
  54.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  55.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  56.             button.columns = {}
  57.  
  58.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  59.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  60.  
  61.             button.columns[2] = button:CreateTexture()
  62.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  63.  
  64.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  65.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  66.  
  67.             content.rows[i] = button
  68.         end
  69.  
  70.         content.rows[i].columns[1]:SetText(data[i][1])
  71.         content.rows[i].columns[2]:SetTexture(data[i][2])
  72.         content.rows[i].columns[3]:SetText(data[i][3])
  73.  
  74.         content.rows[i]:Show()
  75.     end
  76.  
  77.     for i = #data + 1, #content.rows do
  78.         content.rows[i]:Hide()
  79.     end
  80. end
  81.  
  82.  
  83. -- Set your button options here
  84. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  85. btn:SetPoint("CENTER")
  86. btn:SetSize(100, 40)
  87. btn:SetText("Click me")
  88. btn:SetMovable(true)
  89. btn:RegisterForDrag('LeftButton')
  90. btn:RegisterForClicks("AnyDown", "AnyUp")
  91. btn:SetUserPlaced(true)
  92. btn:SetScript('OnDragStart', function(self, button, down)
  93.     if button == "LeftButton" and IsShiftKeyDown() then
  94.         self:StartMoving()
  95.     end
  96. end)
  97. btn:SetScript('OnDragStop', function(self)
  98.     self:StopMovingOrSizing()
  99. end)
  100. btn:SetScript("OnMouseUp", function(self, button, ...)
  101.     if (button == "RightButton" and self:IsVisible()) then
  102.         self:Hide()
  103.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  104.         updateData()
  105.         updateList()
  106.         f:Show()
  107.     end
  108. end)
  109.  
  110. SLASH_HUBB1 = "/hubb"
  111. SlashCmdList["HUBB"] = function(msg)
  112.     updateData()
  113.     updateList()
  114.     f:Show()
  115. end

db.lua
Lua Code:
  1. local addonName, addon = ...
  2. addon.db = {
  3.     {
  4.  name = "Emerald Mark of Mastery",
  5.   icon = "interface/icons/inv_mushroom_11",
  6.   announce = {
  7.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(200106))
  8.         }
  9.     },
  10.     {
  11.  name = "Emerald Mark of Mastery",
  12.   icon = "interface/icons/inv_mushroom_11",
  13.   announce = {
  14.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194730))
  15.         }
  16.     },
  17.     {
  18.  name = "Emerald Mark of Mastery",
  19.   icon = "interface/icons/inv_mushroom_11",
  20.   announce = {
  21.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  22.         }
  23.     },
  24.     {
  25.  name = "Emerald Mark of Mastery",
  26.   icon = "interface/icons/inv_mushroom_11",
  27.   announce = {
  28.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  29.         }
  30.     },
  31.     {
  32.  name = "Emerald Mark of Mastery",
  33.   icon = "interface/icons/inv_mushroom_11",
  34.   announce = {
  35.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  36.         }
  37.     },
  38.     {
  39.  name = "Emerald Mark of Mastery",
  40.   icon = "interface/icons/inv_mushroom_11",
  41.   announce = {
  42.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  43.         }
  44.     },
  45.     {
  46.  name = "Emerald Mark of Mastery",
  47.   icon = "interface/icons/inv_mushroom_11",
  48.   announce = {
  49.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  50.         }
  51.     },
  52.     {
  53.  name = "Emerald Mark of Mastery",
  54.   icon = "interface/icons/inv_mushroom_11",
  55.   announce = {
  56.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  57.         }
  58.     },
  59.     {
  60.  name = "Emerald Mark of Mastery",
  61.   icon = "interface/icons/inv_mushroom_11",
  62.   announce = {
  63.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  64.         }
  65.     },
  66.     {
  67.  name = "Emerald Mark of Mastery",
  68.   icon = "interface/icons/inv_mushroom_11",
  69.   announce = {
  70.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  71.         }
  72.     },
  73.     {
  74.  name = "Emerald Mark of Mastery",
  75.   icon = "interface/icons/inv_mushroom_11",
  76.   announce = {
  77.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  78.         }
  79.     },
  80.     {
  81.  name = "Emerald Mark of Mastery",
  82.   icon = "interface/icons/inv_mushroom_11",
  83.   announce = {
  84.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  85.         }
  86.     },
  87.     {
  88.  name = "Emerald Mark of Mastery",
  89.   icon = "interface/icons/inv_mushroom_11",
  90.   announce = {
  91.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  92.         }
  93.     },
  94.     {
  95.  name = "Emerald Mark of Mastery",
  96.   icon = "interface/icons/inv_mushroom_11",
  97.   announce = {
  98.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  99.         }
  100.     },
  101.     {
  102.  name = "Emerald Mark of Mastery",
  103.   icon = "interface/icons/inv_mushroom_11",
  104.   announce = {
  105.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  106.         }
  107.     },
  108.     {
  109.  name = "Emerald Mark of Mastery",
  110.   icon = "interface/icons/inv_mushroom_11",
  111.   announce = {
  112.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  113.         }
  114.     },
  115.     {
  116.  name = "Emerald Mark of Mastery",
  117.   icon = "interface/icons/inv_mushroom_11",
  118.   announce = {
  119.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  120.         }
  121.     },
  122.     {
  123.  name = "Emerald Mark of Mastery",
  124.   icon = "interface/icons/inv_mushroom_11",
  125.   announce = {
  126.     enUS = format("Awarded for outstanding service to Dragonkind %s Awarded for outstanding service to Dragonkind", GetItemLinkById(194701))
  127.         }
  128.     }
  129. }

Fizzlemizz 02-21-24 11:30 PM

Quote:

But for some reason, the button and the slash command stopped being pressed.
table.lua
I'm not sure what you mean by "stopped being pressed", or the whole sentence really?.

You removed the option to show/hide the button from the slash command (or at least didn't copy the SlashCmdList["HUBB"] = function(msg) code from my example.

Your latest code contains a function GetItemLinkById I have no idea what it is or where it's from but it's not Blizz and it's not defined in anything you've posted so colour me confused that it works at all.

Hubb777 02-22-24 12:02 AM

Quote:

Originally Posted by Fizzlemizz (Post 343398)
I'm not sure what you mean by "stopped being pressed", or the whole sentence really?.

You removed the option to show/hide the button from the slash command (or at least didn't copy the SlashCmdList["HUBB"] = function(msg) code from my example.

Your latest code contains a function GetItemLinkById I have no idea what it is or where it's from but it's not Blizz and it's not defined in anything you've posted so colour me confused that it works at all.

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {format(item.announce[GetLocale()], GetItemLink(id)), item.icon, item.name})
  18.     end
  19. end
  20. local function GetItemLink(id)
  21.     local item = Item:CreateFromItemID(id)
  22.     local itemLink = item:GetItemLink()
  23.  
  24.     return itemLink
  25. end
  26. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  27. f:SetPoint("CENTER")
  28. f:Hide()
  29. f:SetMovable(true)
  30. f:SetScript("OnMouseDown", f.StartMoving)
  31. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  32.  
  33. -- I added this OnHide script
  34. f:SetScript("OnHide", function()
  35.     btn:Show()
  36. end)
  37.  
  38. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  39. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  40. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  41.  
  42. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  43. f.scrollFrame.scrollChild:SetSize(100, 100)
  44. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  45. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  46.  
  47. local content = f.scrollFrame.scrollChild
  48. content.rows = {}
  49.  
  50. local function updateList()
  51.     for i = 1, #data do
  52.         if not content.rows[i] then
  53.             local button = CreateFrame("Button", nil, content)
  54.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  55.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  56.             button.columns = {}
  57.  
  58.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  59.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  60.  
  61.             button.columns[2] = button:CreateTexture()
  62.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  63.  
  64.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  65.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  66.  
  67.             content.rows[i] = button
  68.         end
  69.  
  70.         content.rows[i].columns[1]:SetText(data[i][1])
  71.         content.rows[i].columns[2]:SetTexture(data[i][2])
  72.         content.rows[i].columns[3]:SetText(data[i][3])
  73.  
  74.         content.rows[i]:Show()
  75.     end
  76.  
  77.     for i = #data + 1, #content.rows do
  78.         content.rows[i]:Hide()
  79.     end
  80. end
  81.  
  82.  
  83. -- Set your button options here
  84. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  85. btn:SetPoint("CENTER")
  86. btn:SetSize(100, 40)
  87. btn:SetText("Click me")
  88. btn:SetMovable(true)
  89. btn:RegisterForDrag('LeftButton')
  90. btn:RegisterForClicks("AnyDown", "AnyUp")
  91. btn:SetUserPlaced(true)
  92. btn:SetScript('OnDragStart', function(self, button, down)
  93.     if button == "LeftButton" and IsShiftKeyDown() then
  94.         self:StartMoving()
  95.     end
  96. end)
  97. btn:SetScript('OnDragStop', function(self)
  98.     self:StopMovingOrSizing()
  99. end)
  100. btn:SetScript("OnMouseUp", function(self, button, ...)
  101.     if (button == "RightButton" and self:IsVisible()) then
  102.         self:Hide()
  103.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  104.         updateData()
  105.         updateList()
  106.         f:Show()
  107.     end
  108. end)
  109.  
  110. SLASH_HUBB1 = "/hubb"
  111. SlashCmdList["HUBB"] = function(msg)
  112.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  113.         btn:SetShown(not btn:IsShown()) -- show the button
  114.         return
  115.     end
  116.     updateData()
  117.     updateList()
  118.     f:Show()
  119. end

I was assured that it would work in GetItemLinkById. But it looks like we just didn't understand each other.
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. -- name and icon (and link) set by LoadItem() when the item is cached.
  8. addon.db = {
  9.     {
  10. --        name = "Emerald Mark of Mastery",
  11.         questID = 75612,
  12. --        icon = "interface/icons/inv_mushroom_11",
  13.         item = 6218,
  14.         announce = {
  15.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  16.         }
  17.     },
  18.     {
  19. --        name = "Emerald Mark of Mastery",
  20.         questID = 75624,
  21. --        icon = "interface/icons/inv_mushroom_11",
  22.         item = 20897,
  23.         announce = {
  24.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts\n\nAwarded for outstanding service to (clickable link to the item) Dragonkind. Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  25.         }
  26.     },
  27.     {
  28. --        name = "Emerald Mark of Mastery",
  29.         questID = 74352,
  30.         item = 193440,
  31. --        icon = "interface/icons/inv_mushroom_11",
  32.         announce = {
  33.             enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
  34.         }
  35.     }
  36. }
  37.  
  38. local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- function to print the link when clicked
  39.     print("You just clickled:", text)
  40. end
  41.  
  42. local function OnHyperlinkEnter(self, link, text, region, left, bottom, width, height) -- function to display the hyperlink on mouse over
  43.     GameTooltip:SetOwner(self, "ANCHOR_CURSOR_RIGHT")
  44.     GameTooltip:SetHyperlink(link)
  45.     GameTooltip:Show()
  46. end
  47.  
  48. local function OnHyperlinkLeave(self) -- function to hide the hyperlink on mouse exit
  49.     GameTooltip:Hide()
  50. end
  51.  
  52. local function LoadItem(item) -- adds the item to the bd overwriting the icon, name ans sedtting the itemlink keys
  53.     addon.db[item.dbID].name = item:GetItemName()
  54.     addon.db[item.dbID].icon = "|T"..item:GetItemIcon()..":20:20|t" -- make icon size 20x20
  55.     addon.db[item.dbID].itemlink = item:GetItemLink()
  56.  
  57.  
  58. print(addon.db[item.dbID].name, addon.db[item.dbID].icon, addon.db[item.dbID].itemlink)
  59.  
  60. end
  61.  
  62. for i, v in ipairs(addon.db) do -- Get the item information and call LoadItem when it's returned from the server and cached
  63.     local item = Item:CreateFromItemID(v.item)
  64.     item.dbID = i
  65.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  66. end
  67.  
  68. local data = {}
  69.  
  70. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  71. f.Title = f:CreateFontString()
  72. f.Title:SetFontObject(GameFontNormal)
  73. f.Title:SetPoint("TOP", 0, -5)
  74. f.Title:SetText(addonName)
  75. -- Create the button here
  76. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  77.  
  78. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  79.     wipe(data)
  80.     for _, item in ipairs(addon.db) do
  81.         tinsert(data, {text=item.announce[GetLocale()], icon=item.icon, name=item.name, link=item.itemlink})
  82.     end
  83. end
  84.  
  85. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  86. f:SetPoint("CENTER")
  87. f:Hide()
  88. f:SetMovable(true)
  89. f:SetScript("OnMouseDown", f.StartMoving)
  90. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  91.  
  92.  
  93. -- I added this OnHide script
  94. f:SetScript("OnHide", function()
  95.     btn:Show()
  96. end)
  97.  
  98. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  99. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  100. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  101.  
  102. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  103. f.scrollFrame.scrollChild:SetSize(100, 100)
  104. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  105. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  106.  
  107. local content = f.scrollFrame.scrollChild
  108. content.rows = {}
  109.  
  110. local function updateList()
  111.     for i = 1, #data do
  112.         if not content.rows[i] then
  113.             local button = CreateFrame("Button", nil, content)
  114.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  115.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  116.             button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row
  117.             button:SetScript("OnHyperlinkClick", OnHyperlinkClick)
  118.             button:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)
  119.             button:SetScript("OnHyperlinkLeave", OnHyperlinkLeave)
  120.            
  121.             button.columns = {}
  122.  
  123.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  124.             button.columns[1]:SetJustifyH("LEFT")
  125.             button.columns[1]:SetJustifyV("TOP")
  126. --            button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  127.             button.columns[1]:SetPoint("TOPLEFT")
  128.             button.columns[1]:SetPoint("BOTTOMRIGHT", button, "BOTTOMLEFT", 140, 0)
  129.  
  130. -- Replaced the icon texture with the icon embedded in the description string.
  131. --            button.columns[2] = button:CreateTexture()
  132. --            button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  133. --            button.columns[2]:SetPoint("LEFT", button.columns[1], "RIGHT")
  134.  
  135.             button.columns[2] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  136.             button.columns[2]:SetJustifyH("LEFT")
  137.             button.columns[2]:SetJustifyV("TOP")
  138. --            button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  139.             button.columns[2]:SetPoint("TOPLEFT", button.columns[1], "TOPRIGHT", 5, 0)
  140.             button.columns[2]:SetPoint("BOTTOMRIGHT", button)
  141.  
  142.             content.rows[i] = button
  143.         end
  144.  
  145.         content.rows[i].columns[1]:SetText(data[i].name)
  146. --        content.rows[i].columns[2]:SetTexture(data[i][2])
  147.         content.rows[i].columns[2]:SetText(format(data[i].text, data[i].icon, data[i].link)) -- insert the icon and hyperlink into the text
  148.  
  149.         content.rows[i]:Show()
  150.     end
  151.  
  152.     for i = #data + 1, #content.rows do
  153.         content.rows[i]:Hide()
  154.     end
  155. end
  156.  
  157.  
  158. -- Set your button options here
  159. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  160. btn:SetPoint("CENTER")
  161. btn:SetSize(100, 40)
  162. btn:SetText("Click me")
  163. btn:SetMovable(true)
  164. btn:RegisterForDrag('LeftButton')
  165. btn:RegisterForClicks("AnyDown", "AnyUp")
  166. btn:SetUserPlaced(true)
  167. btn:SetScript('OnDragStart', function(self, button, down)
  168.     if button == "LeftButton" and IsShiftKeyDown() then
  169.         self:StartMoving()
  170.     end
  171. end)
  172. btn:SetScript('OnDragStop', function(self)
  173.     self:StopMovingOrSizing()
  174. end)
  175. btn:SetScript("OnMouseUp", function(self, button, ...)
  176.     if (button == "RightButton" and self:IsVisible()) then
  177.         self:Hide()
  178.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  179.         updateData()
  180.         updateList()
  181.         f:Show()
  182.     end
  183. end)
  184.  
  185. SLASH_HUBB1 = "/hubb"
  186. SlashCmdList["HUBB"] = function(msg)
  187.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  188.         btn:SetShown(not btn:IsShown()) -- show the button
  189.         return
  190.     end
  191.     updateData()
  192.     updateList()
  193.     f:Show()
  194. end

Your code works 100%. But it displays the items in the chat, rather than displaying a table. And it is the table that I need.


An example where instead of {item:194701} there is a link to the item.

Fizzlemizz 02-22-24 12:43 AM

Quote:

I was assured that it would work in GetItemLinkById. But it looks like we just didn't understand each other.
Assured by who? If it's not a game function and it's not one of yours hidden somewher in other code then I don't know where it comes from.

Quote:

But it displays the items in the chat, rather than displaying a table. And it is the table that I need.
Still not sure what it is you want. Possibly just a custom tooltip?

Delete the lines
Lua Code:
  1. button:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)

(You can delete the OnHyperlinkEnter function as well)

Change the OnHyperlinkClick function to:
Lua Code:
  1. Change the OnHyperlinkClick function to be
  2.     GameTooltip:SetOwner(self, "ANCHOR_CURSOR_RIGHT")
  3.     GameTooltip:AddText("Unlocks this customization option for the Renewed Proto-Drake at the Rostrum of Transformation")
  4.     GameTooltip:Show()
  5. end
Once again, just an example tooltip with fixed text (which you could (would) get the actual text from the addon.db table or some other source).

The other possabilty is you want the click to open the item tooltip rather than doing it OnEnter in which case, the the OnHyperlinkClick function would be:
Lua Code:
  1. local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- Show the hyperling tooltip when clicked
  2.     SetItemRef(link, text, button, self);
  3. end

Hubb777 02-22-24 03:10 AM

Quote:

Originally Posted by Fizzlemizz (Post 343400)
Assured by who? If it's not a game function and it's not one of yours hidden somewher in other code then I don't know where it comes from.
Still not sure what it is you want. Possibly just a custom tooltip?

In this example, when I clicked a button, a table appeared. The table contained text and pictures.
https://www.wowinterface.com/forums/...ad.php?t=59796
Here is a table (picture 1)

I want to be able to add a link to an item in the description of the text, anywhere in the text.
I did this in photo editor GIMP (it turned out a little crooked)

Fizzlemizz 02-22-24 09:45 AM

You still don't say what you want to see when a link is clicked so, using the code you linked and guessing you just want to see the item tooltip when a link is clicked:

The item field added to each entry in addon.db is the (random because I don't know that acual) item ID that will be the link/tooltip (replacing the %s in each announce.enUS field).

db.lua file
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.         item = 210399,
  8.         announce = {
  9.             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"
  10.         }
  11.     },
  12.     {
  13.         name = "Emerald Mark of Mastery",
  14.         questID = 75624,
  15.         icon = "interface/icons/inv_mushroom_11",
  16.         item = 20897,
  17.         announce = {
  18.             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"
  19.         }
  20.     },
  21.     {
  22.         name = "Emerald Mark of Mastery",
  23.         questID = 74352,
  24.         icon = "interface/icons/inv_mushroom_11",
  25.         item = 193440,
  26.         announce = {
  27.             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"
  28.         }
  29.     }
  30. }
  31. ---------------------------------------------------------------------------------------------------
  32. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  33. local function LoadItem(item)
  34.     for k, v in pairs(addon.db[item.dbID].announce) do -- replace the %s with the itemlink in eal locale in the .announce key
  35.         addon.db[item.dbID].announce[k] = format(v, item:GetItemLink())
  36.     end
  37. end
  38. for i, v in ipairs(addon.db) do
  39.     local item = Item:CreateFromItemID(v.item)
  40.     item.dbID = i
  41.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  42. end

Lua Code file:
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 function updateData() --commented out because addon.db hasn't been created... in the code at least
  20.     wipe(data)
  21.     for _, item in ipairs(addon.db) do
  22.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  23.     end
  24. end
  25.  
  26. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  27. f:SetPoint("CENTER")
  28. f:Hide()
  29. f:SetMovable(true)
  30. f:SetScript("OnMouseDown", f.StartMoving)
  31. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  32.  
  33. -- I added this OnHide script
  34. f:SetScript("OnHide", function()
  35.     btn:Show()
  36. end)
  37.  
  38. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  39. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  40. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  41.  
  42. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  43. f.scrollFrame.scrollChild:SetSize(100, 100)
  44. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  45. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  46.  
  47. local content = f.scrollFrame.scrollChild
  48. content.rows = {}
  49.  
  50. local function updateList()
  51.     for i = 1, #data do
  52.         if not content.rows[i] then
  53.             local button = CreateFrame("Button", nil, content)
  54.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  55.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  56.             button.columns = {}
  57.  
  58. ---------------------------------------------------------------------------------------------------
  59. -- code to make item links work
  60.             button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row
  61.             button:SetScript("OnHyperlinkClick", OnHyperlinkClick) -- What to do when a link is clicked
  62. ---------------------------------------------------------------------------------------------------
  63.  
  64.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  65.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  66.  
  67.             button.columns[2] = button:CreateTexture()
  68.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  69.  
  70.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  71.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  72.  
  73.             content.rows[i] = button
  74.         end
  75.  
  76.         content.rows[i].columns[1]:SetText(data[i][1])
  77.         content.rows[i].columns[2]:SetTexture(data[i][2])
  78.         content.rows[i].columns[3]:SetText(data[i][3])
  79.  
  80.         content.rows[i]:Show()
  81.     end
  82.  
  83.     for i = #data + 1, #content.rows do
  84.         content.rows[i]:Hide()
  85.     end
  86. end
  87.  
  88.  
  89. -- Set your button options here
  90. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  91. btn:SetPoint("CENTER")
  92. btn:SetSize(100, 40)
  93. btn:SetText("Click me")
  94. btn:SetMovable(true)
  95. btn:RegisterForDrag('LeftButton')
  96. btn:RegisterForClicks("AnyDown", "AnyUp")
  97. btn:SetUserPlaced(true)
  98. btn:SetScript('OnDragStart', function(self, button, down)
  99.     if button == "LeftButton" and IsShiftKeyDown() then
  100.         self:StartMoving()
  101.     end
  102. end)
  103. btn:SetScript('OnDragStop', function(self)
  104.     self:StopMovingOrSizing()
  105. end)
  106. btn:SetScript("OnMouseUp", function(self, button, ...)
  107.     if (button == "RightButton" and self:IsVisible()) then
  108.         self:Hide()
  109.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  110.         updateData()
  111.         updateList()
  112.         f:Show()
  113.     end
  114. end)
  115.  
  116. SLASH_HUBB1 = "/hubb"
  117. SlashCmdList["HUBB"] = function(msg)
  118.     if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
  119.         btn:SetShown(not btn:IsShown()) -- show the button
  120.         return
  121.     end
  122.     updateData()
  123.     updateList()
  124.     f:Show()
  125. end

To show/hide the button:
Code:

/hubb btn

Hubb777 02-22-24 11:23 PM

Quote:

Originally Posted by Fizzlemizz (Post 343403)
You still don't say what you want to see when a link is clicked so, using the code you linked and guessing you just want to see the item tooltip when a link is clicked:

The item field added to each entry in addon.db is the (random because I don't know that acual) item ID that will be the link/tooltip (replacing the %s in each announce.enUS field).

Hello. Yes, that's perfect. This is exactly what I wanted. Thank you so much for your help. I have already started creating my first addon. Which I will definitely publish on https://www.wowinterface.com/.

I set the localization lines correctly, did I do everything right?

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.         announce = {
  12.             deDE = "Die Grundlage eines jeden %s Getränks: Wasser! Aufgegossen mit ausgewählten Kräutern aus meinem Garten.",
  13.              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",
  14.         }
  15.     },
  16.     {
  17.         name = "Emerald Mark of Mastery",
  18.         questID = 75624,
  19.         icon = "interface/icons/inv_mushroom_11",
  20.         item = 20897,
  21.         announce = {
  22.              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"
  23.         }
  24.     },
  25.     {
  26.         name = "Emerald Mark of Mastery",
  27.         questID = 74352,
  28.         icon = "interface/icons/inv_mushroom_11",
  29.         item = 193440,
  30.         announce = {
  31.              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"
  32.         }
  33.     }
  34. }
  35. ---------------------------------------------------------------------------------------------------
  36. -- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
  37. local function LoadItem(item)
  38.     for k, v in pairs(addon.db[item.dbID].announce) do -- replace the %s with the itemlink in eal locale in the .announce key
  39.         addon.db[item.dbID].announce[k] = format(v, item:GetItemLink())
  40.     end
  41. end
  42. for i, v in ipairs(addon.db) do
  43.     local item = Item:CreateFromItemID(v.item)
  44.     item.dbID = i
  45.     item:ContinueOnItemLoad(function() LoadItem(item) end)
  46. end

Fizzlemizz 02-23-24 12:15 AM

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!

Hubb777 02-23-24 12:24 AM

Quote:

Originally Posted by Fizzlemizz (Post 343409)
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?

Fizzlemizz 02-23-24 12:52 AM

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.

Hubb777 02-23-24 10:37 PM

Quote:

Originally Posted by Fizzlemizz (Post 343411)
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.

Fizzlemizz 02-23-24 11:55 PM

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.

Hubb777 02-24-24 12:07 AM

Quote:

Originally Posted by Fizzlemizz (Post 343416)
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

Fizzlemizz 02-24-24 01:15 AM

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.

Hubb777 02-24-24 01:37 AM

Quote:

Originally Posted by Fizzlemizz (Post 343418)
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?

Xrystal 02-24-24 02:46 AM

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.

Hubb777 02-24-24 02:51 AM

Quote:

Originally Posted by Xrystal (Post 343420)
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.

Xrystal 02-24-24 05:31 AM

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.

Hubb777 02-24-24 07:02 AM

Quote:

Originally Posted by Xrystal (Post 343422)
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)

Xrystal 02-24-24 08:44 AM

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.

Fizzlemizz 02-24-24 11:32 AM

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()

Hubb777 02-24-24 10:21 PM

Quote:

Originally Posted by Fizzlemizz (Post 343428)
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

Fizzlemizz 02-25-24 12:16 AM

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

Hubb777 02-25-24 12:27 AM

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 =(

Fizzlemizz 02-25-24 12:52 AM

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

Hubb777 02-25-24 01:02 AM

Quote:

Originally Posted by Fizzlemizz (Post 343439)
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

Fizzlemizz 02-25-24 01:19 AM

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

Hubb777 02-25-24 01:29 AM

Quote:

Originally Posted by Fizzlemizz (Post 343441)
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. }

Fizzlemizz 02-25-24 01:40 AM

Then you're using different code. Line 78 in the code I posted (and you re-posted) is either and end or a blank line so, nothing to do with self:SetText()

I can't diagnose what I can't see.

My best guess is you didn't use the updateData() function from my code in whatever your using.

Hubb777 02-25-24 01:55 AM

Quote:

Originally Posted by Fizzlemizz (Post 343443)
Then you're using different code. Line 78 in the code I posted (and you re-posted) is either and end or a blank line so, nothing to do with self:SetText()

I can't diagnose what I can't see.

My best guess is you didn't use the updateData() function from my code in whatever your using.

Yes, indeed, I made changes to another file. It's my mistake, sorry. And a couple more questions (I understand that I just bombarded you with questions) these will be the last.

1. If I want to make a similar addon, as I understand it, I will need to change (the code below) to which one?
Lua Code:
  1. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")

2. how do I add a table title (in different languages)

Fizzlemizz 02-25-24 02:12 AM

Both

Lua Code:
  1. local f = CreateFrame("Frame", "Addon_1_Name_Frame", UIParent, "BasicFrameTemplateWithInset")

Lua Code:
  1. local f = CreateFrame("Frame", "Addon_2_Name_Frame", UIParent, "BasicFrameTemplateWithInset")

Probably not a lot of point changing the addon title language unless you are going to post it in language specific sites under different names. If you are just hosting it on WowInterace/Curse/Wago people will find it using the single addon name which would be the same in any language so may as well be the title.

To add a title, after:
Lua Code:
  1. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")

add:
Lua Code:
  1. f.Title = f:CreateFontstring(nil, "ARTWORK", "GameFontNormal")
  2. f.Title:SetPoint("TOP", 0, -4)
  3. f.Title:SetText("Your Addon Name")

Hubb777 02-25-24 02:17 AM

Quote:

Originally Posted by Fizzlemizz (Post 343445)
Both

Lua Code:
  1. local f = CreateFrame("Frame", "Addon_1_Name_Frame", UIParent, "BasicFrameTemplateWithInset")

Lua Code:
  1. local f = CreateFrame("Frame", "Addon_2_Name_Frame", UIParent, "BasicFrameTemplateWithInset")

Probably not a lot of point changing the addon title language unless you are going to post it in language specific sites under different names. If you are just hosting it on WowInterace/Curse/Wago people will find it using the single addon name which would be the same in any language so may as well be the title.

To add a title, after:
Lua Code:
  1. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")

add:
Lua Code:
  1. f.Title = f:CreateFontstring(nil, "ARTWORK", "GameFontNormal")
  2. f.Title:SetPoint("TOP", 0, -4)
  3. f.Title:SetText("Your Addon Name")

It looks like the problem with different languages has played a cruel joke again. Not the addon name, but my table name. For example, I will name the table “Possible rewards” or “List of pets”, I would like this inscription to also have a translation.

Fizzlemizz 02-25-24 02:41 AM

Quote:

Originally Posted by Hubb777 (Post 343446)
It looks like the problem with different languages has played a cruel joke again. Not the addon name, but my table name. For example, I will name the table “Possible rewards” or “List of pets”, I would like this inscription to also have a translation.

Create a table for your texts (1 sub-table for each with text you want on screen that contains the localised version of the title/whatever. eg.

Lua Code:
  1. addon.Texts = {
  2.     Rewards = {
  3.         enUS = "Possible Rewards",
  4.         deDE = "German for Possible Rewards",
  5.     },
  6.     Pets = {
  7.         enUS = "List of pets",
  8.         deDE = "German List of pets",
  9.     },
  10. }

You can then create FontStrings and set their texts using (set Rewards text):
Lua Code:
  1. xxx:SetText(addon.Texts.Rewards[GetLocal()] or addon.Texts.Rewards.enUS) -- enUS being the default is the GetLocale() entry doesn't exist.

xxx being the variable used when creating the FontString.

You might want to see the wiki on localisation if it gets more complicated.

Hubb777 02-25-24 02:59 AM

Should I create a new lua file tablename.lua? With
Lua Code:
  1. addon.Texts = {
  2.     Rewards = {
  3.         enUS = "Possible Rewards",
  4.         deDE = "German for Possible Rewards",
  5.     },
  6.     Pets = {
  7.         enUS = "List of pets",
  8.         deDE = "German List of pets",
  9.     },
  10. }

And add this file to table.lua
Lua Code:
  1. Pets:SetText(addon.Texts.Rewards[GetLocal()] or addon.Texts.Rewards.enUS) -- enUS being the default is the GetLocale() entry doesn't exist.

Fizzlemizz 02-25-24 08:32 AM

addon.Texts can go in the same file as addon.db as that seems to be where you're putting "data". Assuming that this file is listed in the .TOC file above the other (table.lua) file so it loads first.

Lua Code:
  1. Pets:SetText(addon.Texts.Rewards[GetLocal()] or addon.Texts.Rewards.enUS) -- enUS being the default is the GetLocale() entry doesn't exist.

Goes after you've:
Lua Code:
  1. local Pets = someframe:CreateFontString(nil, somedrawlayer, somefont)

You can't fontstring:SetText(...) on a FontString that doesn't exist.

Hubb777 02-25-24 10:55 PM

Quote:

Originally Posted by Fizzlemizz (Post 343449)
addon.Texts can go in the same file as addon.db as that seems to be where you're putting "data". Assuming that this file is listed in the .TOC file above the other (table.lua) file so it loads first.

Lua Code:
  1. Pets:SetText(addon.Texts.Rewards[GetLocal()] or addon.Texts.Rewards.enUS) -- enUS being the default is the GetLocale() entry doesn't exist.

Goes after you've:
Lua Code:
  1. local Pets = someframe:CreateFontString(nil, somedrawlayer, somefont)

You can't fontstring:SetText(...) on a FontString that doesn't exist.

This is the code I got
Lua Code:
  1. local Pets = someframe:CreateFontString(nil, somedrawlayer, somefont)
  2. Pets:SetText(addon.Texts.Rewards[GetLocal()] or addon.Texts.Rewards.enUS)
  3. addon.Texts = {
  4.     Rewards = {
  5.         enUS = "Possible Rewards",
  6.         deDE = "German for Possible Rewards",
  7.     },
  8.     Pets = {
  9.         enUS = "List of pets",
  10.         deDE = "German List of pets",
  11.     },
  12. }
Wherever I insert it, either the button disappears or it cannot be pressed. And if everything is pressed, there is no result.

Fizzlemizz 02-26-24 08:59 AM

Because you refuse to read and consider what has been written. In the last post, not even considered what was asked.

Most parts of an addon are created, positioned, formatted etc. in relation to something else depending on what you want your addon to do and how you want it to look and work. Not being a mind reader (and I can't read you screen), I'm not about to decide that for you, all I can do is offer suggestions on how you might do things. It's up to you work that information (if you think it might be useful) into your addon.

With that in mind, not every code block is literal, someframe, somedrawlayer, somefont are for you to replace with whatever works for you and your addon.

Hubb777 02-26-24 10:28 PM

Quote:

Originally Posted by Fizzlemizz (Post 343458)
Because you refuse to read and consider what has been written. In the last post, not even considered what was asked.

Most parts of an addon are created, positioned, formatted etc. in relation to something else depending on what you want your addon to do and how you want it to look and work. Not being a mind reader (and I can't read you screen), I'm not about to decide that for you, all I can do is offer suggestions on how you might do things. It's up to you work that information (if you think it might be useful) into your addon.

With that in mind, not every code block is literal, someframe, somedrawlayer, somefont are for you to replace with whatever works for you and your addon.

Hello. Sorry for the misunderstanding. It’s just that English is not my native language (I’m writing from the Czech Republic). For some of the text I have to use Google Translate (which makes it even more difficult to understand).

I'll try to figure out the issue again.
As I understand it, I can place this part of the code in the code file db.lua
Lua Code:
  1. addon.Texts = {
  2.     Rewards = {
  3.         enUS = "Possible Rewards",
  4.         deDE = "German for Possible Rewards",
  5.     },
  6.     Pets = {
  7.         enUS = "List of pets",
  8.         deDE = "German List of pets",
  9.     },
  10. }
And this part in code table.lua
Lua Code:
  1. local Pets = someframe:CreateFontString(nil, somedrawlayer, somefont)
  2. Pets:SetText(addon.Texts.Rewards[GetLocal()] or addon.Texts.Rewards.enUS)

Fizzlemizz 02-27-24 09:33 AM

Correct,

Lua Code:
  1. local Pets = someframe:CreateFontString(nil, somedrawlayer, somefont)

Replace someframe with the frame you want to be the parent of the new FontString
The parent will effect the Fonstrings scale and when it's, shown/hidden etc.

Replace somedrawlayer and somefont with the relevent information depending on where in the layer stack you want the string displayed and the font/size you want the text to be displayed in. See the docs for CreateFontString and see this page for some of the in-game fonts configurations ie. GameFontNormal, GameFontHighlight etc. etc. etc.

You can't use someframe (whichever that frame is) to create the FontString until after the frame itself has been created (The order that code is placed (runs) matters).

Hubb777 03-02-24 11:56 PM

Quote:

Originally Posted by Fizzlemizz (Post 343464)
Correct,

Lua Code:
  1. local Pets = someframe:CreateFontString(nil, somedrawlayer, somefont)

Replace someframe with the frame you want to be the parent of the new FontString
The parent will effect the Fonstrings scale and when it's, shown/hidden etc.

Replace somedrawlayer and somefont with the relevent information depending on where in the layer stack you want the string displayed and the font/size you want the text to be displayed in. See the docs for CreateFontString and see this page for some of the in-game fonts configurations ie. GameFontNormal, GameFontHighlight etc. etc. etc.

You can't use someframe (whichever that frame is) to create the FontString until after the frame itself has been created (The order that code is placed (runs) matters).

Hello. After several days I still couldn't figure it out (I'm stupid). I made the addon without these changes, it turned out pretty good.
https://www.wowinterface.com/downloa...o.php?id=26699

Fizzlemizz 03-03-24 11:13 AM

Congratulations:banana:

The more you play with it, the more you'll learn. Have Fun!


All times are GMT -6. The time now is 06:34 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI