Example #1
0
def print_rect(dest, x, y, w, h, text):
    # LIBTCOD
    # libtcod.console_print_rect(dest, x, y, w, h, text)

    # BEARLIB
    terminal.layer(dest)
    terminal.print_(x, y, "{0}[bbox={1}x{2}]".format(text, w, h))
Example #2
0
    def draw(self):
        screen_info = self.screen_info
        self.set_sprite_font()
        half_width, half_height = screen_info.half_width, screen_info.half_height - screen_info.message_log_height
        ox, oy = (self.focus_on.x * 2) - half_width, self.focus_on.y - half_height
        max_x, max_y = ox + screen_info.game_area_width, oy + screen_info.game_area_height
        level = self.focus_on.level
        graphics = self.options.graphical_tiles
        draw_method = self._draw_graphic if graphics else self._draw_ascii

        if graphics:
            terminal.layer(1)

        draw_offset_y = screen_info.top_gui_height + 1
        for y, row_tiles in enumerate(level.tiles):
            dy = y - oy
            for x, tile in enumerate(row_tiles):
                dx = (x * 2) - ox
                if x * 2 > max_x or y > max_y or x * 2 < ox or y < oy:
                    continue

                draw_method(dx, dy + draw_offset_y, tile)

        if graphics:
            terminal.layer(3)
        for actor in sorted(level.actors, key=lambda a: a.display_priority, reverse=True):
            dx = (actor.x * 2) - ox
            dy = actor.y - oy

            if actor.x > max_x or actor.y > max_y or actor.x < ox or actor.y < oy:
                continue

            draw_method(dx, dy + draw_offset_y, actor)

        self.reset_font()
Example #3
0
    def create_or_show_menu(self, data):
        blt.layer(1)
        self.owner.render_functions.clear_camera(5)

        if data.name == "choose_animal":
            if self.choose_animal:
                self.choose_animal.refresh()
                self.choose_animal.show()
            else:
                choose_animal_menu = ChooseAnimal(sub_menu=data.sub_menu)
                self.choose_animal = choose_animal_menu
                self.choose_animal.owner = self
                self.choose_animal.show()
        elif data.name == "choose_level":
            if self.choose_level:
                self.choose_level.data = data.params
                self.choose_level.refresh()
                self.choose_level.show()
            else:
                choose_level_menu = ChooseLevel(data=data.params)
                self.choose_level = choose_level_menu
                self.choose_level.owner = self
                self.choose_level.show()
        elif data.name == "avatar_info":
            if self.avatar_info:
                self.avatar_info.data = data.params
                self.avatar_info.refresh()
                self.avatar_info.show()
            else:
                avatar_info_menu = AvatarInfo(data=data.params)
                self.avatar_info = avatar_info_menu
                self.avatar_info.owner = self
                self.avatar_info.show()

        self.owner.game_state = GameStates.PLAYER_TURN
Example #4
0
    def draw(self):
        if self.dirty:
            if self.checked:
                text = self.checked_text
            else:
                text = self.text

            terminal.layer(self.owner.layer)
            if self.hover:
                terminal.color(self.back)
                terminal.puts(self.owner.pos.x + self.x,
                              self.owner.pos.y + self.y,
                              "[U+2588]" * self.length)
                terminal.color(self.fore)
                terminal.puts(self.owner.pos.x + self.x,
                              self.owner.pos.y + self.y,
                              text)
            else:
                terminal.color(self.back_alt)
                terminal.puts(self.owner.pos.x + self.x,
                              self.owner.pos.y + self.y,
                              "[U+2588]" * self.length)
                terminal.color(self.fore_alt)
                terminal.puts(self.owner.pos.x + self.x,
                              self.owner.pos.y + self.y,
                              text)
            terminal.puts(self.owner.pos.x + self.x + self.length + 1,
                          self.owner.pos.y + self.y,
                          self.label)
            self.dirty = False
Example #5
0
    def render_menu(self):
        print(f'Menu: Render menu: i am {self}')
        terminal.layer(Layers.MENU.value)

        window_width = 0
        window_height = 0
        for content in self.menu_contents:
            content_width = content.get_total_width()
            if content_width > window_width:
                window_width = content_width
            window_height += content.get_total_height()
        x1, y1 = self.menu_placement(window_width, window_height)

        draw_background(x1 - 1,
                        y1 - 1,
                        x1 + window_width + 2,
                        y1 + window_height + 1,
                        color='gray')
        self.menu_contents = sorted(self.menu_contents,
                                    key=lambda cont: cont.render_order)
        for content in self.menu_contents:
            y1 += content.margin
            content.paste_on_window(x1, y1, window_width)
            y1 += content.get_height()
            y1 += content.linebreak
            y1 += content.margin

        terminal.refresh()
Example #6
0
def render_all(entities, gamemap):
    #blt.clear()
    # Draw all the tiles in the game map
    blt.layer(0)
    blt.bkcolor("black")
    for y in range(gamemap.height):
        for x in range(gamemap.width):
            blt.puts(
                x, y, "[color=%s]%s[/color]" %
                (gamemap.tiles[x][y].color, gamemap.tiles[x][y].char))

    blt.layer(100)
    # Draw all entities in the list
    for entity in entities:
        draw_entity(entity)

    # Draw all items on the list
    blt.layer(10)
    for i in items:
        draw_item(i)

    blt.layer(255)

    draw_UI()
    blt.layer(254)
    blt.puts(0, 49, "[color=lighter yellow]%s[/color]" % fps_value)
    DrawReticle()

    ### Draw animations

    blt.refresh()
Example #7
0
def DrawProjectile(points):
    blt.layer(251)
    render_all(entities, gamemap)
    lx = -1
    ly = -1

    for i in range(0, len(points) - 1):
        blt.puts(points[i][0], points[i][1], "[color=cyan]*[/color]")
        if lx >= 0:
            blt.puts(lx, ly, "[color=black] [/color]")
            blt.clear_area(lx, ly, 1, 1)
            blt.refresh()
        lx = points[i][0]
        ly = points[i][1]

        blt.refresh()

    # for i in range(0, len(px) - 1):
    #     blt.puts(int(px[i]), int(py[i]), "[color=cyan]*[/color]")
    #     if lx >= 0:
    #         blt.puts(lx, ly, "[color=black] [/color]")
    #         blt.clear_area(lx, ly, 1, 1)
    #         blt.refresh()
    #         lx = px[i]
    #         ly = py[i]
    #     blt.refresh()
    blt.clear()
Example #8
0
def mpGameLoop(client):
    _map = Map(70, 50)
    player = client.players[client.name]
    mapReady = False
    while True:
        client.Loop()
        if client.msgQ.qsize() > 0:
            msg = client.msgQ.get()
            if msg['action'] == 'gameMap':
                _map.mapFrom(msg['gameMap'])
                mapReady = True
                playerx, playery = _map.findPlayerLoc()
                player.x = playerx
                player.y = playery
                terminal.clear()
                _map.do_fov(player.x, player.y, constants.FOV_RADIUS)
        if mapReady:
            _map.render_map()
            terminal.layer(1)
            for k, v in client.players.items():
                v.draw()
            terminal.refresh()
            terminal.layer(1)
            for k, v in client.players.items():
                v.clear()
            ex = handle_keys(player, _map.game_map)
            if ex == 1:
                _map.do_fov(player.x, player.y, constants.FOV_RADIUS)
                client.Send({
                    'action': 'posUpdate',
                    'posUpdate': [player.x, player.y]
                })
            if ex == 2:
                terminal.bkcolor(black)
                break
Example #9
0
    def play(self, game_master):
        while game_master.game_state == 'playing':
            # Check game state
            for player in self.players:
                if not player.avatar.alive:
                    game_master.game_state = 'dead'

            current_player = self.players[0]

            render(current_player, game_master)

            terminal.layer(2)
            for o in self.current_map.objects:
                o.clear(current_player.camera)

            for obj in self.current_map.objects:
                if obj.active:
                    obj.update()

            for effect in self.current_map.effects:
                if effect.active:
                    effect.update()

            self.current_map.update()

            player.action = current_player.input(self)
            if player.action == 'quit':
                game_master.save_game()
                game_master.main_menu()

            terminal.delay(1000 // game_master.fps)
 def main_menu(self, num, x, y, click, enter):
     self.input_state = 'main'
     dict = [
         ['[color=grey] New Game', 'New Game'],
         ['[color=grey]   Continue', '  Continue'],
         ['[color=grey]     Quit Game', '    Quit Game'],
     ]
     terminal.clear()
     terminal.layer(0)
     button0_rect = [self.center_text(dict[0][1]), 16, 8, 1]
     button1_rect = [self.center_text(dict[1][1]), 18, 10, 1]
     button2_rect = [self.center_text(dict[2][1]), 20, 13, 1]
     self.menu_num += num
     if self.menu_num > 2:
         self.menu_num = 0
     if self.menu_num < 0:
         self.menu_num = 2
     if x != 0 or y != 0:
         clickable = False
         if y >= button0_rect[1] and y <= button0_rect[1] + button0_rect[3]:
             if x >= button0_rect[
                     0] and x <= button0_rect[0] + button0_rect[2]:
                 clickable = True
                 self.menu_num = 0
         if y >= button1_rect[1] and y <= button1_rect[1] + button1_rect[3]:
             if x >= button1_rect[
                     0] and x <= button1_rect[0] + button1_rect[2]:
                 clickable = True
                 self.menu_num = 1
         if y >= button2_rect[1] and y <= button2_rect[1] + button2_rect[3]:
             if x >= button2_rect[
                     0] and x <= button2_rect[0] + button2_rect[2]:
                 clickable = True
                 self.menu_num = 2
     if self.menu_num == 0:
         terminal.printf(button0_rect[0], button0_rect[1], dict[0][1])
     else:
         terminal.printf(button0_rect[0], button0_rect[1], dict[0][0])
     if self.menu_num == 1 and num != 0:
         terminal.printf(button1_rect[0], button1_rect[1], dict[1][1])
         if self.coords == []:
             self.main_menu(num, 0, 0, False, False)
             return
     else:
         terminal.printf(button1_rect[0], button1_rect[1], dict[1][0])
     if self.menu_num == 2:
         terminal.printf(button2_rect[0], button2_rect[1], dict[2][1])
     else:
         terminal.printf(button2_rect[0], button2_rect[1], dict[2][0])
     terminal.printf(self.center_text('This is [color=red]Space  '), 11,
                     'This is [color=red]Space  ')
     #terminal.printf(self.center_text('press Enter'), 12, 'press Enter')
     terminal.refresh()
     if (click == True and clickable == True) or enter == True:
         if self.menu_num == 0:
             self.load_sector()
         if self.menu_num == 1:
             self.input_state = 'sector'
         if self.menu_num == 2:
             terminal.close()
Example #11
0
def draw_rect(dest, x, y, w, h, frame=False, f_color=None, bk_color=None, title=None):
    terminal.layer(dest)

    if title:
        if len(title) % 2 == 0:
            adj = 1
        else:
            adj = 2
        offset_x1 = ((w - len(title)) / 2) + adj
        offset_x2 = (w - len(title)) - (offset_x1 - 2)
    else:
        offset_x1 = w
        offset_x2 = 0

    for x1 in range(w):
        for y1 in range(h):
            terminal.color(bk_color)
            draw_char(dest, x1 + x, y1 + y, Utils.get_unicode(219))
            if frame:
                terminal.color(f_color)
                if (x1, y1) == (0, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NW)
                elif (x1, y1) == (w - 1, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NE)
                elif (x1, y1) == (0, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SW)
                elif (x1, y1) == (w - 1, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SE)
                elif x1 == 0 or x1 == w - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_E)
                elif  y1 == h - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_N)
    if title:
        print_line(dest, x, y, " " )
        print_line(dest, x, y, "{0}".format(title).center(w, ' '))
Example #12
0
    def add_widget(self, widget,
                   pos=(0, 0), layer=0, refresh=False):
        """
        Add a widget to the terminal and set `widget.terminal` to `self`.

        No two widgets are allowed to overlap within a layer and no widget can
        be added twice.

        :param widget: a Widget instance

        :param pos: top left corner of the widget

        :param layer: layer to place the widget on

        :param refresh: whether to refresh terminal after adding the widget. If False, the widget will not be actually shown until the next ``terminal.refresh()`` call
        """
        if widget in self.widget_locations.keys():
            raise BearException('Cannot add the same widget twice')
        for y in range(widget.height):
            for x in range(widget.width):
                if self._widget_pointers[layer] and \
                        self._widget_pointers[layer][pos[0] + x][pos[1] + y]:
                    raise BearException('Widgets cannot collide within a layer')
        widget.terminal = self
        widget.parent = self
        self.widget_locations[widget] = WidgetLocation(pos=pos, layer=layer)
        terminal.layer(layer)
        if not self._widget_pointers[layer]:
            size = terminal.get('window.size')
            width, height = (int(x) for x in size.split('x'))
            self._widget_pointers[layer] = [[None for y in range(height)]
                                            for x in range(width)]
        self.update_widget(widget, refresh)
Example #13
0
    def clear_view(self):
        for i in range(len(RenderLayer)):
            blt.layer(i)
            blt.clear_area(0, 0, self.width * 2, self.height * 2)

        blt.layer(RenderLayer.ACTOR.value)
        blt.put(self.center.x, self.center.y, " ")
Example #14
0
 def draw(self, xy: vec, layer: int = 0) -> None:
     blt.layer(layer)
     blt.color(self.fg_colour.blt_colour())
     if self.bg_colour is not None:
         blt.bkcolor(self.bg_colour.blt_colour())
     xy = xy + self.xy
     blt.put(xy.x, xy.y, self.char)
Example #15
0
    def draw_light_sources(self):
        player = self.owner.player
        light_map = player.player.lightmap
        game_map = self.owner.levels.current_map
        game_camera = self.owner.game_camera
        for light in self.light_sources:
            light_fov = np.where(light.fov_map.fov)
            center = np.array([light.owner.y, light.owner.x])

            for i in range(light_fov[0].size):
                y, x = int(light_fov[0][i]), int(light_fov[1][i])
                if player.light_source.fov_map.fov[y, x]:
                    v = np.array([y, x])
                    dist = float(cityblock(center, v))
                    light_level = game_map.tiles[x][y].natural_light_level * \
                                  (1.0 / (0.2 + 0.1 * dist + 0.025 * dist * dist))

                    if light_map[y][x] < light_level:
                        light_map[y][x] = light_level

        player_fov = np.where(player.light_source.fov_map.fov)
        for j in range(player_fov[0].size):
            y, x = int(player_fov[0][j]), int(player_fov[1][j])
            cam_x, cam_y = game_camera.get_coordinates(x, y)
            blt.layer(0)
            c = blt.color_from_name(game_map.tiles[x][y].color)
            argb = argb_from_color(c)
            flicker = random.uniform(
                0.95, 1.05) if self.owner.options.flicker is True else 1
            a = argb[0]
            r = min(int(argb[1] * light_map[y][x] * flicker), 255)
            g = min(int(argb[2] * light_map[y][x] * flicker), 255)
            b = min(int(argb[3] * light_map[y][x] * flicker), 255)

            blt.color(blt.color_from_argb(a, r, g, b))
            blt.put(cam_x * self.owner.options.tile_offset_x,
                    cam_y * self.owner.options.tile_offset_y,
                    game_map.tiles[x][y].char)

            if len(game_map.tiles[x][y].layers) > 0:
                i = 1
                for tile in game_map.tiles[x][y].layers:
                    blt.layer(i)
                    c = blt.color_from_name(tile[1])
                    argb = argb_from_color(c)
                    a = argb[0]
                    r = min(int(argb[1] * light_map[y][x] * flicker), 255)
                    g = min(int(argb[2] * light_map[y][x] * flicker), 255)
                    b = min(int(argb[3] * light_map[y][x] * flicker), 255)
                    blt.color(blt.color_from_argb(a, r, g, b))
                    blt.put(cam_x * self.owner.options.tile_offset_x,
                            cam_y * self.owner.options.tile_offset_y, tile[0])
                    i += 1

            if len(game_map.tiles[x][y].entities_on_tile) > 0:
                for entity in game_map.tiles[x][y].entities_on_tile:

                    if not entity.cursor:
                        self.clear(entity, cam_x, cam_y)
                        self.draw(entity, cam_x, cam_y)
Example #16
0
 def open_menu(self, menu):
     blt.layer(RenderLayer.BACKGROUND.value)
     blt.clear()
     blt.layer(RenderLayer.MENU.value)
     blt.clear()
     blt.refresh()
     self.current_menu = menu
Example #17
0
def ui_print(terminal, x, y, h, w, text_string):

    terminal.layer(UI_LAYER)
    terminal.clear_area(dialog_pos_x, dialog_pos_y, dialog_width,
                        dialog_height)
    terminal.printf(dialog_pos_x, dialog_pos_y, ml.get_scroll_back())
    terminal.refresh()
Example #18
0
def render_map_con(entities, players, game_map, width, height, ox=0, oy=0) -> None:
    terminal.layer(0)
    for player in players:
        for y in range(game_map.height):
            for x in range(game_map.width):   
                #Show if it's visible
                if (x,y) in player.fighter.fov_visible:
                    terminal.color('light amber')
                    terminal.put(x+ox, y+oy, 0x2588)
                    if (x,y) in player.fighter.fov_wall:
                        terminal.color('dark gray')
                        terminal.put(x+ox, y+oy, 0x2588)
                #Not visible but explored
                elif (x,y) in player.fighter.fov_explored:
                    if (x,y) in player.fighter.fov_wall:
                        terminal.color('darker gray')
                        terminal.put(x+ox, y+oy, 0x2588)
                    else:
                        terminal.color('darker amber')
                        terminal.put(x+ox, y+oy, 0x2588)
                #Not explored                     
                else:
                    terminal.color('dark gray')
                    terminal.put(x+ox, y+oy, 0x2588)
    


    print_entities(entities, ox, oy)
def render_tactical_panel(x, y, total_width, total_height, entities, player):
    terminal.layer(0)
    target = ''
    for ent in entities:
        if ent.combatship:
            if ent.combatship.targeted:
                target = ent
                break
    initialize_with_bkcolor('black', 'darkest azure', total_width,
                            total_height, x, y)
    draw_panel_box('white', total_width, total_height, x, y)
    terminal.print_(int(x + total_width / 2 - len('TACTICAL PANEL (t)') / 2),
                    y, 'TACTICAL PANEL (t)')
    if target:
        target_name = target.name
        target_hull = target.combatship.hull
        target_shields = target.combatship.shields
        target_armament = target.inventory.items
    else:
        target_name = 'None'
        target_hull = r'N/A'
        target_shields = r'N/A'
        target_armament = []
    terminal.print_(x + 1, y + 2, 'Target: {}'.format(target_name))
    terminal.print_(x + 1, y + 3, 'Hull: {}'.format(target_hull))
    terminal.print_(x + 1, y + 4, 'Shields: {}'.format(target_shields))
    terminal.print_(x + 1, y + 6, 'Armament:')
    for cnt, wpn in enumerate(target_armament):
        terminal.print_(x + 1, y + 7 + cnt, '  ' + wpn.name)
    terminal.bkcolor('black')
Example #20
0
def draw_map(game_map):
    if game_map:
        terminal.layer(Layers.MAP)
        terminal.color(terminal.color_from_name("white"))

        for point, tile in game_map:
            terminal.put(point.x, point.y, tile.char)
Example #21
0
    def pprint(self, x: int, y: int, string: str):
        """
        Pretty prints a string starting at (x,y).
        :param x: x coordinate

        :param y: y coordinate

        :param string: String to print to screen
        """
        bearlib.layer(1)
        bearlib.composition(bearlib.TK_ON)
        pos = x
        cell_size, _ = self.window.cell_size.split('x')
        cell_width = int(cell_size)
        for c in string:
            if pos >= self.window.width - x - 1:
                pos = pos + 1
                offset = (pos - x) * (cell_width / 2)
                bearlib.put_ext(x, y, int(offset), 0, c)
            else:
                pos = pos + 1
                offset = 0 - pos * (cell_width / 2)
                bearlib.put_ext(pos, y, int(offset), 0, c)
        bearlib.layer(0)
        bearlib.composition(bearlib.TK_OFF)
Example #22
0
 def render_entities(self, game):
     blt.layer(RenderLayer.ENTITIES.value)
     game_map = game.dungeon.current_map
     entities_in_render_order = sorted(game_map.get_entities(),
                                       key=lambda x: x.render_order.value)
     for entity in entities_in_render_order:
         self._draw_entity(entity, game_map)
Example #23
0
def render_entities_camera():
    start = time.perf_counter()

    current_map = World.fetch('current_map')
    min_x, max_x, min_y, max_y = get_screen_bounds()
    map_width = current_map.width
    map_height = current_map.height

    subjects = World.get_components(PositionComponent, RenderableComponent)
    for entity, (position, renderable) in subjects:
        hidden = World.get_entity_component(entity, HiddenComponent)
        idx = current_map.xy_idx(position.x, position.y)
        terminal.layer(renderable.render_order.value)
        if current_map.visible_tiles[idx] and not hidden:
            entity_screen_x = position.x - min_x
            entity_screen_y = position.y - min_y
            if 0 <= entity_screen_x <= map_width and 0 <= entity_screen_y <= map_height:
                if Interface.mode == GraphicalModes.ASCII:
                    terminal.printf(
                        entity_screen_x * Interface.zoom,
                        entity_screen_y * Interface.zoom,
                        f'[color={renderable.fg}]{renderable.glyph}[/color]')
                elif Interface.mode == GraphicalModes.TILES:
                    terminal.color(f'{renderable.fg}')
                    terminal.put(entity_screen_x * Interface.zoom,
                                 entity_screen_y * Interface.zoom,
                                 Interface.get_code(renderable.sprite))
                else:
                    print(
                        f'render camera: graphical mode {Interface.mode} not implemented.'
                    )
                    raise NotImplementedError

    delta_time = (time.perf_counter() - start) * 1000
    print(f'delta time: for render entities : {delta_time}')
Example #24
0
def print_rect(dest, x, y, w, h, text):
    # LIBTCOD
    # libtcod.console_print_rect(dest, x, y, w, h, text)

    # BEARLIB
    terminal.layer(dest)
    terminal.print_(x, y, "{0}[bbox={1}x{2}]".format(text, w, h))
Example #25
0
    def update(self):
        if self.owner:
            layer = self.owner.layer
            x = self.owner.pos.x
            y = self.owner.pos.y
        else:
            layer = terminal.state(terminal.TK_LAYER)
            x = 0
            y = 0

        if mouse.clicked_rect(self.x + x, self.y + y, self.length, 1):
            terminal.layer(layer)
            terminal.color('white')
            terminal.puts(self.x + 1 + x, self.y + y,
                          self.skin['BACKGROUND'] * self.length)
            terminal.color('black')
            terminal.refresh()
            result, text = terminal.read_str(self.x + x + 1, self.y + y,
                                             self.text, self.length)
            terminal.refresh()
            if text.isnumeric() and (self.min_val <= int(text) <=
                                     self.max_val):
                self.text = str(text)
                self.error = None
                self.updated = True
            else:
                self.error = 'Text must be numeric and between ' + str(
                    self.min_val) + ' and ' + str(self.max_val) + '.'

            self.active = True
            self.dirty = True
Example #26
0
    def update(self):
        if self.owner:
            layer = self.owner.layer
            x = self.owner.pos.x
            y = self.owner.pos.y
        else:
            layer = terminal.state(terminal.TK_LAYER)
            x = 0
            y = 0

        if mouse.clicked_rect(self.x + x, self.y + y, self.length, 1):
            terminal.layer(layer)
            terminal.color('white')
            terminal.puts(self.x + 1 + x, self.y + y,
                          self.skin['BACKGROUND'] * self.length)
            terminal.color('black')
            terminal.refresh()
            result, text = terminal.read_str(self.x + x + 1, self.y + y,
                                             self.text, self.length)
            terminal.refresh()
            self.text = text
            self.updated = True

            self.active = True
            self.dirty = True
Example #27
0
    def draw_messages(self):
        message_log = self.owner.message_log
        msg_panel = self.owner.ui.msg_panel

        if message_log.new_msgs or not message_log.buffer:
            blt.layer(0)
            blt.clear_area(msg_panel.offset_x + msg_panel.border,
                           msg_panel.offset_y + msg_panel.border,
                           msg_panel.offset_w + msg_panel.border,
                           msg_panel.offset_h + msg_panel.border)
        if message_log.new_msgs:

            # Print the game messages, one line at a time. Display newest
            # msg at the bottom and scroll others up
            i = 4
            # if i > message_log.max_length:
            #    i = 0

            for idx, message in enumerate(message_log.buffer):

                msg = message.msg
                if message.stacked > 1:
                    msg = msg + " x{0}".format(str(message.stacked))
                blt.puts(msg_panel.border_offset,
                         msg_panel.offset_y + msg_panel.border_offset + i * 2,
                         "[offset=0,-35]" + msg,
                         msg_panel.offset_w - 2,
                         1,
                         align=blt.TK_ALIGN_LEFT)
                i -= 1
            message_log.new_msgs = False
Example #28
0
def draw_rect(dest, x, y, w, h, frame=False, f_color=None, bk_color=None, title=None):
    terminal.layer(dest)

    if title:
        offset_x1 = ((w - len(title)) / 2) + 1
        offset_x2 = (w - len(title)) - (offset_x1 - 2)
    else:
        offset_x1 = w
        offset_x2 = 0

    for x1 in range(w):
        for y1 in range(h):
            terminal.color(bk_color)
            draw_char(dest, x1 + x, y1 + y, Utils.get_unicode(219))
            if frame:
                terminal.color(f_color)
                if (x1, y1) == (0, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NW)
                elif (x1, y1) == (w - 1, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NE)
                elif (x1, y1) == (0, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SW)
                elif (x1, y1) == (w - 1, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SE)
                elif x1 == 0 or x1 == w - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_E)
                elif (y1 == 0 and (offset_x1-1 > x1 or x1 > w - offset_x2)) or y1 == h - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_N)
    if title:
        print_line(dest, x + (w / 2), y, "[wrap={0}x{1}][align=center-center]{2}".format(w, h, title))
Example #29
0
def test_layers():
    blt.set("window.title='Omni: layers'")

    pixel = c_uint32(blt.color_from_name("dark gray"))

    blt.set("U+E000: %d, raw-size=1x1, resize=48x48, resize-filter=nearest" % addressof(pixel))

    blt.clear()
    blt.color("white")

    blt.puts(2, 1, "[color=orange]1.[/color] Without layers:")
    blt.put(7, 3, 0xE000)   
    blt.puts(5, 4, "[color=dark green]abcdefghij")

    blt.puts(2, 8, "[color=orange]2.[/color] With layers:")
    blt.layer(1)
    blt.put(7, 10, 0xE000)
    blt.layer(0)
    blt.puts(5, 11, "[color=dark green]abcdefghij")

    blt.refresh()

    key = None
    while key not in (blt.TK_CLOSE, blt.TK_ESCAPE):
        key = blt.read()

    blt.set("U+E000: none")
Example #30
0
    def update_widget(self, widget, refresh=False):
        """
        Actually draw widget chars on screen.

        If ``widget.chars`` or ``widget.colors`` have changed, this method will
        make these changes visible. It is also called by ``self.add_widget()``
        and other methods that have a ``refresh`` argument.

        :param widget: A widget to be updated.
        """
        if widget not in self.widget_locations:
            raise BearException('Cannot update non-added Widgets')
        pos = self.widget_locations[widget].pos
        layer = self.widget_locations[widget].layer
        terminal.layer(layer)
        terminal.clear_area(*self.widget_locations[widget].pos, widget.width, widget.height)
        running_color = self.default_color
        for y in range(widget.height):
            for x in range(widget.width):
                # Widget can have None as color for its empty cells
                if widget.colors[y][x] and widget.colors[y][x] != running_color:
                    running_color = widget.colors[y][x]
                    terminal.color(running_color)
                terminal.put(pos[0] + x, pos[1] + y, widget.chars[y][x])
                self._widget_pointers[layer][pos[0] + x][pos[1] + y] = widget
        if running_color != self.default_color:
            terminal.color(self.default_color)
        if refresh:
            self.refresh()
Example #31
0
    def pprint_center(self, text: List[str]):
        """
        Prints a string or list of strings in the center of the window

        :param text: List of strings to be printed
        """
        height = self.window.height
        width = self.window.width
        cellsize, _ = self.window.cell_size.split('x')
        cell_width = int(cellsize)
        center = int(width / 2)

        bearlib.clear()
        bearlib.layer(1)
        bearlib.composition("TK_ON")
        y = int(height / 2 - len(text) / 2)
        for i, s in enumerate(text):
            middle_char = int(len(s) / 2)
            x = int(center - middle_char)
            pos = 0
            for c in s:
                offset = (center - x) * (cell_width / 2)
                bearlib.put_ext(x, y + i, int(offset), 0, c)
                x = x + 1
                pos = pos + 1
        bearlib.composition("TK_OFF")
        bearlib.layer(0)
        bearlib.refresh()
Example #32
0
    def draw(self):
        # Draw the menu to the terminal.
        if len(self.options) > 26:
            raise ValueError('Cannot have a menu with more than 26 options.')

        previous_layer = terminal.state(terminal.TK_LAYER)
        terminal.layer(RenderLayer.MENU.value)

        self.draw_background(background_color=self.background_color)

        # Print the header with wrapped text to the center of the menu
        terminal.color('white')
        terminal.composition(terminal.TK_ON)
        for i, _ in enumerate(self.header_wrapped):
            render_functions.print_shadowed_text(
                self.topleft_x + int((self.width / 2) + 1),
                self.topleft_y + i,
                self.header_wrapped[i],
                align=[terminal.TK_ALIGN_DEFAULT, terminal.TK_ALIGN_CENTER])

        # Print options under the menu, aligned to the left (left is the default)
        current_y = self.header_height + 1
        letter_index = ord('a')
        for option_text in self.options:
            text = f"{chr(letter_index)}) {option_text}"
            render_functions.print_shadowed_text(self.topleft_x,
                                                 self.topleft_y + current_y,
                                                 text)
            current_y += 1
            letter_index += 1

        terminal.composition(terminal.TK_OFF)

        terminal.layer(previous_layer)
Example #33
0
def print_line(dest, x, y, text): # bottom-right for BEARLIB
    # LIBTCOD
    # libtcod.console_print_ex(dest, x, y, flag, alignment, text)

    # BERALIB

    terminal.layer(dest)
    terminal.print_(x, y, text)
Example #34
0
 def render(self):
     self.frame += 1
     if self.frame % 5 == 0:
         self.animate()
     term.layer(1)
     term.color(term.color_from_argb(255, *COLOR['WHITE']))
     term.put(self.center[X], self.center[Y], self.picture)
     super(MenuPanel, self).render()
Example #35
0
def draw_char_ex(dest, x, y, dx, dy, char, color=None, flag=None, alpha=255):
    # LIBTCOD
    # libtcod.console_put_char_ex(dest, x, y, char, color, flag)

    # BEARLIB
    terminal.layer(dest)
    # TODO: CONVERT COLORS ON THEME IMPORT, INSTEAD OF INLINE (all render func)
    if color is not None:
        #color = Utils.convert_color(color, alpha)
        terminal.color(color)
    terminal.put_ext(x, y, dx, dy, char, None)
Example #36
0
def print_line(dest, x, y, text, f_color=None): # bottom-right for BEARLIB
    # LIBTCOD
    # libtcod.console_print_ex(dest, x, y, flag, alignment, text)

    # BERALIB

    if f_color:
        set_foreground(dest, f_color)

    terminal.layer(dest)

    terminal.puts(x, y, text)
Example #37
0
def draw_char(dest, x, y, char, color=None, flag=None, alpha=255, verbose=False):
    # LIBTCOD
    # libtcod.console_put_char_ex(dest, x, y, char, color, flag)

    #BEARLIB
    terminal.layer(dest)
    # TODO: CONVERT COLORS ON THEME IMPORT, INSTEAD OF INLINE (all render func)
    if color is not None:
        if verbose:
            print color
            print int(color)
            print color.getRGB()
        #color = Utils.convert_color(color, alpha)
        #print "Color: {0}".format(color)
        #print "In DrawChar Color: {0}".format(color)
        terminal.color(color)
    terminal.put(x, y, char)
Example #38
0
def clear_layer(layer, color='black'):
    terminal.bkcolor(color)
    terminal.layer(layer)
    terminal.clear_area(0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT)