Leviathan game engine
Support of event types in scripts

Adding a new event type to the Engine

First add a new entry to the list of LISTENERNAMEs and LISTENERVALUEs in ScriptModule.h near the top of the file. For example like this:


Then add them to the map in ScriptModule.cpp (around line 40)

Remove this CEGUI mention and add new GUI click stuff

Then finally (if the event is for CEGUI) add it to Leviathan::Gui::BaseGuiObject::MakeSureCEGUIEventsAreFine in BaseGuiObject.cpp

(LISTENERNAME_ONCLICK, &CEGUI::FrameWindow::EventCloseClicked);

Matching the CEGUI event name it needs to be added to a couple of places:

Add support functions for a new CEGUI event

Add a new function

You will need to add a new function to the end of Leviathan::Gui::BaseGuiObject in BaseGuiObject.h. Following this syntax:

bool EventOn/*put the name of the new event here*/(const CEGUI::EventArgs &args);

and the implementation like this:

bool Leviathan::Gui::BaseGuiObject::EventOn/*something*/(const CEGUI::EventArgs &args){
// Pass the event to the script //

Replacing LISTENERNAME_ONCLOSECLICKED with the name used in the maps where the event was previously added.

Add an else-if clause for the new event

Goto the function Leviathan::Gui::BaseGuiObject::_HookCEGUIEvent and find the huge mess of a conditional statement. And add the event to the end.

else if(iter->second == &CEGUI::FrameWindow::EventCloseClicked){
createdconnection = TargetElement->subscribeEvent(*iter->second,
CEGUI::Event::Subscriber(&BaseGuiObject::EventOnCloseClicked, this));

Of course replacing EventCloseClicked with the name and Leviathan::Gui::BaseGuiObject::EventOnCloseClicked with the function created earlier. And that should do it!

Adding support for a new Engine Event

Alternatively if it is a predefined Leviathan event it may need to be added to Leviathan::EventListenerNameToEventMap which is in Event.h Like this: