WinRT: Fix Gamepad input

Fix #9216
This commit is contained in:
George Marques 2017-06-24 12:15:49 -03:00
parent 4b6e43f67e
commit fbb4107ec7
No known key found for this signature in database
GPG Key ID: 046BD46A3201E43D

View File

@ -35,9 +35,9 @@ using namespace Windows::Foundation;
void JoystickWinrt::register_events() { void JoystickWinrt::register_events() {
Gamepad::GamepadAdded += Gamepad::GamepadAdded +=
ref new EventHandler<Gamepad^>(this, &JoystickWinrt::OnGamepadAdded); ref new EventHandler<Gamepad ^>(this, &JoystickWinrt::OnGamepadAdded);
Gamepad::GamepadRemoved += Gamepad::GamepadRemoved +=
ref new EventHandler<Gamepad^>(this, &JoystickWinrt::OnGamepadRemoved); ref new EventHandler<Gamepad ^>(this, &JoystickWinrt::OnGamepadRemoved);
} }
uint32_t JoystickWinrt::process_controllers(uint32_t p_last_id) { uint32_t JoystickWinrt::process_controllers(uint32_t p_last_id) {
@ -50,12 +50,12 @@ uint32_t JoystickWinrt::process_controllers(uint32_t p_last_id) {
case ControllerType::GAMEPAD_CONTROLLER: { case ControllerType::GAMEPAD_CONTROLLER: {
GamepadReading reading = ((Gamepad^)controllers[i].controller_reference)->GetCurrentReading(); GamepadReading reading = ((Gamepad ^) controllers[i].controller_reference)->GetCurrentReading();
int button_mask = (int)GamepadButtons::Menu; int button_mask = (int)GamepadButtons::Menu;
for (int j = 0; j < 14; j++) { for (int j = 0; j < 14; j++) {
p_last_id = input->joy_button(p_last_id, controllers[i].id, j,(int)reading.Buttons & button_mask); p_last_id = input->joy_button(p_last_id, controllers[i].id, j, (int)reading.Buttons & button_mask);
button_mask *= 2; button_mask *= 2;
} }
@ -80,7 +80,7 @@ JoystickWinrt::JoystickWinrt() {
controllers[i].id = i; controllers[i].id = i;
} }
JoystickWinrt::JoystickWinrt(InputDefault * p_input) { JoystickWinrt::JoystickWinrt(InputDefault *p_input) {
input = p_input; input = p_input;
@ -103,9 +103,10 @@ void JoystickWinrt::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::I
controllers[idx].connected = true; controllers[idx].connected = true;
controllers[idx].controller_reference = value; controllers[idx].controller_reference = value;
controllers[idx].id = idx;
controllers[idx].type = ControllerType::GAMEPAD_CONTROLLER; controllers[idx].type = ControllerType::GAMEPAD_CONTROLLER;
input->joy_connection_changed(idx, true, "Xbox Controller", "__WINRT_GAMEPAD__"); input->joy_connection_changed(controllers[idx].id, true, "Xbox Controller", "__WINRT_GAMEPAD__");
} }
void JoystickWinrt::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { void JoystickWinrt::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) {
@ -122,15 +123,8 @@ void JoystickWinrt::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming:
ERR_FAIL_COND(idx == -1); ERR_FAIL_COND(idx == -1);
for (int i = idx + 1; i < MAX_CONTROLLERS - 1; i++) { controllers[idx].connected = false;
controllers[idx].controller_reference = nullptr;
if (!controllers[i].connected) {
break;
}
controllers[i - 1] = controllers[i];
}
controllers[MAX_CONTROLLERS - 1] = ControllerDevice();
input->joy_connection_changed(idx, false, "Xbox Controller"); input->joy_connection_changed(idx, false, "Xbox Controller");
} }