1 | /**************************************************************************/ |
2 | /* openxr_action_editor.cpp */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #include "openxr_action_editor.h" |
32 | |
33 | #include "editor/editor_string_names.h" |
34 | |
35 | void OpenXRActionEditor::_bind_methods() { |
36 | ClassDB::bind_method(D_METHOD("_do_set_name" , "name" ), &OpenXRActionEditor::_do_set_name); |
37 | ClassDB::bind_method(D_METHOD("_do_set_localized_name" , "name" ), &OpenXRActionEditor::_do_set_localized_name); |
38 | ClassDB::bind_method(D_METHOD("_do_set_action_type" , "type" ), &OpenXRActionEditor::_do_set_action_type); |
39 | |
40 | ADD_SIGNAL(MethodInfo("remove" , PropertyInfo(Variant::OBJECT, "action_editor" ))); |
41 | } |
42 | |
43 | void OpenXRActionEditor::_theme_changed() { |
44 | rem_action->set_icon(get_theme_icon(SNAME("Remove" ), EditorStringName(EditorIcons))); |
45 | } |
46 | |
47 | void OpenXRActionEditor::_notification(int p_what) { |
48 | switch (p_what) { |
49 | case NOTIFICATION_ENTER_TREE: |
50 | case NOTIFICATION_THEME_CHANGED: { |
51 | _theme_changed(); |
52 | } break; |
53 | } |
54 | } |
55 | |
56 | void OpenXRActionEditor::_on_action_name_changed(const String p_new_text) { |
57 | if (action->get_name() != p_new_text) { |
58 | undo_redo->create_action(TTR("Rename Action" )); |
59 | undo_redo->add_do_method(this, "_do_set_name" , p_new_text); |
60 | undo_redo->add_undo_method(this, "_do_set_name" , action->get_name()); |
61 | undo_redo->commit_action(false); |
62 | |
63 | // If our localized name matches our action name, set this too |
64 | if (action->get_name() == action->get_localized_name()) { |
65 | undo_redo->create_action(TTR("Rename Actions Localized name" )); |
66 | undo_redo->add_do_method(this, "_do_set_localized_name" , p_new_text); |
67 | undo_redo->add_undo_method(this, "_do_set_localized_name" , action->get_localized_name()); |
68 | undo_redo->commit_action(false); |
69 | |
70 | action->set_localized_name(p_new_text); |
71 | action_localized_name->set_text(p_new_text); |
72 | } |
73 | action->set_name(p_new_text); |
74 | action->set_edited(true); |
75 | } |
76 | } |
77 | |
78 | void OpenXRActionEditor::_do_set_name(const String p_new_text) { |
79 | action->set_name(p_new_text); |
80 | action->set_edited(true); |
81 | action_name->set_text(p_new_text); |
82 | } |
83 | |
84 | void OpenXRActionEditor::_on_action_localized_name_changed(const String p_new_text) { |
85 | if (action->get_localized_name() != p_new_text) { |
86 | undo_redo->create_action(TTR("Rename Actions Localized name" )); |
87 | undo_redo->add_do_method(this, "_do_set_localized_name" , p_new_text); |
88 | undo_redo->add_undo_method(this, "_do_set_localized_name" , action->get_localized_name()); |
89 | undo_redo->commit_action(false); |
90 | |
91 | action->set_localized_name(p_new_text); |
92 | action->set_edited(true); |
93 | } |
94 | } |
95 | |
96 | void OpenXRActionEditor::_do_set_localized_name(const String p_new_text) { |
97 | action->set_localized_name(p_new_text); |
98 | action->set_edited(true); |
99 | action_localized_name->set_text(p_new_text); |
100 | } |
101 | |
102 | void OpenXRActionEditor::_on_item_selected(int p_idx) { |
103 | ERR_FAIL_INDEX(p_idx, OpenXRAction::OPENXR_ACTION_MAX); |
104 | |
105 | OpenXRAction::ActionType action_type = OpenXRAction::ActionType(p_idx); |
106 | |
107 | if (action->get_action_type() != action_type) { |
108 | undo_redo->create_action(TTR("Change Action Type" )); |
109 | undo_redo->add_do_method(this, "_do_set_action_type" , action_type); |
110 | undo_redo->add_undo_method(this, "_do_set_action_type" , action->get_action_type()); |
111 | undo_redo->commit_action(false); |
112 | |
113 | action->set_action_type(action_type); |
114 | action->set_edited(true); |
115 | } |
116 | } |
117 | |
118 | void OpenXRActionEditor::_do_set_action_type(OpenXRAction::ActionType p_action_type) { |
119 | action->set_action_type(p_action_type); |
120 | action->set_edited(true); |
121 | action_type_button->select(int(action->get_action_type())); |
122 | } |
123 | |
124 | void OpenXRActionEditor::_on_remove_action() { |
125 | emit_signal("remove" , this); |
126 | } |
127 | |
128 | OpenXRActionEditor::OpenXRActionEditor(Ref<OpenXRAction> p_action) { |
129 | undo_redo = EditorUndoRedoManager::get_singleton(); |
130 | action = p_action; |
131 | |
132 | set_h_size_flags(Control::SIZE_EXPAND_FILL); |
133 | |
134 | action_name = memnew(LineEdit); |
135 | action_name->set_text(action->get_name()); |
136 | action_name->set_custom_minimum_size(Size2(150.0, 0.0)); |
137 | action_name->connect("text_changed" , callable_mp(this, &OpenXRActionEditor::_on_action_name_changed)); |
138 | add_child(action_name); |
139 | |
140 | action_localized_name = memnew(LineEdit); |
141 | action_localized_name->set_text(action->get_localized_name()); |
142 | action_localized_name->set_custom_minimum_size(Size2(150.0, 0.0)); |
143 | action_localized_name->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
144 | action_localized_name->connect("text_changed" , callable_mp(this, &OpenXRActionEditor::_on_action_localized_name_changed)); |
145 | add_child(action_localized_name); |
146 | |
147 | action_type_button = memnew(OptionButton); |
148 | action_type_button->add_item("Bool" , OpenXRAction::OPENXR_ACTION_BOOL); |
149 | action_type_button->add_item("Float" , OpenXRAction::OPENXR_ACTION_FLOAT); |
150 | action_type_button->add_item("Vector2" , OpenXRAction::OPENXR_ACTION_VECTOR2); |
151 | action_type_button->add_item("Pose" , OpenXRAction::OPENXR_ACTION_POSE); |
152 | action_type_button->add_item("Haptic" , OpenXRAction::OPENXR_ACTION_HAPTIC); |
153 | action_type_button->select(int(action->get_action_type())); |
154 | action_type_button->set_custom_minimum_size(Size2(100.0, 0.0)); |
155 | action_type_button->connect("item_selected" , callable_mp(this, &OpenXRActionEditor::_on_item_selected)); |
156 | add_child(action_type_button); |
157 | |
158 | // maybe add dropdown to edit our toplevel paths, or do we deduce them from our suggested bindings? |
159 | |
160 | rem_action = memnew(Button); |
161 | rem_action->set_tooltip_text(TTR("Remove action" )); |
162 | rem_action->connect("pressed" , callable_mp(this, &OpenXRActionEditor::_on_remove_action)); |
163 | rem_action->set_flat(true); |
164 | add_child(rem_action); |
165 | } |
166 | |