Move keys to constants
[naja.git] / naja / widgets / info_area.py
index 317dfc631cf34ce52ce8d4aa0b7bf3f12be43d5e..4c79f07d330641123285efb5d7e928e32f7fee7b 100644 (file)
@@ -4,7 +4,7 @@ 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.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT, KEYS
 from naja.events import InvalidateTheWorld
 from naja.resources import resources
 from naja.resources.mutators import EIGHT_BIT
@@ -82,18 +82,21 @@ class InfoAreaWidget(Widget):
         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):
+            if ev.key in KEYS.SELECT:
+                action = self.card.actions[self.chosen]
+                if not action.check_available(self.state.gameboard.player):
+                    print "BEEP!"
+                    return True
+                action.perform_action(self.state.gameboard, self.card)
                 self.state.gameboard.change_mode()
-                self.card.actions[self.chosen].perform_action(
-                    self.state.gameboard, self.card)
                 InvalidateTheWorld.post()
                 return True
-            if ev.key in (pgl.K_UP, pgl.K_w):
+            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):
+            if ev.key in KEYS.DOWN:
                 if self.chosen + 1 < len(self.card.actions):
                     self.chosen += 1
                     InvalidateTheWorld.post()