I like to use the EventManger for some popups in the Improved Worldbuilder. But it's problematic to synchronize the EventIDs with other modules. BUG has a nice way to deal with this and i suggest to use this in RFCE too. Here is what BUG does:
There is a getNewEventID function in CvUtil.py that returns a unique EventID
This function is used in the beginning of a module to initialize your module variables. instead of
you write
For new events this function could be used. Only the initial value to g_nextEventID must be synchronized (i.e. it must be higher than any currently used values). IDs that are already in use can be left as they are. There is no need to change them now, although i would suggest to change them too, but step by step.
I think this would also lead to a cleaner use of the event interface in the long run. At the moment some events do not use IDs at all. They are hard coded into the EventManager or EventHandler. If your are looking for event-code you probably have to look into five different files to find the lines you are looking for.
Implementing this little function for new events is not much effort, and old code can be reworked later on step by step.
Edit:
if i rethink it, i think the eventID problematic only applies to popups. So this is actually a request for two things: to implement this nice little function for new popups (RFCE++ could profit from this two ), and to clean the event-code in general
There is a getNewEventID function in CvUtil.py that returns a unique EventID
Code:
g_nextEventID = 5050
def getNewEventID():
"""
Defines a new event and returns its unique ID to be passed to BugEventManager.beginEvent(id).
"""
global g_nextEventID
id = g_nextEventID
g_nextEventID += 1
return id
This function is used in the beginning of a module to initialize your module variables. instead of
Code:
MY_EVENT_ID = 4711
Code:
MY_EVENT_ID = CvUtil.getNewEventID()
For new events this function could be used. Only the initial value to g_nextEventID must be synchronized (i.e. it must be higher than any currently used values). IDs that are already in use can be left as they are. There is no need to change them now, although i would suggest to change them too, but step by step.
I think this would also lead to a cleaner use of the event interface in the long run. At the moment some events do not use IDs at all. They are hard coded into the EventManager or EventHandler. If your are looking for event-code you probably have to look into five different files to find the lines you are looking for.
Implementing this little function for new events is not much effort, and old code can be reworked later on step by step.
Edit:
if i rethink it, i think the eventID problematic only applies to popups. So this is actually a request for two things: to implement this nice little function for new popups (RFCE++ could profit from this two ), and to clean the event-code in general