[gnome-games/wip/abhinavsingh/gamepad-config: 16/16] gamepad: Improve gamepad mapping builder
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 16/16] gamepad: Improve gamepad mapping builder
- Date: Mon, 12 Jun 2017 20:54:46 +0000 (UTC)
commit c54fed99c860d19aff01c71e4f8987c3c16c0ca0
Author: theawless <theawless gmail com>
Date: Tue Jun 13 01:28:51 2017 +0530
gamepad: Improve gamepad mapping builder
Allow more than just hat->hat mappings. Show more error messages for
illegal mapping combinations.
src/gamepad/gamepad-mapping-builder.vala | 27 ++++++++++++---------------
src/ui/gamepad-mapper.vala | 10 +++++++++-
2 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/src/gamepad/gamepad-mapping-builder.vala b/src/gamepad/gamepad-mapping-builder.vala
index c5ffc28..30ea686 100644
--- a/src/gamepad/gamepad-mapping-builder.vala
+++ b/src/gamepad/gamepad-mapping-builder.vala
@@ -11,10 +11,12 @@ private class Games.GamepadMappingBuilder : Object {
"back", "guide", "start",
"leftx", "rightx", "lefty", "righty" };
private string[] destinations;
+ private GamepadDPad[] dpads;
construct {
destinations = new string[sources.length];
inputs = GamepadInput.get_standard_inputs ();
+ dpads = new GamepadDPad[]{};
}
public GamepadMappingBuilder (Gamepad gamepad) {
@@ -44,25 +46,20 @@ private class Games.GamepadMappingBuilder : Object {
return add_destination (destination_string, source);
}
- public bool set_hat_mapping (uint8 hardware_index, int32 hardware_value, GamepadInput source) {
+ public bool set_hat_mapping (uint8 hardware_index, int32 hardware_value, uint16 axis, GamepadInput
source) {
var destination_string = "h" + hardware_index.to_string ();
destination_string += ".";
- // doesn't work for many cases
- switch (source.code) {
- case EventCode.BTN_DPAD_UP:
- case EventCode.BTN_DPAD_DOWN:
- destination_string += (hardware_value == 1) ? "1" : "3";
+ while (dpads.length <= hardware_index)
+ dpads += GamepadDPad ();
+ var dpad = dpads[hardware_index];
+ var changed_value = hardware_value == 0 ? dpad.axis_values[axis] : hardware_value;
+ dpad.axis_values[axis] = hardware_value;
- break;
- case EventCode.BTN_DPAD_LEFT:
- case EventCode.BTN_DPAD_RIGHT:
- destination_string += (hardware_value == 1) ? "4" : "2";
-
- break;
- default:
- break;
- }
+ // add 4 so the remainder is positive
+ var dpad_position = (changed_value + axis + 4) % 4;
+ var dpad_position_2pow = Math.pow (2, dpad_position);
+ destination_string += dpad_position_2pow.to_string ();
return add_destination (destination_string, source);
}
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index e4dca61..fb1d9e1 100644
--- a/src/ui/gamepad-mapper.vala
+++ b/src/ui/gamepad-mapper.vala
@@ -141,6 +141,9 @@ private class Games.GamepadMapper : Gtk.Box {
}
private void on_button_event (EventGamepadButton event) {
+ if (input.type == EventCode.EV_ABS) {
+ error_message.label = _("This combination is not valid");
+ }
if (!mapping_builder.set_button_mapping (event.gamepad_button.hardware_index, input)) {
error_message.label = _("This button is already in use");
@@ -151,6 +154,9 @@ private class Games.GamepadMapper : Gtk.Box {
}
private void on_axis_event (EventGamepadAxis event) {
+ if (input.type == EventCode.EV_KEY) {
+ error_message.label = _("This combination is not valid");
+ }
if (-0.8 < event.gamepad_axis.value && event.gamepad_axis.value < 0.8)
return;
@@ -167,7 +173,9 @@ private class Games.GamepadMapper : Gtk.Box {
if (event.gamepad_hat.value == 0)
return;
- if (!mapping_builder.set_hat_mapping (event.gamepad_hat.hardware_index,
event.gamepad_hat.value, input)) {
+ var success = mapping_builder.set_hat_mapping (event.gamepad_hat.hardware_index,
event.gamepad_hat.value,
+ event.gamepad_hat.axis, input);
+ if (!success) {
error_message.label = _("This hat is already in use");
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]