This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/views/settings/view_lua_scripts.cpp
Quentin 6d6848c2fb
Lua: refactor script api, more doc, add button for Open Lua Scripts Folder (#1588)
* lua manager: pass down the scripts folder to the instance instead of hard coding calls to the file manager everywhere
* lua: add open lua scripts folder button
* lua api: change script binding so that user cannot by mistake try to sleep or yield in a non script context
2023-07-03 13:01:12 +02:00

67 lines
1.8 KiB
C++

#include "fiber_pool.hpp"
#include "lua/lua_manager.hpp"
#include "script.hpp"
#include "thread_pool.hpp"
#include "util/scripts.hpp"
#include "views/view.hpp"
namespace big
{
static std::weak_ptr<lua_module> selected_module{};
void view::lua_scripts()
{
ImGui::PushItemWidth(250);
components::sub_title("Loaded Lua Scipts");
if (ImGui::BeginListBox("##empty", ImVec2(200, 200)))
{
g_lua_manager->for_each_module([](auto& module) {
if (ImGui::Selectable(module->module_name().c_str(),
!selected_module.expired() && selected_module.lock().get() == module.get()))
selected_module = module;
});
ImGui::EndListBox();
}
ImGui::SameLine();
ImGui::BeginGroup();
if (!selected_module.expired())
{
ImGui::Text("Scripts Registered: %d", selected_module.lock()->m_registered_scripts.size());
ImGui::Text("Memory Patches Registered: %d", selected_module.lock()->m_registered_patches.size());
ImGui::Text("GUI Tabs Registered: %d", selected_module.lock()->m_gui.size());
if (components::button("Reload"))
{
auto name = selected_module.lock()->module_name();
auto id = selected_module.lock()->module_id();
g_lua_manager->unload_module(id);
g_lua_manager->queue_load_module(name, [](std::weak_ptr<big::lua_module> loaded_module) {
selected_module = loaded_module;
});
}
}
ImGui::EndGroup();
if (components::button("Reload All"))
{
g_lua_manager->m_schedule_reload_modules = true;
}
ImGui::SameLine();
ImGui::Checkbox("Auto Reload Changed Scripts", &g.lua.enable_auto_reload_changed_scripts);
if (components::button("Open Lua Scripts Folder"))
{
std::string command = "explorer.exe /select," + g_lua_manager->get_scripts_folder().get_path().string();
std::system(command.c_str());
}
}
}