18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 03:37:09 +01:00

feat(editor): the first steps in the inspector, one way to start, the line laid summed up

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.
This commit is contained in:
maj00r
2026-11-23 12:08:36 +01:00
parent a1f1ba4262
commit cd20d8ec94
19 changed files with 810 additions and 90 deletions
+175 -21
View File
@@ -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<std::pair<std::string_view, char const *>, 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<int>(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<int>(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<int>(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<std::size_t>(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<int>(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<int>(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;