...
 
Commits (3)
......@@ -7,6 +7,7 @@ pyuic5 --import-from=ui ui/game.ui -o ui/game_ui.py
pyuic5 --import-from=ui ui/endgame.ui -o ui/endgame_ui.py
pyuic5 --import-from=ui ui/options.ui -o ui/options_ui.py
pyuic5 --import-from=ui ui/authquick.ui -o ui/authquick_ui.py
pyuic5 --import-from=ui ui/authleague.ui -o ui/authleague_ui.py
pyuic5 --import-from=ui ui/leaderboard.ui -o ui/leaderboard_ui.py
# Custom widgets
......
......@@ -48,7 +48,7 @@ class MainWin(QtWidgets.QMainWindow):
self.ui.panels.setCurrentIndex(0)
self.ui.panels.currentWidget().setFocus()
self.ui.panels.currentWidget().grabKeyboard()
self.ui.panels.setFocusProxy(self.ui.panels.currentWidget())
self.ui.panels.currentWidget().load()
self.displaySystemTime()
self.startTimer(1000)
......
......@@ -32,19 +32,20 @@ class Module(QtWidgets.QWidget):
logging.error('Unknown panel {}'.format(new_type))
else:
# Unfocus the current module
self.mainwin.ui.panels.currentWidget().releaseKeyboard()
if QApplication.focusWidget() != None:
QApplication.focusWidget().clearFocus()
# Swap modules by unloading, changing the ui then loading
self.mainwin.modules[curmod_idx].unload()
self.mainwin.ui.panels.setCurrentIndex(newmod_idx)
self.mainwin.ui.panels.setFocusProxy(self.mainwin.modules[newmod_idx])
self.mainwin.modules[newmod_idx].setFocus()
self.mainwin.modules[newmod_idx].load()
# Select first element of the Module
self.mainwin.modules[newmod_idx].focusNextChild()
self.mainwin.modules[newmod_idx].focusPreviousChild()
self.mainwin.modules[newmod_idx].grabKeyboard()
self.mainwin.modules[newmod_idx].focusPreviousChild()
def send(self, to, **kwargs):
mod_idx = self.mainwin.findMod(to)
......
......@@ -17,18 +17,21 @@ from player import Side, Player, PlayerGuest
class AuthModuleBase(Module):
def __init__(self, parent, widget):
super().__init__(parent, widget)
self.players = {Side.Left: list(), Side.Right: list()}
self.createPlayerList()
self.numPlayers = 0
def load(self):
pass
def unload(self):
self.players = {Side.Left: list(), Side.Right: list()}
self.createPlayerList()
self.numPlayers = 0
def other(self, **kwargs):
for key, val in kwargs.items():
if key=='rfid' and 'source' in kwargs:
side = kwargs['source']
self.numPlayers += 1
self.addPlayer(side, Player.fromRFID(val))
def keyPressEvent(self, e):
......@@ -40,10 +43,10 @@ class AuthModuleBase(Module):
elif e.key() == Qt.Key_Left or e.key() == Qt.Key_Right:
side = Side.Left if e.key() == Qt.Key_Left else Side.Right
rfid = -2*(side.value+1) - (self.players[side][0]!=PlayerGuest)
rfid = -(2 + self.numPlayers%5)
self.send(type(self), rfid=rfid, source=side)
def addPlayer(self, side, player):
def createPlayerList(self):
logging.warning('Base function meant to be reimplemented')
def handleCancel(self):
......
......@@ -8,17 +8,55 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from PyQt5.QtWidgets import QAbstractItemView
from module import Module
from ui.authquick_ui import Ui_Form as AuthQuickWidget
from modules.auth import AuthModuleBase
from ui.authleague_ui import Ui_Form as AuthLeagueWidget
class AuthLeagueModule(Module):
from player import Side, PlayerEmpty
class AuthLeagueModule(AuthModuleBase):
def __init__(self, parent):
super().__init__(parent, AuthQuickWidget())
super().__init__(parent, AuthLeagueWidget())
def load(self):
logging.debug('Loading AuthLeagueModule')
super().load()
self.addPlayer(Side.Left, PlayerEmpty)
def unload(self):
logging.debug('Loading AuthLeagueModule')
super().load()
super().unload()
self.ui.playersList.clear()
def createPlayerList(self):
'''
Duplicates the player list to be the same on both sides.
That way, adding a player on the left or on the right have the exact same effect,
and thus the AuthModuleBase code can remain generic.
'''
l = list()
self.players = {Side.Left: l, Side.Right: l}
def addPlayer(self, side, player):
# Add the player if not already in the list
if all([p.id!=player.id for p in self.players[side]]):
if player!=PlayerEmpty:
self.players[side].append(player)
# Update the left side description
player.displayImg(self.ui.img)
self.ui.lblName.setText(player.name)
self.ui.lblStat1.setText('{} Victories'.format(player.stats.victories))
self.ui.lblStat2.setText('{} Games Played'.format(player.stats.games_played))
self.ui.lblStat3.setText('{} Goals Scored'.format(player.stats.goals_scored))
if player!=PlayerEmpty:
# Update the right side list, making sure that the added player is showed
self.ui.playersList.addItem('{}. {}'.format(len(self.players[side]), player.name))
widgetItem = self.ui.playersList.item(self.ui.playersList.count()-1)
self.ui.playersList.scrollToItem(widgetItem, QAbstractItemView.PositionAtBottom)
def handleDone(self):
super().handleDone()
......@@ -40,7 +40,11 @@ class AuthQuickModule(AuthModuleBase):
super().unload()
#self.updateSides()
def createPlayerList(self):
self.players = {Side.Left: list(), Side.Right: list()}
def addPlayer(self, side, player):
# If there is a placeholder Guest, clear it from the list, we don't need it anymore
if len(self.players[side])>0 and self.players[side][0]==PlayerGuest:
self.players[side].clear()
......
......@@ -51,6 +51,13 @@ class Player():
player = Player(id, 'Enzo', 'Arobaz')
player.stats.goals_scored = 1
elif id==-10:
player = Player(id, 'Name', '')
player.stats.victories = ''
player.stats.time_played = ''
player.stats.games_played = ''
player.stats.goals_scored = ''
else:
player = Player(id, fname, lname, pic_url)
......@@ -88,3 +95,4 @@ class Stat():
self.goals_scored = 0
PlayerGuest = Player.fromRFID(-1)
PlayerEmpty = Player.fromRFID(-10)
This diff is collapsed.