Exemplo n.º 1
0
    def __init__(self, game, gameView):
        super(GameWindow, self).__init__()

        stretchA = (1000 - 618) * (1000 - 618)
        stretchB = 1000000 - stretchA

        layout = QGridLayout(self)
        layout.setColumnStretch(0, stretchB)
        layout.setColumnStretch(1, stretchA)

        leftLayout = QGridLayout()
        leftLayout.setRowStretch(0, stretchB)
        leftLayout.setRowStretch(1, stretchA)
        rightLayout = QGridLayout()
        rightLayout.setRowStretch(0, stretchA)
        rightLayout.setRowStretch(1, stretchB)
        layout.addLayout(leftLayout, 0, 0)
        layout.addLayout(rightLayout, 0, 1)

        self.game = game
        self.game.playersUpdated.connect(self._onPlayersUpdated)

        gameView.player = game.connectionManager.player
        gameView.attackInitiated.connect(self.game._onAttackInitiated)

        self.gameView = GameViewWrapper(gameView)
        self.eventBox = EventBox()
        self.countryBox = CountryInfoBox(self)
        self.statBox = StatBox(gameView)

        self.lose = Title('YOU LOSE', 100)
        self.win = Title('YOU WIN', 100)
        self.lose.setParent(self)
        self.win.setParent(self)
        self.lose.raise_()
        self.win.raise_()
        self.lose.hide()
        self.win.hide()

        self.eventBox.setColor(QColor(Qt.black))
        self.countryBox.setColor(QColor(Qt.gray))
        self.statBox.setColor(QColor(Qt.gray))

        leftLayout.addWidget(self.gameView, 0, 0)
        leftLayout.addWidget(self.eventBox, 1, 0)
        rightLayout.addWidget(self.statBox, 0, 0)
        rightLayout.addWidget(self.countryBox, 1, 0)

        gameView.hoverCountry.connect(self.countryBox.updateCountry)
        gameView.ownerChanged.connect(self.statBox.refresh)

        game.gameEvent.connect(self.eventBox.addEvent)
        game.gameLose.connect(self._triggerLose)
        game.gameWin.connect(self._triggerWin)
Exemplo n.º 2
0
        def __init__(self, game, gameView):
                super(GameWindow, self).__init__()

                stretchA = (1000 - 618) * (1000 - 618)
                stretchB = 1000000 - stretchA

                layout = QGridLayout(self)
                layout.setColumnStretch(0, stretchB)
                layout.setColumnStretch(1, stretchA)

                leftLayout = QGridLayout()
                leftLayout.setRowStretch(0, stretchB)
                leftLayout.setRowStretch(1, stretchA)
                rightLayout = QGridLayout()
                rightLayout.setRowStretch(0, stretchA)
                rightLayout.setRowStretch(1, stretchB)
                layout.addLayout(leftLayout, 0, 0)
                layout.addLayout(rightLayout, 0, 1)

                self.game = game
                self.game.playersUpdated.connect(self._onPlayersUpdated)

                gameView.player = game.connectionManager.player
                gameView.attackInitiated.connect(self.game._onAttackInitiated)

                self.gameView = GameViewWrapper(gameView)
                self.eventBox = EventBox()
                self.countryBox = CountryInfoBox(self)
                self.statBox = StatBox(gameView)

                self.lose = Title('YOU LOSE', 100)
                self.win = Title('YOU WIN', 100)
                self.lose.setParent(self)
                self.win.setParent(self)
                self.lose.raise_()
                self.win.raise_()
                self.lose.hide()
                self.win.hide()

                self.eventBox.setColor(QColor(Qt.black))
                self.countryBox.setColor(QColor(Qt.gray))
                self.statBox.setColor(QColor(Qt.gray))

                leftLayout.addWidget(self.gameView, 0, 0)
                leftLayout.addWidget(self.eventBox, 1, 0)
                rightLayout.addWidget(self.statBox, 0, 0)
                rightLayout.addWidget(self.countryBox, 1, 0)

                gameView.hoverCountry.connect(self.countryBox.updateCountry)
                gameView.ownerChanged.connect(self.statBox.refresh)

                game.gameEvent.connect(self.eventBox.addEvent)
                game.gameLose.connect(self._triggerLose)
                game.gameWin.connect(self._triggerWin)
Exemplo n.º 3
0
class GameWindow(QWidget):

        ANIMATION_SHOW_RESULT_DURATION_PHASE_ONE = 2000
        ANIMATION_SHOW_RESULT_DURATION_PHASE_TWO = 5000

        def __init__(self, game, gameView):
                super(GameWindow, self).__init__()

                stretchA = (1000 - 618) * (1000 - 618)
                stretchB = 1000000 - stretchA

                layout = QGridLayout(self)
                layout.setColumnStretch(0, stretchB)
                layout.setColumnStretch(1, stretchA)

                leftLayout = QGridLayout()
                leftLayout.setRowStretch(0, stretchB)
                leftLayout.setRowStretch(1, stretchA)
                rightLayout = QGridLayout()
                rightLayout.setRowStretch(0, stretchA)
                rightLayout.setRowStretch(1, stretchB)
                layout.addLayout(leftLayout, 0, 0)
                layout.addLayout(rightLayout, 0, 1)

                self.game = game
                self.game.playersUpdated.connect(self._onPlayersUpdated)

                gameView.player = game.connectionManager.player
                gameView.attackInitiated.connect(self.game._onAttackInitiated)

                self.gameView = GameViewWrapper(gameView)
                self.eventBox = EventBox()
                self.countryBox = CountryInfoBox(self)
                self.statBox = StatBox(gameView)

                self.lose = Title('YOU LOSE', 100)
                self.win = Title('YOU WIN', 100)
                self.lose.setParent(self)
                self.win.setParent(self)
                self.lose.raise_()
                self.win.raise_()
                self.lose.hide()
                self.win.hide()

                self.eventBox.setColor(QColor(Qt.black))
                self.countryBox.setColor(QColor(Qt.gray))
                self.statBox.setColor(QColor(Qt.gray))

                leftLayout.addWidget(self.gameView, 0, 0)
                leftLayout.addWidget(self.eventBox, 1, 0)
                rightLayout.addWidget(self.statBox, 0, 0)
                rightLayout.addWidget(self.countryBox, 1, 0)

                gameView.hoverCountry.connect(self.countryBox.updateCountry)
                gameView.ownerChanged.connect(self.statBox.refresh)

                game.gameEvent.connect(self.eventBox.addEvent)
                game.gameLose.connect(self._triggerLose)
                game.gameWin.connect(self._triggerWin)

        closed = Signal()

        @Slot()
        def _unfreezeSize(self):
                self.setFixedSize(QSize(16777215, 16777215))

        def _triggerResult(self, result):
                result.changeSize(int(100 * self.gameView.width() / 677))
                rect = QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, result.titleImage().size(), self.gameView.rect())
                result.move(rect.x(), rect.y())
                result.show()
                result.raise_()

                self.setFixedSize(self.size())

                self.showResultAnimationGroup = QSequentialAnimationGroup()

                showResultAnimationPhaseOne = QPropertyAnimation(result, 'pos')
                showResultAnimationPhaseOne.setDuration(GameWindow.ANIMATION_SHOW_RESULT_DURATION_PHASE_ONE)
                showResultAnimationPhaseOne.setStartValue(QPoint(result.x(), -result.height()))
                showResultAnimationPhaseOne.setEndValue(result.pos())
                showResultAnimationPhaseOne.setEasingCurve(QEasingCurve.OutBounce)
                self.showResultAnimationGroup.addAnimation(showResultAnimationPhaseOne)

                showResultAnimationPhaseTwo = QPauseAnimation()
                showResultAnimationPhaseTwo.setDuration(GameWindow.ANIMATION_SHOW_RESULT_DURATION_PHASE_TWO)
                self.showResultAnimationGroup.addAnimation(showResultAnimationPhaseTwo)

                self.showResultAnimationGroup.finished.connect(result.hide)
                self.showResultAnimationGroup.finished.connect(self._unfreezeSize)
                self.showResultAnimationGroup.start(QAbstractAnimation.DeleteWhenStopped)

        @Slot()
        def _triggerLose(self):
                self.game.gameLose.disconnect()
                self._triggerResult(self.lose)

        @Slot()
        def _triggerWin(self):
                self.game.gameWin.disconnect()
                self._triggerResult(self.win)

        def _onPlayersUpdated(self):
                self.statBox.setPlayers(self.game.players)

        def closeEvent(self, event):
                self.closed.emit()
                super(GameWindow, self).closeEvent(event)

        def paintEvent(self, event):
                painter = QPainter()
                painter.begin(self)

                # background
                image = QImage(QDir.currentPath() + '/gui/images/background.png')
                image = image.copy(MainFrame.OFFSET_X, MainFrame.OFFSET_Y, MainFrame.WIDTH, MainFrame.HEIGHT)
                image = image.scaled(self.width(), self.height(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation);
                painter.drawImage(0, 0, image)

                painter.end()

        def show(self):
                super(GameWindow, self).show()
                rect = QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, self.size(),
                                          QApplication.desktop().availableGeometry())
                self.move(rect.x(), rect.y())
Exemplo n.º 4
0
class GameWindow(QWidget):

    ANIMATION_SHOW_RESULT_DURATION_PHASE_ONE = 2000
    ANIMATION_SHOW_RESULT_DURATION_PHASE_TWO = 5000

    def __init__(self, game, gameView):
        super(GameWindow, self).__init__()

        stretchA = (1000 - 618) * (1000 - 618)
        stretchB = 1000000 - stretchA

        layout = QGridLayout(self)
        layout.setColumnStretch(0, stretchB)
        layout.setColumnStretch(1, stretchA)

        leftLayout = QGridLayout()
        leftLayout.setRowStretch(0, stretchB)
        leftLayout.setRowStretch(1, stretchA)
        rightLayout = QGridLayout()
        rightLayout.setRowStretch(0, stretchA)
        rightLayout.setRowStretch(1, stretchB)
        layout.addLayout(leftLayout, 0, 0)
        layout.addLayout(rightLayout, 0, 1)

        self.game = game
        self.game.playersUpdated.connect(self._onPlayersUpdated)

        gameView.player = game.connectionManager.player
        gameView.attackInitiated.connect(self.game._onAttackInitiated)

        self.gameView = GameViewWrapper(gameView)
        self.eventBox = EventBox()
        self.countryBox = CountryInfoBox(self)
        self.statBox = StatBox(gameView)

        self.lose = Title('YOU LOSE', 100)
        self.win = Title('YOU WIN', 100)
        self.lose.setParent(self)
        self.win.setParent(self)
        self.lose.raise_()
        self.win.raise_()
        self.lose.hide()
        self.win.hide()

        self.eventBox.setColor(QColor(Qt.black))
        self.countryBox.setColor(QColor(Qt.gray))
        self.statBox.setColor(QColor(Qt.gray))

        leftLayout.addWidget(self.gameView, 0, 0)
        leftLayout.addWidget(self.eventBox, 1, 0)
        rightLayout.addWidget(self.statBox, 0, 0)
        rightLayout.addWidget(self.countryBox, 1, 0)

        gameView.hoverCountry.connect(self.countryBox.updateCountry)
        gameView.ownerChanged.connect(self.statBox.refresh)

        game.gameEvent.connect(self.eventBox.addEvent)
        game.gameLose.connect(self._triggerLose)
        game.gameWin.connect(self._triggerWin)

    closed = Signal()

    @Slot()
    def _unfreezeSize(self):
        self.setFixedSize(QSize(16777215, 16777215))

    def _triggerResult(self, result):
        result.changeSize(int(100 * self.gameView.width() / 677))
        rect = QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter,
                                  result.titleImage().size(),
                                  self.gameView.rect())
        result.move(rect.x(), rect.y())
        result.show()
        result.raise_()

        self.setFixedSize(self.size())

        self.showResultAnimationGroup = QSequentialAnimationGroup()

        showResultAnimationPhaseOne = QPropertyAnimation(result, 'pos')
        showResultAnimationPhaseOne.setDuration(
            GameWindow.ANIMATION_SHOW_RESULT_DURATION_PHASE_ONE)
        showResultAnimationPhaseOne.setStartValue(
            QPoint(result.x(), -result.height()))
        showResultAnimationPhaseOne.setEndValue(result.pos())
        showResultAnimationPhaseOne.setEasingCurve(QEasingCurve.OutBounce)
        self.showResultAnimationGroup.addAnimation(showResultAnimationPhaseOne)

        showResultAnimationPhaseTwo = QPauseAnimation()
        showResultAnimationPhaseTwo.setDuration(
            GameWindow.ANIMATION_SHOW_RESULT_DURATION_PHASE_TWO)
        self.showResultAnimationGroup.addAnimation(showResultAnimationPhaseTwo)

        self.showResultAnimationGroup.finished.connect(result.hide)
        self.showResultAnimationGroup.finished.connect(self._unfreezeSize)
        self.showResultAnimationGroup.start(
            QAbstractAnimation.DeleteWhenStopped)

    @Slot()
    def _triggerLose(self):
        self.game.gameLose.disconnect()
        self._triggerResult(self.lose)

    @Slot()
    def _triggerWin(self):
        self.game.gameWin.disconnect()
        self._triggerResult(self.win)

    def _onPlayersUpdated(self):
        self.statBox.setPlayers(self.game.players)

    def closeEvent(self, event):
        self.closed.emit()
        super(GameWindow, self).closeEvent(event)

    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)

        # background
        image = QImage(QDir.currentPath() + '/gui/images/background.png')
        image = image.copy(MainFrame.OFFSET_X, MainFrame.OFFSET_Y,
                           MainFrame.WIDTH, MainFrame.HEIGHT)
        image = image.scaled(self.width(), self.height(), Qt.IgnoreAspectRatio,
                             Qt.SmoothTransformation)
        painter.drawImage(0, 0, image)

        painter.end()

    def show(self):
        super(GameWindow, self).show()
        rect = QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, self.size(),
                                  QApplication.desktop().availableGeometry())
        self.move(rect.x(), rect.y())