WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   fontString:SetFont() (https://www.wowinterface.com/forums/showthread.php?t=59542)

Platine 03-28-23 02:51 AM

fontString:SetFont()
 
I have an object from game to which I assign text:
Code:

object:SetText("my text")
I can also assign a font to it right away:
Code:

object:SetFont(My_Font, size)
But some objects don't allow me to assign a font so explicitly:
Quote:

attempt to call method "SetFont" (a nill value)
The object receives, for example, the function:
Code:

for _,GTxtframe in GossipFrame.GreetingPanel.ScrollBox:EnumerateFrames() do
How to specify the exact name of the fontString element of object?

Platine 03-29-23 12:25 AM

Here's the code snippet I'm having problems with:
Code:

      for _,GTxtframe in GossipFrame.GreetingPanel.ScrollBox:EnumerateFrames() do
        if (GTxtframe.GreetingText) then    -- Greeting Text
            GTxtframe.GreetingText:SetText(Greeting_PL);
            GTxtframe.GreetingText:SetFont(QTR_Font2, 13);
        elseif (GTxtframe.GetElementData().buttonType==3) then  -- Options
            GTxtframe:SetText(GS_Gossip[OptHash]);
            GTxtframe:SetFont(QTR_Font2, 13);    -- ERROR: attempt to call method "SetFont" (a nill value)
        end
      end

It's similar here:
Code:

      for GText in QuestFrameGreetingPanel.titleButtonPool:EnumerateActive() do
          GText:SetText(prefix .. GS_Gossip[TitleHash] .. sufix);
          GText:SetFont(QTR_Font2, 13);        -- ERROR: attempt to call method "SetFont" (a nill value)
      end


Fizzlemizz 03-29-23 09:18 AM

That's because the widget type you're "getting" is a Button. Buttons don't have a SetText or Setfont method by default but in some case they are "given" a SetText method to update a FontString they have also been given.
Lua Code:
  1. local Button = CreateFrame("Button", "SomeButton", UIParent)
  2. Button.Text = Button:CreateFontString(GameFontNormal)
  3. Button.Text:SetPoint("CENTER")
  4. function Button:SetText(text)
  5.     self.Text:SetText(text)
  6. end

You can
Code:

Button:SetText("Something")
but you can't
Code:

Button:SetFont(SomeFont)
but you could
Code:

Button.Text:SetFont(SomeFont)
In this case, you need to find the FontString "sub-widget" of GTxtframe you want to effect (like .GreetingText, it may be something other than .Text).

Fizzlemizz 03-29-23 11:42 AM

Taking a look at the templates you could probably use:
Lua Code:
  1. for _,GTxtframe in GossipFrame.GreetingPanel.ScrollBox:EnumerateFrames() do
  2.     if (GTxtframe.GreetingText) then    -- Greeting Text
  3.         GTxtframe.GreetingText:SetText(Greeting_PL);
  4.         GTxtframe.GreetingText:SetFont(QTR_Font2, 13);
  5.     elseif (GTxtframe.GetElementData().buttonType==GOSSIP_BUTTON_TYPE_OPTION) then   -- Options
  6.         GTxtframe:SetText(GS_Gossip[OptHash]);
  7.         local regions = { GTxtframe:GetRegions() }
  8.         for k, v in pairs(regions) do
  9.             if v:GetObjectType() == "FontString" then
  10.                 v:SetFont(QTR_Font2, 13)
  11.             end
  12.         end
  13.     end
  14. end

Platine 03-31-23 03:23 AM

Yes, yes. I searched for this FontString object by different names e.g. .Text, .text, .title etc. But nothing matched. But regions, it's the perfect method. I didn't come up with it before.

Your code works perfectly.
Thank you Fizzlemizz for your help.

Fizzlemizz 03-31-23 08:44 AM

Quote:

Originally Posted by Platine (Post 342298)
Yes, yes. I searched for this FontString object by different names e.g. .Text, .text, .title etc. But nothing matched.

In the XML for the template it's just a
Code:

<ButtonText>
    ...
</ButtonText>

With no name or parentKey attribute to use, you just have to search the child regions of the parent frame and hope there is some easy way to identiy what you want, like being the only FontString child.


All times are GMT -6. The time now is 09:26 AM.

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