Mana
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Private Types | Private Attributes | Static Private Attributes | Friends | List of all members
Event Class Reference

#include <event.h>

Public Types

enum  Channel {
  ActorSpriteChannel , AttributesChannel , BuySellChannel , ChatChannel ,
  ClientChannel , ConfigChannel , GameChannel , ItemChannel ,
  NoticesChannel , NpcChannel , StorageChannel , QuestsChannel
}
 
enum  Type {
  Announcement , Being , ClearDialog , Close ,
  CloseAll , CloseDialog , ConfigOptionChanged , Constructed ,
  LoadingDatabases , Destroyed , Destructed , Destructing ,
  DoCloseInventory , DoDrop , DoEquip , DoMove ,
  DoUnequip , DoUse , EnginesInitialized , EnginesInitializing ,
  GuiWindowsLoaded , GuiWindowsLoading , GuiWindowsUnloaded , GuiWindowsUnloading ,
  IntegerInput , MapLoaded , Menu , Message ,
  Next , NpcCount , Player , Post ,
  PostCount , ServerNotice , StateChange , StorageCount ,
  StringInput , UpdateAttribute , UpdateStat , UpdateStatusEffect ,
  Whisper , WhisperError , QuestVarsChanged
}
 

Public Member Functions

 Event (Type type)
 Makes an event with the given name.
 
template<typename T >
 Event (Type type, const T &value)
 Makes an event with the given name and value.
 
 ~Event ()
 
Type getType () const
 Returns the name of the event.
 
template<typename T >
void setValue (const T &value)
 Sets the value of the event.
 
template<typename T >
const T & value () const
 Returns the value of the event.
 
template<typename T >
bool hasValue (const T &value) const
 Returns whether the event has the given the value.
 
void setInt (const std::string &key, int value)
 Sets the given variable to the given integer, if it isn't already set.
 
int getInt (const std::string &key) const
 Returns the given variable if it is set and an integer.
 
int getInt (const std::string &key, int defaultValue) const
 Returns the given variable if it is set and an integer, returning the given default otherwise.
 
void setString (const std::string &key, const std::string &value)
 Sets the given variable to the given string, if it isn't already set.
 
const std::string & getString (const std::string &key) const
 Returns the given variable if it is set and a string.
 
std::string getString (const std::string &key, const std::string &defaultValue) const
 Returns the given variable if it is set and a string, returning the given default otherwise.
 
void setFloat (const std::string &key, double value)
 Sets the given variable to the given floating-point, if it isn't already set.
 
double getFloat (const std::string &key) const
 Returns the given variable if it is set and a floating-point.
 
double getFloat (const std::string &key, float defaultValue) const
 Returns the given variable if it is set and a floating-point, returning the given default otherwise.
 
void setBool (const std::string &key, bool value)
 Sets the given variable to the given boolean, if it isn't already set.
 
bool getBool (const std::string &key) const
 Returns the given variable if it is set and a boolean.
 
bool getBool (const std::string &key, bool defaultValue) const
 Returns the given variable if it is set and a boolean, returning the given default otherwise.
 
void setItem (const std::string &key, Item *value)
 Sets the given variable to the given Item, if it isn't already set.
 
ItemgetItem (const std::string &key) const
 Returns the given variable if it is set and an Item.
 
ItemgetItem (const std::string &key, Item *defaultValue) const
 Returns the given variable if it is set and an Item, returning the given default otherwise.
 
void setActor (const std::string &key, ActorSprite *value)
 Sets the given variable to the given actor, if it isn't already set.
 
ActorSpritegetActor (const std::string &key) const
 Returns the given variable if it is set and an actor.
 
ActorSpritegetActor (const std::string &key, ActorSprite *defaultValue) const
 Returns the given variable if it is set and an actor, returning the given default otherwise.
 
void trigger (Channel channel) const
 Sends this event to all classes listening to the given channel.
 

Static Public Member Functions

static void trigger (Channel channel, const Event &event)
 Sends the given event to all classes listening to the given channel.
 
static void trigger (Channel channel, Type type)
 Sends an empty event with the given name to all classes listening to the given channel.
 

Static Protected Member Functions

static void bind (EventListener *listener, Channel channel)
 Binds the given listener to the given channel.
 
static void unbind (EventListener *listener, Channel channel)
 Unbinds the given listener from the given channel.
 
static void remove (EventListener *listener)
 Unbinds the given listener from all channels.
 

Private Types

using ListenMap = std::map< Channel, std::set< EventListener * > >
 

Private Attributes

const Type mType
 
std::map< std::string, VariableData * > mData
 
std::any mValue
 

Static Private Attributes

static ListenMap mBindings
 

Friends

class EventListener
 

Detailed Description

Definition at line 41 of file event.h.

Member Typedef Documentation

◆ ListenMap

using Event::ListenMap = std::map<Channel, std::set<EventListener *> >
private

Definition at line 311 of file event.h.

Member Enumeration Documentation

◆ Channel

Enumerator
ActorSpriteChannel 
AttributesChannel 
BuySellChannel 
ChatChannel 
ClientChannel 
ConfigChannel 
GameChannel 
ItemChannel 
NoticesChannel 
NpcChannel 
StorageChannel 
QuestsChannel 

Definition at line 44 of file event.h.

◆ Type

Enumerator
Announcement 
Being 
ClearDialog 
Close 
CloseAll 
CloseDialog 
ConfigOptionChanged 
Constructed 
LoadingDatabases 
Destroyed 
Destructed 
Destructing 
DoCloseInventory 
DoDrop 
DoEquip 
DoMove 
DoUnequip 
DoUse 
EnginesInitialized 
EnginesInitializing 
GuiWindowsLoaded 
GuiWindowsLoading 
GuiWindowsUnloaded 
GuiWindowsUnloading 
IntegerInput 
MapLoaded 
Menu 
Message 
Next 
NpcCount 
Player 
Post 
PostCount 
ServerNotice 
StateChange 
StorageCount 
StringInput 
UpdateAttribute 
UpdateStat 
UpdateStatusEffect 
Whisper 
WhisperError 
QuestVarsChanged 

Definition at line 60 of file event.h.

Constructor & Destructor Documentation

◆ Event() [1/2]

Event::Event ( Type  type)
inline

Makes an event with the given name.

Definition at line 110 of file event.h.

◆ Event() [2/2]

template<typename T >
Event::Event ( Type  type,
const T &  value 
)
inline

Makes an event with the given name and value.

Definition at line 118 of file event.h.

◆ ~Event()

Event::~Event ( )

Definition at line 28 of file event.cpp.

Member Function Documentation

◆ bind()

void Event::bind ( EventListener listener,
Channel  channel 
)
staticprotected

Binds the given listener to the given channel.

The listener will receive all events triggered on the channel.

Definition at line 182 of file event.cpp.

◆ getActor() [1/2]

ActorSprite * Event::getActor ( const std::string &  key) const

Returns the given variable if it is set and an actor.

Definition at line 155 of file event.cpp.

◆ getActor() [2/2]

ActorSprite * Event::getActor ( const std::string &  key,
ActorSprite defaultValue 
) const
inline

Returns the given variable if it is set and an actor, returning the given default otherwise.

Definition at line 266 of file event.h.

◆ getBool() [1/2]

bool Event::getBool ( const std::string &  key) const

Returns the given variable if it is set and a boolean.

Definition at line 111 of file event.cpp.

◆ getBool() [2/2]

bool Event::getBool ( const std::string &  key,
bool  defaultValue 
) const
inline

Returns the given variable if it is set and a boolean, returning the given default otherwise.

Definition at line 228 of file event.h.

◆ getFloat() [1/2]

double Event::getFloat ( const std::string &  key) const

Returns the given variable if it is set and a floating-point.

Definition at line 89 of file event.cpp.

◆ getFloat() [2/2]

double Event::getFloat ( const std::string &  key,
float  defaultValue 
) const
inline

Returns the given variable if it is set and a floating-point, returning the given default otherwise.

Definition at line 209 of file event.h.

◆ getInt() [1/2]

int Event::getInt ( const std::string &  key) const

Returns the given variable if it is set and an integer.

Definition at line 44 of file event.cpp.

◆ getInt() [2/2]

int Event::getInt ( const std::string &  key,
int  defaultValue 
) const
inline

Returns the given variable if it is set and an integer, returning the given default otherwise.

Definition at line 169 of file event.h.

◆ getItem() [1/2]

Item * Event::getItem ( const std::string &  key) const

Returns the given variable if it is set and an Item.

Definition at line 133 of file event.cpp.

◆ getItem() [2/2]

Item * Event::getItem ( const std::string &  key,
Item defaultValue 
) const
inline

Returns the given variable if it is set and an Item, returning the given default otherwise.

Definition at line 247 of file event.h.

◆ getString() [1/2]

const std::string & Event::getString ( const std::string &  key) const

Returns the given variable if it is set and a string.

Definition at line 66 of file event.cpp.

◆ getString() [2/2]

std::string Event::getString ( const std::string &  key,
const std::string &  defaultValue 
) const
inline

Returns the given variable if it is set and a string, returning the given default otherwise.

Definition at line 188 of file event.h.

◆ getType()

Type Event::getType ( ) const
inline

Returns the name of the event.

Definition at line 128 of file event.h.

◆ hasValue()

template<typename T >
bool Event::hasValue ( const T &  value) const
inline

Returns whether the event has the given the value.

Definition at line 150 of file event.h.

◆ remove()

void Event::remove ( EventListener listener)
staticprotected

Unbinds the given listener from all channels.

Definition at line 192 of file event.cpp.

◆ setActor()

void Event::setActor ( const std::string &  key,
ActorSprite value 
)

Sets the given variable to the given actor, if it isn't already set.

Definition at line 147 of file event.cpp.

◆ setBool()

void Event::setBool ( const std::string &  key,
bool  value 
)

Sets the given variable to the given boolean, if it isn't already set.

Definition at line 103 of file event.cpp.

◆ setFloat()

void Event::setFloat ( const std::string &  key,
double  value 
)

Sets the given variable to the given floating-point, if it isn't already set.

Definition at line 81 of file event.cpp.

◆ setInt()

void Event::setInt ( const std::string &  key,
int  value 
)

Sets the given variable to the given integer, if it isn't already set.

Definition at line 36 of file event.cpp.

◆ setItem()

void Event::setItem ( const std::string &  key,
Item value 
)

Sets the given variable to the given Item, if it isn't already set.

Definition at line 125 of file event.cpp.

◆ setString()

void Event::setString ( const std::string &  key,
const std::string &  value 
)

Sets the given variable to the given string, if it isn't already set.

Definition at line 58 of file event.cpp.

◆ setValue()

template<typename T >
void Event::setValue ( const T &  value)
inline

Sets the value of the event.

Definition at line 135 of file event.h.

◆ trigger() [1/3]

void Event::trigger ( Channel  channel) const
inline

Sends this event to all classes listening to the given channel.

Definition at line 275 of file event.h.

◆ trigger() [2/3]

void Event::trigger ( Channel  channel,
const Event event 
)
static

Sends the given event to all classes listening to the given channel.

Definition at line 169 of file event.cpp.

◆ trigger() [3/3]

static void Event::trigger ( Channel  channel,
Type  type 
)
inlinestatic

Sends an empty event with the given name to all classes listening to the given channel.

Definition at line 287 of file event.h.

◆ unbind()

void Event::unbind ( EventListener listener,
Channel  channel 
)
staticprotected

Unbinds the given listener from the given channel.

The listener will no longer receive any events from the channel.

Definition at line 187 of file event.cpp.

◆ value()

template<typename T >
const T & Event::value ( ) const
inline

Returns the value of the event.

Throws an exception if the event has no value of the given type.

Definition at line 143 of file event.h.

Friends And Related Symbol Documentation

◆ EventListener

friend class EventListener
friend

Definition at line 291 of file event.h.

Member Data Documentation

◆ mBindings

Event::ListenMap Event::mBindings
staticprivate

Definition at line 312 of file event.h.

◆ mData

std::map<std::string, VariableData *> Event::mData
private

Definition at line 315 of file event.h.

◆ mType

const Type Event::mType
private

Definition at line 314 of file event.h.

◆ mValue

std::any Event::mValue
private

Definition at line 316 of file event.h.


The documentation for this class was generated from the following files: