Exemplo n.º 1
0
    def startup(self, *items, **kwargs):
        """

        Accepted Keyword Arguments:
            prompt:   String used to let user know what value is being inputted (ie "Name?", "IP Address?")
            callback: Function to be called when dialog is confirmed.  The value will be sent as only argument
            initial:  Optional string to pre-fill the input box with.

        :param items:
        :param kwargs:
        :return:
        """
        super(InputMenu, self).startup(*items, **kwargs)
        self.input_string = kwargs.get("initial", "")

        # area where the input will be shown
        self.text_area = TextArea(self.font, self.font_color, (96, 96, 96))
        self.text_area.animated = False
        self.text_area.rect = Rect(tools.scale_sequence([90, 30, 80, 100]))
        self.text_area.text = self.input_string
        self.sprites.add(self.text_area)

        # prompt
        self.prompt = TextArea(self.font, self.font_color, (96, 96, 96))
        self.prompt.animated = False
        self.prompt.rect = Rect(tools.scale_sequence([50, 20, 80, 100]))
        self.sprites.add(self.prompt)

        self.prompt.text = kwargs.get("prompt", "")
        self.callback = kwargs.get("callback")
        assert self.callback
Exemplo n.º 2
0
    def startup(self, **kwargs):
        super(MonsterMenuState, self).startup(**kwargs)

        # make a text area to show messages
        self.text_area = TextArea(self.font, self.font_color, (96, 96, 96))
        self.text_area.rect = Rect(tools.scale_sequence([20, 80, 80, 100]))
        self.sprites.add(self.text_area, layer=100)

        # Set up the border images used for the monster slots
        self.monster_slot_border = {}
        self.monster_portrait = pygame.sprite.Sprite()
        self.hp_bar = HpBar()
        self.exp_bar = ExpBar()

        # load and scale the monster slot borders
        root = "gfx/ui/monster/"
        border_types = ["empty", "filled", "active"]
        for border_type in border_types:
            filename = root + border_type + "_monster_slot_border.png"
            border = graphics.load_and_scale(filename)

            filename = root + border_type + "_monster_slot_bg.png"
            background = graphics.load_image(filename)

            window = GraphicBox(border, background, None)
            self.monster_slot_border[border_type] = window

        # TODO: something better than this global, load_sprites stuff
        for monster in local_session.player.monsters:
            monster.load_sprites()
Exemplo n.º 3
0
 def build_right_hud():
     hud = self.load_sprite('gfx/ui/combat/hp_player_nohp.png',
                            layer=hud_layer)
     hud.image.blit(text, scale_sequence((12, 4)))
     hud.rect.bottomleft = home.right, home.bottom
     hud.player = True
     animate(hud.rect, left=home.left)
     return hud
Exemplo n.º 4
0
 def build_left_hud():
     hud = self.load_sprite('gfx/ui/combat/hp_opponent_nohp.png',
                            layer=hud_layer)
     hud.image.blit(text, scale_sequence((5, 5)))
     hud.rect.bottomright = 0, home.bottom
     hud.player = False
     animate(hud.rect, right=home.right)
     return hud
Exemplo n.º 5
0
def scaled_image_loader(filename, colorkey, **kwargs):
    """ pytmx image loader for pygame

    Modified to load images at a scaled size

    :param filename:
    :param colorkey:
    :param kwargs:
    :return:
    """
    if colorkey:
        colorkey = pygame.Color("#{0}".format(colorkey))

    pixelalpha = kwargs.get("pixelalpha", True)

    # load the tileset image
    image = pygame.image.load(filename)

    # scale the tileset image to match game scale
    scaled_size = scale_sequence(image.get_size())
    image = pygame.transform.scale(image, scaled_size)

    def load_image(rect=None, flags=None):
        if rect:
            # scale the rect to match the scaled image
            rect = scale_rect(rect)
            try:
                tile = image.subsurface(rect)
            except ValueError:
                logger.error("Tile bounds outside bounds of tileset image")
                raise
        else:
            tile = image.copy()

        if flags:
            tile = handle_transformation(tile, flags)

        tile = smart_convert(tile, colorkey, pixelalpha)
        return tile

    return load_image
Exemplo n.º 6
0
def scale_area(area):
    return Rect(tools.scale_sequence(area))