Skip to content

Commit

Permalink
Added ability to override built-in actions for the editor
Browse files Browse the repository at this point in the history
This adds the ability to add overrides for built-in actions (i.e. ui_*) in the editor. Also added a number of additional built-in actions for various text-related actions, gui-generic actions (like copy and paste) and graph-related actions (duplicate nodes), etc. Moved the definition of input actions to input_map, rather than in project_settings so the editor can make use of these actions as well.
  • Loading branch information
EricEzaM committed Feb 18, 2021
1 parent ca1abc7 commit 074f535
Show file tree
Hide file tree
Showing 8 changed files with 632 additions and 264 deletions.
187 changes: 25 additions & 162 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/core_bind.h"
#include "core/core_string_names.h"
#include "core/input/input_map.h"
#include "core/io/file_access_network.h"
#include "core/io/file_access_pack.h"
#include "core/io/marshalls.h"
Expand Down Expand Up @@ -1057,17 +1058,35 @@ void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
}

void ProjectSettings::_add_builtin_input_map() {
if (InputMap::get_singleton()) {
OrderedHashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();

for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
Array events;

// Convert list of input events into array
for (List<Ref<InputEvent>>::Element *I = E.get().front(); I; I = I->next()) {
events.push_back(I->get());
}

Dictionary action;
action["deadzone"] = Variant(0.5f);
action["events"] = events;

String action_name = "input/" + E.key();
GLOBAL_DEF(action_name, action);
input_presets.push_back(action_name);
}
}
}

ProjectSettings::ProjectSettings() {
// Initialization of engine variables should be done in the setup() method,
// so that the values can be overridden from project.godot or project.binary.

singleton = this;

Array events;
Dictionary action;
Ref<InputEventKey> key;
Ref<InputEventJoypadButton> joyb;

GLOBAL_DEF_BASIC("application/config/name", "");
GLOBAL_DEF_BASIC("application/config/description", "");
custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
Expand All @@ -1094,163 +1113,7 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_ENTER);
events.push_back(key);
key.instance();
key->set_keycode(KEY_KP_ENTER);
events.push_back(key);
key.instance();
key->set_keycode(KEY_SPACE);
events.push_back(key);
joyb.instance();
joyb->set_button_index(JOY_BUTTON_A);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_accept", action);
input_presets.push_back("input/ui_accept");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_SPACE);
events.push_back(key);
joyb.instance();
joyb->set_button_index(JOY_BUTTON_Y);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_select", action);
input_presets.push_back("input/ui_select");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_ESCAPE);
events.push_back(key);
joyb.instance();
joyb->set_button_index(JOY_BUTTON_B);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_cancel", action);
input_presets.push_back("input/ui_cancel");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_TAB);
events.push_back(key);
action["events"] = events;
GLOBAL_DEF("input/ui_focus_next", action);
input_presets.push_back("input/ui_focus_next");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_TAB);
key->set_shift(true);
events.push_back(key);
action["events"] = events;
GLOBAL_DEF("input/ui_focus_prev", action);
input_presets.push_back("input/ui_focus_prev");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_LEFT);
events.push_back(key);
joyb.instance();
joyb->set_button_index(JOY_BUTTON_DPAD_LEFT);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_left", action);
input_presets.push_back("input/ui_left");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_RIGHT);
events.push_back(key);
joyb.instance();
joyb->set_button_index(JOY_BUTTON_DPAD_RIGHT);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_right", action);
input_presets.push_back("input/ui_right");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_UP);
events.push_back(key);
joyb.instance();
joyb->set_button_index(JOY_BUTTON_DPAD_UP);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_up", action);
input_presets.push_back("input/ui_up");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_DOWN);
events.push_back(key);
joyb.instance();
joyb->set_button_index(JOY_BUTTON_DPAD_DOWN);
events.push_back(joyb);
action["events"] = events;
GLOBAL_DEF("input/ui_down", action);
input_presets.push_back("input/ui_down");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_PAGEUP);
events.push_back(key);
action["events"] = events;
GLOBAL_DEF("input/ui_page_up", action);
input_presets.push_back("input/ui_page_up");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_PAGEDOWN);
events.push_back(key);
action["events"] = events;
GLOBAL_DEF("input/ui_page_down", action);
input_presets.push_back("input/ui_page_down");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_HOME);
events.push_back(key);
action["events"] = events;
GLOBAL_DEF("input/ui_home", action);
input_presets.push_back("input/ui_home");

action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
key.instance();
key->set_keycode(KEY_END);
events.push_back(key);
action["events"] = events;
GLOBAL_DEF("input/ui_end", action);
input_presets.push_back("input/ui_end");
_add_builtin_input_map();

custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
Expand Down
3 changes: 3 additions & 0 deletions core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ class ProjectSettings : public Object {

Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false);

void _add_builtin_input_map();

protected:
static void _bind_methods();

public:
Expand Down
16 changes: 8 additions & 8 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,21 +604,21 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
}
}

for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) {
if (InputMap::get_singleton()->event_is_action(p_event, E->key())) {
for (OrderedHashMap<StringName, InputMap::Action>::ConstElement E = InputMap::get_singleton()->get_action_map().front(); E; E = E.next()) {
if (InputMap::get_singleton()->event_is_action(p_event, E.key())) {
// If not echo and action pressed state has changed
if (!p_event->is_echo() && is_action_pressed(E->key(), false) != p_event->is_action_pressed(E->key())) {
if (!p_event->is_echo() && is_action_pressed(E.key(), false) != p_event->is_action_pressed(E.key())) {
Action action;
action.physics_frame = Engine::get_singleton()->get_physics_frames();
action.process_frame = Engine::get_singleton()->get_process_frames();
action.pressed = p_event->is_action_pressed(E->key());
action.pressed = p_event->is_action_pressed(E.key());
action.strength = 0.0f;
action.raw_strength = 0.0f;
action.exact = InputMap::get_singleton()->event_is_action(p_event, E->key(), true);
action_state[E->key()] = action;
action.exact = InputMap::get_singleton()->event_is_action(p_event, E.key(), true);
action_state[E.key()] = action;
}
action_state[E->key()].strength = p_event->get_action_strength(E->key());
action_state[E->key()].raw_strength = p_event->get_action_raw_strength(E->key());
action_state[E.key()].strength = p_event->get_action_strength(E.key());
action_state[E.key()].raw_strength = p_event->get_action_raw_strength(E.key());
}
}

Expand Down
Loading

0 comments on commit 074f535

Please sign in to comment.