Quantcast
Fontstrings not displaying in certain cases - WoWInterface
Thread Tools Display Modes
11-19-20, 04:37 PM   #1
Zulu
A Murloc Raider
Join Date: Nov 2020
Posts: 5
Fontstrings not displaying in certain cases

Hello everyone,

I'm working on an addon which will help players manage their auctions and their stock of "comodities".

Right now, I'm coding a tab in my addon panel called stockpile, which list all reagent in either a list view, or a grid view.

There is also a dropdown with all types of reagent so the user can filter the list or the grid by a specific type (enchanting, metal and stone, ...)

Here is how the grid view looks with no filter (the dropdown in the center is set to "all")



As you can see, on each reagent icon, there is a text which is the count of this reagant in all bags, bank, etc..

But, when I apply a filter, the count texts don't show anymore, and I can't understand why. Here is how it looks with a random filter



Count texts are not shown ! Here is my lua code :

Code:
function Merchant.UI.AddStockpileStock(itemID, count)
  if #Merchant.UI.StockpileStocks < Merchant.UI.StockpileStockCnt then
    local frame = Merchant.UI.StockpileGridScrollFrameContent
    local x = (32 + 10) * ((Merchant.UI.StockpileStockCnt - 1) % Merchant.UI.StockpileGridMaxPerLine)
    local y = (-32 - 10) * math.floor((Merchant.UI.StockpileStockCnt - 1) / Merchant.UI.StockpileGridMaxPerLine)

    local iconFrame = CreateFrame("Frame", nil, frame)
    iconFrame:SetSize(32, 32)
    iconFrame:SetPoint("TOPLEFT", x, y)
    local itemTexture = iconFrame:CreateTexture(nil, "OVERLAY")
    itemTexture:SetAllPoints()

    local countFrame = CreateFrame("Frame", nil, frame)
    countFrame:SetSize(32, 32)
    countFrame:SetPoint("TOPLEFT", x, y - 9)
    local itemCountText = countFrame:CreateFontString(nil, "OVERLAY")
    itemCountText:SetAllPoints()
    itemCountText:SetFont("Fonts\\FRIZQT__.TTF", 11, "THICKOUTLINE")
    itemCountText:SetJustifyH("RIGHT")

    table.insert(Merchant.UI.StockpileStocks, {
      IconFrame = iconFrame,
      ItemTexture = itemTexture,
      ItemCountFrame = countFrame,
      ItemCountText = itemCountText
    })
  end

  local stock = Merchant.UI.StockpileStocks[Merchant.UI.StockpileStockCnt]
  stock.ItemTexture:SetTexture(GetItemIcon(itemID))
  stock.ItemCountText:SetText("|cFFFFFFFF" .. tostring(count))

  Merchant.UI.StockpileStockCnt = Merchant.UI.StockpileStockCnt + 1
  Merchant.UI.StockpileGridScrollFrameContent:SetHeight((32 + 10) * math.floor((Merchant.UI.StockpileStockCnt - 1) / Merchant.UI.StockpileGridMaxPerLine))
end

--------------------------------------------------------------------------------

function Merchant.UI.EmptyStockpileGrid()
  for key, row in pairs(Merchant.UI.StockpileStocks) do
    row.ItemTexture:SetTexture("")
    row.ItemCountText:SetText("")
  end
  Merchant.UI.StockpileStockCnt = 1
end

--------------------------------------------------------------------------------

function Merchant.UI.DrawStockpileGrid(charName, filter)
  Merchant.UI.EmptyStockpileGrid()
  local stockpile = Merchant_Vars.Accounts[Merchant.RealmName].Stockpile[charName]
  if stockpile == nil then
    Merchant.Debug("error: no stockpile for " .. charName .. " character")
    return
  end
  if filter == "all" then
    table.sort(stockpile, function (a, b) return a.ItemSubClassID < b.ItemSubClassID end)
  end
  for idx, stock in ipairs(stockpile) do
    if filter == "all" or stock.ItemSubClassID == filter then
      Merchant.UI.AddStockpileStock(stock.ItemID, stock.ItemCount)
    end
  end
  if math.floor((Merchant.UI.StockpileStockCnt - 1) / Merchant.UI.StockpileGridMaxPerLine) > 9 then
    Merchant.UI.StockpileGridScrollFrameSlider:Show()
  else
    Merchant.UI.StockpileGridScrollFrameSlider:Hide()
  end
end
I create a frame which holds the texture (iconFrame).
I create a frame which holds the count text (countFrame).
They are both children of the upper frame, which is ScrollFrame.
They are created once when a new reagent is added for the first time and stored in a table for future use.
After the widgets are created, they are filled with the correct values, an item icon for the texture, and the reagent count for the count text.


At first, an upper function calls DrawStockpileGrid when the user selects the grid view or select a reagent type filter.
It calls first EmptyStockpileGrid which resets the table of widgets by setting their value to an empty string.
And then iterates an another table which contains all reagents for a character, calling AddStockpileStock for each stock.


I tried to play with frame stratas and levels but it didn't change anything. I tried to comment all code which concerns icons to leave only the countFrame and its FontString, but they still don't show.


I hope I gave you all necessary info. Thanks in advance for any info, help and advices. I'll give you any precision if you need it.
Attached Files
File Type: lua Stockpile_Grid.lua (3.6 KB, 26 views)
  Reply With Quote
11-19-20, 09:51 PM   #2
kurapica.igas
A Flamescale Wyrmkin
Join Date: Aug 2011
Posts: 142
Try to put the fontstring and texture on the same frame, and change the texture's drawlayer to artwork.

Lua Code:
  1. local iconFrame = CreateFrame("Frame", nil, frame)
  2. iconFrame:SetSize(32, 32)
  3. iconFrame:SetPoint("TOPLEFT", x, y)
  4.  
  5. local itemTexture = iconFrame:CreateTexture(nil, "ARTWORK")
  6. itemTexture:SetAllPoints()
  7.  
  8. local itemCountText = iconFrame:CreateFontString(nil, "OVERLAY")
  9. itemCountText:SetPoint("BOTTOMRIGHT", -4, 4)
  10. itemCountText:SetFont("Fonts\\FRIZQT__.TTF", 11, "THICKOUTLINE")
  11. itemCountText:SetJustifyH("RIGHT")
  Reply With Quote
11-20-20, 04:53 AM   #3
Zulu
A Murloc Raider
Join Date: Nov 2020
Posts: 5
Thank you for your help kurapica. I tried your solution but it didn't change. Counts are displayed when no filter is applied and not displayed when any of them is applied.

I even tried to completely remove the texture part and set the fontstring as direct child to the scrollframe:

Code:
function Merchant.UI.AddStockpileStock(itemID, count)
  if #Merchant.UI.StockpileStocks < Merchant.UI.StockpileStockCnt then
    local frame = Merchant.UI.StockpileGridScrollFrameContent
    local x = (32 + 10) * ((Merchant.UI.StockpileStockCnt - 1) % Merchant.UI.StockpileGridMaxPerLine)
    local y = (-32 - 10) * math.floor((Merchant.UI.StockpileStockCnt - 1) / Merchant.UI.StockpileGridMaxPerLine)

--    local iconFrame = CreateFrame("Frame", nil, frame)
--    iconFrame:SetSize(32, 32)
--    iconFrame:SetPoint("TOPLEFT", x, y)
--    local itemTexture = iconFrame:CreateTexture(nil, "ARTWORK")
--    itemTexture:SetAllPoints()

--    local countFrame = CreateFrame("Frame", nil, frame)
--    countFrame:SetSize(32, 32)
--    countFrame:SetPoint("TOPLEFT", x, y - 9)
    local itemCountText = frame:CreateFontString(nil, "OVERLAY")
    itemCountText:SetPoint("TOPLEFT", x, y)
--    itemCountText:SetPoint("BOTTOMRIGHT", -4, 4)
--    itemCountText:SetAllPoints()
    itemCountText:SetFont("Fonts\\FRIZQT__.TTF", 11, "THICKOUTLINE")
    itemCountText:SetJustifyH("RIGHT")

    table.insert(Merchant.UI.StockpileStocks, {
--      IconFrame = iconFrame,
--      ItemTexture = itemTexture,
--      ItemCountFrame = countFrame,
      ItemCountText = itemCountText
    })
  end

  local stock = Merchant.UI.StockpileStocks[Merchant.UI.StockpileStockCnt]
--  stock.ItemTexture:SetTexture(GetItemIcon(itemID))
  stock.ItemCountText:SetText("|cFFFFFFFF" .. tostring(count))
--  Merchant.Debug(stock.ItemCountText:GetText())
  Merchant.UI.StockpileStockCnt = Merchant.UI.StockpileStockCnt + 1
  Merchant.UI.StockpileGridScrollFrameContent:SetHeight((32 + 10) * math.floor((Merchant.UI.StockpileStockCnt - 1) / Merchant.UI.StockpileGridMaxPerLine))
end
but the issue is still here.

I added a dump in the chat/console of "stock.ItemCountText:GetText()" and it's good, the value is good.
  Reply With Quote
11-20-20, 04:31 PM   #4
Zulu
A Murloc Raider
Join Date: Nov 2020
Posts: 5
I fount out that if I move the panel and a filter is selected, icons are not moving alongside the panel.

Here I moved the panel to the right:



If that gives any clue...

PS: yet I displayed parent's name of the iconFrame in the console and the value is correct

Last edited by Zulu : 11-20-20 at 04:40 PM.
  Reply With Quote
11-20-20, 08:25 PM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,550
Check the anchoring.

Parenting controls visibility but not movement. Anchoring decides how the frame will position and move based on the frame it is anchored to.
__________________
  Reply With Quote
11-20-20, 09:51 PM   #6
kurapica.igas
A Flamescale Wyrmkin
Join Date: Aug 2011
Posts: 142
Maybe show the full addon for test is a better idea.
  Reply With Quote
11-21-20, 03:44 AM   #7
Zulu
A Murloc Raider
Join Date: Nov 2020
Posts: 5
Thank you Xrystal, I'll check that.

Here is the full addon : https://github.com/zulunovembre/Merchant/tree/dev

The current branch is "dev"

I've also added it as file attachment to this reply.

You have to open your bank once to fill the stockpile table.

The code calling Merchant.UI.DrawStockpileGrid is in Stockpile.lua, in function Merchant.UI.DrawStockpile, which is called by the three dropdown handlers Merchant.UI.Stockpile[Chars,Display,Filters]DropDownHandler. DrawStockpile is also called in the OnShow event handler of the global panel, in UI/Main.lua in Merchant.UI.Create function
Attached Files
File Type: zip merchant.zip (33.3 KB, 95 views)

Last edited by Zulu : 11-21-20 at 03:49 AM.
  Reply With Quote
11-21-20, 07:02 AM   #8
kurapica.igas
A Flamescale Wyrmkin
Join Date: Aug 2011
Posts: 142
The error is the usage about the ScrollFrame, you normally should use the FauxScrollFrameTemplate or take the logic part from that template to handle the scroll range changes.

Back to the code,

Stockpile_Grid.lua, line 62, comment or delete it :
Lua Code:
  1. --Merchant.UI.StockpileGridScrollFrameContent:SetHeight((32 + 10) * math.floor((Merchant.UI.StockpileStockCnt - 1) / Merchant.UI.StockpileGridMaxPerLine))

The size of the scroll child will changed based on the children on it(show /hide those children also affect the scroll range, there is no need to handle it by your own)

Stockpile.lua, line 149~167
Lua Code:
  1. Merchant.UI.StockpileGridScrollFrameSlider = CreateFrame("Slider", "$parentSlider", Merchant.UI.StockpileGridScrollFrame, "UIPanelScrollBarTemplate")
  2.   Merchant.UI.StockpileGridScrollFrameSlider:SetPoint("TOPLEFT", Merchant.UI.StockpileGridScrollFrame, "TOPRIGHT", -5, 0)
  3.   Merchant.UI.StockpileGridScrollFrameSlider:SetPoint("BOTTOMLEFT", Merchant.UI.StockpileGridScrollFrame, "BOTTOMRIGHT", 0, 0)
  4.   --Merchant.UI.StockpileGridScrollFrameSlider:SetMinMaxValues(0, 1000)
  5.   Merchant.UI.StockpileGridScrollFrameSlider:SetValueStep(1)
  6.   Merchant.UI.StockpileGridScrollFrameSlider:SetValue(0)
  7.   Merchant.UI.StockpileGridScrollFrameSlider:SetWidth(16)
  8.   Merchant.UI.StockpileGridScrollFrameSlider:SetScript("OnValueChanged", function(frame, value)
  9.     Merchant.UI.StockpileGridScrollRefresh(value)
  10.   end)
  11.   Merchant.UI.StockpileGridScrollFrameSliderBackground = Merchant.UI.StockpileGridScrollFrameSlider:CreateTexture(nil, "BACKGROUND")
  12.   Merchant.UI.StockpileGridScrollFrameSliderBackground:SetAllPoints(Merchant.UI.StockpileGridScrollFrameSlider)
  13.   Merchant.UI.StockpileGridScrollFrameSliderBackground:SetColorTexture(0, 0, 0, 0.4)
  14.   Merchant.UI.StockpileGridScrollFrameContent = CreateFrame("Frame", "$parentContent", Merchant.UI.StockpileGridScrollFrame)
  15.   Merchant.UI.StockpileGridScrollFrameContent:SetPoint("TOPLEFT")
  16.   --Merchant.UI.StockpileGridScrollFrameContent:SetPoint("TOPRIGHT")
  17.   --Merchant.UI.StockpileGridScrollFrameContent:SetHeight(0)
  18.   Merchant.UI.StockpileGridScrollFrameContent:SetSize(1, 1)
  19.   Merchant.UI.StockpileGridScrollFrame:SetScrollChild(Merchant.UI.StockpileGridScrollFrameContent)

Don't set the slider's range by your own, should be done by the scrollframe's OnScrollRangeChanged events.

Only need to set the scroll child to topleft, so the wow can handle it, and keep give it a init (1, 1) size to avoid some bugs.

The same file, line 242, you don't need to handle those by your own.
Lua Code:
  1. --Merchant.UI.StockpileGridScrollRefresh(0)

You'd better use the FauxScrollFrameTemplate, the scroll frame is a little complex widget.
Attached Files
File Type: zip merchant.zip (33.3 KB, 64 views)

Last edited by kurapica.igas : 11-21-20 at 07:05 AM.
  Reply With Quote
11-21-20, 10:57 AM   #9
Zulu
A Murloc Raider
Join Date: Nov 2020
Posts: 5
Thank you very much Kurapica !

I'm learning how to use FauxScrollFrame, I believe I'm starting to understand the philosphy and I like this simpler usage.

Last question: is FauxScrollFrameTemplate a deprecated feature ?

Last edited by Zulu : 11-21-20 at 11:01 AM.
  Reply With Quote
11-21-20, 11:08 AM   #10
kurapica.igas
A Flamescale Wyrmkin
Join Date: Aug 2011
Posts: 142
No, blz use it in many places, I also take its code to create my own template in pure Lua.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Fontstrings not displaying in certain cases

Thread Tools
Display Modes

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