Skip to content

Commit 32fe928

Browse files
committed
Support Input and UI for multiple players
1 parent 1ba8565 commit 32fe928

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1028
-244
lines changed

core/config/project_settings.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,9 @@ ProjectSettings::ProjectSettings() {
15291529
GLOBAL_DEF("audio/general/ios/mix_with_others", false);
15301530

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

15331536
// Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
15341537
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");

core/config/project_settings.h

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class ProjectSettings : public Object {
9494
bool project_loaded = false;
9595
List<String> input_presets;
9696

97+
PlayerId keyboard_player_id_override = PlayerId::P1;
98+
PlayerId mouse_player_id_override = PlayerId::P1;
99+
PlayerId touch_player_id_override = PlayerId::P1;
100+
97101
HashSet<String> custom_features;
98102
HashMap<StringName, LocalVector<Pair<StringName, StringName>>> feature_overrides;
99103

core/core_constants.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,26 @@ void register_global_constants() {
527527
BIND_CORE_BITFIELD_CLASS_FLAG(MouseButtonMask, MOUSE_BUTTON_MASK, MB_XBUTTON1);
528528
BIND_CORE_BITFIELD_CLASS_FLAG(MouseButtonMask, MOUSE_BUTTON_MASK, MB_XBUTTON2);
529529

530+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P1);
531+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P2);
532+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P3);
533+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P4);
534+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P5);
535+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P6);
536+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P7);
537+
BIND_CORE_ENUM_CLASS_CONSTANT(PlayerId, PLAYER_ID, P8);
538+
539+
BIND_CORE_BITFIELD_FLAG(PLAYER_NONE);
540+
BIND_CORE_BITFIELD_FLAG(PLAYER_1);
541+
BIND_CORE_BITFIELD_FLAG(PLAYER_2);
542+
BIND_CORE_BITFIELD_FLAG(PLAYER_3);
543+
BIND_CORE_BITFIELD_FLAG(PLAYER_4);
544+
BIND_CORE_BITFIELD_FLAG(PLAYER_5);
545+
BIND_CORE_BITFIELD_FLAG(PLAYER_6);
546+
BIND_CORE_BITFIELD_FLAG(PLAYER_7);
547+
BIND_CORE_BITFIELD_FLAG(PLAYER_8);
548+
BIND_CORE_BITFIELD_FLAG(PLAYER_ALL);
549+
530550
BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, INVALID);
531551
BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, A);
532552
BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, B);
@@ -649,6 +669,7 @@ void register_global_constants() {
649669
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_PHYSICS);
650670
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_NAVIGATION);
651671
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_AVOIDANCE);
672+
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_PLAYER_MASK);
652673

653674
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_FILE);
654675
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_DIR);

core/input/input.compat.inc

+45
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,56 @@
3030

3131
#ifndef DISABLE_DEPRECATED
3232

33+
bool Input::_is_action_pressed_bind_compat_102412(const StringName &p_action, bool p_exact) const {
34+
return is_action_pressed(p_action, p_exact, PlayerId::P1);
35+
}
36+
37+
bool Input::_is_action_just_pressed_bind_compat_102412(const StringName &p_action, bool p_exact) const {
38+
return is_action_just_pressed(p_action, p_exact, PlayerId::P1);
39+
}
40+
41+
bool Input::_is_action_just_released_bind_compat_102412(const StringName &p_action, bool p_exact) const {
42+
return is_action_just_released(p_action, p_exact, PlayerId::P1);
43+
}
44+
45+
float Input::_get_action_strength_bind_compat_102412(const StringName &p_action, bool p_exact) const {
46+
return get_action_strength(p_action, p_exact, PlayerId::P1);
47+
}
48+
49+
float Input::_get_action_raw_strength_bind_compat_102412(const StringName &p_action, bool p_exact) const {
50+
return get_action_raw_strength(p_action, p_exact, PlayerId::P1);
51+
}
52+
53+
float Input::_get_axis_bind_compat_102412(const StringName &p_negative_action, const StringName &p_positive_action) const {
54+
return get_axis(p_negative_action, p_positive_action, PlayerId::P1);
55+
}
56+
57+
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 {
58+
return get_vector(p_negative_x, p_positive_x, p_negative_y, p_positive_y, p_deadzone, PlayerId::P1);
59+
}
60+
61+
void Input::_action_press_bind_compat_102412(const StringName &p_action, float p_strength) {
62+
action_press(p_action, p_strength, PlayerId::P1);
63+
}
64+
65+
void Input::_action_release_bind_compat_102412(const StringName &p_action) {
66+
action_release(p_action, PlayerId::P1);
67+
}
68+
3369
void Input::_vibrate_handheld_bind_compat_91143(int p_duration_ms) {
3470
vibrate_handheld(p_duration_ms, -1.0);
3571
}
3672

3773
void Input::_bind_compatibility_methods() {
74+
ClassDB::bind_compatibility_method(D_METHOD("is_action_pressed", "action", "exact_match"), &Input::_is_action_pressed_bind_compat_102412, DEFVAL(false));
75+
ClassDB::bind_compatibility_method(D_METHOD("is_action_just_pressed", "action", "exact_match"), &Input::_is_action_just_pressed_bind_compat_102412, DEFVAL(false));
76+
ClassDB::bind_compatibility_method(D_METHOD("is_action_just_released", "action", "exact_match"), &Input::_is_action_just_released_bind_compat_102412, DEFVAL(false));
77+
ClassDB::bind_compatibility_method(D_METHOD("get_action_strength", "action", "exact_match"), &Input::_get_action_strength_bind_compat_102412, DEFVAL(false));
78+
ClassDB::bind_compatibility_method(D_METHOD("get_action_raw_strength", "action", "exact_match"), &Input::_get_action_raw_strength_bind_compat_102412, DEFVAL(false));
79+
ClassDB::bind_compatibility_method(D_METHOD("get_axis", "negative_action", "positive_action"), &Input::_get_axis_bind_compat_102412);
80+
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));
81+
ClassDB::bind_compatibility_method(D_METHOD("action_press", "action", "strength"), &Input::_action_press_bind_compat_102412, DEFVAL(1.f));
82+
ClassDB::bind_compatibility_method(D_METHOD("action_release", "action"), &Input::_action_release_bind_compat_102412);
3883
ClassDB::bind_compatibility_method(D_METHOD("vibrate_handheld", "duration_ms"), &Input::_vibrate_handheld_bind_compat_91143, DEFVAL(500));
3984
}
4085

0 commit comments

Comments
 (0)