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.widgets.base import Widget
11 BITS['CYAN']: 'board/tile_cyan.png',
12 BITS['MAGENTA']: 'board/tile_magenta.png',
13 BITS['YELLOW']: 'board/tile_yellow.png',
17 class TileWidget(Widget):
18 """Widget which holds a tile on the game board."""
19 def __init__(self, pos, state=None, board_pos=None):
20 super(TileWidget, self).__init__(pos, TILE_SIZE)
22 self.board_pos = board_pos
25 # Placeholder logic - just draw the outline of a square
26 self.surface = pygame.surface.Surface(TILE_SIZE)
27 pygame.draw.lines(self.surface, pgl.color.THECOLORS['yellow'],
28 True, [(1, 1), (1, 95), (95, 95), (95, 1)], 2)
29 self.surface.convert_alpha(pygame.display.get_surface())
30 # Look up the required bits on the board location
31 card = self.state.gameboard.board_locations[self.board_pos]
33 for action in card.actions:
34 if action.required_bits:
35 bits.append(action.required_bits)
36 # Sort so we have longer lists of bits later
37 self.size = self.surface.get_rect().size
39 bits.sort(key=lambda x: len(x))
40 y_offset = TILE_SIZE[1] - 32 * len(bits)
44 img = resources.get_image(BIT_MAP[bit])
45 self.surface.blit(img, (x_offset, y_offset))
49 def draw(self, surface):
50 surface.blit(self.surface, self.rect)