loon4tic

Toonbase

Jun 4th, 2016 (edited)
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.40 KB | None | 0 0
  1. #Embedded file name: toontown.toonbase.ToonBase
  2. from otp.otpbase import OTPBase
  3. from otp.otpbase import OTPLauncherGlobals
  4. from otp.otpbase import OTPGlobals
  5. from otp.otpbase.PythonUtil import *
  6. import ToontownGlobals
  7. from direct.directnotify import DirectNotifyGlobal
  8. import ToontownLoader
  9. from direct.gui import DirectGuiGlobals
  10. from direct.gui.DirectGui import *
  11. from direct.showbase.Transitions import Transitions
  12. from pandac.PandaModules import *
  13. from direct.interval.IntervalGlobal import Sequence, Func, Wait
  14. from otp.nametag.ChatBalloon import ChatBalloon
  15. from otp.nametag import NametagGlobals
  16. from otp.margins.MarginManager import MarginManager
  17. import sys
  18. import os
  19. import math
  20. import tempfile
  21. import shutil
  22. import atexit
  23. from toontown.toonbase import ToontownAccess
  24. from toontown.toonbase import TTLocalizer
  25. from toontown.toonbase import ToontownBattleGlobals
  26. from toontown.launcher import ToontownDownloadWatcher
  27. from toontown.toontowngui import TTDialog
  28. from sys import platform
  29. from DisplayOptions import DisplayOptions
  30. import otp.ai.DiagnosticMagicWords
  31. import time
  32. from panda3d.core import TrueClock
  33.  
  34. class ToonBase(OTPBase.OTPBase):
  35.     notify = DirectNotifyGlobal.directNotify.newCategory('ToonBase')
  36.  
  37.     def __init__(self):
  38.         self.display = DisplayOptions()
  39.         OTPBase.OTPBase.__init__(self)
  40.         base.enableMusic(settings.GetBool('game', 'music', True))
  41.         base.enableSoundEffects(settings.GetBool('game', 'sfx', True))
  42.         if settings.GetBool('game', 'borderless-fullscreen', False):
  43.             props = WindowProperties()
  44.             props.setUndecorated(True)
  45.             displayInfo = base.pipe.getDisplayInformation()
  46.             props.setSize(displayInfo.getDisplayModeWidth(0), displayInfo.getDisplayModeHeight(0))
  47.             base.win.requestProperties(props)
  48.         self.disableShowbaseMouse()
  49.         self.addCullBins()
  50.         base.debugRunningMultiplier /= OTPGlobals.ToonSpeedFactor
  51.         self.toonChatSounds = self.config.GetBool('toon-chat-sounds', 1)
  52.         self.placeBeforeObjects = config.GetBool('place-before-objects', 1)
  53.         self.endlessQuietZone = False
  54.         self.wantDynamicShadows = 0
  55.         self.exitErrorCode = 0
  56.         camera.setPosHpr(0, 0, 0, 0, 0, 0)
  57.         self.camLens.setMinFov(ToontownGlobals.DefaultCameraFov / (4.0 / 3.0))
  58.         self.camLens.setNearFar(ToontownGlobals.DefaultCameraNear, ToontownGlobals.DefaultCameraFar)
  59.         self.cam2d.node().setCameraMask(BitMask32.bit(1))
  60.         self.musicManager.setVolume(0.65)
  61.         self.setBackgroundColor(ToontownGlobals.DefaultBackgroundColor)
  62.         tpm = TextPropertiesManager.getGlobalPtr()
  63.         candidateActive = TextProperties()
  64.         candidateActive.setTextColor(0, 0, 1, 1)
  65.         tpm.setProperties('candidate_active', candidateActive)
  66.         candidateInactive = TextProperties()
  67.         candidateInactive.setTextColor(0.3, 0.3, 0.7, 1)
  68.         tpm.setProperties('candidate_inactive', candidateInactive)
  69.         self.transitions.IrisModelName = 'phase_3/models/misc/iris'
  70.         self.transitions.FadeModelName = 'phase_3/models/misc/fade'
  71.         self.snapshotSfx = base.loadSfx('phase_4/audio/sfx/Photo_shutter.ogg')
  72.         self.flashTrack = None
  73.         self.exitFunc = self.userExit
  74.         if __builtins__.has_key('launcher') and launcher:
  75.             launcher.setPandaErrorCode(11)
  76.         globalClock.setMaxDt(0.2)
  77.         if self.config.GetBool('want-particles', 1) == 1:
  78.             self.notify.debug('Enabling particles')
  79.             self.enableParticles()
  80.         self.acceptOnce(ToontownGlobals.ScreenshotHotkey, self.takeScreenShot)
  81.         if platform == 'darwin':
  82.             self.acceptOnce(ToontownGlobals.QuitGameHotKeyOSX, self.exitOSX)
  83.             self.accept(ToontownGlobals.QuitGameHotKeyRepeatOSX, self.exitOSX)
  84.             self.acceptOnce(ToontownGlobals.HideGameHotKeyOSX, self.hideGame)
  85.             self.accept(ToontownGlobals.HideGameHotKeyRepeatOSX, self.hideGame)
  86.             self.acceptOnce(ToontownGlobals.MinimizeGameHotKeyOSX, self.minimizeGame)
  87.             self.accept(ToontownGlobals.MinimizeGameHotKeyRepeatOSX, self.minimizeGame)
  88.         self.accept('f3', self.toggleGui)
  89.         self.accept('panda3d-render-error', self.panda3dRenderError)
  90.         oldLoader = self.loader
  91.         self.loader = ToontownLoader.ToontownLoader(self)
  92.         __builtins__['loader'] = self.loader
  93.         oldLoader.destroy()
  94.         self.accept('PandaPaused', self.disableAllAudio)
  95.         self.accept('PandaRestarted', self.enableAllAudio)
  96.         self.friendMode = self.config.GetBool('switchboard-friends', 0)
  97.         self.wantPets = self.config.GetBool('want-pets', 1)
  98.         self.wantBingo = self.config.GetBool('want-fish-bingo', 1)
  99.         self.wantKarts = self.config.GetBool('want-karts', 1)
  100.         self.wantNewSpecies = self.config.GetBool('want-new-species', 0)
  101.         self.inactivityTimeout = self.config.GetFloat('inactivity-timeout', ToontownGlobals.KeyboardTimeout)
  102.         if self.inactivityTimeout:
  103.             self.notify.debug('Enabling Panda timeout: %s' % self.inactivityTimeout)
  104.             self.mouseWatcherNode.setInactivityTimeout(self.inactivityTimeout)
  105.         self.mouseWatcherNode.setEnterPattern('mouse-enter-%r')
  106.         self.mouseWatcherNode.setLeavePattern('mouse-leave-%r')
  107.         self.mouseWatcherNode.setButtonDownPattern('button-down-%r')
  108.         self.mouseWatcherNode.setButtonUpPattern('button-up-%r')
  109.         self.randomMinigameAbort = self.config.GetBool('random-minigame-abort', 0)
  110.         self.randomMinigameDisconnect = self.config.GetBool('random-minigame-disconnect', 0)
  111.         self.randomMinigameNetworkPlugPull = self.config.GetBool('random-minigame-netplugpull', 0)
  112.         self.autoPlayAgain = self.config.GetBool('auto-play-again', 0)
  113.         self.skipMinigameReward = self.config.GetBool('skip-minigame-reward', 0)
  114.         self.wantMinigameDifficulty = self.config.GetBool('want-minigame-difficulty', 0)
  115.         self.minigameDifficulty = self.config.GetFloat('minigame-difficulty', -1.0)
  116.         if self.minigameDifficulty == -1.0:
  117.             del self.minigameDifficulty
  118.         self.minigameSafezoneId = self.config.GetInt('minigame-safezone-id', -1)
  119.         if self.minigameSafezoneId == -1:
  120.             del self.minigameSafezoneId
  121.         cogdoGameSafezoneId = self.config.GetInt('cogdo-game-safezone-id', -1)
  122.         cogdoGameDifficulty = self.config.GetFloat('cogdo-game-difficulty', -1)
  123.         if cogdoGameDifficulty != -1:
  124.             self.cogdoGameDifficulty = cogdoGameDifficulty
  125.         if cogdoGameSafezoneId != -1:
  126.             self.cogdoGameSafezoneId = cogdoGameSafezoneId
  127.         self.creditCardUpFront = self.config.GetInt('credit-card-up-front', -1)
  128.         if self.creditCardUpFront == -1:
  129.             del self.creditCardUpFront
  130.         else:
  131.             self.creditCardUpFront = self.creditCardUpFront != 0
  132.         self.housingEnabled = self.config.GetBool('want-housing', 1)
  133.         self.cannonsEnabled = self.config.GetBool('estate-cannons', 0)
  134.         self.fireworksEnabled = self.config.GetBool('estate-fireworks', 0)
  135.         self.dayNightEnabled = self.config.GetBool('estate-day-night', 0)
  136.         self.cloudPlatformsEnabled = self.config.GetBool('estate-clouds', 0)
  137.         self.greySpacing = self.config.GetBool('allow-greyspacing', 0)
  138.         self.goonsEnabled = self.config.GetBool('estate-goon', 0)
  139.         self.restrictTrialers = self.config.GetBool('restrict-trialers', 1)
  140.         self.roamingTrialers = self.config.GetBool('roaming-trialers', 1)
  141.         self.slowQuietZone = self.config.GetBool('slow-quiet-zone', 0)
  142.         self.slowQuietZoneDelay = self.config.GetFloat('slow-quiet-zone-delay', 5)
  143.         self.killInterestResponse = self.config.GetBool('kill-interest-response', 0)
  144.         tpMgr = TextPropertiesManager.getGlobalPtr()
  145.         WLDisplay = TextProperties()
  146.         WLDisplay.setSlant(0.3)
  147.         WLEnter = TextProperties()
  148.         WLEnter.setTextColor(1.0, 0.0, 0.0, 1)
  149.         tpMgr.setProperties('WLDisplay', WLDisplay)
  150.         tpMgr.setProperties('WLEnter', WLEnter)
  151.         del tpMgr
  152.         self.lastScreenShotTime = globalClock.getRealTime()
  153.         self.accept('InputState-forward', self.__walking)
  154.         self.canScreenShot = 1
  155.         self.glitchCount = 0
  156.         self.walking = 0
  157.         self.oldX = max(1, base.win.getXSize())
  158.         self.oldY = max(1, base.win.getYSize())
  159.         self.aspectRatio = float(self.oldX) / self.oldY
  160.         self.localAvatarStyle = None
  161.         self.magicPlaceCameraMat = None
  162.         sfxVolume = settings.GetInt('game', 'sfx-volume', 100) / 100.0
  163.         sfxVolume = max(min(1.0, sfxVolume), 0.0)
  164.         musicVolume = settings.GetInt('game', 'music-volume', 100) / 100.0
  165.         musicVolume = max(min(1.0, musicVolume), 0.0)
  166.         self.setMasterVolumeMusic(musicVolume)
  167.         self.setMasterVolumeSfx(sfxVolume)
  168.  
  169.     def openMainWindow(self, *args, **kw):
  170.         result = OTPBase.OTPBase.openMainWindow(self, *args, **kw)
  171.         self.setCursorAndIcon()
  172.         return result
  173.  
  174.     def windowEvent(self, win):
  175.         OTPBase.OTPBase.windowEvent(self, win)
  176.         if not config.GetInt('keep-aspect-ratio', 0):
  177.             return
  178.         x = max(1, win.getXSize())
  179.         y = max(1, win.getYSize())
  180.         maxX = base.pipe.getDisplayWidth()
  181.         maxY = base.pipe.getDisplayHeight()
  182.         cwp = win.getProperties()
  183.         originX = 0
  184.         originY = 0
  185.         if cwp.hasOrigin():
  186.             originX = cwp.getXOrigin()
  187.             originY = cwp.getYOrigin()
  188.             if originX > maxX:
  189.                 originX = originX - maxX
  190.             if originY > maxY:
  191.                 oringY = originY - maxY
  192.         maxX -= originX
  193.         maxY -= originY
  194.         if math.fabs(x - self.oldX) > math.fabs(y - self.oldY):
  195.             newY = x / self.aspectRatio
  196.             newX = x
  197.             if newY > maxY:
  198.                 newY = maxY
  199.                 newX = self.aspectRatio * maxY
  200.         else:
  201.             newX = self.aspectRatio * y
  202.             newY = y
  203.             if newX > maxX:
  204.                 newX = maxX
  205.                 newY = maxX / self.aspectRatio
  206.         wp = WindowProperties()
  207.         wp.setSize(newX, newY)
  208.         base.win.requestProperties(wp)
  209.         base.cam.node().getLens().setFilmSize(newX, newY)
  210.         self.oldX = newX
  211.         self.oldY = newY
  212.  
  213.     def setCursorAndIcon(self):
  214.         tempdir = tempfile.mkdtemp()
  215.         atexit.register(shutil.rmtree, tempdir)
  216.         vfs = VirtualFileSystem.getGlobalPtr()
  217.         searchPath = DSearchPath()
  218.         searchPath.appendDirectory(Filename('/phase_3/etc'))
  219.         for filename in ['toonmono.cur', 'icon.ico']:
  220.             p3filename = Filename(filename)
  221.             found = vfs.resolveFilename(p3filename, searchPath)
  222.             if not found:
  223.                 return
  224.             with open(os.path.join(tempdir, filename), 'wb') as f:
  225.                 f.write(vfs.readFile(p3filename, False))
  226.  
  227.         wp = WindowProperties()
  228.         wp.setCursorFilename(Filename.fromOsSpecific(os.path.join(tempdir, 'toonmono.cur')))
  229.         wp.setIconFilename(Filename.fromOsSpecific(os.path.join(tempdir, 'icon.ico')))
  230.         self.win.requestProperties(wp)
  231.  
  232.     def addCullBins(self):
  233.         cbm = CullBinManager.getGlobalPtr()
  234.         cbm.addBin('ground', CullBinManager.BTUnsorted, 18)
  235.         cbm.addBin('shadow', CullBinManager.BTBackToFront, 19)
  236.         cbm.addBin('gui-popup', CullBinManager.BTFixed, 60)
  237.  
  238.     def disableShowbaseMouse(self):
  239.         self.useDrive()
  240.         self.disableMouse()
  241.         if self.mouseInterface:
  242.             self.mouseInterface.detachNode()
  243.         if self.mouse2cam:
  244.             self.mouse2cam.detachNode()
  245.  
  246.     def __walking(self, pressed):
  247.         self.walking = pressed
  248.  
  249.     def toggleGui(self):
  250.         if aspect2d.isHidden():
  251.             aspect2d.show()
  252.         else:
  253.             aspect2d.hide()
  254.  
  255.     def __startScreenshotDelayTask(self):
  256.         taskMgr.doMethodLater(1.0, self.__listenForScreenshotsAgain, 'ToonBase-screenshotDelayTask')
  257.  
  258.     def __listenForScreenshotsAgain(self, task = None):
  259.         self.acceptOnce(ToontownGlobals.ScreenshotHotkey, self.takeScreenShot)
  260.         if task is not None:
  261.             return task.done
  262.  
  263.     def takeScreenShot(self):
  264.         if not os.path.exists(TTLocalizer.ScreenshotPath):
  265.             os.mkdir(TTLocalizer.ScreenshotPath)
  266.             self.notify.info('Made new directory to save screenshots.')
  267.         namePrefix = TTLocalizer.ScreenshotPath + launcher.logPrefix + 'screenshot'
  268.         if not hasattr(self, 'localAvatar'):
  269.             self.screenshot(namePrefix=namePrefix)
  270.             self.lastScreenShotTime = globalClock.getRealTime()
  271.             return
  272.         if self.flashTrack and self.flashTrack.isPlaying():
  273.             self.flashTrack.finish()
  274.         self.transitions.noFade()
  275.         coordOnScreen = self.config.GetBool('screenshot-coords', 0)
  276.         self.localAvatar.stopThisFrame = 1
  277.         ctext = self.localAvatar.getAvPosStr()
  278.         self.screenshotStr = ''
  279.         messenger.send('takingScreenshot')
  280.         if coordOnScreen:
  281.             coordTextLabel = DirectLabel(pos=(-0.81, 0.001, -0.87), text=ctext, text_scale=0.05, text_fg=VBase4(1.0, 1.0, 1.0, 1.0), text_bg=(0, 0, 0, 0), text_shadow=(0, 0, 0, 1), relief=None)
  282.             coordTextLabel.setBin('gui-popup', 0)
  283.             strTextLabel = None
  284.             if len(self.screenshotStr):
  285.                 strTextLabel = DirectLabel(pos=(0.0, 0.001, 0.9), text=self.screenshotStr, text_scale=0.05, text_fg=VBase4(1.0, 1.0, 1.0, 1.0), text_bg=(0, 0, 0, 0), text_shadow=(0, 0, 0, 1), relief=None)
  286.                 strTextLabel.setBin('gui-popup', 0)
  287.         self.graphicsEngine.renderFrame()
  288.         self.screenshot(namePrefix=namePrefix, imageComment=ctext + ' ' + self.screenshotStr)
  289.         self.lastScreenShotTime = globalClock.getRealTime()
  290.         self.transitions.setFadeColor(1, 1, 1)
  291.         self.flashTrack = Sequence(Func(base.playSfx, self.snapshotSfx), Func(self.transitions.fadeOut, 0.15), Wait(0.2), Func(self.transitions.fadeIn, 0.8), Wait(1.0), Func(self.transitions.setFadeColor, 0, 0, 0))
  292.         self.flashTrack.start()
  293.         if coordOnScreen:
  294.             if strTextLabel is not None:
  295.                 strTextLabel.destroy()
  296.             coordTextLabel.destroy()
  297.         self.__startScreenshotDelayTask()
  298.  
  299.     def addScreenshotString(self, str):
  300.         if len(self.screenshotStr):
  301.             self.screenshotStr += '\n'
  302.         self.screenshotStr += str
  303.  
  304.     def initNametagGlobals(self):
  305.         arrow = loader.loadModel('phase_3/models/props/arrow')
  306.         card = loader.loadModel('phase_3/models/props/panel')
  307.         speech3d = ChatBalloon(loader.loadModel('phase_3/models/props/chatbox'))
  308.         thought3d = ChatBalloon(loader.loadModel('phase_3/models/props/chatbox_thought_cutout'))
  309.         speech2d = ChatBalloon(loader.loadModel('phase_3/models/props/chatbox_noarrow'))
  310.         chatButtonGui = loader.loadModel('phase_3/models/gui/chat_button_gui')
  311.         NametagGlobals.setCamera(self.cam)
  312.         NametagGlobals.setArrowModel(arrow)
  313.         NametagGlobals.setNametagCard(card, VBase4(-0.5, 0.5, -0.5, 0.5))
  314.         if self.mouseWatcherNode:
  315.             NametagGlobals.setMouseWatcher(self.mouseWatcherNode)
  316.         NametagGlobals.setSpeechBalloon3d(speech3d)
  317.         NametagGlobals.setThoughtBalloon3d(thought3d)
  318.         NametagGlobals.setSpeechBalloon2d(speech2d)
  319.         NametagGlobals.setThoughtBalloon2d(thought3d)
  320.         NametagGlobals.setPageButton(PGButton.SReady, chatButtonGui.find('**/Horiz_Arrow_UP'))
  321.         NametagGlobals.setPageButton(PGButton.SDepressed, chatButtonGui.find('**/Horiz_Arrow_DN'))
  322.         NametagGlobals.setPageButton(PGButton.SRollover, chatButtonGui.find('**/Horiz_Arrow_Rllvr'))
  323.         NametagGlobals.setQuitButton(PGButton.SReady, chatButtonGui.find('**/CloseBtn_UP'))
  324.         NametagGlobals.setQuitButton(PGButton.SDepressed, chatButtonGui.find('**/CloseBtn_DN'))
  325.         NametagGlobals.setQuitButton(PGButton.SRollover, chatButtonGui.find('**/CloseBtn_Rllvr'))
  326.         rolloverSound = DirectGuiGlobals.getDefaultRolloverSound()
  327.         if rolloverSound:
  328.             NametagGlobals.setRolloverSound(rolloverSound)
  329.         clickSound = DirectGuiGlobals.getDefaultClickSound()
  330.         if clickSound:
  331.             NametagGlobals.setClickSound(clickSound)
  332.         NametagGlobals.setToon(self.cam)
  333.         self.marginManager = MarginManager()
  334.         self.margins = self.aspect2d.attachNewNode(self.marginManager)
  335.         self.margins.setBin('gui-popup', 45)
  336.         mm = self.marginManager
  337.         padding = 0.0225
  338.         self.leftCells = [mm.addGridCell(0.2 + padding, -0.45, base.a2dTopLeft), mm.addGridCell(0.2 + padding, -0.9, base.a2dTopLeft), mm.addGridCell(0.2 + padding, -1.35, base.a2dTopLeft)]
  339.         self.bottomCells = [mm.addGridCell(-0.87, 0.2 + padding, base.a2dBottomCenter),
  340.          mm.addGridCell(-0.43, 0.2 + padding, base.a2dBottomCenter),
  341.          mm.addGridCell(0.01, 0.2 + padding, base.a2dBottomCenter),
  342.          mm.addGridCell(0.45, 0.2 + padding, base.a2dBottomCenter),
  343.          mm.addGridCell(0.89, 0.2 + padding, base.a2dBottomCenter)]
  344.         self.rightCells = [mm.addGridCell(-0.2 - padding, -1.35, base.a2dTopRight), mm.addGridCell(-0.2 - padding, -0.9, base.a2dTopRight), mm.addGridCell(-0.2 - padding, -0.45, base.a2dTopRight)]
  345.  
  346.     def hideFriendMargins(self):
  347.         middleCell = self.rightCells[1]
  348.         topCell = self.rightCells[2]
  349.         self.setCellsAvailable([middleCell, topCell], False)
  350.  
  351.     def showFriendMargins(self):
  352.         middleCell = self.rightCells[1]
  353.         topCell = self.rightCells[2]
  354.         self.setCellsAvailable([middleCell, topCell], True)
  355.  
  356.     def setCellsAvailable(self, cell_list, available):
  357.         for cell in cell_list:
  358.             self.marginManager.setCellAvailable(cell, available)
  359.  
  360.     def cleanupDownloadWatcher(self):
  361.         self.downloadWatcher.cleanup()
  362.         self.downloadWatcher = None
  363.  
  364.     def startShow(self, cr, launcherServer = None):
  365.         self.cr = cr
  366.         if self.display.antialias:
  367.             render.setAntialias(AntialiasAttrib.MAuto)
  368.         base.graphicsEngine.renderFrame()
  369.         self.downloadWatcher = ToontownDownloadWatcher.ToontownDownloadWatcher(TTLocalizer.LauncherPhaseNames)
  370.         if launcher.isDownloadComplete():
  371.             self.cleanupDownloadWatcher()
  372.         else:
  373.             self.acceptOnce('launcherAllPhasesComplete', self.cleanupDownloadWatcher)
  374.         gameServer = config.GetString('game-server', '')
  375.         if gameServer:
  376.             self.notify.info('Using game-server from Configrc: %s ' % gameServer)
  377.         elif launcherServer:
  378.             gameServer = launcherServer
  379.             self.notify.info('Using gameServer from launcher: %s ' % gameServer)
  380.         else:
  381.             gameServer = 'localhost'
  382.         serverPort = config.GetInt('server-port', 7198)
  383.         serverList = []
  384.         for name in gameServer.split(';'):
  385.             url = URLSpec(name, 1)
  386.             if config.GetBool('server-force-ssl', False):
  387.                 url.setScheme('s')
  388.             if not url.hasPort():
  389.                 url.setPort(serverPort)
  390.             serverList.append(url)
  391.  
  392.         base.cr.http.loadCertificates('/phase_3/etc/TTRCA.crt')
  393.  
  394.         if len(serverList) == 1:
  395.             failover = config.GetString('server-failover', '')
  396.             serverURL = serverList[0]
  397.             for arg in failover.split():
  398.                 try:
  399.                     port = int(arg)
  400.                     url = URLSpec(serverURL)
  401.                     url.setPort(port)
  402.                 except:
  403.                     url = URLSpec(arg, 1)
  404.  
  405.                 if url != serverURL:
  406.                     serverList.append(url)
  407.  
  408.         cr.loginFSM.request('connect', [serverList])
  409.         self.ttAccess = ToontownAccess.ToontownAccess()
  410.         self.ttAccess.initModuleInfo()
  411.  
  412.     def __speedhackCheckTick(self, task):
  413.         elapsed = time.time() - self.lastSpeedhackCheck
  414.         tc_elapsed = self.trueClock.getLongTime() - self.lastTrueClockTime
  415.         if tc_elapsed > elapsed + 1:
  416.             self.__killSpeedHacker()
  417.             return task.done
  418.         self.lastSpeedhackCheck = time.time()
  419.         self.lastTrueClockTime = self.trueClock.getLongTime()
  420.         return task.cont
  421.  
  422.     def __killSpeedHacker(self):
  423.         self.cr.bootedIndex = 128
  424.         self.cr.bootedText = 'SERVER CONNECTION FAILURE. CLIENT HAS EXCEEDED RATE-LIMIT.'
  425.         self.cr.stopReaderPollTask()
  426.         self.cr.lostConnection()
  427.  
  428.     def removeGlitchMessage(self):
  429.         self.ignore('InputState-forward')
  430.         print 'ignoring InputState-forward'
  431.  
  432.     def exitShow(self, errorCode = None):
  433.         self.notify.info('Exiting Toontown: errorCode = %s' % errorCode)
  434.         if errorCode:
  435.             launcher.setPandaErrorCode(errorCode)
  436.         else:
  437.             launcher.setPandaErrorCode(0)
  438.         sys.exit()
  439.  
  440.     def setExitErrorCode(self, code):
  441.         self.exitErrorCode = code
  442.         if os.name == 'nt':
  443.             exitCode2exitPage = {OTPLauncherGlobals.ExitEnableChat: 'chat',
  444.              OTPLauncherGlobals.ExitSetParentPassword: 'setparentpassword',
  445.              OTPLauncherGlobals.ExitPurchase: 'purchase'}
  446.             if code in exitCode2exitPage:
  447.                 launcher.setRegistry('EXIT_PAGE', exitCode2exitPage[code])
  448.  
  449.     def getExitErrorCode(self):
  450.         return self.exitErrorCode
  451.  
  452.     def userExit(self):
  453.         try:
  454.             self.localAvatar.d_setAnimState('TeleportOut', 1)
  455.         except:
  456.             pass
  457.  
  458.         if hasattr(self, 'ttAccess'):
  459.             self.ttAccess.delete()
  460.         if self.cr.timeManager:
  461.             self.cr.timeManager.setDisconnectReason(ToontownGlobals.DisconnectCloseWindow)
  462.         base.cr._userLoggingOut = False
  463.         try:
  464.             localAvatar
  465.         except:
  466.             pass
  467.         else:
  468.             messenger.send('clientLogout')
  469.             self.cr.dumpAllSubShardObjects()
  470.  
  471.         self.cr.loginFSM.request('shutdown')
  472.         self.notify.warning('Could not request shutdown; exiting anyway.')
  473.         self.ignore(ToontownGlobals.QuitGameHotKeyOSX)
  474.         self.ignore(ToontownGlobals.QuitGameHotKeyRepeatOSX)
  475.         self.ignore(ToontownGlobals.HideGameHotKeyOSX)
  476.         self.ignore(ToontownGlobals.HideGameHotKeyRepeatOSX)
  477.         self.ignore(ToontownGlobals.MinimizeGameHotKeyOSX)
  478.         self.ignore(ToontownGlobals.MinimizeGameHotKeyRepeatOSX)
  479.         self.exitShow()
  480.  
  481.     def panda3dRenderError(self):
  482.         launcher.setPandaErrorCode(14)
  483.         if self.cr.timeManager:
  484.             self.cr.timeManager.setDisconnectReason(ToontownGlobals.DisconnectGraphicsError)
  485.         self.cr.sendDisconnect()
  486.         sys.exit()
  487.  
  488.     def getShardPopLimits(self):
  489.         return (config.GetInt('shard-low-pop', ToontownGlobals.LOW_POP), config.GetInt('shard-mid-pop', ToontownGlobals.MID_POP), config.GetInt('shard-high-pop', ToontownGlobals.HIGH_POP))
  490.  
  491.     def playMusic(self, music, looping = 0, interrupt = 1, volume = None, time = 0.0):
  492.         OTPBase.OTPBase.playMusic(self, music, looping, interrupt, volume, time)
  493.  
  494.     def exitOSX(self):
  495.         self.confirm = TTDialog.TTGlobalDialog(doneEvent='confirmDone', message=TTLocalizer.OptionsPageExitConfirm, style=TTDialog.TwoChoice)
  496.         self.confirm.show()
  497.         self.accept('confirmDone', self.handleConfirm)
  498.  
  499.     def handleConfirm(self):
  500.         status = self.confirm.doneStatus
  501.         self.ignore('confirmDone')
  502.         self.confirm.cleanup()
  503.         del self.confirm
  504.         if status == 'ok':
  505.             self.userExit()
  506.  
  507.     def hideGame(self):
  508.         hideCommand = 'osascript -e \'tell application "System Events"\n                                            set frontProcess to first process whose frontmost is true\n                                            set visible of frontProcess to false\n                                       end tell\''
  509.         os.system(hideCommand)
  510.  
  511.     def minimizeGame(self):
  512.         wp = WindowProperties()
  513.         wp.setMinimized(True)
  514.         base.win.requestProperties(wp)
  515.  
  516.     def magicPlaceLockCamera(self):
  517.         if self.magicPlaceCameraMat is None:
  518.             self.magicPlaceCameraMat = self.cam.getMat()
  519.             self.cam.wrtReparentTo(self.localAvatar)
  520.  
  521.     def magicPlaceUnlockCamera(self):
  522.         if self.magicPlaceCameraMat is not None:
  523.             self.cam.setMat(self.magicPlaceCameraMat)
  524.             self.cam.reparentTo(self.camera)
  525.             self.magicPlaceCameraMat = None
  526.             self.localAvatar.setCameraFov(OTPGlobals.DefaultCameraFov)
Add Comment
Please, Sign In to add comment