WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Text on top of each other in frame (https://www.wowinterface.com/forums/showthread.php?t=59769)

Trailertina 01-23-24 06:18 AM

Text on top of each other in frame
 
Hey all, I'm trying to make a simple addon to myself because I'm too lazy to look through the chat in M+ :D

The addon opens a frame with peoples loot and a button to easily whisper them and it works okay when two players get loot, BUT when a third or more players receives loot the text is printed on top of the two first players text/loot. I give the complete code for the addon here, but I would recon that the problem is somewhere in the 'UpdateLootWindow' function? I guess it's maybe yoffset that needs adjustment? But I cannot get anything to work. I also give you an image of the loot frame when a third or more player gets loot.

[IMG] https://prnt.sc/bh4sMlYgbGer

Code beneath:

https://github.com/Trailertina/MythicPlusLoot

Fizzlemizz 01-23-24 10:07 AM

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


All times are GMT -6. The time now is 04:25 AM.

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