From f47f148a441656342a4c6694171a46f855de921b Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Tue, 12 Dec 2023 01:56:27 +0100 Subject: [PATCH] Tuneup: fixed known bugs of new UI overrides. codechanges: * GUI_TopMenubar.h: new function `DrawTuningForceRemoveControls()` - helper for both props and flexbodies. * GUI_TopMenubar.cpp - use `DrawTuningForceRemoveControls()` for both props and flexbodies. * ActorSpawner.cpp - renamed func. * TuneupFileFormat.h - nicer doxy groups, renamed `isFooRemoved()` to `isFooAnyhowRemoved()` because it now looks at both 'unwanted_' and 'force_removed' * TuneupFileFormat.cpp - isFooAnyhowRemoved()` funcs updated to look at both 'unwanted_' and 'force_removed' --- source/main/gui/panels/GUI_TopMenubar.cpp | 105 ++++++++++-------- source/main/gui/panels/GUI_TopMenubar.h | 1 + source/main/physics/ActorSpawner.cpp | 4 +- .../tuneup_fileformat/TuneupFileFormat.cpp | 8 +- .../tuneup_fileformat/TuneupFileFormat.h | 24 ++-- 5 files changed, 82 insertions(+), 60 deletions(-) diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index ce07cb284c..1c57b7edb3 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -1659,17 +1659,15 @@ void TopMenubar::Draw(float dt) this->DrawTuningBoxedSubjectIdInline(p.pp_id); - // Draw the checkbox for removing/remounting. - bool propEnabled = !tuneup_entry->tuneup_def->isPropUnwanted(p.pp_id) && !tuneup_entry->tuneup_def->isPropForceRemoved(p.pp_id); - if (ImGui::Checkbox(p.pp_media[0].c_str(), &propEnabled)) - { - ModifyProjectRequest* req = new ModifyProjectRequest(); - req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCEREMOVE_PROP_SET; - req->mpr_subject_id = p.pp_id; - req->mpr_target_actor = tuning_actor; - App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req)); - } + this->DrawTuningForceRemoveControls( + p.pp_id, + p.pp_media[0], + tuneup_entry->tuneup_def->isPropUnwanted(p.pp_id), + tuneup_entry->tuneup_def->isPropForceRemoved(p.pp_id), + ModifyProjectRequestType::TUNEUP_FORCEREMOVE_PROP_SET, + ModifyProjectRequestType::TUNEUP_FORCEREMOVE_PROP_RESET); + // Draw special prop tooltip if (p.pp_beacon_type == 'L' || p.pp_beacon_type == 'R' || p.pp_beacon_type == 'w') { ImGui::SameLine(); @@ -1719,42 +1717,13 @@ void TopMenubar::Draw(float dt) this->DrawTuningBoxedSubjectIdInline(flexbody->getID()); - // Draw the checkbox for force-removing. - bool flexbodyEnabled = !tuneup_entry->tuneup_def->isFlexbodyUnwanted(flexbody->getID()) && !tuneup_entry->tuneup_def->isFlexbodyForceRemoved(flexbody->getID()); - if (tuneup_entry->tuneup_def->isFlexbodyForceRemoved(flexbody->getID())) - { - ImGui::PushStyleColor(ImGuiCol_Border, ORANGE_TEXT); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f); - } - bool chkPressed = ImGui::Checkbox(flexbody->getOrigMeshName().c_str(), &flexbodyEnabled); - bool resetPressed = false; - if (tuneup_entry->tuneup_def->isFlexbodyForceRemoved(flexbody->getID())) - { - ImGui::SameLine(); - ImGui::PushStyleColor(ImGuiCol_Text, GRAY_HINT_TEXT); - resetPressed = ImGui::SmallButton(_LC("Tuning", "Reset")); - ImGui::PopStyleColor(); //ImGuiCol_Text, GRAY_HINT_TEXT - ImGui::PopStyleVar(); //ImGuiStyleVar_FrameBorderSize, 1.f - ImGui::PopStyleColor(); //ImGuiCol_Border, ORANGE_TEXT - } - - // perform project modification if needed - if (chkPressed && !flexbodyEnabled) - { - ModifyProjectRequest* req = new ModifyProjectRequest(); - req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCEREMOVE_FLEXBODY_SET; - req->mpr_subject_id = flexbody->getID(); - req->mpr_target_actor = tuning_actor; - App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req)); - } - else if ((chkPressed && flexbodyEnabled) || resetPressed) - { - ModifyProjectRequest* req = new ModifyProjectRequest(); - req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCEREMOVE_FLEXBODY_RESET; - req->mpr_subject_id = flexbody->getID(); - req->mpr_target_actor = tuning_actor; - App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req)); - } + this->DrawTuningForceRemoveControls( + flexbody->getID(), + flexbody->getOrigMeshName(), + tuneup_entry->tuneup_def->isFlexbodyUnwanted(flexbody->getID()), + tuneup_entry->tuneup_def->isFlexbodyForceRemoved(flexbody->getID()), + ModifyProjectRequestType::TUNEUP_FORCEREMOVE_FLEXBODY_SET, + ModifyProjectRequestType::TUNEUP_FORCEREMOVE_FLEXBODY_RESET); this->DrawTuningProtectedChkRightAligned( flexbody->getID(), @@ -2367,3 +2336,47 @@ void TopMenubar::DrawTuningBoxedSubjectIdInline(int subject_id) ImGui::SameLine(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetStyle().FramePadding.x); } + +void TopMenubar::DrawTuningForceRemoveControls(const int subject_id, const std::string& name, const bool is_unwanted, const bool is_force_removed, ModifyProjectRequestType request_type_set, ModifyProjectRequestType request_type_reset) +{ + // Common for props and flexbodies: draws the force-remove checkbox and the reset button + // ------------------------------------------------------------------------------------ + + // Draw the checkbox for force-removing. + bool isEnabled = !is_unwanted && !is_force_removed; + if (is_force_removed) + { + ImGui::PushStyleColor(ImGuiCol_Border, ORANGE_TEXT); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f); + } + bool chkPressed = ImGui::Checkbox(name.c_str(), &isEnabled); + bool resetPressed = false; + if (is_force_removed) + { + ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_Text, GRAY_HINT_TEXT); + resetPressed = ImGui::SmallButton(_LC("Tuning", "Reset")); + ImGui::PopStyleColor(); //ImGuiCol_Text, GRAY_HINT_TEXT + ImGui::PopStyleVar(); //ImGuiStyleVar_FrameBorderSize, 1.f + ImGui::PopStyleColor(); //ImGuiCol_Border, ORANGE_TEXT + } + + // perform project modification if needed + if (chkPressed && !isEnabled) + { + ModifyProjectRequest* req = new ModifyProjectRequest(); + req->mpr_type = request_type_set; + req->mpr_subject_id = subject_id; + req->mpr_target_actor = tuning_actor; + App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req)); + } + else if ((chkPressed && isEnabled) || resetPressed) + { + ModifyProjectRequest* req = new ModifyProjectRequest(); + req->mpr_type = request_type_reset; + req->mpr_subject_id = subject_id; + req->mpr_target_actor = tuning_actor; + App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req)); + } + +} diff --git a/source/main/gui/panels/GUI_TopMenubar.h b/source/main/gui/panels/GUI_TopMenubar.h index 063ad1f847..d998c03996 100644 --- a/source/main/gui/panels/GUI_TopMenubar.h +++ b/source/main/gui/panels/GUI_TopMenubar.h @@ -119,6 +119,7 @@ class TopMenubar // Tuning menu helpers void DrawTuningBoxedSubjectIdInline(int subject_id); void DrawTuningProtectedChkRightAligned(int subject_id, bool is_protected, ModifyProjectRequestType request_type_set, ModifyProjectRequestType request_type_reset); + void DrawTuningForceRemoveControls(const int subject_id, const std::string& name, const bool is_unwanted, const bool is_force_removed, ModifyProjectRequestType request_type_set, ModifyProjectRequestType request_type_reset); ImVec2 m_open_menu_hoverbox_min; ImVec2 m_open_menu_hoverbox_max; diff --git a/source/main/physics/ActorSpawner.cpp b/source/main/physics/ActorSpawner.cpp index 99ccebe3f5..8d6a359772 100644 --- a/source/main/physics/ActorSpawner.cpp +++ b/source/main/physics/ActorSpawner.cpp @@ -1493,7 +1493,7 @@ void ActorSpawner::ProcessFlexbody(RigDef::Flexbody& def) const FlexbodyID_t flexbody_id = (FlexbodyID_t)m_actor->m_gfx_actor->m_flexbodies.size(); // Check if disabled by .tuneup mod. - if (TuneupUtil::isFlexbodyRemoved(m_actor, flexbody_id)) + if (TuneupUtil::isFlexbodyAnyhowRemoved(m_actor, flexbody_id)) { // Create placeholder m_actor->m_gfx_actor->m_flexbodies.emplace_back(new FlexBody(FlexBody::TUNING_PLACEHOLDER, flexbody_id, def.mesh_name)); @@ -1563,7 +1563,7 @@ void ActorSpawner::ProcessProp(RigDef::Prop & def) PropID_t prop_id = static_cast(m_actor->m_gfx_actor->m_props.size()); // Check if removed via .tuneup - if (TuneupUtil::isPropRemoved(m_actor, prop_id)) + if (TuneupUtil::isPropAnyhowRemoved(m_actor, prop_id)) { RoR::Prop pprop; // placeholder pprop.pp_id = prop_id; diff --git a/source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp b/source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp index f101f9376b..886dd76d62 100644 --- a/source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp +++ b/source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp @@ -167,11 +167,11 @@ Ogre::Vector3 RoR::TuneupUtil::getTweakedNodePosition(CacheEntryPtr& tuneup_entr // > prop -bool RoR::TuneupUtil::isPropRemoved(ActorPtr& actor, PropID_t prop_id) +bool RoR::TuneupUtil::isPropAnyhowRemoved(ActorPtr& actor, PropID_t prop_id) { return actor->getUsedTuneupEntry() && actor->getUsedTuneupEntry()->tuneup_def - && actor->getUsedTuneupEntry()->tuneup_def->unwanted_props.find(prop_id) != actor->getUsedTuneupEntry()->tuneup_def->unwanted_props.end(); + && (actor->getUsedTuneupEntry()->tuneup_def->isPropUnwanted(prop_id) || actor->getUsedTuneupEntry()->tuneup_def->isPropForceRemoved(prop_id)); } Ogre::Vector3 RoR::TuneupUtil::getTweakedPropOffset(CacheEntryPtr& tuneup_entry, PropID_t prop_id, Ogre::Vector3 orig_val) @@ -248,11 +248,11 @@ std::string RoR::TuneupUtil::getTweakedPropMediaRG(ActorPtr& actor, PropID_t pro // > flexbody -bool RoR::TuneupUtil::isFlexbodyRemoved(ActorPtr& actor, FlexbodyID_t flexbody_id) +bool RoR::TuneupUtil::isFlexbodyAnyhowRemoved(ActorPtr& actor, FlexbodyID_t flexbody_id) { return actor->getUsedTuneupEntry() && actor->getUsedTuneupEntry()->tuneup_def - && actor->getUsedTuneupEntry()->tuneup_def->unwanted_flexbodies.find(flexbody_id) != actor->getUsedTuneupEntry()->tuneup_def->unwanted_flexbodies.end(); + && (actor->getUsedTuneupEntry()->tuneup_def->isFlexbodyUnwanted(flexbody_id) || actor->getUsedTuneupEntry()->tuneup_def->isFlexbodyForceRemoved(flexbody_id)); } Ogre::Vector3 RoR::TuneupUtil::getTweakedFlexbodyOffset(CacheEntryPtr& tuneup_entry, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val) diff --git a/source/main/resources/tuneup_fileformat/TuneupFileFormat.h b/source/main/resources/tuneup_fileformat/TuneupFileFormat.h index 9541ed9cfd..c77150942c 100644 --- a/source/main/resources/tuneup_fileformat/TuneupFileFormat.h +++ b/source/main/resources/tuneup_fileformat/TuneupFileFormat.h @@ -143,24 +143,32 @@ class TuneupUtil static std::vector ParseTuneups(Ogre::DataStreamPtr& stream); static void ExportTuneup(Ogre::DataStreamPtr& stream, TuneupDefPtr& tuneup); - /// @name Tweaking helpers + /// @name Wheel helpers /// @{ - // > wheel static float getTweakedWheelTireRadius(CacheEntryPtr& tuneup_entry, int wheel_id, float orig_val); static float getTweakedWheelRimRadius(CacheEntryPtr& tuneup_entry, int wheel_id, float orig_val); static std::string getTweakedWheelMedia(CacheEntryPtr& tuneup_entry, int wheel_id, int media_idx, const std::string& orig_val); static std::string getTweakedWheelMediaRG(ActorPtr& actor, int wheel_id, int media_idx); - static WheelSide getTweakedWheelSide(CacheEntryPtr& tuneup_entry, int wheel_id, WheelSide orig_val); - // > node + static WheelSide getTweakedWheelSide(CacheEntryPtr& tuneup_entry, int wheel_id, WheelSide orig_val); + /// @} + + /// @name Node helpers + /// @{ static Ogre::Vector3 getTweakedNodePosition(CacheEntryPtr& tuneup_entry, NodeNum_t nodenum, Ogre::Vector3 orig_val); - // > prop - static bool isPropRemoved(ActorPtr& actor, PropID_t prop_id); + /// @} + + /// @name Prop helpers + /// @{ + static bool isPropAnyhowRemoved(ActorPtr& actor, PropID_t prop_id); static Ogre::Vector3 getTweakedPropOffset(CacheEntryPtr& tuneup_entry, PropID_t prop_id, Ogre::Vector3 orig_val); static Ogre::Vector3 getTweakedPropRotation(CacheEntryPtr& tuneup_entry, PropID_t prop_id, Ogre::Vector3 orig_val); static std::string getTweakedPropMedia(CacheEntryPtr& tuneup_entry, PropID_t prop_id, int media_idx, const std::string& orig_val); static std::string getTweakedPropMediaRG(ActorPtr& actor, PropID_t prop_id, int media_idx); - // > flexbody - static bool isFlexbodyRemoved(ActorPtr& actor, FlexbodyID_t flexbody_id); + /// @} + + /// @name Flexbody helpers + /// @{ + static bool isFlexbodyAnyhowRemoved(ActorPtr& actor, FlexbodyID_t flexbody_id); static Ogre::Vector3 getTweakedFlexbodyOffset(CacheEntryPtr& tuneup_entry, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val); static Ogre::Vector3 getTweakedFlexbodyRotation(CacheEntryPtr& tuneup_entry, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val); static std::string getTweakedFlexbodyMedia(CacheEntryPtr& tuneup_entry, FlexbodyID_t flexbody_id, int media_idx, const std::string& orig_val);