Added display text event hook.
This commit is contained in:
parent
314b8997be
commit
5a976e4031
|
@ -19,3 +19,5 @@ SIMPLE_GET_FUNC(HealEvent, GetOriginalHealth, uint32_t);
|
|||
SIMPLE_GET_FUNC(HealEvent, GetNewHealth, uint32_t);
|
||||
|
||||
SIMPLE_GET_FUNC(FaintEvent, GetCreature, Creature*);
|
||||
|
||||
export const char* CreatureLib_DisplayTextEvent_GetText(const DisplayTextEvent* p) { return p->GetText().c_str(); }
|
||||
|
|
|
@ -52,6 +52,15 @@ namespace CreatureLib::Battling {
|
|||
Creature* GetCreature() const { return _creature; }
|
||||
};
|
||||
|
||||
class DisplayTextEvent : public EventData {
|
||||
const std::string _text;
|
||||
|
||||
public:
|
||||
DisplayTextEvent(const std::string& text) : _text(text) {}
|
||||
EventDataKind GetKind() const override { return EventDataKind ::DisplayText; }
|
||||
const std::string& GetText() const { return _text; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATA_HPP
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint)
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, DisplayText)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
|
|||
public:
|
||||
void RegisterListener(EVENT_HOOK_FUNC(func)) { _listeners.push_back(func); }
|
||||
|
||||
void TriggerEvent(EventData* eventData) {
|
||||
void TriggerEvent(EventData* eventData) const {
|
||||
for (auto listener : _listeners) {
|
||||
listener(eventData);
|
||||
}
|
||||
|
|
|
@ -130,3 +130,4 @@ void Battle::AddVolatileScript(const ConstString& key) {
|
|||
}
|
||||
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
|
||||
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
|
||||
void Battle::DisplayText(const std::string& text) const { TriggerEventListener(new DisplayTextEvent(text)); }
|
||||
|
|
|
@ -89,8 +89,9 @@ namespace CreatureLib::Battling {
|
|||
bool HasVolatileScript(const ConstString& name) const { return _volatile.Has(name); }
|
||||
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
|
||||
|
||||
void DisplayText(const std::string& text) const;
|
||||
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
|
||||
void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }
|
||||
void TriggerEventListener(EventData* data) const { this->_eventHook.TriggerEvent(data); }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue