Thread Tools Display Modes
02-19-24, 10:32 PM   #1
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
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")

Last edited by Hubb777 : 02-19-24 at 10:36 PM.
  Reply With Quote
02-19-24, 10:40 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-19-24, 10:51 PM   #3
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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
  Reply With Quote
02-20-24, 12:04 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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")
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-20-24, 12:31 AM   #5
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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")
  Reply With Quote
02-20-24, 01:05 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-20-24 at 01:10 AM.
  Reply With Quote
02-20-24, 03:37 AM   #7
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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
  Reply With Quote
02-20-24, 08:53 AM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-20-24 at 10:10 AM.
  Reply With Quote
02-20-24, 11:41 PM   #9
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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?
  Reply With Quote
02-21-24, 12:31 AM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-21-24 at 12:33 AM.
  Reply With Quote
02-21-24, 12:42 AM   #11
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Yes, it worked. The code works completely as intended. Thank you very much. I couldn't have done it without you.
Originally Posted by Fizzlemizz View Post
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
  Reply With Quote
02-21-24, 10:26 AM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-21-24 at 02:28 PM.
  Reply With Quote
02-21-24, 11:11 PM   #13
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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. }

Last edited by Hubb777 : 02-21-24 at 11:16 PM.
  Reply With Quote
02-21-24, 11:30 PM   #14
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-22-24, 12:02 AM   #15
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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.
  Reply With Quote
02-22-24, 12:43 AM   #16
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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.

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

Last edited by Fizzlemizz : 02-22-24 at 01:15 AM.
  Reply With Quote
02-22-24, 03:10 AM   #17
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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)
  Reply With Quote
02-22-24, 09:45 AM   #18
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-22-24 at 12:34 PM.
  Reply With Quote
02-22-24, 11:23 PM   #19
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Fizzlemizz View Post
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
  Reply With Quote
02-23-24, 12:15 AM   #20
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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!
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-23-24 at 12:21 AM.
  Reply With Quote

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


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

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