mirror of https://github.com/WerWolv/ImHex.git
Added custom event registry
This commit is contained in:
parent
46388f4707
commit
e27993aff2
|
@ -33,6 +33,10 @@ namespace hex {
|
|||
static std::map<std::string, std::vector<Entry>>& getEntries();
|
||||
static nlohmann::json& getSettingsData();
|
||||
};
|
||||
|
||||
struct Events {
|
||||
static auto get(std::string_view name);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
namespace hex {
|
||||
|
||||
enum class Events {
|
||||
enum class Events : u32 {
|
||||
FileLoaded,
|
||||
DataChanged,
|
||||
PatternChanged,
|
||||
|
@ -21,7 +23,11 @@ namespace hex {
|
|||
ProjectFileStore,
|
||||
ProjectFileLoad,
|
||||
|
||||
SettingsChanged
|
||||
SettingsChanged,
|
||||
|
||||
|
||||
/* This is not a real event but a flag to show all events after this one are plugin ones */
|
||||
Events_BuiltinEnd
|
||||
};
|
||||
|
||||
struct EventHandler {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <any>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <helpers/event.hpp>
|
||||
#include <helpers/content_registry.hpp>
|
||||
|
@ -55,30 +56,36 @@ namespace hex {
|
|||
static std::map<std::string, std::any> sharedVariablesStorage;
|
||||
static ImVec2 windowPosStorage, windowSizeStorage;
|
||||
static nlohmann::json settingsJsonStorage;
|
||||
static std::map<std::string, Events> customEventsStorage;
|
||||
static u32 customEventsLastIdStorage = u32(Events::Events_BuiltinEnd) + 1;
|
||||
|
||||
this->imguiContext = ImGui::GetCurrentContext();
|
||||
this->eventHandlers = &eventHandlersStorage;
|
||||
this->deferredCalls = &deferredCallsStorage;
|
||||
this->currentProvider = ¤tProviderStorage;
|
||||
this->settingsEntries = &settingsEntriesStorage;
|
||||
this->sharedVariables = &sharedVariablesStorage;
|
||||
this->settingsJson = &settingsJsonStorage;
|
||||
this->imguiContext = ImGui::GetCurrentContext();
|
||||
this->eventHandlers = &eventHandlersStorage;
|
||||
this->deferredCalls = &deferredCallsStorage;
|
||||
this->currentProvider = ¤tProviderStorage;
|
||||
this->settingsEntries = &settingsEntriesStorage;
|
||||
this->sharedVariables = &sharedVariablesStorage;
|
||||
this->settingsJson = &settingsJsonStorage;
|
||||
this->customEvents = &customEventsStorage;
|
||||
this->customEventsLastId = &customEventsLastIdStorage;
|
||||
|
||||
this->windowPos = &windowPosStorage;
|
||||
this->windowSize = &windowSizeStorage;
|
||||
this->windowPos = &windowPosStorage;
|
||||
this->windowSize = &windowSizeStorage;
|
||||
}
|
||||
|
||||
void initializeData(const SharedData &other) {
|
||||
this->imguiContext = other.imguiContext;
|
||||
this->eventHandlers = other.eventHandlers;
|
||||
this->deferredCalls = other.deferredCalls;
|
||||
this->currentProvider = other.currentProvider;
|
||||
this->settingsEntries = other.settingsEntries;
|
||||
this->sharedVariables = other.sharedVariables;
|
||||
this->settingsJson = other.settingsJson;
|
||||
this->imguiContext = other.imguiContext;
|
||||
this->eventHandlers = other.eventHandlers;
|
||||
this->deferredCalls = other.deferredCalls;
|
||||
this->currentProvider = other.currentProvider;
|
||||
this->settingsEntries = other.settingsEntries;
|
||||
this->sharedVariables = other.sharedVariables;
|
||||
this->settingsJson = other.settingsJson;
|
||||
this->customEvents = other.customEvents;
|
||||
this->customEventsLastId = other.customEventsLastId;
|
||||
|
||||
this->windowPos = other.windowPos;
|
||||
this->windowSize = other.windowSize;
|
||||
this->windowPos = other.windowPos;
|
||||
this->windowSize = other.windowSize;
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -88,6 +95,8 @@ namespace hex {
|
|||
prv::Provider **currentProvider;
|
||||
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> *settingsEntries;
|
||||
nlohmann::json *settingsJson;
|
||||
std::map<std::string, Events> *customEvents;
|
||||
u32 *customEventsLastId;
|
||||
|
||||
ImVec2 *windowPos;
|
||||
ImVec2 *windowSize;
|
||||
|
|
|
@ -47,4 +47,19 @@ namespace hex {
|
|||
return *SharedData::get().settingsJson;
|
||||
}
|
||||
|
||||
|
||||
/* Events */
|
||||
|
||||
auto ContentRegistry::Events::get(std::string_view name) {
|
||||
auto &customEvents = *SharedData::get().customEvents;
|
||||
auto &lastId = *SharedData::get().customEventsLastId;
|
||||
|
||||
if (!customEvents.contains(name.data())) {
|
||||
customEvents[name.data()] = static_cast<hex::Events>(lastId);
|
||||
lastId++;
|
||||
}
|
||||
|
||||
return customEvents[name.data()];
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue