DistributedPicnicTable

This commit is contained in:
Zach 2015-05-02 19:00:49 -05:00
parent 758ca8188a
commit cbf9c8451d

View file

@ -1,4 +1,3 @@
import GameGlobals
from pandac.PandaModules import *
from direct.distributed.ClockDelta import *
from direct.task.Task import Task
@ -8,9 +7,7 @@ from direct.gui.DirectGui import *
from toontown.toonbase import TTLocalizer
from direct.distributed import DistributedNode
from direct.distributed.ClockDelta import globalClockDelta
from toontown.distributed.DelayDelete import *
from ChineseCheckersBoard import ChineseCheckersBoard
from GameGlobals import *
from GameTutorials import *
from GameMenu import GameMenu
from direct.fsm import ClassicFSM, State
@ -20,9 +17,6 @@ from toontown.toonbase.ToontownTimer import ToontownTimer
from toontown.toonbase import ToontownGlobals
from direct.showbase import PythonUtil
from otp.otpbase import OTPGlobals
from toontown.chat.WhisperPopup import WhisperPopup
import random
class DistributedPicnicTable(DistributedNode.DistributedNode):
@ -31,7 +25,8 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
NodePath.__init__(self, 'DistributedPicnicTable')
DistributedNode.DistributedNode.__init__(self, cr)
self.reparentTo(render)
self.picnicTable = None
self.picnicTable = loader.loadModel('phase_6/models/golf/game_table.bam')
self.picnicTable.reparentTo(self)
self.picnicTableSphereNodes = []
self.numSeats = 6
self.seats = []
@ -72,12 +67,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
State.State('sitting', self.enterSitting, self.exitSitting, ['off']),
State.State('observing', self.enterObserving, self.exitObserving, ['off'])], 'off', 'off')
self.fsm.enterInitialState()
def setTableIndex(self, index):
self.picnicTable = render.find('**/game_table_%d' % index)
def announceGenerate(self):
for i in range(self.numSeats):
for i in xrange(self.numSeats):
self.seats.append(self.picnicTable.find('**/*seat%d' % (i + 1)))
self.jumpOffsets.append(self.picnicTable.find('**/*jumpOut%d' % (i + 1)))
@ -88,9 +78,11 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.clockNode.setPos(1.16, 0, -0.83)
self.clockNode.setScale(0.3)
self.clockNode.hide()
return
def announceGenerate(self):
DistributedNode.DistributedNode.announceGenerate(self)
for i in range(self.numSeats):
for i in xrange(self.numSeats):
self.picnicTableSphereNodes.append(self.seats[i].attachNewNode(CollisionNode('picnicTable_sphere_%d_%d' % (self.getDoId(), i))))
self.picnicTableSphereNodes[i].node().addSolid(CollisionSphere(0, 0, 0, 2))
@ -185,14 +177,14 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
def setTableState(self, tableStateList, isplaying):
y = 0
print 'SET TABLE STATE', tableStateList, isplaying
print 'SET TABLE STATE'
if isplaying == 0:
self.isPlaying = False
else:
self.isPlaying = True
for x in tableStateList:
if x != 0:
if x not in self.tableState and self.cr.doId2do.has_key(x) and x not in self.haveAnimated:
if x not in self.tableState and x in self.cr.doId2do and x not in self.haveAnimated:
seatIndex = tableStateList.index(x)
toon = self.cr.doId2do[x]
toon.stopSmooth()
@ -220,17 +212,17 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
if x != None:
numPlayers += 1
#print ' GETTING 2', self.gameMenu, numPlayers
print ' GETTING 2', self.gameMenu, numPlayers
if self.gameMenu:
if numPlayers <= 2:
#print ' GETTING HERE!!'
#self.gameMenu.FindFour.setColor(0.7, 0.7, 0.7, 0.7)
#self.gameMenu.FindFour['command'] = self.doNothing
#self.gameMenu.findFourText['fg'] = (0.7, 0.7, 0.7, 0.7)
#self.gameMenu.Checkers.setColor(0.7, 0.7, 0.7, 0.7)
#self.gameMenu.Checkers['command'] = self.doNothing
#self.gameMenu.checkersText['fg'] = (0.7, 0.7, 0.7, 0.7)
return
if numPlayers > 2:
print ' GETTING HERE!!'
self.gameMenu.FindFour.setColor(0.7, 0.7, 0.7, 0.7)
self.gameMenu.FindFour['command'] = self.doNothing
self.gameMenu.findFourText['fg'] = (0.7, 0.7, 0.7, 0.7)
self.gameMenu.Checkers.setColor(0.7, 0.7, 0.7, 0.7)
self.gameMenu.Checkers['command'] = self.doNothing
self.gameMenu.checkersText['fg'] = (0.7, 0.7, 0.7, 0.7)
return
def setIsPlaying(self, isPlaying):
if isPlaying == 0:
@ -248,8 +240,8 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
elif winString == 'Checkers':
whisper = WhisperPopup(TTLocalizer.RegularCheckersYouWon, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif winString == 'Find Four':
whisper = WhisperPopup(TTLocalizer.FindFourYouWon, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif self.cr.doId2do.has_key(avId):
whisper = WhisperPopup('You won a game of Find Four!', OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif avId in self.cr.doId2do:
stateString = self.fsm.getCurrentState().getName()
if stateString == 'sitting' or stateString == 'observing':
base.cr.playGame.getPlace().setState('walk')
@ -259,8 +251,8 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
elif winString == 'Checkers':
whisper = WhisperPopup(av.getName() + TTLocalizer.RegularCheckersGameOf + TTLocalizer.RegularCheckers, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
elif winString == 'Find Four':
whisper = WhisperPopup(av.getName() + TTLocalizer.FindFourGameOf + TTLocalizer.FindFour, OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
if self.cr.doId2do.has_key(avId):
whisper = WhisperPopup(av.getName() + ' has won a game of' + ' Find Four!', OTPGlobals.getInterfaceFont(), WhisperPopup.WTNormal)
if avId in self.cr.doId2do:
toon = self.cr.doId2do[avId]
self.winTrack = Sequence(autoFinish=1)
if self.outTrack.isPlaying():
@ -280,74 +272,73 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.fsm.request('chooseMode')
def enableChoiceButtons(self):
if (not self.game) or (not self.game.playing):
if self.tableState[self.seatBumpForObserve] == None and self.isPlaying == False:
self.joinButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableJoinButton,
text_fg=(1, 1, 0.65, 1),
text_pos=(0, -0.23),
text_pos=(0, -.23),
text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(0, 0, 0.8),
scale=0.15,
command=self.joinButtonPushed)
else:
command=lambda self = self: self.joinButtonPushed())
if self.isPlaying == True:
self.observeButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableObserveButton,
text_fg=(1, 1, 0.65, 1),
text_pos=(0, -0.23),
text_pos=(0, -.23),
text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(0, 0, 0.6),
scale=0.15,
command=self.observeButtonPushed)
command=lambda self = self: self.observeButtonPushed())
self.exitButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableCancelButton,
text_fg=(1, 1, 0.65, 1),
text_pos=(0, -0.23),
text_pos=(0, -.23),
text_scale=0.8,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(1, 0, 0.6),
scale=0.15,
command=self.cancelButtonPushed)
command=lambda self = self: self.cancelButtonPushed())
self.tutorialButton = DirectButton(
relief=None,
text=TTLocalizer.PicnicTableTutorial,
text_fg=(1, 1, 0.65, 1),
text_pos=(-0.05, -0.13),
text_pos=(-.05, -.13),
text_scale=0.55,
image=(self.upButton, self.downButton, self.rolloverButton),
image_color=(1, 0, 0, 1),
image_scale=(20, 1, 11),
pos=(-1, 0, 0.6),
scale=0.15,
command=self.tutorialButtonPushed)
command=lambda self = self: self.tutorialButtonPushed())
base.cr.playGame.getPlace().setState('stopped')
return
def tutorialButtonPushed(self):
self.disableChoiceButtons()
self.gameMenu = GameMenu(self.tutorialFunction, GameGlobals.TutorialMenu)
self.gameMenu = GameMenu(self.tutorialFunction, 1)
self.tutorialButton.destroy()
self.tutorialButton = None
return
def tutorialFunction(self, tutVal):
if tutVal == GameGlobals.CheckersGameIndex:
self.tutorial = CheckersTutorial(self.tutorialDone)
elif tutVal == GameGlobals.ChineseCheckersGameIndex:
if tutVal == 1:
self.tutorial = ChineseTutorial(self.tutorialDone)
elif tutVal == GameGlobals.FindFourGameIndex:
self.tutorial = FindFourTutorial(self.tutorialDone)
else:
self.cancelButtonPushed()
self.destroyGameMenu()
elif tutVal == 2:
self.tutorial = CheckersTutorial(self.tutorialDone)
self.gameMenu.picnicFunction = None
self.gameMenu = None
return
def tutorialDone(self):
@ -382,16 +373,12 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
def disableChoiceButtons(self):
if self.joinButton:
self.joinButton.destroy()
self.joinButton = None
if self.observeButton:
self.observeButton.destroy()
self.observeButton = None
if self.exitButton:
self.exitButton.destroy()
self.exitButton = None
if self.tutorialButton:
self.tutorialButton.destroy()
self.tutorialButton = None
def pickFunction(self, gameNum):
if gameNum == 1:
@ -400,17 +387,11 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.sendUpdate('requestPickedGame', [gameNum])
elif gameNum == 3:
self.sendUpdate('requestPickedGame', [gameNum])
elif gameNum == -1:
self.gameMenu.removeButtons()
self.gameMenu.picnicFunction = None
self.gameMenu = None
self.sendUpdate('requestExit', [])
def allowPick(self):
self.gameMenu = GameMenu(self.pickFunction, 2)
def setZone(self, zoneId):
print 'setZone', zoneId, self.fsm.getCurrentState().getName()
if self.fsm.getCurrentState().getName() == 'sitting' or self.fsm.getCurrentState().getName() == 'observing':
if self.tutorial == None:
self.gameZone = base.cr.addInterest(base.localAvatar.defaultShard, zoneId, 'gameBoard')
@ -430,7 +411,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
else:
self.inGame = True
self.seatPos = index
if self.cr.doId2do.has_key(avId):
if avId in self.cr.doId2do:
toon = self.cr.doId2do[avId]
toon.stopSmooth()
toon.wrtReparentTo(self.tableCloth)
@ -455,7 +436,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
return
if avId in self.haveAnimated:
self.haveAnimated.remove(avId)
if self.cr.doId2do.has_key(avId):
if avId in self.cr.doId2do:
if avId == base.localAvatar.getDoId():
if self.gameZone:
base.cr.removeInterest(self.gameZone)
@ -470,12 +451,13 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
self.outTrack = Sequence(jumpOutTrack)
if base.localAvatar.getDoId() == avId:
self.outTrack.append(Func(self.__enableCollisions))
self.outTrack.append(Func(self.allowToWalk))
self.outTrack.append(Func(self.allowToWalk))
self.fsm.request('off')
val = self.jumpOffsets[index].getPos(render)
self.outTrack.append(Func(toon.setPos, val))
self.outTrack.append(Func(toon.startSmooth))
self.outTrack.append(Func(toon.startSmooth))
self.outTrack.start()
return
def stopToWalk(self):
base.cr.playGame.getPlace().setState('stopped')
@ -484,37 +466,44 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
base.cr.playGame.getPlace().setState('walk')
def moveCamera(self, seatIndex):
localAvatar.stopUpdateSmartCamera()
camera.reparentTo(self)
camera.iPosHpr()
camera.setZ(17)
camera.setP(-90)
self.oldCameraPos = camera.getPos()
self.oldCameraHpr = camera.getHpr()
camera.wrtReparentTo(self.picnicTable)
heading = PythonUtil.fitDestAngle2Src(camera.getH(), 90)
if seatIndex < 3:
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.0, Point3(0, 0, 17), Point3(0, -90, 0))
elif camera.getH() < 0:
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.0, Point3(0, 0, 17), Point3(-180, -90, 0))
else:
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.0, Point3(0, 0, 17), Point3(180, -90, 0))
self.cameraBoardTrack.start()
def moveCameraBack(self):
localAvatar.startUpdateSmartCamera()
self.cameraBoardTrack = LerpPosHprInterval(camera, 2.5, self.oldCameraPos, self.oldCameraHpr)
self.cameraBoardTrack.start()
def __enableCollisions(self):
for i in range(self.numSeats):
for i in xrange(self.numSeats):
self.accept('enterpicnicTable_sphere_%d_%d' % (self.getDoId(), i), self.handleEnterPicnicTableSphere, [i])
self.picnicTableSphereNodes[i].setCollideMask(ToontownGlobals.WallBitmask)
self.tableclothSphereNode.setCollideMask(ToontownGlobals.WallBitmask)
def __disableCollisions(self):
for i in range(self.numSeats):
for i in xrange(self.numSeats):
self.ignore('enterpicnicTable_sphere_%d_%d' % (self.getDoId(), i))
self.ignore('enterPicnicTableOK_%d_%d' % (self.getDoId(), i))
for i in range(self.numSeats):
for i in xrange(self.numSeats):
self.picnicTableSphereNodes[i].setCollideMask(BitMask32(0))
self.tableclothSphereNode.setCollideMask(BitMask32(0))
def enterOff(self):
base.setCellsAvailable(base.leftCells + base.bottomCells, 0)
base.setCellsActive(base.leftCells + base.bottomCells, 0)
def exitOff(self):
base.setCellsAvailable(base.bottomCells, 0)
base.setCellsActive(base.bottomCells, 0)
def enterChooseMode(self):
self.winTrack = Sequence(autoFinish=1)
@ -538,13 +527,8 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
pass
def exitSitting(self):
self.destroyGameMenu()
def destroyGameMenu(self):
if self.gameMenu:
self.gameMenu.removeButtons()
self.gameMenu.picnicFunction = None
self.gameMenu = None
self.gameMenu = None
return
def setGameZone(self, zoneId, gamestate):
self.gameZone = base.cr.addInterest(base.localAvatar.defaultShard, zoneId, 'gameBoard')
@ -567,7 +551,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
image_scale=(20, 1, 11),
pos=(0.92, 0, 0.4),
scale=0.15,
command=self.stopObserveButtonPushed)
command=lambda self = self: self.stopObserveButtonPushed())
return
def stopObserveButtonPushed(self):
@ -660,7 +644,7 @@ class DistributedPicnicTable(DistributedNode.DistributedNode):
keyList.append(key)
for key in keyList:
if self.__toonTracks.has_key(key):
if key in self.__toonTracks:
self.clearToonTrack(key)
def doNothing(self):