Main interface.py questions

Pickly

Prince
Joined
Jun 5, 2009
Messages
535
Admittedly, this entire file is quite baffling for me, despite being able to figure out most other python files pretty well, reading through this one gets quite confusing quite quick. Really, a tuturial on this file (and possibly other interface files) itself might be useful, but that is a long shot. :)

So, for now, here come a couple of what might be a long string of questions about the file as/until I get more comfortable with it.


First up: I'm hoping to add a couple of new commerce types that build for an entire civilization. (Mana, faith, and espionage for an FfH modmod.), and (think) I have the DLL, XML, gamefonts, etc. set up for everything (The civilopedia displays properly), but am not quite sure what needs to be done to display the information in the main interface.

An attempt at adding text strings (code shown below, done by analogy with gold strings) causes all upper right corner commerce strings to disappear, and the city interface to not show at all.

Spoiler :

As you can probably see, this was mostly a copy/paste for the gold display. Game strings seemed to be the only thing I noticed that either mentioned gold or was directly linked to something that would mention gold, but I may well have missed something.

Code:
def updateGameDataStrings( self ):
	
		screen = CyGInterfaceScreen( "MainInterface", CvScreenEnums.MAIN_INTERFACE )

		screen.hide( "ResearchText" )
		screen.hide( "GoldText" )
		screen.hide( "EnergyText" )
		screen.hide( "FaithText" )
		screen.hide( "TimeText" )
		screen.hide( "ResearchBar" )

		bShift = CyInterface().shiftKey()
		
		xResolution = screen.getXResolution()
		yResolution = screen.getYResolution()

		pHeadSelectedCity = CyInterface().getHeadSelectedCity()

		if (pHeadSelectedCity):
			ePlayer = pHeadSelectedCity.getOwner()
		else:
			ePlayer = gc.getGame().getActivePlayer()

		if ( ePlayer < 0 or ePlayer >= gc.getMAX_PLAYERS() ):
			return 0

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			szString = "PercentText" + str(iI)
			screen.hide(szString)
			szString = "RateText" + str(iI)
			screen.hide(szString)

		if ( CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_HIDE_ALL and CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_MINIMAP_ONLY  and CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_ADVANCED_START):

			# Percent of commerce
			if (gc.getPlayer(ePlayer).isAlive()):
				iCount = 0
				for iI in range( CommerceTypes.NUM_COMMERCE_TYPES ):
					eCommerce = (iI + 1) % CommerceTypes.NUM_COMMERCE_TYPES
					if (gc.getPlayer(ePlayer).isCommerceFlexible(eCommerce) or (CyInterface().isCityScreenUp() and (eCommerce == CommerceTypes.COMMERCE_GOLD))):
						iShift = 60
						if (CyInterface().isCityScreenUp()):
							iShift = 0
						szOutText = u"<font=2>%c:%d%%</font>" %(gc.getCommerceInfo(eCommerce).getChar(), gc.getPlayer(ePlayer).getCommercePercent(eCommerce))
						szString = "PercentText" + str(iI)
						screen.setLabel( szString, "Background", szOutText, CvUtil.FONT_LEFT_JUSTIFY, 14 + iShift, 50 + (iCount * 19), -0.1, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
						screen.show( szString )

						if not CyInterface().isCityScreenUp():
							szOutText = u"<font=2>" + localText.getText("TXT_KEY_MISC_POS_GOLD_PER_TURN", (gc.getPlayer(ePlayer).getCommerceRate(CommerceTypes(eCommerce)), )) + u"</font>"
							szString = "RateText" + str(iI)
							screen.setLabel( szString, "Background", szOutText, CvUtil.FONT_LEFT_JUSTIFY, 112 + iShift, 50 + (iCount * 19), -0.1, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
							screen.show( szString )

						iCount = iCount + 1;
                                                
			self.updateTimeText()
			screen.setLabel( "TimeText", "Background", g_szTimeText, CvUtil.FONT_RIGHT_JUSTIFY, xResolution - 56, 6, -0.3, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
			screen.show( "TimeText" )
			
			if (gc.getPlayer(ePlayer).isAlive()):
				
				szText1 = CyGameTextMgr().getGoldStr(ePlayer)
				szText2 = CyGameTextMgr().getManaStr(ePlayer)
				szText3 = CyGameTextMgr().getFaithStr(ePlayer)

#FfH: Added by Kael 12/08/2007
				if (gc.getPlayer(ePlayer).getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KHAZAD') and gc.getPlayer(ePlayer).getNumCities() > 0):
					iGold = gc.getPlayer(ePlayer).getGold() / gc.getPlayer(ePlayer).getNumCities()
					if iGold <= 49:
						szText = szText + " " + localText.getText("TXT_KEY_MISC_DWARVEN_VAULT_EMPTY", ())
					if (iGold >= 50 and iGold <= 99):
						szText = szText + " " + localText.getText("TXT_KEY_MISC_DWARVEN_VAULT_LOW", ())
					if (iGold >= 150 and iGold <= 199):
						szText = szText + " " + localText.getText("TXT_KEY_MISC_DWARVEN_VAULT_STOCKED", ())
					if (iGold >= 200 and iGold <= 299):
						szText = szText + " " + localText.getText("TXT_KEY_MISC_DWARVEN_VAULT_ABUNDANT", ())
					if (iGold >= 300 and iGold <= 499):
						szText = szText + " " + localText.getText("TXT_KEY_MISC_DWARVEN_VAULT_FULL", ())
					if iGold >= 500:
						szText = szText + " " + localText.getText("TXT_KEY_MISC_DWARVEN_VAULT_OVERFLOWING", ())
#FfH: End Add
				iShift = 60
				if (CyInterface().isCityScreenUp()):
					iShift = 0

				screen.setLabel( "GoldText", "Background", szText1, CvUtil.FONT_LEFT_JUSTIFY, 12 + iShift, 6, -0.3, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
				screen.show( "GoldText" )
				
				if not CyInterface().isCityScreenUp():
					screen.setLabel( "EnergyText", "Background", szText2, CvUtil.FONT_LEFT_JUSTIFY, 12 + iShift+iTier1, 6, -0.3, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
					screen.show( "EnergyText" )

					screen.setLabel( "FaithText", "Background", szText3, CvUtil.FONT_LEFT_JUSTIFY, 12 + iShift+iTier3, 6, -0.3, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
					screen.show( "FaithText" )
				
				if (gc.getPlayer(ePlayer).isAnarchy()):
				
					szText = localText.getText("INTERFACE_ANARCHY", (gc.getPlayer(ePlayer).getAnarchyTurns(), ))
					screen.setText( "ResearchText", "Background", szText, CvUtil.FONT_CENTER_JUSTIFY, screen.centerX(512), 3, -0.4, FontTypes.GAME_FONT, WidgetTypes.WIDGET_RESEARCH, -1, -1 )
					if ( gc.getPlayer(ePlayer).getCurrentResearch() != -1 ):
						screen.show( "ResearchText" )
					else:
						screen.hide( "ResearchText" )
					
				elif (gc.getPlayer(ePlayer).getCurrentResearch() != -1):

					szText = CyGameTextMgr().getResearchStr(ePlayer)
					screen.setText( "ResearchText", "Background", szText, CvUtil.FONT_CENTER_JUSTIFY, screen.centerX(512), 3, -0.4, FontTypes.GAME_FONT, WidgetTypes.WIDGET_RESEARCH, -1, -1 )
					screen.show( "ResearchText" )

					researchProgress = gc.getTeam(gc.getPlayer(ePlayer).getTeam()).getResearchProgress(gc.getPlayer(ePlayer).getCurrentResearch())
					overflowResearch = (gc.getPlayer(ePlayer).getOverflowResearch() * gc.getPlayer(ePlayer).calculateResearchModifier(gc.getPlayer(ePlayer).getCurrentResearch()))/100
					researchCost = gc.getTeam(gc.getPlayer(ePlayer).getTeam()).getResearchCost(gc.getPlayer(ePlayer).getCurrentResearch())
					researchRate = gc.getPlayer(ePlayer).calculateResearchRate(-1)
					
					iFirst = float(researchProgress + overflowResearch) / float(researchCost)
					screen.setBarPercentage( "ResearchBar", InfoBarTypes.INFOBAR_STORED, iFirst )
					if ( iFirst == 1 ):
						screen.setBarPercentage( "ResearchBar", InfoBarTypes.INFOBAR_RATE, ( float(researchRate) / float(researchCost) ) )
					else:
						screen.setBarPercentage( "ResearchBar", InfoBarTypes.INFOBAR_RATE, ( ( float(researchRate) / float(researchCost) ) ) / ( 1 - iFirst ) )

					screen.show( "ResearchBar" )
					
		return 0


2. How would I go about changing the right side of the city screen to display specialists as a separate panel than resources, instead of showing both in a big box? (I think I tried this before, but quickly got confused by the specialist related stuff in the main interface file) As a demonstration, the planetfall screenshot shows what I'd like to do, the Fall from Heaven screenshot shows what is there now.
 
1. You probably have an exception. Try enabling Python exceptions in the INI file (or at least enable the log). That should show you where the problem is.

2. :dunno: try looking at the planetfall source - specifically in its CvMainInterface.py...
 
On #1: Turned out I didn't have python exceptions enabled (which is strange, as I am quite sure I had them enabled before.), and get an error that "CyGameTextManager has no attribute GetManaStr", which is strange, as it is definitely in the file in question does definitely have the function, the DLL compiled properly, and I am using the most recent one. So now I suppose I'll be looking through the various DLL files for something else missing, or possibly spelling, or whatever other issue is not allowing the connection.

On #2: I was hoping you wouldn't say that, as previous attempts to look through the files have been quite confusing. But I suppose it's something I'll try again when I get around to the addition.
 
Just because a function exists in the DLL doesn't mean it is being exported to the Python API. You have to manually make things available to Python, it isn't automatic. See CyGameTextMgrInterface.cpp.
 
That is the file used. (It is in all four of the text manager files.) That is why this issue is confusing.
 
Back
Top Bottom