18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 17:46:48 +01:00
Files
maszyna/application/editoruipanels.h
T
maj00r fef7eaac11 feat(editor): one card for the tools, one layout of the fields, windows of their own, one name for each thing
The consistency pass of the editor's interface after its first steps (P2 of the plan of the editor's interface):

- One card for the tool in use in every field of work. The card of the track tools (its icon, name, family and key, what
  the tool is for, the mouse and the keys drawing its gestures, the link to all the shortcuts) is a component of its own,
  render_tool_card, fed by the tracks as before and now by the surroundings, the roads and the terrain: their tools, kept in
  one table each with their icons, keys, tooltips and gestures for the toolbar and the card, had a plain heading and a line
  of keys or a few rows of gestures there. The tool options of the surroundings are headed by the field of work as the
  others are. The card is folded to its title row unless the user opened it, for all the tools: what the tool is for shows
  over the title, a click opens the gestures, which are in the strip under the view of the tracks as well. Kept with the
  settings of the editor under the key tool_card_folded, so the open card the tracks had by default before stays behind.
- One layout of the fields: the name on the left, the field on the right (begin_fields and field_row, as in the inspector of
  the tracks) in the inspector of the surroundings (the name, the position, the rotation, the scale), Weather and time,
  Change history, the settings of the orthophoto and the settings of the editor. The square buttons of the download area go
  on to the next line at the edge, the last one was cut off.
- Windows of their own, which don't hide the inspector: Editor settings, Weather and time and the orthophoto settings float
  over the view, opened in its top left corner below the rows of the tools and kept between them and the status line, as
  the window of a lesson is. They were tabs over the inspector, and the orthophoto settings unfolded inside the layers; Map >
  Orthophoto settings..., the button of the terrain tools and the button in the layers open the window now.
- One list of the objects of the scenery: Windows > Scene Hierarchy, a plain list of the same nodes, is gone; Windows >
  Scene opens the Scene tab (by layer and group, with the filter) and brings it forward when it lies behind the layers.
- One name for each thing, in the menus, the toolbar, the panels, the tutorial and F1: the orthophoto ("Ortofotomapa
  (zdjęcia lotnicze z geoportal.gov.pl)" where it's introduced, "ortofotomapa" in the rest, for "zdjęcia lotnicze",
  "ortofoto" and "zdjęcie"), the terrain model ("Teren z map (NMT)" for "Prawdziwy teren z map", "model terenu", "prawdziwy
  teren", "Teren z NMT"), the plan tool ("Plan", the lesson "Correcting a curve" and the section of F1 "Plan of a curve"
  before), the area fill (the terrain's "Fill" is "Area fill" as in the surroundings, with the icon of it, Water without).
  The texts of the laying, whose panel is to be redone, are left as they are.
- The node bank: a model clicked with the select tool of the surroundings arms the insert tool with it (the click did
  nothing before), the random model of a set is left off then. A model inserted where there's no ground under the cursor
  stands at the height 0 where the cursor points, or in front of the camera when it points above the horizon, and the
  status says where; it stood at the point the renderer last had under the cursor, out of sight. The search field of the
  bank has no name beside it, which was cut to its first letter.
- The settings in one place: Editor settings holds the movement and the speed of the camera (as View > Camera speed), the
  gizmo and the colours, the terrain made of the terrain model by itself (as in the layers and the download area) and the
  maximum placement distance (as in Change history).
- F1 and the menus: Esc closes the window of the shortcuts, before anything else; the window stays in the work area as the
  window of a lesson; the menus are opaque, the windows under them showed through.
- What the first steps left: with an empty scenery the panel in the middle of the view gives way to the inspector, which
  says the same with the button of the lay tool and the first steps; it's drawn only while the inspector isn't seen. A
  switch whose speed limits its diverging track alone shows that speed under its empty speed field ("The diverging track
  40 km/h, the main one no limit"), read only; the field alone said no limit.
- Self-tests: the command bankpick, the expectations tool, window and selected, the cases c_1_bank_card_arms_insert and
  c_2_esc_closes_shortcuts.

lang/editor_pl.po: the Polish of the new texts (the cards of the tools, the windows, the fields, the notices), the entries of
the texts renamed given their new English, those no longer used taken out, and the names unified in the Polish of the
orthophoto and of the terrain model.
2026-11-23 13:35:56 +01:00

321 lines
13 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/.
*/
#pragma once
#include "application/uilayer.h"
#include "utilities/Classes.h"
#include "editor/editorIncludeInfo.hpp"
#include "editor/editorPreviews.hpp"
#include <functional>
#include <utility>
/*
// helper, associated bool is set when the primary value was changed and expects processing at the observer's leisure
template<typename Type_>
using changeable = std::pair<Type_, bool>;
// helper, holds a set of changeable properties for a scene node
struct item_properties {
scene::basic_node const *node { nullptr }; // properties' owner
changeable<std::string> name {};
changeable<glm::dvec3> location {};
changeable<glm::vec3> rotation {};
};
*/
// include of a scenery template selected in the editor, with the values its directive passes to the template.
// owned by the editor mode; the node properties let the user change the values
struct include_selection
{
scene::instance_handle instance{0};
std::string target; // name of the template, the way the directive spells it
include_info info; // description of the template
std::vector<std::string> values; // value of each parameter in turn
bool placement{false}; // the position and rotation parameters can be driven by the gizmo
std::string issue; // why the values can't be changed, if they can't
bool changed{false}; // set by the UI when a value was changed, cleared by the editor mode once the change is applied
bool active{false}; // the UI is in the middle of changing a value
};
class itemproperties_panel : public ui_panel
{
public:
itemproperties_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen) {}
// non-const node pointer so the transform editor in render() can mutate
// position/rotation/scale of TAnimModel nodes in place. Other node types
// are still treated as read-only.
void update(scene::basic_node *Node);
// binds include of a scenery template to the panel, shown in place of a node; nullptr unbinds
void include(include_selection *Include)
{
m_include = Include;
}
void render() override;
// panel content without the window, also drawn inside the toolset window
void render_body();
private:
// methods
void update_group();
bool render_group();
// renders DragFloat3/DragScalarN widgets for position, rotation and scale
// of the currently bound TAnimModel; no-op for other node subclasses.
void render_transform_editor();
// renders the field with the name of the currently bound TAnimModel, which gives the instance another name; no-op for other node subclasses
void render_name_editor();
// renders widgets for the parameters of the bound include
void render_include();
// members
scene::basic_node *m_node{nullptr}; // scene node bound to the panel
scene::basic_node *m_namednode{nullptr}; // scene node whose name is held by the edit buffer
char m_namebuffer[128]{}; // name of the node, as shown and typed in
bool m_nameactive{false}; // the name is being typed in
std::string m_nameissue; // why the name typed in wasn't taken
include_selection *m_include{nullptr}; // include of a scenery template bound to the panel
scene::group_handle m_grouphandle{null_handle}; // scene group bound to the panel
std::string m_groupprefix;
std::vector<text_line> m_grouplines;
};
// reference to a set of node templates, used by the random insert, the brush and the area fill
struct model_set_ref
{
enum class source
{
manual, // list assembled by hand in the tool itself (or no set, where the tool has no such list)
user, // user-defined set (see EditorModelSets), id == set id
nodebank // node bank group, id == group index (as returned by nodebank_panel::group_names())
};
source kind{source::manual};
int id{-1};
};
class nodebank_panel;
// brush settings, drawn inside the node bank window when the brush mode is active
class brush_object_list
{
private:
int idx{-1};
public:
void render_options(nodebank_panel &Bank);
// class use
std::vector<std::string> Objects; // manual list, used when source is set to manual
std::string *GetRandomObject();
bool useRandom = {false};
model_set_ref source;
float spacing{1.0f};
};
class nodebank_panel : public ui_panel
{
public:
enum edit_mode
{
MODIFY,
COPY,
ADD,
BRUSH,
FILL,
TRACK
};
edit_mode mode = MODIFY;
bool suppressed{false}; // the field of work has no use for it: not drawn, though it stays open for the others
nodebank_panel(std::string const &Name, bool const Isopen);
void nodebank_reload();
void render() override;
void add_template(const std::string &desc);
const std::string *get_active_template();
// nodebank groups (collapsing headers), in file order; entries listed before the first header form an unnamed group
std::vector<std::string> group_names() const;
// node templates of the group with specified index (as returned by group_names())
std::vector<std::string> group_templates(std::size_t const Group) const;
// model sets (user-defined sets and node bank groups)
// combo selecting a set. Manuallabel names the tool's own hand-made list; nullptr hides that choice. returns: true on change
bool set_combo(char const *Label, model_set_ref &Ref, char const *Manuallabel);
// list of templates assembled by hand, with buttons to add the node bank selection, remove entries and save it as a user set
void manual_list(char const *Id, std::vector<std::string> &List, int &Selected);
// node templates of referenced set; empty for the manual list or a set which no longer exists
std::vector<std::string const *> set_entries(model_set_ref const &Ref) const;
// random template from referenced set, or nullptr if the set is empty
std::string const *random_template(model_set_ref const &Ref) const;
std::string set_name(model_set_ref const &Ref, char const *Manuallabel) const;
// shows the set manager window, optionally with specified user set selected
void open_sets_window(int const Setid = 0);
// content drawn in the window of the node bank in its place, with its own title (a field of work of the editor uses the window
// for its own browser); none: the node bank
void stand_in(std::function<void()> Content, std::string Title)
{
m_standin = std::move(Content);
m_standintitle = std::move(Title);
}
// a template was clicked in the node bank since the last call: the select tool of the surroundings takes it as the one to insert
bool take_picked() { return std::exchange(m_picked, false); }
// the template of the node bank at the index, the headers of the groups left out, chosen as a click on its card chooses it; false
// if there's none there. For the self-test
bool pick(std::size_t const Index);
private:
// methods:
std::string generate_node_label(std::string Input) const;
void render_sets_window();
// finds the preview images of the entries, in the order of the file, as the generator names them
void index_previews();
// entries of a group as cards with their previews, in rows as many as fit the width
void render_cards(std::vector<std::pair<std::string, std::shared_ptr<std::string>> const *> const &Entries);
// the same entries as a list, for when the previews are off
void render_list(std::vector<std::pair<std::string, std::shared_ptr<std::string>> const *> const &Entries);
// the scenery templates (.inc), as a list; they're placed with include directives, so they take a scenery opened for editing
void render_templates_list(std::string const &Filter);
// the entry dragged from the item drawn last, to drop it on a list of the model sets or of a tool
void drag_entry(std::pair<std::string, std::shared_ptr<std::string>> const &Entry);
// image of a node definition as the node bank has it, or an empty string
std::string const &template_preview(std::string const &Template) const;
// texture of the small preview of the image, 0 if there's none (yet)
std::uint64_t preview_texture(std::string const &Path, char const *&Placeholder);
// the templates of the edited model set as cards with their previews
void render_set_cards(int const Setid);
// the entry pointed at for a moment: a popup with its preview, big, and the model and skin it shows
void preview_popup(std::pair<std::string, std::shared_ptr<std::string>> const &Entry);
// true if the node bank selection is a definition of a node, which the hand-made lists and the model sets can take
bool node_selected() const;
// members:
std::function<void()> m_standin;
std::string m_standintitle;
std::vector<std::pair<std::string, std::shared_ptr<std::string>>> m_nodebank;
char m_nodesearch[128];
std::shared_ptr<std::string> m_selectedtemplate;
bool m_picked{false}; // a template clicked since take_picked() was called
// previews of the models: image of each node definition, by its address, and the images read so far
std::unordered_map<std::string const *, std::string> m_previewpaths;
std::unique_ptr<editor_previews::image_cache> m_previews;
std::unique_ptr<editor_previews::image_cache> m_largepreviews; // a few, for the popup
bool m_previewfolder{false}; // the generator was run, there's the folder of the images
std::unordered_map<std::string, std::string> m_templatepreviews; // images of the node definitions by their text, for the model sets
// the group of the node bank shown, by its place among the groups; scenery_templates for the scenery templates
static int constexpr scenery_templates{-1};
int m_category{0};
// set manager window
bool m_setsopen{false};
int m_setsselected{0}; // id of the user set being edited
int m_setsentry{-1}; // selected template of the edited set
int m_setsnameid{0}; // id of the set whose name is held in the edit buffer
char m_setsname[128]{};
model_set_ref m_setsgroup{model_set_ref::source::nodebank, 0}; // node bank group to append to the edited set
};
// scenery layers of a scenery opened for editing: their visibility, selection lock, the layer receiving new nodes,
// and layer management. the changes are applied to the scenery files on save
class layers_panel : public ui_panel
{
public:
layers_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen) {}
void render() override;
// saves the scenery; provided by the editor mode
std::function<void()> save;
// the base layers under the scenery, the orthophoto and the WMS layers of the user's, with their settings; provided by the
// editor mode
std::function<void()> base_layers;
// the window brought to the front the next time it's drawn
bool focus{false};
// outcome of the most recent operation, shown at the bottom of the window
std::string status;
bool status_error{false};
private:
// methods
void render_list();
void render_popups();
void report(std::string const &Status, bool const Error = false);
// members
scene::layer_handle m_selected{null_handle}; // layer the buttons act on
char m_newname[128]{}; // file name of the layer being created
scene::layer_handle m_newparent{null_handle}; // layer which is going to include it
scene::layer_handle m_mergetarget{null_handle};
std::string m_popuperror;
};
// database of the *.inc scenery templates: the templates found in the scenery directory, with the editor of their
// descriptions (see editorIncludeInfo.hpp). templates whose descriptions are complete are offered by the node bank
class includes_panel : public ui_panel
{
public:
includes_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen) {}
void render() override;
private:
// methods
void open(std::string const &File);
void render_list();
void render_description();
// members
// template list
char m_filter[128]{};
bool m_describedonly{false};
bool m_usedonly{false};
std::vector<std::size_t> m_listed; // entries of the template bank matching the filter
int m_listrevision{-1}; // revision of the template bank the list was made for
int m_described{0};
// description editor
std::string m_file; // template being edited, relative to the scenery directory
include_info m_info;
int m_parameters{0}; // number of parameters the template uses
bool m_loaded{false};
std::string m_status;
bool m_statuserror{false};
};
class functions_panel : public ui_panel
{
public:
enum rotation_mode
{
RANDOM,
FIXED,
DEFAULT
};
rotation_mode rot_mode = DEFAULT;
float rot_value = 0.0f;
bool rot_from_last = false;
functions_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen) {}
void update(scene::basic_node const *Node);
void render() override;
// rotation settings widgets, also drawn inside the node bank window
void render_controls();
private:
// methods
// members
scene::basic_node const *m_node{nullptr}; // scene node bound to the panel
scene::group_handle m_grouphandle{null_handle}; // scene group bound to the panel
std::string m_groupprefix;
std::vector<text_line> m_grouplines;
};