X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Fwidgets%2Finfo_area.py;h=0bb02f41aca8551d453680fdf68e363066ee8ad6;hb=963216cd4493996f5859347fe50249fb5865d6e5;hp=2a4d06b69e2ca5082ccd2508f4f27bcb7461212d;hpb=42e40dc4e5a5ae8a11934b5f718c9bd4e91f06ce;p=naja.git diff --git a/naja/widgets/info_area.py b/naja/widgets/info_area.py index 2a4d06b..0bb02f4 100644 --- a/naja/widgets/info_area.py +++ b/naja/widgets/info_area.py @@ -4,8 +4,8 @@ Widget for the game board information area. import pygame import pygame.locals as pgl -from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT -from naja.events import InvalidateTheWorld +from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT, KEYS +from naja.events import PlayerMoved, finish_event from naja.resources import resources from naja.resources.mutators import EIGHT_BIT @@ -32,15 +32,12 @@ class InfoAreaWidget(Widget): """ def __init__(self, pos, state): super(InfoAreaWidget, self).__init__(pos, INFO_SIZE) - self.card = None self.state = state - self.chosen = 0 + self.set_position(state.player.position) def prepare(self): self.surface = pygame.surface.Surface(INFO_SIZE) self.surface.fill((0, 0, 0)) - # Quick hack for testing - self.card = self.state.board_locations[self.state.player.position] # Extract actions and such from the card title = TextWidget((0, 0), TITLES[self.state.gameboard.player_mode], colour=(255, 255, 255)) @@ -72,30 +69,37 @@ class InfoAreaWidget(Widget): y_offset = INFO_SIZE[1] - hint.surface.get_rect().height self.surface.blit(hint.surface, (0, y_offset)) - def set_card(self, card): - self.card = card + def set_position(self, position): + self.card = self.state.board_locations[position] + self.chosen = 0 def draw(self, surface): surface.blit(self.surface, self.pos) def handle_event(self, ev): + if PlayerMoved.matches(ev): + self.set_position(self.state.player.position) + return False + if self.state.gameboard.player_mode == MOVE: return super(InfoAreaWidget, self).handle_event(ev) if ev.type == pgl.KEYDOWN: - if ev.key in (pgl.K_RETURN, pgl.K_KP_ENTER): - self.state.gameboard.change_mode() - # FIXME: also need to signal the correct action - # here - InvalidateTheWorld.post() - return True - if ev.key in (pgl.K_UP, pgl.K_w): + if ev.key in KEYS.SELECT: + player = self.state.gameboard.player + action = self.card.actions[self.chosen] + if not action.check_available(player): + print "BEEP!" + else: + action.perform_action(self.state.gameboard, self.card) + self.state.gameboard.replace_card(player.position) + self.state.gameboard.change_mode() + return finish_event() + if ev.key in KEYS.UP: if self.chosen > 0: self.chosen -= 1 - InvalidateTheWorld.post() - return True - if ev.key in (pgl.K_DOWN, pgl.K_s): + return finish_event() + if ev.key in KEYS.DOWN: if self.chosen + 1 < len(self.card.actions): self.chosen += 1 - InvalidateTheWorld.post() - return True + return finish_event() return super(InfoAreaWidget, self).handle_event(ev)