1 # These will probably need to go away when we have images
3 import pygame.locals as pgl
5 from naja.constants import TILE_SIZE, BITS
6 from naja.resources import resources
7 from naja.resources.mutators import EIGHT_BIT
8 from naja.widgets.base import Widget
12 BITS.CYAN: 'board/tile_cyan.png',
13 BITS.MAGENTA: 'board/tile_magenta.png',
14 BITS.YELLOW: 'board/tile_yellow.png',
18 class TileWidget(Widget):
19 """Widget which holds a tile on the game board."""
20 def __init__(self, pos, state=None, board_pos=None):
21 super(TileWidget, self).__init__(pos, TILE_SIZE)
23 self.board_pos = board_pos
26 # Placeholder logic - just draw the outline of a square
27 self.surface = pygame.surface.Surface(TILE_SIZE)
28 pygame.draw.lines(self.surface, pgl.color.THECOLORS['yellow'],
29 True, [(1, 1), (1, 95), (95, 95), (95, 1)], 2)
30 self.surface.convert_alpha(pygame.display.get_surface())
31 # Look up the required bits on the board location
32 card = self.state.board_locations[self.board_pos]
34 for action in card.actions:
35 if action.required_bits:
36 bits.append(action.required_bits)
37 # Sort so we have longer lists of bits later
38 self.size = self.surface.get_rect().size
40 bits.sort(key=lambda x: len(x))
41 y_offset = TILE_SIZE[1] - 32 * len(bits)
45 img = resources.get_image(BIT_MAP[bit],
46 transforms=(EIGHT_BIT,))
47 self.surface.blit(img, (x_offset, y_offset))
51 def draw(self, surface):
52 surface.blit(self.surface, self.pos)