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