Ejemplo n.º 1
0
    def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if not self.chatting:
                if self.keys_held[pygame.K_LSHIFT]:  # Shift + key
                    if event.key == pygame.K_q:
                        self.return_mode = 2
                else:
                    if event.key == pygame.K_SPACE:  # Space - transfer level
                        newlevel_data = self.map.transfer_level(
                            self.player.x, self.player.y)
                        if newlevel_data:
                            self.conn.send("xfer_map|" + newlevel_data[1])
                            self.load_map(newlevel_data[1])
                            self.player.set_pos(int(newlevel_data[2]),
                                                int(newlevel_data[3]))
                            self.update_camera_plpos()

                    elif event.key == pygame.K_PAGEUP:  # PageUp - scroll chatlog
                        self.chatlog.scroll(4)
                    elif event.key == pygame.K_PAGEDOWN:  # PageDown - scroll chatlog
                        self.chatlog.scroll(-4)

                    elif event.key == pygame.K_RETURN:  # Enter - chat/return to menu
                        if self.return_mode == 0:
                            self.chat_toggle(True)
                        else:
                            self.return_mode = 2
            else:
                # Player chat
                if event.key == pygame.K_RETURN:  # Enter - send message
                    tmp_chat = self.chat_input.strip()
                    if tmp_chat:
                        self.conn.send("pl_chat|" + tmp_chat)
                    self.chat_toggle(False)

                elif event.key == pygame.K_BACKSPACE:
                    self.chat_input = self.chat_input[:-1]
                elif event.key == pygame.K_ESCAPE:
                    self.chat_toggle(False)
                else:
                    self.chat_input += event.unicode

                self.chatlog.msg_input = self.chat_input

        return Screen.handle_event(self, event)
Ejemplo n.º 2
0
    def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if not self.inputting:
                if event.key == pygame.K_w or event.key == pygame.K_UP:
                    self.menu_selected -= 1
                    if self.menu_selected < 0:
                        self.menu_selected = len(self.menu_buttons) - 1

                elif event.key == pygame.K_s or event.key == pygame.K_DOWN:
                    self.menu_selected += 1
                    if self.menu_selected > len(self.menu_buttons) - 1:
                        self.menu_selected = 0

            else:
                # Currently selected button
                sel_button = self.menu_buttons[self.menu_selected]

                if not event.key == pygame.K_RETURN:
                    if event.key == pygame.K_BACKSPACE:
                        sel_button.input_text = sel_button.input_text[:-1]
                        self.update_backg_size()

                    elif event.key == pygame.K_ESCAPE:
                        self.inputting = False

                    elif len(sel_button.input_text) < sel_button.input_maxlen:
                        if not sel_button.input_number:
                            sel_button.input_text += event.unicode
                        else:
                            try:
                                sel_button.input_text += str(int(
                                    event.unicode))
                            except ValueError:
                                pass

                        self.update_backg_size()

            if event.key == pygame.K_RETURN:
                self.button_press()

        return Screen.handle_event(self, event)