Adding New Pop-Up/Rollover Items

jrandrew

Warlord
Joined
Nov 2, 2007
Messages
130
Location
L.A.
Hi All --

I am working on adding an updated unit upgrade screen to the Sevopedia. I already have the screen mostly constructed. I have added a text field showing the amount of research required to upgrade to a unit from the current position the player is in for each unit on the upgrade tree.

Now, I would like to display the list of technologies still required to obtain the unit when the player moves the mouse pointer over the text box displaying the

My problem at this point is that I can't figure out what function to call to get a rollover text box to appear.

This is my current code to generate the text box:

Code:
		if iCost > 0:
			szCostText = str(iCost)
			szCostText += u"%c" % gc.getCommerceInfo(CommerceTypes.COMMERCE_RESEARCH).getChar()
			szCostText = u"<font=5>" + szCostText.upper() + u"</font>"
			
			researchAmount = self.pediaScreen.getNextWidgetName()
			screen.setTextAt(researchAmount, iUnitPanel, szCostText, CvUtil.FONT_LEFT_JUSTIFY,
				int(self.buttonSize / 2), int(self.buttonSize * 1.5 * iUnitSize), 0, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

I have tried various combinations of the below to get a simple text field to appear when I rollover the text box above, but nothing works (I've tried both .setText and .attachTextGFC independantly but not both at the same time, just adding both here for completeness):

Code:
			infoPanelName = self.pediaScreen.getNextWidgetName()
			screen.attachPanel(researchAmount, infoPanelName, "", "", False, False, PanelStyles.PANEL_STYLE_EMPTY)

			screen.setText(self.pediaScreen.getNextWidgetName(), infoPanelName, "Testing", CvUtil.FONT_LEFT_JUSTIFY, 0, 0, 0, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

			screen.attachTextGFC(infoPanelName, "", CyTranslator().getText("TXT_KEY_PEDIA_FAV_CIVIC", ()) + ":", FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)

Any suggestions? Any general guidance on exactly how to use .setText and .attachTextGFC would be helpful, the calls to add various GUI widgets in BTS are pretty confusing.
 
If you're using BUG you can define a new WidgetTypes value or add your extra text to the existing unit hover. You can still do this without BUG, but it will take a lot more explaining. Let me know first if you're using BUG then we can go from there.
 
Thanks! I am doing this in Wildmana 8.2, which has integrated chunks of BUG (although I am not 100% sure if it has integrated all of it.) However, I believe that the version of BUG integrated is a bit older, 3.6 to be exact.
 
Wow, 3.6 is pretty old, but you can find everything you need in the WidgetUtil.py module. The createWidget(name) function shows how to create a new widget generically. You could even use most of this module as-is. Remove the import of BugConfig at the top and remove everything after "## Configuration Handler".

Edit: Continuing . . .

The key piece that adds the text is getWidgetHelp(). This is a callback in CvGameUtils.py which you'll need to copy into your mod's Python folder if it doesn't have it already. In getWidgetHelp() in that module, call the same function in WidgetUtil, passing in the same argsList parameter.

This allows you to append text to whatever text that widget already has. When you create a new widget using WidgetUtil.createWidget(), this function obviously generates all of the text since there is no text for the widget yet.

In the argsList list you will receive the WidgetType and the two integers that get assigned when creating the UI object in the first place. This allows you to set the UnitTypes value as the first parameter so you can use that in getWidgetHelp().
 
Thanks for the help, EmperorFool! I still have a couple more questions, a bit confused about a couple of things.

I am not doing this modularly at the moment, just hacking away at the python files under the Assets/Python folder and subfolders with the FFH Wild Mana mod. I probably should make it modular, but that adds an extra layer of complexity with Python that I was not yet ready to handle.

Ok, my questions:

1. Should WidgetTypes.py already be included in the list of python files? I ask because it's not present in any of the subdirectories under the Wild Mana mod, and in fact it's not present anywhere under the "Sid Meier's Civilization 4" subdirectory. Should I just place this file in the same directory as the current BUG files? (FFH Wild Mana\Assets\BUG currently.)

2.
In getWidgetHelp() in that module, call the same function in WidgetUtil, passing in the same argsList parameter.
in getWidgetHelp() in which module? My module? WidgetTypes.py? Or CvGameUtils.py? FFH Wild Mana does have a copy of CvGameUtils.py, here is what the getWidgetHelp() code there looks like:

Code:
	def getWidgetHelp(self, argsList):
		eWidgetType, iData1, iData2, bOption = argsList

		return u""

I'm not really sure if you mean that I need to modify the python callback, something in WidgetTypes.py, or whether you're referring to what I am going to do in my custom code.

3. Do I need to do an import of WidgetUtils at the top of the Python file that I am editing to be able to make a call like WidgetUtil.createWidget()?

Thanks for all your help!
 
Top Bottom