handleInput in CvMainInterface.py

The Great Apple

Big Cheese
Joined
Mar 24, 2002
Messages
3,361
Location
Oxford, England
What I'm trying to do is to get custom mouseover info showing when I mouseover an action button (using the action buttons mod). Now the info is quite easy to do - what I'm having trouble doing is getting the handleInput function in CvMainInterface.py to recognise when the mouse is over the button.

I've done a bit of testing with the function, and it seems that it is only fired when you actually select an item such as the end turn button... which is not when I want it to be fired.

I notice poking through other screens that the handleInput functions on them seem to handle a lot more inputs then the main interface screen - including "LISTBOX_ITEM_SELECTED", "NOTIFY_CURSOR_MOVE_OFF", and "NOTIFY_CURSOR_MOVE_ON", all of which sounds like they might be the ones I want.... but I can't work out how to get by buttons to fire the input when the curser moves on or off in the first place.

Any ideas?
 
Honestly, I don't think it's possible right now for the main interface. I fought this for about 3 days straight, literally.

I think this might be a "wait till the SDK comes around."
 
I think that the handleInput() is useless for triggering action on mouse over button. You should use update() which is called on every 0.25 sec intervals.
In CvMainInterface.update(), getcoods where mouse is on. (Using CyIntarfcae. getMousePos() which returns mouse screen coordinates in pixel (X, Y) then compare it with button rectangle postition..
Dirty hack may be..
I think that WIDGET_XXX or (WIDGET_ACTION, iAction argument) of the button is the key.
If you can add new WIDGET_XXX, or new action type, then you can specify new mouse over handler for the button. for WIDGET_ACTION, new text for on-screen help string.
The action numer/ help string of specific WIDGET_ACTION is secified in CvMissionInfo.xml, CvAutomationInfo.xml and various XML files. Most of them we can not add new entry unless we can modify "CvEnum.h" :C++ header file.
 
I think it's possible to get these mouse over events in main interface, but only in you change the widget type of the related object.
In my (still not released) Plot List Enhancements I was only able to get this mouse over for th eplot list buttons, by changing the widget type from WIDGET_PLOT_LIST to WIDGET_GENERAL. This prevents the standard widget type consumes to consume the event.

EDIT : I was also able to use the mouse over events in my Modified Special Domestic Advisor.
 
SimCutie said:
I think that the handleInput() is useless to triggering action on mouse over plots. You should use update() which is called on every 0.25 sec intervals.
In CvMainInterface.update(), get plot where mouse is on. (Using CyIntarfcae. getMouseOverPlot() which returns *CyPlot struct), and find out what is in the plot. (Using CyPlot.getUnit(), getNumUnits(), getPlotCity(), etc etc...
If some thing of your interest is on the plot, then add the action button.
I want to find which selection button the mouse is over, not the plot.

I could do it a really long winded way because I can work out where all the buttons are, and then if one is under the pointer at any specific time. Not really what I wanted to do, but it'd probably work.

Does anybody know what the fDelta argument on the update function is? I had assumed it was the time between the two updates.
 
12monkeys said:
I think it's possible to get these mouse over events in main interface, but only in you change the widget type of the related object.
In my (still not released) Plot List Enhancements I was only able to get this mouse over for th eplot list buttons, by changing the widget type from WIDGET_PLOT_LIST to WIDGET_GENERAL. This prevents the standard widget type consumes to consume the event.

EDIT : I was also able to use the mouse over events in my Modified Special Domestic Advisor.
Fantastic - I'll have a go.
 
Mmhh. If the inputHandler works for the NOTIFY_CLICKED event before, I assume that the object naming the interface input map was Ok as well.

What type of objects you want to get the event for? I managed to get it work for a check box ( screen.addCheckBoxGFC() ) with WidgetTypes.WIDGET_GENERAL.

Are you trying to get that event for an existing or an added interface object?
 
12monkeys said:
Mmhh. If the inputHandler works for the NOTIFY_CLICKED event before, I assume that the object naming the interface input map was Ok as well.

What type of objects you want to get the event for? I managed to get it work for a check box ( screen.addCheckBoxGFC() ) with WidgetTypes.WIDGET_GENERAL.

Are you trying to get that event for an existing or an added interface object?
An added object to an existing parent object...

First using screen.addMultiListControlGFC then using screen.appendMultiListButton several times to add the separate buttons.
 
The Great Apple said:
An added object to an existing parent object...

First using screen.addMultiListControlGFC then using screen.appendMultiListButton several times to add the separate buttons.

I had a short look in that action button mod. I think the problem is, that those added action buttons don't pass the CvActionButtonsGameUtils.cannotHandleAction() method, if they don't have the widget type WIDGET_ACTION. Thats the reason why you loose your handler. A solution for this may be to add a handler in the main interface itself.

The possible reason why you don't get a mouse over event, could be that the event handler for those buttons is not part of the main interface but of the game core. This multi list button container is kind a special thing.

I had similar effects with the plot list buttons. Because the plot list is also bit of high integrated into game core, I had to change widget type to prevent the game core mixing everything up. As a side effect I switched off the mouse over info, which forces me to reprogram it. It was not my major intention to do so.

I'm afraid, you have to made a similar decision. If you want to change the mouse over info for the action buttons, you may have to write your own handler for the actions when you click such a button. You have to do that not only for your added ones, you have to do that for all possible action buttons.

Most of the actions can be pictured with CyGroup.pushMissions() (except the grouping stuff, this will hard to do, maybe its even impossible!). It could be a high price you have to pay.

As an alternative, you sould try to seperate those added buttons from the standard action buttons by creating your own container.

No good news I'm afraid.
 
12monkeys said:
As an alternative, you sould try to seperate those added buttons from the standard action buttons by creating your own container.
I believe I have some commented out examples of how this could be done in my Spell mod. It added images (that act like buttons) above the normal interface and could handle stuff for them in handleInput.
 
talchas said:
I believe I have some commented out examples of how this could be done in my Spell mod. It added images (that act like buttons) above the normal interface and could handle stuff for them in handleInput.
Unfortunetly then you don't get all the nice things like the flashing pulse.

I've managed to implement it by finding the mouse pointer. Seems to be working fairly smoothly.
 
The Great Apple said:
Unfortunetly then you don't get all the nice things like the flashing pulse.

I've managed to implement it by finding the mouse pointer. Seems to be working fairly smoothly.
Do you have any code you care to share with us yet?
 
TheLopez said:
Do you have any code you care to share with us yet?
Unfortunetly it's a tiny bit specific. The button positions I've used aren't the default button positions, as I had to fiddle them so that they'd fit inside the interface image I was using.

I am also yet to fiddle with the ActionButton class to tie text to the button. Getting there :p
 
The Great Apple said:
Unfortunetly it's a tiny bit specific. The button positions I've used aren't the default button positions, as I had to fiddle them so that they'd fit inside the interface image I was using.

I am also yet to fiddle with the ActionButton class to tie text to the button. Getting there :p

Are you retrieveing the mouse position with CyInterface.getMousePos(), checking if the resulting x,y-coord is over one of your square button objects? Is that correct?
 
When are you checking the mouse position? Every update?
 
Yes - checking it every update and tracking the mouse position. Have to be quite careful not to put too much load on it, and it seems to be holding up alright.

The only problem I have is the lack of dropshadow on the multiline text. I think I may have to split it into several single-line text pieces to get it to work.
 
The Great Apple said:
Yes - checking it every update and tracking the mouse position. Have to be quite careful not to put too much load on it, and it seems to be holding up alright.

you may reduce the load by splitting it :
option 1 : doing a scan on each button each 2nd or 3rd update
option 2 : doing a scan on half of the button one update and the second half next update.

Of course, this makes only sense, if the logic to split the load is not to complex.
 
12monkeys said:
you may reduce the load by splitting it :
option 1 : doing a scan on each button each 2nd or 3rd update
option 2 : doing a scan on half of the button one update and the second half next update.

Of course, this makes only sense, if the logic to split the load is not to complex.

The problem with this logic is that you could possibly get some flickering in the interface.
 
Back
Top Bottom