Skip to content

Commit

Permalink
Tuning: misc fixes
Browse files Browse the repository at this point in the history
* GUIUtils.cpp - fixed ImButtonHoldToConfirm() not reacting to first press in game session.
* GUI_TopMenubar.cpp - fixed crash when tuning is disabled
* FlexBody.cpp - fixed crash hazzard when flexbody is removed via UI or AddonPar - reported by Mike on Discord.
* AddonPartFileFormat.cpp - reset tweak data every time - fixes Reload button (under addonparts section) having no effect.
* CacheSystem - properly unload all cached documents (skin/truckfile/addonpart) when reloading cache entry.
* TuneupFileFormat.h - codedoc
* TuneupFileFormat.cpp - fixed 'wheel_forced_side' not saved to/loaded from .tuneup file.
  • Loading branch information
ohlidalp committed Dec 4, 2023
1 parent 7104026 commit bf8de0d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
39 changes: 18 additions & 21 deletions source/main/gui/GUIUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,34 +440,31 @@ void RoR::ImDrawModifierKeyHighlighted(OIS::KeyCode key)
bool RoR::ImButtonHoldToConfirm(const std::string& btn_caption, bool small, float time_limit, float& time_left_var, float dt)
{

bool btn_pressed = false;
if (small)
btn_pressed = ImGui::SmallButton(btn_caption.c_str());
ImGui::SmallButton(btn_caption.c_str());
else
btn_pressed = ImGui::Button(btn_caption.c_str());
ImGui::Button(btn_caption.c_str());

if (btn_pressed)
if (ImGui::IsItemActive() && time_left_var > 0.f)
{
time_left_var = time_limit; // Initialize
time_left_var -= dt;
if (time_left_var > 0.f)
{
ImGui::BeginTooltip();
std::string text = _L("Hold to confirm");
ImGui::TextDisabled(text.c_str());
ImGui::ProgressBar(time_left_var/time_limit, ImVec2(ImGui::CalcTextSize(text.c_str()).x, 8.f), "");
ImGui::EndTooltip();
}
else
{
return true;
}
}
else
{
if (ImGui::IsItemActive() && time_left_var > 0.f)
{
time_left_var -= dt;
if (time_left_var > 0.f)
{
ImGui::BeginTooltip();
std::string text = _L("Hold to confirm");
ImGui::TextDisabled(text.c_str());
ImGui::ProgressBar(time_left_var/time_limit, ImVec2(ImGui::CalcTextSize(text.c_str()).x, 8.f), "");
ImGui::EndTooltip();
}
else
{
return true;
}
}
time_left_var = time_limit;
}

return false;
}
4 changes: 2 additions & 2 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,13 +1594,13 @@ void TopMenubar::Draw(float dt)

ImGui::SetNextItemOpen(true, ImGuiCond_FirstUseEver);
std::string addonparts_title = fmt::format(_LC("TopMenubar", "Addon parts ({})"), tuning_addonparts.cqy_results.size());
if (ImGui::CollapsingHeader(addonparts_title.c_str()))
if (ImGui::CollapsingHeader(addonparts_title.c_str()) && tuneup_entry)
{
for (CacheQueryResult& addonpart_result: tuning_addonparts.cqy_results)
{
ImGui::PushID(addonpart_result.cqr_entry->fname.c_str());

bool used = tuning_actor->getUsedTuneupEntry()->tuneup_def->use_addonparts.count(addonpart_result.cqr_entry->fname) > 0;
bool used = tuneup_entry->tuneup_def->use_addonparts.count(addonpart_result.cqr_entry->fname) > 0;
if (ImGui::Checkbox(addonpart_result.cqr_entry->dname.c_str(), &used))
{
ModifyProjectRequest* req = new ModifyProjectRequest();
Expand Down
4 changes: 3 additions & 1 deletion source/main/physics/flex/FlexBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ void FlexBody::setVisible(bool visible)

void FlexBody::setFlexbodyCastShadow(bool val)
{
m_scene_entity->setCastShadows(val);
// Scene entity is NULL if disabled via addonpart/tuneup.
if (m_scene_entity)
m_scene_entity->setCastShadows(val);
}

void FlexBody::computeFlexbody()
Expand Down
8 changes: 6 additions & 2 deletions source/main/resources/CacheSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,12 @@ void CacheSystem::UnLoadResource(CacheEntryPtr& entry)
{
if (i_entry->resource_group == resource_group)
{
i_entry->actor_def = nullptr; // Delete cached truck file - force reload from disk
i_entry->resource_group = ""; // Mark as unloaded
// Delete cached documents - force reload from disk
i_entry->actor_def = nullptr;
i_entry->tuneup_def = nullptr;
i_entry->skin_def = nullptr;
// Mark as unloaded
i_entry->resource_group = "";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ void AddonPartUtility::ResolveUnwantedAndTweakedElements(TuneupDefPtr& tuneup, C
m_addonpart_entry = addonpart_entry;
m_tuneup = tuneup;

// Reset tweak data - to be reloaded from addonpart
m_tuneup->prop_tweaks.clear();
m_tuneup->flexbody_tweaks.clear();
m_tuneup->wheel_tweaks.clear();
m_tuneup->node_tweaks.clear();

try
{
Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().openResource(addonpart_entry->fname, addonpart_entry->resource_group);
Expand Down
5 changes: 5 additions & 0 deletions source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ void RoR::TuneupUtil::ParseTuneupAttribute(const std::string& line, TuneupDefPtr
if (attrib == "remove_flexbody" && params.size() == 2) { tuneup_def->remove_flexbodies.insert(PARSEINT(params[1])); return; }
if (attrib == "protected_prop" && params.size() == 2) { tuneup_def->protected_props.insert(PARSEINT(params[1])); return; }
if (attrib == "protected_flexbody" && params.size() == 2) { tuneup_def->protected_flexbodies.insert(PARSEINT(params[1])); return; }
if (attrib == "forced_wheel_side" && params.size() == 3) { tuneup_def->wheel_forced_sides[PARSEINT(params[1])] = (WheelSide)PARSEINT(params[2]); return; }
}

void RoR::TuneupUtil::ExportTuneup(Ogre::DataStreamPtr& stream, TuneupDefPtr& tuneup)
Expand Down Expand Up @@ -450,6 +451,10 @@ void RoR::TuneupUtil::ExportTuneup(Ogre::DataStreamPtr& stream, TuneupDefPtr& tu
{
buf << "\tprotected_flexbody = " << (int)protected_flexbody << "\n";
}
for (auto& pair: tuneup->wheel_forced_sides)
{
buf << "\tforced_wheel_side = " << pair.first << ", " << (int)pair.second << "\n";
}
buf << "}\n\n";

size_t written = stream->write(buf.GetBuffer(), buf.GetLength());
Expand Down
4 changes: 2 additions & 2 deletions source/main/resources/tuneup_fileformat/TuneupFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ struct TuneupDef: public RefCountingObject<TuneupDef>

std::map<NodeNum_t, TuneupNodeTweak> node_tweaks; //!< Node position overrides via 'addonpart_tweak_node'
std::map<WheelID_t, TuneupWheelTweak> wheel_tweaks; //!< Mesh name and radius overrides via 'addonpart_tweak_wheel'
std::map<PropID_t, TuneupPropTweak> prop_tweaks;
std::map<FlexbodyID_t, TuneupFlexbodyTweak> flexbody_tweaks;
std::map<PropID_t, TuneupPropTweak> prop_tweaks; //!< Mesh name(s), offset and rotation overrides via 'addonpart_tweak_prop'
std::map<FlexbodyID_t, TuneupFlexbodyTweak> flexbody_tweaks; //!< Mesh name, offset and rotation overrides via 'addonpart_tweak_flexbody'

std::set<PropID_t> remove_props; //!< Either UI overrides or 'addonpart_unwanted_prop' directives.
std::set<FlexbodyID_t> remove_flexbodies; //!< Either UI overrides or 'addonpart_unwanted_flexbody' directives.
Expand Down

0 comments on commit bf8de0d

Please sign in to comment.