summaryrefslogtreecommitdiffstats
path: root/modules/openxr/editor/openxr_action_set_editor.cpp
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2022-11-12 01:59:22 +1100
committerBastiaan Olij <mux213@gmail.com>2022-11-25 20:26:30 +1100
commit96bbdf72490971d886f6ce57476f11bb14523f15 (patch)
tree61519b914686c23f0d996bb10c2af00cb8e3c30a /modules/openxr/editor/openxr_action_set_editor.cpp
parent7580565c28e7e10db7f551287e1f91cfd614b195 (diff)
downloadredot-engine-96bbdf72490971d886f6ce57476f11bb14523f15.tar.gz
Various fixes for OpenXR action map meta data and editing
Diffstat (limited to 'modules/openxr/editor/openxr_action_set_editor.cpp')
-rw-r--r--modules/openxr/editor/openxr_action_set_editor.cpp128
1 files changed, 96 insertions, 32 deletions
diff --git a/modules/openxr/editor/openxr_action_set_editor.cpp b/modules/openxr/editor/openxr_action_set_editor.cpp
index 3869146e8e..d3b6945635 100644
--- a/modules/openxr/editor/openxr_action_set_editor.cpp
+++ b/modules/openxr/editor/openxr_action_set_editor.cpp
@@ -32,8 +32,14 @@
#include "openxr_action_editor.h"
void OpenXRActionSetEditor::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("_do_set_name", "name"), &OpenXRActionSetEditor::_do_set_name);
+ ClassDB::bind_method(D_METHOD("_do_set_localized_name", "name"), &OpenXRActionSetEditor::_do_set_localized_name);
+ ClassDB::bind_method(D_METHOD("_do_set_priority", "value"), &OpenXRActionSetEditor::_do_set_priority);
+ ClassDB::bind_method(D_METHOD("_do_add_action_editor", "action_editor"), &OpenXRActionSetEditor::_do_add_action_editor);
+ ClassDB::bind_method(D_METHOD("_do_remove_action_editor", "action_editor"), &OpenXRActionSetEditor::_do_remove_action_editor);
+
ADD_SIGNAL(MethodInfo("remove", PropertyInfo(Variant::OBJECT, "action_set_editor")));
- ADD_SIGNAL(MethodInfo("action_removed"));
+ ADD_SIGNAL(MethodInfo("action_removed", PropertyInfo(Variant::OBJECT, "action")));
}
void OpenXRActionSetEditor::_set_fold_icon() {
@@ -68,20 +74,6 @@ OpenXRActionEditor *OpenXRActionSetEditor::_add_action_editor(Ref<OpenXRAction>
return action_editor;
}
-void OpenXRActionSetEditor::_update_actions() {
- // out with the old...
- while (actions_vb->get_child_count() > 0) {
- memdelete(actions_vb->get_child(0));
- }
-
- // in with the new...
- Array actions = action_set->get_actions();
- for (int i = 0; i < actions.size(); i++) {
- Ref<OpenXRAction> action = actions[i];
- _add_action_editor(action);
- }
-}
-
void OpenXRActionSetEditor::_on_toggle_expand() {
is_expanded = !is_expanded;
actions_vb->set_visible(is_expanded);
@@ -89,24 +81,66 @@ void OpenXRActionSetEditor::_on_toggle_expand() {
}
void OpenXRActionSetEditor::_on_action_set_name_changed(const String p_new_text) {
- // TODO validate if entry is allowed
-
- // If our localized name matches our action set name, set this too
- if (action_set->get_name() == action_set->get_localized_name()) {
- action_set->set_localized_name(p_new_text);
- action_set_localized_name->set_text(p_new_text);
+ if (action_set->get_name() != p_new_text) {
+ undo_redo->create_action(TTR("Rename Action Set"));
+ undo_redo->add_do_method(this, "_do_set_name", p_new_text);
+ undo_redo->add_undo_method(this, "_do_set_name", action_set->get_name());
+ undo_redo->commit_action(false);
+
+ // If our localized name matches our action set name, set this too
+ if (action_set->get_name() == action_set->get_localized_name()) {
+ undo_redo->create_action(TTR("Rename Action Sets Localized name"));
+ undo_redo->add_do_method(this, "_do_set_localized_name", p_new_text);
+ undo_redo->add_undo_method(this, "_do_set_localized_name", action_set->get_localized_name());
+ undo_redo->commit_action(false);
+
+ action_set->set_localized_name(p_new_text);
+ action_set_localized_name->set_text(p_new_text);
+ }
+ action_set->set_name(p_new_text);
+ action_set->set_edited(true);
}
+}
+
+void OpenXRActionSetEditor::_do_set_name(const String p_new_text) {
action_set->set_name(p_new_text);
+ action_set_name->set_text(p_new_text);
}
void OpenXRActionSetEditor::_on_action_set_localized_name_changed(const String p_new_text) {
+ if (action_set->get_localized_name() != p_new_text) {
+ undo_redo->create_action(TTR("Rename Action Sets Localized name"));
+ undo_redo->add_do_method(this, "_do_set_localized_name", p_new_text);
+ undo_redo->add_undo_method(this, "_do_set_localized_name", action_set->get_localized_name());
+ undo_redo->commit_action(false);
+
+ action_set->set_localized_name(p_new_text);
+ action_set->set_edited(true);
+ }
+}
+
+void OpenXRActionSetEditor::_do_set_localized_name(const String p_new_text) {
action_set->set_localized_name(p_new_text);
+ action_set_localized_name->set_text(p_new_text);
}
void OpenXRActionSetEditor::_on_action_set_priority_changed(const String p_new_text) {
int64_t value = p_new_text.to_int();
- action_set->set_priority(value);
+ if (action_set->get_priority() != value) {
+ undo_redo->create_action(TTR("Change Action Sets priority"));
+ undo_redo->add_do_method(this, "_do_set_priority", value);
+ undo_redo->add_undo_method(this, "_do_set_priority", action_set->get_priority());
+ undo_redo->commit_action(false);
+
+ action_set->set_priority(value);
+ action_set->set_edited(true);
+ }
+}
+
+void OpenXRActionSetEditor::_do_set_priority(int64_t p_value) {
+ action_set->set_priority(p_value);
+ action_set_priority->set_text(itos(p_value));
}
void OpenXRActionSetEditor::_on_add_action() {
@@ -116,8 +150,14 @@ void OpenXRActionSetEditor::_on_add_action() {
new_action->set_name("New");
new_action->set_localized_name("New");
action_set->add_action(new_action);
+ action_set->set_edited(true);
- _add_action_editor(new_action);
+ OpenXRActionEditor *action_editor = _add_action_editor(new_action);
+
+ undo_redo->create_action(TTR("Add action"));
+ undo_redo->add_do_method(this, "_do_add_action_editor", action_editor);
+ undo_redo->add_undo_method(this, "_do_remove_action_editor", action_editor);
+ undo_redo->commit_action(false);
// TODO handle focus
}
@@ -133,17 +173,36 @@ void OpenXRActionSetEditor::_on_remove_action(Object *p_action_editor) {
Ref<OpenXRAction> action = action_editor->get_action();
ERR_FAIL_COND(action.is_null());
- // TODO add undo/redo action
+ emit_signal("action_removed", action);
+
+ undo_redo->create_action(TTR("Delete action"));
+ undo_redo->add_do_method(this, "_do_remove_action_editor", action_editor);
+ undo_redo->add_undo_method(this, "_do_add_action_editor", action_editor);
+ undo_redo->commit_action(true);
- // TODO find where this action is used by our interaction profiles and remove it there
+ action_set->set_edited(true);
+}
- // And remove it....
- action_map->remove_action(action->get_name_with_set()); // remove it from the set and any interaction profile it relates to
- actions_vb->remove_child(action_editor);
- action_editor->queue_free();
+void OpenXRActionSetEditor::_do_add_action_editor(OpenXRActionEditor *p_action_editor) {
+ Ref<OpenXRAction> action = p_action_editor->get_action();
+ ERR_FAIL_COND(action.is_null());
- // Let action map editor know so we can update our interaction profiles
- emit_signal("action_removed");
+ action_set->add_action(action);
+ actions_vb->add_child(p_action_editor);
+}
+
+void OpenXRActionSetEditor::_do_remove_action_editor(OpenXRActionEditor *p_action_editor) {
+ Ref<OpenXRAction> action = p_action_editor->get_action();
+ ERR_FAIL_COND(action.is_null());
+
+ actions_vb->remove_child(p_action_editor);
+ action_set->remove_action(action);
+}
+
+void OpenXRActionSetEditor::remove_all_actions() {
+ for (int i = actions_vb->get_child_count(); i > 0; --i) {
+ _on_remove_action(actions_vb->get_child(i));
+ }
}
void OpenXRActionSetEditor::set_focus_on_entry() {
@@ -214,5 +273,10 @@ OpenXRActionSetEditor::OpenXRActionSetEditor(Ref<OpenXRActionMap> p_action_map,
actions_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_vb->add_child(actions_vb);
- _update_actions();
+ // Add our existing actions
+ Array actions = action_set->get_actions();
+ for (int i = 0; i < actions.size(); i++) {
+ Ref<OpenXRAction> action = actions[i];
+ _add_action_editor(action);
+ }
}