Prof. Monster's Text Elements

Hi

Here is something for the Blenderheads who want to display text. (for 2.49 and 2.5)
TextElements



This are several GameObjects and Python module that provide you the possiblility to

  • use multi language text
  • switchable wordWrapping
  • smooth scrolling
  • dynamical limitation (hight and width)
  • switchable trailing (leading and trailing space while scrolling)
  • runs with bitmap text (2.5 without non-ascii characters)
  • runs with font object (only 2.5 but without CR)

Have a look at the demo file. Check the installation instructions!
Documentation cames later

Installation

  • all 4 textblocks “test_??.properties”
  • must be saved in the folder of the .blend file otherwise you do not get any text to see.

see post #4 for an alternative way to install the languages.

Usage
all Scenes:

  • e English
  • d German
  • p Polish
  • f French

Demo2 see in-game help:

The TextController and the TextViewer are part of groups that include a lot of logic.
Special logic (like user input) should be applid to the group instance.

Remarks:

  • The French and Polish translations are from Google translator. They might be a bit … incorrect ;).
  • The Polish language uses some characters that are not included in the bitmap font. They are displayed as something cryptical. I’m not sure if thatis fixable
  • In 2.50 it is not possible to use non-ascii characters. They are displayed as two other characters
  • In 2.50 font objects can be used. Unfortunately line breaks are not processed correctly.

I think I can prepare some more usage demos

Monster

[Edit]
ok, new upload this time with textures :eyebrowlift:

Attachments

TextBlock.blend (131 KB)

The Text Elements consists of severeal elements.
Each lement has it’s own things to do. They are quite flexible. You can replace one element with another.

TextController
The TextController loads the language files and stores their content in an TextSet at startup. A TextSet can be shared by multiple TextControllers.
Each TextController sets up one TextSource. The TextSource is identified by a textId. The textId is required to communicate with the TextViewer (see later).

The TextController takes an text key as input. The text key will be translated to full text in the current language. The TextController sends a message to the TextViewers. The subject is the associated text Id. The body is the full text. On language change or text key change the TextController sends the translated text.

Parameters:

  • languageFile
    [LIST]

  • the file name of the properties files. The text controller adds the language suffixes to it.

  • e.g. myText.properties -> reads all myText_??.properties

  • textId

  • identifies the TextSource and the TextViewers

  • messages with the full text in body contain the textId in subject

[/LIST]
Currently you have to setthe text key via Python (see Test.py)

Summary:

  1. language text read from files defined in langageFile
  2. text key change of language change --> lookup in language texts -> send to text viewers as message with textId as subject

Basic TextViewer:
The only purpose of a TextViewer is to show the text received in a message. Messages are filtered by subject. The subject must match a textId.
A TextViewer can be any Bitmap font object (plane with a text font) or a Font object (only usable in 2.5). The Textviewer just needs to listen to the filtered message (message sensor) and show the body of the message.

You can send any text to the TextViewer. It does not need to be a TextController (but you wouldn’t get multi language).

TextViewer:
The TextViewer provided in the demo file can do much more.

First the TextViewer is designed with a group. For identification reasons it needs a property “TextViewer” otherwise it can’t take over any parameter you set up.

The TextViewer dos not provide any font of bitmap font object (TextObject). You wouldn’t be able to access them (instance objects are not editable).
You can create your own TextObject. It must be exactly 2 BU in hight. You can scale it in object mode as much as you like. Parent the TextObject to the TextViewer. It will identify them automatically. You can even parent multiple TextObjects. but they will show the same text with the same format. You can use this to fake a shadow.

What can the TextViewer do what a basic TextViwer can’t?

  • wrapping words (line length limit)
  • limiting the number of displayed lines
  • smooth scrolling
  • switchable trailing space
  • distinguished by textId
  • returns the complete number of lines (important after wrapping)
  • returns the line number of the first displayed line
  • as all TextViewers: receives new text via a message

Parameters:

TextObjects as children:

  • Bitmap Text objects
    [LIST]

  • identified by the Property “Text”

  • Font objects

  • identified by attribute text (not property)

[/LIST]



Properties (on TextViewer):

  • TextViewer
    [LIST]

  • Identifies the TextViewer to take over the parameters (mandatory)

  • textId

  • the subject this TextViewer is listen for new texts

  • (Bug in 2.49: it is not possible to set subject of a message sensor. More logic is required.)

  • default is “default”

  • numLines

  • Return value only

  • contains the number of lines after wrapping

  • firstLine

  • the line number of the first visible line

  • is float for smooth scrolling

  • will be corrected after hitting the scrolling limits (return value)

  • 0.0 is the default

  • lineSize

  • the maximum number of characters in a line after wrapping

  • only valid when word wrap is True

  • no wrapping when zero or below (default)

  • maxLines

  • the maximum number of linesto be displayed

  • if zero or below zero all lines are displayed (default)

  • wordWrap

  • True = word wrap on (default)

  • False = no wrapping

  • trailingSpace

  • True = the text can scroll out of the display area

  • False = the text stays in the display area (default)

[/LIST]
Make it dynamic (optional):

If you change a parameter while running the game you need to notify the TextViewer with:
Property change sensor (true pulse)
—> Python controller Module: LinkLib.copyPropsToBaseThe return parameters are updated automatically by the TextViewer.

Issues:

Because of a bug you need to apply additionaly logic in 2.49:
Message sensor sensing for subject <value of textId>
----> Python controller Module:TextViewer.setViewerText

Because of a Bug in 2.5x (all versions) you can’t display non-ascii characters with bitmap text.

Because of a Bug in 2.59 you can’t display line breaks with font objects. They are displayed as square.

Not all non-ascii characters are supported by bitmap text (e.g. polish). This is because the bitmap text can’t contain all characters. But it looks like the character set is not correctly translated. French and German seems to be fine (in 2.49).

Font objects are not supported in 2.49.

Hints:

If you want to set up (auto) scrolling simply count the property firstLine. You can change it by a float value wich allows a quite smooth scrolling.

I hope you are not tired after reading this :wink:

Monster

that looks interesting!!
but i got some Error:

unable to initialize image(0) in MAFont.SlateGray, image will not be available
unable to initialize image(0) in MAFont.yellow, image will not be available

Did you forget to pack them, or did i mess it up? (i followed the instruction, it seems to work, but the letters are just white planes…)

You are right the textures were missing :(. But now they are included.

I also saw it is quite hard to extract the language files from the blend file.
So I packed them into this .zip file.

[Edit]
I just saw we can attach zip files - very cool :RocknRoll:- no renaming anymore :smiley:

Attachments

languages.zip (4.6 KB)

Very Useful !! Thanks for sharing, i guess i’ll try to import this into my Scrollbox Widget(coming soon…):spin:

Indeed,
for vertical scrolling you can set the property “firstLine” which is the top line (as float) of the displayed text.
Horizontal scrolling is currently not supported.
The complete length of the wrapped text is in property “numLines” (read only).

I’m preparing some documentation and some more examples.