1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-23 15:16:17 +00:00

Cleanup Path3D editor

This commit is contained in:
kobewi
2024-09-06 16:01:02 +02:00
parent 5675c76461
commit a49dbdcbef
2 changed files with 24 additions and 53 deletions

View File

@@ -687,11 +687,11 @@ void Path3DEditorPlugin::make_visible(bool p_visible) {
} }
void Path3DEditorPlugin::_mode_changed(int p_mode) { void Path3DEditorPlugin::_mode_changed(int p_mode) {
curve_create->set_pressed(p_mode == MODE_CREATE); curve_create->set_pressed_no_signal(p_mode == MODE_CREATE);
curve_edit_curve->set_pressed(p_mode == MODE_EDIT_CURVE); curve_edit_curve->set_pressed_no_signal(p_mode == MODE_EDIT_CURVE);
curve_edit_tilt->set_pressed(p_mode == MODE_EDIT_TILT); curve_edit_tilt->set_pressed_no_signal(p_mode == MODE_EDIT_TILT);
curve_edit->set_pressed(p_mode == MODE_EDIT); curve_edit->set_pressed_no_signal(p_mode == MODE_EDIT);
curve_del->set_pressed(p_mode == MODE_DELETE); curve_del->set_pressed_no_signal(p_mode == MODE_DELETE);
Node3DEditor::get_singleton()->clear_subgizmo_selection(); Node3DEditor::get_singleton()->clear_subgizmo_selection();
} }
@@ -790,17 +790,14 @@ void Path3DEditorPlugin::_restore_curve_points(const PackedVector3Array &p_point
} }
void Path3DEditorPlugin::_update_theme() { void Path3DEditorPlugin::_update_theme() {
// TODO: Split the EditorPlugin instance from the UI instance and connect this properly. curve_edit->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveEdit")));
// See the 2D path editor for inspiration. curve_edit_curve->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveCurve")));
curve_edit->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("CurveEdit"), EditorStringName(EditorIcons))); curve_edit_tilt->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveTilt")));
curve_edit_curve->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("CurveCurve"), EditorStringName(EditorIcons))); curve_create->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveCreate")));
curve_edit_tilt->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("CurveTilt"), EditorStringName(EditorIcons))); curve_del->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveDelete")));
curve_create->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("CurveCreate"), EditorStringName(EditorIcons))); curve_close->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveClose")));
curve_del->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("CurveDelete"), EditorStringName(EditorIcons))); curve_clear_points->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("Clear")));
curve_close->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("CurveClose"), EditorStringName(EditorIcons))); create_curve_button->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("Curve3D")));
curve_clear_points->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Clear"), EditorStringName(EditorIcons)));
create_curve_button->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Curve3D"), EditorStringName(EditorIcons)));
} }
void Path3DEditorPlugin::_update_toolbar() { void Path3DEditorPlugin::_update_toolbar() {
@@ -812,42 +809,14 @@ void Path3DEditorPlugin::_update_toolbar() {
create_curve_button->set_visible(!has_curve); create_curve_button->set_visible(!has_curve);
} }
void Path3DEditorPlugin::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
curve_create->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_CREATE));
curve_edit_curve->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_CURVE));
curve_edit_tilt->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_TILT));
curve_edit->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT));
curve_del->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_DELETE));
curve_close->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_close_curve));
_update_theme();
} break;
case NOTIFICATION_READY: {
// FIXME: This can trigger theme updates when the nodes that we want to update are not yet available.
// The toolbar should be extracted to a dedicated control and theme updates should be handled through
// the notification.
Node3DEditor::get_singleton()->connect(SceneStringName(theme_changed), callable_mp(this, &Path3DEditorPlugin::_update_theme));
} break;
}
}
void Path3DEditorPlugin::_bind_methods() { void Path3DEditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_toolbar"), &Path3DEditorPlugin::_update_toolbar); ClassDB::bind_method(D_METHOD("_update_toolbar"), &Path3DEditorPlugin::_update_toolbar);
ClassDB::bind_method(D_METHOD("_clear_curve_points"), &Path3DEditorPlugin::_clear_curve_points); ClassDB::bind_method(D_METHOD("_clear_curve_points"), &Path3DEditorPlugin::_clear_curve_points);
ClassDB::bind_method(D_METHOD("_restore_curve_points"), &Path3DEditorPlugin::_restore_curve_points); ClassDB::bind_method(D_METHOD("_restore_curve_points"), &Path3DEditorPlugin::_restore_curve_points);
} }
Path3DEditorPlugin *Path3DEditorPlugin::singleton = nullptr;
Path3DEditorPlugin::Path3DEditorPlugin() { Path3DEditorPlugin::Path3DEditorPlugin() {
path = nullptr;
singleton = this; singleton = this;
mirror_handle_angle = true;
mirror_handle_length = true;
disk_size = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8); disk_size = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8);
Ref<Path3DGizmoPlugin> gizmo_plugin = memnew(Path3DGizmoPlugin(disk_size)); Ref<Path3DGizmoPlugin> gizmo_plugin = memnew(Path3DGizmoPlugin(disk_size));
@@ -856,7 +825,6 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
topmenu_bar = memnew(HBoxContainer); topmenu_bar = memnew(HBoxContainer);
topmenu_bar->hide(); topmenu_bar->hide();
Node3DEditor::get_singleton()->add_control_to_menu_panel(topmenu_bar);
toolbar = memnew(HBoxContainer); toolbar = memnew(HBoxContainer);
topmenu_bar->add_child(toolbar); topmenu_bar->add_child(toolbar);
@@ -867,6 +835,7 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
curve_edit->set_focus_mode(Control::FOCUS_NONE); curve_edit->set_focus_mode(Control::FOCUS_NONE);
curve_edit->set_tooltip_text(TTR("Select Points") + "\n" + TTR("Shift+Click: Select multiple Points") + "\n" + keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point")); curve_edit->set_tooltip_text(TTR("Select Points") + "\n" + TTR("Shift+Click: Select multiple Points") + "\n" + keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point"));
toolbar->add_child(curve_edit); toolbar->add_child(curve_edit);
curve_edit->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT));
curve_edit_curve = memnew(Button); curve_edit_curve = memnew(Button);
curve_edit_curve->set_theme_type_variation("FlatButton"); curve_edit_curve->set_theme_type_variation("FlatButton");
@@ -874,6 +843,7 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
curve_edit_curve->set_focus_mode(Control::FOCUS_NONE); curve_edit_curve->set_focus_mode(Control::FOCUS_NONE);
curve_edit_curve->set_tooltip_text(TTR("Select Control Points") + "\n" + TTR("Shift+Click: Drag out Control Points")); curve_edit_curve->set_tooltip_text(TTR("Select Control Points") + "\n" + TTR("Shift+Click: Drag out Control Points"));
toolbar->add_child(curve_edit_curve); toolbar->add_child(curve_edit_curve);
curve_edit_curve->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_CURVE));
curve_edit_tilt = memnew(Button); curve_edit_tilt = memnew(Button);
curve_edit_tilt->set_theme_type_variation("FlatButton"); curve_edit_tilt->set_theme_type_variation("FlatButton");
@@ -881,6 +851,7 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
curve_edit_tilt->set_focus_mode(Control::FOCUS_NONE); curve_edit_tilt->set_focus_mode(Control::FOCUS_NONE);
curve_edit_tilt->set_tooltip_text(TTR("Select Tilt Handles")); curve_edit_tilt->set_tooltip_text(TTR("Select Tilt Handles"));
toolbar->add_child(curve_edit_tilt); toolbar->add_child(curve_edit_tilt);
curve_edit_tilt->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_TILT));
curve_create = memnew(Button); curve_create = memnew(Button);
curve_create->set_theme_type_variation("FlatButton"); curve_create->set_theme_type_variation("FlatButton");
@@ -888,6 +859,7 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
curve_create->set_focus_mode(Control::FOCUS_NONE); curve_create->set_focus_mode(Control::FOCUS_NONE);
curve_create->set_tooltip_text(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)")); curve_create->set_tooltip_text(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)"));
toolbar->add_child(curve_create); toolbar->add_child(curve_create);
curve_create->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_CREATE));
curve_del = memnew(Button); curve_del = memnew(Button);
curve_del->set_theme_type_variation("FlatButton"); curve_del->set_theme_type_variation("FlatButton");
@@ -895,12 +867,14 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
curve_del->set_focus_mode(Control::FOCUS_NONE); curve_del->set_focus_mode(Control::FOCUS_NONE);
curve_del->set_tooltip_text(TTR("Delete Point")); curve_del->set_tooltip_text(TTR("Delete Point"));
toolbar->add_child(curve_del); toolbar->add_child(curve_del);
curve_del->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_DELETE));
curve_close = memnew(Button); curve_close = memnew(Button);
curve_close->set_theme_type_variation("FlatButton"); curve_close->set_theme_type_variation("FlatButton");
curve_close->set_focus_mode(Control::FOCUS_NONE); curve_close->set_focus_mode(Control::FOCUS_NONE);
curve_close->set_tooltip_text(TTR("Close Curve")); curve_close->set_tooltip_text(TTR("Close Curve"));
toolbar->add_child(curve_close); toolbar->add_child(curve_close);
curve_close->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_close_curve));
curve_clear_points = memnew(Button); curve_clear_points = memnew(Button);
curve_clear_points->set_theme_type_variation("FlatButton"); curve_clear_points->set_theme_type_variation("FlatButton");
@@ -927,18 +901,17 @@ Path3DEditorPlugin::Path3DEditorPlugin() {
topmenu_bar->add_child(create_curve_button); topmenu_bar->add_child(create_curve_button);
create_curve_button->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_create_curve)); create_curve_button->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_create_curve));
PopupMenu *menu; PopupMenu *menu = handle_menu->get_popup();
menu = handle_menu->get_popup();
menu->add_check_item(TTR("Mirror Handle Angles")); menu->add_check_item(TTR("Mirror Handle Angles"));
menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle); menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);
menu->add_check_item(TTR("Mirror Handle Lengths")); menu->add_check_item(TTR("Mirror Handle Lengths"));
menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length); menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);
menu->connect(SceneStringName(id_pressed), callable_mp(this, &Path3DEditorPlugin::_handle_option_pressed)); menu->connect(SceneStringName(id_pressed), callable_mp(this, &Path3DEditorPlugin::_handle_option_pressed));
curve_edit->set_pressed(true); curve_edit->set_pressed_no_signal(true);
}
Path3DEditorPlugin::~Path3DEditorPlugin() { topmenu_bar->connect(SceneStringName(theme_changed), callable_mp(this, &Path3DEditorPlugin::_update_theme));
Node3DEditor::get_singleton()->add_control_to_menu_panel(topmenu_bar);
} }
Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) {

View File

@@ -162,13 +162,12 @@ class Path3DEditorPlugin : public EditorPlugin {
}; };
protected: protected:
void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
public: public:
Path3D *get_edited_path() { return path; } Path3D *get_edited_path() { return path; }
static Path3DEditorPlugin *singleton; inline static Path3DEditorPlugin *singleton = nullptr;
virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override; virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;
virtual String get_name() const override { return "Path3D"; } virtual String get_name() const override { return "Path3D"; }
@@ -183,7 +182,6 @@ public:
void set_handle_clicked(bool clicked) { handle_clicked = clicked; } void set_handle_clicked(bool clicked) { handle_clicked = clicked; }
Path3DEditorPlugin(); Path3DEditorPlugin();
~Path3DEditorPlugin();
}; };
#endif // PATH_3D_EDITOR_PLUGIN_H #endif // PATH_3D_EDITOR_PLUGIN_H