Contents |
Events are things which occur due to certain triggers. There is only certain amount of fixed triggers, and this ties down modders slightly, however the triggers will accommodate most scripts. If you open up CvEventManager.py, the event triggers run from line 193 down to line 747 (patch 1.52). There are nearly 60 different triggers that can be used, ranging from onUpdate which runs every frame (probably about 30 times a second), to onGameStart which runs only once, at the start of the game.
Most triggers have arguments associated with them. These arguments are stored in the argsList. Under most event headers these arguments are defined. It's usually pretty obvious what they do.
Perhaps the simplest method of adding events on triggers is to just to add the event into the events manager. This will work for small mods, although it raises certain compatibility issues. A better way of doing it is to create your own CvCustomEventManager file. I recommend Dr Elmer Jiggle's event manager (found here). It's a bit tricky to understand at first, but well worth it if you can get it working. For examples of it in action I'd check out any of TheLopez's ModComps (look in this forum).
def onBeginGameTurn(self, argsList):
'Called at the beginning of the end of each turn'
iGameTurn = argsList[0]
CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
with the following code:
def onBeginGameTurn(self, argsList):
'Called at the beginning of the end of each turn'
iGameTurn = argsList[0]
CyInterface.addImmediateMessage("You have just started a new turn", "") # Adds the message "You have just started a new turn" with no sound attached.
CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
NOTE: When making a formal mod you shouldn't simply add stuff to the event manager like this as it can cause compatibility issues. Check out the custom event manager linked to above.
As mentioned in the introduction, almost all of the GUI is created dynamically either when you enter the relevant screen, or at the start of the game. Just about all of it is moddable. The files for modding the interface are in /Assets/Python/Screens.
CyGInterfaceScreen.getXResolution() or CyGInterfaceScreen.getYResolution()