ToontownTimer callback support

This commit is contained in:
John 2015-06-30 20:11:20 +03:00
parent 4990317c41
commit 6bb4ea0dbe

View file

@ -80,15 +80,16 @@ class ToontownTimer(DirectFrame):
if task.time >= task.duration: if task.time >= task.duration:
self.timerExpired() self.timerExpired()
if task.callback: if task.callback:
task.callback() task.callback(*task.extraArgs)
return Task.done return Task.done
else: else:
return Task.cont return Task.cont
def countdown(self, duration, callback = None): def countdown(self, duration, callback = None, extraArgs = []):
self.countdownTask = Task.Task(self._timerTask) self.countdownTask = Task.Task(self._timerTask)
self.countdownTask.duration = duration self.countdownTask.duration = duration
self.countdownTask.callback = callback self.countdownTask.callback = callback
self.countdownTask.extraArgs = extraArgs
taskMgr.remove('timerTask%s' % self.timerId) taskMgr.remove('timerTask%s' % self.timerId)
return taskMgr.add(self.countdownTask, 'timerTask%s' % self.timerId) return taskMgr.add(self.countdownTask, 'timerTask%s' % self.timerId)
@ -113,4 +114,4 @@ class ToontownTimer(DirectFrame):
def cleanup(self): def cleanup(self):
self.destroy() self.destroy()
self.notify.warning('Call destroy, not cleanup') self.notify.warning('Call destroy, not cleanup')