def show_ticker_scene(self, new_ticker=False): """ Replace everything on screen with the scene displaying the drink ticker. If the engine is not yet running, this method will start a new engine and will block until the engine has stopped. """ # Instantiate objects if not self._ticker_layer or new_ticker: self._ticker_layer = BottomTicker(screen_width=self._width) if not self._center_display_controller: self._center_display_controller = CenterDisplayController() if not self._title_layer: self._title_layer = TitleLayer() # Glue everything together self._ticker_layer.update_drinks(self._drinks) self._ticker_layer.on_focused_drink_changed += self._center_display_controller.drink_focused_changed # Show the scene scene = cocos.scene.Scene(self._ticker_layer, self._center_display_controller.get_layer(), self._title_layer) self._display_scene(scene)
class CocosGui(object): """ Main object containing the Cocos2D GUI. Initialize and start this object to start a show. """ def __init__(self, hostname=None, port=1234, width=1024, height=768, fullscreen=True): """ Set up all parameters and objects for the GUI. """ self._width = width self._height = height self._fullscreen = fullscreen self._hostname = hostname self._port = port self._refresh_ticker_on_update = True self._ticker_layer = None self._center_display_controller = None self._title_layer = None self._mix_layer = None self._connector = None self._drinks = None def start(self): """ Start running the Cocos GUI. This method will block until the GUI has been shut down. After returning there might still be some processes cleaning up. """ print("Starting Cocos GUI") print("\nUsing following settings:") print("\tConnection: %s:%d" % (self._hostname, self._port)) print("\tGraphics: (%d, %d) fullscreen=%s" %(self._width, self._height, self._fullscreen)) print() print("Loaded libraries:") print("\tPyglet:\t%s" % pyglet.version) print("\tCocos:\t%s" % cocos.version) import twisted print("\tTwisted:%s" % twisted.version.short()) print() print("Opening connection to server...") self._connector = ClientConnector(self._hostname, self._port) self._connector.start() self._drinks = self._connector.database.get_drinks() random.shuffle(self._drinks) self._connector.database.on_drinks_updated += self._update_drinks self._connector.stock_exchange.on_next_round += self._next_round print() print("Initializing graphics...") cocos.director.director.init(width=self._width, height=self._height, fullscreen=self._fullscreen) cocos.director.director.set_show_FPS(debug_mode) self.show_gl_info() print() print("Starting the show!") self.show_ticker_scene() print() print("Shut down in progress...") print() self._center_display_controller.stop() self._connector.stop() @staticmethod def show_gl_info(): """ Display some information about the GL renderer. """ from pyglet.gl.gl_info import GLInfo info = GLInfo() info.set_active_context() print("GL Info:") print("\tVersion:\t%s" % info.get_version()) print("\tRenderer:\t%s" % info.get_renderer()) print("\tVendor:\t\t%s" % info.get_vendor()) print("\tExtensions:\t%s" % info.get_extensions()) from pyglet.gl.glu_info import GLUInfo info = GLUInfo() info.set_active_context() print() print("GLU Info:") print("\tVersion:\t%s" % info.get_version()) print("\tExtensions:\t%s" % info.get_extensions()) def show_ticker_scene(self, new_ticker=False): """ Replace everything on screen with the scene displaying the drink ticker. If the engine is not yet running, this method will start a new engine and will block until the engine has stopped. """ # Instantiate objects if not self._ticker_layer or new_ticker: self._ticker_layer = BottomTicker(screen_width=self._width) if not self._center_display_controller: self._center_display_controller = CenterDisplayController() if not self._title_layer: self._title_layer = TitleLayer() # Glue everything together self._ticker_layer.update_drinks(self._drinks) self._ticker_layer.on_focused_drink_changed += self._center_display_controller.drink_focused_changed # Show the scene scene = cocos.scene.Scene(self._ticker_layer, self._center_display_controller.get_layer(), self._title_layer) self._display_scene(scene) @staticmethod def _display_scene(scene): """ Change the display to show the given scene. If no engine is running yet, an engine will be started. In that case this method will not return until the engine has stopped again. """ if cocos.director.director.scene is None: cocos.director.director.run(scene) else: cocos.director.director.replace(cocos.scenes.transitions.FadeTransition(scene)) def _update_drinks(self, drinks): random.shuffle(drinks) self._drinks = drinks if self._ticker_layer: self._ticker_layer.update_drinks(drinks) if self._center_display_controller: self._center_display_controller.update_drinks(drinks) def _next_round(self): pass
class CocosGui(object): """ Main object containing the Cocos2D GUI. Initialize and start this object to start a show. """ def __init__(self, hostname=None, port=1234, width=1024, height=768, fullscreen=True): """ Set up all parameters and objects for the GUI. """ self._width = width self._height = height self._fullscreen = fullscreen self._hostname = hostname self._port = port self._refresh_ticker_on_update = True self._ticker_layer = None self._center_display_controller = None self._title_layer = None self._mix_layer = None self._connector = None self._drinks = None def start(self): """ Start running the Cocos GUI. This method will block until the GUI has been shut down. After returning there might still be some processes cleaning up. """ print("Starting Cocos GUI") print("\nUsing following settings:") print("\tConnection: %s:%d" % (self._hostname, self._port)) print("\tGraphics: (%d, %d) fullscreen=%s" % (self._width, self._height, self._fullscreen)) print() print("Loaded libraries:") print("\tPyglet:\t%s" % pyglet.version) print("\tCocos:\t%s" % cocos.version) import twisted print("\tTwisted:%s" % twisted.version.short()) print() print("Opening connection to server...") self._connector = ClientConnector(self._hostname, self._port) self._connector.start() self._drinks = self._connector.database.get_drinks() random.shuffle(self._drinks) self._connector.database.on_drinks_updated += self._update_drinks self._connector.stock_exchange.on_next_round += self._next_round print() print("Initializing graphics...") cocos.director.director.init(width=self._width, height=self._height, fullscreen=self._fullscreen) cocos.director.director.set_show_FPS(debug_mode) self.show_gl_info() print() print("Starting the show!") self.show_ticker_scene() print() print("Shut down in progress...") print() self._center_display_controller.stop() self._connector.stop() @staticmethod def show_gl_info(): """ Display some information about the GL renderer. """ from pyglet.gl.gl_info import GLInfo info = GLInfo() info.set_active_context() print("GL Info:") print("\tVersion:\t%s" % info.get_version()) print("\tRenderer:\t%s" % info.get_renderer()) print("\tVendor:\t\t%s" % info.get_vendor()) print("\tExtensions:\t%s" % info.get_extensions()) from pyglet.gl.glu_info import GLUInfo info = GLUInfo() info.set_active_context() print() print("GLU Info:") print("\tVersion:\t%s" % info.get_version()) print("\tExtensions:\t%s" % info.get_extensions()) def show_ticker_scene(self, new_ticker=False): """ Replace everything on screen with the scene displaying the drink ticker. If the engine is not yet running, this method will start a new engine and will block until the engine has stopped. """ # Instantiate objects if not self._ticker_layer or new_ticker: self._ticker_layer = BottomTicker(screen_width=self._width) if not self._center_display_controller: self._center_display_controller = CenterDisplayController() if not self._title_layer: self._title_layer = TitleLayer() # Glue everything together self._ticker_layer.update_drinks(self._drinks) self._ticker_layer.on_focused_drink_changed += self._center_display_controller.drink_focused_changed # Show the scene scene = cocos.scene.Scene(self._ticker_layer, self._center_display_controller.get_layer(), self._title_layer) self._display_scene(scene) @staticmethod def _display_scene(scene): """ Change the display to show the given scene. If no engine is running yet, an engine will be started. In that case this method will not return until the engine has stopped again. """ if cocos.director.director.scene is None: cocos.director.director.run(scene) else: cocos.director.director.replace( cocos.scenes.transitions.FadeTransition(scene)) def _update_drinks(self, drinks): random.shuffle(drinks) self._drinks = drinks if self._ticker_layer: self._ticker_layer.update_drinks(drinks) if self._center_display_controller: self._center_display_controller.update_drinks(drinks) def _next_round(self): pass