1

New artifact notifications with combined report on Take All

This commit is contained in:
Eddoursul 2022-07-12 00:37:19 +02:00
parent a374e0c71f
commit 1797222063
5 changed files with 68 additions and 10 deletions

Binary file not shown.

View File

@ -8,9 +8,13 @@ using namespace SKSE::log;
namespace ArtifactTracker
{
bool g_bLoaded;
bool g_bHomeContainer;
bool g_bBookShelf;
bool g_bLoaded = false;
bool g_bHomeContainer = false;
bool g_bBookShelf = false;
bool g_bTakeAll = false;
bool g_bNotifyNewArtifact = false;
std::uint32_t g_bTakeAllCount = 0;
std::int32_t g_iFollowerIndex = 0;
RE::TESBoundObject* g_cellContainer;
RE::BGSListForm* g_listNew;
RE::BGSListForm* g_listStored;
@ -22,7 +26,6 @@ namespace ArtifactTracker
std::unordered_map<RE::FormID, RE::TESObjectREFR*> g_persistentMap;
RE::TESObjectREFR* g_cellStorage;
const SKSE::LoadInterface* g_loadInterface;
std::int32_t g_iFollowerIndex;
bool Init(bool bKID)
{
@ -61,9 +64,12 @@ namespace ArtifactTracker
std::map<std::string, bool> settings{
{ "DumpItemList", false },
{ "NewArtifactNotifications", true },
};
LoadINI(&settings, "Data/SKSE/Plugins/ArtifactTracker.ini");
g_bNotifyNewArtifact = settings.at("NewArtifactNotifications");
// Preloading item lists
g_artifactFormTypes.insert(RE::FormType::Weapon);
@ -279,7 +285,7 @@ namespace ArtifactTracker
if (cellStorage) {
g_bHomeContainer = false;
g_cellStorage = cellStorage;
RE::UI::GetSingleton()->AddEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
//RE::UI::GetSingleton()->AddEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESActivateEvent>(EventListener::GetSingleton());
#ifdef _DEBUG
log::info("Home mode ON");
@ -288,7 +294,7 @@ namespace ArtifactTracker
} else if (g_cellStorage) {
g_bHomeContainer = false;
g_cellStorage = nullptr;
RE::UI::GetSingleton()->RemoveEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
//RE::UI::GetSingleton()->RemoveEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
RE::ScriptEventSourceHolder::GetSingleton()->RemoveEventSink<RE::TESActivateEvent>(EventListener::GetSingleton());
#ifdef _DEBUG
log::info("Home mode OFF");
@ -521,6 +527,14 @@ namespace ArtifactTracker
if (!g_listStored->HasForm(form) && !g_listFound->HasForm(form)) { // it's a new item, move it to found
ListRemoveItem(g_listNew, form);
g_listFound->AddForm(form);
if (g_bNotifyNewArtifact) {
if (g_bTakeAll) {
g_bTakeAllCount++;
} else {
RE::DebugNotification(fmt::format("New artifact acquired: {}", form->GetName()).c_str());
}
}
}
} else if (g_cellStorage && g_cellStorage->formID == a_event->newContainer) {

View File

@ -5,6 +5,9 @@ namespace ArtifactTracker
extern bool g_bLoaded;
extern bool g_bHomeContainer;
extern bool g_bBookShelf;
extern bool g_bTakeAll;
extern bool g_bNotifyNewArtifact;
extern std::uint32_t g_bTakeAllCount;
extern RE::TESBoundObject* g_cellContainer;
extern RE::BGSListForm* g_listNew;
extern RE::BGSListForm* g_listStored;

View File

@ -13,6 +13,7 @@ void EventListener::Install()
RE::PlayerCharacter::GetSingleton()->AddEventSink<RE::BGSActorCellEvent>(EventListener::GetSingleton());
RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESContainerChangedEvent>(EventListener::GetSingleton());
RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESActorLocationChangeEvent>(EventListener::GetSingleton());
RE::UI::GetSingleton()->AddEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
}
auto EventListener::ProcessEvent(
@ -78,12 +79,25 @@ auto EventListener::ProcessEvent(
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") {
if (a_event->menuName == "ContainerMenu") {
#ifdef _DEBUG
SKSE::log::info("MenuOpenCloseEvent");
#endif
ArtifactTracker::SetContainerMode(a_event->opening);
if (a_event->opening) {
RE::BSInputDeviceManager::GetSingleton()->AddEventSink(EventListener::GetSingleton());
} else {
RE::BSInputDeviceManager::GetSingleton()->RemoveEventSink(EventListener::GetSingleton());
if (ArtifactTracker::g_bTakeAll && ArtifactTracker::g_bTakeAllCount > 0) {
RE::DebugNotification(fmt::format("{} new artifact(s) acquired", ArtifactTracker::g_bTakeAllCount).c_str());
}
ArtifactTracker::g_bTakeAll = false;
ArtifactTracker::g_bTakeAllCount = 0;
}
if (ArtifactTracker::IsHome()) {
ArtifactTracker::SetContainerMode(a_event->opening);
}
}
return RE::BSEventNotifyControl::kContinue;
@ -119,3 +133,24 @@ auto EventListener::ProcessEvent(
return RE::BSEventNotifyControl::kContinue;
}
RE::BSEventNotifyControl EventListener::ProcessEvent(
RE::InputEvent* const* a_event,
RE::BSTEventSource<RE::InputEvent*>* a_eventSource)
{
if (RE::UI::GetSingleton()->GameIsPaused()) {
auto inputEvent = a_event ? *a_event : nullptr;
auto buttonEvent = inputEvent ? inputEvent->AsButtonEvent() : nullptr;
if (!buttonEvent) {
return RE::BSEventNotifyControl::kContinue;
}
if (RE::UI::GetSingleton()->IsMenuOpen("ContainerMenu") && buttonEvent->QUserEvent() == RE::UserEvents::GetSingleton()->xButton) {
ArtifactTracker::g_bTakeAll = true;
ArtifactTracker::g_bTakeAllCount = 0;
}
}
return RE::BSEventNotifyControl::kContinue;
}

View File

@ -7,7 +7,8 @@ class EventListener :
public RE::BSTEventSink<RE::BGSActorCellEvent>,
public RE::BSTEventSink<RE::MenuOpenCloseEvent>,
public RE::BSTEventSink<RE::TESActivateEvent>,
public RE::BSTEventSink<RE::TESActorLocationChangeEvent>
public RE::BSTEventSink<RE::TESActorLocationChangeEvent>,
public RE::BSTEventSink<RE::InputEvent*>
{
public:
~EventListener() = default;
@ -54,6 +55,11 @@ public:
RE::BSTEventSource<RE::TESActorLocationChangeEvent>* a_eventSource)
-> RE::BSEventNotifyControl override;
RE::BSEventNotifyControl ProcessEvent(
RE::InputEvent* const* a_event,
RE::BSTEventSource<RE::InputEvent*>* a_eventSource)
override;
private:
EventListener() = default;
};