Application: improve weapon management UI.

This commit is contained in:
Guillaume Jacquemin 2024-12-08 20:35:54 +01:00
parent a3c2865e68
commit 08de4ef475
Signed by: williamjcm
SSH key fingerprint: SHA256:AYLOg+iTV0ElElnlu4vqM4edFazVdRiuQB0Y5LoKc4A
2 changed files with 36 additions and 142 deletions

View file

@ -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<GameObjects::Weapon> weapons_view,
bool& dirty, Containers::StringView payload_type,
Containers::StringView payload_tooltip);
void drawWeaponCategory(Containers::StringView name, GameObjects::Weapon::Type category,
Containers::ArrayView<GameObjects::Weapon> 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<std::size_t> _selectedArmourSlot{Containers::NullOpt};
Containers::StaticArray<38, std::int32_t> _selectedArmourDecals{ValueInit};

View file

@ -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<GameObjects::Weapon> 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;
@ -225,8 +140,8 @@ Application::drawWeapons() {
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<GameObjects::Weapon> 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();