Skip to content

Commit

Permalink
Tuneup: fixed known bugs of new UI overrides.
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
ohlidalp committed Dec 12, 2023
1 parent 0e2eea0 commit f47f148
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 60 deletions.
105 changes: 59 additions & 46 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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));
}

}
1 change: 1 addition & 0 deletions source/main/gui/panels/GUI_TopMenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -1563,7 +1563,7 @@ void ActorSpawner::ProcessProp(RigDef::Prop & def)
PropID_t prop_id = static_cast<int>(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;
Expand Down
8 changes: 4 additions & 4 deletions source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 16 additions & 8 deletions source/main/resources/tuneup_fileformat/TuneupFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,32 @@ class TuneupUtil
static std::vector<TuneupDefPtr> 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);
Expand Down

0 comments on commit f47f148

Please sign in to comment.