• Civilization 7 has been announced. For more info please check the forum here .

Script for "custom game" screen

juni_be_good

Black mage
Joined
Jun 26, 2005
Messages
115
Location
Caen, France
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 ?
 
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. :(
 
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:
 
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 :(
 
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 :)
 
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.
 
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
 
I'm no Python expert but for what it's worth, here goes.

You need to edit two Python files:

1) CvEventManager.py

Code:
	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.BUTTONPOPUP_PYTHON_SCREEN)
					popupInfo.setText(u"showDawnOfMan")
					popupInfo.addPopup(iPlayer)
			
			self.getNumWondersVictory()#  <=== juni	
			
		else:
			CyInterface().setSoundSelectionReady(true)

and add to the bottom of the file:

Code:
	 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.BUTTONPOPUP_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:

Code:
	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
 
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:
 
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.
 
Top Bottom