Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tom Pillot
Thymio Game
Commits
39938868
Commit
39938868
authored
Jun 30, 2020
by
Tom Pillot
Browse files
Add event history to the scoreboard
parent
bed25ff1
Changes
6
Show whitespace changes
Inline
Side-by-side
game/list_widget.qss
0 → 100644
View file @
39938868
QListWidget {
color: rgba(255, 255, 255, 222);
background-color: rgb(63, 81, 181);
}
QListWidget::item {
margin-top: 10px;
}
QScrollBar {
width:0px;
}
\ No newline at end of file
game/scoreboard.py
View file @
39938868
...
...
@@ -53,18 +53,24 @@ class ScoreWindow(ScoreWindowUi):
i
+=
1
def
set_table_item
(
self
,
row
,
team
):
# Set the rank
rank_item
=
qtw
.
QTableWidgetItem
(
"#"
+
str
(
team
.
rank
))
rank_item
.
setBackground
(
qtg
.
QColor
(
team
.
color
))
rank_item
.
setTextAlignment
(
qtc
.
Qt
.
AlignCenter
)
self
.
table_widget
.
setItem
(
row
,
self
.
RANK
,
rank_item
)
# Set the name
self
.
table_widget
.
setItem
(
row
,
self
.
NAME
,
qtw
.
QTableWidgetItem
(
" "
+
team
.
name
))
# Set the points
points_item
=
qtw
.
QTableWidgetItem
()
points_item
.
setData
(
qtc
.
Qt
.
EditRole
,
team
.
points
)
points_item
.
setTextAlignment
(
qtc
.
Qt
.
AlignCenter
)
self
.
table_widget
.
setItem
(
row
,
self
.
POINTS
,
points_item
)
# Show a message
self
.
list_widget
.
insertItem
(
0
,
team
.
name
+
" a rejoint la partie."
)
team
.
points_item
=
points_item
self
.
table_widget
.
resizeRowsToContents
()
self
.
table_widget
.
resizeColumnsToContents
()
...
...
@@ -113,5 +119,11 @@ class ScoreWindow(ScoreWindowUi):
if
remaining_time
>
0
:
# Teams can't win any points after the timer has ended
max_points
=
1000
min_points
=
100
points_added
=
min_points
+
(
max_points
-
min_points
)
/
self
.
initial_time
*
remaining_time
points_added
=
int
(
min_points
+
(
max_points
-
min_points
)
/
self
.
initial_time
*
remaining_time
)
if
team
.
can_win_points
:
team
.
add_points
(
points_added
)
self
.
show_event
(
team
,
points_added
)
def
show_event
(
self
,
team
,
points_added
):
message
=
team
.
name
+
" a gagné "
+
str
(
points_added
)
+
" points."
self
.
list_widget
.
insertItem
(
0
,
message
)
game/scoreboard_ui.py
View file @
39938868
...
...
@@ -18,12 +18,18 @@ class ScoreWindowUi(qtw.QMainWindow):
self
.
time_edit
.
setDisplayFormat
(
"mm:ss"
)
self
.
time_edit
.
setAlignment
(
qtc
.
Qt
.
AlignCenter
)
self
.
time_edit
.
setFixedHeight
(
200
)
self
.
time_edit
.
setDisabled
(
True
)
self
.
time_edit
.
setDisabled
(
True
)
# The time can't be modified or selected
with
open
(
"game/time_edit.qss"
,
"r"
)
as
f
:
self
.
time_edit
.
setStyleSheet
(
f
.
read
())
self
.
list_view
=
qtw
.
QListView
()
self
.
list_widget
=
qtw
.
QListWidget
()
self
.
list_widget
.
setFont
(
qtg
.
QFont
(
"Arial"
,
25
))
self
.
list_widget
.
setDisabled
(
True
)
with
open
(
"game/list_widget.qss"
,
"r"
)
as
f
:
self
.
list_widget
.
setStyleSheet
(
f
.
read
())
self
.
webcam_label
=
qtw
.
QLabel
()
self
.
webcam_timer
=
qtc
.
QTimer
()
...
...
@@ -45,7 +51,7 @@ class ScoreWindowUi(qtw.QMainWindow):
self
.
timer
=
qtc
.
QTimer
(
self
)
vlayout1
=
qtw
.
QVBoxLayout
()
vlayout1
.
addWidget
(
self
.
list_
view
)
vlayout1
.
addWidget
(
self
.
list_
widget
)
vlayout1
.
addWidget
(
self
.
webcam_label
)
hlayout
=
qtw
.
QHBoxLayout
()
...
...
game/table_widget.qss
View file @
39938868
...
...
@@ -19,5 +19,4 @@ QHeaderView::section:vertical {
QTableWidget {
color: rgba(0, 0, 0, 222);
background-color: rgb(245, 245, 246);
border-radius: 10px;
}
\ No newline at end of file
game/team.py
View file @
39938868
class
Team
:
def
__init__
(
self
,
name
,
tag_id
,
color
,
points
):
def
__init__
(
self
,
name
,
tag_id
,
color
):
self
.
name
=
name
self
.
tag_id
=
tag_id
self
.
color
=
color
self
.
points
=
points
self
.
points
=
0
self
.
rank
=
0
self
.
points_item
=
None
# Points item in the scoreboard table
self
.
can_win_points
=
True
# Prevent a team from winning multiple times
def
add_points
(
self
,
points_added
):
if
self
.
can_win_points
:
self
.
points
+=
points_added
self
.
can_win_points
=
False
game/team_chooser.py
View file @
39938868
...
...
@@ -19,8 +19,6 @@ class TeamWindow(TeamWindowUi):
def
__init__
(
self
):
super
().
__init__
()
self
.
random_gen
=
qtc
.
QRandomGenerator
()
# For testing
self
.
detector
=
Detector
()
self
.
teams
=
{}
# The keys are the tag ids and the values are the teams
...
...
@@ -61,7 +59,7 @@ class TeamWindow(TeamWindowUi):
self
.
tag_label
.
setText
(
""
)
self
.
tag_label
.
setStyleSheet
(
""
)
self
.
name_input
.
setText
(
""
)
self
.
teams
[
tag_id
]
=
Team
(
name
,
tag_id
,
self
.
team_colors
[
tag_id
]
,
int
(
self
.
random_gen
.
generate
()
/
10000000
)
)
self
.
teams
[
tag_id
]
=
Team
(
name
,
tag_id
,
self
.
team_colors
[
tag_id
])
def
edit_team
(
self
):
"""
...
...
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