mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-19 19:26:36 +02:00
add imgui engine tools (based on imgui menu bar)
This commit is contained in:
89
framework/imgui/src/mm/services/engine_tools.cpp
Normal file
89
framework/imgui/src/mm/services/engine_tools.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "./engine_tools.hpp"
|
||||
|
||||
#include <entt/config/version.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <mm/logger.hpp>
|
||||
#define LOGIGS(x) LOG("ImGuiSceneToolsService", x)
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
bool ImGuiEngineTools::enable(Engine& engine) {
|
||||
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||
|
||||
menu_bar.menu_tree["Engine"]["Stop Engine"] = [](Engine& e) {
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Stop Engine")) {
|
||||
e.stop();
|
||||
}
|
||||
};
|
||||
|
||||
menu_bar.menu_tree["Engine"]["About"] = [this](Engine&) {
|
||||
ImGui::MenuItem("About", NULL, &_show_about);
|
||||
};
|
||||
|
||||
menu_bar.menu_tree["Engine"]["Services"] = [this](Engine&) {
|
||||
ImGui::MenuItem("Services", NULL, &_show_services);
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::disable(Engine& engine) {
|
||||
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||
|
||||
menu_bar.menu_tree["Engine"].erase("Stop Engine");
|
||||
}
|
||||
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiEngineTools::registerUpdates(void) {
|
||||
using namespace entt::literals;
|
||||
return {
|
||||
{
|
||||
"ImGuiEngineTools::render"_hs,
|
||||
"ImGuiEngineTools::render",
|
||||
[this](Engine& e){ renderImGui(e); },
|
||||
UpdateStrategies::update_phase_t::MAIN,
|
||||
true,
|
||||
{
|
||||
"ImGuiMenuBar::render"_hs
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::renderImGui(Engine& engine) {
|
||||
if (_show_about) {
|
||||
renderAbout();
|
||||
}
|
||||
|
||||
if (_show_services) {
|
||||
renderServices(engine);
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::renderAbout(void) {
|
||||
if (ImGui::Begin("About##EngineTools", &_show_about)) {
|
||||
ImGui::Text("TODO");
|
||||
ImGui::Text("MushMachine");
|
||||
ImGui::Text("EnTT v%d.%d.%d", ENTT_VERSION_MAJOR, ENTT_VERSION_MINOR, ENTT_VERSION_PATCH);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::renderServices(Engine& engine) {
|
||||
if (ImGui::Begin("Services##EngineTools", &_show_services)) {
|
||||
ImGui::Text("TODO: use new table api");
|
||||
|
||||
for (auto& it : engine._services) {
|
||||
ImGui::Text("[%d|%s]: %s", it.first, it.second->second->name(), it.second->first ? "enabled" : "disabled");
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // namespace MM::Services
|
||||
|
28
framework/imgui/src/mm/services/engine_tools.hpp
Normal file
28
framework/imgui/src/mm/services/engine_tools.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "./imgui_menu_bar.hpp"
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
class ImGuiEngineTools : public Service {
|
||||
public:
|
||||
const char* name(void) override { return "ImGuiEngineTools"; }
|
||||
|
||||
bool enable(Engine& engine) override;
|
||||
void disable(Engine& engine) override;
|
||||
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override;
|
||||
|
||||
private:
|
||||
bool _show_about = false;
|
||||
bool _show_services = false;
|
||||
|
||||
private:
|
||||
void renderImGui(Engine& engine);
|
||||
|
||||
void renderAbout(void);
|
||||
void renderServices(Engine& engine);
|
||||
};
|
||||
|
||||
} // namespace MM::Services
|
||||
|
@ -80,7 +80,7 @@ namespace MM::Services {
|
||||
}
|
||||
|
||||
|
||||
ImGui::Text("%.1fFPS", ImGui::GetIO().Framerate);
|
||||
ImGui::Text("| %.1fFPS", ImGui::GetIO().Framerate);
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user