1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Redesign InputEvent editor plugin

- Use vertical layout and add text wrapping
- Fix Window.popup_centered() rect calculation
This commit is contained in:
FireForge
2022-04-07 17:46:49 -05:00
parent 43f94c95aa
commit 0b0a74e135
5 changed files with 31 additions and 33 deletions

View File

@@ -589,8 +589,6 @@ void InputEventConfigurationDialog::_notification(int p_what) {
icon_cache.joypad_button = get_theme_icon(SNAME("JoyButton"), SNAME("EditorIcons")); icon_cache.joypad_button = get_theme_icon(SNAME("JoyButton"), SNAME("EditorIcons"));
icon_cache.joypad_axis = get_theme_icon(SNAME("JoyAxis"), SNAME("EditorIcons")); icon_cache.joypad_axis = get_theme_icon(SNAME("JoyAxis"), SNAME("EditorIcons"));
mouse_detection_rect->set_color(get_theme_color(SNAME("dark_color_2"), SNAME("Editor")));
_update_input_list(); _update_input_list();
} break; } break;
} }
@@ -624,7 +622,7 @@ void InputEventConfigurationDialog::popup_and_configure(const Ref<InputEvent> &p
device_id_option->select(0); device_id_option->select(0);
} }
popup_centered(); popup_centered(Size2(0, 400) * EDSCALE);
} }
Ref<InputEvent> InputEventConfigurationDialog::get_event() const { Ref<InputEvent> InputEventConfigurationDialog::get_event() const {
@@ -656,8 +654,8 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() {
event_as_text = memnew(Label); event_as_text = memnew(Label);
event_as_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); event_as_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
vb->add_child(event_as_text); vb->add_child(event_as_text);
// Mouse button detection rect (Mouse button event outside this ColorRect will be ignored) // Mouse button detection rect (Mouse button event outside this rect will be ignored)
mouse_detection_rect = memnew(ColorRect); mouse_detection_rect = memnew(Panel);
mouse_detection_rect->set_v_size_flags(Control::SIZE_EXPAND_FILL); mouse_detection_rect->set_v_size_flags(Control::SIZE_EXPAND_FILL);
vb->add_child(mouse_detection_rect); vb->add_child(mouse_detection_rect);
tab_container->add_child(vb); tab_container->add_child(vb);
@@ -1171,7 +1169,7 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
void ActionMapEditor::show_message(const String &p_message) { void ActionMapEditor::show_message(const String &p_message) {
message->set_text(p_message); message->set_text(p_message);
message->popup_centered(Size2(300, 100) * EDSCALE); message->popup_centered();
} }
void ActionMapEditor::use_external_search_box(LineEdit *p_searchbox) { void ActionMapEditor::use_external_search_box(LineEdit *p_searchbox) {

View File

@@ -67,7 +67,7 @@ private:
// Listening for input // Listening for input
Label *event_as_text = nullptr; Label *event_as_text = nullptr;
ColorRect *mouse_detection_rect = nullptr; Panel *mouse_detection_rect = nullptr;
// List of All Key/Mouse/Joypad input options. // List of All Key/Mouse/Joypad input options.
int allowed_input_types; int allowed_input_types;

View File

@@ -33,6 +33,15 @@
void InputEventConfigContainer::_bind_methods() { 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() { void InputEventConfigContainer::_configure_pressed() {
config_dialog->popup_and_configure(input_event); config_dialog->popup_and_configure(input_event);
} }
@@ -47,12 +56,6 @@ void InputEventConfigContainer::_config_dialog_confirmed() {
_event_changed(); _event_changed();
} }
Size2 InputEventConfigContainer::get_minimum_size() const {
// Don't bother with a minimum x size for the control - we don't want the inspector
// to jump in size if a long text is placed in the label (e.g. Joypad Axis description)
return Size2(0, HBoxContainer::get_minimum_size().y);
}
void InputEventConfigContainer::set_event(const Ref<InputEvent> &p_event) { void InputEventConfigContainer::set_event(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event; Ref<InputEventKey> k = p_event;
Ref<InputEventMouseButton> m = p_event; Ref<InputEventMouseButton> m = p_event;
@@ -75,29 +78,26 @@ void InputEventConfigContainer::set_event(const Ref<InputEvent> &p_event) {
} }
InputEventConfigContainer::InputEventConfigContainer() { InputEventConfigContainer::InputEventConfigContainer() {
MarginContainer *mc = memnew(MarginContainer); input_event_text = memnew(Label);
mc->add_theme_constant_override("margin_left", 10); input_event_text->set_h_size_flags(SIZE_EXPAND_FILL);
mc->add_theme_constant_override("margin_right", 10); input_event_text->set_autowrap_mode(Label::AutowrapMode::AUTOWRAP_WORD_SMART);
mc->add_theme_constant_override("margin_top", 10); input_event_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
mc->add_theme_constant_override("margin_bottom", 10); add_child(input_event_text);
add_child(mc);
HBoxContainer *hb = memnew(HBoxContainer);
mc->add_child(hb);
open_config_button = memnew(Button); open_config_button = memnew(Button);
open_config_button->set_text(TTR("Configure")); open_config_button->set_text(TTR("Configure"));
open_config_button->connect("pressed", callable_mp(this, &InputEventConfigContainer::_configure_pressed)); open_config_button->connect("pressed", callable_mp(this, &InputEventConfigContainer::_configure_pressed));
hb->add_child(open_config_button); add_child(open_config_button);
input_event_text = memnew(Label); add_child(memnew(Control));
hb->add_child(input_event_text);
config_dialog = memnew(InputEventConfigurationDialog); config_dialog = memnew(InputEventConfigurationDialog);
config_dialog->connect("confirmed", callable_mp(this, &InputEventConfigContainer::_config_dialog_confirmed)); config_dialog->connect("confirmed", callable_mp(this, &InputEventConfigContainer::_config_dialog_confirmed));
add_child(config_dialog); add_child(config_dialog);
} }
///////////////////////
bool EditorInspectorPluginInputEvent::can_handle(Object *p_object) { bool EditorInspectorPluginInputEvent::can_handle(Object *p_object) {
Ref<InputEventKey> k = Ref<InputEventKey>(p_object); Ref<InputEventKey> k = Ref<InputEventKey>(p_object);
Ref<InputEventMouseButton> m = Ref<InputEventMouseButton>(p_object); Ref<InputEventMouseButton> m = Ref<InputEventMouseButton>(p_object);
@@ -115,6 +115,8 @@ void EditorInspectorPluginInputEvent::parse_begin(Object *p_object) {
add_custom_control(picker_controls); add_custom_control(picker_controls);
} }
///////////////////////
InputEventEditorPlugin::InputEventEditorPlugin() { InputEventEditorPlugin::InputEventEditorPlugin() {
Ref<EditorInspectorPluginInputEvent> plugin; Ref<EditorInspectorPluginInputEvent> plugin;
plugin.instantiate(); plugin.instantiate();

View File

@@ -35,8 +35,8 @@
#include "editor/editor_inspector.h" #include "editor/editor_inspector.h"
#include "editor/editor_plugin.h" #include "editor/editor_plugin.h"
class InputEventConfigContainer : public HBoxContainer { class InputEventConfigContainer : public VBoxContainer {
GDCLASS(InputEventConfigContainer, HBoxContainer); GDCLASS(InputEventConfigContainer, VBoxContainer);
Label *input_event_text = nullptr; Label *input_event_text = nullptr;
Button *open_config_button = nullptr; Button *open_config_button = nullptr;
@@ -50,10 +50,10 @@ class InputEventConfigContainer : public HBoxContainer {
void _event_changed(); void _event_changed();
protected: protected:
void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
public: public:
virtual Size2 get_minimum_size() const override;
void set_event(const Ref<InputEvent> &p_event); void set_event(const Ref<InputEvent> &p_event);
InputEventConfigContainer(); InputEventConfigContainer();

View File

@@ -1066,11 +1066,9 @@ void Window::popup_centered(const Size2i &p_minsize) {
} }
Rect2i popup_rect; Rect2i popup_rect;
if (p_minsize == Size2i()) { Size2 contents_minsize = _get_contents_minimum_size();
popup_rect.size = _get_contents_minimum_size(); popup_rect.size.x = MAX(p_minsize.x, contents_minsize.x);
} else { popup_rect.size.y = MAX(p_minsize.y, contents_minsize.y);
popup_rect.size = p_minsize;
}
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2; popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
popup(popup_rect); popup(popup_rect);