Path: blob/master/modules/openxr/editor/openxr_select_action_dialog.cpp
10278 views
/**************************************************************************/1/* openxr_select_action_dialog.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "openxr_select_action_dialog.h"3132#include "editor/themes/editor_scale.h"3334void OpenXRSelectActionDialog::_bind_methods() {35ADD_SIGNAL(MethodInfo("action_selected", PropertyInfo(Variant::STRING, "action")));36}3738void OpenXRSelectActionDialog::_notification(int p_what) {39switch (p_what) {40case NOTIFICATION_THEME_CHANGED: {41scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));42} break;43}44}4546void OpenXRSelectActionDialog::_on_select_action(const String p_action) {47if (selected_action != "") {48NodePath button_path = action_buttons[selected_action];49Button *button = Object::cast_to<Button>(get_node(button_path));50if (button != nullptr) {51button->set_flat(true);52}53}5455selected_action = p_action;5657if (selected_action != "") {58NodePath button_path = action_buttons[selected_action];59Button *button = Object::cast_to<Button>(get_node(button_path));60if (button != nullptr) {61button->set_flat(false);62}63}64}6566void OpenXRSelectActionDialog::open() {67ERR_FAIL_COND(action_map.is_null());6869// Out with the old.70while (main_vb->get_child_count() > 0) {71memdelete(main_vb->get_child(0));72}7374selected_action = "";75action_buttons.clear();7677// In with the new.78Array action_sets = action_map->get_action_sets();79for (int i = 0; i < action_sets.size(); i++) {80Ref<OpenXRActionSet> action_set = action_sets[i];8182Label *action_set_label = memnew(Label);83action_set_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);84action_set_label->set_text(action_set->get_localized_name());85main_vb->add_child(action_set_label);8687Array actions = action_set->get_actions();88for (int j = 0; j < actions.size(); j++) {89Ref<OpenXRAction> action = actions[j];9091HBoxContainer *action_hb = memnew(HBoxContainer);92main_vb->add_child(action_hb);9394Control *indent_node = memnew(Control);95indent_node->set_custom_minimum_size(Size2(10.0, 0.0));96action_hb->add_child(indent_node);9798Button *action_button = memnew(Button);99String action_name = action->get_name_with_set();100action_button->set_flat(true);101action_button->set_text(action->get_name() + ": " + action->get_localized_name());102action_button->connect(SceneStringName(pressed), callable_mp(this, &OpenXRSelectActionDialog::_on_select_action).bind(action_name));103action_hb->add_child(action_button);104105action_buttons[action_name] = action_button->get_path();106}107}108109popup_centered();110}111112void OpenXRSelectActionDialog::ok_pressed() {113if (selected_action == "") {114return;115}116117emit_signal("action_selected", selected_action);118119hide();120}121122OpenXRSelectActionDialog::OpenXRSelectActionDialog(Ref<OpenXRActionMap> p_action_map) {123action_map = p_action_map;124125set_title(TTR("Select an action"));126127scroll = memnew(ScrollContainer);128scroll->set_custom_minimum_size(Size2(600.0 * EDSCALE, 400.0 * EDSCALE));129add_child(scroll);130131main_vb = memnew(VBoxContainer);132main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);133scroll->add_child(main_vb);134}135136137