From 82170b30782b0ee996eeea2d568b4c662ac9d0fd Mon Sep 17 00:00:00 2001 From: William JCM Date: Thu, 17 Feb 2022 20:22:33 +0100 Subject: [PATCH] Mass,SaveTool: optimise the effect colour mode. --- src/CMakeLists.txt | 1 + src/Maps/EffectColourModes.hpp | 20 ++++++++++++++++++++ src/Mass/Mass.cpp | 17 +++++++++++++++-- src/Mass/Weapon.h | 7 ++++++- src/SaveTool/SaveTool_MassViewer.cpp | 10 +++++----- 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/Maps/EffectColourModes.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0afc71d..afc8ac7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,6 +138,7 @@ add_executable(MassBuilderSaveTool WIN32 Maps/ArmourSets.h Maps/ArmourSlots.hpp Maps/DamageTypes.hpp + Maps/EffectColourModes.hpp Maps/LastMissionId.h Maps/StoryProgress.h Maps/StyleNames.h diff --git a/src/Maps/EffectColourModes.hpp b/src/Maps/EffectColourModes.hpp new file mode 100644 index 0000000..7df0077 --- /dev/null +++ b/src/Maps/EffectColourModes.hpp @@ -0,0 +1,20 @@ +// 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 . + +#ifdef c +c(Default, "enuWeaponEffectColorMode::NewEnumerator0") +c(Custom, "enuWeaponEffectColorMode::NewEnumerator1") +#endif diff --git a/src/Mass/Mass.cpp b/src/Mass/Mass.cpp index 3cc7bd4..84b6b45 100644 --- a/src/Mass/Mass.cpp +++ b/src/Mass/Mass.cpp @@ -1145,7 +1145,14 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we Utility::Warning{} << "Invalid damage type enum value in getWeaponType()."; } weapon.dualWield = weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value; - weapon.effectColourMode = weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue; + auto& effect_colour_mode = weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue; + #define c(enumerator, strenum) if(effect_colour_mode == (strenum)) { weapon.effectColourMode = EffectColourMode::enumerator; } else + #include "../Maps/EffectColourModes.hpp" + #undef c + { + _state = State::Invalid; + Utility::Warning{} << "Invalid effect colour mode in getWeaponType()."; + } auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"); weapon.effectColour = Color4{effect_colour->r, effect_colour->g, effect_colour->b, effect_colour->a}; } @@ -1239,7 +1246,13 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView Utility::Warning{} << "Invalid damage type enum value in writeWeaponType()."; } weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value = weapon.dualWield; - weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = weapon.effectColourMode; + switch(weapon.effectColourMode) { + #define c(enumerator, enumstr) case EffectColourMode::enumerator: \ + weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = enumstr; \ + break; + #include "../Maps/EffectColourModes.hpp" + #undef c + } auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"); effect_colour->r = weapon.effectColour.r(); effect_colour->g = weapon.effectColour.g(); diff --git a/src/Mass/Weapon.h b/src/Mass/Weapon.h index a2c4b00..660de20 100644 --- a/src/Mass/Weapon.h +++ b/src/Mass/Weapon.h @@ -48,6 +48,11 @@ enum class DamageType { Shock = 4, }; +enum class EffectColourMode { + Default = 0, + Custom = 1, +}; + struct Weapon { Weapon() = default; @@ -64,6 +69,6 @@ struct Weapon { bool attached = false; DamageType damageType = DamageType::Physical; bool dualWield = false; - std::string effectColourMode; + EffectColourMode effectColourMode = EffectColourMode::Default; Color4 effectColour{0.0f}; }; diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index a73a866..7dba4e1 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -947,15 +947,15 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { if(weapon.type == WeaponType::Melee) { ImGui::Checkbox("##DualWield", &weapon.dualWield); - if(ImGui::RadioButton("Default##Default", weapon.effectColourMode == "enuWeaponEffectColorMode::NewEnumerator0")) { - weapon.effectColourMode = "enuWeaponEffectColorMode::NewEnumerator0"; + if(ImGui::RadioButton("Default##Default", weapon.effectColourMode == EffectColourMode::Default)) { + weapon.effectColourMode = EffectColourMode::Default; } ImGui::SameLine(); - if(ImGui::RadioButton("Custom##Custom", weapon.effectColourMode == "enuWeaponEffectColorMode::NewEnumerator1")) { - weapon.effectColourMode = "enuWeaponEffectColorMode::NewEnumerator1"; + if(ImGui::RadioButton("Custom##Custom", weapon.effectColourMode == EffectColourMode::Custom)) { + weapon.effectColourMode = EffectColourMode::Custom; } - bool custom_effect = (weapon.effectColourMode == "enuWeaponEffectColorMode::NewEnumerator1"); + bool custom_effect = (weapon.effectColourMode == EffectColourMode::Custom); if(!custom_effect) { ImGui::BeginDisabled(); }