Click on String

The basis of the work described on this page is to extend OpenTTD so that it is possible to detect which part of a string that was clicked. Basically, was the town name in this string clicked? Yes? Lets view that town in the main viewport then. The final goal is that this functionality will be available for GUIs that display text from GameScripts. But as you can see in the Roadmap below, there will probably be two feature patches before that.

This screenshot shows a work-in-progress version of the functionality added by the click-on-chat patch: /File/en/Development/Design Drafts/Scripts/Click-town-names-in-chat.png

Contents

Roadmap

Framework concepts

Click control chars (added in patch 10)

In raw UTF8 strings, character 0xE300 to 0xE3FF are used to indicate start/stop of clickable text. There are up to 255 clickable text areas within a string. The same code is used to both start and end a cilck area. For example for click area #0, 0xE300 is used both to start and terminate that click area.

For the most basic usage of this framework, insert two 0xE300 characters into a string using eg. Utf8InsertChar(). Then when a click event is received, call GetStringParamAtCursor. If it returns 0, the text between the two 0xE300 characters was clicked.

(note in the current patch, these control chars are named as string-parameter control codes. I think I will change the naming of them to "click codes" or similar to not make them refer to string parameters as at this raw level they have no connection to the string parameter system in OpenTTD.

String parameters (patch 30)

On top of the click control characters, I'm thinking about adding code can inject click control chars before/after a string parameter. An alternative to this would be to introduce {CLICK1}, {CLICK2}, {CLICK3}, .. and require these to be included in english.txt and all translations. The later may add too much burden for translators but is an alternative solution worth mentioning.

Other than being a new way to inject 0xE00 to 0xEFF, which is useful for translatable strings, this part doesn't add anything more new than that.

Although, an extension to the basic idea could be a method that look on the type of string parameter and provide a default action based on the parameter type. Eg. View town, View industry, etc. which may be useful already for OpenTTD strings. (if not, it will be needed for GameScript strings)

GameScript parameters (patch 50)

This part will be described further when it has been implemented.

Patches

http://devs.openttd.org/~zuu/click-on-string/