Skip to content

listen_events

Ansuz edited this page Mar 1, 2024 · 1 revision

Using Events

Configurable company provides some events that can help you updating configuration values and many other things.

The events are all registered under CEvents class.

Add An Event Listener

To start listening a new event you need to attach a listener. I recommend to add all listeners when your mod starts.

// This method should be called when you plugin starts
public static void AttachListeners() {

    // In this example we will listen to configuration changes
    CEvents.ConfigEvents.ChangeConfig.AddListener(MyEventListener);

}

public static void MyEventListener(CEventChangeConfig evt) {

    if (evt.Config.ID == myConfig.ID) {
        // The configuration is the one I want to check
    }
}

A brief explanation about what is happening. When you attach a listener, you are telling the event what method(s) should it call.

All events have one parameter that contains all the information about the event. In the example above this paramter is a CEventChangeConfig that contains information about what value changed in a configuration.

INFO
Some events have a CEvent parameter. This is the default one and does not contain any information, however it should be added as a parameter anyways.

Existing Events

There a lot of events you can listen to. These are divided into multiples sections depending on the type of event.

Event Type Event Subtype Parameter Type Information
Menu Events Save CEvent Called every time the save button is pressed
Reset CEvent Called every time the reset button is pressed
Restore CEvent Called every time the restore button is pressed
Copy CEvent Called every time the copy button is pressed
Paste CEvent Called every time the paste button is pressed
Prepare CEvent Called before the in-game menu is created
Create CEvent Called when the in-game menu is created
Destroy CEvent Called when the in-game menu is deleted
Toggle CEventMenuToggle Called when the menu is open or closed (using the in-game button)
Visible CEventMenuVisible Called when the menu is hidden or shown (when even the in-game show button is hidden/shown)
ChangePage CEventChangePage Called when the currently shown page is changed
Config Events CreatePage CEventCreatePage Called every time a new page is registered
CreateCategory CEventCreateCategory Called every time a new category is registered
CreateSection CEventCreateSection Called every time a new section is registered
CreateConfig CEventCreateConfig Called every time a new config is registered
ChangeConfig CEventChangeConfig Called every time the value of a configuration tries to be changed
ToggleConfig CEventToggleConfig Called every time a configuration is enabled or disabled
Lifecycle Events PluginStart CEvent Called after Configurable Company finishes loading
IO Events CopyToClipboard CEventCopyClipboard Called after the configuration has been copied to clipboard
PasteFromClipboard CEventPasteClipboard Called after the configuration has been pasted from the clipboard