building-list

pashaintel

Chieftain
Joined
Nov 22, 2008
Messages
22
Guys, can anybody help me with popups? Can I launch my popup by right-clicking on building in building-list on the city screen? I want to add some options for each building, and i want to use a city screen for it.
I use CvDLLWidgetData::executeAction :
Code:
case WIDGET_HELP_BUILDING:
		demolishBuilding(widgetDataStruct);
		break;
Then i write:
Code:
void CvDLLWidgetData::demolishBuilding(CvWidgetDataStruct &widgetDataStruct)
{

	BuildingTypes eBuilding;
	eBuilding = ((BuildingTypes)(widgetDataStruct.m_iData1));


			CvEventReporter::getInstance().demolishBuilding(eBuilding );


}

and
Code:
void CvDllPythonEvents::reportDemolishBuilding(BuildingTypes eBuilding )
{
	if (preEvent())
	{
		CyArgsList eventData;
		eventData.add("destroyBuilding");						// add key to lookup python handler fxn


		eventData.add((int)eBuilding);

		postEvent(eventData);

	}
}
and
Code:
void CvEventReporter::demolishBuilding(BuildingTypes eBuilding)
{
	m_kPythonEventMgr.reportDemolishBuilding(eBuilding);
}

Then I compile dll without any mistakes.
But my code in phyton don't works. That's it:

Code:
def onDestroyBuilding(self, argsList):
		
			self.__eventDestroyBuildingBegin(argsList)
and
Code:
def __eventDestroyBuildingBegin(self, argsList):
		iBuilding = argsList[0]

		popup = PyPopup.PyPopup(CvUtil.EventDestroyBuilding, EventContextTypes.EVENTCONTEXT_ALL)
		
		popup.setHeaderString(localText.getText("TXT_KEY_DESTROY_B", ()))
		popup.setBodyString(localText.getText("TXT_KEY_DESTROY_DB", ()))		
		popup.setUserData((iBuilding.getID(),))
		popup.addButton("OK")
		popup.addButton(localText.getText("TXT_KEY_SCREEN_CANCEL", ()))
		popup.launch(False, PopupStates.POPUPSTATE_IMMEDIATE)
		return
and

Code:
def __eventDestroyBuildingApply(self, playerID, userData, popupReturn):
		iBuilding = userData[0]
		if (popupReturn.getButtonClicked() == 0):
			CyInterface().getHeadSelectedCity().setNumRealBuilding(iBuilding, False)
			CyAudioGame().Play2DSound("AS2D_PILLAGE")
			
		return
This code doesn't destroy building. May be, problem with argsList? If i rewrite code to choose building after clicking building list,it works correctly. But I want to choose building to destroy by clicking on it in building list,but not after. Please help with dll, argslist...
 
I don't see that you're linking "destroyBuilding" with onDestroyBuilding(). Also, while False for setNumRealBuilding() should be cast to 0, it's more correct to use this:

Code:
setNumRealBuilding(iBuilding, [B][COLOR="Red"]0[/COLOR][/B])

Can you be more specific about "doesn't work"? Do you see your popup? Do you get a Python exception? The more details you can provide, the more likely someone can help you. Think like the CSIs! :)
 
Code:
'destroyBuilding'		:self.onDestroyBuilding,
That's link.
Code:
CvUtil.EventDestroyBuilding : ('DestroyBuilding', self.__eventDestroyBuildingApply, self.__eventDestroyBuildingBegin),

I see my popup if i delete
Code:
 popup.setUserData((iBuilding.getID(),))
. That's why i think the problem is in dll. Popup executes any code on "OK" if i don't use argsList from dll.
 
Yes! I found mistake. It should be
Code:
popup.setUserData(iBuilding)
Now it works correctly.
But i have new problem:). When i try to use
Code:
gc.getBuildingInfo(iBuilding).getDescription()
to get building name, my popup doesn't launch again. I'm in shock:eek: . What's wrong?
 
Make sure iBuilding isn't -1 (BUILDING_NONE) because that's an invalid building. You can use CvUtil.pyPrint(iBuilding) to see it in PythonDbg.log.
 
If i use CvUtil.pyPrint(iBuilding) my popup doesn't launch.
I try to use
Code:
popup.setBodyString(localText.getText(str(iBuilding), ()))

On clicking Palace I see (0,) , on clicking Granary - (13,) , on clicking Lighthouse - (20,) ,
on clicking Courthouse - (67,) , etc...
 
It sounds like iBuilding has the correct value. If you look in Logs/PythonErr.log you should see a reason why the popup doesn't launch. Can you post that file's contents here? Make sure you turn on logging. See our Troubleshooting page for instructions to do this.
 
Top Bottom