How do I display text and values in the game screens.

Harrier

Deity
Joined
Feb 19, 2002
Messages
2,424
Location
UK
I have scanned the tutorials but can not find an answer.

So how can I display text on a game screen.

Main screen or any F key screen.

i.e. Just display "Hello World"

Also how do I display a value. Such as the units cost per turn on another screen.

Can I do this without access to the SDK or the C++ language.

Can it be done by editting just python and XML?

Any help will be appreciated.
 
Can definitely be done in Python. I would suggest using the CyInterface.addImmediateMessage( 'Hello World', '' ) function. You can look for other Python functions here.

This will produce a message in white in the messages area (where you see combat and other announcements). You'll need to tie it to some game event using Python. I suggest checking out other peoples code to learn how. A very useful related piece of code you can use is DrElmerGiggles CustomEventManager ... it's part of the Civ4lerts mod component, also listed standalone I think in the mod components sub-forum.

To get things to show up in different screens, you would create custom versions of the appropriate python file from the /Assets/Screens/ folder in the corresponding folder in your mod. If you bring over an exact copy of the file, it will work exactly as before. Then you can open it up and find some line where it's putting text on the screen and edit it. Usually the text comes from XML, often indirectly through things like city.getName() etc.

Hope that gets you started.
 
To display a value inside a normal text string, you can use the following string:

string = 'Unit damage = %d'%(unit.getDamage())

This is will produce 'Unit damage = 17' if the unit is 17% damaged. The %d indicates that an integer will be placed in, you can drop in strings with %s and floats with %f.
 
One thing I have found that requires C++ SDK coding is changing any hover text, for example hovering over a city, unit or tech. When you said "the unit's cost per turn," it made me think of this. You may not have been thinking the same thing.

I learned much of how to muck about on the screens looking at the code included in Ruff Hi's cobbled SG mod which combines many other interface mods (no gameplay alteration). It has minor changes to the city screen and revamped domestic (F1) and diplomatic (F4) advisor screens. I learned enough from them to add my own small changes.

The hardest part I've found is that I haven't found any API description of the widget routines. So while I can alter the text displayed for a widget, I haven't figured out how to easily rearrange a screen. The layout on screen partially seems magical when you look at the diplomatic advisor.

In one case, the INFO page of the advisor is completely new, and the Python code to me doesn't look complete enough to fully create what I see on screen. Obviously it is because that page doesn't exist in the original game -- I just don't fully understand it. :)
 
Thanks for the info guys.
 
Top Bottom