diff options
author | Bastiaan Olij <mux213@gmail.com> | 2022-11-12 01:59:22 +1100 |
---|---|---|
committer | Bastiaan Olij <mux213@gmail.com> | 2022-11-25 20:26:30 +1100 |
commit | 96bbdf72490971d886f6ce57476f11bb14523f15 (patch) | |
tree | 61519b914686c23f0d996bb10c2af00cb8e3c30a /modules/openxr/editor/openxr_interaction_profile_editor.cpp | |
parent | 7580565c28e7e10db7f551287e1f91cfd614b195 (diff) | |
download | redot-engine-96bbdf72490971d886f6ce57476f11bb14523f15.tar.gz |
Various fixes for OpenXR action map meta data and editing
Diffstat (limited to 'modules/openxr/editor/openxr_interaction_profile_editor.cpp')
-rw-r--r-- | modules/openxr/editor/openxr_interaction_profile_editor.cpp | 89 |
1 files changed, 73 insertions, 16 deletions
diff --git a/modules/openxr/editor/openxr_interaction_profile_editor.cpp b/modules/openxr/editor/openxr_interaction_profile_editor.cpp index e2dc2d1b74..3eca1967f5 100644 --- a/modules/openxr/editor/openxr_interaction_profile_editor.cpp +++ b/modules/openxr/editor/openxr_interaction_profile_editor.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "openxr_interaction_profile_editor.h" +#include "editor/editor_node.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/label.h" @@ -58,6 +59,13 @@ void OpenXRInteractionProfileEditorBase::_notification(int p_what) { } } +void OpenXRInteractionProfileEditorBase::_do_update_interaction_profile() { + if (!is_dirty) { + is_dirty = true; + call_deferred("_update_interaction_profile"); + } +} + void OpenXRInteractionProfileEditorBase::_add_binding(const String p_action, const String p_path) { ERR_FAIL_COND(action_map.is_null()); ERR_FAIL_COND(interaction_profile.is_null()); @@ -71,14 +79,16 @@ void OpenXRInteractionProfileEditorBase::_add_binding(const String p_action, con binding.instantiate(); binding->set_action(action); interaction_profile->add_binding(binding); + interaction_profile->set_edited(true); } binding->add_path(p_path); + binding->set_edited(true); // Update our toplevel paths action->set_toplevel_paths(action_map->get_top_level_paths(action)); - call_deferred("_update_interaction_profile"); + _do_update_interaction_profile(); } void OpenXRInteractionProfileEditorBase::_remove_binding(const String p_action, const String p_path) { @@ -91,25 +101,54 @@ void OpenXRInteractionProfileEditorBase::_remove_binding(const String p_action, Ref<OpenXRIPBinding> binding = interaction_profile->get_binding_for_action(action); if (binding.is_valid()) { binding->remove_path(p_path); + binding->set_edited(true); if (binding->get_path_count() == 0) { interaction_profile->remove_binding(binding); + interaction_profile->set_edited(true); } // Update our toplevel paths action->set_toplevel_paths(action_map->get_top_level_paths(action)); - call_deferred("_update_interaction_profile"); + _do_update_interaction_profile(); + } +} + +void OpenXRInteractionProfileEditorBase::remove_all_bindings_for_action(Ref<OpenXRAction> p_action) { + Ref<OpenXRIPBinding> binding = interaction_profile->get_binding_for_action(p_action); + if (binding.is_valid()) { + String action_name = p_action->get_name_with_set(); + + // for our undo/redo we process all paths + undo_redo->create_action(TTR("Remove action from interaction profile")); + PackedStringArray paths = binding->get_paths(); + for (const String &path : paths) { + undo_redo->add_do_method(this, "_remove_binding", p_action, path); + undo_redo->add_undo_method(this, "_add_binding", p_action, path); + } + undo_redo->commit_action(false); + + // but we take a shortcut here :) + interaction_profile->remove_binding(binding); + interaction_profile->set_edited(true); + + // Update our toplevel paths + p_action->set_toplevel_paths(action_map->get_top_level_paths(p_action)); + + _do_update_interaction_profile(); } } OpenXRInteractionProfileEditorBase::OpenXRInteractionProfileEditorBase(Ref<OpenXRActionMap> p_action_map, Ref<OpenXRInteractionProfile> p_interaction_profile) { + undo_redo = EditorNode::get_undo_redo(); + action_map = p_action_map; interaction_profile = p_interaction_profile; String profile_path = interaction_profile->get_interaction_profile_path(); String profile_name = profile_path; - profile_def = OpenXRDefs::get_profile(profile_path); + profile_def = OpenXRInteractionProfileMetaData::get_singleton()->get_profile(profile_path); if (profile_def != nullptr) { profile_name = profile_def->display_name; } @@ -117,6 +156,9 @@ OpenXRInteractionProfileEditorBase::OpenXRInteractionProfileEditorBase(Ref<OpenX set_name(profile_name); set_h_size_flags(SIZE_EXPAND_FILL); set_v_size_flags(SIZE_EXPAND_FILL); + + // Make sure it is updated when it enters the tree... + is_dirty = true; } /////////////////////////////////////////////////////////////////////////// @@ -128,11 +170,22 @@ void OpenXRInteractionProfileEditor::select_action_for(const String p_io_path) { } void OpenXRInteractionProfileEditor::action_selected(const String p_action) { - _add_binding(p_action, selecting_for_io_path); + undo_redo->create_action(TTR("Add binding")); + undo_redo->add_do_method(this, "_add_binding", p_action, selecting_for_io_path); + undo_redo->add_undo_method(this, "_remove_binding", p_action, selecting_for_io_path); + undo_redo->commit_action(true); + selecting_for_io_path = ""; } -void OpenXRInteractionProfileEditor::_add_io_path(VBoxContainer *p_container, const OpenXRDefs::IOPath *p_io_path) { +void OpenXRInteractionProfileEditor::_on_remove_pressed(const String p_action, const String p_for_io_path) { + undo_redo->create_action(TTR("Remove binding")); + undo_redo->add_do_method(this, "_remove_binding", p_action, p_for_io_path); + undo_redo->add_undo_method(this, "_add_binding", p_action, p_for_io_path); + undo_redo->commit_action(true); +} + +void OpenXRInteractionProfileEditor::_add_io_path(VBoxContainer *p_container, const OpenXRInteractionProfileMetaData::IOPath *p_io_path) { HBoxContainer *path_hb = memnew(HBoxContainer); path_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); p_container->add_child(path_hb); @@ -196,7 +249,7 @@ void OpenXRInteractionProfileEditor::_add_io_path(VBoxContainer *p_container, co Button *action_rem = memnew(Button); action_rem->set_flat(true); action_rem->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - action_rem->connect("pressed", callable_mp((OpenXRInteractionProfileEditorBase *)this, &OpenXRInteractionProfileEditorBase::_remove_binding).bind(action->get_name_with_set(), String(p_io_path->openxr_path))); + action_rem->connect("pressed", callable_mp((OpenXRInteractionProfileEditor *)this, &OpenXRInteractionProfileEditor::_on_remove_pressed).bind(action->get_name_with_set(), String(p_io_path->openxr_path))); action_hb->add_child(action_rem); } } @@ -206,6 +259,11 @@ void OpenXRInteractionProfileEditor::_add_io_path(VBoxContainer *p_container, co void OpenXRInteractionProfileEditor::_update_interaction_profile() { ERR_FAIL_NULL(profile_def); + if (!is_dirty) { + // no need to update + return; + } + // out with the old... while (main_hb->get_child_count() > 0) { memdelete(main_hb->get_child(0)); @@ -214,9 +272,9 @@ void OpenXRInteractionProfileEditor::_update_interaction_profile() { // in with the new... // Determine toplevel paths - Vector<const OpenXRDefs::TopLevelPath *> top_level_paths; - for (int i = 0; i < profile_def->io_path_count; i++) { - const OpenXRDefs::IOPath *io_path = &profile_def->io_paths[i]; + Vector<String> top_level_paths; + for (int i = 0; i < profile_def->io_paths.size(); i++) { + const OpenXRInteractionProfileMetaData::IOPath *io_path = &profile_def->io_paths[i]; if (!top_level_paths.has(io_path->top_level_path)) { top_level_paths.push_back(io_path->top_level_path); @@ -233,16 +291,19 @@ void OpenXRInteractionProfileEditor::_update_interaction_profile() { panel->add_child(container); Label *label = memnew(Label); - label->set_text(top_level_paths[i]->display_name); + label->set_text(OpenXRInteractionProfileMetaData::get_singleton()->get_top_level_name(top_level_paths[i])); container->add_child(label); - for (int j = 0; j < profile_def->io_path_count; j++) { - const OpenXRDefs::IOPath *io_path = &profile_def->io_paths[j]; + for (int j = 0; j < profile_def->io_paths.size(); j++) { + const OpenXRInteractionProfileMetaData::IOPath *io_path = &profile_def->io_paths[j]; if (io_path->top_level_path == top_level_paths[i]) { _add_io_path(container, io_path); } } } + + // and we've updated it... + is_dirty = false; } void OpenXRInteractionProfileEditor::_theme_changed() { @@ -256,14 +317,10 @@ void OpenXRInteractionProfileEditor::_theme_changed() { OpenXRInteractionProfileEditor::OpenXRInteractionProfileEditor(Ref<OpenXRActionMap> p_action_map, Ref<OpenXRInteractionProfile> p_interaction_profile) : OpenXRInteractionProfileEditorBase(p_action_map, p_interaction_profile) { - // TODO background of scrollbox should be darker with our VBoxContainers we're adding in _update_interaction_profile the normal color - main_hb = memnew(HBoxContainer); add_child(main_hb); select_action_dialog = memnew(OpenXRSelectActionDialog(p_action_map)); select_action_dialog->connect("action_selected", callable_mp(this, &OpenXRInteractionProfileEditor::action_selected)); add_child(select_action_dialog); - - _update_interaction_profile(); } |