1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

A little help adding a button for units

Discussion in 'Civ4 - Creation & Customization' started by Crayton, May 2, 2008.

  1. Crayton

    Crayton King

    Jul 18, 2004
    I want to add an action button to the spy unit and have attempted mirroring the code used in God Of Old which gave the Prophet units an extra button to call down calamities. However, when I load the mod the Main Interface is often missing, meaning I see my units and cities but no buttons or... well, interface.

    Here is what I have changed in the CvMainInterface file.

    This first part is at the end of the updateSelectionButtons function which places all of the buttons you can push for a selected unit. I have added a button for the spy unit, and when I can get the interface working the button exists (I am using the 'automate' art temporarily) however it will never execute the button code and eventually (after 10-20 turns) Civ IV crashes to the desktop.

    					if (CyInterface().canCreateGroup()):
    						screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUTTONS_CREATEGROUP").getPath(), 0, WidgetTypes.WIDGET_CREATE_GROUP, -1, -1, False )
    						screen.show( "BottomButtonContainer" )
    						iCount = iCount + 1
    					if (CyInterface().canDeleteGroup()):
    						screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUTTONS_SPLITGROUP").getPath(), 0, WidgetTypes.WIDGET_DELETE_GROUP, -1, -1, False )
    						screen.show( "BottomButtonContainer" )
    						iCount = iCount + 1
    					###### Unit Buttons ######
    					pUnit = g_pSelectedUnit
    					iUnitType = pUnit.getUnitType()
    					pUnitOwner = gc.getPlayer( pUnit.getOwner( ))
    					if pUnitOwner.isTurnActive( ):
                                                    # SG-Unit 
                                                    if iUnitType == CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_SPY") and gc.getMap().plot( g_pSelectedUnit.getX(), g_pSelectedUnit.getY() ).isCity():
    							screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_AUTOMATE").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 665, 665, False )
    							screen.show( "BottomButtonContainer" )
    							iCount = iCount + 1
    		elif (CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_HIDE_ALL and CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_MINIMAP_ONLY):
    		return 0
    This next one is near the end of the file and sends a ModNetMessage which I catch in my Event Manager. I think the goof may be in this bit of coding here.

    	# Will handle the input for this screen...
    	def handleInput (self, inputClass):
    		# Explores New Planet
    		if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 665 and inputClass.getData2() == 665):
    			pPlot = CyMap( ).plot( g_pSelectedUnit.getX( ), g_pSelectedUnit.getY( ) )
    			iPlotX = pPlot.getX()
    			iPlotY = pPlot.getY()
    			iOwner = g_pSelectedUnit.getOwner()
    			iUnitID = g_pSelectedUnit.getID()
    			CyMessageControl( ).sendModNetMessage( 1, iPlotX, iPlotY, iOwner, iUnitID )
    		return 0
    Anything look out of the ordinary or incomplete here? There is a small possibility the code called through the ModNetMessage would have an error in it, but I don't think that should prevent the Main Interface from initializing when I start the game.

    EDIT: Out of curiosity, what is a Notify Code of 11 mean? or any Notify Code for that matter?

Share This Page