Fix number ring animation
parent
e8a0eee941
commit
e89c727e11
|
@ -117,26 +117,24 @@ class GameBoard(BoxBoard):
|
||||||
self.playmenu.buttonClicked.connect(self.new_game)
|
self.playmenu.buttonClicked.connect(self.new_game)
|
||||||
self.gamegrid.finishDrawing.connect(self.gridDrawn.emit)
|
self.gamegrid.finishDrawing.connect(self.gridDrawn.emit)
|
||||||
self.gamegrid.puzzleFinished.connect(self.sudokuDone.emit)
|
self.gamegrid.puzzleFinished.connect(self.sudokuDone.emit)
|
||||||
|
self.numring.loseFocus.connect(self.game_refocus)
|
||||||
self.toggle_anim(True)
|
self.toggle_anim(True)
|
||||||
|
|
||||||
def show_number_ring(self, x=0, y=0):
|
def show_number_ring(self, x=0, y=0):
|
||||||
if not self.gamegrid.freeze:
|
if not self.numring.isVisible():
|
||||||
self.numring.setPos(x, y)
|
self.numring.setPos(x, y)
|
||||||
self.numring.setVisible(True)
|
self.numring.setVisible(True)
|
||||||
self.numring.setFocus()
|
self.numring.setFocus()
|
||||||
self.numring.toggle_anim(True)
|
self.numring.toggle_anim(True)
|
||||||
else:
|
|
||||||
self.gamegrid.freeze = False
|
|
||||||
self.gamegrid.setFocus()
|
|
||||||
|
|
||||||
def select_ring_number(self, val):
|
def select_ring_number(self, val):
|
||||||
if val == 'X':
|
if val == 'X':
|
||||||
val = 0
|
val = 0
|
||||||
self.gamegrid.replace_cell_number(int(val))
|
self.gamegrid.replace_cell_number(int(val))
|
||||||
self.show_number_ring()
|
self.game_refocus()
|
||||||
|
|
||||||
def game_refocus(self):
|
def game_refocus(self):
|
||||||
self.gamegrid.freeze = False
|
self.gamegrid.set_disabled(False)
|
||||||
self.gamegrid.setFocus()
|
self.gamegrid.setFocus()
|
||||||
|
|
||||||
def show_grid(self, state):
|
def show_grid(self, state):
|
||||||
|
|
|
@ -126,9 +126,8 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
self.selection_pen.setWidth(self.selection_unit)
|
self.selection_pen.setWidth(self.selection_unit)
|
||||||
self.selection_box = QRectF(0, 0, self.cell_width, self.cell_height)
|
self.selection_box = QRectF(0, 0, self.cell_width, self.cell_height)
|
||||||
|
|
||||||
self.setAcceptHoverEvents(True)
|
|
||||||
self.setAcceptedMouseButtons(Qt.LeftButton)
|
|
||||||
self.setFlag(QGraphicsItem.ItemIsFocusable, True)
|
self.setFlag(QGraphicsItem.ItemIsFocusable, True)
|
||||||
|
self.set_disabled(False)
|
||||||
|
|
||||||
# Length of the box to be drawn
|
# Length of the box to be drawn
|
||||||
self.length = 0
|
self.length = 0
|
||||||
|
@ -143,6 +142,13 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
self.drawn = False
|
self.drawn = False
|
||||||
self.anim.finished.connect(self.finish_drawing)
|
self.anim.finished.connect(self.finish_drawing)
|
||||||
|
|
||||||
|
def set_disabled(self, state):
|
||||||
|
if state:
|
||||||
|
self.setAcceptedMouseButtons(Qt.NoButton)
|
||||||
|
else:
|
||||||
|
self.setAcceptedMouseButtons(Qt.LeftButton)
|
||||||
|
self.setAcceptHoverEvents(not state)
|
||||||
|
|
||||||
def finish_drawing(self):
|
def finish_drawing(self):
|
||||||
if self.length == self.width:
|
if self.length == self.width:
|
||||||
self.drawn = True
|
self.drawn = True
|
||||||
|
@ -186,7 +192,7 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
painter.drawRect(self.selection_box)
|
painter.drawRect(self.selection_box)
|
||||||
|
|
||||||
def hoverMoveEvent(self, event):
|
def hoverMoveEvent(self, event):
|
||||||
if not (self.freeze and self.drawn):
|
if self.drawn:
|
||||||
box_w = bound_value(0, int(event.pos().x()/self.cell_width), 8)
|
box_w = bound_value(0, int(event.pos().x()/self.cell_width), 8)
|
||||||
box_h = bound_value(0, int(event.pos().y() / self.cell_height), 8)
|
box_h = bound_value(0, int(event.pos().y() / self.cell_height), 8)
|
||||||
if box_w != self.mouse_w or box_h != self.mouse_h:
|
if box_w != self.mouse_w or box_h != self.mouse_h:
|
||||||
|
@ -196,7 +202,7 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
if not (self.freeze and self.drawn):
|
if self.drawn:
|
||||||
w = (self.mouse_w + 0.5) * self.cell_width
|
w = (self.mouse_w + 0.5) * self.cell_width
|
||||||
h = (self.mouse_h + 0.5) * self.cell_height
|
h = (self.mouse_h + 0.5) * self.cell_height
|
||||||
|
|
||||||
|
@ -204,9 +210,10 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
self.buttonClicked.emit(w, h)
|
self.buttonClicked.emit(w, h)
|
||||||
else:
|
else:
|
||||||
self.buttonClicked.emit(0, 0)
|
self.buttonClicked.emit(0, 0)
|
||||||
|
def focusInEvent(self, event):
|
||||||
|
self.set_disabled(False)
|
||||||
def focusOutEvent(self, event):
|
def focusOutEvent(self, event):
|
||||||
self.freeze = True
|
self.set_disabled(True)
|
||||||
|
|
||||||
# Defining the length to be drawn as a pyqtProperty
|
# Defining the length to be drawn as a pyqtProperty
|
||||||
@pyqtProperty(float)
|
@pyqtProperty(float)
|
||||||
|
@ -237,6 +244,7 @@ class NumberRing(BaseSudokuItem):
|
||||||
# TODO: Add functions to animated the ring appearing
|
# TODO: Add functions to animated the ring appearing
|
||||||
# TODO: Adjust the positioning of each element
|
# TODO: Adjust the positioning of each element
|
||||||
# TODO: Make it transparent when mouse is out of range
|
# TODO: Make it transparent when mouse is out of range
|
||||||
|
loseFocus = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
@ -273,6 +281,7 @@ class NumberRing(BaseSudokuItem):
|
||||||
if self.radius == 0:
|
if self.radius == 0:
|
||||||
self.setVisible(False)
|
self.setVisible(False)
|
||||||
self.freeze_buttons(True)
|
self.freeze_buttons(True)
|
||||||
|
self.loseFocus.emit()
|
||||||
else:
|
else:
|
||||||
self.freeze_buttons(False)
|
self.freeze_buttons(False)
|
||||||
|
|
||||||
|
@ -297,6 +306,7 @@ class NumberRing(BaseSudokuItem):
|
||||||
def connect_button_signals(self, func):
|
def connect_button_signals(self, func):
|
||||||
for btn in self.cell_buttons:
|
for btn in self.cell_buttons:
|
||||||
btn.buttonClicked.connect(func)
|
btn.buttonClicked.connect(func)
|
||||||
|
btn.buttonClicked.connect(self.close_menu)
|
||||||
print('Buttons Connected')
|
print('Buttons Connected')
|
||||||
|
|
||||||
def freeze_buttons(self, freeze):
|
def freeze_buttons(self, freeze):
|
||||||
|
@ -304,6 +314,12 @@ class NumberRing(BaseSudokuItem):
|
||||||
btn.set_freeze(freeze)
|
btn.set_freeze(freeze)
|
||||||
|
|
||||||
def focusOutEvent(self, event):
|
def focusOutEvent(self, event):
|
||||||
|
if not any(btn.isUnderMouse() for btn in self.cell_buttons):
|
||||||
|
self.close_menu()
|
||||||
|
else:
|
||||||
|
self.setFocus()
|
||||||
|
|
||||||
|
def close_menu(self):
|
||||||
self.toggle_anim(False)
|
self.toggle_anim(False)
|
||||||
|
|
||||||
# Defining the length to be drawn as a pyqtProperty
|
# Defining the length to be drawn as a pyqtProperty
|
||||||
|
|
Loading…
Reference in New Issue