mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 14:07:06 +01:00
075a66d169
editor-project-setup.md: a new user drew with no word of what: the norms, the speed, the gauge and the rail lay about the panels, set on the way. Now one short step, "What do you draw?" (Co rysujesz?), one screen of defaults and one button: - The fields: the norms (PLK ST-T1-A6, TSI alone, EN 13803, CH; PLK by default, no "none": a fictional scenery has a profile too), the speed of the line (chips 40..200, 100 km/h), the traffic, a main or a side track, the gauge (1435 / 1520 / 1000 / 750 / 600 mm), the rail (60E1 / 49E1 / S42), the look of the tracks under More (the rails and the trackbed as now where left empty). application/editorsetupui.* draws them for all three places below. - Asked for as the last step of the wizard of a new scenery (4., or 2. for a fictional one; its button Start: create and open in the editor), which writes them into the new scenery; and in a scenery with none, as a card in the inspector of the tracks in place of the first steps, until its Start. Changed later in their window, Assumptions of the project, from the editor settings or the line of them under the first steps in Tracks; a change checks the lines laid before against them, the report in the window of the norms, nothing laid changed by it. - Kept with the map (editor/editorProjectSetup.*, one record "setup norms plk speed 100 traffic mixed track main gauge 1435 rail 60E1"): in its project file where it has one (a record of its own; the profile of the scenery the model judges by set with it), else in the scenery as //$u lines, which the simulator skips and the scene layers keep as a mark of the editor. Read when the map is opened, the project file first. A scenery saved without them holds nothing new. - The defaults of the tools from them: the speed of the laying and of the route design, the gauge and the rails and the trackbed of the tracks laid, the norms checked against, the rail of the switch tool and the usual switch of the rail for the speed on its diverging track (the closest speed, the ratio usual for it). A route with no speed of its own takes the speed of the assumptions. Self-test: setup [<key> <value>]..., setupwindow [close]; expect setup none|<key> <value>, expect setupmark <present|absent>, expect layspeed <km/h>. The cases ps_1_setup_saved (set, saved into the scenery, read back after a reopen) and ps_2_setup_project (into the project file with the editing on the model, read from there after a reopen with it off). Tests: U: the record written and read back, the defaults, what it can't read, the class of the line, kept in the project file. lang/editor_pl.po: the Polish of the new texts.
169 lines
5.8 KiB
C++
169 lines
5.8 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "application/editorsetupui.h"
|
|
#include "application/editormodeshared.h"
|
|
#include "editor/editorFormat.hpp"
|
|
#include "editor/editorNormsReport.hpp"
|
|
|
|
#include "imgui/imgui.h"
|
|
#include "utilities/translation.h"
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cfloat>
|
|
#include <cmath>
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
namespace setup_ui
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
// a translated name, what follows ## in it left out: the short names of the choices, told apart from the same words elsewhere
|
|
std::string shown(char const *Translated)
|
|
{
|
|
std::string text{Translated};
|
|
return text.substr(0, text.find("##"));
|
|
}
|
|
|
|
// a texture of the look, typed: empty for the one the lay tool has
|
|
bool texture_field(char const *Label, char const *Id, std::string &Value, char const *Hint)
|
|
{
|
|
field_row(Label);
|
|
std::array<char, 256> text{};
|
|
std::strncpy(text.data(), Value.c_str(), text.size() - 1);
|
|
if (false == ImGui::InputTextWithHint(Id, Hint, text.data(), text.size()))
|
|
return false;
|
|
Value = text.data();
|
|
return true;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
char const *profile_label(norms::profile_id const Profile)
|
|
{
|
|
switch (Profile)
|
|
{
|
|
case norms::profile_id::tsi: return "TSI";
|
|
case norms::profile_id::en13803: return "EN 13803";
|
|
case norms::profile_id::ch: return "CH";
|
|
default: return "PLK";
|
|
}
|
|
}
|
|
|
|
std::string summary(project_setup::setup const &Setup)
|
|
{
|
|
return format("%s · %.0f km/h · %s · %s · %d mm · %s", profile_label(Setup.profile), Setup.speed, norms_report::traffic_name(Setup.traffic),
|
|
Setup.track == norms::track_kind::side ? STR_C("siding") : STR_C("main track"), Setup.gauge, Setup.rail.c_str());
|
|
}
|
|
|
|
bool fields(char const *Id, project_setup::setup &Setup)
|
|
{
|
|
bool changed{false};
|
|
ImGui::PushID(Id);
|
|
if (begin_fields("##setupfields", 0.3f))
|
|
{
|
|
field_row("Norms");
|
|
if (int profile{static_cast<int>(Setup.profile)};
|
|
segmented("setupnorms", profile,
|
|
{{static_cast<int>(norms::profile_id::plk), "PLK", "PKP PLK Id-1 (ST-T1-A6): the values preferred, the normal and the extended limits"},
|
|
{static_cast<int>(norms::profile_id::tsi), "TSI", "TSI INF alone: the least the law of the EU allows, the loosest; its limits can't be passed either"},
|
|
{static_cast<int>(norms::profile_id::en13803), "EN 13803", "EN 13803: the normal limits warn, the exceptional ones can't be passed"},
|
|
{static_cast<int>(norms::profile_id::ch), "CH", "Swiss AB-EBV: the normal limits warn, the greatest ones can't be passed"}}))
|
|
{
|
|
Setup.profile = static_cast<norms::profile_id>(profile);
|
|
changed = true;
|
|
}
|
|
ImGui::PushTextWrapPos(0.0f);
|
|
ImGui::TextDisabled("%s", STR_C("A map across two countries: the areas of the norms later, in the settings"));
|
|
ImGui::PopTextWrapPos();
|
|
|
|
field_row("Line speed");
|
|
changed |= value_chips("setupspeeds", Setup.speed, {40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 200.0}, "%.0f");
|
|
ImGui::SetNextItemWidth(std::round(ImGui::GetFontSize() * 5.0f));
|
|
changed |= ImGui::DragScalar("##setupspeed", ImGuiDataType_Double, &Setup.speed, 1.0f, nullptr, nullptr, "%.0f km/h");
|
|
Setup.speed = std::clamp(Setup.speed, 10.0, 350.0);
|
|
|
|
field_row("Traffic");
|
|
auto const passenger{shown(STR_C("passenger##traffic"))};
|
|
auto const mixed{shown(STR_C("mixed##traffic"))};
|
|
auto const freight{shown(STR_C("freight##traffic"))};
|
|
if (int traffic{static_cast<int>(Setup.traffic)};
|
|
segmented("setuptraffic", traffic,
|
|
{{static_cast<int>(norms::traffic::passenger), passenger.c_str()}, {static_cast<int>(norms::traffic::mixed), mixed.c_str()}, {static_cast<int>(norms::traffic::freight), freight.c_str()}}))
|
|
{
|
|
Setup.traffic = static_cast<norms::traffic>(traffic);
|
|
changed = true;
|
|
}
|
|
|
|
field_row("Track");
|
|
auto const main{shown(STR_C("main##track"))};
|
|
auto const side{shown(STR_C("side (station)##track"))};
|
|
if (int track{static_cast<int>(Setup.track)};
|
|
segmented("setuptrack", track,
|
|
{{static_cast<int>(norms::track_kind::main), main.c_str(), "A running line or a main track of a station"},
|
|
{static_cast<int>(norms::track_kind::side), side.c_str(), "A siding of a station: the norms of the side tracks"}}))
|
|
{
|
|
Setup.track = static_cast<norms::track_kind>(track);
|
|
changed = true;
|
|
}
|
|
|
|
field_row("Gauge");
|
|
{
|
|
std::vector<segment_option> options;
|
|
std::vector<std::string> names;
|
|
for (auto const gauge : project_setup::gauges)
|
|
names.push_back(format("%d", gauge));
|
|
for (std::size_t i = 0; i < names.size(); ++i)
|
|
options.push_back({project_setup::gauges[i], names[i].c_str()});
|
|
if (int gauge{Setup.gauge}; choice_chips("setupgauge", gauge, options))
|
|
{
|
|
Setup.gauge = gauge;
|
|
changed = true;
|
|
}
|
|
}
|
|
|
|
field_row("Rail");
|
|
{
|
|
int rail{0};
|
|
for (std::size_t i = 0; i < project_setup::rail_kinds.size(); ++i)
|
|
if (project_setup::rail_kinds[i] == Setup.rail)
|
|
rail = static_cast<int>(i);
|
|
if (segmented("setuprail", rail, {{0, "60E1"}, {1, "49E1"}, {2, "S42"}}))
|
|
{
|
|
Setup.rail = std::string{project_setup::rail_kinds[static_cast<std::size_t>(rail)]};
|
|
changed = true;
|
|
}
|
|
ImGui::PushTextWrapPos(0.0f);
|
|
ImGui::TextDisabled("%s", STR_C("the switches of this rail first"));
|
|
ImGui::PopTextWrapPos();
|
|
}
|
|
ImGui::EndTable();
|
|
}
|
|
if (ImGui::TreeNode(STR_C("More")))
|
|
{
|
|
ImGui::TextDisabled("%s", STR_C("Look of the tracks laid: empty, rails and trackbed as now"));
|
|
if (begin_fields("##setuplook", 0.3f))
|
|
{
|
|
changed |= texture_field("Rails##setuplook", "##setuprails", Setup.rails, "rail_screw_used1");
|
|
changed |= texture_field("Trackbed##setuplook", "##setupballast", Setup.ballast, "1435mm/tpbps-new2");
|
|
ImGui::EndTable();
|
|
}
|
|
ImGui::TreePop();
|
|
}
|
|
ImGui::PopID();
|
|
return changed;
|
|
}
|
|
|
|
} // namespace setup_ui
|