コード例 #1
0
    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()
コード例 #2
0
    def OnGUINotify(self, id, control, event):
        "Events from all the dialogs in the MarkerGameGUI Age..."
        if id != MarkerGameDlg.id:
            return

        #~PtDebugPrint("grtzMarkerScopeGUI::OnGUINotify id=%d, event=%d control=" % (id,event),control)#,level=kDebugDumpLevel )
        if event == kDialogLoaded:
            PtDebugPrint(
                "DEBUG: grtzMarkerScopeGUI():\tMarker Scope GUU--->Dialog Loaded!"
            )
            # hide stuff until needed
            MGAnim.animation.skipToTime(1.5)

        elif event == kShowHide:
            if control.isEnabled():
                PtDebugPrint(
                    "DEBUG: grtzMarkerScopeGUI():\tMarker Scope-GUI--->Show Dialog"
                )
                # make sure the player has enough level to see the GUI
                gameType = grtzMarkerGames.GetCurrentGameType()
                if PtDetermineKIMarkerLevel() < kKIMarkerNormalLevel:
                    PtDebugPrint(
                        "DEBUG: grtzMarkerScopeGUI.OnGUINotify():\tKI Level not high enough, disabling GUI controls"
                    )
                    gameSelector = ptGUIControlRadioGroup(
                        MarkerGameDlg.dialog.getControlFromTag(
                            kRGMarkerGameSelect))
                    gameSelector.setValue(-1)
                    gameSelector.disable()
                    self.updateLevel = kNoRefresh
                elif gameType > -1 and gameType != PtMarkerGameTypes.kMarkerGameCGZ:
                    PtDebugPrint(
                        "DEBUG: grtzMarkerScopeGUI.OnGUINotify():\tUser Created Marker Game in Progress, disabling GUI controls"
                    )
                    gameSelector = ptGUIControlRadioGroup(
                        MarkerGameDlg.dialog.getControlFromTag(
                            kRGMarkerGameSelect))
                    gameSelector.setValue(-1)
                    gameSelector.disable()
                    self.updateLevel = kNoRefresh
                    msg = "Please quit existing User-Created Marker Game, to play a CGZ Game."
                    PtSendKIMessage(kKILocalChatStatusMsg, msg)
                    self.IRefreshGamesDisplay()
                    MGMachineOnResp.run(self.key, netPropagate=0)
                else:  #We're loading the GUI
                    # Get gameData (if Any)
                    gameNum, numCaptured, numMarkers = grtzMarkerGames.GetGameProgress(
                    )
                    PtDebugPrint(
                        "DEBUG: grtzMarkerScopeGUI.OnGUINotify():\tInitializing GUI, current gameNum = %s"
                        % gameNum)

                    #Set refresh level to not update, later we'll change it if necessary...
                    self.updateLevel = kNoRefresh
                    self.lastGame = -1
                    self.lastGameScore = -1

                    if gameNum > -1 and numCaptured > -1 and numMarkers > -1:
                        if numCaptured == numMarkers:
                            #We've got a completed game!!!
                            #Stop the game....
                            PtSendKIMessage(kMGStopCGZGame, 0)

                            #Save the game information
                            self.lastGame = gameNum
                            self.lastGameScore = grtzMarkerGames.GetGameScore(
                                gameNum)

                            #Now set the selector to unselected...
                            gameNum = -1

                            #Setup the timer to refresh the display
                            self.updateLevel = kPartialRefresh

                    # Set selector to the game being played (if Any)
                    gameSelector = ptGUIControlRadioGroup(
                        MarkerGameDlg.dialog.getControlFromTag(
                            kRGMarkerGameSelect))
                    gameSelector.enable()
                    oldGame = gameSelector.getValue()
                    if gameNum != oldGame:
                        gameSelector.setValue(gameNum)
                        self.init = 0
                    else:
                        #We've already initialized properly, no need to do it again!
                        self.init = 1

                    if gameNum > -1:
                        # start/continue the counting
                        self.updateLevel = kPartialRefresh

                    #Refresh Display
                    self.IRefreshGamesDisplay()
                    MGMachineOnResp.run(self.key, netPropagate=0)

                    if self.updateLevel > kNoRefresh:
                        PtAtTimeCallback(self.key, 1, kDisplayTimer)
            else:
                PtDebugPrint(
                    "DEBUG: grtzMarkerScopeGUI():\tMarker Scope-GUI--->Hide dialog"
                )
                #Hide scope...
                MGAnim.animation.skipToTime(1.5)
                self.lastGame = -1
                self.lastGameScore = -1

                #Stop the timer callbacks...
                self.updateLevel = kNoRefresh

                #Get the game selected
                gameSelector = ptGUIControlRadioGroup(
                    MarkerGameDlg.dialog.getControlFromTag(
                        kRGMarkerGameSelect))
                reqGameNum = gameSelector.getValue()
                curGameNum = grtzMarkerGames.GetCurrentCGZGame()

                #Start the game if necessary
                if self.selectorChanged:
                    #Exit if somehow we really don't have a valid game!
                    if reqGameNum < 0 or reqGameNum > len(grtzMarkerGames.mgs):
                        PtDebugPrint(
                            "ERROR: grtzMarkerScopeGUI.OnGUINotify:\tCannot start invalid game number: %d"
                            % reqGameNum)
                        return

                    #Finally, start the new game!
                    PtDebugPrint(
                        "DEBUG: grtzMarkerScopeGUI.OnGUINotify():\tReceived GUI notification to start game: %s"
                        % reqGameNum)
                    PtSendKIMessageInt(kMGStartCGZGame, reqGameNum)

                    #Reset selector sensor
                    self.selectorChanged = 0

        elif event == kValueChanged:
            rgid = control.getTagID()
            if rgid == kRGMarkerGameSelect:
                #The first time we update the selector, we don't want to register a new game selected!!!
                #All played games are initialized upon age load, not upon marker scope GUI load....
                if self.init == 0:
                    PtDebugPrint(
                        "DEBUG: grtzMarkerScopeGUI.OnGUINotify():\tFinished initialization.... (ignoring selector change)"
                    )
                    self.init = 1  #Make sure we don't try to re-init!
                    return

                self.selectorChanged = 1  #let us know if the selector changed for (so we can start/stop a game if necessary)

                gameNum = control.getValue()
                PtDebugPrint(
                    "DEBUG: grtzMarkerScopeGUI.OnGUINotify():\tReceived CGZ Game Selector change: %s"
                    % gameNum)

                #If we were playing an existing game, we need to quit it!!!
                curGame = grtzMarkerGames.GetCurrentCGZGame()
                if curGame != None and curGame > -1:
                    PtDebugPrint(
                        "DEBUG: grtzMarkerScopeGUI.OnGUINotify():\tSelector value changed, stopping current game!"
                    )
                    PtSendKIMessage(kMGStopCGZGame, 0)
                    self.updateLevel = kOneTimeFullRefresh

                #Reset the score if we've seleced a game
                prevRefresh = self.updateLevel
                if gameNum > -1 and gameNum < len(grtzMarkerGames.mgs):
                    grtzMarkerGames.UpdateScore(gameNum, PtGetDniTime(), 0.0)
                    self.updateLevel = kPartialRefresh
                else:
                    #just need to refresh the entire display to ensure we've stopped any timer displays
                    self.updateLevel = kOneTimeFullRefresh
                    pass

                #Force one update...
                self.IRefreshGamesDisplay()

                #Update display... only if we didn't have plans to update...
                if prevRefresh == kNoRefresh:
                    PtAtTimeCallback(self.key, 0, kDisplayTimer)