From 9db517cfb39e62933f65133ad4f4abac870d5bfe Mon Sep 17 00:00:00 2001 From: John Date: Sat, 6 Jun 2015 17:12:47 +0300 Subject: [PATCH] DANIEL: Cycle through races shit --- dependencies/astron/dclass/stride.dc | 7 +++- toontown/hood/GSHoodAI.py | 15 +++---- toontown/racing/DistributedLeaderBoard.py | 14 ++++--- toontown/racing/DistributedLeaderBoardAI.py | 45 +++++++++++++++------ toontown/toonbase/TTLocalizerEnglish.py | 6 +++ 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/dependencies/astron/dclass/stride.dc b/dependencies/astron/dclass/stride.dc index e26ff2bc..9319e513 100644 --- a/dependencies/astron/dclass/stride.dc +++ b/dependencies/astron/dclass/stride.dc @@ -2623,9 +2623,14 @@ dclass DistributedStartingBlock : DistributedObject { dclass DistributedViewingBlock : DistributedStartingBlock { }; +struct LeaderboardResult { + string name; + uint32 time; +}; + dclass DistributedLeaderBoard : DistributedObject { setPosHpr(int16/10, int16/10, int16/10, int16/10, int16/10, int16/10) required broadcast ram; - setDisplay(blob) broadcast ram; + setDisplay(uint8, uint8, LeaderboardResult[]) required broadcast ram; }; dclass DistributedLawbotBoss : DistributedBossCog { diff --git a/toontown/hood/GSHoodAI.py b/toontown/hood/GSHoodAI.py index 19b28c6b..672c75fd 100755 --- a/toontown/hood/GSHoodAI.py +++ b/toontown/hood/GSHoodAI.py @@ -133,10 +133,11 @@ class GSHoodAI(HoodAI.HoodAI): hpr = childDnaGroup.getHpr() nameInfo = childDnaGroup.getName().split('_') - leaderBoard = DistributedLeaderBoardAI(simbase.air, nameInfo[1]) - leaderBoard.setPosHpr(pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]) - leaderBoard.generateWithRequired(zoneId) - leaderBoards.append(leaderBoard) + if nameInfo[1] in RaceGlobals.LBSubscription: + leaderBoard = DistributedLeaderBoardAI(simbase.air, RaceGlobals.LBSubscription[nameInfo[1]]) + leaderBoard.setPosHpr(pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]) + leaderBoard.generateWithRequired(zoneId) + leaderBoards.append(leaderBoard) elif isinstance(dnaGroup, DNAVisGroup): zoneId = int(dnaGroup.getName().split(':')[0]) @@ -151,12 +152,6 @@ class GSHoodAI(HoodAI.HoodAI): dnaData = self.air.dnaDataMap[self.zoneId] if dnaData.getName() == 'root': self.leaderBoards = self.findLeaderBoards(dnaData, self.zoneId) - for leaderBoard in self.leaderBoards: - if not leaderBoard: - continue - leaderBoardType = leaderBoard.getName() - for subscription in RaceGlobals.LBSubscription[leaderBoardType]: - leaderBoard.subscribeTo(subscription) def __cycleLeaderBoards(self, task = None): messenger.send('GS_LeaderBoardSwap' + str(self.zoneId)) diff --git a/toontown/racing/DistributedLeaderBoard.py b/toontown/racing/DistributedLeaderBoard.py index 535f6127..a03483af 100755 --- a/toontown/racing/DistributedLeaderBoard.py +++ b/toontown/racing/DistributedLeaderBoard.py @@ -5,7 +5,6 @@ from toontown.racing import KartShopGlobals from toontown.toonbase import TTLocalizer from toontown.toonbase.ToonBaseGlobal import * from toontown.toonbase.ToontownGlobals import * -import cPickle class DistributedLeaderBoard(DistributedObject.DistributedObject): notify = DirectNotifyGlobal.directNotify.newCategory('DisributedLeaderBoard') @@ -35,10 +34,13 @@ class DistributedLeaderBoard(DistributedObject.DistributedObject): def setPosHpr(self, x, y, z, h, p, r): self.surface.setPosHpr(x, y, z, h, p, r) - def setDisplay(self, pData): - self.notify.debug('setDisplay: changing leaderboard text on local side') - trackName, recordTitle, scores = cPickle.loads(pData) - self.display(trackName, recordTitle, scores) + def setDisplay(self, track, type, results): + if not track in TTLocalizer.KartRace_TrackNames or len(TTLocalizer.RecordPeriodStrings) <= type: + return + + trackName = TTLocalizer.KartRace_TrackNames[track] + recordTitle = TTLocalizer.RecordPeriodStrings[type] + self.display(trackName, recordTitle, results) def buildListParts(self): self.surface = self.board.attachNewNode('surface') @@ -78,7 +80,7 @@ class DistributedLeaderBoard(DistributedObject.DistributedObject): self.trackNameNode.setText(pTrackTitle) self.updateCount += 1 for i in xrange(10): - if i > len(pLeaderList): + if i >= len(pLeaderList): self.nameTextNodes[i].setText('-') self.timeTextNodes[i].setText('-') else: diff --git a/toontown/racing/DistributedLeaderBoardAI.py b/toontown/racing/DistributedLeaderBoardAI.py index 875acf7c..669a825b 100755 --- a/toontown/racing/DistributedLeaderBoardAI.py +++ b/toontown/racing/DistributedLeaderBoardAI.py @@ -1,28 +1,47 @@ from direct.directnotify import DirectNotifyGlobal +from direct.task import Task from direct.distributed.DistributedObjectAI import DistributedObjectAI +import random class DistributedLeaderBoardAI(DistributedObjectAI): notify = DirectNotifyGlobal.directNotify.newCategory("DistributedLeaderBoardAI") - def __init__(self, air, name): + def __init__(self, air, displays): DistributedObjectAI.__init__(self, air) + self.displays = displays + self.display = (0, 0, []) self.posHpr = (0, 0, 0, 0, 0, 0) - self.name = name + + def generateWithRequired(self, zoneId): + DistributedObjectAI.generateWithRequired(self, zoneId) + self.setup() + + def delete(self): + DistributedObjectAI.delete(self) + taskMgr.remove(self.switchTask) + + def setup(self): + self.currentId = 0 + self.switchDisplay() + self.switchTask = taskMgr.doMethodLater(15, self.switchDisplay, 'leaderboardSwitchTask-%s' % random.random()) + + def switchDisplay(self, task=None): + race = self.displays[self.currentId] + + self.display = (race[0], race[1], []) + self.currentId += 1 + + if self.currentId >= len(self.displays): + self.currentId = 0 + + self.sendUpdate('setDisplay', [self.display[0], self.display[1], self.display[2]]) + return Task.again def setPosHpr(self, x, y, z, h, p, r): self.posHpr = (x, y, z, h, p, r) def getPosHpr(self): return self.posHpr - - def setName(self, name): - self.name = name - - def getName(self): - return self.name - - def setDisplay(self, todo0): - pass - def subscribeTo(self, todo0): - print 'subscribed to %s' % (todo0,) \ No newline at end of file + def getDisplay(self): + return self.display \ No newline at end of file diff --git a/toontown/toonbase/TTLocalizerEnglish.py b/toontown/toonbase/TTLocalizerEnglish.py index c0d53b45..db3c6aea 100755 --- a/toontown/toonbase/TTLocalizerEnglish.py +++ b/toontown/toonbase/TTLocalizerEnglish.py @@ -8467,3 +8467,9 @@ TrueFriendsNotFriends = 'You cannot be True Friends with %s until you are regula TrueFriendsAddNotice = 'If you are playing Toontown with someone you trust, you can become True Friends.\n\nYou can chat using the keyboard with your True Friends.\n\nOther Toons won\'t understand what you\'re saying.\n\n\x01WLRed\x01However, this chat is completely unfiltered.\x02\n\nAre you sure you want to be True Friends with %s?' TrueFriendsAdded = 'You are now True Friends with %s!\n\nYou can now understand everything %s says.\n\nHowever, chances are %s hasn\'t added you as a True Friend yet.\n\nIf this is the case, he cannot understand you yet. Please ask %s to add you as a True Friend aswell!' TrueFriendsRemoved = 'You are no longer True Friends with %s.' + +def convertSecondsToDate(seconds): + m, s = divmod(seconds, 60) + h, m = divmod(m, 60) + + print '%d:%02d:%02d' % (h, m, s)