View Single Post
01-23-24, 10:07 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,892
Every time UpdateLootWindow runs, it's creating a new set of widgets (Fontstrings and Buttons) on top of the old ones.

You should only create them once (and maybe add extras (once) if needed)
Very rough example:

Lua Code:
  1. LootAddonFrame.LootWindow = CreateFrame("Frame", "LootAddonFrame_LootWindow", UIParent, "UIPanelDialogTemplate")
  2. LootAddonFrame.LootWindow.PlayerInfo = {} -- a table to store created FontString references

UpdateLootWindow()

Lua Code:
  1. local count = 0
  2. for playerName, lootList in pairs(lootHistory) do
  3.    -- ...
  4.     local playerLabel
  5.     count = count + 1
  6.     local last = #LootAddonFrame.LootWindow.PlayerInfo -- How many have we created previously
  7.     if last < count -- not enough widgets so create new FontString and Button
  8.         playerLabel = LootAddonFrame.LootWindow:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  9.         local whisperButton = CreateFrame("Button", nil, LootAddonFrame.LootWindow, "UIPanelButtonTemplate")
  10.         -- configure the fontstring and button scripts etc.
  11.         if count = 1 then -- place them relative to the frame or previous string/buttons (instead of calculating y offset
  12.                 playerLabel:SetPoint("TOPLEFT", 10, -30)
  13.         else
  14.                 local lastInList = LootAddonFrame.LootWindow.PlayerInfo[last]
  15.                 playerLabel:SetPoint("TOPLEFT", lastInList, "BOTTOMLEFT", 0, -3)
  16.         end
  17.         whisperButton:SetPoint("LEFT", playerLabel, "RIGHT", 5, 0)
  18.         tinsert(LootAddonFrame.LootWindow.PlayerInfo, playerLabel) -- add the label to the reacking table
  19.     else
  20.         playerLabel = LootAddonFrame.LootWindow.PlayerInfo[last] -- a fonstring exists so re-use those first
  21.     end
  22.     -- update the FontString text and whatever else.
  23.     playerLabel:SetText(coloredPlayerName .. " looted:")
  24.     -- ...
  25. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-23-24 at 12:25 PM.
  Reply With Quote