New ActionMapEditor to replace InputMapEditor. Used in ProjectSettings.

Renamed to ActionMapEditor as it is more generic and can be used for more than just the InputMapEditor if required.
This also includes a new Event Configuration dialog (previously "Press A key...") which can be used to create and edit InputEvents for any use - like the Project Settings input map, or the Editor Settings shortcuts.
This commit is contained in:
Eric M 2020-10-01 23:04:57 +10:00
parent aeea4280a0
commit 3db45ff198
7 changed files with 1594 additions and 1160 deletions

1167
editor/action_map_editor.cpp Normal file

File diff suppressed because it is too large Load diff

203
editor/action_map_editor.h Normal file
View file

@ -0,0 +1,203 @@
/*************************************************************************/
/* action_map_editor.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 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. */
/*************************************************************************/
#ifndef ACTION_MAP_EDITOR_H
#define ACTION_MAP_EDITOR_H
#include "editor/editor_data.h"
// Confirmation Dialog used when configuring an input event.
// Separate from ActionMapEditor for code cleanliness and separation of responsibilities.
class InputEventConfigurationDialog : public ConfirmationDialog {
GDCLASS(InputEventConfigurationDialog, ConfirmationDialog);
public:
enum InputType {
INPUT_KEY = 1,
INPUT_MOUSE_BUTTON = 2,
INPUT_JOY_BUTTON = 4,
INPUT_JOY_MOTION = 8
};
private:
struct IconCache {
Ref<Texture2D> keyboard;
Ref<Texture2D> mouse;
Ref<Texture2D> joypad_button;
Ref<Texture2D> joypad_axis;
} icon_cache;
Ref<InputEvent> event = Ref<InputEvent>();
TabContainer *tab_container;
// Listening for input
Label *event_as_text;
// List of All Key/Mouse/Joypad input options.
int allowed_input_types;
Tree *input_list_tree;
LineEdit *input_list_search;
// Additional Options, shown depending on event selected
VBoxContainer *additional_options_container;
HBoxContainer *device_container;
OptionButton *device_id_option;
HBoxContainer *mod_container; // Contains the subcontainer and the store command checkbox.
enum ModCheckbox {
MOD_ALT,
MOD_SHIFT,
MOD_COMMAND,
MOD_CONTROL,
MOD_META,
MOD_MAX
};
String mods[MOD_MAX] = { "Alt", "Shift", "Command", "Control", "Meta" };
CheckBox *mod_checkboxes[MOD_MAX];
CheckBox *store_command_checkbox;
CheckBox *physical_key_checkbox;
void _set_event(const Ref<InputEvent> &p_event);
void _tab_selected(int p_tab);
void _listen_window_input(const Ref<InputEvent> &p_event);
void _search_term_updated(const String &p_term);
void _update_input_list();
void _input_list_item_selected();
void _mod_toggled(bool p_checked, int p_index);
void _store_command_toggled(bool p_checked);
void _physical_keycode_toggled(bool p_checked);
void _set_current_device(int i_device);
int _get_current_device() const;
String _get_device_string(int i_device) const;
protected:
void _notification(int p_what);
public:
// Pass an existing event to configure it. Alternatively, pass no event to start with a blank configuration.
void popup_and_configure(const Ref<InputEvent> &p_event = Ref<InputEvent>());
Ref<InputEvent> get_event() const;
String get_event_text(const Ref<InputEvent> &p_event);
void set_allowed_input_types(int p_type_masks);
InputEventConfigurationDialog();
};
class ActionMapEditor : public Control {
GDCLASS(ActionMapEditor, Control);
public:
struct ActionInfo {
String name = String();
Dictionary action = Dictionary();
Ref<Texture2D> icon = Ref<Texture2D>();
bool editable = true;
};
private:
enum ItemButton {
BUTTON_ADD_EVENT,
BUTTON_EDIT_EVENT,
BUTTON_REMOVE_ACTION,
BUTTON_REMOVE_EVENT,
};
Vector<ActionInfo> actions_cache;
Tree *action_tree;
// Storing which action/event is currently being edited in the InputEventConfigurationDialog.
Dictionary current_action = Dictionary();
String current_action_name = String();
int current_action_event_index = -1;
// Popups
InputEventConfigurationDialog *event_config_dialog;
AcceptDialog *message;
// Filtering and Adding actions
bool show_uneditable;
CheckBox *show_uneditable_actions_checkbox;
LineEdit *action_list_search;
bool allow_editing_actions;
HBoxContainer *add_hbox;
LineEdit *add_edit;
void _event_config_confirmed();
void _add_action_pressed();
void _add_action(const String &p_name);
void _action_edited();
void _tree_button_pressed(Object *p_item, int p_column, int p_id);
void _tree_item_activated();
void _search_term_updated(const String &p_search_term);
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
protected:
void _notification(int p_what);
static void _bind_methods();
public:
LineEdit *get_search_box() const;
InputEventConfigurationDialog *get_configuration_dialog();
// Dictionary represents an Action with "events" (Array) and "deadzone" (float) items. Pass with no param to update list from cached action map.
void update_action_list(const Vector<ActionInfo> &p_action_infos = Vector<ActionInfo>());
void show_message(const String &p_message);
void set_show_uneditable(bool p_show);
void set_allow_editing_actions(bool p_allow);
void set_toggle_editable_label(const String &p_label);
void use_external_search_box(LineEdit *p_searchbox);
ActionMapEditor();
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,109 +0,0 @@
/*************************************************************************/
/* input_map_editor.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 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. */
/*************************************************************************/
#ifndef INPUT_MAP_EDITOR_H
#define INPUT_MAP_EDITOR_H
#include "core/object/undo_redo.h"
#include "editor/editor_data.h"
class InputMapEditor : public Control {
GDCLASS(InputMapEditor, Control);
enum InputType {
INPUT_KEY,
INPUT_KEY_PHYSICAL,
INPUT_JOY_BUTTON,
INPUT_JOY_MOTION,
INPUT_MOUSE_BUTTON
};
Tree *input_editor;
LineEdit *action_name;
Button *action_add;
Label *action_add_error;
InputType add_type;
String add_at;
int edit_idx;
PopupMenu *popup_add;
ConfirmationDialog *press_a_key;
bool press_a_key_physical;
Label *press_a_key_label;
ConfirmationDialog *device_input;
OptionButton *device_id;
OptionButton *device_index;
Label *device_index_label;
MenuButton *popup_copy_to_feature;
Ref<InputEventKey> last_wait_for_key;
AcceptDialog *message;
UndoRedo *undo_redo;
String inputmap_changed;
bool setting = false;
void _update_actions();
void _add_item(int p_item, Ref<InputEvent> p_exiting_event = Ref<InputEvent>());
void _edit_item(Ref<InputEvent> p_exiting_event);
void _action_check(String p_action);
void _action_adds(String);
void _action_add();
void _device_input_add();
void _action_selected();
void _action_edited();
void _action_activated();
void _action_button_pressed(Object *p_obj, int p_column, int p_id);
void _wait_for_key(const Ref<InputEvent> &p_event);
void _press_a_key_confirm();
void _show_last_added(const Ref<InputEvent> &p_event, const String &p_name);
String _get_joypad_motion_event_text(const Ref<InputEventJoypadMotion> &p_event);
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
protected:
int _get_current_device();
void _set_current_device(int i_device);
String _get_device_string(int i_device);
void _notification(int p_what);
static void _bind_methods();
public:
InputMapEditor();
};
#endif // INPUT_MAP_EDITOR_H

View file

@ -269,6 +269,206 @@ void ProjectSettingsEditor::_editor_restart_close() {
restart_container->hide();
}
void ProjectSettingsEditor::_action_added(const String &p_name) {
String name = "input/" + p_name;
if (ProjectSettings::get_singleton()->has_setting(name)) {
action_map->show_message(vformat(TTR("An action with the name '%s' already exists."), name));
return;
}
Dictionary action;
action["events"] = Array();
action["deadzone"] = 0.5f;
undo_redo->create_action(TTR("Add Input Action"));
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", name);
undo_redo->add_do_method(this, "_update_action_map_editor");
undo_redo->add_undo_method(this, "_update_action_map_editor");
undo_redo->add_do_method(this, "queue_save");
undo_redo->add_undo_method(this, "queue_save");
undo_redo->commit_action();
}
void ProjectSettingsEditor::_action_edited(const String &p_name, const Dictionary &p_action) {
const String property_name = "input/" + p_name;
Dictionary old_val = ProjectSettings::get_singleton()->get(property_name);
if (old_val["deadzone"] != p_action["deadzone"]) {
// Deadzone Changed
undo_redo->create_action(TTR("Change Action deadzone"));
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", property_name, p_action);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property_name, old_val);
} else {
// Events changed
int event_count = ((Array)p_action["events"]).size();
int old_event_count = ((Array)old_val["events"]).size();
if (event_count == old_event_count) {
undo_redo->create_action(TTR("Edit Input Action Event"));
} else if (event_count > old_event_count) {
undo_redo->create_action(TTR("Add Input Action Event"));
} else if (event_count < old_event_count) {
undo_redo->create_action(TTR("Remove Input Action Event"));
}
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", property_name, p_action);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property_name, old_val);
}
undo_redo->add_do_method(this, "_update_action_map_editor");
undo_redo->add_undo_method(this, "_update_action_map_editor");
undo_redo->add_do_method(this, "queue_save");
undo_redo->add_undo_method(this, "queue_save");
undo_redo->commit_action();
}
void ProjectSettingsEditor::_action_removed(const String &p_name) {
const String property_name = "input/" + p_name;
Dictionary old_val = ProjectSettings::get_singleton()->get(property_name);
int order = ProjectSettings::get_singleton()->get_order(property_name);
undo_redo->create_action(TTR("Erase Input Action"));
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", property_name);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property_name, old_val);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", property_name, order);
undo_redo->add_do_method(this, "_update_action_map_editor");
undo_redo->add_undo_method(this, "_update_action_map_editor");
undo_redo->add_do_method(this, "queue_save");
undo_redo->add_undo_method(this, "queue_save");
undo_redo->commit_action();
}
void ProjectSettingsEditor::_action_renamed(const String &p_old_name, const String &p_new_name) {
const String old_property_name = "input/" + p_old_name;
const String new_property_name = "input/" + p_new_name;
if (ProjectSettings::get_singleton()->has_setting(new_property_name)) {
action_map->show_message(vformat(TTR("An action with the name '%s' already exists."), new_property_name));
return;
}
int order = ProjectSettings::get_singleton()->get_order(old_property_name);
Dictionary action = ProjectSettings::get_singleton()->get(old_property_name);
undo_redo->create_action(TTR("Rename Input Action Event"));
// Do: clear old, set new
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", old_property_name);
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", new_property_name, action);
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", new_property_name, order);
// Undo: clear new, set old
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", new_property_name);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", old_property_name, action);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", old_property_name, order);
undo_redo->add_do_method(this, "_update_action_map_editor");
undo_redo->add_undo_method(this, "_update_action_map_editor");
undo_redo->add_do_method(this, "queue_save");
undo_redo->add_undo_method(this, "queue_save");
undo_redo->commit_action();
}
void ProjectSettingsEditor::_action_reordered(const String &p_action_name, const String &p_relative_to, bool p_before) {
const String action_name = "input/" + p_action_name;
const String target_name = "input/" + p_relative_to;
// It is much easier to rebuild the custom "input" properties rather than messing around with the "order" values of them.
Variant action_value = ps->get(action_name);
Variant target_value = ps->get(target_name);
List<PropertyInfo> props;
OrderedHashMap<String, Variant> action_values;
ProjectSettings::get_singleton()->get_property_list(&props);
undo_redo->create_action(TTR("Update Input Action Order"));
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
PropertyInfo prop = E->get();
// Skip builtins and non-inputs
if (ProjectSettings::get_singleton()->is_builtin_setting(prop.name) || !prop.name.begins_with("input/")) {
continue;
}
action_values.insert(prop.name, ps->get(prop.name));
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", prop.name);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", prop.name);
}
for (OrderedHashMap<String, Variant>::Element E = action_values.front(); E; E = E.next()) {
String name = E.key();
Variant value = E.get();
if (name == target_name) {
if (p_before) {
// Insert before target
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
} else {
// Insert after target
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
}
} else if (name != action_name) {
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, value);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, value);
}
}
undo_redo->add_do_method(this, "_update_action_map_editor");
undo_redo->add_undo_method(this, "_update_action_map_editor");
undo_redo->add_do_method(this, "queue_save");
undo_redo->add_undo_method(this, "queue_save");
undo_redo->commit_action();
}
void ProjectSettingsEditor::_update_action_map_editor() {
Vector<ActionMapEditor::ActionInfo> actions;
List<PropertyInfo> props;
ProjectSettings::get_singleton()->get_property_list(&props);
const Ref<Texture2D> builtin_icon = get_theme_icon("PinPressed", "EditorIcons");
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
const String property_name = E->get().name;
if (!property_name.begins_with("input/")) {
continue;
}
// Strip the "input/" from the left.
String display_name = property_name.substr(String("input/").size() - 1);
Dictionary action = ProjectSettings::get_singleton()->get(property_name);
ActionMapEditor::ActionInfo action_info;
action_info.action = action;
action_info.editable = true;
action_info.name = display_name;
const bool is_builtin_input = ProjectSettings::get_singleton()->get_input_presets().find(property_name) != nullptr;
if (is_builtin_input) {
action_info.editable = false;
action_info.icon = builtin_icon;
}
actions.push_back(action_info);
}
action_map->update_action_list(actions);
}
void ProjectSettingsEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
@ -289,6 +489,8 @@ void ProjectSettingsEditor::_notification(int p_what) {
restart_container->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree"));
restart_icon->set_texture(get_theme_icon("StatusWarning", "EditorIcons"));
restart_label->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor"));
_update_action_map_editor();
} break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
search_box->set_right_icon(get_theme_icon("Search", "EditorIcons"));
@ -299,6 +501,8 @@ void ProjectSettingsEditor::_notification(int p_what) {
void ProjectSettingsEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("queue_save"), &ProjectSettingsEditor::queue_save);
ClassDB::bind_method(D_METHOD("_update_action_map_editor"), &ProjectSettingsEditor::_update_action_map_editor);
}
ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
@ -437,10 +641,16 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
restart_close_button->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_editor_restart_close));
restart_hb->add_child(restart_close_button);
inputmap_editor = memnew(InputMapEditor);
inputmap_editor->set_name(TTR("Input Map"));
inputmap_editor->connect("inputmap_changed", callable_mp(this, &ProjectSettingsEditor::queue_save));
tab_container->add_child(inputmap_editor);
action_map = memnew(ActionMapEditor);
action_map->set_name(TTR("Input Map"));
action_map->connect("action_added", callable_mp(this, &ProjectSettingsEditor::_action_added));
action_map->connect("action_edited", callable_mp(this, &ProjectSettingsEditor::_action_edited));
action_map->connect("action_removed", callable_mp(this, &ProjectSettingsEditor::_action_removed));
action_map->connect("action_renamed", callable_mp(this, &ProjectSettingsEditor::_action_renamed));
action_map->connect("action_reordered", callable_mp(this, &ProjectSettingsEditor::_action_reordered));
action_map->set_toggle_editable_label(TTR("Show built-in Actions"));
action_map->set_show_uneditable(false);
tab_container->add_child(action_map);
localization_editor = memnew(LocalizationEditor);
localization_editor->set_name(TTR("Localization"));

View file

@ -32,10 +32,10 @@
#define PROJECT_SETTINGS_EDITOR_H
#include "core/object/undo_redo.h"
#include "editor/action_map_editor.h"
#include "editor/editor_data.h"
#include "editor/editor_plugin_settings.h"
#include "editor/editor_sectioned_inspector.h"
#include "editor/input_map_editor.h"
#include "editor/localization_editor.h"
#include "editor/shader_globals_editor.h"
#include "editor_autoload_settings.h"
@ -44,26 +44,18 @@
class ProjectSettingsEditor : public AcceptDialog {
GDCLASS(ProjectSettingsEditor, AcceptDialog);
enum InputType {
INPUT_KEY,
INPUT_KEY_PHYSICAL,
INPUT_JOY_BUTTON,
INPUT_JOY_MOTION,
INPUT_MOUSE_BUTTON
};
static ProjectSettingsEditor *singleton;
ProjectSettings *ps;
Timer *timer;
TabContainer *tab_container;
SectionedInspector *inspector;
InputMapEditor *inputmap_editor;
LocalizationEditor *localization_editor;
EditorAutoloadSettings *autoload_settings;
ShaderGlobalsEditor *shaders_global_variables_editor;
EditorPluginSettings *plugin_settings;
ActionMapEditor *action_map;
HBoxContainer *search_bar;
LineEdit *search_box;
CheckButton *advanced;
@ -102,6 +94,14 @@ class ProjectSettingsEditor : public AcceptDialog {
void _editor_restart_close();
void _add_feature_overrides();
void _action_added(const String &p_name);
void _action_edited(const String &p_name, const Dictionary &p_action);
void _action_removed(const String &p_name);
void _action_renamed(const String &p_old_name, const String &p_new_name);
void _action_reordered(const String &p_action_name, const String &p_relative_to, bool p_before);
void _update_action_map_editor();
ProjectSettingsEditor();
protected:

View file

@ -881,10 +881,6 @@ bool Window::_can_consume_input_events() const {
}
void Window::_window_input(const Ref<InputEvent> &p_ev) {
if (Engine::get_singleton()->is_editor_hint() && (Object::cast_to<InputEventJoypadButton>(p_ev.ptr()) || Object::cast_to<InputEventJoypadMotion>(*p_ev))) {
return; //avoid joy input on editor
}
if (EngineDebugger::is_active()) {
//quit from game window using F8
Ref<InputEventKey> k = p_ev;