17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-23 08:51:11 +02:00

feat(editor): labels for a layman, light at the start; whole sceneries fitted to the terrain model

Labels:
- every button, field, tooltip and message of the editor reread for a beginner: short nouns for the fields with the
  sentence in the tooltip, the less used options under More settings, one glossary (field of work, template, track,
  grade), sides told from directions, degrees and per mille as signs, messages built from one format string
- plural forms through STR_P; the last entry of a po file is read too, and the Polish plural rule is in the header
- lang/editor_pl.po: the code pass entries merged, 391 entries no code uses and 3 duplicates dropped
- roads: the notes and errors naming a road translated; the build options and the layout fold the texture length,
  kerb sizes, traffic share, roundabout part, height over the ground and junction speed limit under More settings, the
  lanes start folded

Grade lines fitted to the terrain model (NMT), a line or the whole scenery at once:
- fit_ground: a robust fit on nodes 5 m apart; the ground parting from the line (a bridge, a viaduct, a wall) is gone
  past rather than followed, the bends keep off the switches as far as their curves reach, a run of bends the same way
  is one point of intersection, a curve with no room is as sharp as the room lets it be
- the ends of the line and the other paths of its switches leading into lines fitted already bound the line by what
  the tracks between can climb; ends meeting in the plan, laid apart in height by hand, are joined before the run
- apply_profile: the paths are split where split_path takes the parameter (a straight was cut in the wrong place, into
  pieces of a few centimetres the game takes for zero length), no piece shorter than the margin; the paths off the
  ends of the route are brought to its height
- Bytom: 1600 lines, grade breaks at the joints 89 -> 20; Tarnowskie Gory: 848 lines, 223 -> 3; no step over 2 cm
This commit is contained in:
maj00r
2026-10-19 15:27:50 +02:00
parent 5a00d88be9
commit ff1710d9ea
78 changed files with 15011 additions and 4386 deletions

View File

@@ -44,10 +44,45 @@ std::string lower(std::string Text)
return Text;
}
std::string skin_name(ui::skin_set const &Skin)
{
return Skin.meta != nullptr && false == Skin.meta->name.empty() ? Skin.meta->name : Skin.skin;
}
// side view of the vehicle from textures/mini, 0 while there's none; reading one takes a moment, a few of them go in a frame
ImTextureID vehicle_mini(ui::skin_set &Skin, std::set<ui::skin_set const *> &Asked, int &Loads)
{
if (false == static_cast<bool>(Skin.mini))
return 0;
if (Asked.count(&Skin) == 0)
{
if (Loads >= 4)
return 0;
++Loads;
Asked.insert(&Skin);
}
auto const id{Skin.mini.get()};
return id == deferred_image::invalid_id ? 0 : static_cast<ImTextureID>(id);
}
// the side view fitted into the box, kept in proportion and standing on its bottom; mirrored for a vehicle turned around
void draw_mini(ImDrawList &Draw, ImTextureID const Image, glm::ivec2 const Size, ImVec2 const Low, ImVec2 const High, bool const Turned)
{
if (Image == 0 || Size.x <= 0 || Size.y <= 0)
{
Draw.AddRect(Low, High, ImGui::GetColorU32(ImGuiCol_Border), 3.0f);
return;
}
auto const scale{std::min((High.x - Low.x) / Size.x, (High.y - Low.y) / Size.y)};
auto const width{std::round(Size.x * scale)};
auto const height{std::round(Size.y * scale)};
ImVec2 const low{std::round(Low.x + (High.x - Low.x - width) * 0.5f), High.y - height};
Draw.AddImage(Image, low, ImVec2(low.x + width, High.y), ImVec2(Turned ? 1.0f : 0.0f, 1.0f), ImVec2(Turned ? 0.0f : 1.0f, 0.0f));
}
std::string skin_label(ui::vehicle_desc const &Vehicle, ui::skin_set const &Skin)
{
auto label{Skin.meta != nullptr && false == Skin.meta->name.empty() ? Skin.meta->name : Skin.skin};
return label + " (" + Vehicle.path.generic_string() + ")";
return skin_name(Skin) + " (" + Vehicle.path.generic_string() + ")";
}
int path_under(TTrack const &Track, glm::dvec3 const &Point)
@@ -176,8 +211,9 @@ bool editor_mode::vehicle_place()
}
tool.placed = head;
first_step_done(first_step::drive);
auto const trackname{tool.track->name().empty() ? std::string{"(noname)"} : tool.track->name()};
tool.status = format(STR_C("%s and %d vehicle(s) behind it stand on %s"), head.c_str(), static_cast<int>(vehicles.size()) - 1, trackname.c_str());
auto const trackname{tool.track->name().empty() ? std::string{STR("(no name)")} : tool.track->name()};
auto const behind{static_cast<int>(vehicles.size()) - 1};
tool.status = behind > 0 ? format(STR_P("%s and %d vehicle behind it stand on %s", "%s and %d vehicles behind it stand on %s", behind), head.c_str(), behind, trackname.c_str()) : format(STR_C("%s stands on %s"), head.c_str(), trackname.c_str());
if (tool.write && tool.track->name().empty())
tool.status += ". " + std::string{STR_C("The track has no name, the trainset can't be written to the scenery")};
else if (tool.write)
@@ -220,7 +256,6 @@ void editor_mode::render_vehicle_ui()
tool.bank = std::make_shared<ui::vehicles_bank>();
tool.bank->scan_textures();
}
ImGui::TextDisabled("%s", STR_C("A trainset on the track, placed where the track was clicked, or in the middle of the path"));
ImGui::SetNextItemWidth(-1.0f);
ImGui::InputTextWithHint("##vehiclesearch", STR_C("search: name, series, skin"), tool.search, sizeof(tool.search));
ImGui::Checkbox(STR_C("Only the ones with a cab"), &tool.controllable_only);
@@ -242,78 +277,164 @@ void editor_mode::render_vehicle_ui()
listed.emplace_back(vehicle, skin);
}
}
ImGui::BeginChild("##vehicles", ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 8.0f + 6.0f), true);
int loads{0};
auto const line{ImGui::GetTextLineHeight()};
auto const box{ImVec2(std::round(ImGui::GetFontSize() * 7.0f), std::round(line * 2.0f))};
ImGui::BeginChild("##vehicles", ImVec2(0.0f, (box.y + ImGui::GetStyle().ItemSpacing.y) * 5.5f + 6.0f), ImGuiChildFlags_Borders);
for (std::size_t i = 0; i < listed.size(); ++i)
{
auto const &[vehicle, skin] = listed[i];
if (ImGui::Selectable(format("%s##vehicle%zu", skin_label(*vehicle, *skin).c_str(), i).c_str(), tool.skin == skin))
ImGui::PushID(static_cast<int>(i));
auto const low{ImGui::GetCursorScreenPos()};
if (ImGui::Selectable("##vehicle", tool.skin == skin, ImGuiSelectableFlags_AllowDoubleClick, ImVec2(0.0f, box.y)))
{
tool.vehicle = vehicle;
tool.skin = skin;
if (ImGui::IsMouseDoubleClicked(0))
tool.consist.push_back({vehicle, skin, false});
}
if (ImGui::IsItemVisible())
{
auto &draw{*ImGui::GetWindowDrawList()};
draw_mini(draw, vehicle_mini(*skin, tool.minis, loads), skin->mini.size(), ImVec2(low.x + 2.0f, low.y + 1.0f), ImVec2(low.x + box.x, low.y + box.y - 1.0f), false);
auto const left{low.x + box.x + ImGui::GetStyle().ItemSpacing.x};
auto const right{ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMax().x};
draw.PushClipRect(ImVec2(left, low.y), ImVec2(right, low.y + box.y), true);
draw.AddText(ImVec2(left, low.y), ImGui::GetColorU32(ImGuiCol_Text), skin_name(*skin).c_str());
draw.AddText(ImVec2(left, low.y + line), ImGui::GetColorU32(ImGuiCol_TextDisabled), vehicle->path.generic_string().c_str());
draw.PopClipRect();
}
ImGui::PopID();
}
ImGui::EndChild();
if (total > listed.size())
ImGui::TextDisabled(STR_C("%zu found, the first %zu listed"), total, listed.size());
if (tool.vehicle != nullptr && tool.skin != nullptr && ImGui::Button(STR_C("Add to the train")))
tool.consist.push_back({tool.vehicle, tool.skin, false});
if (false == tool.consist.empty())
if (tool.vehicle != nullptr && tool.skin != nullptr)
{
ImGui::SameLine();
ImGui::TextDisabled(STR_C("Train: %d vehicle(s), the first one leads"), static_cast<int>(tool.consist.size()));
std::optional<std::size_t> remove;
std::optional<std::size_t> raise;
if (ImGui::Button(format(STR_C("Add %s to the train"), skin_name(*tool.skin).c_str()).c_str(), ImVec2(-1.0f, 0.0f)))
tool.consist.push_back({tool.vehicle, tool.skin, false});
item_tooltip("A double click on the list adds it too");
}
// the train as a picture, the head on the left; a click on a vehicle shows its buttons
ImGui::SeparatorText(STR_C("Train"));
if (tool.consist.empty())
ImGui::TextDisabled("%s", STR_C("No vehicles yet: pick one from the list and add it"));
else
{
auto const height{std::round(line * 1.8f)};
auto const width_of = [&](ui::skin_set const &Skin) {
auto const size{Skin.mini.size()};
return size.y > 0 ? std::round(height * size.x / size.y) : height * 3.0f;
};
float total_width{0.0f};
for (auto const &item : tool.consist)
total_width += width_of(*item.skin) + 2.0f;
auto const scrolled{total_width > ImGui::GetContentRegionAvail().x};
ImGui::BeginChild("##train", ImVec2(0.0f, height + 6.0f + (scrolled ? ImGui::GetStyle().ScrollbarSize : 0.0f)), ImGuiChildFlags_None, ImGuiWindowFlags_HorizontalScrollbar);
auto &draw{*ImGui::GetWindowDrawList()};
for (std::size_t i = 0; i < tool.consist.size(); ++i)
{
auto &item{tool.consist[i]};
auto const vehicle{item.skin->vehicle.lock()};
auto const width{width_of(*item.skin)};
if (i > 0)
ImGui::SameLine(0.0f, 2.0f);
ImGui::PushID(static_cast<int>(i));
ImGui::Checkbox("##turned", &item.turned);
auto const low{ImGui::GetCursorScreenPos()};
if (ImGui::InvisibleButton("##car", ImVec2(width, height + 4.0f)))
tool.picked = tool.picked == static_cast<int>(i) ? -1 : static_cast<int>(i);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("Turned around in the train"));
ImGui::SameLine();
ImGui::Text("%2d. %s", static_cast<int>(i + 1), vehicle != nullptr ? skin_label(*vehicle, *item.skin).c_str() : item.skin->skin.c_str());
ImGui::SameLine();
if (i > 0 && ImGui::SmallButton(STR_C("up")))
raise = i;
ImGui::SameLine();
if (ImGui::SmallButton("x"))
remove = i;
{
auto const vehicle{item.skin->vehicle.lock()};
ImGui::SetTooltip("%d. %s", static_cast<int>(i + 1), vehicle != nullptr ? skin_label(*vehicle, *item.skin).c_str() : item.skin->skin.c_str());
}
if (tool.picked == static_cast<int>(i) || ImGui::IsItemHovered())
draw.AddRectFilled(low, ImVec2(low.x + width, low.y + height + 4.0f), tool.picked == static_cast<int>(i) ? family_colour(0, 0.45f) : ImGui::GetColorU32(ImGuiCol_FrameBgHovered), 3.0f);
draw_mini(draw, vehicle_mini(*item.skin, tool.minis, loads), item.skin->mini.size(), ImVec2(low.x, low.y + 2.0f), ImVec2(low.x + width, low.y + height + 2.0f), item.turned);
ImGui::PopID();
}
if (raise)
std::swap(tool.consist[*raise], tool.consist[*raise - 1]);
if (remove)
tool.consist.erase(tool.consist.begin() + static_cast<std::ptrdiff_t>(*remove));
ImGui::EndChild();
if (tool.picked >= static_cast<int>(tool.consist.size()))
tool.picked = -1;
if (tool.picked >= 0)
{
auto const i{static_cast<std::size_t>(tool.picked)};
auto &item{tool.consist[i]};
ImGui::Text("%d. %s", tool.picked + 1, skin_name(*item.skin).c_str());
auto const button = [](char const *Label, bool const Enabled, char const *Tooltip) {
ImGui::BeginDisabled(false == Enabled);
auto const pressed{ImGui::Button(STR_C(Label))};
ImGui::EndDisabled();
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetTooltip("%s", STR_C(Tooltip));
ImGui::SameLine();
return pressed;
};
auto const forward{button("Forward", i > 0, "Moves it one place towards the head")};
auto const back{button("Back", i + 1 < tool.consist.size(), "Moves it one place towards the end")};
auto const turn{button("Turn around", true, "Turned around in the train")};
auto const remove{button("Remove", true, "Takes it out of the train")};
ImGui::NewLine();
if (forward)
{
std::swap(tool.consist[i], tool.consist[i - 1]);
--tool.picked;
}
else if (back)
{
std::swap(tool.consist[i], tool.consist[i + 1]);
++tool.picked;
}
else if (turn)
item.turned = !item.turned;
else if (remove)
{
tool.consist.erase(tool.consist.begin() + static_cast<std::ptrdiff_t>(i));
tool.picked = -1;
}
}
else
ImGui::TextDisabled(STR_P("%d vehicle, the head on the left: click it to move it, turn it or remove it", "%d vehicles, the head on the left: click one to move it, turn it or remove it", static_cast<long long>(tool.consist.size())), static_cast<int>(tool.consist.size()));
if (ImGui::SmallButton(STR_C("Empty the train")))
{
tool.consist.clear();
tool.picked = -1;
}
}
ImGui::SeparatorText(STR_C("On the track"));
if (ImGui::Button(STR_C("Turn the train around")))
tool.facing = -tool.facing;
ImGui::SameLine();
ImGui::TextDisabled("%s", STR_C("the head goes where the arrow at the marker points"));
ImGui::RadioButton(STR_C("With a driver, to drive"), &tool.driver, 0);
ImGui::SameLine();
ImGui::RadioButton(STR_C("Nobody, parked"), &tool.driver, 1);
ImGui::Checkbox(STR_C("Write to the scenery as a trainset"), &tool.write);
item_tooltip("On: the trainset is written to the scenery on save (Ctrl+S). Off: only to drive now, gone when the scenery is loaded again");
if (tool.write)
item_tooltip("The head goes where the arrow at the marker points");
segmented("driver", tool.driver,
{{0, STR_C("With a driver, to drive"), "The train can be driven or run by the AI at once"}, {1, STR_C("Nobody, parked"), "The vehicles stand braked, without a crew"}});
toggle_chips("vehiclewrite", {{STR_C("Write to the scenery as a trainset"), &tool.write, "On: the trainset is written to the scenery on save (Ctrl+S). Off: only to drive now, gone when the scenery is loaded again"}});
if (tool.write && ImGui::TreeNode(STR_C("More settings")))
{
ImGui::PushItemWidth(120.0f);
ImGui::InputText(STR_C("Timetable"), tool.timetable, sizeof(tool.timetable));
item_tooltip("The timetable the train runs by; none: no timetable, it waits for orders");
ImGui::DragScalar(STR_C("Speed at the start (km/h)"), ImGuiDataType_Double, &tool.velocity, 1.0f, nullptr, nullptr, "%.0f");
tool.velocity = std::clamp(tool.velocity, 0.0, 400.0);
ImGui::PopItemWidth();
if (begin_fields("##vehiclefields", 0.45f))
{
field_row("Timetable##trainset");
ImGui::InputText("##vehicletimetable", tool.timetable, sizeof(tool.timetable));
item_tooltip("The timetable the train runs by; none: no timetable, it waits for orders");
field_row("Speed at the start (km/h)");
ImGui::DragScalar("##vehiclevelocity", ImGuiDataType_Double, &tool.velocity, 1.0f, nullptr, nullptr, "%.0f");
tool.velocity = std::clamp(tool.velocity, 0.0, 400.0);
ImGui::EndTable();
}
ImGui::TreePop();
}
if (tool.consist.empty() && (tool.vehicle == nullptr || tool.skin == nullptr))
ImGui::TextDisabled("%s", STR_C("Pick a vehicle from the list"));
else
if (false == tool.consist.empty() || (tool.vehicle != nullptr && tool.skin != nullptr))
{
if (ImGui::Button(STR_C("Place")))
auto const half{std::floor((ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f)};
auto const tall{std::round(ImGui::GetFrameHeight() * 1.3f)};
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.55f, 0.25f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.25f, 0.65f, 0.3f, 1.0f));
if (ImGui::Button(STR_C("Place"), ImVec2(half, tall)))
vehicle_place();
item_tooltip("A trainset on the track, placed where the track was clicked, or in the middle of the path");
ImGui::PopStyleColor(2);
ImGui::SameLine();
if (ImGui::Button(STR_C("Place and drive")) && vehicle_place())
if (ImGui::Button(STR_C("Place and drive"), ImVec2(-1.0f, tall)) && vehicle_place())
{
Global.editor_enter_vehicle = tool.placed;
tool.leave = true;
@@ -324,7 +445,7 @@ void editor_mode::render_vehicle_ui()
if (tool.trainsets.empty())
return;
ImGui::Separator();
ImGui::TextDisabled(STR_C("%d trainset(s) to write on save:"), static_cast<int>(tool.trainsets.size()));
ImGui::TextDisabled(STR_P("%d trainset to write on save:", "%d trainsets to write on save:", static_cast<long long>(tool.trainsets.size())), static_cast<int>(tool.trainsets.size()));
std::optional<std::size_t> drop;
for (std::size_t i = 0; i < tool.trainsets.size(); ++i)
{