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
6f2c9e46
Commit
6f2c9e46
authored
Apr 25, 2024
by
Georgiy Yankovskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Game items gamepad switch (beta) + GameInfoScene.qml buttons gamepad switch (beta)
parent
9f5bf5e8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
12 deletions
+138
-12
App.py
ingame/models/App.py
+6
-0
Gamepad.py
ingame/models/Gamepad.py
+44
-1
Tabs.qml
qml/components/Tabs.qml
+45
-11
qml.qml
qml/qml.qml
+9
-0
GameInfoScene.qml
qml/scenes/GameInfoScene.qml
+34
-0
No files found.
ingame/models/App.py
View file @
6f2c9e46
...
...
@@ -28,6 +28,9 @@ 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_axis_left
=
Signal
(
bool
,
name
=
"gamepadAxisLeft"
)
gamepad_axis_right
=
Signal
(
bool
,
name
=
"gamepadAxisRight"
)
def
__init__
(
self
):
super
()
.
__init__
()
...
...
@@ -40,6 +43,9 @@ class App(QtCore.QObject):
self
.
gamepad
:
Gamepad
=
Gamepad
()
self
.
gamepad
.
lb_clicked
=
lambda
:
self
.
gamepad_clicked_LB
.
emit
(
True
)
self
.
gamepad
.
rb_clicked
=
lambda
:
self
.
gamepad_clicked_RB
.
emit
(
True
)
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
.
setup
()
...
...
ingame/models/Gamepad.py
View file @
6f2c9e46
...
...
@@ -9,14 +9,23 @@ from pygame.joystick import Joystick
class
Gamepad
:
LB_BUTTON
=
4
RB_BUTTON
=
5
LEFT_RIGHT_AXIS
=
0
LEFT_RIGHT_AXIS_SENSITIVITY
=
0.7
APPLY_BUTTON
=
0
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
.
lb_clicked
:
()
=
lambda
:
None
self
.
rb_clicked
:
()
=
lambda
:
None
self
.
l_clicked
:
()
=
lambda
:
None
self
.
r_clicked
:
()
=
lambda
:
None
self
.
apply_clicked
:
()
=
lambda
:
None
self
.
thread
:
Union
[
threading
.
Thread
,
None
]
=
None
pygame
.
init
()
...
...
@@ -35,12 +44,20 @@ class Gamepad:
def
cycle
(
self
):
try
:
# TODO: use this instead:
# events = pygame.event.get()
# for event in events:
# if event.type == pygame.JOYBUTTONDOWN:
while
not
self
.
terminated
:
# pygame.event.pump()
pygame
.
event
.
wait
()
lb_button
=
self
.
joystick
.
get_button
(
self
.
LB_BUTTON
)
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
)
# LB
...
...
@@ -60,13 +77,39 @@ class Gamepad:
if
not
rb_button
and
self
.
last_rb_clicked
:
self
.
last_rb_clicked
=
not
self
.
last_rb_clicked
# APPLY
if
apply_button
and
not
self
.
last_apply_clicked
:
self
.
last_apply_clicked
=
not
self
.
last_apply_clicked
self
.
apply_clicked
()
if
not
apply_button
and
self
.
last_apply_clicked
:
self
.
last_apply_clicked
=
not
self
.
last_apply_clicked
# LEFT
if
(
left_right_axis
<=
-
self
.
LEFT_RIGHT_AXIS_SENSITIVITY
)
and
not
self
.
last_left_clicked
:
self
.
last_left_clicked
=
not
self
.
last_left_clicked
self
.
l_clicked
()
if
not
(
left_right_axis
<=
-
self
.
LEFT_RIGHT_AXIS_SENSITIVITY
)
and
self
.
last_left_clicked
:
self
.
last_left_clicked
=
not
self
.
last_left_clicked
# RIGHT
if
(
left_right_axis
>=
self
.
LEFT_RIGHT_AXIS_SENSITIVITY
)
and
not
self
.
last_right_clicked
:
self
.
last_right_clicked
=
not
self
.
last_right_clicked
self
.
r_clicked
()
if
(
not
left_right_axis
>=
self
.
LEFT_RIGHT_AXIS_SENSITIVITY
)
and
self
.
last_right_clicked
:
self
.
last_right_clicked
=
not
self
.
last_right_clicked
# print(f"Button {self.LB_BUTTON}: {lb_button}")
# print(f"Button {self.RB_BUTTON}: {rb_button}")
# for i in range(self.joystick.get_numaxes()):
# axis = self.joystick.get_axis(i)
# print(f"Axis {i}: {axis}")
#
# for i in range(self.joystick.get_numbuttons()):
# button = self.joystick.get_button(i)
# print(f"Button {i}: {button}")
...
...
qml/components/Tabs.qml
View file @
6f2c9e46
...
...
@@ -148,23 +148,24 @@ Rectangle {
}
// LOGIC
property
int
focused
:
0
;
property
int
focusedTabs
:
0
;
property
int
focusedItems
:
0
;
function
applyFocus
(
inc
){
function
apply
Tabs
Focus
(
inc
){
if
(
!
visible
)
return
;
let
c
=
row
.
children
;
tabs
.
focused
+=
inc
;
if
(
tabs
.
focused
>=
c
.
length
)
tabs
.
focused
=
0
;
tabs
.
focused
Tabs
+=
inc
;
if
(
tabs
.
focused
Tabs
>=
c
.
length
)
tabs
.
focused
Tabs
=
0
;
if
(
tabs
.
focused
<
0
)
tabs
.
focused
=
c
.
length
-
1
;
if
(
tabs
.
focused
Tabs
<
0
)
tabs
.
focused
Tabs
=
c
.
length
-
1
;
c
[
tabs
.
focused
].
forceActiveFocus
();
c
[
tabs
.
focused
].
clicked
();
c
[
tabs
.
focused
Tabs
].
forceActiveFocus
();
c
[
tabs
.
focused
Tabs
].
clicked
();
/* if (c[i].focus) {
console.log("focus found");
...
...
@@ -173,13 +174,46 @@ Rectangle {
} */
}
function
applyItemsFocus
(
inc
){
if
(
!
gamesScroller
.
visible
)
return
;
let
c
=
gamesGrid
.
children
;
tabs
.
focusedItems
+=
inc
;
if
(
tabs
.
focusedItems
>=
c
.
length
)
tabs
.
focusedItems
=
0
;
if
(
tabs
.
focusedItems
<
0
)
tabs
.
focusedItems
=
c
.
length
-
1
;
c
[
tabs
.
focusedItems
].
forceActiveFocus
();
// gamesScroller.contentY = c[tabs.focusedItems].y; // not working
// c[tabs.focusedItems].clicked();
}
Connections
{
target
:
core_app
function
onGamepadClickedLB
(
done
){
tabs
.
applyFocus
(
1
)
if
(
!
visible
)
return
;
tabs
.
applyTabsFocus
(
-
1
)
}
function
onGamepadClickedRB
(
done
){
tabs
.
applyFocus
(
-
1
)
if
(
!
visible
)
return
;
tabs
.
applyTabsFocus
(
1
)
}
function
onGamepadAxisLeft
(
done
){
if
(
!
visible
)
return
;
tabs
.
applyItemsFocus
(
-
1
)
}
function
onGamepadAxisRight
(
done
){
if
(
!
visible
)
return
;
tabs
.
applyItemsFocus
(
1
)
}
function
onGamepadClickedApply
(
done
){
if
(
!
visible
)
return
;
let
c
=
gamesGrid
.
children
;
c
[
tabs
.
focusedItems
].
clicked
();
}
}
...
...
qml/qml.qml
View file @
6f2c9e46
...
...
@@ -24,6 +24,15 @@ Window {
function
onGamepadClickedRB
(
done
){
// console.log("core_app: onGamepadClickedRB");
}
function
onGamepadAxisLeft
(
done
){
// console.log("core_app: onGamepadAxisLeft");
}
function
onGamepadAxisRight
(
done
){
// console.log("core_app: onGamepadAxisRight");
}
function
onGamepadClickedApply
(
done
){
// console.log("core_app: onGamepadClickedApply");
}
}
Component.onDestruction
:
{
...
...
qml/scenes/GameInfoScene.qml
View file @
6f2c9e46
...
...
@@ -79,4 +79,38 @@ Rectangle {
}
}
// LOGIC
property
int
focusedItems
:
0
;
function
applyItemsFocus
(
inc
){
let
c
=
children
;
focusedItems
+=
inc
;
if
(
focusedItems
>=
c
.
length
)
focusedItems
=
0
;
if
(
focusedItems
<
0
)
focusedItems
=
c
.
length
-
1
;
c
[
focusedItems
].
forceActiveFocus
();
// c[focusedItems].clicked();
}
Connections
{
target
:
core_app
function
onGamepadAxisLeft
(
done
){
if
(
!
visible
)
return
;
container
.
applyItemsFocus
(
-
1
)
}
function
onGamepadAxisRight
(
done
){
if
(
!
visible
)
return
;
container
.
applyItemsFocus
(
1
)
}
function
onGamepadClickedApply
(
done
){
if
(
!
visible
)
return
;
let
c
=
container
.
children
;
c
[
container
.
focusedItems
].
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