From cd20d8ec94510b107c3cb6d3ca129fcf70085092 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:08:36 +0100 Subject: [PATCH] feat(editor): the first steps in the inspector, one way to start, the line laid summed up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first steps of the editor, after the first-run pass at 1920x1080 and 1366x768 (P1 of the plan of the editor's interface): - The tutorial no longer opens by itself as a window over the middle of the view (at 1366x768 over all of it, its close button under the tool row). With nothing selected, the inspector shows a compact "First steps" card: the lesson of the tool in use, its steps to try ticked as they're reached, the links "Show the lesson", "The camera" (the first lesson) and "Hide" (the setting first_steps, which the checkbox of the window now names "Show the first steps in the inspector"). Opened, the window of the lesson goes into the corner of the view by the inspector, below the rows of the menu and the tools; moved, it stays between them and the status line, as high as that room at most, the lesson scrolled inside. Its close button is always within reach. - The lesson follows the tool: the select tool of Tracks opens "Laying track" until its steps are done, so a new scenery opened in Tracks starts there, not with the camera, which stays the first page and a link of the card. - An empty scenery in Tracks with nothing selected: "The scenery has no tracks yet" and one highlighted button, "Lay the first track (L)"; the tutorial is the card under it, a "Tutorial" link when the card is hidden. With tracks, the select tool keeps its hints and a plain "Lay a track (L)". - "Without terrain", the answer to the question of the terrain at the first L, turns off the terrain made of the terrain model by itself: under the tracks as they're laid (the checkbox of the layers) and around the camera within the download area (the checkbox of the terrain panel), stops putting the squares of the area into the cache, a square on its way giving way at once, and drops the squares waiting. Kept on, the model went on being asked for, and offline the log filled with "NMT square ... not fetched: WinHTTP error"; now nothing is asked for after the answer. "Load the terrain" turns both on again. The squares of the area go to the cache, and the aerial photos ask for the model to lie on, only while some terrain is made of the model by itself. The question stands in the middle of the view, the window of the lesson waiting meanwhile. The warning of no ground under the mouse shows only while the pointer is over the view and the terrain is to be there. - The tooltip of the line being laid names the panel the rest of its warnings are in ("listed in the tool options"): the translation of the text before said "in the panel on the right", the panel is on the left. - While the pointer is over a panel, the line being laid stays as it was: the point of the cursor, the free end it snaps to and its height aren't taken from where the pointer is under the panel, which added a leg there with curves and warnings of its own. A drag begun in the view goes on over a panel. - After Enter the inspector sums up the line laid: its tracks, length and curves, those below the norms in orange, and what comes next, "A switch (T)" and "Save (Ctrl+S)". It stays while the last track is the selection the laying left; a click on a track shows the sheet of that track. The switch tool with nothing clicked shows the same, not the sheet of the last track laid. - A switch the switch tool refuses is told in its panel and by the cursor, no longer in the status line and the layers window as well, where it stayed after the next switch was laid. Why a branch couldn't lead into a free end goes into the panel with the rest; a switch laid takes the note by the cursor away. - The panel of the lay tool fits one screen at 1366x768: what the tool is for is the tooltip of the title of its card, the paragraph of the radius at the bends the tooltip of its "?" (which still opens the lesson), "This speed also on from a track with a speed of its own" is under More settings; the mode, the speed and the height stay up front. - The layout made on the first start: the side columns 22% of the width, at least 300 px, at most the 400 and 460 px they had and 30%; at 1366 px the view has about 766 px instead of 557. The tool options take 60% of the left column, and in a window under 800 px high the layers are a tab beside them, the tool options shown, so the panel of a tool has the whole column. The line of the keys of the surroundings goes on under itself at the edge of the panel. Layouts kept in imgui.ini are left as they are. - The names of the period of the day, the season and the weather in Weather and time, and the type of a node in the inspector of the surroundings, go through the translations ("(day)", "(autumn)", "(scattered)", "Typ: track" before). The degree sign of the air temperature is written as its UTF-8 bytes: CMakeLists.txt sets COMPILE_OPTIONS of eu07 and eu07_core after add_compile_options("/utf-8"), which drops /utf-8, so MSVC writes the "°" of a literal as the single byte 0xB0 of the ANSI code page, not UTF-8, and ImGui drew '?'. - Self-tests: the expectations statuslacks, refusal, statusline, laycursor and terrain, the command nmtquestion, and the cases fs_1_preview_over_panel, fs_2_switch_refusal_cleared and fs_3_without_terrain. lang/editor_pl.po: the Polish of the new texts (the card of the first steps, the summary of the line laid, "Lay the first track", the names of the periods, seasons and weathers and of the node types), the entries of the texts replaced given their new English ("Show the first steps in the inspector", "and %zu more, listed in the tool options", "Lay the first track (L)" in place of "Or start with:"), and "(do transmisji)" in place of the English "(stream)" of the drawn cursor. --- application/editormode.cpp | 196 ++++++++++++++++-- application/editormode.h | 35 +++- application/editormodelay.cpp | 93 +++++++-- application/editormodenmt.cpp | 45 +++- application/editormodeselftest.cpp | 8 + application/editormodeselftestexpect.cpp | 98 ++++++++- application/editormodeselftestterrain.cpp | 25 +++ application/editormodeswitchplace.cpp | 36 ++-- application/editormodetrack.cpp | 79 +++++-- application/editormodetrackprops.cpp | 1 + application/editoruilayer.cpp | 40 +++- application/editoruilayer.h | 12 ++ application/editoruipanels.cpp | 19 +- editor/editorNmt.cpp | 13 +- lang/editor_pl.po | 128 +++++++++++- tests/editor/README.md | 13 ++ .../editor/cases/fs_1_preview_over_panel.txt | 23 ++ .../cases/fs_2_switch_refusal_cleared.txt | 16 ++ tests/editor/cases/fs_3_without_terrain.txt | 20 ++ 19 files changed, 810 insertions(+), 90 deletions(-) create mode 100644 tests/editor/cases/fs_1_preview_over_panel.txt create mode 100644 tests/editor/cases/fs_2_switch_refusal_cleared.txt create mode 100644 tests/editor/cases/fs_3_without_terrain.txt diff --git a/application/editormode.cpp b/application/editormode.cpp index 863d9cc9c..ad505486c 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -559,6 +559,12 @@ editor_mode::editor_mode() { ui()->set_workspace_options(editor_ui::workspace::roads, [this]() { render_road_tool_options(); }, [this]() { render_road_selection(); }); ui()->set_workspace_options(editor_ui::workspace::terrain, [this]() { render_terrain_tool_options(); }); ui()->set_workspace_bank(editor_ui::workspace::terrain, [this]() { render_texture_browser(); }, STR("Textures")); + // the first steps on top of the inspector of the surroundings, the roads and the terrain, with nothing selected there; the + // tracks draw them with their own selection + ui()->set_first_steps([this]() { + if (m_node == nullptr && m_roadtool.marker == nullptr && m_roadtool.points.empty()) + render_first_steps_card(); + }); // a node picked in the scene window is selected as if clicked in the view; a double click flies the camera to it ui()->set_scene_select([this](scene::basic_node *Node, bool const Focus) { if (Focus) @@ -609,8 +615,9 @@ void editor_mode::ground_sources(editor_orthophoto &Layer) Layer.guess_source([this](double const X, double const Z, double &Height) { if (nmt_ground(X, Z, Height)) return true; - // asked for, the tile goes onto it once it comes - if (m_nmt.placed()) + // asked for, the tile goes onto it once it comes; not where no terrain is to be made of the model, as after the answer without + // terrain + if (m_nmt.placed() && (m_nmt_state.grow || EditorSettings.terrain_model().area)) m_nmt.request({X - 1.0, Z - 1.0}, {X + 1.0, Z + 1.0}); return false; }); @@ -1054,6 +1061,13 @@ std::string editor_mode::refused(std::string Text) return Text; } +std::string editor_mode::switch_refused(std::string Text) +{ + // not in the status line as well: told there, it stayed after the next switch was laid + ui()->set_refusal(Text); + return Text; +} + void editor_mode::drop_step(std::size_t const Step) { if (Step == 0 || m_history.size() != Step) @@ -4298,6 +4312,33 @@ void editor_mode::render_view_menu() ImGui::EndMenu(); } +namespace +{ + +// the name of the period of the day, of the season or of the weather as the environment keeps it, translated; it ends with a colon, +// being a key of other lookups. One not known is shown as it is, without the colon +std::string environment_name(std::string_view const Key) +{ + static std::array, 12> const names{{{"day:", STRN("day")}, + {"night:", STRN("night")}, + {"winter:", STRN("winter")}, + {"spring:", STRN("spring")}, + {"summer:", STRN("summer")}, + {"autumn:", STRN("autumn")}, + {"clear:", STRN("clear")}, + {"scattered:", STRN("scattered")}, + {"broken:", STRN("broken")}, + {"overcast:", STRN("overcast")}, + {"rain:", STRN("rain")}, + {"snow:", STRN("snow")}}}; + for (auto const &[key, text] : names) + if (key == Key) + return STR_C(text); + return std::string{Key.ends_with(':') ? Key.substr(0, Key.size() - 1) : Key}; +} + +} // namespace + void editor_mode::render_environment_window() { if (false == m_environment_open) @@ -4317,19 +4358,13 @@ void editor_mode::render_environment_window() } simulation::Environment.update_moon(); }; - // the names of the period, season and weather end with a colon, being keys of other lookups - auto const name = [](std::string Text) { - if (false == Text.empty() && Text.back() == ':') - Text.pop_back(); - return Text; - }; auto const &time{simulation::Time.data()}; auto minute{time.wHour * 60 + time.wMinute}; - auto const clock{format("%02d:%02d (%s)", time.wHour, time.wMinute, name(Global.Period).c_str())}; + auto const clock{format("%02d:%02d (%s)", time.wHour, time.wMinute, environment_name(Global.Period).c_str())}; if (ImGui::SliderInt((std::string(STR_C("Time of day")) + "###timeofday").c_str(), &minute, 0, 1439, clock.c_str())) set_date_time(static_cast(std::round(Global.fMoveLight)), std::clamp(minute, 0, 1439)); auto yearday{Global.fMoveLight}; - auto const day{format("%.0f (%s)", Global.fMoveLight, name(Global.Season).c_str())}; + auto const day{format("%.0f (%s)", Global.fMoveLight, environment_name(Global.Season).c_str())}; if (ImGui::SliderFloat((std::string(STR_C("Day of the year")) + "###dayofyear").c_str(), &yearday, 0.0f, 364.0f, day.c_str())) set_date_time(static_cast(std::round(std::clamp(yearday, 0.0f, 365.0f))), time.wHour * 60 + time.wMinute); ImGui::Separator(); @@ -4341,7 +4376,7 @@ void editor_mode::render_environment_window() simulation::Environment.compute_weather(); } auto overcast{Global.Overcast}; - auto const clouds{format("%.2f (%s)", Global.Overcast, name(Global.Weather).c_str())}; + auto const clouds{format("%.2f (%s)", Global.Overcast, environment_name(Global.Weather).c_str())}; if (ImGui::SliderFloat((std::string(STR_C("Clouds")) + "###overcast").c_str(), &overcast, 0.0f, 2.0f, clouds.c_str())) { Global.Overcast = std::clamp(overcast, 0.0f, 2.0f); @@ -4350,7 +4385,8 @@ void editor_mode::render_environment_window() if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", STR_C("Up to 1 the sky clouds over, past it rain or snow falls, by the air temperature")); auto temperature{Global.AirTemperature}; - auto const air{format("%.1f °C", Global.AirTemperature)}; + // the degree sign as UTF-8 bytes: the literal itself goes into the build in the ANSI code page, which ImGui shows as '?' + auto const air{format("%.1f \xc2\xb0" "C", Global.AirTemperature)}; if (ImGui::SliderFloat((std::string(STR_C("Air temperature")) + "###airtemperature").c_str(), &temperature, -35.0f, 40.0f, air.c_str())) { Global.AirTemperature = std::clamp(temperature, -35.0f, 40.0f); @@ -6057,6 +6093,9 @@ char const *editor_mode::tutorial_of_tool() case track_tab::station_signals: case track_tab::line_block: return undone({"A whole line, step by step"}); + case track_tab::path: + // a scenery opened in Tracks starts with laying a track, not with the camera, the first lesson + return undone({"Laying track"}); default: return ""; } @@ -6083,8 +6122,12 @@ void editor_mode::follow_tutorial() } m_tutorial_page = std::clamp(m_tutorial_page, 0, static_cast(lessons.size()) - 1); auto const &lesson{lessons[m_tutorial_page]}; - if (lesson.clip == nullptr) - m_tutorial_clip.close(); + // the clip only for the window of the lesson; the card of the first steps has none + if (lesson.clip == nullptr || false == m_first_steps_open) + { + if (false == m_tutorial_clip.path().empty()) + m_tutorial_clip.close(); + } else if (auto const path{std::string{"lang/editor_tutorial/"} + lesson.clip + ".gif"}; path != m_tutorial_clip.path()) { m_tutorial_clip.open(path); @@ -6092,23 +6135,62 @@ void editor_mode::follow_tutorial() } } +namespace +{ + +// a window kept in the room between the rows of the menu and the tools and the status line: not under them, where its title bar +// with the close button was out of reach, nor past the edge of the screen. A docked one is left where its dock is +void keep_in_work_area(char const *Name) +{ + auto const *window{ImGui::FindWindowByName(Name)}; + if (window == nullptr || window->DockIsActive) + return; + auto const *viewport{ImGui::GetMainViewport()}; + auto const low{viewport->WorkPos}; + ImVec2 const high{low.x + viewport->WorkSize.x, low.y + viewport->WorkSize.y}; + ImVec2 position{window->Pos}; + position.x = std::max(low.x, std::min(position.x, high.x - window->Size.x)); + position.y = std::max(low.y, std::min(position.y, high.y - window->Size.y)); + if (position.x != window->Pos.x || position.y != window->Pos.y) + ImGui::SetNextWindowPos(position); +} + +} // namespace + void editor_mode::render_first_steps() { - if (false == m_first_steps_open) + // the card of the first steps in the inspector follows the lesson of the tool as the window does, with the window closed too + if (false == m_first_steps_open && false == EditorSettings.first_steps()) { + m_first_steps_shown = 0; if (false == m_tutorial_clip.path().empty()) m_tutorial_clip.close(); return; } note_first_steps(); follow_tutorial(); + // the question of the terrain of a new scenery isn't drawn over the window: the window waits for the answer + if (false == m_first_steps_open || m_nmt_state.prompt) + { + m_first_steps_shown = 0; + return; + } auto const &lessons{tutorial_lessons()}; auto const &lesson{lessons[m_tutorial_page]}; auto const scale{Global.ui_scale}; - ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * 0.5f, ImGui::GetIO().DisplaySize.y * 0.5f), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f)); + auto const *viewport{ImGui::GetMainViewport()}; + // opened, it goes into the corner of the view by the inspector, below the rows of the tools, for its first frames, as its size + // comes after it's drawn once (placed by the size it had then, it lay over the panels); moved, it stays between the rows and the + // status line. It's as high as the room there at most, its lesson scrolled inside + auto const pad{std::round(8.0f * scale)}; + auto const *window{ImGui::FindWindowByName("###tutorial")}; + if (m_first_steps_shown < 3 && (window == nullptr || false == window->DockIsActive)) + ImGui::SetNextWindowPos(ImVec2(editor_ui::view_max().x - pad, viewport->WorkPos.y + pad), ImGuiCond_Always, ImVec2(1.0f, 0.0f)); + else + keep_in_work_area("###tutorial"); + m_first_steps_shown = std::min(m_first_steps_shown + 1, 3); ImGui::SetNextWindowBgAlpha(1.0f); - ImGui::SetNextWindowSizeConstraints(ImVec2(0.0f, 0.0f), ImVec2(FLT_MAX, ImGui::GetIO().DisplaySize.y - 60.0f)); - keep_on_screen("###tutorial"); + ImGui::SetNextWindowSizeConstraints(ImVec2(0.0f, 0.0f), ImVec2(FLT_MAX, std::max(100.0f, viewport->WorkSize.y - 2.0f * pad))); if (ImGui::Begin((std::string(STR_C("Tutorial")) + "###tutorial").c_str(), &m_first_steps_open, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize)) { // floating it's as wide as the clips; docked it takes the width of its dock, the texts wrapped to it @@ -6169,6 +6251,12 @@ void editor_mode::render_tutorial_goals(tutorial_lesson const &Lesson) tutorial_input(entry.keys, entry.text, 150.0f * Global.ui_scale); if (false == Lesson.goals.empty()) ImGui::SeparatorText(STR_C("Try it")); + render_tutorial_steps(Lesson); + render_ground_warning(Lesson); +} + +void editor_mode::render_tutorial_steps(tutorial_lesson const &Lesson) +{ for (auto const &entry : Lesson.goals) { bool const reached{m_first_steps_done[static_cast(entry.step)]}; @@ -6179,10 +6267,75 @@ void editor_mode::render_tutorial_goals(tutorial_lesson const &Lesson) else ImGui::TextWrapped("%s", STR_C(entry.text)); } - if (Lesson.action == tutorial_lesson::trial::lay && ui()->mode() == nodebank_panel::TRACK && false == GfxRenderer->Mouse_Hit()) +} + +void editor_mode::render_ground_warning(tutorial_lesson const &Lesson) +{ + // over a panel the pointer is over no ground, and in a scenery laid without terrain no ground is to be there + if (Lesson.action != tutorial_lesson::trial::lay || ui()->mode() != nodebank_panel::TRACK || ImGui::GetIO().WantCaptureMouse || false == ImGui::IsMousePosValid()) + return; + auto const expected{m_streamer.resident() > 0 || ((m_nmt_state.grow || EditorSettings.terrain_model().area) && m_nmt.placed())}; + if (expected && false == GfxRenderer->Mouse_Hit()) ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", STR_C("There is no ground under the mouse: the track will lie flat at height 0. Real ground: F5")); } +bool editor_mode::render_first_steps_card() +{ + if (false == EditorSettings.first_steps() || m_first_steps_open) + return false; + auto const &lessons{tutorial_lessons()}; + auto const page{std::clamp(m_tutorial_page, 0, static_cast(lessons.size()) - 1)}; + auto const &lesson{lessons[page]}; + auto const font{ImGui::GetFontSize()}; + ImGui::Spacing(); + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_FrameBg)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(std::round(font * 0.6f), std::round(font * 0.5f))); + if (ImGui::BeginChild("##firststeps", ImVec2(0.0f, 0.0f), ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_AlwaysUseWindowPadding)) + { + ImGui::PushTextWrapPos(0.0f); + ImGui::TextUnformatted(STR_C("First steps")); + ImGui::SameLine(); + ImGui::TextDisabled(STR_C("Lesson %d of %d"), page + 1, static_cast(lessons.size())); + ImGui::TextColored(ImVec4(0.55f, 0.8f, 1.0f, 1.0f), "%s", STR_C(lesson.title)); + render_tutorial_steps(lesson); + render_ground_warning(lesson); + ImGui::PopTextWrapPos(); + ImGui::Spacing(); + if (ImGui::TextLink(STR_C("Show the lesson"))) + m_first_steps_open = true; + item_tooltip("The whole lesson in its window: a clip, the mouse and the keys, the lessons before and after"); + // a scenery opened in Tracks starts with laying a track: the camera, the first lesson, stays a click away + if (page != 0) + { + same_line_if_fits(STR_C("The camera")); + if (ImGui::TextLink(STR_C("The camera"))) + { + m_first_steps_open = true; + m_tutorial_goto = lessons.front().title; + } + item_tooltip("The lesson of the camera: looking around, flying, the view from above"); + } + // hidden for good, as the checkbox of the window of the lessons hides it + auto const *hide{STR_C("Hide")}; + ImGui::SameLine(); + auto const right{ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(hide).x}; + if (right > ImGui::GetCursorPosX()) + ImGui::SetCursorPosX(right); + else + ImGui::NewLine(); + if (ImGui::TextLink(hide)) + { + EditorSettings.first_steps(false); + EditorSettings.save(); + } + item_tooltip("Hides the first steps for good; Help > Tutorial opens the lessons, and its checkbox brings the first steps back"); + } + ImGui::EndChild(); + ImGui::PopStyleVar(); + ImGui::PopStyleColor(); + return true; +} + void editor_mode::render_tutorial_trial(tutorial_lesson const &Lesson) { using trial = tutorial_lesson::trial; @@ -6284,8 +6437,9 @@ void editor_mode::render_tutorial_pages() } else if (ImGui::Button(STR_C("Close"))) m_first_steps_open = false; + // the window doesn't open by itself any more: the first steps are the card in the inspector with nothing selected bool show{EditorSettings.first_steps()}; - if (ImGui::Checkbox(STR_C("Show when the editor opens"), &show)) + if (ImGui::Checkbox(STR_C("Show the first steps in the inspector"), &show)) { EditorSettings.first_steps(show); EditorSettings.save(); @@ -7082,7 +7236,7 @@ void editor_mode::enter() choose_work_area(work_area::tracks); WriteLog("Editor: camera over the origin of the empty scenery"); } - m_first_steps_open = EditorSettings.first_steps(); + // the window of the lessons isn't opened by itself over the view: the first steps are a card in the inspector } Global.ControlPicking = true; diff --git a/application/editormode.h b/application/editormode.h index d571fdcb7..986626f31 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -204,6 +204,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri void undo_one(); void drop_step(std::size_t const Step); std::string refused(std::string Text); + // a switch not laid: told in the panel of the switch tool, which shows the text returned, and by the cursor + std::string switch_refused(std::string Text); void redo_one(); // the changes of the heightmap terrain since the last step become a step of the history: a stroke of the brush, // or what a frame did; the next change is recorded from now on @@ -284,6 +286,13 @@ class editor_mode : public application_mode, private editor_track::observer, pri // a lesson is done once all its steps are bool tutorial_done(tutorial_lesson const &Lesson) const; void render_first_steps(); + // the first steps in the inspector with nothing selected: the lesson of the tool in use with its steps to try, the whole lesson + // in its window on request. false: hidden for good, or the window of the lesson is open + bool render_first_steps_card(); + // the steps to try of a lesson, ticked as they're reached + void render_tutorial_steps(tutorial_lesson const &Lesson); + // a track laid where there's no ground lies flat at the height 0: told while the pointer is over the view where the terrain is to be + void render_ground_warning(tutorial_lesson const &Lesson); // the steps reached by what the editor is doing now void note_first_steps(); // the lesson of the tool in use: the first of its lessons not done yet, or none @@ -298,7 +307,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri void render_tutorial_pages(); void first_step_done(first_step const Step) override; void open_kilometrage() override; - bool m_first_steps_open{false}; + bool m_first_steps_open{false}; // the window of the lesson + int m_first_steps_shown{0}; // frames the window of the lesson was drawn since it opened, up to 3: it's placed anew as it opens std::array(first_step::count)> m_first_steps_done{}; int m_tutorial_page{0}; char const *m_tutorial_goto{nullptr}; // the lesson of this title opened by a button of a panel @@ -645,6 +655,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri // the place picked in the terrain window: the terrain model and the orthophoto take it void nmt_place_scenery(glm::dvec2 const &Point); void nmt_accept_offer(); + // the answer without terrain: the tracks lie on the plane, nothing of the terrain model is loaded by itself any more, under the + // tracks laid nor around the camera + void nmt_decline_offer(); // the whole scenery: tracks, includes and models, moved up or down as one undo step std::size_t nmt_join_ends(); // the turntables as they lie, each with the ends of the tracks running up to it on its rim @@ -1882,8 +1895,25 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::string skew; // what Alt turned the straight to double escape_time{-100.0}; // when Esc was pressed over points not laid: the second Esc drops them std::size_t history{0}; // the step of the history the track laid last was begun at + // the line laid last, told in the inspector while the last of its tracks stays the selection the laying left + struct laid_curve + { + std::string label; + bool meets{true}; // the norms for the speed + }; + struct laid_line + { + std::vector tracks; + double length{0.0}; + std::vector curves; + }; + laid_line laid; }; lay_tool m_lay; + // the line laid last is told in the inspector in place of the sheet of its last track: that one is selected by the laying, not by + // a click + bool laid_shown() const; + void render_laid_summary(); alignment::limits laying_norms() const; glm::dvec3 lay_angle_snap(glm::dvec3 const &Mouse, std::string &Label) const; // the straight track Alt turns the laid straight to: the nearest one the straight from From to To crosses, or one along From @@ -2293,6 +2323,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri // the track tools in the tool options window, and the selected path in the inspector void render_track_tool_options(); void render_track_selection(); + // the inspector with no track selected: in an empty scenery the one thing to do first, the first steps of the tutorial under it + void render_track_nothing_selected(); void show_track_tab(track_tab const Wanted) override; bool track_analysis_tab() const { return m_track_tab == track_tab::profile || m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::norms || m_track_tab == track_tab::infra; } bool track_shortcut(int const Key); @@ -3176,6 +3208,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::string badge; // the mouse or the keys drawn over the view, for the clips of the tutorial glm::vec2 badge_at{0.0f}; // its bottom left corner, in the pixels of the window std::map marks; // the heights of the ends of tracks kept by mark, for expect lift + std::optional> terrain_kept; // the terrain made while laying and around the camera before nmtquestion }; selftest m_selftest; using selftest_result = editor_selftest_result; diff --git a/application/editormodelay.cpp b/application/editormodelay.cpp index aad3333b1..c73aa2e0e 100644 --- a/application/editormodelay.cpp +++ b/application/editormodelay.cpp @@ -14,6 +14,7 @@ http: #include "application/editoruilayer.h" #include "application/editorprojection.h" #include "application/editormodeshared.h" +#include "application/editorgestures.h" #include "editor/editorFormat.hpp" #include "editor/editorAlignmentStore.hpp" #include "editor/editorSwitchStore.hpp" @@ -145,7 +146,9 @@ void editor_mode::update_build_tools() m_join_radius = 0.0; m_join_variant = 0; }; - bool const pointing{m_cursor_override.has_value() || ImGui::IsMousePosValid()}; + // the pointer over a panel points at no ground: the line shown stays as it was, rather than gaining a leg to where the pointer + // is under the panel. A drag begun in the view goes on over a panel, the panel doesn't take the mouse then + bool const pointing{m_cursor_override.has_value() || (ImGui::IsMousePosValid() && false == ImGui::GetIO().WantCaptureMouse)}; if (m_extend.active) { if (pointing) @@ -189,12 +192,15 @@ void editor_mode::update_build_tools() if (pointing) lay.mouse = typed_lay(cursor_terrain(height)); auto const oncursor{lap()}; - lay.skew.clear(); - if (pointing && ImGui::GetIO().KeyAlt && m_typed.empty() && false == lay.points.empty()) - lay.mouse = lay_angle_snap(lay.mouse, lay.skew); - lay.mouse_snap = m_typed.empty() ? snap_free_end(lay.mouse, cursor, nullptr, kRailCategory, {}) : editor_track::find_free_end(nullptr, kRailCategory, lay.mouse, kLaySnapRadius, {}); + if (pointing) + { + lay.skew.clear(); + if (ImGui::GetIO().KeyAlt && m_typed.empty() && false == lay.points.empty()) + lay.mouse = lay_angle_snap(lay.mouse, lay.skew); + lay.mouse_snap = m_typed.empty() ? snap_free_end(lay.mouse, cursor, nullptr, kRailCategory, {}) : editor_track::find_free_end(nullptr, kRailCategory, lay.mouse, kLaySnapRadius, {}); + } auto const snapping{lap()}; - if (lay.mouse_snap.track == nullptr) + if (pointing && lay.mouse_snap.track == nullptr) lay.mouse = lay_bed(lay.mouse); auto const bedding{lap()}; if (false == m_extend.active) @@ -2113,6 +2119,11 @@ void editor_mode::lay_finish(editor_track::snap_target const &End) tool.status += "\n" + STR("The scenery isn't opened for editing: new track won't be saved"); m_node = created.back(); ui()->set_node(m_node); + // what was laid, told in the inspector as long as the last track stays selected + tool.laid = {created, length, {}}; + if (plan.shape.valid) + for (auto const &curve : plan.shape.curves) + tool.laid.curves.emplace_back(format("%d. %s", curve.vertex + 1, curve_label(curve, laying_norms()).c_str()), alignment::meets_norms(curve, plan.design)); if (nmt_fit_laid(tool.history, created.back()->m_paths.front().points[segment_data::point::end])) tool.status += "\n" + STR("The grade line of the whole track laid in a row fitted to the terrain model, as the tracks go onto the terrain"); m_nmt_state.laying = false; @@ -2357,10 +2368,16 @@ void editor_mode::render_lay_ui() m_first_steps_open = true; m_tutorial_goto = "Radius of the curves at the bends"; } - item_tooltip("What it is: the lesson of the tutorial"); - ImGui::PushTextWrapPos(0.0f); - ImGui::TextDisabled("%s", STR_C("The largest radius that fits between your points is taken: two transition curves meeting, with no cant, from 6000 m down to 2000 m, and below that an arc with the transitions and the cant of the norms")); - ImGui::PopTextWrapPos(); + // the explanation over the button: under it, it pushed the speed and the height out of the panel at 1366 x 768 + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(std::round(ImGui::GetFontSize() * 30.0f)); + ImGui::TextUnformatted(STR_C("The largest radius that fits between your points is taken: two transition curves meeting, with no cant, from 6000 m down to 2000 m, and below that an arc with the transitions and the cant of the norms")); + ImGui::TextDisabled("%s", STR_C("What it is: the lesson of the tutorial")); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } } else { @@ -2393,8 +2410,6 @@ void editor_mode::render_lay_ui() } value_chips("speeds", tool.style.velocity, {40.0, 60.0, 80.0, 100.0, 120.0, 160.0}, "%.0f"); tool.style.velocity = std::clamp(tool.style.velocity, 0.0, 400.0); - ImGui::Checkbox(STR_C("This speed also on from a track with a speed of its own"), &tool.own_speed); - item_tooltip("Off: a track laid on from another one, or joined to it, is designed for the speed of that track and takes it.\nOn: it's designed for the speed above and the new tracks get it.\nWhile laying: Ctrl+Shift+wheel"); if (auto const [from, to]{laying_ends()}; from != nullptr || to != nullptr) ImGui::TextDisabled("%s", design_speed_of(from, to).c_str()); ImGui::TextDisabled("%s", STR_C("Height of the track on the ground")); @@ -2442,6 +2457,8 @@ void editor_mode::render_lay_ui() render_lay_status(); return; } + ImGui::Checkbox(STR_C("This speed also on from a track with a speed of its own"), &tool.own_speed); + item_tooltip("Off: a track laid on from another one, or joined to it, is designed for the speed of that track and takes it.\nOn: it's designed for the speed above and the new tracks get it.\nWhile laying: Ctrl+Shift+wheel"); ImGui::TextDisabled("%s", STR_C("Dragged from a free end, or laid from a point to one")); if (begin_fields("##layradius")) { @@ -2529,3 +2546,55 @@ void editor_mode::render_lay_status() if (false == tool.status.empty()) ImGui::TextWrapped("%s", tool.status.c_str()); } + +bool editor_mode::laid_shown() const +{ + auto const &tracks{m_lay.laid.tracks}; + return false == tracks.empty() && m_node == tracks.back() && m_track_set.empty() && std::ranges::none_of(tracks, [](TTrack const *Track) { return Track->m_editorremoved; }); +} + +void editor_mode::render_laid_summary() +{ + auto const &laid{m_lay.laid}; + auto const below{std::ranges::any_of(laid.curves, [](lay_tool::laid_curve const &Curve) { return false == Curve.meets; })}; + auto const warning{ImVec4(1.0f, 0.55f, 0.15f, 1.0f)}; + ImGui::TextUnformatted(STR_C("Track laid")); + metric_tiles({{format("%zu", laid.tracks.size()), STR_C("tracks"), ImGui::GetColorU32(ImGuiCol_Text)}, + {format("%.0f m", laid.length), STR_C("length"), ImGui::GetColorU32(ImGuiCol_Text)}, + {format("%zu", laid.curves.size()), STR_C("curves"), below ? ImGui::GetColorU32(warning) : ImGui::GetColorU32(ImGuiCol_Text)}}); + if (false == laid.curves.empty()) + { + ImGui::PushTextWrapPos(0.0f); + ImGui::TextDisabled("%s", STR_C("R: radius, L: transition curve (m), h: cant (mm)")); + for (auto const &curve : laid.curves) + { + if (curve.meets) + ImGui::TextUnformatted(curve.label.c_str()); + else + ImGui::TextColored(warning, "%s", curve.label.c_str()); + } + if (below) + ImGui::TextColored(warning, "%s", STR_C("Orange: below the norms for the speed, laid all the same")); + ImGui::PopTextWrapPos(); + } + // what comes next: a switch into the line and the scenery saved + ImGui::SeparatorText(STR_C("Next")); + if (m_track_tab != track_tab::turnout) + { + if (ImGui::Button(STR_C("A switch (T)"))) + show_track_tab(track_tab::turnout); + item_tooltip("The switch tool: press on a straight and drag along it and to the side"); + ImGui::SameLine(); + } + ImGui::BeginDisabled(scene::Layers.empty()); + if (ImGui::Button(STR_C("Save (Ctrl+S)"))) + save(); + ImGui::EndDisabled(); + ImGui::Spacing(); + if (m_track_tab == track_tab::lay) + gesture_rows({{"LMB on a free end", "lays the track on from it"}, {"Esc", "stop laying"}}); + else if (m_track_tab == track_tab::turnout) + gesture_rows({{"Drag on a track", "along: the direction, sideways: the side"}, {"LMB on a track", "its properties show here"}}); + else + gesture_rows({{"LMB on a track", "its properties show here"}}); +} diff --git a/application/editormodenmt.cpp b/application/editormodenmt.cpp index 13465a006..56e450f3f 100644 --- a/application/editormodenmt.cpp +++ b/application/editormodenmt.cpp @@ -1215,7 +1215,10 @@ void editor_mode::nmt_update() if (auto const &wanted{m_orthophoto.area()}; wanted != m_nmt_prefetched) { m_nmt_prefetched = wanted; - m_nmt.prefetch(wanted); + // unless no terrain is made of the model by itself, as after the answer without terrain: what the terrain panel asks for then is + // downloaded as it's asked for + if (state.grow || EditorSettings.terrain_model().area) + m_nmt.prefetch(wanted); // the terrain around the camera looked at again within the new area m_area_terrain.listed = false; m_area_terrain.empty.clear(); @@ -2596,16 +2599,50 @@ void editor_mode::nmt_accept_offer() state.offset = 0.0; nmt_make(nmt_keys_around()); state.prompt = false; + // the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also after the other answer was + // given for a scenery before; the model of the download area is put into the cache again if that answer stopped it + state.grow = true; + EditorSettings.terrain_while_laying(true); + EditorSettings.terrain_model().area = true; + EditorSettings.save(); + if (m_nmt.prefetched().total == 0 && false == m_nmt_prefetched.empty()) + m_nmt.prefetch(m_nmt_prefetched); +} + +void editor_mode::nmt_decline_offer() +{ + auto &state{m_nmt_state}; + state.prompt = false; + // nothing of the model loaded any more: not under the tracks as they're laid, as the checkbox of the layers turns it off, nor around + // the camera within the download area, as the checkbox of the terrain panel does, nor the squares of the download area into the + // cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log + state.grow = false; + EditorSettings.terrain_while_laying(false); + EditorSettings.terrain_model().area = false; + EditorSettings.save(); + m_nmt.prefetch({}); + // nor the squares asked for meanwhile, as the aerial photos asked for them to lie on + m_nmt.cancel(); } void editor_mode::render_nmt_prompt() { auto &state{m_nmt_state}; - if (false == state.prompt) - return; char const *const title{STR_C("Terrain for the new scenery###nmtoffer")}; + if (false == state.prompt) + { + // answered by the self-test, not by a card of its own: the question is closed, or it would hold the input as a modal + if (ImGui::IsPopupOpen(title) && ImGui::BeginPopupModal(title, nullptr, ImGuiWindowFlags_NoResize)) + { + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + } + return; + } if (false == ImGui::IsPopupOpen(title)) ImGui::OpenPopup(title); + // in the middle of the view, not of the screen with the docks; the window of the lesson waits meanwhile, not to lie under it + ImGui::SetNextWindowPos(ImVec2((editor_ui::view_min().x + editor_ui::view_max().x) * 0.5f, (editor_ui::view_min().y + editor_ui::view_max().y) * 0.5f), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowSize(ImVec2(520.0f * Global.ui_scale, 0.0f)); if (false == ImGui::BeginPopupModal(title, nullptr, ImGuiWindowFlags_NoResize)) return; @@ -2627,7 +2664,7 @@ void editor_mode::render_nmt_prompt() ImGui::SameLine(0.0f, gap); if (ground_card("##flat", STR_C("Without terrain"), STR_C("The tracks lie on the flat plane at the height 0; the terrain can be loaded later in Terrain (F5)"), false, true, width)) { - state.prompt = false; + nmt_decline_offer(); ImGui::CloseCurrentPopup(); } ImGui::Spacing(); diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index 8cac340c5..a6b42dec4 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -193,6 +193,8 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // turntables the height of each turntable and of the model in its pit, and the heights of the tracks running up // to it out along their lines from the rim, against the model there // nmtstate logs how far the tracks going onto the terrain model are +// nmtquestion the question of the terrain of a new scenery opened, or answered without terrain as its card does; +// restore: the settings of the terrain made by itself put back as they were before that answer // gradelines the grade line each track shares written to the file, for a map of them // fitreport to the file: the tracks off the terrain model, the switches off their plane, the rails on common timbers apart in height // gradeline the common grade line of the route open in the profile tool: its design lifted and applied, the route taken off it and back @@ -232,6 +234,12 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // expect lift