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