mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
OpenXR: Add support for binding modifiers
This commit is contained in:
parent
c2e4ae782a
commit
0a61ebdcea
56 changed files with 3127 additions and 763 deletions
|
@ -29,20 +29,16 @@
|
|||
/**************************************************************************/
|
||||
|
||||
#include "openxr_interaction_profile_editor.h"
|
||||
|
||||
#include "../openxr_api.h"
|
||||
#include "editor/editor_string_names.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/panel_container.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/gui/text_edit.h"
|
||||
#include "openxr_action_map_editor.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Interaction profile editor base
|
||||
|
||||
void OpenXRInteractionProfileEditorBase::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("setup", "action_map", "interaction_profile"), &OpenXRInteractionProfileEditorBase::setup);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_add_binding", "action", "path"), &OpenXRInteractionProfileEditorBase::_add_binding);
|
||||
ClassDB::bind_method(D_METHOD("_remove_binding", "action", "path"), &OpenXRInteractionProfileEditorBase::_remove_binding);
|
||||
}
|
||||
|
@ -112,12 +108,36 @@ void OpenXRInteractionProfileEditorBase::_remove_binding(const String p_action,
|
|||
}
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditorBase::remove_all_bindings_for_action(Ref<OpenXRAction> p_action) {
|
||||
void OpenXRInteractionProfileEditorBase::_update_interaction_profile() {
|
||||
if (!is_dirty) {
|
||||
// no need to update
|
||||
return;
|
||||
}
|
||||
|
||||
// Nothing to do here for now..
|
||||
|
||||
// and we've updated it...
|
||||
is_dirty = false;
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditorBase::_theme_changed() {
|
||||
if (binding_modifiers_btn) {
|
||||
binding_modifiers_btn->set_button_icon(get_theme_icon(SNAME("Modifiers"), EditorStringName(EditorIcons)));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditorBase::remove_all_for_action_set(Ref<OpenXRActionSet> p_action_set) {
|
||||
// Note, don't need to remove bindings themselves as remove_all_for_action will be called for each before this is called.
|
||||
|
||||
// TODO update binding modifiers
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditorBase::remove_all_for_action(Ref<OpenXRAction> p_action) {
|
||||
Vector<Ref<OpenXRIPBinding>> bindings = interaction_profile->get_bindings_for_action(p_action);
|
||||
if (bindings.size() > 0) {
|
||||
String action_name = p_action->get_name_with_set();
|
||||
|
||||
// for our undo/redo we process all paths
|
||||
// For our undo/redo we process all paths
|
||||
undo_redo->create_action(TTR("Remove action from interaction profile"));
|
||||
for (const Ref<OpenXRIPBinding> &binding : bindings) {
|
||||
undo_redo->add_do_method(this, "_remove_binding", action_name, binding->get_binding_path());
|
||||
|
@ -125,7 +145,7 @@ void OpenXRInteractionProfileEditorBase::remove_all_bindings_for_action(Ref<Open
|
|||
}
|
||||
undo_redo->commit_action(false);
|
||||
|
||||
// but we take a shortcut here :)
|
||||
// But remove them all in one go so we're more efficient in updating our UI.
|
||||
for (const Ref<OpenXRIPBinding> &binding : bindings) {
|
||||
interaction_profile->remove_binding(binding);
|
||||
}
|
||||
|
@ -137,10 +157,39 @@ void OpenXRInteractionProfileEditorBase::remove_all_bindings_for_action(Ref<Open
|
|||
_do_update_interaction_profile();
|
||||
}
|
||||
}
|
||||
void OpenXRInteractionProfileEditorBase::_on_open_binding_modifiers() {
|
||||
binding_modifiers_dialog->popup_centered(Size2i(500, 400));
|
||||
}
|
||||
|
||||
OpenXRInteractionProfileEditorBase::OpenXRInteractionProfileEditorBase(Ref<OpenXRActionMap> p_action_map, Ref<OpenXRInteractionProfile> p_interaction_profile) {
|
||||
OpenXRInteractionProfileEditorBase::OpenXRInteractionProfileEditorBase() {
|
||||
undo_redo = EditorUndoRedoManager::get_singleton();
|
||||
|
||||
set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
interaction_profile_sc = memnew(ScrollContainer);
|
||||
interaction_profile_sc->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
interaction_profile_sc->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
add_child(interaction_profile_sc);
|
||||
|
||||
binding_modifiers_dialog = memnew(OpenXRBindingModifiersDialog);
|
||||
add_child(binding_modifiers_dialog);
|
||||
|
||||
toolbar_vb = memnew(VBoxContainer);
|
||||
toolbar_vb->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
add_child(toolbar_vb);
|
||||
|
||||
binding_modifiers_btn = memnew(Button);
|
||||
binding_modifiers_btn->set_tooltip_text(TTR("Edit binding modifiers"));
|
||||
binding_modifiers_btn->connect("pressed", callable_mp(this, &OpenXRInteractionProfileEditorBase::_on_open_binding_modifiers));
|
||||
// TODO show visual difference if there are binding modifiers for this interaction profile
|
||||
toolbar_vb->add_child(binding_modifiers_btn);
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditorBase::setup(Ref<OpenXRActionMap> p_action_map, Ref<OpenXRInteractionProfile> p_interaction_profile) {
|
||||
ERR_FAIL_NULL(binding_modifiers_dialog);
|
||||
binding_modifiers_dialog->setup(p_action_map, p_interaction_profile);
|
||||
|
||||
action_map = p_action_map;
|
||||
interaction_profile = p_interaction_profile;
|
||||
String profile_path = interaction_profile->get_interaction_profile_path();
|
||||
|
@ -149,11 +198,15 @@ OpenXRInteractionProfileEditorBase::OpenXRInteractionProfileEditorBase(Ref<OpenX
|
|||
profile_def = OpenXRInteractionProfileMetadata::get_singleton()->get_profile(profile_path);
|
||||
if (profile_def != nullptr) {
|
||||
profile_name = profile_def->display_name;
|
||||
|
||||
if (!profile_def->openxr_extension_name.is_empty()) {
|
||||
profile_name += "*";
|
||||
|
||||
tooltip = vformat(TTR("Note: This interaction profile requires extension %s support."), profile_def->openxr_extension_name);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -167,7 +220,7 @@ void OpenXRInteractionProfileEditor::select_action_for(const String p_io_path) {
|
|||
select_action_dialog->open();
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditor::action_selected(const String p_action) {
|
||||
void OpenXRInteractionProfileEditor::_on_action_selected(const String p_action) {
|
||||
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);
|
||||
|
@ -189,7 +242,12 @@ void OpenXRInteractionProfileEditor::_add_io_path(VBoxContainer *p_container, co
|
|||
p_container->add_child(path_hb);
|
||||
|
||||
Label *path_label = memnew(Label);
|
||||
path_label->set_text(p_io_path->display_name);
|
||||
if (p_io_path->openxr_extension_name.is_empty()) {
|
||||
path_label->set_text(p_io_path->display_name);
|
||||
} else {
|
||||
path_label->set_text(p_io_path->display_name + "*");
|
||||
p_container->set_tooltip_text(vformat(TTR("Note: This binding path requires extension %s support."), p_io_path->openxr_extension_name));
|
||||
}
|
||||
path_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
path_hb->add_child(path_label);
|
||||
|
||||
|
@ -243,6 +301,17 @@ void OpenXRInteractionProfileEditor::_add_io_path(VBoxContainer *p_container, co
|
|||
action_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
action_hb->add_child(action_label);
|
||||
|
||||
OpenXRBindingModifiersDialog *action_binding_modifiers_dialog = memnew(OpenXRBindingModifiersDialog);
|
||||
action_binding_modifiers_dialog->setup(action_map, interaction_profile, binding);
|
||||
action_hb->add_child(action_binding_modifiers_dialog);
|
||||
|
||||
Button *action_binding_modifiers_btn = memnew(Button);
|
||||
action_binding_modifiers_btn->set_flat(true);
|
||||
action_binding_modifiers_btn->set_button_icon(get_theme_icon(SNAME("Modifiers"), EditorStringName(EditorIcons)));
|
||||
action_binding_modifiers_btn->connect(SceneStringName(pressed), callable_mp((Window *)action_binding_modifiers_dialog, &Window::popup_centered).bind(Size2i(500, 400)));
|
||||
// TODO change style of button if there are binding modifiers
|
||||
action_hb->add_child(action_binding_modifiers_btn);
|
||||
|
||||
Button *action_rem = memnew(Button);
|
||||
action_rem->set_flat(true);
|
||||
action_rem->set_button_icon(get_theme_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
|
||||
|
@ -261,9 +330,11 @@ void OpenXRInteractionProfileEditor::_update_interaction_profile() {
|
|||
return;
|
||||
}
|
||||
|
||||
PackedStringArray requested_extensions = OpenXRAPI::get_all_requested_extensions();
|
||||
|
||||
// out with the old...
|
||||
while (main_hb->get_child_count() > 0) {
|
||||
memdelete(main_hb->get_child(0));
|
||||
while (interaction_profile_hb->get_child_count() > 0) {
|
||||
memdelete(interaction_profile_hb->get_child(0));
|
||||
}
|
||||
|
||||
// in with the new...
|
||||
|
@ -281,7 +352,7 @@ void OpenXRInteractionProfileEditor::_update_interaction_profile() {
|
|||
for (int i = 0; i < top_level_paths.size(); i++) {
|
||||
PanelContainer *panel = memnew(PanelContainer);
|
||||
panel->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
main_hb->add_child(panel);
|
||||
interaction_profile_hb->add_child(panel);
|
||||
panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("TabContainer")));
|
||||
|
||||
VBoxContainer *container = memnew(VBoxContainer);
|
||||
|
@ -293,31 +364,37 @@ void OpenXRInteractionProfileEditor::_update_interaction_profile() {
|
|||
|
||||
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]) {
|
||||
if (io_path->top_level_path == top_level_paths[i] && (io_path->openxr_extension_name.is_empty() || requested_extensions.has(io_path->openxr_extension_name))) {
|
||||
_add_io_path(container, io_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// and we've updated it...
|
||||
is_dirty = false;
|
||||
OpenXRInteractionProfileEditorBase::_update_interaction_profile();
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditor::_theme_changed() {
|
||||
for (int i = 0; i < main_hb->get_child_count(); i++) {
|
||||
Control *panel = Object::cast_to<Control>(main_hb->get_child(i));
|
||||
OpenXRInteractionProfileEditorBase::_theme_changed();
|
||||
|
||||
interaction_profile_sc->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
|
||||
|
||||
for (int i = 0; i < interaction_profile_hb->get_child_count(); i++) {
|
||||
Control *panel = Object::cast_to<Control>(interaction_profile_hb->get_child(i));
|
||||
if (panel) {
|
||||
panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("TabContainer")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OpenXRInteractionProfileEditor::OpenXRInteractionProfileEditor(Ref<OpenXRActionMap> p_action_map, Ref<OpenXRInteractionProfile> p_interaction_profile) :
|
||||
OpenXRInteractionProfileEditorBase(p_action_map, p_interaction_profile) {
|
||||
main_hb = memnew(HBoxContainer);
|
||||
add_child(main_hb);
|
||||
OpenXRInteractionProfileEditor::OpenXRInteractionProfileEditor() {
|
||||
interaction_profile_hb = memnew(HBoxContainer);
|
||||
interaction_profile_sc->add_child(interaction_profile_hb);
|
||||
}
|
||||
|
||||
void OpenXRInteractionProfileEditor::setup(Ref<OpenXRActionMap> p_action_map, Ref<OpenXRInteractionProfile> p_interaction_profile) {
|
||||
OpenXRInteractionProfileEditorBase::setup(p_action_map, p_interaction_profile);
|
||||
|
||||
select_action_dialog = memnew(OpenXRSelectActionDialog(p_action_map));
|
||||
select_action_dialog->connect("action_selected", callable_mp(this, &OpenXRInteractionProfileEditor::action_selected));
|
||||
select_action_dialog->connect("action_selected", callable_mp(this, &OpenXRInteractionProfileEditor::_on_action_selected));
|
||||
add_child(select_action_dialog);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue