Код:
void lua_edit(std::string window_name)
{
std::string file_path = crypt_str("C:\\Oreo\\Scripts\\");
file_path += window_name + crypt_str(".lua");
const char* child_name = (window_name + window_name).c_str();
ImGui::SetNextWindowSize(ImVec2(700, 600), ImGuiCond_FirstUseEver);
ImGui::Begin(window_name.c_str(), nullptr, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar);
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 5.f);
static TextEditor editor;
if (!loaded_editing_script)
{
static auto lang = TextEditor::LanguageDefinition::Lua();
editor.SetLanguageDefinition(lang);
editor.SetReadOnly(false);
std::ifstream t(file_path);
if (t.good())
{
std::string str((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
editor.SetText(str);
}
loaded_editing_script = true;
}
ImGui::SetWindowFontScale(1.f + ((c_menu::get().dpi_scale - 1.0) * 0.5f));
ImGui::SetWindowSize(ImVec2(ImFloor(800 * (1.f + ((c_menu::get().dpi_scale - 1.0) * 0.5f))), ImFloor(700 * (1.f + ((c_menu::get().dpi_scale - 1.0) * 0.5f)))));
editor.Render(child_name, ImGui::GetWindowSize() - ImVec2(0, 66 * (1.f + ((c_menu::get().dpi_scale - 1.0) * 0.5f))));
ImGui::Separator();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetWindowSize().x - (16.f * (1.f + ((c_menu::get().dpi_scale - 1.0) * 0.5f))) - (250.f * (1.f + ((c_menu::get().dpi_scale - 1.0) * 0.5f))));
ImGui::BeginGroup();
if (ImGui::Button(crypt_str("Save"), ImVec2(70, 20)))
{
std::ofstream out;
out.open(file_path);
out << editor.GetText() << std::endl;
out.close();
}
ImGui::SameLine();
if (ImGui::Button(crypt_str("Close"), ImVec2(70, 20)))
{
g_ctx.globals.focused_on_input = false;
loaded_editing_script = false;
editing_script.clear();
}
ImGui::EndGroup();
ImGui::PopStyleVar();
ImGui::End();
}