2021-06-27 16:15:56 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* input_event_editor_plugin.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#include "input_event_editor_plugin.h"
|
|
|
|
|
2022-10-05 14:42:12 +02:00
|
|
|
#include "editor/event_listener_line_edit.h"
|
|
|
|
#include "editor/input_event_configuration_dialog.h"
|
|
|
|
|
2021-06-27 16:15:56 +02:00
|
|
|
void InputEventConfigContainer::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
2022-04-08 00:46:49 +02:00
|
|
|
void InputEventConfigContainer::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2022-08-29 11:04:31 +02:00
|
|
|
case NOTIFICATION_ENTER_TREE:
|
2022-04-08 00:46:49 +02:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2023-08-13 02:33:39 +02:00
|
|
|
open_config_button->set_icon(get_editor_theme_icon(SNAME("Edit")));
|
2022-04-08 00:46:49 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-27 16:15:56 +02:00
|
|
|
void InputEventConfigContainer::_configure_pressed() {
|
|
|
|
config_dialog->popup_and_configure(input_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventConfigContainer::_event_changed() {
|
|
|
|
input_event_text->set_text(input_event->as_text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventConfigContainer::_config_dialog_confirmed() {
|
|
|
|
Ref<InputEvent> ie = config_dialog->get_event();
|
|
|
|
input_event->copy_from(ie);
|
|
|
|
_event_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventConfigContainer::set_event(const Ref<InputEvent> &p_event) {
|
|
|
|
Ref<InputEventKey> k = p_event;
|
|
|
|
Ref<InputEventMouseButton> m = p_event;
|
|
|
|
Ref<InputEventJoypadButton> jb = p_event;
|
|
|
|
Ref<InputEventJoypadMotion> jm = p_event;
|
|
|
|
|
|
|
|
if (k.is_valid()) {
|
2022-10-02 16:50:05 +02:00
|
|
|
config_dialog->set_allowed_input_types(INPUT_KEY);
|
2021-06-27 16:15:56 +02:00
|
|
|
} else if (m.is_valid()) {
|
2022-10-02 16:50:05 +02:00
|
|
|
config_dialog->set_allowed_input_types(INPUT_MOUSE_BUTTON);
|
2021-06-27 16:15:56 +02:00
|
|
|
} else if (jb.is_valid()) {
|
2022-10-02 16:50:05 +02:00
|
|
|
config_dialog->set_allowed_input_types(INPUT_JOY_BUTTON);
|
2021-06-27 16:15:56 +02:00
|
|
|
} else if (jm.is_valid()) {
|
2022-10-02 16:50:05 +02:00
|
|
|
config_dialog->set_allowed_input_types(INPUT_JOY_MOTION);
|
2021-06-27 16:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
input_event = p_event;
|
|
|
|
_event_changed();
|
2023-07-03 21:29:37 +02:00
|
|
|
input_event->connect_changed(callable_mp(this, &InputEventConfigContainer::_event_changed));
|
2021-06-27 16:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InputEventConfigContainer::InputEventConfigContainer() {
|
2022-04-08 00:46:49 +02:00
|
|
|
input_event_text = memnew(Label);
|
|
|
|
input_event_text->set_h_size_flags(SIZE_EXPAND_FILL);
|
2022-06-15 10:01:45 +02:00
|
|
|
input_event_text->set_autowrap_mode(TextServer::AutowrapMode::AUTOWRAP_WORD_SMART);
|
2022-04-08 00:46:49 +02:00
|
|
|
input_event_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
|
|
|
add_child(input_event_text);
|
2021-06-27 16:15:56 +02:00
|
|
|
|
2022-06-15 08:44:16 +02:00
|
|
|
open_config_button = EditorInspector::create_inspector_action_button(TTR("Configure"));
|
2024-05-14 09:40:21 +02:00
|
|
|
open_config_button->connect(SceneStringName(pressed), callable_mp(this, &InputEventConfigContainer::_configure_pressed));
|
2022-04-08 00:46:49 +02:00
|
|
|
add_child(open_config_button);
|
2021-06-27 16:15:56 +02:00
|
|
|
|
2022-04-08 00:46:49 +02:00
|
|
|
add_child(memnew(Control));
|
2021-06-27 16:15:56 +02:00
|
|
|
|
|
|
|
config_dialog = memnew(InputEventConfigurationDialog);
|
2024-05-14 14:28:18 +02:00
|
|
|
config_dialog->connect(SceneStringName(confirmed), callable_mp(this, &InputEventConfigContainer::_config_dialog_confirmed));
|
2021-06-27 16:15:56 +02:00
|
|
|
add_child(config_dialog);
|
|
|
|
}
|
|
|
|
|
2022-04-08 00:46:49 +02:00
|
|
|
///////////////////////
|
|
|
|
|
2021-06-27 16:15:56 +02:00
|
|
|
bool EditorInspectorPluginInputEvent::can_handle(Object *p_object) {
|
|
|
|
Ref<InputEventKey> k = Ref<InputEventKey>(p_object);
|
|
|
|
Ref<InputEventMouseButton> m = Ref<InputEventMouseButton>(p_object);
|
|
|
|
Ref<InputEventJoypadButton> jb = Ref<InputEventJoypadButton>(p_object);
|
|
|
|
Ref<InputEventJoypadMotion> jm = Ref<InputEventJoypadMotion>(p_object);
|
|
|
|
|
|
|
|
return k.is_valid() || m.is_valid() || jb.is_valid() || jm.is_valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorInspectorPluginInputEvent::parse_begin(Object *p_object) {
|
|
|
|
Ref<InputEvent> ie = Ref<InputEvent>(p_object);
|
|
|
|
|
|
|
|
InputEventConfigContainer *picker_controls = memnew(InputEventConfigContainer);
|
|
|
|
picker_controls->set_event(ie);
|
|
|
|
add_custom_control(picker_controls);
|
|
|
|
}
|
|
|
|
|
2022-04-08 00:46:49 +02:00
|
|
|
///////////////////////
|
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
InputEventEditorPlugin::InputEventEditorPlugin() {
|
2021-06-27 16:15:56 +02:00
|
|
|
Ref<EditorInspectorPluginInputEvent> plugin;
|
|
|
|
plugin.instantiate();
|
|
|
|
add_inspector_plugin(plugin);
|
|
|
|
}
|