#pragma once // MassBuilderSaveTool // Copyright (C) 2021 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 #include #include #include #include #include #include #include "../MassBuilderManager/MassBuilderManager.h" #include "../ProfileManager/ProfileManager.h" #include "../MassManager/MassManager.h" using namespace Corrade; using namespace Magnum; class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener { public: explicit SaveTool(const Arguments& arguments); ~SaveTool() override; void handleFileAction(efsw::WatchID watch_id, const std::string& dir, const std::string& filename, efsw::Action action, std::string old_filename = "") override; private: // Events void drawEvent() override; void viewportEvent(ViewportEvent& event) override; void keyPressEvent(KeyEvent& event) override; void keyReleaseEvent(KeyEvent& event) override; void mousePressEvent(MouseEvent& event) override; void mouseReleaseEvent(MouseEvent& event) override; void mouseMoveEvent(MouseMoveEvent& event) override; void mouseScrollEvent(MouseScrollEvent& event) override; void textInputEvent(TextInputEvent& event) override; void anyEvent(SDL_Event& event) override; enum InitStatus: Int { InitSuccess, MbManagerFailure, ProfileManagerFailure }; void initEvent(SDL_Event& event); // Initialisation methods void initialiseGui(); void initialiseManager(); void initialiseMassManager(); void initialiseFileWatcher(); // GUI-related methods void drawImGui(); void drawGui(); void drawMainMenu(); void drawDisclaimer(); void drawInitialisation(); void drawProfileManager(); auto drawBackupListPopup() -> ImGuiID; auto drawBackupProfilePopup(std::size_t profile_index) -> ImGuiID; auto drawDeleteProfilePopup(std::size_t profile_index) -> ImGuiID; void drawManager(); auto drawIntEditPopup(int* value_to_edit, int max) -> bool; auto drawRenamePopup(Containers::ArrayView name_view) -> bool; void drawGeneralInfo(); void drawResearchInventory(); void drawMassManager(); auto drawDeleteMassPopup(int mass_index) -> ImGuiID; auto drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID; void drawAbout(); void drawGameState(); // Convenience wrappers over ImGui stuff void drawHelpMarker(const char* text, Float wrap_pos = 0.0f); void drawTooltip(const char* text, Float wrap_pos = 0.0f); template auto drawUnsafeWidget(Functor func, Args... args) -> bool { GameState game_state = _mbManager->gameState(); if(!_unsafeMode && game_state != GameState::NotRunning) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f); } bool result = func(std::forward(args)...); if(!_unsafeMode && game_state != GameState::NotRunning) { ImGui::PopItemFlag(); ImGui::PopStyleVar(); } return result; } // Obviously, should only be used with ImGui widgets that return a bool. // Also, func should be a lambda if there are any default arguments, like ImGui::Button(), etc... void drawUnsafeText(const char* text, ...); // Alternative to the above, for ImGui::Text*() variants. void openUri(const std::string& uri); Utility::Resource _rs{"assets"}; // GUI-related members ImGuiIntegration::Context _imgui{NoCreate}; enum class UiState: uint8_t { Disclaimer, Initialising, ProfileManager, MainManager }; UiState _uiState{UiState::Disclaimer}; bool _aboutPopup{false}; #ifdef MANAGER_DEBUG_BUILD bool _demoWindow{false}; bool _styleEditor{false}; bool _metricsWindow{false}; #endif std::thread _thread; UnsignedInt _initEventId; Containers::Pointer _mbManager; SDL_TimerID _gameCheckTimerId; Containers::Pointer _profileManager; Profile* _currentProfile{nullptr}; Containers::Pointer _massManager; Containers::Pointer _fileWatcher; enum watchID { SaveDir = 0, StagingDir = 1 }; Containers::StaticArray<2, efsw::WatchID> _watchIDs; bool _unsafeMode{false}; };