Tooltips, multi language support, and lua

Discussion about Mods for Prison Architect

Moderator: NBJeff

murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Tooltips, multi language support, and lua

Postby murgh » Fri Aug 12, 2016 7:30 pm

I'm having a hard time figuring out how to get multi language support into tooltips when the tooltips also have some variables...

This works fine:

Code: Select all

in base-language.txt
tooltip_mine      This is my tooltip

in the .lua script:
Object.SetProperty(this,"Tooltip","tooltip_mine")


However, when a tooltip contains other stuff as well, it seems impossible to get it in there?

It works fine for buttons, here is the snip from the post in another topic:
You can put flags into your interface buttons and captions in the same way other language strings work. If you have a language string file that contains

Code: Select all

my_language_string            This is *X string
my_language_string_my         my


In the lua code you can do any of the following:

Code: Select all

- Interface.AddComponent( "MyButton", "Button", "my_language_string", "my_language_string_my", "X" )                  -- Caption is set to "This is my string"
- Interface.AddComponent( "MyButton", "Button", "my_language_string", "your", "X" )                                 -- Caption is set to "This is your string"
- Interface.AddComponent( "MyButton", "Button", "my_language_string", 4, "X" )                                       -- Caption is set to "This is 4 string"


You can also include multiple flags in the same string

Code: Select all

my_other_string          This is *X other *Y

for example.



But trying to do stuff like that for a tooltip setting like this:

Code: Select all

Object.SetProperty(this,"Tooltip", "Used by Utility Booth nr. "..this.HomeUID.."\n\nClick me for more options")

is what all the brain damage is about.

So far I've tried this for base-language.txt:

Code: Select all

tooltip_clickforoptions               Used by Utility Booth nr. *X\n\nClick me for more options



... and then these failed attempts in the .lua script:

Code: Select all

Object.SetProperty(this,"Tooltip","tooltip_clickforoptions",this.HomeUID,"X")
Object.SetProperty(this,"Tooltip","tooltip_clickforoptions"..this.HomeUID.."X")
Object.SetProperty(this,"Tooltip","tooltip_clickforoptions,this.HomeUID,X")
Object.SetProperty(this,"Tooltip",tooltip_clickforoptions,this.HomeUID,X)

this.Tooltip = "tooltip_clickforoptions",this.HomeUID,"X"
this.Tooltip = ("tooltip_clickforoptions",this.HomeUID,"X")
this.Tooltip = "tooltip_clickforoptions"..this.HomeUID.."X"

Object.SetInterfaceCaption(this,"Tooltip","tooltip_clickforoptions",this.HomeUID,"X")

Object.SetProperty(this,"Tooltip",string.format("tooltip_clickforoptions",this.HomeUID,"X")
Object.SetProperty(this,"Tooltip",string.format("tooltip_clickforoptions",this.HomeUID)

local tmptooltip = string.format("tooltip_clickforoptions",this.HomeUID)
Object.SetProperty(this,"Tooltip",tmptooltip)


But all of the options above either output this:

Code: Select all

Used by Utility Booth nr. *X

Click me for more options

or this

Code: Select all

tooltip_clickforoptions62352X

(where the number represents the HomeUID number)

One interesting line I tried was:

Code: Select all

Object.SetProperty(this,"Tooltip",string.format("tooltip click for %d options",this.HomeUID))

it will output

Code: Select all

tooltip click for 62352 options


But when trying to use %d in the base-language file like this

Code: Select all

tooltip_clickforoptions               Used by Utility Booth nr. %d\n\nClick me for more options

with code like this

Code: Select all

Object.SetProperty(this,"Tooltip",string.format("tooltip_clickforoptions",this.HomeUID)

it will output

Code: Select all

Used by Utility Booth nr. %d

Click me for more options

And unfortunately pumping the tooltip in another variable first wont help, so we get same results from above when using these two lines:

Code: Select all

local tmptooltip = "tooltip_clickforoptions"
Object.SetProperty(this,"Tooltip",string.format(tmptooltip,this.HomeUID))


Also merging the tips together like this

Code: Select all

Object.SetProperty(this,"Tooltip","tooltip_usedbybooth"..this.HomeUID.."tooltip_clickforoptions")

Does not work... it will output

Code: Select all

tooltip_usedbybooth62352tooltip_clickforoptions



Any suggestions are very welcome, I haven't seen mods yet using this kind of stuff...
And when you got the simple example above to work, have a crack on this one as well:

Code: Select all

Object.SetProperty(this,"Tooltip", "Used by Utility Booth nr. "..this.HomeUID.."\n\nFIRE DETECTED!\nSending "..entity.Category.." "..entity.Type.." at "..string.sub(tostring(_),0,4).."m\nto the Evacuation Area")


The base-language.txt entry you'll get for free (I'm guessing it's this):

Code: Select all

tooltip_evacprisoner                         Used by Utility Booth nr. *W\n\nSending *X *Y at *Zm\nto the Evacuation Area

..but how on earth get that into a tooltip? :shock:
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Re: Tooltips, multi language support, and lua

Postby elDiablo » Mon Aug 15, 2016 2:12 pm

For various reasons (how we hold the tooltip, how we do marker replacements, etc.) this doesn't work at the moment. So I've changed the behaviour of this.Tooltip for scripted objects (and objectTable.Tooltip in the general case of WorldObjects). In the next update you'll be able to do the following

Code: Select all

   this.Tooltip = "my_caption"        -- Set the tooltip to be the language string "my_caption"
   this.Tooltip = "a string I wrote"  -- Set the tooltip to be the literal string "a string I wrote"
   this.Tooltip = {
         "my_test_string",            -- captionId in the language file
         "replacement_string1", "X",  -- Replace *X with the language file string 'replacement_string1'
         "a string", "Y",             -- Replace *Y with the literal string "a string"
         2, "Z"                       -- Replace *Z with the number 2
      }
      
   myPrisoner.Tooltip = { "my_prisoner_string", myVar, "X" }


Though please note that objectTable.SetProperty( "Tooltip", "string" ) won't work in the same way. This should help you out soon!
murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Re: Tooltips, multi language support, and lua

Postby murgh » Mon Aug 15, 2016 4:18 pm

Thank god, I thought I was going completely nuts for not being able to get it to work. Thanks a lot, looks like that code will do just what's needed!
murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Re: Tooltips, multi language support, and lua

Postby murgh » Mon Aug 15, 2016 4:50 pm

So then the final example line

Code: Select all

Object.SetProperty(this,"Tooltip", "Used by Utility Booth nr. "..this.HomeUID.."\n\nFIRE DETECTED!\nSending "..entity.Category.." "..entity.Type.." at "..string.sub(tostring(_),0,4).."m\nto the Evacuation Area")

can become:

Code: Select all

this.Tooltip={"tooltip_evacprisoner",this.HomeUID,"W,entity.Category,"X",entity.Type,"Y",string.sub(tostring(_)0,4),"Z"}

or also:

Code: Select all

this.Tooltip={"tooltip_usedby",this.HomeUID,"W","tooltip_firedetectsend",entity.Category,"X",entity.Type,"Y","tooltip_at",string.sub(tostring(_),0,4),"Z","tooltip_toarea"}


Correct?
Profit!

Is there a limit on how many of those arguments can be put together in one tooltip? I'm assuming it's 26 -> *A up to *Z.
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Re: Tooltips, multi language support, and lua

Postby elDiablo » Tue Aug 16, 2016 8:45 am

Code: Select all

this.Tooltip={"tooltip_usedby",this.HomeUID,"W","tooltip_firedetectsend",entity.Category,"X",entity.Type,"Y","tooltip_at",string.sub(tostring(_),0,4),"Z","tooltip_toarea"}


is wrong. You need it in the order

Code: Select all

this.Tooltip = { "caption_string_id", variable1, flag1, variable2, flag2, variable3, flag3, ... }


Where all the flags are single letter strings (we use the first character in the string to determine the flag char) and variables are either a string id, a string, or a number.
murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Re: Tooltips, multi language support, and lua

Postby murgh » Tue Aug 16, 2016 9:33 am

That makes sense. And keeps the tooltip from getting a mess as well :p

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 4 guests