Commit 4b5a7b32 authored by Georgiy Yankovskiy's avatar Georgiy Yankovskiy

Gamepad up/down handler

parent ac8c42df
......@@ -31,6 +31,8 @@ class App(QtCore.QObject):
gamepad_clicked_RB = Signal(bool, name="gamepadClickedRB")
gamepad_clicked_apply = Signal(bool, name="gamepadClickedApply")
gamepad_clicked_back = Signal(bool, name="gamepadClickedBack")
gamepad_axis_up = Signal(bool, name="gamepadAxisUp")
gamepad_axis_down = Signal(bool, name="gamepadAxisDown")
gamepad_axis_left = Signal(bool, name="gamepadAxisLeft")
gamepad_axis_right = Signal(bool, name="gamepadAxisRight")
......@@ -48,6 +50,8 @@ class App(QtCore.QObject):
self.gamepad.apply_clicked = lambda: self.gamepad_clicked_apply.emit(True)
self.gamepad.l_clicked = lambda: self.gamepad_axis_left.emit(True)
self.gamepad.r_clicked = lambda: self.gamepad_axis_right.emit(True)
self.gamepad.u_clicked = lambda: self.gamepad_axis_up.emit(True)
self.gamepad.d_clicked = lambda: self.gamepad_axis_down.emit(True)
self.gamepad.back_clicked = lambda: self.gamepad_clicked_back.emit(True)
self.agent = GameAgent()
......
......@@ -11,6 +11,8 @@ class Gamepad:
RB_BUTTON = 5
LEFT_RIGHT_AXIS = 0
LEFT_RIGHT_AXIS_SENSITIVITY = 0.7
UP_DOWN_AXIS = 1
UP_DOWN_AXIS_SENSITIVITY = 0.7
APPLY_BUTTON = 0
BACK_BUTTON = 1
......@@ -23,12 +25,16 @@ class Gamepad:
self.last_apply_clicked: bool = False
self.last_left_clicked: bool = False
self.last_right_clicked: bool = False
self.last_up_clicked: bool = False
self.last_down_clicked: bool = False
self.last_back_clicked: bool = False
self.lb_clicked: () = lambda: None
self.rb_clicked: () = lambda: None
self.l_clicked: () = lambda: None
self.r_clicked: () = lambda: None
self.u_clicked: () = lambda: None
self.d_clicked: () = lambda: None
self.back_clicked: () = lambda: None
self.apply_clicked: () = lambda: None
......@@ -64,6 +70,7 @@ class Gamepad:
rb_button = self.joystick.get_button(self.RB_BUTTON)
apply_button = self.joystick.get_button(self.APPLY_BUTTON)
left_right_axis = self.joystick.get_axis(self.LEFT_RIGHT_AXIS)
up_down_axis = self.joystick.get_axis(self.UP_DOWN_AXIS)
back_button = self.joystick.get_button(self.BACK_BUTTON)
# LB
......@@ -110,6 +117,23 @@ class Gamepad:
if (not left_right_axis >= self.LEFT_RIGHT_AXIS_SENSITIVITY) and self.last_right_clicked:
self.last_right_clicked = not self.last_right_clicked
# UP
if (up_down_axis <= -self.UP_DOWN_AXIS_SENSITIVITY) and not self.last_up_clicked:
self.last_up_clicked = not self.last_up_clicked
self.u_clicked()
if not (up_down_axis <= -self.UP_DOWN_AXIS_SENSITIVITY) and self.last_up_clicked:
self.last_up_clicked = not self.last_up_clicked
# DOWN
if (up_down_axis >= self.UP_DOWN_AXIS_SENSITIVITY) and not self.last_down_clicked:
self.last_down_clicked = not self.last_down_clicked
self.d_clicked()
if (not up_down_axis >= self.UP_DOWN_AXIS_SENSITIVITY) and self.last_down_clicked:
self.last_down_clicked = not self.last_down_clicked
# BACK
if back_button and not self.last_back_clicked:
self.last_back_clicked = not self.last_back_clicked
......
......@@ -380,14 +380,17 @@ Rectangle {
if(window.scene !== S.homeScene) return;
let c = gamesGrid.children;
let l = c.length - 1; // exclude QQuickRepeater
tabs.focusedItems += inc;
if(tabs.focusedItems >= c.length)
tabs.focusedItems = 0;
if(tabs.focusedItems < 0)
tabs.focusedItems = c.length - 1;
console.log(tabs.focusedItems);
if(tabs.focusedItems + inc >= l) {
tabs.focusedItems = (c.focusedItems + inc === l - 1) ? 0 : l - 1;
} else if(tabs.focusedItems + inc < 0) {
tabs.focusedItems = (c.focusedItems + inc === 0) ? l - 1 : 0; //;
} else {
tabs.focusedItems += inc;
}
c[tabs.focusedItems].forceActiveFocus();
// gamesScroller.contentY = c[tabs.focusedItems].y; // not working
// c[tabs.focusedItems].clicked();
......@@ -401,6 +404,14 @@ Rectangle {
if(window.scene !== S.homeScene) return;
tabs.applyTabsFocus(1)
}
function onGamepadAxisUp(done){
if(window.scene !== S.homeScene) return;
tabs.applyItemsFocus(-gamesGrid.columns)
}
function onGamepadAxisDown(done){
if(window.scene !== S.homeScene) return;
tabs.applyItemsFocus(gamesGrid.columns)
}
function onGamepadAxisLeft(done){
if(window.scene !== S.homeScene) return;
tabs.applyItemsFocus(-1)
......
......@@ -40,6 +40,12 @@ Window {
function onGamepadAxisRight(done){
window._trigger("onGamepadAxisRight", done);
}
function onGamepadAxisUp(done){
window._trigger("onGamepadAxisUp", done);
}
function onGamepadAxisDown(done){
window._trigger("onGamepadAxisDown", done);
}
function onGamepadClickedApply(done){
window._trigger("onGamepadClickedApply", done);
}
......@@ -56,6 +62,8 @@ Window {
let d = scenes[scene];
// console.log("CALLUP " + _method);
if(d !== null && d[_method] !== undefined && d[_method] !== null)
d[_method](args);
}
......
......@@ -95,7 +95,7 @@ Rectangle {
}
ColumnLayout{
ColumnLayout {
// anchors.fill:parent
anchors.left: parent.left
anchors.top: parent.top
......@@ -107,7 +107,7 @@ Rectangle {
anchors.topMargin: parent.height / 100 * 3
spacing: 6
ItemGroup{
ItemGroup {
id: topPanel
Button {
id: back
......@@ -178,7 +178,7 @@ Rectangle {
}
}
}
Rectangle{
Rectangle {
// Start pos
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -387,6 +387,13 @@ Rectangle {
}
function onGamepadAxisUp(done){
root.onGamepadAxisLeft(done);
}
function onGamepadAxisDown(done){
root.onGamepadAxisRight(done);
}
function onGamepadAxisLeft(done){
if(window.scene !== S.gameInfoScene) return;
root.applyItemsFocus(-1)
......
......@@ -54,6 +54,14 @@ Rectangle {
function onGamepadAxisRight(done){
tabs.onGamepadAxisRight(done)
}
function onGamepadAxisUp(done){
tabs.onGamepadAxisUp(done)
}
function onGamepadAxisDown(done){
tabs.onGamepadAxisDown(done)
}
function onGamepadClickedApply(done){
tabs.onGamepadClickedApply(done)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment