Skip to content

Commit

Permalink
Tuning: improved UI overrides, separated from tuneups/unwants.
Browse files Browse the repository at this point in the history
All the UI overrides are now separate from any addonpart changes (tweaks or 'unwanted_*'). The 'protected' checkbox on the right just blocks addonpart changes, but isn't necessary for the UI overrides anymore. When you make an UI override, the respective widget will be outlined orange and a 'reset' button will be drawn. Internally, the UI overrides are called "force_*something*".

CAUTION: Top menubar Tuning menu is only corrected for flexbodies, not props yet!

Codechanges:
* TuneupFileFormat.h: replaced shared 'remove_props/flexbodies' by dual 'unwanted_*' and 'force_remove_*'. Added helper funcs.
* TuneupFileFormat.cpp: Updated parsing + exporting code.
* CacheSystem.h: `enum ModifyProjectRequestType`: REMOVE fields renamed to FORCEREMOVE. `struct ModifyProjectRequest`: removed hacky field `mpr_subject_set_protected`. Added func `LoadSupplementaryDocuments()`
* CacheSystem.cpp: updated and cleaned up `ModifyProject()` as the `mpr_subject_set_protected` hack isn't needed anymore.
* AddonPartFileFormat.cpp: updated to set/reset `unwanted_` fields - cleaner.
* GUI_TopMenubar.cpp - updated UI to signify overrided elements.
  • Loading branch information
ohlidalp committed Dec 11, 2023
1 parent bf8de0d commit 0e2eea0
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 107 deletions.
82 changes: 65 additions & 17 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ void TopMenubar::Draw(float dt)

// Draw props
size_t total_props = tuning_actor->GetGfxActor()->getProps().size();
std::string props_title = fmt::format(_LC("TopMenubar", "Props ({})"), total_props);
std::string props_title = fmt::format(_LC("Tuning", "Props ({})"), total_props);
if (ImGui::CollapsingHeader(props_title.c_str()) && tuneup_entry)
{
// Draw all props (those removed by addonparts are also present as placeholders)
Expand All @@ -1660,14 +1660,13 @@ void TopMenubar::Draw(float dt)
this->DrawTuningBoxedSubjectIdInline(p.pp_id);

// Draw the checkbox for removing/remounting.
bool propEnabled = tuneup_entry->tuneup_def->remove_props.find(p.pp_id) == tuneup_entry->tuneup_def->remove_props.end();
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_REMOVE_PROP_SET;
req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCEREMOVE_PROP_SET;
req->mpr_subject_id = p.pp_id;
req->mpr_target_actor = tuning_actor;
req->mpr_subject_set_protected = true; // stop evaluating addonparts for the prop (that would undo the user selection).
App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req));
}

Expand Down Expand Up @@ -1709,7 +1708,7 @@ void TopMenubar::Draw(float dt)

// Ditto for flexbodies
size_t total_flexbodies = tuning_actor->GetGfxActor()->GetFlexbodies().size();
std::string flexbodies_title = fmt::format(_LC("TopMenubar", "Flexbodies ({})"), total_flexbodies);
std::string flexbodies_title = fmt::format(_LC("Tuning", "Flexbodies ({})"), total_flexbodies);
if (ImGui::CollapsingHeader(flexbodies_title.c_str()) && tuneup_entry)
{
// Draw all flexbodies (those removed by addonparts are also present as placeholders)
Expand All @@ -1720,17 +1719,40 @@ void TopMenubar::Draw(float dt)

this->DrawTuningBoxedSubjectIdInline(flexbody->getID());

// Draw the checkbox for removing/remounting.
bool flexbodyEnabled = tuneup_entry->tuneup_def->remove_flexbodies.find(flexbody->getID()) == tuneup_entry->tuneup_def->remove_flexbodies.end();
if (ImGui::Checkbox(flexbody->getOrigMeshName().c_str(), &flexbodyEnabled))
// 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_REMOVE_FLEXBODY_SET;
req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCEREMOVE_FLEXBODY_RESET;
req->mpr_subject_id = flexbody->getID();
req->mpr_target_actor = tuning_actor;
req->mpr_subject_set_protected = true; // stop evaluating addonparts for the flexbody (that would undo the user selection).
App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req));
}

Expand All @@ -1757,6 +1779,11 @@ void TopMenubar::Draw(float dt)
this->DrawTuningBoxedSubjectIdInline(i);

// Draw R/L radio buttons
if (tuneup_entry->tuneup_def->isWheelSideForced(i))
{
ImGui::PushStyleColor(ImGuiCol_Border, ORANGE_TEXT);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f);
}
const RoR::WheelSide active_side = TuneupUtil::getTweakedWheelSide(tuneup_entry, i, tuning_actor->GetGfxActor()->getWheelSide(i));
RoR::WheelSide selected_side = active_side;
if (ImGui::RadioButton("##L", active_side == WheelSide::LEFT))
Expand All @@ -1767,21 +1794,42 @@ void TopMenubar::Draw(float dt)
if (ImGui::RadioButton("##R", active_side == WheelSide::RIGHT))
selected_side = WheelSide::RIGHT;

// Apply selection
// Draw rim mesh name
ImGui::SameLine();
ImGui::Text("%s", tuning_actor->GetGfxActor()->getWheelRimMeshName(i).c_str());

// Draw reset button

bool resetPressed = false;
if (tuneup_entry->tuneup_def->isWheelSideForced(i))
{
ImGui::SameLine();
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
}

// modify project if needed
if (selected_side != active_side)
{
ModifyProjectRequest* req = new ModifyProjectRequest();
req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCED_WHEEL_SIDE_SET;
req->mpr_subject_id = i;
req->mpr_value_int = (int)selected_side;
req->mpr_target_actor = tuning_actor;
req->mpr_subject_set_protected = true; // stop evaluating addonparts for the wheel (that would undo the user selection).
App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req));
}

// Draw rim mesh name
ImGui::SameLine();
ImGui::Text("%s", tuning_actor->GetGfxActor()->getWheelRimMeshName(i).c_str());
else if (resetPressed)
{
ModifyProjectRequest* req = new ModifyProjectRequest();
req->mpr_type = ModifyProjectRequestType::TUNEUP_FORCED_WHEEL_SIDE_RESET;
req->mpr_subject_id = i;
req->mpr_target_actor = tuning_actor;
App::GetGameContext()->PushMessage(Message(MSG_EDI_MODIFY_PROJECT_REQUESTED, req));
}

this->DrawTuningProtectedChkRightAligned(
i,
Expand Down
79 changes: 39 additions & 40 deletions source/main/resources/CacheSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,27 @@ std::string CacheSystem::ComposeResourceGroupName(const CacheEntryPtr& entry)
return fmt::format("{{bundle {}}}", name);
}

void CacheSystem::LoadSupplementaryDocuments(CacheEntryPtr& entry)
{
// Because we use one resource group per bundle and multiple entries can share the same bundle,
// we need to load the supplementary documents even if the bundle is already loaded.
// -------------------------------------------------------------------------------------------

if (!entry)
return;

ROR_ASSERT(entry->resource_group != "");

if (entry->fext == "skin")
{
this->LoadAssociatedSkinDef(entry);
}
else if (entry->fext == "tuneup")
{
this->LoadAssociatedTuneupDef(entry);
}
}

void CacheSystem::LoadResource(CacheEntryPtr& entry)
{
if (!entry)
Expand All @@ -1242,6 +1263,7 @@ void CacheSystem::LoadResource(CacheEntryPtr& entry)
// Check if already loaded for this entry->
if (entry->resource_group != "")
{
this->LoadSupplementaryDocuments(entry);
return;
}

Expand Down Expand Up @@ -1294,15 +1316,7 @@ void CacheSystem::LoadResource(CacheEntryPtr& entry)
ResourceGroupManager::getSingleton().initialiseResourceGroup(group);
entry->resource_group = group;

// Attach supplementary documents
if (entry->fext == "skin")
{
this->LoadAssociatedSkinDef(entry);
}
else if (entry->fext == "tuneup")
{
this->LoadAssociatedTuneupDef(entry);
}
this->LoadSupplementaryDocuments(entry);

// Inform other entries sharing this bundle (i.e. '.skin' entries in vehicle bundles)
for (CacheEntryPtr& i_entry: m_entries)
Expand Down Expand Up @@ -1392,7 +1406,6 @@ void CacheSystem::LoadAssociatedSkinDef(CacheEntryPtr& cache_entry)

try
{
App::GetCacheSystem()->LoadResource(cache_entry); // Load if not already
Ogre::DataStreamPtr ds = Ogre::ResourceGroupManager::getSingleton()
.openResource(cache_entry->fname, cache_entry->resource_group);

Expand Down Expand Up @@ -1442,7 +1455,6 @@ void CacheSystem::LoadAssociatedTuneupDef(CacheEntryPtr& cache_entry)

try
{
App::GetCacheSystem()->LoadResource(cache_entry); // Load if not already
Ogre::DataStreamPtr ds = Ogre::ResourceGroupManager::getSingleton()
.openResource(cache_entry->fname, cache_entry->resource_group);

Expand Down Expand Up @@ -1671,40 +1683,28 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)
tuneup_entry->tuneup_def->use_addonparts.erase(request->mpr_subject);
break;

case ModifyProjectRequestType::TUNEUP_REMOVE_PROP_SET:
tuneup_entry->tuneup_def->remove_props.insert(request->mpr_subject_id);
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_props.insert(request->mpr_subject_id);
case ModifyProjectRequestType::TUNEUP_FORCEREMOVE_PROP_SET:
tuneup_entry->tuneup_def->force_remove_props.insert(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_REMOVE_PROP_RESET:
tuneup_entry->tuneup_def->remove_props.erase(request->mpr_subject_id);
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_props.insert(request->mpr_subject_id);
case ModifyProjectRequestType::TUNEUP_FORCEREMOVE_PROP_RESET:
tuneup_entry->tuneup_def->force_remove_props.erase(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_REMOVE_FLEXBODY_SET:
tuneup_entry->tuneup_def->remove_flexbodies.insert(request->mpr_subject_id);
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_flexbodies.insert(request->mpr_subject_id);
case ModifyProjectRequestType::TUNEUP_FORCEREMOVE_FLEXBODY_SET:
tuneup_entry->tuneup_def->force_remove_flexbodies.insert(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_REMOVE_FLEXBODY_RESET:
tuneup_entry->tuneup_def->remove_flexbodies.erase(request->mpr_subject_id);
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_flexbodies.insert(request->mpr_subject_id);
case ModifyProjectRequestType::TUNEUP_FORCEREMOVE_FLEXBODY_RESET:
tuneup_entry->tuneup_def->force_remove_flexbodies.erase(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_FORCED_WHEEL_SIDE_SET:
tuneup_entry->tuneup_def->wheel_forced_sides[request->mpr_subject_id] = (WheelSide)request->mpr_value_int;
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_wheels.insert(request->mpr_subject_id);
tuneup_entry->tuneup_def->force_wheel_sides[request->mpr_subject_id] = (WheelSide)request->mpr_value_int;
break;

case ModifyProjectRequestType::TUNEUP_FORCED_WHEEL_SIDE_RESET:
tuneup_entry->tuneup_def->wheel_forced_sides.erase(request->mpr_subject_id);
if (request->mpr_subject_set_protected)
tuneup_entry->tuneup_def->protected_wheels.insert(request->mpr_subject_id);
tuneup_entry->tuneup_def->force_wheel_sides.erase(request->mpr_subject_id);
break;

case ModifyProjectRequestType::TUNEUP_PROTECTED_PROP_SET:
Expand All @@ -1729,7 +1729,6 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)

case ModifyProjectRequestType::TUNEUP_PROTECTED_WHEEL_RESET:
tuneup_entry->tuneup_def->protected_wheels.erase(request->mpr_subject_id);
tuneup_entry->tuneup_def->wheel_forced_sides.erase(request->mpr_subject_id); // Unlike props and flexbodies, forced sides are not updated from addonparts - we must clear manually.
break;

case ModifyProjectRequestType::PROJECT_LOAD_TUNEUP:
Expand All @@ -1746,10 +1745,10 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)
this->LoadResource(save_entry);
ROR_ASSERT(save_entry->tuneup_def);

tuneup_entry->tuneup_def->remove_flexbodies.clear();
tuneup_entry->tuneup_def->remove_flexbodies = save_entry->tuneup_def->remove_flexbodies;
tuneup_entry->tuneup_def->remove_props.clear();
tuneup_entry->tuneup_def->remove_props = save_entry->tuneup_def->remove_props;
tuneup_entry->tuneup_def->unwanted_flexbodies.clear();
tuneup_entry->tuneup_def->unwanted_flexbodies = save_entry->tuneup_def->unwanted_flexbodies;
tuneup_entry->tuneup_def->unwanted_props.clear();
tuneup_entry->tuneup_def->unwanted_props = save_entry->tuneup_def->unwanted_props;
tuneup_entry->tuneup_def->use_addonparts.clear();
tuneup_entry->tuneup_def->use_addonparts = save_entry->tuneup_def->use_addonparts;
tuneup_entry->tuneup_def->wheel_tweaks.clear();
Expand All @@ -1760,8 +1759,8 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)
}

case ModifyProjectRequestType::PROJECT_RESET_TUNEUP:
tuneup_entry->tuneup_def->remove_flexbodies.clear();
tuneup_entry->tuneup_def->remove_props.clear();
tuneup_entry->tuneup_def->unwanted_flexbodies.clear();
tuneup_entry->tuneup_def->unwanted_props.clear();
tuneup_entry->tuneup_def->use_addonparts.clear();
tuneup_entry->tuneup_def->wheel_tweaks.clear();
tuneup_entry->tuneup_def->node_tweaks.clear();
Expand Down
Loading

0 comments on commit 0e2eea0

Please sign in to comment.