Jump to content

InternalText changes KSP 1.2.2 to KSP 1.3.0?


Recommended Posts

When Mihara implemented some of the early text rendering in RasterPropMonitor, he used KSP's InternalText.  That worked fine through 1.2.2, even with the switch to TMPro in that release (or whenever that was).  However, it looks like something changed with 1.3.0 - the text rendered with InternalText is now drawing like it's configured as a vertical advance text (eg Japanese) instead horizontal (eg English).  The code on my end that initializes it didn't change (there's not much to the initializer):

float fontSize = (a KSP field)
string transformName = (a KSP field)

Transform textObjTransform = internalProp.FindModelTransform(transformName);
textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform);

I'm hoping @JPLRepo or someone with some insight into TMPro and the localization changes in KSP can point me in the right direction - what knob do I need to set now to make this text render left-to-right?

 

Link to comment
Share on other sites

16 hours ago, MOARdV said:

When Mihara implemented some of the early text rendering in RasterPropMonitor, he used KSP's InternalText.  That worked fine through 1.2.2, even with the switch to TMPro in that release (or whenever that was).  However, it looks like something changed with 1.3.0 - the text rendered with InternalText is now drawing like it's configured as a vertical advance text (eg Japanese) instead horizontal (eg English).  The code on my end that initializes it didn't change (there's not much to the initializer):


float fontSize = (a KSP field)
string transformName = (a KSP field)

Transform textObjTransform = internalProp.FindModelTransform(transformName);
textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform);

I'm hoping @JPLRepo or someone with some insight into TMPro and the localization changes in KSP can point me in the right direction - what knob do I need to set now to make this text render left-to-right?

 

Yes I think this one might have slipped through.
Try this and let me know how you go.

So try using:

textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform, "", Color.Green, false, "TopLeft");

This creates a TMPro text element using the base underlying method (that you were calling) but also adds the TMPro text element. You don't have to set textString, color, etc on the initial call other than a default.
You can adjust the text element on the InternalText that is returned through the textObj.text field - which is a TMPro text element.
eg:

textObj.text.enableWordWrapping = true;
textObj.text.color = Color.Red;
textObj.text.text = "This is a test string";


The following are valid Values for the last variable in that call which is the TextAligment:

"TopLeft", "BottomLeft", "MidlineLeft", "Left", "Center", "Top", "TopGeoAligned", "CenterGeoAligned", "BottomGeoAligned"


(EDIT) - Just to explain why. The base method JSI was using used to work and now doesn't because of the font changes for Localization. If you still have alignment issues let me know and I can take a closer look.
I'm guessing because I only quickly looked at it but I think the problem is enableWordWrapping = true by default. try it with it set to false.

Link to comment
Share on other sites

9 hours ago, JPLRepo said:

(EDIT) - Just to explain why. The base method JSI was using used to work and now doesn't because of the font changes for Localization. If you still have alignment issues let me know and I can take a closer look.
I'm guessing because I only quickly looked at it but I think the problem is enableWordWrapping = true by default. try it with it set to false.

Yeah, I figured the localization changes were at fault. :)

Using the CreateText with the additional parameters fixes the problem, which is "Not Just Good, It's Good Enough" (TM).

Now I need to find out why a Mac no longer finds an Arial font.  I used to be able to load an "Arial" font cross-platform, and it would work.  Or is that because the fallback font's not being included now because of the TMPro change?

Link to comment
Share on other sites

7 hours ago, MOARdV said:

Yeah, I figured the localization changes were at fault. :)

Using the CreateText with the additional parameters fixes the problem, which is "Not Just Good, It's Good Enough" (TM).

Now I need to find out why a Mac no longer finds an Arial font.  I used to be able to load an "Arial" font cross-platform, and it would work.  Or is that because the fallback font's not being included now because of the TMPro change?

The InternalText component above uses a class construct to name a font "Arial" in InternalText.fontName. But actually that is just a name. The actual font is part of the text element in that class which is TMPro and the new NotoSans font for Localization.
The InternalComponents.Instance.textPrefabs contains the "TextArial" prefab which is used when calling InternalComponents.Instance.CreateText.
To properly support localization the font would be "NotoSans-Regular SDF". There is still an "Arial SDF" and "Calibri SDF". But they are all TMP fonts now.
 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...