HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Substituting Custom Fonts  (Read 2055 times)

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Substituting Custom Fonts
« on: May 20, 16, 05:15:18 AM »

Firstly
According to the Wiki:

LoadFontResource() does NO LONGER WORK it is deprecated.


*****************************
So,

Step 1


upload your custom myFont.ttf to the repository /HE/GUI/fonts/ folder
if you do not have a "fonts" subfolder inside GUI folder, create one.

Fonts are automatically loaded from this folder when the blade/client is loaded.

Now, this explanation will focus on replacing a default font with your custom font.

We will replace "GAMETEXT" with the new one.

First a NOTE regarding what the wiki says about this:
The article on the wiki is sadly one, which is out of date, no worries, the following should help you get your fonts up and running smoothly, without crashing your blade/client and locking you out of it.


Step 2

Open your E_BaseClientClassMethods script on the CLIENT side.
If you chose to create an alternate override for the _BaseClient class, open that instead.

Now, you'll need to determine the location to insert your font substitution.

The substitution MUST take place AFTER the GUI has been loaded.

For our example, we use a splash screen which is destroyed only after the character is ready and the GUI has been created and displayed.  So we call for font substitution immediately before destroying the splash screen.

we do so by calling the following:
SubstituteFont("GAMETEXT", "/GUI/fonts/Germanica.ttf")

and all controls which use the GAMETEXT font are changed to our custom font.
This substitution appears to remain until the blade/client is closed, and so only needs to be called
once, unless you need to change it again during runtime.

If i find a better suitable location to call it from SAFELY I'll update it here, or if you know of a better suitable location feel free to reply to this.



Via HSL:

Alternatively, you can also change the font on an individual GUI control from HSL as follows:
Code: [Select]
var gui = FindGUIControlByName(0,"mycontrol")
gui.fontface = "/GUI/fonts/Germanica.ttf"




« Last Edit: May 20, 16, 05:39:43 AM by ToY-Krun »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1405
    • View Profile
    • Forever Interactive, Inc.
Re: Substituting Custom Fonts
« Reply #1 on: May 20, 16, 02:40:30 PM »

We also use SubstituteFont() and we call it inside of the method method HE_FirstChance() of the class we have glommed onto the $BASECLIENT system node, which works fine.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Substituting Custom Fonts
« Reply #2 on: May 20, 16, 07:50:05 PM »

Yeah it may or may not, depending on your game/server etc and how the GUI is designed.  And also what fonts you have loaded prior to it being called.

This wasn't just posted for an FYI.  Its in response to the issues it has caused others, so be fairly warned :P
If SubstituteFont() fails, its a ctd. (this tested on a clean engine world)

What prompted this post was,  a major issue on other worlds with crashes upon calling it.

To be safe (unless you are already successfully doing so) don't call within the first chance as GUI's/fonts are not guaranteed to be loaded yet.

Also a further note, the font enum value you're addressing to substitute should be one of the default fonts such as "DEFAULTTEXT"/"GAMETEXT" etc., otherwise it will crash the blade/client.  At one time you could add a new value to the "font" enum and substitute that value with your custom font.  this is no longer the case.

The reason for this notice and the caution against using it in a function such as FirstChance() is due to the nature of the FirstChance() function being loaded on client load up.  If it fails, you'll have to deal with reverting the proper script in the repo to get the client working again, which can be a mess.

Safest Option:  Don't do eet :)

If you have it working, I would still take some precautions and at the very least ensure SubstituteFont() isnt called prior to loading to Character Select so that you always have the ability to login and make changes as needed.

This isn't something caused by the latest update, this is something that simply hasn't been used by many people and hasn't seen the testing that much of the other systems have over the last year, and so just now got really noticed.

Thanks

« Last Edit: May 20, 16, 07:56:18 PM by ToY-Krun »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1405
    • View Profile
    • Forever Interactive, Inc.
Re: Substituting Custom Fonts
« Reply #3 on: May 20, 16, 08:00:56 PM »

Would you clarify where you call it, i.e. what is telling you that the character is ready and gui created.  Is it in response to a clean engine method callback?
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Substituting Custom Fonts
« Reply #4 on: May 20, 16, 08:20:13 PM »

Quote
For our example, we use a splash screen which is destroyed only after the character is ready and the GUI has been created and displayed.  So we call for font substitution immediately before destroying the splash screen.

Thanks Scott, that does bear some clarification, I had been up most of the night when I wrote that and was making some assumptions :)

SERVER SIDE:

_AccountClassMethods: _CharacterActivated is called when character has been activated.
It checks for an override called HE_PostCharacterActivated which you'll find in the E_AccountClassMethods.

in the E_AccountClassMethods script Method HE_PostCharacterActivated() after dealing with all else, I send a call to the client to destroy the splash screen.  When this method runs on the server the server has been told the character is ready.


CLIENT SIDE:

the client method we call to destroy the splash screen is :
_baseClientClassMethods:Remote Unique Method _DestroySplashScreen()
Which we have overriden in our E_BaseClientClassMethods script.

HE_DestroySplashScreen( )

within this method we call the substituteFont() function as long as it isn't areaID 1 which is the character selection area.

Thazager

  • General Accounts
  • *
  • Posts: 1129
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Substituting Custom Fonts
« Reply #5 on: May 23, 16, 07:20:02 PM »

We also had it here

method HE_FirstChance( ) as Boolean
  SubstituteFont(LARGETEXT, "GUI/fonts/Xolonium-Regular.otf" )
  return false
.

and its been working since it was added.

I recently tried putting it here

method HE_DestroySplashScreen( ) as Boolean
  SubstituteFont(LARGETEXT, "GUI/fonts/Xolonium-Regular.otf" )
  return false
.

but that seems to have messed up many other things in the GUIs we had, including stuff that would not seem effected by it. So I had to put it back where it was working again. Perhaps I missed a step or 2 from 1st post.
Logged

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Substituting Custom Fonts
« Reply #6 on: May 23, 16, 08:26:32 PM »

We spent a while tracking this down.  we tested it on several worlds to confirm, one was a clean one.
If your world was originally an HE1 world, then its possible thats why it works for you.


Tested on HE2 worlds:
calling SubstituteFont() before GUI's are loaded results in a crash to desktop.
With no error, in debug or in logs.

the reason for the warning is that if you call it from a location that gets called for every area change (for example FirstChance())  and it "does" cause the crash, you won't be able to log back into the game, even to the point where you can alter the script the normal way.  In such a scenario you would have to work your way through the compiled scripts in the repository and hope you can find it to revert the change.

The world which discovered the problem was moving their code from an HE1 world to an entirely new HE2 world.
Its possible the newer worlds might have this issue where the older ones might not.
Our world is 3 years old, and in testing , _FirstChance() is definitely not an option for us.

IF you have it working, then you don't need this tutorial anyway :)
If the caution isn't included, and then we get more bug reports and say "oh yeah, by the way....."
it just looks better to add the precaution up front :P

Thazager

  • General Accounts
  • *
  • Posts: 1129
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Substituting Custom Fonts
« Reply #7 on: Oct 08, 16, 09:12:51 PM »

when adding a font using SubstituteFont(), and looking thru the c:\Windows\fonts directory, right click on the font, then select Properties, on general tab it will have the name to use in the textbox at top.

example: for Arial Black, use   ariblk

    SubstituteFont(DEFAULT, "ariblk")

example: for Courier New Bold, use   courbd

    SubstituteFont(JUMBO, "courbd")

Logged

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Substituting Custom Fonts
« Reply #8 on: Oct 13, 16, 03:11:47 PM »

nice find Thaz!