Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ingame
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
ingame
Commits
72484c3a
Commit
72484c3a
authored
May 06, 2024
by
Georgiy Yankovskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gamepad back button, autofocus to play button for GameInfoScene.qml
parent
d85cd652
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
38 deletions
+92
-38
App.py
ingame/models/App.py
+2
-0
Gamepad.py
ingame/models/Gamepad.py
+15
-0
Button.qml
qml/components/Button.qml
+23
-23
Tabs.qml
qml/components/Tabs.qml
+2
-1
Game.qml
qml/delegates/Game.qml
+11
-6
GameInfoScene.qml
qml/scenes/GameInfoScene.qml
+39
-8
No files found.
ingame/models/App.py
View file @
72484c3a
...
...
@@ -29,6 +29,7 @@ class App(QtCore.QObject):
gamepad_clicked_LB
=
Signal
(
bool
,
name
=
"gamepadClickedLB"
)
gamepad_clicked_RB
=
Signal
(
bool
,
name
=
"gamepadClickedRB"
)
gamepad_clicked_apply
=
Signal
(
bool
,
name
=
"gamepadClickedApply"
)
gamepad_clicked_back
=
Signal
(
bool
,
name
=
"gamepadClickedBack"
)
gamepad_axis_left
=
Signal
(
bool
,
name
=
"gamepadAxisLeft"
)
gamepad_axis_right
=
Signal
(
bool
,
name
=
"gamepadAxisRight"
)
...
...
@@ -46,6 +47,7 @@ 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
.
back_clicked
=
lambda
:
self
.
gamepad_clicked_back
.
emit
(
True
)
self
.
setup
()
...
...
ingame/models/Gamepad.py
View file @
72484c3a
...
...
@@ -12,20 +12,26 @@ class Gamepad:
LEFT_RIGHT_AXIS
=
0
LEFT_RIGHT_AXIS_SENSITIVITY
=
0.7
APPLY_BUTTON
=
0
BACK_BUTTON
=
1
def
__init__
(
self
):
self
.
joystick
:
Union
[
Joystick
,
None
]
=
None
self
.
terminated
:
bool
=
False
self
.
last_rb_clicked
:
bool
=
False
self
.
last_lb_clicked
:
bool
=
False
self
.
last_apply_clicked
:
bool
=
False
self
.
last_left_clicked
:
bool
=
False
self
.
last_right_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
.
back_clicked
:
()
=
lambda
:
None
self
.
apply_clicked
:
()
=
lambda
:
None
self
.
thread
:
Union
[
threading
.
Thread
,
None
]
=
None
pygame
.
init
()
...
...
@@ -58,6 +64,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
)
back_button
=
self
.
joystick
.
get_button
(
self
.
BACK_BUTTON
)
# LB
...
...
@@ -103,6 +110,14 @@ 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
# BACK
if
back_button
and
not
self
.
last_back_clicked
:
self
.
last_back_clicked
=
not
self
.
last_back_clicked
self
.
back_clicked
()
if
not
back_button
and
self
.
last_back_clicked
:
self
.
last_back_clicked
=
not
self
.
last_back_clicked
# print(f"Button {self.LB_BUTTON}: {lb_button}")
# print(f"Button {self.RB_BUTTON}: {rb_button}")
...
...
qml/components/Button.qml
View file @
72484c3a
...
...
@@ -7,32 +7,32 @@ C.Button {
font.bold
:
true
//font.letterSpacing: font.pixelSize / 100 * 30
//
font.pointSize: Math.max(parent.width / 100,10)
//
contentItem: Text {
//
text: control.text
//
font: control.font
//
//fontSizeMode: Text.Fit; minimumPixelSize: 10;
//
opacity: enabled ? 1.0 : 0.3
// color: control.down ? "Black
" : (control.activeFocus ? "#333333" : "#ffffff")
//
horizontalAlignment: Text.AlignHCenter
//
verticalAlignment: Text.AlignVCenter
//
elide: Text.ElideRight
//
leftPadding: font.pointSize / 100 * 20
//
rightPadding: font.pointSize / 100 * 20
//
topPadding: font.pointSize / 100 * 0
//
bottomPadding: font.pointSize / 100 * 0
font.pointSize
:
Math
.
max
(
parent
.
width
/
100
,
10
)
contentItem
:
Text
{
text
:
control
.
text
font
:
control
.
font
//fontSizeMode: Text.Fit; minimumPixelSize: 10;
opacity
:
enabled
?
1.0
:
0.3
color
:
control
.
down
?
"#000000
"
:
(
control
.
activeFocus
?
"#333333"
:
"#ffffff"
)
horizontalAlignment
:
Text
.
AlignHCenter
verticalAlignment
:
Text
.
AlignVCenter
elide
:
Text
.
ElideRight
leftPadding
:
font
.
pointSize
/
100
*
20
rightPadding
:
font
.
pointSize
/
100
*
20
topPadding
:
font
.
pointSize
/
100
*
0
bottomPadding
:
font
.
pointSize
/
100
*
0
//
}
}
//
background: Rectangle {
//
//implicitWidth: 100
//
//implicitHeight: 40
//
opacity: enabled ? 1 : 0.3
// color: control.down ? "#000000" : (control.activeFocus ? "#ffffff" : "#00
000000")
//
border.width: 0
//
radius: 16
background
:
Rectangle
{
//implicitWidth: 100
//implicitHeight: 40
opacity
:
enabled
?
1
:
0.3
color
:
control
.
down
?
"#aaaaaa"
:
(
control
.
activeFocus
?
"#aaaaaa"
:
"#
000000"
)
border.width
:
0
radius
:
16
//
}
}
}
qml/components/Tabs.qml
View file @
72484c3a
...
...
@@ -218,8 +218,9 @@ Rectangle {
}
function
onGamepadClickedApply
(
done
){
if
(
!
visible
)
return
;
console
.
log
(
"onGamepadClickedApply"
,
tabs
.
focusedItems
);
let
c
=
gamesGrid
.
children
;
c
[
tabs
.
focusedItems
].
clicked
();
c
[
tabs
.
focusedItems
].
press
();
}
}
...
...
qml/delegates/Game.qml
View file @
72484c3a
...
...
@@ -17,16 +17,21 @@ C.Button {
id
:
hoverArea
anchors.fill
:
parent
hoverEnabled
:
true
acceptedButtons
:
"AllButtons"
onClicked
:
function
(){
// console.log(game.title);
gameInfoScene
.
title
=
game
.
gameTitle
;
gameInfoScene
.
icon
=
game
.
gameIcon
;
gameInfoScene
.
exec
=
game
.
gameExec
;
window
.
scene
=
SceneConstants
.
gameInfoScene
;
if
(
!
game
.
visible
)
return
;
game
.
press
();
}
}
function
press
(){
if
(
!
visible
)
return
;
console
.
log
(
game
.
title
);
gameInfoScene
.
title
=
game
.
gameTitle
;
gameInfoScene
.
icon
=
game
.
gameIcon
;
gameInfoScene
.
exec
=
game
.
gameExec
;
window
.
scene
=
SceneConstants
.
gameInfoScene
;
}
...
...
qml/scenes/GameInfoScene.qml
View file @
72484c3a
...
...
@@ -9,6 +9,17 @@ Rectangle {
property
string
icon
:
""
property
string
exec
:
""
onVisibleChanged
:
function
(){
// if(visible){
if
(
!
visible
)
return
;
container
.
setItemsFocus
(
1
);
// }
}
Keys.onEscapePressed
:
function
(){
if
(
!
visible
)
return
;
back
.
clicked
();
}
id
:
container
x
:
0
...
...
@@ -67,6 +78,7 @@ Rectangle {
}
Button
{
id
:
runGameButton
anchors.left
:
parent
.
left
anchors.top
:
parent
.
top
anchors.leftMargin
:
142
...
...
@@ -82,20 +94,35 @@ Rectangle {
// LOGIC
property
int
focusedItems
:
0
;
function
focusElements
(){
return
[
back
,
runGameButton
];
}
function
applyItemsFocus
(
inc
){
let
c
=
children
;
let
c
=
focusElements
();
let
i
=
focusedItems
;
focusedItems
+=
inc
;
if
(
focusedItems
>=
c
.
length
)
focusedItems
=
0
;
i
+=
inc
;
if
(
i
>=
c
.
length
)
i
=
0
;
if
(
focusedItems
<
0
)
focusedItems
=
c
.
length
-
1
;
if
(
i
<
0
)
i
=
c
.
length
-
1
;
c
[
focusedItems
].
forceActiveFocus
(
);
setItemsFocus
(
i
);
// c[focusedItems].clicked();
}
function
setItemsFocus
(
i
){
let
c
=
focusElements
();
focusedItems
=
i
;
c
[
i
].
forceActiveFocus
();
}
Connections
{
target
:
core_app
function
onGamepadAxisLeft
(
done
){
...
...
@@ -108,9 +135,13 @@ Rectangle {
}
function
onGamepadClickedApply
(
done
){
if
(
!
visible
)
return
;
let
c
=
container
.
children
;
let
c
=
focusElements
()
;
c
[
container
.
focusedItems
].
clicked
();
}
function
onGamepadClickedBack
(
done
){
if
(
!
visible
)
return
;
back
.
clicked
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment