// MassBuilderSaveTool // Copyright (C) 2021-2024 Guillaume Jacquemin // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include #include #include "../Configuration/Configuration.h" #include "../FontAwesome/IconsFontAwesome5.h" #include "../FontAwesome/IconsFontAwesome5Brands.h" #include "../Logger/Logger.h" #include "Application.h" namespace mbst { void Application::initEvent(SDL_Event& event) { _initThread.join(); switch(event.user.code) { case InitSuccess: _uiState = UiState::ProfileManager; ImGui::CloseCurrentPopup(); break; case ProfileManagerFailure: SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error ", _profileManager->lastError().data(), window()); exit(EXIT_FAILURE); break; default: break; } } void Application::initialiseConfiguration() { LOG_INFO("Reading configuration file."); setSwapInterval(conf().swapInterval()); setMinimalLoopPeriod(0); } void Application::initialiseGui() { LOG_INFO("Initialising Dear ImGui."); auto ctx = ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); const auto size = Vector2{windowSize()}/dpiScaling(); auto reg_font = _rs.getRaw("SourceSansPro-Regular.ttf"_s); ImFontConfig font_config; font_config.FontDataOwnedByAtlas = false; std::strcpy(font_config.Name, "Source Sans Pro"); io.Fonts->AddFontFromMemoryTTF(const_cast(reg_font.data()), int(reg_font.size()), 20.0f * float(framebufferSize().x()) / size.x(), &font_config); auto icon_font = _rs.getRaw(FONT_ICON_FILE_NAME_FAS); static const ImWchar icon_range[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; ImFontConfig icon_config; icon_config.FontDataOwnedByAtlas = false; icon_config.MergeMode = true; icon_config.PixelSnapH = true; icon_config.OversampleH = icon_config.OversampleV = 1; icon_config.GlyphMinAdvanceX = 18.0f; io.Fonts->AddFontFromMemoryTTF(const_cast(icon_font.data()), int(icon_font.size()), 16.0f * float(framebufferSize().x()) / size.x(), &icon_config, icon_range); auto brand_font = _rs.getRaw(FONT_ICON_FILE_NAME_FAB); static const ImWchar brand_range[] = { ICON_MIN_FAB, ICON_MAX_FAB, 0 }; io.Fonts->AddFontFromMemoryTTF(const_cast(brand_font.data()), int(brand_font.size()), 16.0f * float(framebufferSize().x()) / size.x(), &icon_config, brand_range); auto mono_font = _rs.getRaw("SourceCodePro-Regular.ttf"_s); io.Fonts->AddFontFromMemoryTTF(const_cast(mono_font.data()), int(mono_font.size()), 18.0f * float(framebufferSize().x()) / size.x(), &font_config); _imgui = ImGuiIntegration::Context(*ctx, Vector2{windowSize()}/dpiScaling(), windowSize(), framebufferSize()); io.IniFilename = nullptr; ImGuiStyle& style = ImGui::GetStyle(); style.WindowTitleAlign = {0.5f, 0.5f}; style.FrameRounding = 3.2f; style.Colors[ImGuiCol_WindowBg] = ImColor(0xff1f1f1f); } void Application::initialiseManager() { LOG_INFO("Initialising the profile manager."); SDL_Event event; SDL_zero(event); event.type = _initEventId; _profileManager.emplace(); if(!_profileManager->ready()) { event.user.code = ProfileManagerFailure; SDL_PushEvent(&event); return; } _backupManager.emplace(); event.user.code = InitSuccess; SDL_PushEvent(&event); } void Application::initialiseMassManager() { LOG_INFO("Initialising the M.A.S.S. manager."); _massManager.emplace(conf().directories().gameSaves, _currentProfile->account(), _currentProfile->isDemo(), conf().directories().staging); } void Application::initialiseFileWatcher() { LOG_INFO("Initialising the file watcher."); _fileWatcher.emplace(); _watchIDs[SaveDir] = _fileWatcher->addWatch(conf().directories().gameSaves, this, false); _watchIDs[StagingDir] = _fileWatcher->addWatch(conf().directories().staging, this, false); _fileWatcher->watch(); } }