18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 05:02:45 +01:00

feat(editor): the cab of a vehicle edited in the Models mode, from the seat of the driver

The cab of a vehicle is loaded only by getting in. "Get in the cab" in the Models mode does what the
simulation does then: it makes the train of the vehicle (TTrain::Init loads the cab, its controls and its
sounds), makes it the vehicle driven, and puts the camera in the seat of the driver. While the cab is edited
the editor draws it as from that seat: FreeFlyModeFlag is off and the vehicle owns the camera, which moves
with it by its offset (the sounds read the owner of the camera then). With the body picked, or in another
field of work, the view is free again.

A new self-test command, modelvehicle <name> [cab], picks a vehicle and gets in its cab. Tested on the
EU07-424 (303e-tv) with a light added to its cab.
This commit is contained in:
maj00r
2026-11-29 23:00:52 +01:00
parent 6828e52a45
commit 42e0884606
7 changed files with 173 additions and 8 deletions
+70 -8
View File
@@ -1047,14 +1047,7 @@ void eu07m_model_panel::render_bank()
ImGui::TextUnformatted(name.empty() ? STR_C("(no name)") : name.c_str());
if (m_target.vehicle != nullptr)
{
ImGui::BeginDisabled(m_target.vehicle->mdKabina == nullptr);
std::array const parts{STR_C("Body"), STR_C("Cab")};
if (auto const clicked{choice_buttons("##part", static_cast<std::size_t>(m_target.part), parts)})
{
// the other part is shown in the next frame
m_part = static_cast<int>(*clicked);
}
ImGui::EndDisabled();
render_vehicle_part();
}
ImGui::TextDisabled("%s", m_path.empty() ? m_source->NameGet().c_str() : std::filesystem::path{m_path}.filename().string().c_str());
}
@@ -1115,6 +1108,56 @@ void eu07m_model_panel::render_bank()
ImGui::EndChild();
}
void eu07m_model_panel::render_vehicle_part()
{
auto *vehicle{m_target.vehicle};
auto const cab{(vehicle->mdKabina != nullptr) && (vehicle->mdKabina != vehicle->mdModel)};
if (false == cab)
{
// the cab is loaded only by getting in: the button does what the game does then
if (ImGui::Button(STR_C("Get in the cab")))
{
open_cab();
}
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("%s", STR_C("Loads the cab of the vehicle as the game does when you get in, and puts the camera in the seat of the driver"));
}
return;
}
std::array const parts{STR_C("Body"), STR_C("Cab")};
if (auto const clicked{choice_buttons("##part", static_cast<std::size_t>(m_target.part), parts)})
{
// the other part is shown in the next frame; from the cab the camera goes out to look at the body
m_part = static_cast<int>(*clicked);
if ((m_part == 1) && (enter_cab != nullptr))
{
enter_cab(*vehicle);
}
else if (m_part == 0)
{
fly_to_vehicle(*vehicle);
}
}
}
bool eu07m_model_panel::open_cab()
{
auto *vehicle{m_target.vehicle != nullptr ? m_target.vehicle : m_pickedvehicle};
if ((vehicle == nullptr) || (enter_cab == nullptr))
{
return false;
}
m_pickedvehicle = vehicle;
if (false == enter_cab(*vehicle))
{
m_message = STR("The vehicle has no cab of its own to get in");
return false;
}
m_part = 1;
return true;
}
void eu07m_model_panel::render_insert()
{
if ((place_model == nullptr) || (false == ImGui::TreeNode(STR_C("Put a model in the scenery"))))
@@ -1727,6 +1770,25 @@ bool eu07m_model_panel::editable(scene::basic_node const *Node) const
return Global.modelformat_eu07m && (instance != nullptr) && (instance->pModel != nullptr) && (false == FileCased(instance->pModel->NameGet() + ".eu07m").empty());
}
bool eu07m_model_panel::pick_vehicle(std::string_view const Name, int const Part)
{
auto const &vehicles{simulation::Vehicles.sequence()};
auto const wanted_name{lowered(Name)};
auto const found{std::ranges::find_if(vehicles, [&wanted_name](TDynamicObject const *Vehicle) { return lowered(Vehicle->name()) == wanted_name; })};
if (found == vehicles.end())
{
return false;
}
m_pickedvehicle = *found;
m_part = Part;
if (Part == 1)
{
return (enter_cab != nullptr) && enter_cab(**found);
}
fly_to_vehicle(**found);
return true;
}
bool eu07m_model_panel::select_node(std::string_view const Name)
{
auto const nodes{eu07m::find_nodes(m_model, Name)};