MassBuilderSaveTool/src/SaveTool/SaveTool_MainManager.cpp

721 lines
28 KiB
C++
Raw Normal View History

// MassBuilderSaveTool
// Copyright (C) 2021-2022 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 <https://www.gnu.org/licenses/>.
#include "SaveTool.h"
#include <algorithm>
#include <Corrade/Containers/Reference.h>
#include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/String.h>
#include "../FontAwesome/IconsFontAwesome5.h"
#include "../Maps/LastMissionId.h"
#include "../Maps/StoryProgress.h"
static const std::string empty_str;
void SaveTool::drawManager() {
ImGui::SetNextWindowPos({0.0f, ImGui::GetItemRectSize().y}, ImGuiCond_Always);
2021-06-20 14:13:30 +02:00
ImGui::SetNextWindowSize({Float(windowSize().x()), Float(windowSize().y()) - ImGui::GetItemRectSize().y},
ImGuiCond_Always);
if(!ImGui::Begin("##MainWindow", nullptr,
ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_NoMove|
ImGuiWindowFlags_NoBackground|ImGuiWindowFlags_NoBringToFrontOnFocus))
{
ImGui::End();
return;
}
drawAlignedText("Current profile: %s (%s)",
_currentProfile->companyName(),
_currentProfile->type() == ProfileType::Demo ? "demo" : "full game");
2021-07-23 14:17:42 +02:00
ImGui::SameLine();
2021-08-19 14:31:17 +02:00
if(ImGui::Button(ICON_FA_ARROW_LEFT " Back to profile manager")) {
2021-07-23 14:17:42 +02:00
_currentProfile = nullptr;
_massManager.reset();
_fileWatcher.reset();
_uiState = UiState::ProfileManager;
}
2021-06-21 00:28:16 +02:00
if(ImGui::BeginChild("##ProfileInfo",
{ImGui::GetContentRegionAvailWidth() * 0.60f, 0.0f},
2021-06-20 23:48:23 +02:00
true, ImGuiWindowFlags_MenuBar))
{
if(ImGui::BeginMenuBar()) {
2021-06-21 00:28:16 +02:00
ImGui::TextUnformatted("Profile information");
2021-06-20 23:48:23 +02:00
ImGui::EndMenuBar();
}
2021-06-21 00:28:16 +02:00
if(ImGui::BeginTabBar("##ProfileTabBar")) {
if(ImGui::BeginTabItem("General info")) {
drawGeneralInfo();
ImGui::EndTabItem();
}
2021-06-21 00:28:16 +02:00
if(ImGui::BeginTabItem("Research inventory")) {
drawResearchInventory();
ImGui::EndTabItem();
}
2021-06-21 00:28:16 +02:00
ImGui::EndTabBar();
2021-06-20 23:48:23 +02:00
}
}
ImGui::EndChild();
ImGui::SameLine();
2021-06-20 23:48:23 +02:00
if(ImGui::BeginChild("##MASSManager", {0.0f, 0.0f},
true, ImGuiWindowFlags_MenuBar))
{
if(ImGui::BeginMenuBar()) {
ImGui::TextUnformatted("M.A.S.S. management");
drawHelpMarker("To move, import, or export builds, drag-and-drop them.");
ImGui::EndMenuBar();
}
drawMassManager();
}
ImGui::EndChild();
ImGui::End();
}
auto SaveTool::drawIntEditPopup(int* value_to_edit, int max) -> bool {
bool apply = false;
if(ImGui::BeginPopup("int_edit")) {
ImGui::Text("Please enter a value between 0 and %i:", max);
ImGui::AlignTextToFramePadding();
drawHelpMarker("You can either drag the widget left or right to change the value,\n"
"or click on it while holding Ctrl to edit the value directly.");
ImGui::SameLine();
drawUnsafeWidget([](auto... args){ return ImGui::SliderInt("", args...); },
value_to_edit, 0, max, "%d", ImGuiSliderFlags_AlwaysClamp);
ImGui::SameLine();
if(drawUnsafeWidget([]{ return ImGui::Button("Apply"); })) {
apply = true;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
return apply;
}
auto SaveTool::drawRenamePopup(Containers::ArrayView<char> name_view) -> bool {
bool apply = false;
if(ImGui::BeginPopup("name_edit")) {
ImGui::TextUnformatted("Please enter a new name. Conditions:");
std::size_t len = std::strlen(name_view.data());
ImGui::BulletText("Length between 6 and 32 characters included. %s",
(len >= 6 && len <= 32) ? ICON_FA_CHECK : ICON_FA_TIMES);
ImGui::BulletText("Only A-Z, a-z, 0-9, -, and whitespaces. " ICON_FA_CHECK);
ImGui::BulletText("No whitespace at the beginning or end. %s",
(name_view[0] != ' ' && name_view[len - 1] != ' ') ? ICON_FA_CHECK : ICON_FA_TIMES);
static auto callback = [](ImGuiInputTextCallbackData* data)->int {
if(data->EventChar < 256 && std::strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- ", char(data->EventChar))) {
return 0;
}
return 1;
};
drawUnsafeWidget([](auto... args){ return ImGui::InputText("", args...); },
name_view.data(), name_view.size(),
ImGuiInputTextFlags_CallbackCharFilter,
callback, nullptr);
ImGui::SameLine();
GameState game_state = _gameState;
2021-07-10 16:46:45 +02:00
if((!_unsafeMode && game_state != GameState::NotRunning) ||
!(len >= 6 && len <= 32) ||
2021-07-10 16:46:45 +02:00
!(name_view[0] != ' ' && name_view[len - 1] != ' '))
{
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f);
}
if(ImGui::Button("Apply")) {
apply = true;
ImGui::CloseCurrentPopup();
}
2021-07-10 16:46:45 +02:00
if((!_unsafeMode && game_state != GameState::NotRunning) ||
!(len >= 6 && len <= 32) ||
2021-07-10 16:46:45 +02:00
!(name_view[0] != ' ' && name_view[len - 1] != ' '))
{
ImGui::PopItemFlag();
ImGui::PopStyleVar();
}
ImGui::EndPopup();
}
return apply;
}
void SaveTool::drawGeneralInfo() {
if(!_currentProfile) {
return;
}
ImGui::Text("Credits: %i", _currentProfile->credits());
auto it = std::find_if(story_progress.begin(), story_progress.end(),
[this](const StoryProgressPoint& p){ return p.id == _currentProfile->storyProgress(); });
if(it != story_progress.end())
{
ImGui::TextUnformatted("Story progress:");
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.x / 4.0f);
if(!it->after) {
ImGui::TextWrapped("%s - %s", it->chapter, it->point);
}
else {
ImGui::TextWrapped("%s - %s - %s", it->chapter, it->after, it->point);
}
}
else {
ImGui::Text("Story progress: 0x%x", _currentProfile->storyProgress());
}
if(mission_id_map.find(_currentProfile->lastMissionId()) != mission_id_map.cend()) {
ImGui::Text("Last mission: %s", mission_id_map.at(_currentProfile->lastMissionId()));
}
else if(_currentProfile->lastMissionId() == -1) {
ImGui::TextUnformatted("Last mission: none");
}
else {
ImGui::Text("Last mission: 0x%x", _currentProfile->lastMissionId());
}
drawTooltip("This is the last mission selected in the mission selection screen, not the last mission played.",
windowSize().x() * 0.35f);
2021-06-20 14:13:30 +02:00
const Float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
ImGui::Dummy({ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y - footer_height_to_reserve});
ImGui::Separator();
static Containers::StaticArray<33, char> name_buf{ValueInit};
if(drawUnsafeWidget([]{ return ImGui::Button("Rename company"); })) {
for(auto& c : name_buf) {
c = '\0';
}
std::strncpy(name_buf.data(), _currentProfile->companyName().data(), 32);
ImGui::OpenPopup("name_edit");
}
if(drawRenamePopup(name_buf)) {
if(!_currentProfile->renameCompany(name_buf.data())) {
_queue.addToast(Toast::Type::Error, _currentProfile->lastError());
}
}
2021-07-28 15:00:15 +02:00
if(!_cheatMode) {
return;
}
ImGui::SameLine();
2021-06-20 14:13:30 +02:00
static Int credits;
if(drawUnsafeWidget([]{ return ImGui::Button("Edit credits"); })) {
credits = _currentProfile->credits();
ImGui::OpenPopup("int_edit");
}
2021-07-10 16:47:18 +02:00
if(drawIntEditPopup(&credits, 20000000)) {
if(!_currentProfile->setCredits(credits)) {
_queue.addToast(Toast::Type::Error, _currentProfile->lastError());
}
}
ImGui::SameLine();
if(drawUnsafeWidget([]{ return ImGui::Button("Change story progression"); })) {
ImGui::OpenPopup("StoryProgressMenu");
}
drawTooltip("Story progress directly affects unlocked levels.");
if(ImGui::BeginPopup("StoryProgressMenu")) {
if(!_unsafeMode && _gameState != GameState::NotRunning) {
ImGui::CloseCurrentPopup();
}
for(const auto& sp : story_progress) {
if(ImGui::BeginMenu(sp.chapter.data())) {
if(!sp.after) {
if(ImGui::MenuItem(sp.point.data())) {
if(!_currentProfile->setStoryProgress(sp.id)) {
_queue.addToast(Toast::Type::Error, _currentProfile->lastError());
}
}
}
else {
if(ImGui::BeginMenu(sp.after.data())) {
if(ImGui::MenuItem(sp.point.data())) {
if(!_currentProfile->setStoryProgress(sp.id)) {
_queue.addToast(Toast::Type::Error, _currentProfile->lastError());
}
}
ImGui::EndMenu();
}
}
ImGui::EndMenu();
}
}
ImGui::EndPopup();
}
}
void SaveTool::drawResearchInventory() {
if(!_currentProfile) {
return;
}
if(ImGui::BeginTable("##ResearchInventoryTable", 4,
ImGuiTableFlags_BordersOuter|ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersInnerH))
{
ImGui::TableSetupColumn("##Tier", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("##Name", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("##Value", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##Edit", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableSetColumnIndex(1);
ImGui::Text("Engine materials");
drawMaterialRow("Verse steel", 1,
[this]{ return _currentProfile->verseSteel(); },
[this](Int amount){ return _currentProfile->setVerseSteel(amount); });
drawMaterialRow("Undinium", 2,
[this]{ return _currentProfile->undinium(); },
[this](Int amount){ return _currentProfile->setUndinium(amount); });
drawMaterialRow("Necrium alloy", 3,
[this]{ return _currentProfile->necriumAlloy(); },
[this](Int amount){ return _currentProfile->setNecriumAlloy(amount); });
drawMaterialRow("Lunarite", 4,
[this]{ return _currentProfile->lunarite(); },
[this](Int amount){ return _currentProfile->setLunarite(amount); });
drawMaterialRow("Asterite", 5,
[this]{ return _currentProfile->asterite(); },
[this](Int amount){ return _currentProfile->setAsterite(amount); });
drawUnavailableMaterialRow("Hallite fragma", 6);
drawUnavailableMaterialRow("Unnoctinium", 7);
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableSetColumnIndex(1);
ImGui::Text("OS materials");
drawMaterialRow("Ednil", 1,
[this]{ return _currentProfile->ednil(); },
[this](Int amount){ return _currentProfile->setEdnil(amount); });
drawMaterialRow("Nuflalt", 2,
[this]{ return _currentProfile->nuflalt(); },
[this](Int amount){ return _currentProfile->setNuflalt(amount); });
drawMaterialRow("Aurelene", 3,
[this]{ return _currentProfile->aurelene(); },
[this](Int amount){ return _currentProfile->setAurelene(amount); });
drawMaterialRow("Soldus", 4,
[this]{ return _currentProfile->soldus(); },
[this](Int amount){ return _currentProfile->setSoldus(amount); });
drawMaterialRow("Synthesized N", 5,
[this]{ return _currentProfile->synthesisedN(); },
[this](Int amount){ return _currentProfile->setSynthesisedN(amount); });
drawUnavailableMaterialRow("Nanoc", 6);
drawUnavailableMaterialRow("Abyssillite", 7);
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableSetColumnIndex(1);
ImGui::Text("Architect materials");
drawMaterialRow("Alcarbonite", 1,
[this]{ return _currentProfile->alcarbonite(); },
[this](Int amount){ return _currentProfile->setAlcarbonite(amount); });
drawMaterialRow("Keripehene", 2,
[this]{ return _currentProfile->keriphene(); },
[this](Int amount){ return _currentProfile->setKeriphene(amount); });
drawMaterialRow("Nitinol-CM", 3,
[this]{ return _currentProfile->nitinolCM(); },
[this](Int amount){ return _currentProfile->setNitinolCM(amount); });
drawMaterialRow("Quarkium", 4,
[this]{ return _currentProfile->quarkium(); },
[this](Int amount){ return _currentProfile->setQuarkium(amount); });
drawMaterialRow("Alterene", 5,
[this]{ return _currentProfile->alterene(); },
[this](Int amount){ return _currentProfile->setAlterene(amount); });
drawUnavailableMaterialRow("Cosmium", 6);
drawUnavailableMaterialRow("Purified quarkium", 7);
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableSetColumnIndex(1);
ImGui::Text("Quark data");
drawMaterialRow("Mixed composition", 1,
[this]{ return _currentProfile->mixedComposition(); },
[this](Int amount){ return _currentProfile->setMixedComposition(amount); });
drawMaterialRow("Void residue", 2,
[this]{ return _currentProfile->voidResidue(); },
[this](Int amount){ return _currentProfile->setVoidResidue(amount); });
drawMaterialRow("Muscular construction", 3,
[this]{ return _currentProfile->muscularConstruction(); },
[this](Int amount){ return _currentProfile->setMuscularConstruction(amount); });
drawMaterialRow("Mineral exoskeletology", 4,
[this]{ return _currentProfile->mineralExoskeletology(); },
[this](Int amount){ return _currentProfile->setMineralExoskeletology(amount); });
drawMaterialRow("Carbonized skin", 5,
[this]{ return _currentProfile->carbonisedSkin(); },
[this](Int amount){ return _currentProfile->setCarbonisedSkin(amount); });
drawUnavailableMaterialRow("Isolated void particle", 6);
drawUnavailableMaterialRow("Weaponised physiology", 7);
ImGui::EndTable();
}
}
template<typename Getter, typename Setter>
void SaveTool::drawMaterialRow(Containers::StringView name, Int tier, Getter getter, Setter setter) {
static_assert(std::is_same<decltype(getter()), Int>::value, "getter doesn't return an Int, and/or doesn't take zero arguments.");
static_assert(std::is_same<decltype(setter(0)), bool>::value, "setter doesn't return a bool, and/or doesn't take a single Int as an argument.");
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("T%i", tier);
ImGui::TableSetColumnIndex(1);
ImGui::TextUnformatted(name.data());
ImGui::TableSetColumnIndex(2);
if(getter() != -1) {
ImGui::Text("%i", getter());
if(_cheatMode) {
ImGui::TableSetColumnIndex(3);
ImGui::PushID(name.data());
static Int var = 0;
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_EDIT)) {
(var) = getter();
ImGui::OpenPopup("int_edit");
}
if(drawIntEditPopup(&(var), 9999)) {
if(!setter(var)) {
_queue.addToast(Toast::Type::Error, _currentProfile->lastError());
}
}
ImGui::PopID();
}
}
else {
ImGui::TextDisabled("Not found in the save file");
}
}
void SaveTool::drawUnavailableMaterialRow(Containers::StringView name, Int tier) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("T%i", tier);
ImGui::TableSetColumnIndex(1);
ImGui::TextUnformatted(name.data());
ImGui::TableSetColumnIndex(2);
ImGui::TextDisabled("Unavailable as of game version " SUPPORTED_GAME_VERSION);
}
void SaveTool::drawMassManager() {
if(!_massManager) {
return;
}
static int mass_to_delete = 0;
static ImGuiID mass_deletion_popup_ID = drawDeleteMassPopup(mass_to_delete);
if(ImGui::BeginTable("##HangarsTable", 4,
ImGuiTableFlags_BordersOuter|ImGuiTableFlags_RowBg|ImGuiTableFlags_ScrollY,
{0.0f, ImGui::GetContentRegionAvail().y * 0.45f}))
{
ImGui::TableSetupColumn("##Hangar", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("##MASSName", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##Active", ImGuiTableColumnFlags_WidthFixed);
2022-01-14 13:42:09 +01:00
ImGui::TableSetupColumn("##Buttons", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted("#");
ImGui::TableSetColumnIndex(1);
ImGui::TextUnformatted("Name");
for(int i = 0; i < 32; i++) {
ImGui::TableNextRow();
static int drag_drop_index = 0;
ImGui::TableSetColumnIndex(0);
ImGui::Selectable(Utility::formatString("{:.2d}", i + 1).c_str(),
false, ImGuiSelectableFlags_SpanAllColumns|ImGuiSelectableFlags_AllowItemOverlap);
if(_massManager->hangar(i).state() == Mass::State::Valid &&
ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
{
drag_drop_index = i;
ImGui::SetDragDropPayload("Mass", &drag_drop_index, sizeof(int));
ImGui::Text("%s - Hangar %.2d", _massManager->hangar(i).name().data(), i + 1);
ImGui::EndDragDropSource();
}
if((_unsafeMode || _gameState == GameState::NotRunning) && ImGui::BeginDragDropTarget()) {
if(const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("StagedMass")) {
if(payload->DataSize != sizeof(std::string)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error",
"payload->DataSize != sizeof(std::string) in SaveTool::drawMassManager()",
window());
exit(EXIT_FAILURE);
}
std::string file = *(static_cast<std::string*>(payload->Data));
if(!_massManager->importMass(file, i)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
}
}
else if((payload = ImGui::AcceptDragDropPayload("Mass"))) {
if(payload->DataSize != sizeof(int)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error",
"payload->DataSize != sizeof(int) in SaveTool::drawMassManager()",
window());
exit(EXIT_FAILURE);
}
int index = *(static_cast<int*>(payload->Data));
if(!_massManager->moveMass(index, i)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
}
}
ImGui::EndDragDropTarget();
}
ImGui::TableSetColumnIndex(1);
switch(_massManager->hangar(i).state()) {
case Mass::State::Empty:
ImGui::TextDisabled("<empty>");
break;
case Mass::State::Invalid:
ImGui::TextDisabled("<invalid>");
break;
case Mass::State::Valid:
ImGui::TextUnformatted(_massManager->hangar(i).name().data());
break;
}
if(i == _currentProfile->activeFrameSlot()) {
ImGui::TableSetColumnIndex(2);
ImGui::TextUnformatted(ICON_FA_CHECK);
drawTooltip("This is the currently active frame slot.");
}
if(_massManager->hangar(i).state() != Mass::State::Empty) {
ImGui::TableSetColumnIndex(3);
ImGui::PushID(i);
if(_massManager->hangar(i).state() == Mass::State::Valid) {
if(ImGui::SmallButton(ICON_FA_SEARCH)) {
_currentMass = &_massManager->hangar(i);
_uiState = UiState::MassViewer;
}
ImGui::SameLine(0.0f, 2.0f);
}
2022-01-14 13:42:09 +01:00
else{
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.0f);
ImGui::SmallButton(ICON_FA_SEARCH);
ImGui::PopStyleVar();
}
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_TRASH_ALT)) {
mass_to_delete = i;
ImGui::OpenPopup(mass_deletion_popup_ID);
}
ImGui::PopID();
}
}
ImGui::EndTable();
}
drawDeleteMassPopup(mass_to_delete);
static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup("");
static Containers::StringView staged_mass_to_delete;
if(ImGui::BeginTable("##StagingArea", 2,
ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuter|ImGuiTableFlags_RowBg))
{
ImGui::TableSetupColumn("##NameColumn", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##DeleteColumn", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted("Staging area");
ImGui::SameLine();
if(ImGui::SmallButton(ICON_FA_FOLDER_OPEN " Open staging folder")) {
openUri(Utility::Directory::toNativeSeparators(_stagingDir));
}
for(const auto& pair : _massManager->stagedMasses()) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
std::string staged_formatted = Utility::formatString("{} ({})", pair.second, pair.first);
ImGui::Selectable(staged_formatted.c_str());
if((ImGui::CalcTextSize(staged_formatted.c_str()).x + ImGui::GetStyle().FramePadding.x) > ImGui::GetContentRegionAvailWidth()) {
drawTooltip(staged_formatted.c_str());
}
if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) {
ImGui::SetDragDropPayload("StagedMass", &(pair.first), sizeof(std::string));
ImGui::Text("%s - Staged", pair.second.data());
ImGui::EndDragDropSource();
}
ImGui::TableSetColumnIndex(1);
ImGui::PushID(pair.first.data());
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
staged_mass_to_delete = pair.first;
ImGui::OpenPopup(staged_mass_deletion_popup_ID);
}
ImGui::PopID();
}
ImGui::EndTable();
}
if(ImGui::BeginDragDropTarget()) {
if(const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("Mass")) {
if(payload->DataSize != sizeof(int)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error",
"payload->DataSize != sizeof(int) in SaveTool::drawMassManager()",
window());
exit(EXIT_FAILURE);
}
int index = *(static_cast<int*>(payload->Data));
if(!_massManager->exportMass(index)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
}
}
ImGui::EndDragDropTarget();
}
drawDeleteStagedMassPopup(staged_mass_to_delete);
}
auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID {
if(!ImGui::BeginPopupModal("Confirmation##DeleteMassConfirmation", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{
return ImGui::GetID("Confirmation##DeleteMassConfirmation");
}
if(_massManager->hangar(mass_index).state() == Mass::State::Empty) {
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
return 0;
}
if(_gameState != GameState::NotRunning) {
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
return 0;
}
ImGui::PushTextWrapPos(windowSize().x() * 0.40f);
if(_massManager->hangar(mass_index).state() == Mass::State::Invalid) {
ImGui::Text("Are you sure you want to delete the invalid M.A.S.S. data in hangar %.2i ? This operation is irreversible.",
mass_index + 1);
}
else {
ImGui::Text("Are you sure you want to delete the M.A.S.S. named %s in hangar %.2i ? This operation is irreversible.",
_massManager->hangar(mass_index).name().data(), mass_index + 1);
}
ImGui::PopTextWrapPos();
if(ImGui::BeginTable("##DeleteMassLayout", 2)) {
ImGui::TableSetupColumn("##Dummy", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##YesNo", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_massManager->deleteMass(mass_index)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
}
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if(ImGui::Button("No", ImGui::GetItemRectSize())) {
ImGui::CloseCurrentPopup();
}
ImGui::EndTable();
}
ImGui::EndPopup();
return 0;
}
auto SaveTool::drawDeleteStagedMassPopup(Containers::StringView filename) -> ImGuiID {
if(!ImGui::BeginPopupModal("Confirmation##DeleteStagedMassConfirmation", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{
return ImGui::GetID("Confirmation##DeleteStagedMassConfirmation");
}
ImGui::PushTextWrapPos(windowSize().x() * 0.40f);
ImGui::Text("Are you sure you want to delete the staged M.A.S.S. named %s ? This operation is irreversible.",
_massManager->stagedMasses().at(filename).data());
ImGui::PopTextWrapPos();
if(ImGui::BeginTable("##DeleteStagedMassLayout", 2)) {
ImGui::TableSetupColumn("##Dummy", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##YesNo", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_massManager->deleteStagedMass(filename)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
}
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if(ImGui::Button("No", ImGui::GetItemRectSize())) {
ImGui::CloseCurrentPopup();
}
ImGui::EndTable();
}
ImGui::EndPopup();
return 0;
}