Display the correct difficulty
parent
07e4a188e5
commit
f57bfaa07c
|
@ -98,6 +98,7 @@ class GameBoard(BoxBoard):
|
|||
It is intended to swap the interface depending on whether the game is ongoing
|
||||
"""
|
||||
boxClicked = pyqtSignal(bool)
|
||||
newGameSelected = pyqtSignal(str)
|
||||
|
||||
def __init__(self, width, height, parent=None):
|
||||
super().__init__(width, height, parent)
|
||||
|
@ -150,6 +151,7 @@ class GameBoard(BoxBoard):
|
|||
print('new game selected')
|
||||
self.gamegrid.generate_new_grid(menu_grap.DIFFICULTIES.index(string))
|
||||
self.show_grid(True)
|
||||
self.newGameSelected.emit(string)
|
||||
|
||||
|
||||
class MenuBoard(BoxBoard):
|
||||
|
@ -179,10 +181,12 @@ class MenuBoard(BoxBoard):
|
|||
self.toggle_anim(True)
|
||||
|
||||
def show_difficulty(self, state):
|
||||
print(state)
|
||||
self.diff_display.selected = state
|
||||
self.diff_display.update()
|
||||
|
||||
def show_children(self, state):
|
||||
for chd in self.children():
|
||||
chd.setVisible(state)
|
||||
|
||||
def set_difficulty_text(self, string):
|
||||
self.diff_display.set_text(string)
|
||||
|
|
|
@ -37,7 +37,6 @@ class TimerDisplayer(QGraphicsWidget):
|
|||
|
||||
def paint(self, painter, style, widget=None):
|
||||
box = self.timer_box
|
||||
#print(self.size().width())
|
||||
painter.setPen(self.box_pen)
|
||||
painter.drawRect(box)
|
||||
painter.drawText(box, Qt.AlignCenter, "00:00")
|
||||
|
@ -57,6 +56,8 @@ class DifficultyDisplayer(QGraphicsWidget):
|
|||
self.diff_menu.setY(-self.diff_menu.height)
|
||||
self.diff_menu.setVisible(False)
|
||||
|
||||
self.text = "None"
|
||||
|
||||
self.box_pen = QPen()
|
||||
self.box_pen.setColor(Qt.white)
|
||||
self.pen_width = 3
|
||||
|
@ -81,7 +82,7 @@ class DifficultyDisplayer(QGraphicsWidget):
|
|||
def paint(self, painter, style, widget=None):
|
||||
painter.setPen(self.box_pen)
|
||||
painter.drawRect(self.diff_box)
|
||||
painter.drawText(self.diff_box, Qt.AlignCenter, "Normal")
|
||||
painter.drawText(self.diff_box, Qt.AlignCenter, self.text)
|
||||
painter.drawRect(self.boundingRect())
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
|
@ -97,10 +98,15 @@ class DifficultyDisplayer(QGraphicsWidget):
|
|||
self.diff_menu.menuClicked.connect(func)
|
||||
print('Diff buttons connected')
|
||||
|
||||
def selected_difficulty(self):
|
||||
def selected_difficulty(self, string):
|
||||
self.diff_menu.setVisible(False)
|
||||
self.set_text(string)
|
||||
self.notFocus.emit()
|
||||
|
||||
def set_text(self, string):
|
||||
self.text = string
|
||||
self.update()
|
||||
|
||||
def focusOutEvent(self, event):
|
||||
print('Menu lose focus')
|
||||
self.notFocus.emit()
|
||||
|
|
2
main.py
2
main.py
|
@ -45,6 +45,8 @@ class SudokuWindow(QGraphicsView):
|
|||
self.show()
|
||||
|
||||
# Cross-Board signal connections
|
||||
self.gameboard.newGameSelected.connect(lambda: self.menuboard.show_children(True))
|
||||
self.gameboard.newGameSelected.connect(self.menuboard.set_difficulty_text)
|
||||
self.menuboard.diff_display.notFocus.connect(self.gameboard.game_refocus)
|
||||
self.menuboard.diff_display.connect_buttons_signal(self.gameboard.new_game)
|
||||
|
||||
|
|
Loading…
Reference in New Issue