From 1621a4dbd5b01e1aaefb8ce0a7fc3634d686c0bf Mon Sep 17 00:00:00 2001 From: William JCM Date: Fri, 14 Jan 2022 13:22:51 +0100 Subject: [PATCH] SaveTool: move M.A.S.S. viewer state tracking. That way, it's easier to reset. Some states, such as the current tab or which headers are open/collapsed, are internal to ImGui, though, so I can't do much there. Well, I could use the internal ImGui API, but, it's still a pain in the ass. --- src/SaveTool/SaveTool.h | 9 +++ src/SaveTool/SaveTool_MassViewer.cpp | 90 +++++++++++++--------------- 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index d390be1..7338049 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -248,5 +248,14 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener std::string _releaseLink; std::string _downloadLink; + bool _jointsDirty{false}; + bool _stylesDirty{false}; + bool _eyeFlareDirty{false}; + Containers::StaticArray<38, Int> _selectedArmourDecals{ValueInit}; + Containers::StaticArray<38, Int> _selectedArmourAccessories{ValueInit}; + Int _selectedWeaponPart{0}; + Int _selectedWeaponDecal{0}; + Int _selectedWeaponAccessory{0}; + bool _cheatMode{false}; }; diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index 8b639ea..fccd93d 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -74,6 +74,9 @@ void SaveTool::drawMassViewer() { if(ImGui::SmallButton(ICON_FA_SYNC_ALT " Refresh")) { _currentMass->refreshValues(); _currentMass->setDirty(false); + _jointsDirty = false; + _stylesDirty = false; + _eyeFlareDirty = false; } } @@ -82,7 +85,15 @@ void SaveTool::drawMassViewer() { current_weapon = nullptr; _currentMass = nullptr; _uiState = UiState::MainManager; - } + _jointsDirty = false; + _stylesDirty = false; + _eyeFlareDirty = false; + _selectedArmourDecals = Containers::StaticArray<38, Int>{ValueInit}; + _selectedArmourAccessories = Containers::StaticArray<38, Int>{ValueInit}; + _selectedWeaponPart = 0; + _selectedWeaponDecal = 0; + _selectedWeaponAccessory = 0; + }; ImGui::EndTable(); } @@ -201,8 +212,6 @@ void SaveTool::drawJointSliders() { return; } - static bool joints_dirty = false; - ImGui::TextWrapped("In-game values are multiplied by 100.\nFor example, 0.500 here is equal to 50 in-game."); if(ImGui::BeginTable("##JointSliderTable", 2, ImGuiTableFlags_Borders)) { @@ -216,7 +225,7 @@ void SaveTool::drawJointSliders() { ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##NeckSlider", &_currentMass->jointSliders().neck, 0.0f, 1.0f)) { - joints_dirty = true; + _jointsDirty = true; } ImGui::TableNextRow(); @@ -226,7 +235,7 @@ void SaveTool::drawJointSliders() { ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##BodySlider", &_currentMass->jointSliders().body, 0.0f, 1.0f)) { - joints_dirty = true; + _jointsDirty = true; } ImGui::TableNextRow(); @@ -236,7 +245,7 @@ void SaveTool::drawJointSliders() { ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##ShouldersSlider", &_currentMass->jointSliders().shoulders, 0.0f, 1.0f)) { - joints_dirty = true; + _jointsDirty = true; } ImGui::TableNextRow(); @@ -246,7 +255,7 @@ void SaveTool::drawJointSliders() { ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##HipsSlider", &_currentMass->jointSliders().hips, 0.0f, 1.0f)) { - joints_dirty = true; + _jointsDirty = true; } ImGui::TableNextRow(); @@ -262,12 +271,12 @@ void SaveTool::drawJointSliders() { ImGui::TableNextColumn(); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##UpperArmsSlider", &_currentMass->jointSliders().upperArms, 0.0f, 1.0f, "Upper: %.3f")) { - joints_dirty = true; + _jointsDirty = true; } ImGui::TableNextColumn(); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##LowerArmsSlider", &_currentMass->jointSliders().lowerArms, 0.0f, 1.0f, "Lower: %.3f")) { - joints_dirty = true; + _jointsDirty = true; } ImGui::EndTable(); @@ -287,12 +296,12 @@ void SaveTool::drawJointSliders() { ImGui::TableNextColumn(); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##UpperLegsSlider", &_currentMass->jointSliders().upperLegs, 0.0f, 1.0f, "Upper: %.3f")) { - joints_dirty = true; + _jointsDirty = true; } ImGui::TableNextColumn(); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##LowerLegsSlider", &_currentMass->jointSliders().lowerLegs, 0.0f, 1.0f, "Lower: %.3f")) { - joints_dirty = true; + _jointsDirty = true; } ImGui::EndTable(); @@ -302,7 +311,7 @@ void SaveTool::drawJointSliders() { ImGui::EndTable(); } - if(!joints_dirty) { + if(!_jointsDirty) { ImGui::BeginDisabled(); ImGui::Button(ICON_FA_SAVE " Save"); ImGui::SameLine(); @@ -314,12 +323,12 @@ void SaveTool::drawJointSliders() { if(!_currentMass->writeJointSliders()) { _queue.addToast(Toast::Type::Error, "Error: " + Mass::lastError()); } - joints_dirty = false; + _jointsDirty = false; } ImGui::SameLine(); if(ImGui::Button(ICON_FA_UNDO " Reset")) { _currentMass->getJointSliders(); - joints_dirty = false; + _jointsDirty = false; } } } @@ -329,8 +338,6 @@ void SaveTool::drawFrameStyles() { return; } - static bool styles_dirty = false; - for(Int i = 0; i < 4; i++) { ImGui::AlignTextToFramePadding(); ImGui::Text("Slot %d:", i + 1); @@ -343,7 +350,7 @@ void SaveTool::drawFrameStyles() { for(const auto& style : style_names) { if(ImGui::Selectable(getStyleName(style.first, _currentMass->frameCustomStyles()), _currentMass->frameStyles()[i] == style.first)) { _currentMass->frameStyles()[i] = style.first; - styles_dirty = true; + _stylesDirty = true; } } @@ -353,7 +360,7 @@ void SaveTool::drawFrameStyles() { ImGui::PopID(); } - if(!styles_dirty) { + if(!_stylesDirty) { ImGui::BeginDisabled(); ImGui::Button(ICON_FA_SAVE " Save"); ImGui::SameLine(); @@ -365,12 +372,12 @@ void SaveTool::drawFrameStyles() { if(!_currentMass->writeFrameStyles()) { _queue.addToast(Toast::Type::Error, "Error: " + Mass::lastError()); } - styles_dirty = false; + _stylesDirty = false; } ImGui::SameLine(); if(ImGui::Button(ICON_FA_UNDO " Reset")) { _currentMass->getFrameStyles(); - styles_dirty = false; + _stylesDirty = false; } } } @@ -380,13 +387,11 @@ void SaveTool::drawEyeColourPicker() { return; } - static bool eye_flare_dirty = false; - if(ImGui::ColorPicker3("##EyeFlarePicker", &_currentMass->eyeFlareColour().x())) { - eye_flare_dirty = true; + _eyeFlareDirty = true; } - if(!eye_flare_dirty) { + if(!_eyeFlareDirty) { ImGui::BeginDisabled(); ImGui::Button(ICON_FA_SAVE " Save"); ImGui::SameLine(); @@ -398,12 +403,12 @@ void SaveTool::drawEyeColourPicker() { if(!_currentMass->writeEyeFlareColour()) { _queue.addToast(Toast::Type::Error, "Error writing the eye flare colour."); } - eye_flare_dirty = false; + _eyeFlareDirty = false; } ImGui::SameLine(); if(ImGui::Button(ICON_FA_UNDO " Reset")) { _currentMass->getEyeFlareColour(); - eye_flare_dirty = false; + _eyeFlareDirty = false; } } } @@ -454,9 +459,6 @@ void SaveTool::drawArmour() { return; } - static Containers::StaticArray<38, Int> selected_decals{ValueInit}; - static Containers::StaticArray<38, Int> selected_accessories{ValueInit}; - for(UnsignedInt i = 0; i < _currentMass->armourParts().size(); i++) { ImGui::PushID(i); @@ -543,10 +545,10 @@ void SaveTool::drawArmour() { ImGui::TextUnformatted("Showing/editing decal"); for(UnsignedLong j = 0; j < part.demoDecals; j++) { ImGui::SameLine(); - ImGui::RadioButton(std::to_string(j + 1).c_str(), &selected_decals[i], j); + ImGui::RadioButton(std::to_string(j + 1).c_str(), &_selectedArmourDecals[i], j); } - drawDecalEditor(part.decals[selected_decals[i]]); + drawDecalEditor(part.decals[_selectedArmourDecals[i]]); ImGui::PopID(); @@ -559,10 +561,10 @@ void SaveTool::drawArmour() { ImGui::TextUnformatted("Showing/editing accessory"); for(UnsignedInt j = 0; j < part.accessories.size(); j++) { ImGui::SameLine(); - ImGui::RadioButton(std::string{char(65 + j)}.c_str(), &selected_accessories[i], j); + ImGui::RadioButton(std::string{char(65 + j)}.c_str(), &_selectedArmourAccessories[i], j); } - drawAccessoryEditor(part.accessories[selected_accessories[i]], _currentMass->armourCustomStyles()); + drawAccessoryEditor(part.accessories[_selectedArmourAccessories[i]], _currentMass->armourCustomStyles()); ImGui::PopID(); } @@ -872,19 +874,17 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::Separator(); if(ImGui::CollapsingHeader("Weapon parts")) { - static Int selected_part = 0; - ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("Viewing/editing part:"); for(Int i = 0; UnsignedLong(i) < weapon.parts.size(); i++) { - if(UnsignedLong(selected_part) >= weapon.parts.size()) { - selected_part = 0; + if(UnsignedLong(_selectedWeaponPart) >= weapon.parts.size()) { + _selectedWeaponPart = 0; } ImGui::SameLine(); - ImGui::RadioButton(std::to_string(i + 1).c_str(), &selected_part, i); + ImGui::RadioButton(std::to_string(i + 1).c_str(), &_selectedWeaponPart, i); } - auto& part = weapon.parts[selected_part]; + auto& part = weapon.parts[_selectedWeaponPart]; ImGui::Text("ID: %i", part.id); @@ -917,16 +917,14 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::PushID("Decal"); - static Int selected_decal = 0; - ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("Showing/editing decal"); for(UnsignedLong i = 0; i < part.demoDecals; i++) { ImGui::SameLine(); - ImGui::RadioButton(std::to_string(i + 1).c_str(), &selected_decal, i); + ImGui::RadioButton(std::to_string(i + 1).c_str(), &_selectedWeaponDecal, i); } - drawDecalEditor(part.decals[selected_decal]); + drawDecalEditor(part.decals[_selectedWeaponDecal]); ImGui::PopID(); @@ -935,16 +933,14 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::PushID("Accessory"); - static Int selected_accessory = 0; - ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("Showing/editing accessory"); for(UnsignedLong i = 0; i < part.accessories.size(); i++) { ImGui::SameLine(); - ImGui::RadioButton(std::string{char(65 + i)}.c_str(), &selected_accessory, i); + ImGui::RadioButton(std::string{char(65 + i)}.c_str(), &_selectedWeaponAccessory, i); } - drawAccessoryEditor(part.accessories[selected_accessory], weapon.customStyles); + drawAccessoryEditor(part.accessories[_selectedWeaponAccessory], weapon.customStyles); ImGui::PopID(); }