Jeckel
Great Reverend
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.
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.
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.
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.
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.
Go down to this part
and make it look like
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.
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
}
Code:
# add new screens here
}
Code:
# add new screens here
TUTORIAL_SCREEN_BLANK: tutorialBlankScreen,
}
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.
