Tooltips with dynamic content

Game development with Board Game Arena Studio
Post Reply
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

Tooltips with dynamic content

Post by apollo1001 »

Okay, so I'm starting to look at polishing the game up a bit and I thought I'd start with the tooltips.

I was previously using something similar to:

Code: Select all

this.addTooltipToClass( 'possibleLocation', '', _('Place a worker here to activate the tile<hr>') );
Whilst I would still like to add these tool tips to my tiles, they overwrites the standard tool tips I have now created (and I can't see an appendTooltipToClass option instead).

I have now got my standard tooltips set up:

Code: Select all

var html = '<div id="help_' + tid + '"></div>Tooltip for tile ' + tid + '<hr><div class="tile tile_' + tid + '_' + side + '"></div>';
this.addTooltipHtml( 'tile_' + tid, html, '');
but when I attempt to update the helper div with:

Code: Select all

$('help_' + possibleLocations[ x ].id).innerHTML = 'Place a worker here to activate the tile<hr>';
I get

Code: Select all

Cannot set property 'innerHTML' of null
I'm clearly missing something straightforward: any ideas?
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: Tooltips with dynamic content

Post by pikiou »

I guess the tooltip is saved as a Javascript object, not a hidden HTML element.
There is no way to modify a tooltip created using the BGA tooltip helpers. I mean you probably can, but it'll require hacking pretty deep under the hood, and have everything fall apart when admins change the tooltip helper :/

Instead you'll have to save the content of each created tooltip to eventually concatenate it with new content when you need to update it (by destroying and re-creating its tooltip). I don't know how you'll manage if you want to remove the freshly added tooltip content, though...
I opted for a complete wipe of all tooltips at the end of each and every state so I don't forget to remove tooltip content. To make it work I had to add tooltips in onEnteringState instead of doing it in the setup function. That way, new HTML elements added to the table get their tooltip (if any) at the start of the next state, so I don't forget to add tooltips either.

In active states especially when I want to change things only during that state (set or change an element CSS class, style or event trigger), I have other tools to handle the removing for me, but it's bad practice to have such tools on BGA projects so I'll keep them to me :P
Post Reply

Return to “Developers”