mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 06:59:13 +01:00
Merge remote-tracking branch 'origin/feat/switch-blades' into feat/renderers-cleanup
This commit is contained in:
@@ -58,11 +58,6 @@ bool rail(TTrack const &Track)
|
||||
return (Track.iCategoryFlag & 15) == kRailCategory && false == Track.m_editorremoved && Track.visible();
|
||||
}
|
||||
|
||||
std::string name_of(TTrack const &Track)
|
||||
{
|
||||
return Track.name().empty() ? std::string{STR_C("(no name)")} : Track.name();
|
||||
}
|
||||
|
||||
char const *type_of(TTrack const &Track)
|
||||
{
|
||||
switch (Track.eType)
|
||||
@@ -252,6 +247,7 @@ struct track_property
|
||||
char const *empty{nullptr}; // hint of an empty field
|
||||
std::vector<char const *> choices;
|
||||
std::function<bool(TTrack const &)> applies;
|
||||
bool off{false}; // the feature isn't in this build: the field is shown greyed and nothing changes it
|
||||
std::function<std::string(TTrack const &)> get;
|
||||
// false: the text doesn't fit the track or changes nothing, the track stays as it was
|
||||
std::function<bool(TTrack &, std::string const &)> set;
|
||||
@@ -465,7 +461,8 @@ std::vector<track_property> make_properties()
|
||||
{
|
||||
auto &property{add(list, "frogs", field::check, section::look, group::frogs, "Frog and check rails made from the rails", "Cuts the rails of the switch at its frog and lays wing rails and check rails.\nOff for a switch whose include has its own model of them")};
|
||||
property.rebuild = true;
|
||||
property.applies = [](TTrack const &Track) { return track_features::crossings && Track.eType == tt_Switch && Track.SwitchExtension != nullptr; };
|
||||
property.applies = [](TTrack const &Track) { return Track.eType == tt_Switch && Track.SwitchExtension != nullptr; };
|
||||
property.off = false == track_features::crossings;
|
||||
property.get = [](TTrack const &Track) { return std::string{Track.SwitchExtension->m_frogs ? "1" : "0"}; };
|
||||
property.set = [](TTrack &Track, std::string const &Text) {
|
||||
auto const frogs{Text == "1"};
|
||||
@@ -478,7 +475,8 @@ std::vector<track_property> make_properties()
|
||||
{
|
||||
auto &property{add(list, "movablenose", field::check, section::look, group::frogs, "Movable nose", "The nose of the frog moves with the blades over to the wing rail of the track set, leaving no gap; the frog has no check rails")};
|
||||
property.rebuild = true;
|
||||
property.applies = [](TTrack const &Track) { return track_features::crossings && Track.eType == tt_Switch && Track.SwitchExtension != nullptr; };
|
||||
property.applies = [](TTrack const &Track) { return Track.eType == tt_Switch && Track.SwitchExtension != nullptr; };
|
||||
property.off = false == track_features::crossings;
|
||||
property.get = [](TTrack const &Track) { return std::string{Track.SwitchExtension->m_movablenose ? "1" : "0"}; };
|
||||
property.set = [](TTrack &Track, std::string const &Text) {
|
||||
auto const movable{Text == "1"};
|
||||
@@ -633,7 +631,7 @@ std::vector<track_property> make_properties()
|
||||
{
|
||||
auto &property{add(list, "sleeperpack", field::choice, section::look_sleepers, group::sleepers, "Sleeper model from the pack", "Model of the sleepers of the track running alone, of the models of sleepers in the scenery data, laid as 3D sleepers\nin place of the one set with sleepers3dplain in eu07.ini. (as in eu07.ini): the one set there")};
|
||||
property.rebuild = true;
|
||||
property.applies = [](TTrack const &Track) { return track_features::sleepers && Track.m_visible; };
|
||||
property.off = false == track_features::sleepers;
|
||||
property.choices = choices(sleepermodels);
|
||||
property.get = [index_of](TTrack const &Track) { return std::to_string(Track.m_sleeper_enabled ? index_of(sleepermodels, Track.m_sleeper_model_name) : 0); };
|
||||
property.set = [](TTrack &Track, std::string const &Text) {
|
||||
@@ -651,7 +649,7 @@ std::vector<track_property> make_properties()
|
||||
{
|
||||
auto &property{add(list, "timbermodel", field::choice, section::look_sleepers, group::sleepers, "Timber model", "Model of the timbers under the switch or the crossing the track is part of, of the models of timbers in the scenery data,\nin place of the one set with sleepers3d in eu07.ini. It's put together from its submodels begin, main and end to the length of each timber")};
|
||||
property.rebuild = true;
|
||||
property.applies = [](TTrack const &Track) { return track_features::sleepers && Track.m_visible; };
|
||||
property.off = false == track_features::sleepers;
|
||||
property.choices = choices(timbermodels);
|
||||
property.get = [index_of](TTrack const &Track) { return std::to_string(index_of(timbermodels, Track.m_timber_model_name)); };
|
||||
property.set = [](TTrack &Track, std::string const &Text) {
|
||||
@@ -668,7 +666,7 @@ std::vector<track_property> make_properties()
|
||||
{
|
||||
auto &property{add(list, "timberskin", field::text, section::look_sleepers, group::sleepers, "Timber skin", "Replaceable skin of the timber model, empty: the one of the model")};
|
||||
property.rebuild = true;
|
||||
property.applies = [](TTrack const &Track) { return track_features::sleepers && Track.m_visible; };
|
||||
property.off = false == track_features::sleepers;
|
||||
property.empty = "of the model";
|
||||
property.get = [](TTrack const &Track) { return Track.m_timber_skin_name; };
|
||||
property.set = [](TTrack &Track, std::string const &Text) {
|
||||
@@ -806,7 +804,7 @@ std::vector<std::pair<std::string, std::string>> values_of_track(TTrack const &T
|
||||
{
|
||||
std::vector<std::pair<std::string, std::string>> values;
|
||||
for (auto const &property : properties())
|
||||
if (property.applies(Track))
|
||||
if (false == property.off && property.applies(Track))
|
||||
values.emplace_back(property.key, property.get(Track));
|
||||
return values;
|
||||
}
|
||||
@@ -940,7 +938,7 @@ std::size_t editor_mode::track_property_apply(int const Property, std::vector<TT
|
||||
auto const &property{properties()[Property]};
|
||||
std::vector<TTrack *> targets;
|
||||
for (auto *track : Tracks)
|
||||
if (track != nullptr && false == track->m_editorremoved && property.applies(*track))
|
||||
if (track != nullptr && false == property.off && false == track->m_editorremoved && property.applies(*track))
|
||||
targets.push_back(track);
|
||||
auto const changed{tracks_apply(targets, [&](TTrack &Track) { return property.set(Track, Text); }, property.rebuild, property.label)};
|
||||
if (changed == 0 && targets.size() == 1)
|
||||
@@ -1000,21 +998,28 @@ void editor_mode::track_textures_index()
|
||||
for (std::filesystem::recursive_directory_iterator entry{root, options, error}, end; false == static_cast<bool>(error) && entry != end; entry.increment(error))
|
||||
{
|
||||
std::error_code ignored;
|
||||
if (entry->is_directory(ignored))
|
||||
try
|
||||
{
|
||||
if (entry->is_directory(ignored))
|
||||
{
|
||||
// the normal maps go with their textures, not on a track by themselves
|
||||
if (lowered(entry->path().filename().string()) == "normals")
|
||||
entry.disable_recursion_pending();
|
||||
continue;
|
||||
}
|
||||
auto const extension{lowered(entry->path().extension().string())};
|
||||
auto const material{extension == ".mat"};
|
||||
if (false == material && false == texture_extension(extension))
|
||||
continue;
|
||||
auto path{entry->path().lexically_relative(root)};
|
||||
path.replace_extension();
|
||||
auto &known{found[path.generic_string()]};
|
||||
known = known || material;
|
||||
}
|
||||
catch (std::exception const &)
|
||||
{
|
||||
// the normal maps go with their textures, not on a track by themselves
|
||||
if (lowered(entry->path().filename().string()) == "normals")
|
||||
entry.disable_recursion_pending();
|
||||
continue;
|
||||
}
|
||||
auto const extension{lowered(entry->path().extension().string())};
|
||||
auto const material{extension == ".mat"};
|
||||
if (false == material && false == texture_extension(extension))
|
||||
continue;
|
||||
auto path{entry->path().lexically_relative(root)};
|
||||
path.replace_extension();
|
||||
auto &known{found[path.generic_string()]};
|
||||
known = known || material;
|
||||
}
|
||||
m_track_texture_index.clear();
|
||||
m_track_texture_index.reserve(found.size());
|
||||
@@ -1397,6 +1402,7 @@ void editor_mode::render_track_properties(std::vector<TTrack *> const &Tracks)
|
||||
if (list[i].part != Part || list[i].more != More || cache.applies[i] == 0)
|
||||
continue;
|
||||
ImGui::PushID(list[i].key);
|
||||
ImGui::BeginDisabled(list[i].off);
|
||||
row_label(i);
|
||||
switch (list[i].kind)
|
||||
{
|
||||
@@ -1406,6 +1412,9 @@ void editor_mode::render_track_properties(std::vector<TTrack *> const &Tracks)
|
||||
case field::slider: slider_row(i); break;
|
||||
default: text_row(i); break;
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
if (list[i].off && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
||||
ImGui::SetTooltip("%s", STR_C("Switched off in this build of the simulator"));
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndTable();
|
||||
@@ -1484,7 +1493,7 @@ std::optional<std::size_t> editor_mode::apply_track_values(std::vector<std::pair
|
||||
if (index < 0)
|
||||
continue;
|
||||
auto const &property{list[index]};
|
||||
if (property.late != late || false == Groups[property.group])
|
||||
if (property.off || property.late != late || false == Groups[property.group])
|
||||
continue;
|
||||
pasted.emplace_back(&property, value);
|
||||
rebuild |= property.rebuild;
|
||||
|
||||
Reference in New Issue
Block a user