How To: Add New Screens to Civ4

Jeckel

Great Reverend
Joined
Nov 16, 2005
Messages
1,637
Location
Peoria, IL
How To: Add New Screens To Civ4

I've been adding new screens to Civ4 for a while now and finnally decided to jot down a tutorial describing the steps to add new screens into the game.

Acually adding the screen into the game is pretty simple, but creating the new screen itself will take some python knowledge and is described in How To: Display a Blank Civ4 Screen.

SECTION 1: Letting Civ4 know you added a Screen

You will need 4 files to get the new screen to work. I'll go through them one at a time and explain it step by step below.

1) Define the Screen's Background Image

Directory: /Assets/XML/Art/
File: CIV4ArtDefines_Interface.xml

First I'll start with the only XML file we have to mess with. In this file you define what image file to use as a background. The file must be in the DDS format and should be put in the /Assets/Art/Interface/Screens folder. Just add an entry like the example below.

Code:
		<InterfaceArtInfo>
			<Type>TUTORIAL_BLANK_SCREEN_BACKGROUND</Type>
			<Path>Art/Interface/Screens/YourImage.dds</Path>
		</InterfaceArtInfo>

NOTE: TUTORIAL_BLANK_SCREEN_BACKGROUND can be any string of text and will be used in the Python code to display the DDS image on your screen.

The XML work done, lets move on to the Python.

2) You Need A Screen File

Directory: /Assets/Python/Screens/
File: CvTutorialBlankScreen.py

Each screen has its own file that contains the python class for that screen. This tutorial is not about creating the screen class, its about getting the screen to show in game, so just make sure you have this file and lets move on.

You can fine my tutorial on creating and displaying your screen here

3) The Screen File Needs A Unique Enum Value

Directory: /Assets/Python/Screens/
File: CvScreenEnums.py

Each screen needs to be identified by a number. In this file you must add an attribute and set that attribute with a unique integer.

Code:
TUTORIAL_SCREEN_BLANK = 11000

You will have to call this attribute in the next file.

4) Do It the Right Way

Directory: /Assets/Python/EntryPoints/
File: CvScreensInterface.py

Everything in this file is technically optional.

First to do things right we will add a function to display our screen. There are ways to display your screen without using this file, but best to do things the right way.

So find a spot in the file after all the import calls and add the following code.

Code:
import CvTutorialBlankScreen
tutorialBlankScreen = CvTutorialBlankScreen.CvTutorialBlankScreen()
def showTutorialBlankScreen():
	tutorialBlankScreen.interfaceScreen()

First we set an attribute equal to an instance of your screen class.
Then define a function to call that will run the interfaceScreen method from the screen instance we just created.

To display the screen we would use code similar to the following.

Code:
import CvScreensInterface
CvScreensInterface.showYourScreen()

If your lazy you can also just import your screen file, instance the screen class and manually call the interfaceScreen method, but you will lose the ability to handle input to the screen.

5) If We Want Screen Input

There is one more thing to be done in this file and this can be very important if you wish to handle the input for the screen yourself.
Go to the bottom of the file and look for a dictionary similar to this.

Code:
#######################################################################################
## Handle Input Map
#######################################################################################
HandleInputMap = {  MAIN_INTERFACE : mainInterface,
					DOMESTIC_ADVISOR : domesticAdvisor,
					RELIGION_SCREEN : religionScreen,
					CORPORATION_SCREEN : corporationScreen,
					CIVICS_SCREEN : civicScreen,
					TECH_CHOOSER : techChooser,
					FOREIGN_ADVISOR : foreignAdvisor,
					FINANCE_ADVISOR : financeAdvisor,
					MILITARY_ADVISOR : militaryAdvisor,
					DAWN_OF_MAN : dawnOfMan,
					WONDER_MOVIE_SCREEN : wonderMovie,
					ERA_MOVIE_SCREEN : eraMovie,
					SPACE_SHIP_SCREEN : spaceShip,
					INTRO_MOVIE_SCREEN : introMovie,
					OPTIONS_SCREEN : optionsScreen,
					INFO_SCREEN : infoScreen,
					TECH_SPLASH : techSplashScreen,
					REPLAY_SCREEN : replayScreen,
					VICTORY_SCREEN : victoryScreen,
					TOP_CIVS : topCivs,
					HALL_OF_FAME : hallOfFameScreen,
					VICTORY_MOVIE_SCREEN : victoryMovie,
					ESPIONAGE_ADVISOR : espionageAdvisor,
					DAN_QUAYLE_SCREEN : danQuayleScreen,
					
					PEDIA_MAIN : pediaMainScreen,
					PEDIA_TECH : pediaMainScreen,
					PEDIA_UNIT : pediaMainScreen,
					PEDIA_BUILDING : pediaMainScreen,
					PEDIA_PROMOTION : pediaMainScreen,
					PEDIA_PROJECT : pediaMainScreen,
					PEDIA_UNIT_CHART : pediaMainScreen,
					PEDIA_BONUS : pediaMainScreen,
					PEDIA_IMPROVEMENT : pediaMainScreen,
					PEDIA_TERRAIN : pediaMainScreen,
					PEDIA_FEATURE : pediaMainScreen,
					PEDIA_CIVIC : pediaMainScreen,
					PEDIA_CIVILIZATION : pediaMainScreen,
					PEDIA_LEADER : pediaMainScreen,
					PEDIA_RELIGION : pediaMainScreen,
					PEDIA_CORPORATION : pediaMainScreen,
					PEDIA_HISTORY : pediaMainScreen,
					WORLDBUILDER_SCREEN : worldBuilderScreen,
					WORLDBUILDER_DIPLOMACY_SCREEN : worldBuilderDiplomacyScreen,
					
					DEBUG_INFO_SCREEN : debugInfoScreen,
				
				# add new screens here
				}
Go down to this part
Code:
				# add new screens here
				}
and make it look like
Code:
				# add new screens here
				TUTORIAL_SCREEN_BLANK: tutorialBlankScreen,
				}
Where YOUR_SCREEN_MANAGER is the screen enum attribute we add in CvScreenEnums.py and yourScreen is the attribute in this file we set to an instance of our screen class.

That is all you have to do to get a new screen working in the game. To get the screen to popup in game will require you to edit the event manager in some way to grab a key input or to add a button to the main interface and writing the screen class itself is the hardest part, but whats the point if you can't let the game know it exists anyway. :)
 
Tremendously helpful. Thanks for posting! Looking forward to your future tutorials, especially on how to handle screen input.

-isau
 
Thanx all, I'm glad this helped. :band:

I'm half done with the next section, Displaying a Blank Screen. I'm going to work on it today some and should have it done by tomorrow. :)
 
Alright, got the second tutorial done and posted. Its thread is linked at the top of the OP.

I aslo added a link in the second post to the example mod I wrote and based these tutorials on.
 
Saw this a while ago, possibly when it was posted looking at the dates, just didn't have much use for it till now.

For those of you who also modify the SDK, you can call the screen from there as well by using a line like this one:


gDLL->getPythonIFace()->callFunction("CvScreensInterface", "showTutorialBlankScreen");

You can actually use such a line to launch any command from any python file as far as I gather. Bloody hate python myself, so avoid it for anything other than interface issues, which I am finally being forced to get really in-depth on :)
 
Wow, you must have been reading my mind xienwolf.. I was just wondering how I would go about calling my Screen from SDK. I myself dislike C++ as much as you Python and was not looking forward to searching the SDK to find how they called their Screens. That just saved me a few hours of work. :P

Thanx for that dude. :goodjob:
 
DDS requires a specific ratio of dimensions (IIRC each side must be divisible by 4px). If you do not wish to follow that rule, then just use TGA, same commands for placing them, and no notable performance changes for me thus far.
 
OK, now I got GIMP and the dds-plug-in, but I've found no instructions on how to use/plug-in the plug-in with GIMP...
 
OK, thx again!:) (I'm assuming with "it" you mean the dds.)

EDIT: The plug-in I DLed seems to have an Install file my comp doesn't recognize; also, there's no extension to the Install. Do I need to find what kind of file it is first or do I just put it in the bin? (I'm sorry, I'm new at this and a technical moron at that.)
 
EDIT: The plug-in I DLed seems to have an Install file my comp doesn't recognize; also, there's no extension to the Install. Do I need to find what kind of file it is first or do I just put it in the bin? (I'm sorry, I'm new at this and a technical moron at that.)
The plugin is an executable but you don't run it yourself. Just put it with the other Gimp plugins and it should all work out.
 
Back
Top Bottom