diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index ed76717..00999c3 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -260,6 +260,12 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener Int _selectedWeaponPart{0}; Int _selectedWeaponDecal{0}; Int _selectedWeaponAccessory{0}; + bool _meleeDirty{false}; + bool _shieldsDirty{false}; + bool _bShootersDirty{false}; + bool _eShootersDirty{false}; + bool _bLaunchersDirty{false}; + bool _eLaunchersDirty{false}; bool _cheatMode{false}; }; diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index fccd93d..2b70a68 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -620,7 +620,14 @@ void SaveTool::drawWeapons() { return; } - if(!ImGui::BeginTable("##WeaponsList", 1, ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuter|ImGuiTableFlags_BordersInnerH, {ImGui::GetContentRegionAvailWidth() * 0.2f, 0.0f})) { + const Float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); + + ImGui::BeginGroup(); + + if(!ImGui::BeginTable("##WeaponsList", 1, + ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuter|ImGuiTableFlags_BordersInnerH, + {ImGui::GetContentRegionAvailWidth() * 0.2f, -footer_height_to_reserve})) + { return; } @@ -628,7 +635,7 @@ void SaveTool::drawWeapons() { int id = 0; -#define weapcat(header, array, payload_type, payload_tooltip) \ +#define weapcat(header, array, dirty, payload_type, payload_tooltip) \ ImGui::TableNextRow(ImGuiTableRowFlags_Headers); \ ImGui::TableNextColumn(); \ ImGui::TextUnformatted(header); \ @@ -659,6 +666,7 @@ void SaveTool::drawWeapons() { } \ \ std::swap(_currentMass->array()[index], _currentMass->array()[i]); \ + (dirty) = true; \ } \ \ ImGui::EndDragDropTarget(); \ @@ -672,17 +680,85 @@ void SaveTool::drawWeapons() { } \ } - weapcat("Melee weapons", meleeWeapons, "MeleeWeapon", "Melee weapon") - weapcat("Shield", shields, "Shield", "Shield") - weapcat("Bullet shooters", bulletShooters, "BShooter", "Bullet shooter") - weapcat("Energy shooters", energyShooters, "EShooter", "Energy shooter") - weapcat("Bullet launchers", bulletLaunchers, "BLauncher", "Bullet launcher") - weapcat("Energy launchers", energyLaunchers, "ELauncher", "Energy launcher") + weapcat("Melee weapons", meleeWeapons, _meleeDirty, "MeleeWeapon", "Melee weapon") + weapcat("Shield", shields, _shieldsDirty, "Shield", "Shield") + weapcat("Bullet shooters", bulletShooters, _bShootersDirty, "BShooter", "Bullet shooter") + weapcat("Energy shooters", energyShooters, _eShootersDirty, "EShooter", "Energy shooter") + weapcat("Bullet launchers", bulletLaunchers, _bLaunchersDirty, "BLauncher", "Bullet launcher") + weapcat("Energy launchers", energyLaunchers, _eLaunchersDirty, "ELauncher", "Energy launcher") #undef weapcat ImGui::EndTable(); + bool dirty = _meleeDirty || _shieldsDirty || _bShootersDirty || _eShootersDirty || _bLaunchersDirty || _eLaunchersDirty; + + if(!dirty) { + ImGui::BeginDisabled(); + } + + if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { + if(_meleeDirty) { + _currentMass->writeMeleeWeapons(); + _meleeDirty = false; + } + if(_shieldsDirty) { + _currentMass->writeShields(); + _shieldsDirty = false; + } + if(_bShootersDirty) { + _currentMass->writeBulletShooters(); + _bShootersDirty = false; + } + if(_eShootersDirty) { + _currentMass->writeEnergyShooters(); + _eShootersDirty = false; + } + if(_bLaunchersDirty) { + _currentMass->writeBulletLaunchers(); + _bLaunchersDirty = false; + } + if(_eLaunchersDirty) { + _currentMass->writeEnergyLaunchers(); + _eLaunchersDirty = false; + } + } + + ImGui::SameLine(); + + if(ImGui::Button(ICON_FA_UNDO_ALT " Reset")) { + if(_meleeDirty) { + _currentMass->getMeleeWeapons(); + _meleeDirty = false; + } + if(_shieldsDirty) { + _currentMass->getShields(); + _shieldsDirty = false; + } + if(_bShootersDirty) { + _currentMass->getBulletShooters(); + _bShootersDirty = false; + } + if(_eShootersDirty) { + _currentMass->getEnergyShooters(); + _eShootersDirty = false; + } + if(_bLaunchersDirty) { + _currentMass->getBulletLaunchers(); + _bLaunchersDirty = false; + } + if(_eLaunchersDirty) { + _currentMass->getEnergyLaunchers(); + _eLaunchersDirty = false; + } + } + + if(!dirty) { + ImGui::EndDisabled(); + } + + ImGui::EndGroup(); + ImGui::SameLine(); if(!current_weapon) { @@ -692,7 +768,6 @@ void SaveTool::drawWeapons() { ImGui::BeginGroup(); - const Float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); if(!ImGui::BeginChild("##WeaponChild", {0.0f, -footer_height_to_reserve})) { ImGui::EndChild(); return;