def load(cls, state: t.Any, undo_stack: QUndoStack) -> PoolView: pool_model = PoolModel.load(state['pool_model']) pool_view = cls( pool_model, maindeck_cube_view=CubeView.load( state['maindeck_view'], pool_model.maindeck, undo_stack=undo_stack, ), sideboard_cube_view=CubeView.load( state['sideboard_view'], pool_model.sideboard, undo_stack=undo_stack, ), pool_cube_view=CubeView.load( state['pool_view'], pool_model.pool, undo_stack=undo_stack, ), undo_stack=undo_stack, ) pool_view._horizontal_splitter.restoreState( state['horizontal_splitter']) pool_view._vertical_splitter.restoreState(state['vertical_splitter']) return pool_view
def load(cls, state: t.Any, undo_stack: QUndoStack) -> DeckView: deck_model = DeckModel.load(state['deck_model']) deck_view = DeckView( deck_model, maindeck_cube_view = CubeView.load( state['maindeck_view'], deck_model.maindeck, undo_stack = undo_stack, ), sideboard_cube_view = CubeView.load( state['sideboard_view'], deck_model.sideboard, undo_stack = undo_stack, ), undo_stack = undo_stack, ) deck_view._horizontal_splitter.restoreState(state['splitter']) return deck_view
def __init__(self, draft_model: DraftModel): super().__init__() self._undo_stack = Context.get_undo_stack() self._draft_model = draft_model self._latest_meta_info = PickMetaInfo(draft_model) self._head_meta_info = PickMetaInfo(draft_model) self._head_meta_info.hide() self._countdown = Countdown() self._countdown.hide() self._picking_info = QtWidgets.QLabel('') self._picking_info.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self._booster_scene = CubeScene( mode=CubeEditMode.CLOSED, scene_type=SceneType.BOOSTER, ) self._booster_view = CubeView( scene=self._booster_scene, undo_stack=self._undo_stack, cube_image_view=BoosterImageView( self._undo_stack, self._booster_scene, self._draft_model, ), ) layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) info_bar_layout = QtWidgets.QHBoxLayout() info_bar_layout.setContentsMargins(0, 0, 0, 0) info_bar_layout.addWidget(self._latest_meta_info) info_bar_layout.addWidget(self._head_meta_info) info_bar_layout.addStretch() info_bar_layout.addWidget(self._picking_info) info_bar_layout.addWidget(self._countdown) layout.addLayout(info_bar_layout) layout.addWidget(self._booster_view) self._draft_model.new_head.connect(self._set_pick_point) self._draft_model.picked.connect(self._on_picked) self._draft_model.received_booster.connect(self._on_receive_booster) self._draft_model.boosters_changed.connect(self._on_boosters_changed) self._booster_view.cube_image_view.card_double_clicked.connect( self._on_card_double_clicked)
def __init__(self, deck_scene: CubeScene, *, parent: t.Optional[QtWidgets.QWidget] = None) -> None: super().__init__(parent) self._deck_scene = deck_scene self._undo_stack = Context.get_undo_stack() self._hand_scene = CubeScene( aligner_type=GridAligner, mode=CubeEditMode.CLOSED, scene_type=SceneType.SAMPLE_HAND, ) self._hand_view = CubeView(self._hand_scene, self._undo_stack) self._draw_hand_button = QtWidgets.QPushButton('Draw Hand') self._draw_hand_button.clicked.connect(self.refresh) self._create_shortcut(self.refresh, 'h') self._draw_card_button = QtWidgets.QPushButton('Draw Card') self._draw_card_button.clicked.connect(lambda: self.add_cubeables(1)) self._create_shortcut(self.add_cubeables, 'd') layout = QtWidgets.QVBoxLayout(self) control_bar = QtWidgets.QHBoxLayout() control_bar.addWidget(self._draw_hand_button) control_bar.addWidget(self._draw_card_button) layout.addWidget(self._hand_view) layout.addLayout(control_bar)
def __init__( self, pool_model: PoolModel, undo_stack: QUndoStack, *, maindeck_cube_view: t.Optional[CubeView] = None, sideboard_cube_view: t.Optional[CubeView] = None, pool_cube_view: t.Optional[CubeView] = None, ) -> None: super().__init__(undo_stack) self._pool_model = pool_model layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(3, 3, 3, 1) self._vertical_splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical, self) self._horizontal_splitter = QtWidgets.QSplitter( QtCore.Qt.Horizontal, self) self._maindeck_cube_view = (maindeck_cube_view if maindeck_cube_view is not None else CubeView( self._pool_model.maindeck, self._undo_stack, )) self._sideboard_cube_view = (sideboard_cube_view if sideboard_cube_view is not None else CubeView( self._pool_model.sideboard, self._undo_stack, )) self._pool_cube_view = (pool_cube_view if pool_cube_view is not None else CubeView( self._pool_model.pool, self._undo_stack, )) self._all_scenes = { self._maindeck_cube_view.cube_scene, self._sideboard_cube_view.cube_scene, self._pool_cube_view.cube_scene, } for scene in self._all_scenes: scene.selection_cleared.connect( self._on_cube_scene_selection_cleared) self._horizontal_splitter.addWidget(self._maindeck_cube_view) self._horizontal_splitter.addWidget(self._sideboard_cube_view) self._horizontal_splitter.setStretchFactor(0, 3) self._horizontal_splitter.setStretchFactor(1, 1) self._vertical_splitter.addWidget(self._pool_cube_view) self._vertical_splitter.addWidget(self._horizontal_splitter) self._vertical_splitter.setStretchFactor(0, 1) self._vertical_splitter.setStretchFactor(1, 1) layout.addWidget(self._vertical_splitter) self._connect_move_cubeable(self._maindeck_cube_view, self._pool_cube_view, self._sideboard_cube_view) self._connect_move_cubeable(self._sideboard_cube_view, self._pool_cube_view, self._maindeck_cube_view) self._connect_move_cubeable(self._pool_cube_view, self._maindeck_cube_view, self._sideboard_cube_view)
def __init__( self, deck_model: DeckModel, undo_stack: QUndoStack, *, maindeck_cube_view: t.Optional[CubeView] = None, sideboard_cube_view: t.Optional[CubeView] = None, ) -> None: super().__init__(undo_stack) self._deck_model = deck_model layout = QVBoxLayout() layout.setContentsMargins(3, 3, 3, 1) self._horizontal_splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal, self) self._maindeck_cube_view = ( maindeck_cube_view if maindeck_cube_view is not None else CubeView( self._deck_model.maindeck, self._undo_stack, ) ) self._sideboard_cube_view = ( sideboard_cube_view if sideboard_cube_view is not None else CubeView( self._deck_model.sideboard, self._undo_stack, ) ) self._all_scenes = { self._maindeck_cube_view.cube_scene, self._sideboard_cube_view.cube_scene, } for scene in self._all_scenes: scene.selection_cleared.connect(self._on_cube_scene_selection_cleared) self._horizontal_splitter.addWidget(self._maindeck_cube_view) self._horizontal_splitter.addWidget(self._sideboard_cube_view) self._horizontal_splitter.setStretchFactor(0, 3) self._horizontal_splitter.setStretchFactor(1, 1) layout.addWidget(self._horizontal_splitter) self.setLayout(layout) self._maindeck_cube_view.cube_image_view.card_double_clicked.connect( lambda card, _: self._undo_stack.push( self._maindeck_cube_view.cube_scene.get_inter_move( [card], self._sideboard_cube_view.cube_scene, QPoint(), ) ) ) self._sideboard_cube_view.cube_image_view.card_double_clicked.connect( lambda card, _: self._undo_stack.push( self._sideboard_cube_view.cube_scene.get_inter_move( [card], self._maindeck_cube_view.cube_scene, QPoint(), ) ) )
class SampleHandView(QtWidgets.QWidget, WithActions): def __init__(self, deck_scene: CubeScene, *, parent: t.Optional[QtWidgets.QWidget] = None) -> None: super().__init__(parent) self._deck_scene = deck_scene self._undo_stack = Context.get_undo_stack() self._hand_scene = CubeScene( aligner_type=GridAligner, mode=CubeEditMode.CLOSED, scene_type=SceneType.SAMPLE_HAND, ) self._hand_view = CubeView(self._hand_scene, self._undo_stack) self._draw_hand_button = QtWidgets.QPushButton('Draw Hand') self._draw_hand_button.clicked.connect(self.refresh) self._create_shortcut(self.refresh, 'h') self._draw_card_button = QtWidgets.QPushButton('Draw Card') self._draw_card_button.clicked.connect(lambda: self.add_cubeables(1)) self._create_shortcut(self.add_cubeables, 'd') layout = QtWidgets.QVBoxLayout(self) control_bar = QtWidgets.QHBoxLayout() control_bar.addWidget(self._draw_hand_button) control_bar.addWidget(self._draw_card_button) layout.addWidget(self._hand_view) layout.addLayout(control_bar) def _get_cubeables(self, amount: int = 1) -> t.List[Cubeable]: remaining_cubeables = list(self._deck_scene.cube - self._hand_scene.cube) if len(remaining_cubeables) <= amount: return remaining_cubeables return random.sample(remaining_cubeables, amount) def add_cubeables(self, amount: int = 1) -> None: add = self._get_cubeables(amount) if add: self._hand_scene.get_cube_modification( CubeDeltaOperation(add), closed_operation=True, ).redo() self._undo_stack.clear() self._hand_view.update() def refresh(self) -> None: remove = self._hand_scene.items() if remove: self._hand_scene.get_cube_modification( remove=remove, closed_operation=True, ).redo() self.add_cubeables(7)