Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Programming and Scripting
Problem with setting font with ccbSetSceneNodeProperty
Author Text

dekon_17
Registered User
Quote
2022-08-30 09:14:08

I was a bit tired of setting fonts all by myself and wanted to give people an ability to change the font to whatever they want to. All the localization files are separated from the game. But... Here's the thing.

Upon setting a font with a ccbSetSceneNodeProperty, the font is nothing like it is supposed to be. Just like that:
🔎︎


In this example, font on all the buttons (Move Forward, Jump and so on) except for the language switch one is changed. Thing is, the font is different (and it is the same no matter what font I've set in file) like it is supposed to be. Only thing that can change is its size. It is all correct (since I've copied it from editor). Am I doing something wrong here?


just_in_case
Moderator
Quote
2022-08-31 05:31:58

I am not sure but you also need to provide all the fonts that you are going to use to the end client it is required by the end client to install all of them to his PC.

And It is hard to say what's going on without actually looking at the code that changes the font. You probably are having some issues there.


veganpete
Registered User
Quote
2022-08-31 08:06:56

Not sure if this will help dekon_17, but I noticed in the past that any changes I make to fonts in a 2D overlay, will only be actioned if I have also filled in the "text" box of the node itself. If I leave the text field blank/empty (even If I update the text externally afterwards) - the font values/parameter are completely ignored whenever I try to change/update the 2D overlay...

🔎︎


Basically, try just adding some random text to the box and see if it starts working properly - only leave it blank/empty if you plan to use the overlay an image, rather than text.


dekon_17
Registered User
Quote
2022-08-31 08:54:05

Okay, so, here's how it works (and the entire code):

Text in "*" symbols is a description, so it doesn't matter.

First text from the file isconsidered as a node name. The node itself is recieved with ccbGetSceneNodeFromName function.

Text after the first "/" symbol is considered as content of this overlay (text).

And lastly, text after next "/" symbol is considered as the font.

Editing of one overlay ends with "|" symbol, after which it resets it's cycle for another node.

If there is no font, it will still work.

Here's the code:
var Content = ccbReadFileContent (this.File);
var Text = "";
var Array = ["Name", "Text", "Font"];
var Slashes = 0;
var Desc = false;
var CurrNode = null;

for (var C = 0; C < Content.length; C++)
{
var Char = Content.charAt (C);
if (Char == "*")
{
Desc = !Desc;
C++;
}

else if (Desc == false && Char != "\n")
{
if (Char == "/" || Char == "|")
{
if (Slashes == 0)
{
var CurrNode = ccbGetSceneNodeFromName (Text);
Text = "";
}
else if (CurrNode)
{
ccbSetSceneNodeProperty (CurrNode, Array [Slashes], Text);
Text = "";
}
Slashes += 1;

if (Char == "|")
{
var CurrNode = null;
Text = "";
var Slashes = 0;
C++;
}
}

if (Char != "/" && Char != "|" && Char != "*")
Text += Char;
}
}

And here's the example file (a part from my localization file):
*
Options tab
*
Sens/SENSITIVITY|
Sound/SOUND VOLUME|
Forw/MOVE FORWARD|
Back/MOVE BACKWARD|
Left/MOVE LEFT|
Right/MOVE RIGHT|
Dash/DASH|
Jump/JUMP|
FireP/FIRE PRIMARY|
FireS/FIRE SECONDARY|
DualWield/DUAL WIELD|
NWpn/NEXT WEAPON|
PWpn/PREVIOUS WEAPON|
Pause/PAUSE|
Use/USE|

There is no font setting. So, when I add it, it should look like this:
Use/USE/18; Consolas; Normal; Normal; Not Underlined; Modern|

Font was copied from the editor itself, so, it should be right.
Still, this issue happens, and I don't know why.
Thing is:
- I do have this font, as it is set in main menu (not options tab);
- Text is being added before the font.

So, both of the things are done exactly as you guys said. Is there something else?


VP
Guest
Quote
2022-08-31 12:46:48

I can't follow the code at all but: if the code is simply passing details to a 2D overlay node, it's possibly conflicting with the default settings of the overlay itself (ie: an empty text box field in the scene graph editor).

If the code is actually creating the overlay node and handling all attributes of the 2D overlay itself, that's above my skill level at the moment.

I did initially have exactly the same issue when trying to enter node names on a 2D overlay (for my weapons selection wheel), the font would not change to the size I had specified until I filled the text field and then everything worked as expected.

Might be a completely different issue your facing though.


dekon_17
Registered User
Quote
2022-08-31 13:36:12

No, VP, this doesn't create new objects, it overrides the initial parameters. I mean, it does work with text, both with english and russian. Only problem for me is the non-changeable font. So, I don't know clearly what the issue is. Still, I might just leave this not working now, since I have some... Other things to fix.


Robo
Guest
Quote
2022-09-02 02:43:34

From the code above the text wont change as using "ccbSetSceneNodeProperty (CurrNode, Array [Slashes], Text);" wont work - you need to have something like :

ccbSetSceneNodeProperty (CurrNode, "Text", Text);
ccbSetSceneNodeProperty (CurrNode, "Font", "10; Default; PBIO Bold; Normal; Bold; Not Underlined");


dekon_17
Registered User
Quote
2022-09-02 11:24:37

First of all, the way I made it does work for text. If this wouldn't work as well, I would also ask why can't it change the text. It doesn't work for fonts only.

Secondly, I tried to change the font by your method, and uhm... Here's the result:
🔎︎
Have I messed up the script or something?


just_in_case
Moderator
Quote
2022-09-06 10:20:54

yup, that's a bug you can't change the custom font that way. Might get fixed in future versions, I will look into this. Also, you might need to use the extra tag,
 Decorative; 
after the font size.


dekon_17
Registered User
Quote
2022-09-06 13:05:02

Well, that's unfortunate. Then, I hope it will be fixed soon.


just_in_case
Moderator
Quote
2022-09-07 03:23:21

Well, by bug I meant to say, that you need to put the FontFamily first not the the FaceName. If you do so, then the font will change as expected.

Correct order of changing the font is as follows.

Point Size
Family (Default|Decorative|Roman|Script|Swiss|Modern)
Face Name (Arial etc)
Style (Normal|Slant|Italic)
Weight (Normal|Light|Bold)
Underlined (True|false)


while in editor it shows the fontfamily in the last. So I was talking about that, that is why I asked you to put "decorative" in between your fontsize and facename.
the code itself works fine.

try using
 var s = ccbGetSceneNodeFromName("overlay");
ccbSetSceneNodeProperty(s,"Font","14; Normal; Chiller; Normal; Not Underlined;");


and this code will change your font just fine, Also always make sure that the string ends with a semicolon, ; otherwise it won't work. @robo code seems correct except that it has no semicolon after Not Underlined so it will never change the font and will show the default font.

These are some things to keep in mind while working with fonts in CC.

Hopefully, the font-family will be added as the last object, so that there will be no mismatch.

Hope this helps


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© 2020 Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact