Various fixes for OpenXR action map meta data and editing

This commit is contained in:
Bastiaan Olij 2022-11-12 01:59:22 +11:00
parent 7580565c28
commit 96bbdf7249
29 changed files with 1418 additions and 1018 deletions

View file

@ -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 (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()) {
action_set->set_localized_name(p_new_text);
action_set_localized_name->set_text(p_new_text);
// 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);
// TODO find where this action is used by our interaction profiles and remove it there
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);
// 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();
action_set->set_edited(true);
}
// Let action map editor know so we can update our interaction profiles
emit_signal("action_removed");
void OpenXRActionSetEditor::_do_add_action_editor(OpenXRActionEditor *p_action_editor) {
Ref<OpenXRAction> action = p_action_editor->get_action();
ERR_FAIL_COND(action.is_null());
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);
}
}