View Full Version : Script for "custom game" screen
juni_be_good Jun 11, 2007, 06:54 AM I would like to add an option to the custom game screen for a mod I'm working on. I guess this screen is defined somewhere in Python files, but I don't find it ! :confused:
Can someone please help me ?
Zebra 9 Jun 11, 2007, 10:46 AM Do you mean in the Main Menu Section (You havn't started an actuall game yet). If so that would be in the EXE and is not editable. :(
juni_be_good Jun 11, 2007, 11:07 AM Yes, I mean the screen that opens when you click "Single player" and then "Custom game" in the main menu.
Is that considered as part of the menu and defined in exe file ? :faint:
ww2commander Jun 11, 2007, 11:49 PM Have a look at the two following downloads if using warlords. The same concept should apply to vanilla as well.
http://forums.civfanatics.com/downloads.php?do=file&id=316
http://forums.civfanatics.com/downloads.php?do=file&id=2845
Also, this thread exists in the tutorial section, but I leave you to decide how useful it is:
http://forums.civfanatics.com/showthread.php?t=197780
Hope it gets you started in the right direction ;)
EDIT: After re-reading your post, this may not be exactly what your after :(
juni_be_good Jun 12, 2007, 03:50 AM No, it's not what I was looking for, but I think Zebra answered it well, and your links are useful even if not for this case, so thank you anyway :)
PeteT Jun 13, 2007, 04:17 PM What are you trying to do?
I needed to set an "End Era" for games and, although I would have liked to have added a button to the "Custom Game" screen, I had to work around it.
If you want to see what I did, check out this thread at Poly:
http://apolyton.net/forums/showthread.php?s=&threadid=166104
juni_be_good Jun 14, 2007, 11:16 AM I am working on a new victory condition : you win when you have built or captured a certain number of world wonders (but unlike Space Race victory, you just have a number to reach, you can choose which wonders you build among all available)
I already have this mod working, but the number of wonders to reach is defined deep in the C++ code. What I want to do is adding an option in custom game screen so that players can choose this number.
Could you tell me how you did this popup ? It may be the best solution for me too.
juni_be_good Jun 16, 2007, 01:52 PM I am now missing only very little Python code to make everything work. All I need is a popup appearing at the beginning of the game (or something added to Dawn of Man screen) that asks the player how many wonders he wants to build to achieve Wonders victory. All the SDK job to get and use this answer is already done. I just don't know how to make a text field appear on the screen, and how to put the text typed in a variable.
If some experienced modder is around, I wouldn't refuse some help :D
PeteT Jun 17, 2007, 12:36 PM I'm no Python expert but for what it's worth, here goes.
You need to edit two Python files:
1) CvEventManager.py
def onGameStart(self, argsList):
'Called at the start of the game'
if (gc.getGame().getStartEra() == gc.getDefineINT("STANDARD_ERA")):
for iPlayer in range(gc.getMAX_PLAYERS()):
player = gc.getPlayer(iPlayer)
if (player.isAlive() and player.isHuman()):
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTT ONPOPUP_PYTHON_SCREEN)
popupInfo.setText(u"showDawnOfMan")
popupInfo.addPopup(iPlayer)
self.getNumWondersVictory()# <=== juni
else:
CyInterface().setSoundSelectionReady(true)
and add to the bottom of the file:
def getNumWondersVictory(self):
"Brings up a popup allowing the active player to choose the number of wonders which constitutes victory"
iPlayerID = gc.getPlayer(CyGame().getActivePlayer()).getID()
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTT ONPOPUP_PYTHON)
popupInfo.setText("Choose the number of Wonders needed for a Wonder Victory")
popupInfo.setOnClickedPythonCallback("wondersVictoryOnClickedCallback")
#set the range parameters
#for example:
iStart = 10
iStop = 20
iStep = 2
for i in range(iStart,iStop,iStep):
strButtonText = str(i)
popupInfo.addPythonButton(strButtonText, "")
#pass the range parameters to the callback
popupInfo.setData1(iStart)
popupInfo.setData2(iStop)
popupInfo.setData3(iStep)
#show the popup
popupInfo.addPopup(iPlayerID)
2) CvScreensInterface.py
Near the bottom of the file, add:
def wondersVictoryOnClickedCallback(argsList):
iButtonID = argsList[0]
iStart = argsList[1]
iStop = argsList[2]
iStep = argsList[3]
iCount = -1
for i in range(iStart, iStop, iStep):
iCount = iCount+1
if (iCount==iButtonID):
CyGlobalContext().getGame().setNumWondersVictory(i ) # <= !!!
return 0
################################################## #####################################
## Handle Close Map
################################################## #####################################
This assumes that you have added a member "m_iNumWondersVictory" to the C++ class CvGame in the normal way and exposed it's "setNumWondersVictory" to Python.
BTW, Kael wrote a tutorial on Popups:
http://forums.civfanatics.com/showthread.php?t=183126
juni_be_good Jun 18, 2007, 03:20 AM In the meanwhile I found Kael's tutorial about popups and got a solution close to this, but your code is better than mine because it is easier to change the numbers in it.
Thank you very much for your help Pete. :goodjob:
PeteT Jun 20, 2007, 11:21 AM You're very welcome.
There was a bug in 'GrampsMod' that I linked to in post #6. If anyone's downloaded it, I've put up a new version at Poly.
|
|