Source code for yyagl.engine.pause

from direct.gui.DirectFrame import DirectFrame
from yyagl.gameobject import GuiColleague, LogicColleague, GameObject, Colleague
from yyagl.lib.p3d.pause import P3dPause
LibPause = P3dPause


[docs]class PauseGui(GuiColleague): def __init__(self, mediator): GuiColleague.__init__(self, mediator) self.pause_frm = None
[docs] def toggle(self, show_frm=True): if not self.mediator.logic._pause.paused: if show_frm: self.pause_frm = DirectFrame(frameColor=(.3, .3, .3, .7), frameSize=(-1.8, 1.8, -1, 1)) else: if self.pause_frm: self.pause_frm.destroy()
[docs] def destroy(self): if self.pause_frm: self.pause_frm = self.pause_frm.destroy() GuiColleague.destroy(self)
[docs]class PauseLogic(LogicColleague): def __init__(self, mediator): LogicColleague.__init__(self, mediator) self._pause = LibPause()
[docs] def remove_task(self, tsk): self._pause.remove_task(tsk)
[docs] def pause(self): self.notify('on_pause') return self._pause.pause()
[docs] def resume(self): self.notify('on_resume') return self._pause.resume()
[docs] def toggle(self, show_frm=True): self.mediator.gui.toggle(show_frm) (self.resume if self._pause.paused else self.pause)()
[docs] def destroy(self): self._pause.destroy() LogicColleague.destroy(self)
[docs]class PauseFacade: @property def paused(self): return self.logic._pause.paused
[docs]class PauseMgr(GameObject, Colleague, PauseFacade): def __init__(self, mediator): GameObject.__init__(self) Colleague.__init__(self, mediator) self.gui = PauseGui(self) self.logic = PauseLogic(self)
[docs] def remove_task(self, tsk): return self.logic.remove_task(tsk)
[docs] def destroy(self): self.gui = self.gui.destroy() self.logic = self.logic.destroy() GameObject.destroy(self) Colleague.destroy(self)