mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 02:42:46 +01:00
feat(editor): the EU07M models as a field of work of their own, made for those who don't know the format
The window of an EU07M model becomes the field of work "Models" (F7) beside the surroundings, the tracks, the roads, the terrain and the catenary. The node bank says what is edited and lists the vehicles, the tool options hold the page of the tool chosen in the toolbar (Lights, Parts of the vehicle, All parts, Animations), and the inspector the settings of the part picked, in plain words; the fields of the format are kept under Advanced. - A click on the model picks its part (the smallest box of geometry of a part shown holding the point); a light is added where the model is clicked, a spot shining towards the camera. - A light which nothing else points at is taken out (eu07m::node_removable / remove_node, with TModel3d::UnlinkEditorSubmodel / LinkEditorSubmodel on the model the game has). - Ctrl+Z / Ctrl+Y take the changes of the model back and make them again, a light added or taken out among them; another model asked for with changes not saved asks first. - "Import to EU07M" writes <model>.eu07m beside the .e3d or .t3d of a model without one, made of the model as the game loaded it (eu07m::import_model), so a lamp post or a cab gets its lights here. - "Put a model in the scenery" puts a model of the folder of the models in front of the camera, "Whole model" moves the scenery model with the gizmo of the editor, "Put a vehicle on a track..." opens the Trainset tool. - The inspector of a scenery model with an .eu07m file offers "Edit this model (F7)"; the floating window is gone. - Review: the model is written to its .tmp, closed and checked before it replaces the file, and a failed .tmp is removed; play_clip counts From only for a positive pace again, so a pace of 0 holds the clip and a negative one runs it backwards. New icons at the end of editor_icons.png (the cells before them are unchanged), the strings in lang/editor_pl.po, new self-test commands (modelmode, modeltool, modeladdlight, modelundo, modelredo, modelremove, modelplace, modelimport) and unit tests of remove_node. No asset in the SVN is needed or changed; the import writes an .eu07m file into the game data only when the user asks for it.
This commit is contained in:
@@ -562,6 +562,17 @@ 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"));
|
||||
ui()->set_workspace_options(editor_ui::workspace::models, [this]() { ui()->model_panel().render_tools(); }, [this]() { ui()->model_panel().render_selection(); });
|
||||
ui()->set_workspace_bank(editor_ui::workspace::models, [this]() { ui()->model_panel().render_bank(); }, STR("Model"));
|
||||
ui()->set_edit_model([this]() { choose_work_area(work_area::models); });
|
||||
ui()->model_panel().place_model = [this](std::string const &File) { place_model_file(File); };
|
||||
ui()->model_panel().place_vehicle = [this]() {
|
||||
// the Trainset tool of the tracks: a click on a track, the vehicle picked, Place
|
||||
choose_work_area(work_area::tracks);
|
||||
show_track_tab(track_tab::lineside);
|
||||
m_vehicle.tab().expand = true;
|
||||
ui()->set_status(STR("Click a track, pick the vehicle and Place it; F7 goes back to the models"));
|
||||
};
|
||||
// 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)
|
||||
@@ -1733,7 +1744,13 @@ bool editor_mode::update()
|
||||
update_road_tool();
|
||||
draw_road_overlay();
|
||||
// the roads and the terrain are fields of work, their tools are drawn in the tool options window in place of the edit mode ones
|
||||
ui()->set_workspace(m_terrain_open ? editor_ui::workspace::terrain : m_roadtool.window ? editor_ui::workspace::roads : editor_ui::workspace::none);
|
||||
ui()->set_workspace([this]() {
|
||||
if (m_models_open)
|
||||
return editor_ui::workspace::models;
|
||||
if (m_terrain_open)
|
||||
return editor_ui::workspace::terrain;
|
||||
return m_roadtool.window ? editor_ui::workspace::roads : editor_ui::workspace::none;
|
||||
}());
|
||||
|
||||
steps.step("roads");
|
||||
// --- array: the one made last is kept in line with its settings ---
|
||||
@@ -4811,6 +4828,8 @@ void editor_mode::render_open_scenery_popup()
|
||||
void editor_mode::terrain_workspace(bool const Open)
|
||||
{
|
||||
m_terrain_open = Open;
|
||||
if (Open)
|
||||
m_models_open = false;
|
||||
if (false == Open)
|
||||
m_terrain_tool = terrain_tool::none;
|
||||
else if (m_streamer.active())
|
||||
@@ -5797,8 +5816,9 @@ void editor_mode::render_array()
|
||||
|
||||
void editor_mode::choose_edit_mode(nodebank_panel::edit_mode const Mode)
|
||||
{
|
||||
// an edit mode is the field of work instead of the tracks, roads or terrain
|
||||
// an edit mode is the field of work instead of the tracks, roads, terrain or models
|
||||
m_track_window_open = false;
|
||||
m_models_open = false;
|
||||
m_roadtool.window = false;
|
||||
terrain_workspace(false);
|
||||
if (Mode != nodebank_panel::MODIFY)
|
||||
@@ -5806,8 +5826,32 @@ void editor_mode::choose_edit_mode(nodebank_panel::edit_mode const Mode)
|
||||
ui()->set_mode(Mode);
|
||||
}
|
||||
|
||||
void editor_mode::place_model_file(std::string const &File)
|
||||
{
|
||||
// on the ground some way ahead of the camera, as far as Insert would put it by a click there
|
||||
auto const view{GfxRenderer->Camera_View_Matrix()};
|
||||
glm::dvec3 ahead{-view[0][2], 0.0, -view[2][2]};
|
||||
ahead = glm::length(ahead) > 1e-6 ? glm::normalize(ahead) : glm::dvec3{0.0, 0.0, 1.0};
|
||||
auto const where{placement_on_ground(Camera.Pos + ahead * 12.0)};
|
||||
auto *placed{simulation::State.create_model("node -1 0 none model 0 0 0 0 " + File + " none endmodel", "editor_", where)};
|
||||
if (placed == nullptr)
|
||||
{
|
||||
ui()->set_status(format(STR_C("The model %s couldn't be put in, the log says why"), File.c_str()), true);
|
||||
return;
|
||||
}
|
||||
placed->m_name = "editor_" + placed->uuid.to_string();
|
||||
std::string as_text;
|
||||
placed->export_as_text(as_text);
|
||||
push_snapshot(placed, EditorSnapshot::Action::Add, as_text);
|
||||
m_node = placed;
|
||||
ui()->set_node(m_node);
|
||||
ui()->set_status(format(STR_C("%s stands in the scenery; Whole model in the toolbar moves it"), File.c_str()));
|
||||
}
|
||||
|
||||
editor_mode::work_area editor_mode::current_work_area() const
|
||||
{
|
||||
if (m_models_open)
|
||||
return work_area::models;
|
||||
// the terrain is shown over the tracks, see the tool options window
|
||||
if (m_terrain_open)
|
||||
return work_area::terrain;
|
||||
@@ -5836,6 +5880,7 @@ void editor_mode::choose_work_area(work_area const Area)
|
||||
break;
|
||||
case work_area::roads:
|
||||
m_track_window_open = false;
|
||||
m_models_open = false;
|
||||
terrain_workspace(false);
|
||||
m_roadtool.window = true;
|
||||
break;
|
||||
@@ -5844,6 +5889,11 @@ void editor_mode::choose_work_area(work_area const Area)
|
||||
m_roadtool.window = false;
|
||||
terrain_workspace(true);
|
||||
break;
|
||||
case work_area::models:
|
||||
// a model of the scenery or a vehicle; a click on another model selects it, as in the surroundings
|
||||
choose_edit_mode(nodebank_panel::MODIFY);
|
||||
m_models_open = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5862,8 +5912,9 @@ void editor_mode::render_workspaces()
|
||||
{STR_C("Roads"), work_area::roads, editor_icons::icon::work_roads, STR_C("Roads and junctions, level crossings, the points where the traffic comes and goes")},
|
||||
{STR_C("Terrain"), work_area::terrain, editor_icons::icon::work_terrain, STR_C("Heightmap terrain: chunks, sculpting, painting, water, orthophoto")},
|
||||
{STR_C("Catenary"), work_area::catenary, editor_icons::icon::work_catenary, STR_C("The overhead catenary: poles with cantilevers, gantries, the wires of the chains")},
|
||||
{STR_C("Models"), work_area::models, editor_icons::icon::work_models, STR_C("The models of the vehicles and of the scenery: their lights, the parts of a vehicle, moving and turning their parts")},
|
||||
};
|
||||
char const *const keys[] = {"F2", "F3", "F4", "F5", "F6"};
|
||||
char const *const keys[] = {"F2", "F3", "F4", "F5", "F6", "F7"};
|
||||
auto const current{current_work_area()};
|
||||
auto const &style{ImGui::GetStyle()};
|
||||
auto *list{ImGui::GetWindowDrawList()};
|
||||
@@ -7047,6 +7098,9 @@ void editor_mode::render_shortcuts_window()
|
||||
|
||||
bool editor_mode::gizmo_shown() const
|
||||
{
|
||||
// the models move their parts with a gizmo of their own, the model as a whole only when Whole model is chosen
|
||||
if (m_models_open)
|
||||
return ui()->model_panel().moves_whole();
|
||||
return ui()->mode() == nodebank_panel::TRACK ? m_track_gizmo_on : m_gizmo_enabled;
|
||||
}
|
||||
|
||||
@@ -7897,6 +7951,7 @@ void editor_mode::on_key(int const Key, int const Scancode, int const Action, in
|
||||
case GLFW_KEY_F4: choose_work_area(work_area::roads); break;
|
||||
case GLFW_KEY_F5: choose_work_area(work_area::terrain); break;
|
||||
case GLFW_KEY_F6: choose_work_area(work_area::catenary); break;
|
||||
case GLFW_KEY_F7: choose_work_area(work_area::models); break;
|
||||
// the edit modes in the order of the toolbar; in the track mode the digits typed as a value were taken already
|
||||
case GLFW_KEY_1: handled = ui()->mode() != nodebank_panel::TRACK; if (handled) choose_edit_mode(nodebank_panel::MODIFY); break;
|
||||
case GLFW_KEY_2: handled = ui()->mode() != nodebank_panel::TRACK; if (handled) choose_edit_mode(nodebank_panel::ADD); break;
|
||||
@@ -7995,6 +8050,18 @@ void editor_mode::on_key(int const Key, int const Scancode, int const Action, in
|
||||
// shortcuts: undo/redo. not in the middle of a drag, it would go on from the state which was undone
|
||||
if (Global.ctrlState && (Key == GLFW_KEY_Z || Key == GLFW_KEY_Y) && is_press(Action) && (m_track_gizmo_using || m_track_set_using || m_straights.dragging || m_extend.active || m_switch.placing || m_point_drag.active || m_handle_drag.active || m_roadtool.lifting))
|
||||
return;
|
||||
// in the field of work of the models the changes of the model are taken back first, then those of the scenery (a model put in or
|
||||
// moved as a whole); while the whole model is moved, those of the scenery
|
||||
if (Global.ctrlState && (Key == GLFW_KEY_Z || Key == GLFW_KEY_Y) && is_press(Action) && m_models_open)
|
||||
{
|
||||
auto &panel{ui()->model_panel()};
|
||||
auto const whole{panel.moves_whole()};
|
||||
if (Key == GLFW_KEY_Z && (whole || false == panel.undo()))
|
||||
undo_last();
|
||||
else if (Key == GLFW_KEY_Y && (whole || false == panel.redo()))
|
||||
redo_last();
|
||||
return;
|
||||
}
|
||||
if (Global.ctrlState && Key == GLFW_KEY_Z && is_press(Action))
|
||||
{
|
||||
// in the catenary tool its own changes are taken back first
|
||||
@@ -8037,6 +8104,8 @@ void editor_mode::on_key(int const Key, int const Scancode, int const Action, in
|
||||
// the chunks of the terrain selected, where the terrain is the field of work; else what's selected in the scenery
|
||||
if (is_press(Action) && m_terrain_open && false == m_terrain_selection.empty())
|
||||
remove_selected_chunks();
|
||||
else if (is_press(Action) && m_models_open)
|
||||
ui()->model_panel().remove_selected(); // a light of the model; the scenery isn't changed there
|
||||
else if (is_press(Action))
|
||||
delete_selected();
|
||||
break;
|
||||
@@ -8368,6 +8437,10 @@ void editor_mode::on_mouse_button(int const Button, int const Action, int const
|
||||
// the press turned out to be meant for the UI, or for the gizmo or a mark of a light of the model window
|
||||
if (!viewport_click() || ui()->model_took_press())
|
||||
return;
|
||||
// in the field of work of the models a click picks a part of the model shown, or another model; anything else
|
||||
// leaves the selection as it is
|
||||
if (m_models_open && (ui()->model_panel().pick(node) || dynamic_cast<TAnimModel *>(node) == nullptr))
|
||||
return;
|
||||
|
||||
auto *const previous{m_node};
|
||||
m_node = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user