View Single Post
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,892
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