Esempio n. 1
0
    def IPartialRefreshDisplay(self):
        "Refreshes only the volitile time entries (i.e. a game being played or a completed game)"
        
        gameSelector = ptGUIControlRadioGroup(MarkerGameDlg.dialog.getControlFromTag(kRGMarkerGameSelect))
        curGame = gameSelector.getValue()


        #check a completed game
        if self.lastGame > -1:
            if self.debug:
                print "PARTIAL--LASTGAME!"
            fieldID = self.lastGame * 10 + kMarkerGameFieldStart
            timeTB = ptGUIControlTextBox(MarkerGameDlg.dialog.getControlFromTag(fieldID+kMarkerGameNameFieldOffset))
            gameName = grtzMarkerGames.GetCGZGameName(self.lastGame)

            startTime,bestTime = grtzMarkerGames.GetGameTime(gameName)

            if bestTime >= 0.1:
                tuptime = time.gmtime(bestTime)
                modText = ""

                if self.lastGameScore < bestTime or (self.lastGameScore > 0 and bestTime <= 0):
                    modText = "*"
                    #Kill the timer if we were only awaiting a best game update
                    if curGame == -1:
                        self.updateLevel = kNoRefresh
                if tuptime[2] == 1:
                    ostring = modText+"%02d:%02d:%02d"+modText
                    timeTB.setString(ostring % (tuptime[3],tuptime[4],tuptime[5]))
                else:
                    ostring = modText+"%02d:%02d:%02d:%02d"+modText
                    timeTB.setString(ostring % (tuptime[2]-1,tuptime[3],tuptime[4],tuptime[5]))
            else:
                timeTB.setString("--:--:--")

        #Check the current game
        if curGame > -1:
            if self.debug:
                print "PARTIAL--CURRENT!"
            fieldID = curGame * 10 + kMarkerGameFieldStart
            timeTB = ptGUIControlTextBox(MarkerGameDlg.dialog.getControlFromTag(fieldID+kMarkerGameNameFieldOffset))
            gameName = grtzMarkerGames.GetCGZGameName(curGame)

            startTime,bestTime = grtzMarkerGames.GetGameTime(gameName)
            bestTime = PtGetDniTime() - startTime

            if bestTime == 0:
                timeTB.setString("00:00:00")
            elif bestTime >= 0.1:
                tuptime = time.gmtime(bestTime)
                if tuptime[2] == 1:
                    ostring = "%02d:%02d:%02d"
                    timeTB.setString(ostring % (tuptime[3],tuptime[4],tuptime[5]))
                else:
                    ostring = "%02d:%02d:%02d:%02d"
                    timeTB.setString(ostring % (tuptime[2]-1,tuptime[3],tuptime[4],tuptime[5]))
            else:
                timeTB.setString("--:--:--")
    def stopCGZGame(self):
        "Call this to stop a CGZ marker game, it automatically checks for win conditiions"
        gameNum = self.gameData.data['CGZGameNum']
        #check for End Game
        finishTime = 0.0
        if self.gameData.data['numMarkers'] == self.gameData.data[
                'numCapturedMarkers'] and self.gameData.data['numMarkers'] > 0:
            PtDebugPrint(
                "DEBUG: xMarkerGameManager.stopCGZGame():\tGame Completed!  ---Checking for new best score---"
            )
            endTime = PtGetDniTime()
            startTime, bestTime = grtzMarkerGames.GetGameTime(
                grtzMarkerGames.GetCGZGameName(gameNum))
            finishTime = endTime - startTime

        #Update Score Display
        PtDebugPrint(
            "DEBUG: xMarkerGameManager.stopCGZGame(): Attempting to Register score: %s for game: %s"
            % (finishTime, gameNum))
        grtzMarkerGames.UpdateScore(self.gameData.data['CGZGameNum'], 0,
                                    finishTime)

        #Delete Game from the server
        try:
            PtDebugPrint(
                "DEBUG: xMarkerGameManager.stopCGZGame():\t----Dispatching stop CGZ Marker Game----"
            )
            server = GetGameClient(self.gameData.data['svrGameClientID'])
            server.deleteGame()
        except:
            #if we could not process previous statements, we had better clean up a little!
            self.gameData.initDefaultValues()
            self.gameData.save()
    def IRefreshGamesDisplay(self):
        "refresh the number and best time fields for the games"
        if self.debug:
            print "---->FULL UPDATE!"
        gameSelector = ptGUIControlRadioGroup(
            MarkerGameDlg.dialog.getControlFromTag(kRGMarkerGameSelect))
        curGame = gameSelector.getValue()

        curGameName = grtzMarkerGames.GetCGZGameName(curGame)
        for fieldID in range(kMarkerGameFieldStart, kMarkerGameFieldEnd, 10):
            numTB = ptGUIControlTextBox(
                MarkerGameDlg.dialog.getControlFromTag(
                    fieldID + kMarkerGameNumFieldOffset))
            timeTB = ptGUIControlTextBox(
                MarkerGameDlg.dialog.getControlFromTag(
                    fieldID + kMarkerGameNameFieldOffset))
            gameidx = (fieldID - kMarkerGameFieldStart) / 10
            numTB.setString("%d" % (grtzMarkerGames.GetNumMarkers(gameidx)))
            gameName = grtzMarkerGames.GetCGZGameName(gameidx)

            startTime, bestTime = grtzMarkerGames.GetGameTime(gameName)
            showZeros = 0
            if curGameName == gameName:
                # use the currentTime
                bestTime = PtGetDniTime() - startTime
                showZeros = 1

            if showZeros == 1 and bestTime == 0:
                timeTB.setString("00:00:00")
            elif bestTime >= 0.1:
                tuptime = time.gmtime(bestTime)
                preText = ""
                postText = ""

                #Check for best game....
                if self.lastGame == gameidx:
                    if self.lastGameScore < bestTime or (self.lastGameScore > 0
                                                         and bestTime <= 0):
                        preText = "*"
                        postText = "*"
                if tuptime[2] == 1:
                    ostring = preText + "%02d:%02d:%02d" + postText
                    timeTB.setString(ostring %
                                     (tuptime[3], tuptime[4], tuptime[5]))
                else:
                    ostring = preText + "%02d:%02d:%02d:%02d" + postText
                    timeTB.setString(
                        ostring %
                        (tuptime[2] - 1, tuptime[3], tuptime[4], tuptime[5]))
            else:
                timeTB.setString("--:--:--")