Skip to content

Support Input and UI for multiple players #102412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,9 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("audio/general/ios/mix_with_others", false);

_add_builtin_input_map();
GLOBAL_DEF(PropertyInfo(Variant::INT, "input/keyboard_player_id_override", PROPERTY_HINT_ENUM, "P1,P2,P3,P4,P5,P6,P7,P8"), (int)PlayerId::P1);
GLOBAL_DEF(PropertyInfo(Variant::INT, "input/mouse_player_id_override", PROPERTY_HINT_ENUM, "P1,P2,P3,P4,P5,P6,P7,P8"), (int)PlayerId::P1);
GLOBAL_DEF(PropertyInfo(Variant::INT, "input/touch_player_id_override", PROPERTY_HINT_ENUM, "P1,P2,P3,P4,P5,P6,P7,P8"), (int)PlayerId::P1);

// Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor");
Expand Down
4 changes: 4 additions & 0 deletions core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class ProjectSettings : public Object {
bool project_loaded = false;
List<String> input_presets;

PlayerId keyboard_player_id_override = PlayerId::P1;
PlayerId mouse_player_id_override = PlayerId::P1;
PlayerId touch_player_id_override = PlayerId::P1;

HashSet<String> custom_features;
HashMap<StringName, LocalVector<Pair<StringName, StringName>>> feature_overrides;

Expand Down
21 changes: 21 additions & 0 deletions core/core_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,26 @@ void register_global_constants() {
BIND_CORE_BITFIELD_CLASS_FLAG(MouseButtonMask, MOUSE_BUTTON_MASK, MB_XBUTTON1);
BIND_CORE_BITFIELD_CLASS_FLAG(MouseButtonMask, MOUSE_BUTTON_MASK, MB_XBUTTON2);

BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P1);
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P2);
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P3);
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P4);
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P5);
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P6);
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P7);
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P8);

BIND_CORE_BITFIELD_FLAG(PLAYER_NONE);
BIND_CORE_BITFIELD_FLAG(PLAYER_1);
BIND_CORE_BITFIELD_FLAG(PLAYER_2);
BIND_CORE_BITFIELD_FLAG(PLAYER_3);
BIND_CORE_BITFIELD_FLAG(PLAYER_4);
BIND_CORE_BITFIELD_FLAG(PLAYER_5);
BIND_CORE_BITFIELD_FLAG(PLAYER_6);
BIND_CORE_BITFIELD_FLAG(PLAYER_7);
BIND_CORE_BITFIELD_FLAG(PLAYER_8);
BIND_CORE_BITFIELD_FLAG(PLAYER_ALL);

BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, INVALID);
BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, A);
BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, B);
Expand Down Expand Up @@ -649,6 +669,7 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_PHYSICS);
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_NAVIGATION);
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_AVOIDANCE);
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_PLAYER_MASK);

BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_FILE);
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_DIR);
Expand Down
45 changes: 45 additions & 0 deletions core/input/input.compat.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,56 @@

#ifndef DISABLE_DEPRECATED

bool Input::_is_action_pressed_bind_compat_102412(const StringName &p_action, bool p_exact) const {
return is_action_pressed(p_action, p_exact, PlayerId::P1);
}

bool Input::_is_action_just_pressed_bind_compat_102412(const StringName &p_action, bool p_exact) const {
return is_action_just_pressed(p_action, p_exact, PlayerId::P1);
}

bool Input::_is_action_just_released_bind_compat_102412(const StringName &p_action, bool p_exact) const {
return is_action_just_released(p_action, p_exact, PlayerId::P1);
}

float Input::_get_action_strength_bind_compat_102412(const StringName &p_action, bool p_exact) const {
return get_action_strength(p_action, p_exact, PlayerId::P1);
}

float Input::_get_action_raw_strength_bind_compat_102412(const StringName &p_action, bool p_exact) const {
return get_action_raw_strength(p_action, p_exact, PlayerId::P1);
}

float Input::_get_axis_bind_compat_102412(const StringName &p_negative_action, const StringName &p_positive_action) const {
return get_axis(p_negative_action, p_positive_action, PlayerId::P1);
}

Vector2 Input::_get_vector_bind_compat_102412(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone) const {
return get_vector(p_negative_x, p_positive_x, p_negative_y, p_positive_y, p_deadzone, PlayerId::P1);
}

void Input::_action_press_bind_compat_102412(const StringName &p_action, float p_strength) {
action_press(p_action, p_strength, PlayerId::P1);
}

void Input::_action_release_bind_compat_102412(const StringName &p_action) {
action_release(p_action, PlayerId::P1);
}

void Input::_vibrate_handheld_bind_compat_91143(int p_duration_ms) {
vibrate_handheld(p_duration_ms, -1.0);
}

void Input::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("is_action_pressed", "action", "exact_match"), &Input::_is_action_pressed_bind_compat_102412, DEFVAL(false));
ClassDB::bind_compatibility_method(D_METHOD("is_action_just_pressed", "action", "exact_match"), &Input::_is_action_just_pressed_bind_compat_102412, DEFVAL(false));
ClassDB::bind_compatibility_method(D_METHOD("is_action_just_released", "action", "exact_match"), &Input::_is_action_just_released_bind_compat_102412, DEFVAL(false));
ClassDB::bind_compatibility_method(D_METHOD("get_action_strength", "action", "exact_match"), &Input::_get_action_strength_bind_compat_102412, DEFVAL(false));
ClassDB::bind_compatibility_method(D_METHOD("get_action_raw_strength", "action", "exact_match"), &Input::_get_action_raw_strength_bind_compat_102412, DEFVAL(false));
ClassDB::bind_compatibility_method(D_METHOD("get_axis", "negative_action", "positive_action"), &Input::_get_axis_bind_compat_102412);
ClassDB::bind_compatibility_method(D_METHOD("get_vector", "negative_x", "positive_x", "negative_y", "positive_y", "deadzone"), &Input::_get_vector_bind_compat_102412, DEFVAL(-1.0f));
ClassDB::bind_compatibility_method(D_METHOD("action_press", "action", "strength"), &Input::_action_press_bind_compat_102412, DEFVAL(1.f));
ClassDB::bind_compatibility_method(D_METHOD("action_release", "action"), &Input::_action_release_bind_compat_102412);
ClassDB::bind_compatibility_method(D_METHOD("vibrate_handheld", "duration_ms"), &Input::_vibrate_handheld_bind_compat_91143, DEFVAL(500));
}

Expand Down
Loading