Commit 39938868 authored by Tom Pillot's avatar Tom Pillot
Browse files

Add event history to the scoreboard

parent bed25ff1
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
...@@ -53,18 +53,24 @@ class ScoreWindow(ScoreWindowUi): ...@@ -53,18 +53,24 @@ class ScoreWindow(ScoreWindowUi):
i += 1 i += 1
def set_table_item(self, row, team): def set_table_item(self, row, team):
# Set the rank
rank_item = qtw.QTableWidgetItem("#" + str(team.rank)) rank_item = qtw.QTableWidgetItem("#" + str(team.rank))
rank_item.setBackground(qtg.QColor(team.color)) rank_item.setBackground(qtg.QColor(team.color))
rank_item.setTextAlignment(qtc.Qt.AlignCenter) rank_item.setTextAlignment(qtc.Qt.AlignCenter)
self.table_widget.setItem(row, self.RANK, rank_item) self.table_widget.setItem(row, self.RANK, rank_item)
# Set the name
self.table_widget.setItem(row, self.NAME, qtw.QTableWidgetItem(" " + team.name)) self.table_widget.setItem(row, self.NAME, qtw.QTableWidgetItem(" " + team.name))
# Set the points
points_item = qtw.QTableWidgetItem() points_item = qtw.QTableWidgetItem()
points_item.setData(qtc.Qt.EditRole, team.points) points_item.setData(qtc.Qt.EditRole, team.points)
points_item.setTextAlignment(qtc.Qt.AlignCenter) points_item.setTextAlignment(qtc.Qt.AlignCenter)
self.table_widget.setItem(row, self.POINTS, points_item) 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 team.points_item = points_item
self.table_widget.resizeRowsToContents() self.table_widget.resizeRowsToContents()
self.table_widget.resizeColumnsToContents() self.table_widget.resizeColumnsToContents()
...@@ -113,5 +119,11 @@ class ScoreWindow(ScoreWindowUi): ...@@ -113,5 +119,11 @@ class ScoreWindow(ScoreWindowUi):
if remaining_time > 0: # Teams can't win any points after the timer has ended if remaining_time > 0: # Teams can't win any points after the timer has ended
max_points = 1000 max_points = 1000
min_points = 100 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)
team.add_points(points_added) 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)
...@@ -18,12 +18,18 @@ class ScoreWindowUi(qtw.QMainWindow): ...@@ -18,12 +18,18 @@ class ScoreWindowUi(qtw.QMainWindow):
self.time_edit.setDisplayFormat("mm:ss") self.time_edit.setDisplayFormat("mm:ss")
self.time_edit.setAlignment(qtc.Qt.AlignCenter) self.time_edit.setAlignment(qtc.Qt.AlignCenter)
self.time_edit.setFixedHeight(200) 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: with open("game/time_edit.qss", "r") as f:
self.time_edit.setStyleSheet(f.read()) 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_label = qtw.QLabel()
self.webcam_timer = qtc.QTimer() self.webcam_timer = qtc.QTimer()
...@@ -45,7 +51,7 @@ class ScoreWindowUi(qtw.QMainWindow): ...@@ -45,7 +51,7 @@ class ScoreWindowUi(qtw.QMainWindow):
self.timer = qtc.QTimer(self) self.timer = qtc.QTimer(self)
vlayout1 = qtw.QVBoxLayout() vlayout1 = qtw.QVBoxLayout()
vlayout1.addWidget(self.list_view) vlayout1.addWidget(self.list_widget)
vlayout1.addWidget(self.webcam_label) vlayout1.addWidget(self.webcam_label)
hlayout = qtw.QHBoxLayout() hlayout = qtw.QHBoxLayout()
......
...@@ -19,5 +19,4 @@ QHeaderView::section:vertical { ...@@ -19,5 +19,4 @@ QHeaderView::section:vertical {
QTableWidget { QTableWidget {
color: rgba(0, 0, 0, 222); color: rgba(0, 0, 0, 222);
background-color: rgb(245, 245, 246); background-color: rgb(245, 245, 246);
border-radius: 10px;
} }
\ No newline at end of file
class Team: class Team:
def __init__(self, name, tag_id, color, points): def __init__(self, name, tag_id, color):
self.name = name self.name = name
self.tag_id = tag_id self.tag_id = tag_id
self.color = color self.color = color
self.points = points self.points = 0
self.rank = 0 self.rank = 0
self.points_item = None # Points item in the scoreboard table self.points_item = None # Points item in the scoreboard table
self.can_win_points = True # Prevent a team from winning multiple times self.can_win_points = True # Prevent a team from winning multiple times
def add_points(self, points_added): def add_points(self, points_added):
if self.can_win_points: self.points += points_added
self.points += points_added self.can_win_points = False
self.can_win_points = False
...@@ -19,8 +19,6 @@ class TeamWindow(TeamWindowUi): ...@@ -19,8 +19,6 @@ class TeamWindow(TeamWindowUi):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.random_gen = qtc.QRandomGenerator() # For testing
self.detector = Detector() self.detector = Detector()
self.teams = {} # The keys are the tag ids and the values are the teams self.teams = {} # The keys are the tag ids and the values are the teams
...@@ -61,7 +59,7 @@ class TeamWindow(TeamWindowUi): ...@@ -61,7 +59,7 @@ class TeamWindow(TeamWindowUi):
self.tag_label.setText("") self.tag_label.setText("")
self.tag_label.setStyleSheet("") self.tag_label.setStyleSheet("")
self.name_input.setText("") 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): def edit_team(self):
""" """
......
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