Thread Tools Display Modes
Prev Previous Post   Next Post Next
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: 120
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
 

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