def addedToWorld(self, world): """Added to the world""" super(MusicGrid, self).addedToWorld(world) # # Set up the grid to show the state self.layout = serge.blocks.utils.addActorToWorld( world, serge.blocks.layout.Grid( 'grid', 'grid', self.size, G('grid-width'), G('grid-height'), background_colour=G('grid-background-colour'), background_layer='background', ), layer_name='main', center_position=G('grid-position'), ) # # Add actors for ix in range(self.size[0]): for iy in range(self.size[1]): actor = serge.actor.Actor('cell', 'cell-%d-%d' % (ix, iy)) actor.setSpriteName('null') actor.setLayerName('main') actor.linkEvent(serge.events.E_LEFT_CLICK, self.cellClick, (ix, iy)) self.layout.addActor((ix, iy), actor) # world.addActor(self.automaton)
def addActor(self, actor, start=None, stop=None): """Add an actor to be controlled and callback to be called when dragging start and stops""" if actor in self.draggables: raise DuplicateActor('The actor %s is already controlled by %s' % (actor.getNiceName(), self.getNiceName())) self.draggables.append(actor) actor.linkEvent(serge.events.E_LEFT_MOUSE_DOWN, self.mouseDown, (actor, start)) actor.linkEvent(serge.events.E_LEFT_CLICK, self.clickedActor, (actor, stop))
def __init__(self, tag, name, items, layout, callback, background_colour=(0, 0, 0), font_colour=(255, 255, 255), font_size=12, font_name='DEFAULT'): """Initialise the menu""" super(FullScreenMenu, self).__init__(tag, name) # self.background_colour = background_colour self.font_colour = font_colour self.font_size = font_size self.font_name = font_name self.layout = layout self.items = items self.callback = callback # sx, sy = serge.engine.CurrentEngine().getRenderer().getScreenSize() self.moveTo(sx / 2, sy / 2) # # Background self.bg = self.mountActor(serge.actor.Actor('menu', 'bg'), (0, 0)) self.bg.visual = serge.blocks.visualblocks.Rectangle( (sx, sy), self.background_colour ) self.bg.linkEvent(serge.events.E_LEFT_CLICK, lambda o, a: serge.events.E_LEFT_CLICK) # # Layout self.mountActor(self.layout, (0, 0)) # # Options for idx, item in enumerate(self.items): actor = self.layout.addActor(StringText( 'menu', 'item-%d' % idx, item, colour=self.font_colour, font_name=self.font_name, font_size=self.font_size )) actor.linkEvent(serge.events.E_LEFT_CLICK, self.menuClick, item)
def addTextItemsToWorld(world, items, theme, layer_name): """Add multiple text items to the world""" for item in items: text, name = item[0:2] callback = None if len(item) == 2 else item[2] actor = addTextToWorld(world, text, name, theme, layer_name) if callback: actor.linkEvent(serge.events.E_LEFT_CLICK, callback)
def assignBehaviour(self, actor, behaviour, name): """Assign a behaviour to an actor""" record = BehaviourRecord(actor, behaviour, name) if record._getId() in self._behaviours: raise DuplicateBehaviour('The behaviour %s,%s was already recorded' % (actor, behaviour)) nice_name = 'the game' if actor is None else actor.getNiceName() self.log.debug('Assigned behaviour %s to %s' % (behaviour, nice_name)) self._behaviours[record._getId()] = record if actor: actor.linkEvent(serge.events.E_REMOVED_FROM_WORLD, self._actorRemoved) return record
def assignBehaviour(self, actor, behaviour, name): """Assign a behaviour to an actor""" record = BehaviourRecord(actor, behaviour, name) if record._getId() in self._behaviours: raise DuplicateBehaviour( 'The behaviour %s,%s was already recorded' % (actor, behaviour)) nice_name = 'the game' if actor is None else actor.getNiceName() self.log.debug('Assigned behaviour %s to %s' % (behaviour, nice_name)) self._behaviours[record._getId()] = record if actor: actor.linkEvent(serge.events.E_REMOVED_FROM_WORLD, self._actorRemoved) return record
def addActor(self, actor, start=None, stop=None, x_constraint=None, y_constraint=None): """Add an actor to be controlled and callback to be called when dragging start and stops""" # # Reality checks if actor in self.draggables: raise DuplicateActor('The actor %s is already controlled by %s' % (actor.getNiceName(), self.getNiceName())) if x_constraint is not None and not isinstance(x_constraint, tuple): raise BadConstraint('The x_constraint was not a tuple') if y_constraint is not None and not isinstance(y_constraint, tuple): raise BadConstraint('The y_constraint was not a tuple') # # Add the draggable self.draggables[actor] = DragItem(actor, start, stop, x_constraint, y_constraint) actor.linkEvent(serge.events.E_LEFT_MOUSE_DOWN, self.mouseDown, (actor, start)) actor.linkEvent(serge.events.E_LEFT_CLICK, self.clickedActor, (actor, stop))
def __init__(self, tag, name, items, layout, callback, background_colour=(0, 0, 0), font_colour=(255, 255, 255), font_size=12, font_name='DEFAULT'): """Initialise the menu""" super(FullScreenMenu, self).__init__(tag, name) # self.background_colour = background_colour self.font_colour = font_colour self.font_size = font_size self.font_name = font_name self.layout = layout self.items = items self.callback = callback # sx, sy = serge.engine.CurrentEngine().getRenderer().getScreenSize() self.moveTo(sx / 2, sy / 2) # # Background self.bg = self.mountActor(serge.actor.Actor('menu', 'bg'), (0, 0)) self.bg.visual = serge.blocks.visualblocks.Rectangle( (sx, sy), self.background_colour) self.bg.linkEvent(serge.events.E_LEFT_CLICK, lambda o, a: serge.events.E_LEFT_CLICK) # # Layout self.mountActor(self.layout, (0, 0)) # # Options for idx, item in enumerate(self.items): actor = self.layout.addActor( StringText('menu', 'item-%d' % idx, item, colour=self.font_colour, font_name=self.font_name, font_size=self.font_size)) actor.linkEvent(serge.events.E_LEFT_CLICK, self.menuClick, item)
def addChild(self, actor): """Add an actor to the manager""" super(FocusManager, self).addChild(actor) # actor.linkEvent(serge.events.E_LEFT_CLICK, self.actorSelected, actor) actor.linkEvent(serge.events.E_ACCEPT_ENTRY, self.actorEntry, actor)