@@ -122,13 +122,13 @@ void Input::_bind_methods() {
122
122
ClassDB::bind_method (D_METHOD (" is_key_label_pressed" , " keycode" ), &Input::is_key_label_pressed);
123
123
ClassDB::bind_method (D_METHOD (" is_mouse_button_pressed" , " button" ), &Input::is_mouse_button_pressed);
124
124
ClassDB::bind_method (D_METHOD (" is_joy_button_pressed" , " device" , " button" ), &Input::is_joy_button_pressed);
125
- ClassDB::bind_method (D_METHOD (" is_action_pressed" , " action" , " exact_match" ), &Input::is_action_pressed, DEFVAL (false ));
126
- ClassDB::bind_method (D_METHOD (" is_action_just_pressed" , " action" , " exact_match" ), &Input::is_action_just_pressed, DEFVAL (false ));
127
- ClassDB::bind_method (D_METHOD (" is_action_just_released" , " action" , " exact_match" ), &Input::is_action_just_released, DEFVAL (false ));
128
- ClassDB::bind_method (D_METHOD (" get_action_strength" , " action" , " exact_match" ), &Input::get_action_strength, DEFVAL (false ));
129
- ClassDB::bind_method (D_METHOD (" get_action_raw_strength" , " action" , " exact_match" ), &Input::get_action_raw_strength, DEFVAL (false ));
130
- ClassDB::bind_method (D_METHOD (" get_axis" , " negative_action" , " positive_action" ), &Input::get_axis);
131
- ClassDB::bind_method (D_METHOD (" get_vector" , " negative_x" , " positive_x" , " negative_y" , " positive_y" , " deadzone" ), &Input::get_vector, DEFVAL (-1 .0f ));
125
+ ClassDB::bind_method (D_METHOD (" is_action_pressed" , " action" , " exact_match" , " player_mask " ), &Input::is_action_pressed, DEFVAL (false ), DEFVAL (PLAYER_ALL ));
126
+ ClassDB::bind_method (D_METHOD (" is_action_just_pressed" , " action" , " exact_match" , " player_mask " ), &Input::is_action_just_pressed, DEFVAL (false ), DEFVAL (PLAYER_ALL ));
127
+ ClassDB::bind_method (D_METHOD (" is_action_just_released" , " action" , " exact_match" , " player_mask " ), &Input::is_action_just_released, DEFVAL (false ), DEFVAL (PLAYER_ALL ));
128
+ ClassDB::bind_method (D_METHOD (" get_action_strength" , " action" , " exact_match" , " player_mask " ), &Input::get_action_strength, DEFVAL (false ), DEFVAL (PLAYER_ALL ));
129
+ ClassDB::bind_method (D_METHOD (" get_action_raw_strength" , " action" , " exact_match" , " player_mask " ), &Input::get_action_raw_strength, DEFVAL (false ), DEFVAL (PLAYER_ALL ));
130
+ ClassDB::bind_method (D_METHOD (" get_axis" , " negative_action" , " positive_action" , " player_mask " ), &Input::get_axis, DEFVAL (PLAYER_ALL) );
131
+ ClassDB::bind_method (D_METHOD (" get_vector" , " negative_x" , " positive_x" , " negative_y" , " positive_y" , " deadzone" , " player_mask " ), &Input::get_vector, DEFVAL (-1 .0f ), DEFVAL (PLAYER_ALL ));
132
132
ClassDB::bind_method (D_METHOD (" add_joy_mapping" , " mapping" , " update_existing" ), &Input::add_joy_mapping, DEFVAL (false ));
133
133
ClassDB::bind_method (D_METHOD (" remove_joy_mapping" , " guid" ), &Input::remove_joy_mapping);
134
134
ClassDB::bind_method (D_METHOD (" is_joy_known" , " device" ), &Input::is_joy_known);
@@ -157,8 +157,8 @@ void Input::_bind_methods() {
157
157
ClassDB::bind_method (D_METHOD (" set_mouse_mode" , " mode" ), &Input::set_mouse_mode);
158
158
ClassDB::bind_method (D_METHOD (" get_mouse_mode" ), &Input::get_mouse_mode);
159
159
ClassDB::bind_method (D_METHOD (" warp_mouse" , " position" ), &Input::warp_mouse);
160
- ClassDB::bind_method (D_METHOD (" action_press" , " action" , " strength" ), &Input::action_press, DEFVAL (1 .f ));
161
- ClassDB::bind_method (D_METHOD (" action_release" , " action" ), &Input::action_release);
160
+ ClassDB::bind_method (D_METHOD (" action_press" , " action" , " strength" , " player_mask " ), &Input::action_press, DEFVAL (1 .f ), DEFVAL (PLAYER_ALL ));
161
+ ClassDB::bind_method (D_METHOD (" action_release" , " action" , " player_mask " ), &Input::action_release, DEFVAL (PLAYER_ALL) );
162
162
ClassDB::bind_method (D_METHOD (" set_default_cursor_shape" , " shape" ), &Input::set_default_cursor_shape, DEFVAL (CURSOR_ARROW));
163
163
ClassDB::bind_method (D_METHOD (" get_current_cursor_shape" ), &Input::get_current_cursor_shape);
164
164
ClassDB::bind_method (D_METHOD (" set_custom_mouse_cursor" , " image" , " shape" , " hotspot" ), &Input::set_custom_mouse_cursor, DEFVAL (CURSOR_ARROW), DEFVAL (Vector2 ()));
@@ -201,6 +201,17 @@ void Input::_bind_methods() {
201
201
BIND_ENUM_CONSTANT (CURSOR_HSPLIT);
202
202
BIND_ENUM_CONSTANT (CURSOR_HELP);
203
203
204
+ BIND_ENUM_CONSTANT (PLAYER_NONE);
205
+ BIND_ENUM_CONSTANT (PLAYER_1);
206
+ BIND_ENUM_CONSTANT (PLAYER_2);
207
+ BIND_ENUM_CONSTANT (PLAYER_3);
208
+ BIND_ENUM_CONSTANT (PLAYER_4);
209
+ BIND_ENUM_CONSTANT (PLAYER_5);
210
+ BIND_ENUM_CONSTANT (PLAYER_6);
211
+ BIND_ENUM_CONSTANT (PLAYER_7);
212
+ BIND_ENUM_CONSTANT (PLAYER_8);
213
+ BIND_ENUM_CONSTANT (PLAYER_ALL);
214
+
204
215
ADD_SIGNAL (MethodInfo (" joy_connection_changed" , PropertyInfo (Variant::INT, " device" ), PropertyInfo (Variant::BOOL, " connected" )));
205
216
}
206
217
@@ -369,7 +380,7 @@ bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const {
369
380
return joy_buttons_pressed.has (_combine_device (p_button, p_device));
370
381
}
371
382
372
- bool Input::is_action_pressed (const StringName &p_action, bool p_exact) const {
383
+ bool Input::is_action_pressed (const StringName &p_action, bool p_exact, uint8_t p_player_mask ) const {
373
384
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), false , InputMap::get_singleton ()->suggest_actions (p_action));
374
385
375
386
if (disable_input) {
@@ -381,10 +392,10 @@ bool Input::is_action_pressed(const StringName &p_action, bool p_exact) const {
381
392
return false ;
382
393
}
383
394
384
- return E->value .cache .pressed && (p_exact ? E->value .exact : true );
395
+ return E->value .cache .pressed && (p_exact ? E->value .exact : true ) && p_player_mask & E-> value . player_mask ;
385
396
}
386
397
387
- bool Input::is_action_just_pressed (const StringName &p_action, bool p_exact) const {
398
+ bool Input::is_action_just_pressed (const StringName &p_action, bool p_exact, uint8_t p_player_mask ) const {
388
399
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), false , InputMap::get_singleton ()->suggest_actions (p_action));
389
400
390
401
if (disable_input) {
@@ -400,6 +411,10 @@ bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) con
400
411
return false ;
401
412
}
402
413
414
+ if (!(p_player_mask & E->value .player_mask )) {
415
+ return false ;
416
+ }
417
+
403
418
// Backward compatibility for legacy behavior, only return true if currently pressed.
404
419
bool pressed_requirement = legacy_just_pressed_behavior ? E->value .cache .pressed : true ;
405
420
@@ -410,7 +425,7 @@ bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) con
410
425
}
411
426
}
412
427
413
- bool Input::is_action_just_released (const StringName &p_action, bool p_exact) const {
428
+ bool Input::is_action_just_released (const StringName &p_action, bool p_exact, uint8_t p_player_mask ) const {
414
429
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), false , InputMap::get_singleton ()->suggest_actions (p_action));
415
430
416
431
if (disable_input) {
@@ -426,6 +441,10 @@ bool Input::is_action_just_released(const StringName &p_action, bool p_exact) co
426
441
return false ;
427
442
}
428
443
444
+ if (!(p_player_mask & E->value .player_mask )) {
445
+ return false ;
446
+ }
447
+
429
448
// Backward compatibility for legacy behavior, only return true if currently released.
430
449
bool released_requirement = legacy_just_pressed_behavior ? !E->value .cache .pressed : true ;
431
450
@@ -436,7 +455,7 @@ bool Input::is_action_just_released(const StringName &p_action, bool p_exact) co
436
455
}
437
456
}
438
457
439
- float Input::get_action_strength (const StringName &p_action, bool p_exact) const {
458
+ float Input::get_action_strength (const StringName &p_action, bool p_exact, uint8_t p_player_mask ) const {
440
459
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), 0.0 , InputMap::get_singleton ()->suggest_actions (p_action));
441
460
442
461
if (disable_input) {
@@ -452,10 +471,14 @@ float Input::get_action_strength(const StringName &p_action, bool p_exact) const
452
471
return 0 .0f ;
453
472
}
454
473
474
+ if (!(p_player_mask & E->value .player_mask )) {
475
+ return 0 .0f ;
476
+ }
477
+
455
478
return E->value .cache .strength ;
456
479
}
457
480
458
- float Input::get_action_raw_strength (const StringName &p_action, bool p_exact) const {
481
+ float Input::get_action_raw_strength (const StringName &p_action, bool p_exact, uint8_t p_player_mask ) const {
459
482
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), 0.0 , InputMap::get_singleton ()->suggest_actions (p_action));
460
483
461
484
if (disable_input) {
@@ -471,17 +494,21 @@ float Input::get_action_raw_strength(const StringName &p_action, bool p_exact) c
471
494
return 0 .0f ;
472
495
}
473
496
497
+ if (!(p_player_mask & E->value .player_mask )) {
498
+ return 0 .0f ;
499
+ }
500
+
474
501
return E->value .cache .raw_strength ;
475
502
}
476
503
477
- float Input::get_axis (const StringName &p_negative_action, const StringName &p_positive_action) const {
478
- return get_action_strength (p_positive_action) - get_action_strength (p_negative_action);
504
+ float Input::get_axis (const StringName &p_negative_action, const StringName &p_positive_action, uint8_t p_player_mask ) const {
505
+ return get_action_strength (p_positive_action, false , p_player_mask ) - get_action_strength (p_negative_action, false , p_player_mask );
479
506
}
480
507
481
- Vector2 Input::get_vector (const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone) const {
508
+ Vector2 Input::get_vector (const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone, uint8_t p_player_mask ) const {
482
509
Vector2 vector = Vector2 (
483
- get_action_raw_strength (p_positive_x) - get_action_raw_strength (p_negative_x),
484
- get_action_raw_strength (p_positive_y) - get_action_raw_strength (p_negative_y));
510
+ get_action_raw_strength (p_positive_x, false , p_player_mask ) - get_action_raw_strength (p_negative_x, false , p_player_mask ),
511
+ get_action_raw_strength (p_positive_y, false , p_player_mask ) - get_action_raw_strength (p_negative_y, false , p_player_mask ));
485
512
486
513
if (p_deadzone < 0 .0f ) {
487
514
// If the deadzone isn't specified, get it from the average of the actions.
@@ -879,6 +906,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
879
906
device_state.strength [event_index] = p_event->get_action_strength (E.key );
880
907
device_state.raw_strength [event_index] = p_event->get_action_raw_strength (E.key );
881
908
909
+ // TODO: Not sure.
910
+ // uint32_t player_mask = p_event->get_player();
911
+
882
912
// Update the action's global state and cache.
883
913
if (!is_pressed) {
884
914
action_state.api_pressed = false ; // Always release the event from action_press() method.
@@ -1014,7 +1044,7 @@ Point2 Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, cons
1014
1044
return rel_warped;
1015
1045
}
1016
1046
1017
- void Input::action_press (const StringName &p_action, float p_strength) {
1047
+ void Input::action_press (const StringName &p_action, float p_strength, uint8_t p_player_mask ) {
1018
1048
ERR_FAIL_COND_MSG (!InputMap::get_singleton ()->has_action (p_action), InputMap::get_singleton ()->suggest_actions (p_action));
1019
1049
1020
1050
// Create or retrieve existing action.
@@ -1028,10 +1058,11 @@ void Input::action_press(const StringName &p_action, float p_strength) {
1028
1058
action_state.exact = true ;
1029
1059
action_state.api_pressed = true ;
1030
1060
action_state.api_strength = CLAMP (p_strength, 0 .0f , 1 .0f );
1061
+ action_state.player_mask = p_player_mask;
1031
1062
_update_action_cache (p_action, action_state);
1032
1063
}
1033
1064
1034
- void Input::action_release (const StringName &p_action) {
1065
+ void Input::action_release (const StringName &p_action, uint8_t p_player_mask ) {
1035
1066
ERR_FAIL_COND_MSG (!InputMap::get_singleton ()->has_action (p_action), InputMap::get_singleton ()->suggest_actions (p_action));
1036
1067
1037
1068
// Create or retrieve existing action.
@@ -1046,6 +1077,7 @@ void Input::action_release(const StringName &p_action) {
1046
1077
action_state.exact = true ;
1047
1078
action_state.api_pressed = false ;
1048
1079
action_state.api_strength = 0.0 ;
1080
+ action_state.player_mask = p_player_mask;
1049
1081
}
1050
1082
1051
1083
void Input::set_emulate_touch_from_mouse (bool p_emulate) {
0 commit comments