@@ -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 (PlayerMask::PLAYER_ALL ));
161
+ ClassDB::bind_method (D_METHOD (" action_release" , " action" , " player_mask " ), &Input::action_release, DEFVAL (PlayerMask::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,19 @@ void Input::_bind_methods() {
201
201
BIND_ENUM_CONSTANT (CURSOR_HSPLIT);
202
202
BIND_ENUM_CONSTANT (CURSOR_HELP);
203
203
204
+ BIND_CONSTANT (PLAYERS_MAX);
205
+
206
+ BIND_BITFIELD_FLAG (PLAYER_NONE);
207
+ BIND_BITFIELD_FLAG (PLAYER_1);
208
+ BIND_BITFIELD_FLAG (PLAYER_2);
209
+ BIND_BITFIELD_FLAG (PLAYER_3);
210
+ BIND_BITFIELD_FLAG (PLAYER_4);
211
+ BIND_BITFIELD_FLAG (PLAYER_5);
212
+ BIND_BITFIELD_FLAG (PLAYER_6);
213
+ BIND_BITFIELD_FLAG (PLAYER_7);
214
+ BIND_BITFIELD_FLAG (PLAYER_8);
215
+ BIND_BITFIELD_FLAG (PLAYER_ALL);
216
+
204
217
ADD_SIGNAL (MethodInfo (" joy_connection_changed" , PropertyInfo (Variant::INT, " device" ), PropertyInfo (Variant::BOOL, " connected" )));
205
218
}
206
219
@@ -369,7 +382,7 @@ bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const {
369
382
return joy_buttons_pressed.has (_combine_device (p_button, p_device));
370
383
}
371
384
372
- bool Input::is_action_pressed (const StringName &p_action, bool p_exact) const {
385
+ bool Input::is_action_pressed (const StringName &p_action, bool p_exact, BitField<PlayerMask> p_player_mask ) const {
373
386
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), false , InputMap::get_singleton ()->suggest_actions (p_action));
374
387
375
388
if (disable_input) {
@@ -381,10 +394,10 @@ bool Input::is_action_pressed(const StringName &p_action, bool p_exact) const {
381
394
return false ;
382
395
}
383
396
384
- return E->value .cache .pressed && (p_exact ? E->value .exact : true );
397
+ return E->value .cache .pressed && (p_exact ? E->value .exact : true ) && p_player_mask & E-> value . player_mask ;
385
398
}
386
399
387
- bool Input::is_action_just_pressed (const StringName &p_action, bool p_exact) const {
400
+ bool Input::is_action_just_pressed (const StringName &p_action, bool p_exact, BitField<PlayerMask> p_player_mask ) const {
388
401
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), false , InputMap::get_singleton ()->suggest_actions (p_action));
389
402
390
403
if (disable_input) {
@@ -400,6 +413,10 @@ bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) con
400
413
return false ;
401
414
}
402
415
416
+ if (!(p_player_mask & E->value .player_mask )) {
417
+ return false ;
418
+ }
419
+
403
420
// Backward compatibility for legacy behavior, only return true if currently pressed.
404
421
bool pressed_requirement = legacy_just_pressed_behavior ? E->value .cache .pressed : true ;
405
422
@@ -410,7 +427,7 @@ bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) con
410
427
}
411
428
}
412
429
413
- bool Input::is_action_just_released (const StringName &p_action, bool p_exact) const {
430
+ bool Input::is_action_just_released (const StringName &p_action, bool p_exact, BitField<PlayerMask> p_player_mask ) const {
414
431
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), false , InputMap::get_singleton ()->suggest_actions (p_action));
415
432
416
433
if (disable_input) {
@@ -426,6 +443,10 @@ bool Input::is_action_just_released(const StringName &p_action, bool p_exact) co
426
443
return false ;
427
444
}
428
445
446
+ if (!(p_player_mask & E->value .player_mask )) {
447
+ return false ;
448
+ }
449
+
429
450
// Backward compatibility for legacy behavior, only return true if currently released.
430
451
bool released_requirement = legacy_just_pressed_behavior ? !E->value .cache .pressed : true ;
431
452
@@ -436,7 +457,7 @@ bool Input::is_action_just_released(const StringName &p_action, bool p_exact) co
436
457
}
437
458
}
438
459
439
- float Input::get_action_strength (const StringName &p_action, bool p_exact) const {
460
+ float Input::get_action_strength (const StringName &p_action, bool p_exact, BitField<PlayerMask> p_player_mask ) const {
440
461
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), 0.0 , InputMap::get_singleton ()->suggest_actions (p_action));
441
462
442
463
if (disable_input) {
@@ -452,10 +473,14 @@ float Input::get_action_strength(const StringName &p_action, bool p_exact) const
452
473
return 0 .0f ;
453
474
}
454
475
476
+ if (!(p_player_mask & E->value .player_mask )) {
477
+ return 0 .0f ;
478
+ }
479
+
455
480
return E->value .cache .strength ;
456
481
}
457
482
458
- float Input::get_action_raw_strength (const StringName &p_action, bool p_exact) const {
483
+ float Input::get_action_raw_strength (const StringName &p_action, bool p_exact, BitField<PlayerMask> p_player_mask ) const {
459
484
ERR_FAIL_COND_V_MSG (!InputMap::get_singleton ()->has_action (p_action), 0.0 , InputMap::get_singleton ()->suggest_actions (p_action));
460
485
461
486
if (disable_input) {
@@ -471,17 +496,21 @@ float Input::get_action_raw_strength(const StringName &p_action, bool p_exact) c
471
496
return 0 .0f ;
472
497
}
473
498
499
+ if (!(p_player_mask & E->value .player_mask )) {
500
+ return 0 .0f ;
501
+ }
502
+
474
503
return E->value .cache .raw_strength ;
475
504
}
476
505
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);
506
+ float Input::get_axis (const StringName &p_negative_action, const StringName &p_positive_action, BitField<PlayerMask> p_player_mask ) const {
507
+ return get_action_strength (p_positive_action, false , p_player_mask ) - get_action_strength (p_negative_action, false , p_player_mask );
479
508
}
480
509
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 {
510
+ 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, BitField<PlayerMask> p_player_mask ) const {
482
511
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));
512
+ get_action_raw_strength (p_positive_x, false , p_player_mask ) - get_action_raw_strength (p_negative_x, false , p_player_mask ),
513
+ get_action_raw_strength (p_positive_y, false , p_player_mask ) - get_action_raw_strength (p_negative_y, false , p_player_mask ));
485
514
486
515
if (p_deadzone < 0 .0f ) {
487
516
// If the deadzone isn't specified, get it from the average of the actions.
@@ -711,11 +740,14 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
711
740
if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index () == MouseButton::LEFT) {
712
741
Ref<InputEventScreenTouch> touch_event;
713
742
touch_event.instantiate ();
743
+
714
744
touch_event->set_pressed (mb->is_pressed ());
715
745
touch_event->set_canceled (mb->is_canceled ());
716
746
touch_event->set_position (mb->get_position ());
717
747
touch_event->set_double_tap (mb->is_double_click ());
718
748
touch_event->set_device (InputEvent::DEVICE_ID_EMULATION);
749
+ touch_event->set_player_from_device ();
750
+
719
751
_THREAD_SAFE_UNLOCK_
720
752
event_dispatch_function (touch_event);
721
753
_THREAD_SAFE_LOCK_
@@ -746,6 +778,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
746
778
drag_event->set_velocity (get_last_mouse_velocity ());
747
779
drag_event->set_screen_velocity (get_last_mouse_screen_velocity ());
748
780
drag_event->set_device (InputEvent::DEVICE_ID_EMULATION);
781
+ drag_event->set_player_from_device ();
749
782
750
783
_THREAD_SAFE_UNLOCK_
751
784
event_dispatch_function (drag_event);
@@ -784,6 +817,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
784
817
button_event.instantiate ();
785
818
786
819
button_event->set_device (InputEvent::DEVICE_ID_EMULATION);
820
+ button_event->set_player_from_device ();
787
821
button_event->set_position (st->get_position ());
788
822
button_event->set_global_position (st->get_position ());
789
823
button_event->set_pressed (st->is_pressed ());
@@ -818,6 +852,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
818
852
motion_event.instantiate ();
819
853
820
854
motion_event->set_device (InputEvent::DEVICE_ID_EMULATION);
855
+ motion_event->set_player_from_device ();
821
856
motion_event->set_tilt (sd->get_tilt ());
822
857
motion_event->set_pen_inverted (sd->get_pen_inverted ());
823
858
motion_event->set_pressure (sd->get_pressure ());
@@ -879,6 +914,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
879
914
device_state.strength [event_index] = p_event->get_action_strength (E.key );
880
915
device_state.raw_strength [event_index] = p_event->get_action_raw_strength (E.key );
881
916
917
+ // TODO: Not sure.
918
+ // uint32_t player_mask = p_event->get_player();
919
+
882
920
// Update the action's global state and cache.
883
921
if (!is_pressed) {
884
922
action_state.api_pressed = false ; // Always release the event from action_press() method.
@@ -1014,7 +1052,7 @@ Point2 Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, cons
1014
1052
return rel_warped;
1015
1053
}
1016
1054
1017
- void Input::action_press (const StringName &p_action, float p_strength) {
1055
+ void Input::action_press (const StringName &p_action, float p_strength, uint8_t p_player_mask ) {
1018
1056
ERR_FAIL_COND_MSG (!InputMap::get_singleton ()->has_action (p_action), InputMap::get_singleton ()->suggest_actions (p_action));
1019
1057
1020
1058
// Create or retrieve existing action.
@@ -1028,10 +1066,11 @@ void Input::action_press(const StringName &p_action, float p_strength) {
1028
1066
action_state.exact = true ;
1029
1067
action_state.api_pressed = true ;
1030
1068
action_state.api_strength = CLAMP (p_strength, 0 .0f , 1 .0f );
1069
+ action_state.player_mask = p_player_mask;
1031
1070
_update_action_cache (p_action, action_state);
1032
1071
}
1033
1072
1034
- void Input::action_release (const StringName &p_action) {
1073
+ void Input::action_release (const StringName &p_action, uint8_t p_player_mask ) {
1035
1074
ERR_FAIL_COND_MSG (!InputMap::get_singleton ()->has_action (p_action), InputMap::get_singleton ()->suggest_actions (p_action));
1036
1075
1037
1076
// Create or retrieve existing action.
@@ -1046,6 +1085,7 @@ void Input::action_release(const StringName &p_action) {
1046
1085
action_state.exact = true ;
1047
1086
action_state.api_pressed = false ;
1048
1087
action_state.api_strength = 0.0 ;
1088
+ action_state.player_mask = p_player_mask;
1049
1089
}
1050
1090
1051
1091
void Input::set_emulate_touch_from_mouse (bool p_emulate) {
@@ -1067,6 +1107,7 @@ void Input::ensure_touch_mouse_raised() {
1067
1107
button_event.instantiate ();
1068
1108
1069
1109
button_event->set_device (InputEvent::DEVICE_ID_EMULATION);
1110
+ button_event->set_player_from_device ();
1070
1111
button_event->set_position (mouse_pos);
1071
1112
button_event->set_global_position (mouse_pos);
1072
1113
button_event->set_pressed (false );
@@ -1104,6 +1145,7 @@ void Input::set_default_cursor_shape(CursorShape p_shape) {
1104
1145
mm->set_position (mouse_pos);
1105
1146
mm->set_global_position (mouse_pos);
1106
1147
mm->set_device (InputEvent::DEVICE_ID_INTERNAL);
1148
+ mm->set_player_from_device ();
1107
1149
parse_input_event (mm);
1108
1150
}
1109
1151
@@ -1363,6 +1405,7 @@ void Input::_button_event(int p_device, JoyButton p_index, bool p_pressed) {
1363
1405
Ref<InputEventJoypadButton> ievent;
1364
1406
ievent.instantiate ();
1365
1407
ievent->set_device (p_device);
1408
+ ievent->set_player_from_device ();
1366
1409
ievent->set_button_index (p_index);
1367
1410
ievent->set_pressed (p_pressed);
1368
1411
@@ -1373,6 +1416,7 @@ void Input::_axis_event(int p_device, JoyAxis p_axis, float p_value) {
1373
1416
Ref<InputEventJoypadMotion> ievent;
1374
1417
ievent.instantiate ();
1375
1418
ievent->set_device (p_device);
1419
+ ievent->set_player_from_device ();
1376
1420
ievent->set_axis (p_axis);
1377
1421
ievent->set_axis_value (p_value);
1378
1422
0 commit comments