fd6453c45e
This reverts commit 4b817a565c
.
Fixes #64988.
Fixes #64997.
This caused several regressions (#64988, #64997,
https://github.com/godotengine/godot/issues/64997#issuecomment-1229970605)
which point at a flaw in the current logic:
- `Control::NOTIFICATION_ENTER_TREE` triggers a *deferred* notification with
`NOTIFCATION_THEME_CHANGED` as introduced in #62845.
- Some classes use their `THEME_CHANGED` to cache theme items in
member variables (e.g. `style_normal`, etc.), and use those member
variables in `ENTER_TREE`, `READY`, `DRAW`, etc. Since the `THEME_CHANGE`
notification is now deferred, they end up accessing invalid state and this
can lead to not applying theme properly (e.g. for EditorHelp) or crashing
(e.g. for EditorLog or CodeEdit).
So we need to go back to the drawing board and see if `THEME_CHANGED` can be
called earlier so that the previous logic still works?
Or can we refactor all engine code to make sure that:
- `ENTER_TREE` and similar do not depend on theme properties cached in member
variables.
- Or `THEME_CHANGE` does trigger a general UI update to make sure that any
bad theme handling in `ENTER_TREE` and co. gets fixed when `THEME_CHANGE`
does arrive for the first time. But that means having a temporary invalid
(and possibly still crashing) state, and doing some computations twice
which might be heavy (e.g. `EditorHelp::_update_doc()`).
123 lines
5.4 KiB
C++
123 lines
5.4 KiB
C++
/*************************************************************************/
|
|
/* input_event_editor_plugin.cpp */
|
|
/*************************************************************************/
|
|
/* This file is part of: */
|
|
/* GODOT ENGINE */
|
|
/* https://godotengine.org */
|
|
/*************************************************************************/
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
|
/* */
|
|
/* 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"
|
|
|
|
void InputEventConfigContainer::_bind_methods() {
|
|
}
|
|
|
|
void InputEventConfigContainer::_notification(int p_what) {
|
|
switch (p_what) {
|
|
case NOTIFICATION_ENTER_TREE:
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
open_config_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
|
|
} break;
|
|
}
|
|
}
|
|
|
|
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()) {
|
|
config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_KEY);
|
|
} else if (m.is_valid()) {
|
|
config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_MOUSE_BUTTON);
|
|
} else if (jb.is_valid()) {
|
|
config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_JOY_BUTTON);
|
|
} else if (jm.is_valid()) {
|
|
config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_JOY_MOTION);
|
|
}
|
|
|
|
input_event = p_event;
|
|
_event_changed();
|
|
input_event->connect("changed", callable_mp(this, &InputEventConfigContainer::_event_changed));
|
|
}
|
|
|
|
InputEventConfigContainer::InputEventConfigContainer() {
|
|
input_event_text = memnew(Label);
|
|
input_event_text->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
input_event_text->set_autowrap_mode(TextServer::AutowrapMode::AUTOWRAP_WORD_SMART);
|
|
input_event_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
|
add_child(input_event_text);
|
|
|
|
open_config_button = EditorInspector::create_inspector_action_button(TTR("Configure"));
|
|
open_config_button->connect("pressed", callable_mp(this, &InputEventConfigContainer::_configure_pressed));
|
|
add_child(open_config_button);
|
|
|
|
add_child(memnew(Control));
|
|
|
|
config_dialog = memnew(InputEventConfigurationDialog);
|
|
config_dialog->connect("confirmed", callable_mp(this, &InputEventConfigContainer::_config_dialog_confirmed));
|
|
add_child(config_dialog);
|
|
}
|
|
|
|
///////////////////////
|
|
|
|
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);
|
|
}
|
|
|
|
///////////////////////
|
|
|
|
InputEventEditorPlugin::InputEventEditorPlugin() {
|
|
Ref<EditorInspectorPluginInputEvent> plugin;
|
|
plugin.instantiate();
|
|
add_inspector_plugin(plugin);
|
|
}
|