def _handle_keydown_normal(self, event): if not self.game.menus.main.enabled and key_identified(event, config.MENU_KEY): self.game.menus.main.enable() return True if self.game.is_network_game(): if key_identified(event, config.SEND_TEXT_KEY): self._send_text_key_pressed() # Don't steal the key in any case return False
def _handle_keydown_normal(self, event): if key_identified(event, config.CREATE_PLAYER_KEY): self._create_player_key_pressed() elif key_identified(event, config.REMOVE_PLAYER_KEY): self._remove_chosen_player() elif key_identified(event, config.PREV_KEY): self._chosen_player_index -= 1 elif key_identified(event, config.NEXT_KEY): self._chosen_player_index += 1 return False
def chat_key_pressed(event): if key_identified(event, (0, pygame.K_BACKSPACE)): update_text(cur_text[0][:-1]) return for to_selected, key in [(False, config.SEND_TO_ALL_KEY), (True, config.SEND_TO_HOST_KEY)]: if key_identified(event, key): if self._send_text_msg(to_selected, cur_text[0]): self.game.update_message() self._handle_keydown = self._handle_keydown_normal return False if key_identified(event, config.CANCEL_KEY): self.game.update_message() self._handle_keydown = self._handle_keydown_normal return False try: key_value = event.unicode.encode('latin1') except UnicodeEncodeError: return False if len(key_value) != 1 or not 0x20 <= ord(key_value) < 0x80: return False update_text(cur_text[0] + key_value) return False
def worm_key_setter_handler(event): if key_identified(event, config.CREATE_PLAYER_KEY): self.game.set_text('Player creation cancelled') self._handle_keydown = self._handle_keydown_normal return False key_value = (0, event.key) keyname = key_name(key_value) if not config.ALLOW_SAME_KEYS and key_value in self.game.all_keys() + worm_keys: # Key already mapped if self.game.is_paused(): self.game.set_text('%s is already taken!' % (keyname,)) return False worm_keys.append(key_value) if len(worm_keys) == 1: self.game.set_text('%s is a nice choice! Now press <rightkey>' % (keyname,)) elif len(worm_keys) == 2: self.game.network.run_action_locally('create_local_player', worm_keys) self.game.network.run_action_remotely('create_player') self._handle_keydown = self._handle_keydown_normal return False
def _handle_keydown(self, event): if key_identified(event, config.CANCEL_KEY): self.game.unshow_credits() return True