From 08de4ef4752713a1f4d9ed8d0a34d1f2a17f3b7f Mon Sep 17 00:00:00 2001 From: Guillaume Jacquemin Date: Sun, 8 Dec 2024 20:35:54 +0100 Subject: [PATCH] Application: improve weapon management UI. --- src/Application/Application.h | 12 +- .../Application_MassViewer_Weapons.cpp | 166 ++++-------------- 2 files changed, 36 insertions(+), 142 deletions(-) diff --git a/src/Application/Application.h b/src/Application/Application.h index 1a18a16..ba7c9e4 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -140,9 +140,9 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe void drawBLAttachment(); void drawCustomArmourStyles(); void drawWeapons(); - void drawWeaponCategory(Containers::StringView name, Containers::ArrayView weapons_view, - bool& dirty, Containers::StringView payload_type, - Containers::StringView payload_tooltip); + void drawWeaponCategory(Containers::StringView name, GameObjects::Weapon::Type category, + Containers::ArrayView weapons_view, + Containers::StringView payload_type, Containers::StringView payload_tooltip); void drawWeaponEditor(GameObjects::Weapon& weapon); void drawGlobalStyles(); void drawTuning(); @@ -280,12 +280,6 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe bool _jointsDirty = false; bool _stylesDirty = false; bool _eyeFlareDirty = false; - bool _meleeDirty = false; - bool _shieldsDirty = false; - bool _bShootersDirty = false; - bool _eShootersDirty = false; - bool _bLaunchersDirty = false; - bool _eLaunchersDirty = false; Containers::Optional _selectedArmourSlot{Containers::NullOpt}; Containers::StaticArray<38, std::int32_t> _selectedArmourDecals{ValueInit}; diff --git a/src/Application/Application_MassViewer_Weapons.cpp b/src/Application/Application_MassViewer_Weapons.cpp index b75114f..dea84ee 100644 --- a/src/Application/Application_MassViewer_Weapons.cpp +++ b/src/Application/Application_MassViewer_Weapons.cpp @@ -22,6 +22,7 @@ #include "../GameData/WeaponParts.h" #include "Application.h" +#include "../Configuration/Configuration.h" namespace mbst { @@ -32,13 +33,11 @@ Application::drawWeapons() { return; } - const float footer_height_to_reserve = ImGui::GetFrameHeightWithSpacing(); - ImGui::BeginGroup(); if(!ImGui::BeginTable("##WeaponsList", 1, ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuter|ImGuiTableFlags_BordersInnerH, - {ImGui::GetContentRegionAvail().x * 0.2f, -footer_height_to_reserve})) + {ImGui::GetContentRegionAvail().x * 0.2f, 0.0f})) { ImGui::EndGroup(); return; @@ -46,118 +45,20 @@ Application::drawWeapons() { ImGui::TableSetupColumn("Weapon"); - drawWeaponCategory("Melee weapons", _currentMass->meleeWeapons(), _meleeDirty, "MeleeWeapon", "Melee weapon"); - drawWeaponCategory("Shield", _currentMass->shields(), _shieldsDirty, "Shield", "Shield"); - drawWeaponCategory("Bullet shooters", _currentMass->bulletShooters(), _bShootersDirty, "BShooter", "Bullet shooter"); - drawWeaponCategory("Energy shooters", _currentMass->energyShooters(), _eShootersDirty, "EShooter", "Energy shooter"); - drawWeaponCategory("Bullet launchers", _currentMass->bulletLaunchers(), _bLaunchersDirty, "BLauncher", "Bullet launcher"); - drawWeaponCategory("Energy launchers", _currentMass->energyLaunchers(), _eLaunchersDirty, "ELauncher", "Energy launcher"); + drawWeaponCategory("Melee weapons", GameObjects::Weapon::Type::Melee, _currentMass->meleeWeapons(), "MeleeWeapon", + "Melee weapon"); + drawWeaponCategory("Shield", GameObjects::Weapon::Type::Shield, _currentMass->shields(), "Shield", "Shield"); + drawWeaponCategory("Bullet shooters", GameObjects::Weapon::Type::BulletShooter, _currentMass->bulletShooters(), + "BShooter", "Bullet shooter"); + drawWeaponCategory("Energy shooters", GameObjects::Weapon::Type::EnergyShooter, _currentMass->energyShooters(), + "EShooter", "Energy shooter"); + drawWeaponCategory("Bullet launchers", GameObjects::Weapon::Type::BulletLauncher, _currentMass->bulletLaunchers(), + "BLauncher", "Bullet launcher"); + drawWeaponCategory("Energy launchers", GameObjects::Weapon::Type::EnergyLauncher, _currentMass->energyLaunchers(), + "ELauncher", "Energy launcher"); ImGui::EndTable(); - bool dirty = _meleeDirty || _shieldsDirty || _bShootersDirty || _eShootersDirty || _bLaunchersDirty || _eLaunchersDirty; - - ImGui::BeginDisabled(!dirty); - - if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save order"); })) { - if(_meleeDirty) { - _modifiedBySaveTool = true; - if(!_currentMass->writeMeleeWeapons()) { - _modifiedBySaveTool = false; - _queue.addToast(Toast::Type::Error, _currentMass->lastError()); - } - else { - _meleeDirty = false; - } - } - - if(_shieldsDirty) { - _modifiedBySaveTool = true; - if(!_currentMass->writeShields()) { - _modifiedBySaveTool = false; - _queue.addToast(Toast::Type::Error, _currentMass->lastError()); - } - else { - _shieldsDirty = false; - } - } - - if(_bShootersDirty) { - _modifiedBySaveTool = true; - if(!_currentMass->writeBulletShooters()) { - _modifiedBySaveTool = false; - _queue.addToast(Toast::Type::Error, _currentMass->lastError()); - } - else { - _bShootersDirty = false; - } - } - - if(_eShootersDirty) { - _modifiedBySaveTool = true; - if(_currentMass->writeEnergyShooters()) { - _modifiedBySaveTool = false; - _queue.addToast(Toast::Type::Error, _currentMass->lastError()); - } - else { - _eShootersDirty = false; - } - } - - if(_bLaunchersDirty) { - _modifiedBySaveTool = true; - if(_currentMass->writeBulletLaunchers()) { - _modifiedBySaveTool = false; - _queue.addToast(Toast::Type::Error, _currentMass->lastError()); - } - else { - _bLaunchersDirty = false; - } - } - - if(_eLaunchersDirty) { - _modifiedBySaveTool = true; - if(_currentMass->writeEnergyLaunchers()) { - _modifiedBySaveTool = false; - _queue.addToast(Toast::Type::Error, _currentMass->lastError()); - } - else { - _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; - } - } - - ImGui::EndDisabled(); - ImGui::EndGroup(); ImGui::SameLine(); @@ -169,7 +70,7 @@ Application::drawWeapons() { ImGui::BeginGroup(); - if(!ImGui::BeginChild("##WeaponChild", {0.0f, -footer_height_to_reserve})) { + if(!ImGui::BeginChild("##WeaponChild")) { ImGui::EndChild(); return; } @@ -178,9 +79,23 @@ Application::drawWeapons() { ImGui::EndChild(); - if(drawUnsafeWidget([](){ return ImGui::Button(ICON_FA_SAVE " Save changes to weapon category"); })) { + ImGui::EndGroup(); +} + +void +Application::drawWeaponCategory(Containers::StringView name, GameObjects::Weapon::Type category, + Containers::ArrayView weapons_view, + Containers::StringView payload_type, Containers::StringView payload_tooltip) +{ + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(name.cbegin(), name.cend()); + + ImGui::PushID(payload_type.data()); + + if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_SAVE " Save")) { _modifiedBySaveTool = true; - switch(_currentWeapon->type) { + switch(category) { case GameObjects::Weapon::Type::Melee: if(!_currentMass->writeMeleeWeapons()) { _modifiedBySaveTool = false; @@ -219,14 +134,14 @@ Application::drawWeapons() { break; default: _modifiedBySaveTool = false; - _queue.addToast(Toast::Type::Error, "Unknown weapon type"); + _queue.addToast(Toast::Type::Error, "Unknown weapon type"); } } ImGui::SameLine(); - if(ImGui::Button(ICON_FA_UNDO_ALT " Reset weapon category")) { - switch(_currentWeapon->type) { + if(ImGui::SmallButton(ICON_FA_UNDO_ALT " Reset")) { + switch(category) { case GameObjects::Weapon::Type::Melee: _currentMass->getMeleeWeapons(); break; @@ -250,20 +165,6 @@ Application::drawWeapons() { } } - ImGui::EndGroup(); -} - -void -Application::drawWeaponCategory(Containers::StringView name, Containers::ArrayView weapons_view, - bool& dirty, Containers::StringView payload_type, - Containers::StringView payload_tooltip) -{ - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - ImGui::TableNextColumn(); - ImGui::TextUnformatted(name.cbegin(), name.cend()); - - ImGui::PushID(payload_type.data()); - for(std::uint32_t i = 0; i < weapons_view.size(); i++) { auto& weapon = weapons_view[i]; @@ -302,7 +203,6 @@ Application::drawWeaponCategory(Containers::StringView name, Containers::ArrayVi else { weapons_view[i] = weapons_view[index]; } - dirty = true; } ImGui::EndDragDropTarget();