2022-10-21 22:05:39 +02:00
|
|
|
#include "gui/components/components.hpp"
|
|
|
|
#include "services/globals/globals_service.hpp"
|
|
|
|
#include "thread_pool.hpp"
|
|
|
|
#include "view_debug.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
void debug::globals()
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
if (ImGui::BeginTabItem("DEBUG_TAB_GLOBALS"_T.data()))
|
2022-10-21 22:05:39 +02:00
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
if (ImGui::Checkbox("DEBUG_GLOBALS_ENABLE_FREEZING"_T.data(), &g_globals_service->m_running)
|
|
|
|
&& g_globals_service->m_running)
|
|
|
|
g_thread_pool->push([&]() {
|
|
|
|
g_globals_service->loop();
|
|
|
|
});
|
2022-10-21 22:05:39 +02:00
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
if (components::button("LOAD"_T))
|
2022-10-21 22:05:39 +02:00
|
|
|
g_globals_service->load();
|
|
|
|
ImGui::SameLine();
|
2023-02-01 19:46:33 +01:00
|
|
|
if (components::button("SAVE"_T))
|
2022-10-21 22:05:39 +02:00
|
|
|
g_globals_service->save();
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
2023-02-01 19:46:33 +01:00
|
|
|
if (components::button("DEBUG_GLOBALS_ADD"_T))
|
2022-10-21 22:05:39 +02:00
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::OpenPopup("DEBUG_GLOBALS_NEW"_T.data());
|
2022-10-21 22:05:39 +02:00
|
|
|
}
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
if (ImGui::BeginPopupModal("DEBUG_GLOBALS_NEW"_T.data()))
|
2022-10-21 22:05:39 +02:00
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
static int base_address = 0;
|
|
|
|
static bool freeze = false;
|
|
|
|
static char name[32] = "";
|
2023-04-16 18:28:49 +00:00
|
|
|
static int offsets[10][2] = {};
|
2023-03-01 21:27:15 +00:00
|
|
|
static int offset_count = 0;
|
2022-10-21 22:05:39 +02:00
|
|
|
static int previous_offset_count = 0;
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("DEBUG_GLOBALS_NAME"_T.data());
|
2022-10-21 22:05:39 +02:00
|
|
|
components::input_text_with_hint("##global_name", "Name", name, sizeof(name));
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("DEBUG_GLOBALS_BASE_ADDRESS"_T.data());
|
2022-10-21 22:05:39 +02:00
|
|
|
ImGui::InputInt("##modal_global_base_addr", &base_address);
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("DEBUG_GLOBAL_FREEZE"_T.data());
|
2022-10-21 22:05:39 +02:00
|
|
|
ImGui::Checkbox("##modal_global_freeze", &freeze);
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("DEBUG_GLOBAL_OFFSET_COUNT"_T.data());
|
2022-10-21 22:05:39 +02:00
|
|
|
ImGui::InputInt("##modal_offset_count", &offset_count);
|
|
|
|
|
2023-04-16 18:28:49 +00:00
|
|
|
offset_count = std::clamp(offset_count, 0, 10);
|
2022-10-21 22:05:39 +02:00
|
|
|
|
|
|
|
ImGui::PushItemWidth(320.f);
|
|
|
|
for (int i = 0; i < offset_count; i++)
|
|
|
|
{
|
|
|
|
ImGui::PushID(i);
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("DEBUG_GLOBAL_OFFSET"_T.data(), i + 1);
|
2022-10-21 22:05:39 +02:00
|
|
|
ImGui::InputInt("##offset", &offsets[i][0]);
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("DEBUG_GLOBAL_SIZE"_T.data());
|
2022-10-21 22:05:39 +02:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::InputInt("##size", &offsets[i][1]);
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
}
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
if (components::button("CANCEL"_T))
|
2022-10-21 22:05:39 +02:00
|
|
|
{
|
|
|
|
strcpy(name, "");
|
2023-04-16 18:28:49 +00:00
|
|
|
freeze = false;
|
2023-03-01 21:27:15 +00:00
|
|
|
offset_count = 0;
|
2022-10-21 22:05:39 +02:00
|
|
|
previous_offset_count = 0;
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2023-02-01 19:46:33 +01:00
|
|
|
if (components::button("SAVE"_T))
|
2022-10-21 22:05:39 +02:00
|
|
|
{
|
|
|
|
auto new_global = global(name, base_address, freeze, offsets, offset_count);
|
|
|
|
new_global.build_cache();
|
|
|
|
|
|
|
|
g_globals_service->m_globals.push_back(new_global);
|
|
|
|
|
|
|
|
strcpy(name, "");
|
2023-04-16 18:28:49 +00:00
|
|
|
freeze = false;
|
2023-03-01 21:27:15 +00:00
|
|
|
offset_count = 0;
|
2022-10-21 22:05:39 +02:00
|
|
|
previous_offset_count = 0;
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& global : g_globals_service->m_globals)
|
|
|
|
{
|
|
|
|
char label[64];
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
ImGui::PushID(global.get_id());
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Checkbox("DEBUG_GLOBAL_FREEZE_TOGGLE"_T.data(), &global.m_freeze);
|
2022-10-21 22:05:39 +02:00
|
|
|
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("DEBUG_GLOBALS_NAME"_T.data());
|
|
|
|
ImGui::Text("DEBUG_GLOBALS_VALUE"_T.data());
|
2022-10-21 22:05:39 +02:00
|
|
|
|
|
|
|
ImGui::EndGroup();
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
|
|
|
|
ImGui::Text(global.m_name.c_str());
|
|
|
|
|
|
|
|
sprintf(label, "###input_%d", global.get_id());
|
|
|
|
ImGui::SetNextItemWidth(200.f);
|
|
|
|
ImGui::InputInt(label, global.get());
|
|
|
|
|
|
|
|
ImGui::EndGroup();
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
if (components::button("DELETE"_T))
|
2022-10-21 22:05:39 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < g_globals_service->m_globals.size(); i++)
|
|
|
|
if (auto& it = g_globals_service->m_globals.at(i); it.get_id() == global.get_id())
|
|
|
|
g_globals_service->m_globals.erase(g_globals_service->m_globals.begin() + i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
if (components::button("WRITE"_T))
|
2022-10-21 22:05:39 +02:00
|
|
|
global.write();
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
ImGui::EndGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|