how to pass more args to getWidgetHelp?

modifieda4

Chief Time Waster
Joined
Sep 3, 2006
Messages
385
Location
Gold Coast
the default args list is:

eWidgetType, iData1, iData2, bOption

i want to use a text string as the hover which includes a string variable

here would an example text xml:
Code:
	<TEXT>
		<Tag>TXT_KEY_CORPORATE_RELOCATION_MOUSE_OVER</Tag>
		<English>Relocate %s1 headquarters to this city</English>
		<French></French>
		<German></German>
		<Italian></Italian>
		<Spanish></Spanish>
	</TEXT>
how would i get the corporation's name into a mouse over?
 
When you place a widget on the screen, you give it the widget ID (eWidgetType) and two numeric identifiers, iData1, and iData2. That's all you get. To put substitute the name of a city into your text you need to find a way to determine the city's name from those two numbers. Luckily for you, that's pretty easy: iData1 holds the player ID and iData2 holds the city ID.

It's been a long time since I did this, so I'll have to resort to English text rather than code. If you put this into code I can help from there. You can get help with some of it from the BUG tutorial.

Nevermind, let's try some code:

Code:
MY_CUSTOM_WIDGET = 12345

def getWidgetHelp(argsList):
    eWidgetType, iPlayer, iCity = argsList
    if eWidgetType is MY_CUSTOM_WIDGET:
        pPlayer = gc.getPlayer(iPlayer)
        pCity = pPlayer.getCity(iCity)
        return BugUtil.getText("TXT_KEY_CORPORATE_RELOCATION_MOUSE_OVER", pCity.getName())

Next you'll need to hook up this handler to the getWidgetHelp game utils callback. Follow the tutorial for that. Try it out and post again with how far you got.
 
EmporerFool, thanks! Ill try those suggestions out.

BTW the brute force way of hijacking iData2 seems to be working. The problem with that is there is a cost calculation in my mod that I had to put into the maininterface.py. So every time the action button is rendered, the calculation would run.

If I can get your method to work, I can put the cost calculation into the getWidgetHelp of my BUG event so the calculation would only run on mouse over. It seems more efficient that way.

I'll let you know how it goes. :goodjob:
 
I don't know if it was clear, but BUG can define new widget types for you very easily that you can then use in Python. For ones that need to have a function called in Python use

Code:
<widget name="WIDGET_GP_PROGRESS_BAR" module="GPUtil" function="getHoverText"/>

And for simple ones that display a static help text hover from an XML file, use

Code:
<widget name="WIDGET_BUG_OPTION_SCREEN" xml="TXT_KEY_BUG_OPTIONS_SCREEN_HOVER"/>

When placing custom widgets, just reference them as you would any other widget type:

Code:
WidgetType.WIDGET_GP_PROGRESS_BAR
 
I don't know if it was clear, but BUG can define new widget types for you very easily that you can then use in Python. For ones that need to have a function called in Python use

Code:
<widget name="WIDGET_GP_PROGRESS_BAR" module="GPUtil" function="getHoverText"/>

And for simple ones that display a static help text hover from an XML file, use

Code:
<widget name="WIDGET_BUG_OPTION_SCREEN" xml="TXT_KEY_BUG_OPTIONS_SCREEN_HOVER"/>

When placing custom widgets, just reference them as you would any other widget type:

Code:
WidgetType.WIDGET_GP_PROGRESS_BAR

yah i just got the "register widget error" :)
which bug xml file contains the registrations?

oops i found it in WidgetUtil.py...
 
EmperorFool:

I understand all the logic to creating a BUG help widget now EXCEPT in what file to call the widgetutils and to register the wiget.

does this go in my mod's gameutils? the widget needs to be visible to the maininterface.py and i know load order matters.
 
Adding <widget .../> to your mod's config XML file makes the constant available on the WidgetType class. You don't need to use create a gameutils callback or use WidgetUtils (BUG does both). All you need to do is place an object (button, text, whatever) on the screen that references the new WidgetType you declared.

I don't recall "register widget error". Did this appear in the logs? If so, can you paste the full message including some surrounding context? Code helps a ton in understanding what's going wrong. Your XML config file and the Python where you place the widget would be most helpful.
 
some progress, though i've hit another snag:

python exception:
type error: getWidgetHelp() takes exactly 1 argument (4 given)

in Basic Corporate Relocation.xml:
Code:
<widget name="WIDGET_CORPORATE" module="BasicCorporateRelocation" function="getWidgetHelp"/>
in CvMainInterface.py:
Code:
screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_CORPORATE_RELOCATION").getPath(), 0, WidgetTypes.WIDGET_CORPORATE, iCity, iUnit, False)

i guess its not understanding the 4 parameters being passed into argsList?
 
more issues...

how do i launch the button? I know how to do it the old way. not the new way :(

in:

def handleInput (self, inputClass):

the old way:

if (inputClass.getNotifyCode() == 11 and inputClass.getData() == 667): and inputClass.getData2() == 667):

this would be a whole lot easier with a nice write up like (the old way):
http://forums.civfanatics.com/showthread.php?t=331001

i can't find any bug examples...ROM AND doesnt use this :( nor does the BUG sourceforge page
http://sourceforge.net/apps/mediawiki/civ4bug/index.php?title=Special:Search&search=widget
 
BUG extracts the four parameters from the argsList array and passes them directly to your function. You can see an example in Python/BUG/GPUtil.py:

Code:
def getHoverText(eWidgetType, iData1, iData2, bOption):

To use the button should be no different from before; inputClass.getFunctionName() returns the name of the button. Here's an example for the BUG Options Screen button:

Code:
# create the button

sBUGOptionsScreenButton = ArtFileMgr.getInterfaceArtInfo("BUG_OPTIONS_SCREEN_BUTTON").getPath()
screen.setImageButton("BUGOptionsScreenWidget", sBUGOptionsScreenButton,  iBtnX + 30, iBtnY - 2, iBtnWidth, iBtnWidth, WidgetTypes.WIDGET_BUG_OPTION_SCREEN, -1, -1)

# in handleInput():

if inputClass.getNotifyCode() == NotifyCode.NOTIFY_CLICKED:
    if inputClass.getFunctionName() == "BUGOptionsScreenWidget":
        BugOptionsScreen.showOptionsScreen()
 
I don't know if it was clear, but BUG can define new widget types for you very easily that you can then use in Python. For ones that need to have a function called in Python use

Code:
<widget name="WIDGET_GP_PROGRESS_BAR" module="GPUtil" function="getHoverText"/>

And for simple ones that display a static help text hover from an XML file, use

Code:
<widget name="WIDGET_BUG_OPTION_SCREEN" xml="TXT_KEY_BUG_OPTIONS_SCREEN_HOVER"/>

When placing custom widgets, just reference them as you would any other widget type:

Code:
WidgetType.WIDGET_GP_PROGRESS_BAR

in what file that's should be put?? do we need create new XML file?

i have codes like this in CvGameUtil.py, which should be display text when a button hovered:

Code:
	def getWidgetHelp(self, argsList):
		eWidgetType, iData1, iData2, bOption = argsList
	
          if eWidgetType == WidgetTypes.WIDGET_GENERAL:
			GameSpeedInfo = gc.getGameSpeedInfo(CyGame().getGameSpeedType())
			if iData1 == 800:
				return CyTranslator().getText("TXT_KEY_PLATY_GENERAL_MISSION1",())

that's not working since i'm using BUG mod
I have read the "WidgetUtil.py" but still don't get it :confused:
 
If you're adding hover widgets, you'll need to edit both the XML and Python. The *.py file that you put your code into depends on what you're trying to accomplish.
 
Hello, having some issues getting hover text to work:

Assets\Config\VassalWar.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
VassalWar
-->
<mod id="VassalWar" module="VassalWar">
<gameutils module="VassalWar" handlers="getWidgetHelp" override="True"/>
<widget name="WIDGET_VASSAL_WAR" xml="TXT_KEY_DECLARE_WAR"/>
</mod>

Asstes\Python\VassalWar.py:

# VassalWar

from CvPythonExtensions import *
import BugCore
import BugUtil

gc = CyGlobalContext()

def getWidgetHelp(argsList):
eWidgetType, iData1, iData2, bOption = argsList
## War on Vassal ##
if eWidgetType == WidgetTypes.WIDGET_VASSAL_WAR:
if iData1 == 3434:
return CyTranslator().getText("TXT_KEY_DECLARE_WAR",())
## War on Vassal ##
return u""

Assets\Python\Screens\CvForeignAdvisor.py:

iLoopTeam = player.getTeam()
iActiveTeam = playerActive.getTeam()
if iLoopTeam != iActiveTeam and not gc.getTeam(iLoopTeam).isForcePeace(iActiveTeam) and not gc.getTeam(iActiveTeam).isAVassal() and not gc.getTeam(iLoopTeam).isAtWar(iActiveTeam):
screen.setImageButton("DeclareWar" + str(iPlayer), ",Art/Interface/Buttons/Promotions/Blitz.dds,Art/Interface/Buttons/Promotions_Atlas.dds,8,1", fX - 24, fY+ iLeaderHeight, 24, 24, WidgetTypes.WIDGET_VASSAL_WAR, 3434, iLoopTeam)

If I just use WIDGET_GENERAL, the mod works but there's no hover text.

Also, I copied in a python file: Assets\Python\CvEventManager.py - Can this file coexist with BUG? It works for my mod but will it break BUG in other places?
 
Never mind - was missing the load in init.xml.

I still have this question about Assets\Python\CvEventManager.py - do the functions in this file exist elsewhere in BUG or can I safely copy it in?
 
Top Bottom