Changing background color of label during game?

Is there a way to change the color of the background for a Text Label during gameplay? (I know it can be done by editing the module, but the functionality I’m looking for would let a player change during a game, from a list of available options). Thanks for any thoughts.

–Dave Conn

You could try enabling HTML (I think it is enabled by default), and then set your Text Label to <html><span style="background-color:$bgcolor$;">My text here</span></html>, and then create a Dynamic Property “bgcolor” to hold the background color. However, I’m not certain if the ancient HTML parser in VASSAL supports CSS, so this might not work. I don’t think you can change the background color of a text element with plain HTML, unfortunately.

As an alternative (might be easier, actually), you could add a Layer trait to the piece with the text label, and just make images that are the different background colors you want, and then change the active layer to change the background color. The problem with this method is the image size will be fixed, so if your text label varies in size, the background won’t always match.

I used this expression (which is similar, but works on the text rather than the background) for the text color:

{"<html><span style="+ '"' + "color:" + CharterTextColor + ";" + '"' + ">" + "Shares "+GetProperty(Tag+Tag+"Shares") + "</span></html>"},

and it seems to work fine.

Note: the expression is for a text label reporting the number of shares in a railroad’s treasury and displays on that company’s charter. The variable color is so that the text color of the label matches the predominate text color on the charter which varies by company. The property Tag is an abbreviation identifying the company like SP for Southern Pacific.

Thanks for the ideas; I hadn’t thought of using the Layer trait, but I think that will work (even though there is some variation in the Text Label length). I will likely try that, since I am not very comfortable yet fiddling around with HTML.

–Dave

1 Like