92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
#include "EventListener.h"
|
|
#include "ArtifactTracker.h"
|
|
|
|
auto EventListener::GetSingleton() -> EventListener*
|
|
{
|
|
static EventListener singleton{};
|
|
return std::addressof(singleton);
|
|
}
|
|
|
|
void EventListener::Install()
|
|
{
|
|
RE::PlayerCharacter::GetSingleton()->AddEventSink<RE::BGSActorCellEvent>(EventListener::GetSingleton());
|
|
RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESContainerChangedEvent>(EventListener::GetSingleton());
|
|
}
|
|
|
|
auto EventListener::ProcessEvent(
|
|
const SKSE::ModCallbackEvent* a_event,
|
|
RE::BSTEventSource<SKSE::ModCallbackEvent>* a_eventSource)
|
|
-> RE::BSEventNotifyControl
|
|
{
|
|
if (a_event->eventName == "KID_KeywordDistributionDone") {
|
|
SKSE::GetModCallbackEventSource()->RemoveEventSink(EventListener::GetSingleton());
|
|
ArtifactTracker::OnKeywordDistribution();
|
|
}
|
|
|
|
return RE::BSEventNotifyControl::kContinue;
|
|
}
|
|
|
|
auto EventListener::ProcessEvent(
|
|
const RE::TESContainerChangedEvent* a_event,
|
|
RE::BSTEventSource<RE::TESContainerChangedEvent>* a_eventSource)
|
|
-> RE::BSEventNotifyControl
|
|
{
|
|
if (!ArtifactTracker::g_bHomeContainer && (a_event->newContainer == 0x14 || a_event->oldContainer == 0x14 || (ArtifactTracker::IsHome() && a_event->reference))) {
|
|
const auto form = ArtifactTracker::GetArtifactByID(a_event->baseObj);
|
|
if (form) {
|
|
ArtifactTracker::OnContainerChanged(a_event, form);
|
|
}
|
|
}
|
|
|
|
return RE::BSEventNotifyControl::kContinue;
|
|
}
|
|
|
|
auto EventListener::ProcessEvent(
|
|
const RE::BGSActorCellEvent* a_event,
|
|
RE::BSTEventSource<RE::BGSActorCellEvent>* a_eventSource)
|
|
-> RE::BSEventNotifyControl
|
|
{
|
|
// Fires on every cell change, loaded or not.
|
|
// If it's new and not loaded, we can't add a new cell storage.
|
|
// In this case, it registers TESCellFullyLoadedEvent, which ensures a new ref can be added.
|
|
if (a_event->flags == RE::BGSActorCellEvent::CellFlag::kEnter) {
|
|
#ifdef _DEBUG
|
|
SKSE::log::info("BGSActorCellEvent");
|
|
#endif
|
|
|
|
ArtifactTracker::OnCellEnter(a_event->cellID);
|
|
}
|
|
|
|
return RE::BSEventNotifyControl::kContinue;
|
|
}
|
|
|
|
auto EventListener::ProcessEvent(
|
|
const RE::TESCellFullyLoadedEvent* a_event,
|
|
RE::BSTEventSource<RE::TESCellFullyLoadedEvent>* a_eventSource)
|
|
-> RE::BSEventNotifyControl
|
|
{
|
|
#ifdef _DEBUG
|
|
SKSE::log::info("TESCellFullyLoadedEvent");
|
|
#endif
|
|
|
|
ArtifactTracker::OnCellEnter(a_event->cell->GetLocation(), a_event->cell);
|
|
|
|
return RE::BSEventNotifyControl::kContinue;
|
|
}
|
|
|
|
auto EventListener::ProcessEvent(
|
|
const RE::MenuOpenCloseEvent* a_event,
|
|
RE::BSTEventSource<RE::MenuOpenCloseEvent>* a_eventSource)
|
|
-> RE::BSEventNotifyControl
|
|
{
|
|
// This listener is expected to be unregistered outside of home.
|
|
if (ArtifactTracker::IsHome() && a_event->menuName == "ContainerMenu") {
|
|
#ifdef _DEBUG
|
|
SKSE::log::info("MenuOpenCloseEvent");
|
|
#endif
|
|
ArtifactTracker::SetContainerMode(a_event->opening);
|
|
}
|
|
|
|
return RE::BSEventNotifyControl::kContinue;
|
|
}
|