Exemple #1
0
    def on_key_press(self, key, modifiers) -> bool:
        """Manage the key press event.

        Update the selected move when pressing UP or BOTTOM.
        Choose the selected move when pressing ENTER or go back to the
        previous menu.

        :param key: The pressed key.
        :param modifiers: The pressed modifiers.
        :return Whether the event has been handled.
        """

        event_handled = False
        if self._is_visible:
            if is_key_cancel(key) or (is_key_action(key) and self._selected
                                      == len(self._actions) - 1):
                self.do(
                    CallFunc(self.toggle_apparition) + Delay(0.3) +
                    CallFunc(self.parent.show_actions))
                event_handled = True
            elif is_key_action(key):
                self.parent.fight_action(self._pokemon.moves[self._selected])
                event_handled = True
            elif is_key_up(key) and self._selected > 0:
                self._selected = self._selected - 1
                event_handled = True
            elif is_key_down(key) and self._selected < len(self._actions) - 1:
                self._selected = self._selected + 1
                event_handled = True

            self._update_selected_action()

            return event_handled
Exemple #2
0
    def on_key_press(self, key, modifiers) -> bool:
        """Manage the key press event.

        Update the selected action when pressing UP or BOTTOM.
        Activate the selected action when pressing ENTER.

        :param key: The pressed key.
        :param modifiers: The pressed modifiers.
        :return Whether the event has been handled.
        """

        event_handled = False

        if is_key_up(key) and self._choice > 0 and (self._game_state
                                                    or self._choice > 1):
            self._choice -= 1
            event_handled = True
        elif is_key_down(key) and self._choice < len(ActionsLayer.ACTIONS) - 1:
            self._choice += 1
            event_handled = True
        elif is_key_action(key):
            if self._choice == ActionsLayer.CONTINUE:
                self.parent.continue_game()
            elif self._choice == ActionsLayer.NEW_GAME:
                self.parent.new_game()
            else:
                self.parent.settings()
            event_handled = True

        self._update_screen()

        return event_handled
Exemple #3
0
    def on_key_press(self, key, modifiers) -> bool:
        """Manage the key press event.

        Show the next part of the text if there is some left by pressing ENTER.
        Call the callback function if there is some and send the potential
        answer to the question.

        :param key: The pressed key.
        :param modifiers: The pressed modifiers.
        :return Whether the event has been handled.
        """

        event_handled = False

        if (is_key_action(key) or is_key_cancel(key)) and self._cursor.visible:
            if self._end_index != len(self._split_text):
                self._start_index = self._end_index
                self._update_text()
            elif self._end_index == len(self._split_text) and len(
                    self._text) > self._text_index + 1:
                self._text_index += 1
                self._start_index = 0
                self._end_index = 0
                self._split_text = self._text[self._text_index].split(" ")
                self._update_text()
            else:
                self._cursor.visible = False
                if self._callback:
                    if self._selected_choice is None:
                        self._callback()
            event_handled = True
        elif is_key_action(key) and not self._cursor.visible and self._choices:
            self._choices_cursor.visible = False
            self._choices_background.visible = False
            for choice in self._choices_labels:
                self.remove(choice)
            self._choices_labels = []

            self._callback(self._selected_choice)
            event_handled = True
        elif is_key_up(key) and self._selected_choice is not None:
            self._selected_choice = 0 if self._selected_choice <= 1 else self._selected_choice - 1
            self._update_choices_cursor()
            event_handled = True
        elif is_key_down(key) and self._selected_choice is not None:
            self._selected_choice = len(
                self._choices) - 1 if self._selected_choice >= len(
                    self._choices) - 2 else self._selected_choice + 1
            self._update_choices_cursor()
            event_handled = True

        return event_handled
Exemple #4
0
    def on_key_press(self, key, modifiers) -> bool:
        """Manage the key press event.

        Update the selected action when pressing UP or BOTTOM.
        Change the value of the settings with RIGHT or LEFT.

        :param key: The pressed key.
        :param modifiers: The pressed modifiers.
        :return Whether the event has been handled.
        """

        event_handled = False

        if is_key_up(key) and self._choice > 0:
            self._choice -= 1
            event_handled = True
        elif is_key_down(key) and self._choice < len(self._actions) - 1:
            self._choice += 1
            event_handled = True
        elif self._actions[ActionsLayer.LANGUAGE].get(
                ActionsLayer.SELECTED_SPRITE).visible and (is_key_left(key) or
                                                           is_key_right(key)):
            if is_key_left(key):
                self._selected_language = self._selected_language - 1 if self._selected_language > 0 else len(
                    LanguageEnum) - 1
            elif is_key_right(key):
                self._selected_language = self._selected_language + 1 if self._selected_language < len(
                    LanguageEnum) - 1 else 0
            self.get(str(ActionsLayer.LANGUAGE)).get(
                ActionsLayer.LANGUAGE_VALUE).element.text = I18n().get(
                    "SETTINGS.LANGUAGE.{0}".format(
                        LanguageEnum.from_index(self._selected_language).name))
            event_handled = True
        elif (is_key_action(key) and self._actions[ActionsLayer.CANCEL].get(
                ActionsLayer.SELECTED_SPRITE).visible) or is_key_cancel(key):
            new_settings = {
                LanguageEnum: LanguageEnum.from_index(self._selected_language)
            }
            self.parent.cancel_settings(new_settings)
            event_handled = True

        self._update_screen()

        return event_handled
Exemple #5
0
    def on_key_press(self, key, modifiers) -> bool:
        """Manage the key press event.

        Update the selected action when pressing UP or BOTTOM.
        Activate the selected action when pressing ENTER.

        :param key: The pressed key.
        :param modifiers: The pressed modifiers.
        :return Whether the event has been handled.
        """

        event_handled = False

        if self._is_visible:
            if is_key_up(key) and self._selected.value < 3:
                self._selected = ActionEnum(self._selected.value + 1)
                event_handled = True
            elif is_key_down(key) and self._selected.value > 0:
                self._selected = ActionEnum(self._selected.value - 1)
                event_handled = True
            elif is_key_action(key):
                if self._selected == ActionEnum.FIGHT:
                    self.toggle_apparition()
                    self.parent.show_moves()
                    event_handled = True
                elif self._selected == ActionEnum.PKMN:
                    self.parent.show_infos()
                    event_handled = True
                elif self._selected == ActionEnum.RUN:
                    self.toggle_apparition()
                    self.parent.run_action()
                    event_handled = True

            self._update_selection()

        return event_handled
Exemple #6
0
    def on_key_press(self, key, modifiers) -> bool:
        """Manage the key press event.

        Update the selected action when pressing UP or BOTTOM.
        Activate the selected action when pressing ENTER.

        :param key: The pressed key.
        :param modifiers: The pressed modifiers.
        :return Whether the event has been handled.
        """

        event_handled = False
        if is_key_left(key) and self._selected_action > 0:
            self._selected_action -= 1
            event_handled = True
        elif is_key_right(key) and self._selected_action < len(
                self._available_actions) - 1:
            self._selected_action += 1
            event_handled = True
        elif is_key_up(
                key
        ) and self._pkmn_infos_type == PkmnInfosTypeEnum.NEW_MOVE and self._selected_action > 0:
            self._selected_action -= 1
            event_handled = True
        elif is_key_down(
                key
        ) and self._pkmn_infos_type == PkmnInfosTypeEnum.NEW_MOVE and self._selected_action < len(
                self._available_actions) - 1:
            self._selected_action += 1
            event_handled = True
        elif is_key_action(key):
            if self._available_actions[
                    self._selected_action] == ActionEnum.CANCEL:
                self.parent.cancel()
                event_handled = True
            elif self._available_actions[
                    self._selected_action] == ActionEnum.PREVIOUS:
                self.parent.next_previous_pokemon(ActionEnum.PREVIOUS)
                event_handled = True
            elif self._available_actions[
                    self._selected_action] == ActionEnum.NEXT:
                self.parent.next_previous_pokemon(ActionEnum.NEXT)
                event_handled = True
            elif self._available_actions[
                    self._selected_action] == ActionEnum.SHIFT:
                self.parent.shift(self._pokemon)
                event_handled = True
            elif self._available_actions[
                    self._selected_action] == ActionEnum.NEW_MOVE:
                self.parent.cancel()
                event_handled = True
            elif self._available_actions[self._selected_action] in [
                    ActionEnum.MOVE_1, ActionEnum.MOVE_2, ActionEnum.MOVE_3,
                    ActionEnum.MOVE_4
            ]:
                self.parent.cancel(
                    [self._pokemon.moves[self._selected_action]])
                event_handled = True
        elif is_key_cancel(key):
            self.parent.cancel()
            event_handled = True

        self._update_screen()

        return event_handled