[PYTHON] MainInterface question - can't get rid of '+'

Maniac

Apolyton Sage
Joined
Nov 27, 2004
Messages
5,588
Location
Gent, Belgium
Hi all.

I have modified a little something in the MainInterface python file of the Planetfall mod.

A predecessor added this line among some other code, in order to show the Flowering Counter value on the main screen:

Code:
screen.setLabel("PlanetValueLabel", "", u"<font=4>%d</font>" % gc.getGame().getPlanetValue(), CvUtil.FONT_RIGHT_JUSTIFY, 240, 5, 0, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_HELP_PLANET_VALUE, -1, -1)

As, thanks to Shakiko, there is now a gamefont icon available to represent the Flowering Counter, I wanted to modify this line to add a symbol behind it.

I did it like this:

Code:
screen.setLabel("PlanetValueLabel", "", u"<font=4>" + localText.getText("TXT_KEY_FLOWERING_COUNTER" , (gc.getGame().getPlanetValue(), )) + u"</font>", CvUtil.FONT_RIGHT_JUSTIFY, 240, 5, 0, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_HELP_PLANET_VALUE, -1, -1)

The txt string is:

Code:
<Tag>TXT_KEY_FLOWERING_COUNTER</Tag>
<English>%D1_Change&#8706;</English>

Edit: Um, the forum automatically converts the symbol code &# 8706 ; in something wrong. But anyway, that's not the problem. The icon shows up fine and all that. No problem there. There is an unintended side-effect though. While previously the number showed up without anything else, now it shows up with a plus in front of it. I don't like that because:
1) The Flowering Counter can never go under zero anyway;
2) It takes up valuable interface space. I have plans to add another value to the left of the Flowering Counter. Looks like there may be some overlap with that plus present.

I've tried putting the flowering value between abs(), but the plus still stays.

So does anyone know how to get rid of that + ??

Thanks. :)

PS: What's the deal with those % btw (as in u"%d" % blah)? What are those for? Does that remove the plus? Can those be combined with a txt string? My attempts gave some errors.
 
Use a lower case d instead of an upper case D in your Text.xml file.

The % signs mean that the next character tells it to fetch something and shouldn't be printed. %d means an integer, %s means a string, %f.2 would mean a float and you want it to show 2 decimals... not entirely sure I am formatting the float one right, don't use them quite so often so always have a side-reference when I do. %c means a character.

Those are for python mostly (nearly the same in SDK, and the % after you close paranthesis indicates that you are starting to list all the things you claimed you would provide. The order you list them in needs to be the same as the order you called for them in), for XML I don't think you can use the float command at all. And it changes so that you can use %d to indicate a number (it will show - for a negative), %D to indicate a number AND state the sign of it (+/-), %s means a string, %c means a character.

For XML though you also have to state which of the values that were sent to you you want to use, hence the number which comes next. After the number you can use an underscore and any text you want to indicate what you are doing and the program ignores all of that.


So:

%d1_BigNumber / %d2_SmallNumber

Would display 2 numbers, which presumably would make a mixed fraction: ie - 5/3

You could also write:

%d2_BigNumber / %d1_SmallNumber

And since the number you used (1 or 2) is all that matters to the program, and you sent it the numbers 5 and 3 (in that order) you will wind up displaying:

3/5

So knowing the order of what is passed to you is important, and having the purpose there is a nice bonus, but easily can be misleading if you try to be too precise. A better way to state it would be:

%d1_CityPopulation / %d2_UnitsGarrisoned

Or whatever you happened to be sending in.
 
Use a lower case d instead of an upper case D in your Text.xml file.

:eek: Wow, thanks. Never would have guessed that was the solution.

Thanks for the further explanation.

Regarding floats, I noticed that Firaxis uses %s in the XML. For the feature healthpercent txtstring for instance. When I used %d (or %D, can't remember 'cause I didn't know that made a difference) for some similar feature cityplanetpercent txtstring, the game displayed some randomly large number.
 
Yeah, you need string for floats in XML. Forgot about that one, ran into it a couple of times. Quite a PITA really to deal with floats at all, and supposedly a major source of possible OOS issues when the players have different OSs (which might be why Firaxis avoided it so much)
 
Top Bottom