def ask_question(self, x, y): self.parent.visible = True self.parent.set_position(x, y) x = self.x y = self.y items = self.loader.text.items self.answers = answers = [] width = 0 height = 0 for item in items[1:]: label = self.create_label(self.answerFont, item.value, item.color) answers.append(label) width = max(width, label.content_width) height += label.content_height self.questionLabel = label = self.create_label(self.questionFont, items[0].value, items[0].color) width = max(width, label.content_width) height += label.content_height width += X_MARGIN * 2 height += Y_MARGIN * (2 + len(answers)) current_y = -Y_MARGIN for label in [label] + answers: label.x = x label.y = y + current_y label.width = width label.set_style('align', 'center') label.content_valign = 'center' current_y -= (label.content_height + Y_MARGIN) self.width = width self.height = height from mmfparser.player.collision import BoundingBox self.collision = BoundingBox(self) self.player.pause(-2)
def update(self): value = self.value self.changed = False displayType = self.displayType if displayType == HIDDEN: return width = self.width height = self.height if displayType == HORIZONTAL_BAR: try: pixelCount = width - int(width * (self.value - self.minimum) / (self.maximum - self.minimum)) except ZeroDivisionError: pixelCount = 0 if self.countInverse: # count from right self.shape.set_offset(0, 0, pixelCount, 0) else: # count from left self.shape.set_offset(0, 0, 0, pixelCount) elif displayType == VERTICAL_BAR: pixelCount = height - int(height * (self.value - self.minimum) / (self.maximum - self.minimum)) if self.countInverse: # count up self.shape.set_offset(pixelCount, 0, 0, 0) else: # count down self.shape.set_offset(0, pixelCount, 0, 0) elif displayType == NUMBERS: imageList = [ self.make_image( self.loader.counters.getImage(character, self.player.gameData.images)) for character in self.as_text() ] self.height = max([image.height for image in imageList]) self.width = sum([image.width for image in imageList]) self.hotspotX = self.width self.hotspotY = self.height self.sprites = sprites = [] for image in imageList: newSprite = self.make_sprite(image) newSprite.shape.left = 0 newSprite.shape.top = 0 sprites.append(newSprite) self.parent.object_changed() self.collision = BoundingBox(self) elif displayType == ANIMATION: frames = self.loader.counters.frames if self.loader.counter: imageIndex = ((self.value - self.minimum) * (len(frames) - 1) / (self.maximum - self.minimum)) else: imageIndex = 0 currentImage = self.make_image_handle(frames[imageIndex]) if self.parent.objectType == LIVES: self.sprites = sprites = [] x = self.x or 0 y = self.y or 0 for blitX in xrange(0, int(currentImage.width * value), currentImage.width): newSprite = self.make_sprite(currentImage) newSprite.shape.left = 0 newSprite.shape.top = 0 newSprite.x = x + blitX newSprite.y = y sprites.append(newSprite) else: # assume it's not self.sprites = [self.make_sprite(currentImage)] elif displayType == TEXT_COUNTER: self.label.text = self.as_text() # if we have coordinates to set yet if self.x and self.y: self.set_position(self.x, self.y) self.set_transparency(self.parent.transparency) if width != self.width or height != self.height: self.collision.resize(width, height)