Thread Tools Display Modes
01-23-24, 06:18 AM   #1
Trailertina
A Kobold Labourer
Join Date: Jan 2024
Posts: 1
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+

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
  Reply With Quote
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,879
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

WoWInterface » Developer Discussions » Lua/XML Help » Text on top of each other in frame


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