Display some info about the current tile
[naja.git] / naja / widgets / info_area.py
1 """
2 Widget for the game board information area.
3 """
4 import pygame
5
6 from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE
7 from naja.resources import resources
8 from naja.resources.mutators import EIGHT_BIT
9
10 from naja.widgets.base import Widget
11 from naja.widgets.tile import BIT_MAP
12 from naja.widgets.text import TextBoxWidget
13
14
15 class InfoAreaWidget(Widget):
16     """
17     Widget for the game board information area.
18     """
19     def __init__(self, pos, state):
20         super(InfoAreaWidget, self).__init__(pos, INFO_SIZE)
21         self.card = None
22         self.state = state
23
24     def prepare(self):
25         self.surface = pygame.surface.Surface(INFO_SIZE)
26         self.surface.fill((0, 0, 0))
27         # Quick hack for testing
28         self.card = self.state.board_locations[self.state.player.position]
29         # Extract actions and such from the card
30         y_offset = 0
31         for action in self.card.actions:
32             if action.required_bits:
33                 img_name = BIT_MAP[action.required_bits].replace('.png', '_small.png')
34                 img = resources.get_image(img_name,
35                                           transforms=(EIGHT_BIT,))
36                 self.surface.blit(img, (0, y_offset))
37                 y_offset += 8
38             text = TextBoxWidget((12, y_offset), action.TEXT,
39                                  box_width= (INFO_SIZE[0] - 12) // EIGHT_BIT_SCALE,
40                                  fontsize = 28, padding = 4)
41             text.render(self.surface)
42             y_offset += text.surface.get_rect().height + 16
43
44
45     def set_card(self, card):
46         self.card = card
47
48     def draw(self, surface):
49         surface.blit(self.surface, self.pos)