Esempio n. 1
0
 def add_game_cancelled(self) -> None:
     """(internal)"""
     from bastd.ui.playlist import edit as pedit
     ba.containerwidget(edit=ba.app.main_menu_window,
                        transition='out_right')
     ba.app.main_menu_window = (pedit.PlaylistEditWindow(
         editcontroller=self, transition='in_left').get_root_widget())
Esempio n. 2
0
    def _edit_game_done(self, config: Optional[Dict[str, Any]]) -> None:
        from bastd.ui.playlist import edit as pedit
        from bastd.ui.playlist import addgame
        from ba.internal import get_type_name
        if config is None:
            # If we were editing, go back to our list.
            if self._editing_game:
                ba.playsound(ba.getsound('powerdown01'))
                ba.containerwidget(edit=ba.app.main_menu_window,
                                   transition='out_right')
                ba.app.main_menu_window = (pedit.PlaylistEditWindow(
                    editcontroller=self,
                    transition='in_left').get_root_widget())

            # Otherwise we were adding; go back to the add type choice list.
            else:
                ba.containerwidget(edit=ba.app.main_menu_window,
                                   transition='out_right')
                ba.app.main_menu_window = (addgame.PlaylistAddGameWindow(
                    editcontroller=self,
                    transition='in_left').get_root_widget())
        else:
            # Make sure type is in there.
            assert self._editing_game_type is not None
            config['type'] = get_type_name(self._editing_game_type)

            if self._editing_game:
                self._playlist[self._selected_index] = copy.deepcopy(config)
            else:
                # Add a new entry to the playlist.
                insert_index = min(len(self._playlist),
                                   self._selected_index + 1)
                self._playlist.insert(insert_index, copy.deepcopy(config))
                self._selected_index = insert_index

            ba.playsound(ba.getsound('gunCocking'))
            ba.containerwidget(edit=ba.app.main_menu_window,
                               transition='out_right')
            ba.app.main_menu_window = (pedit.PlaylistEditWindow(
                editcontroller=self, transition='in_left').get_root_widget())
Esempio n. 3
0
    def __init__(self,
                 sessiontype: Type[ba.Session],
                 existing_playlist_name: str = None,
                 transition: str = 'in_right',
                 playlist: List[Dict[str, Any]] = None,
                 playlist_name: str = None):
        from ba.internal import preload_map_preview_media, filter_playlist
        from bastd.ui import playlist as playlistui
        from bastd.ui.playlist import edit as peditui

        appconfig = ba.app.config

        # Since we may be showing our map list momentarily,
        # lets go ahead and preload all map preview textures.
        preload_map_preview_media()
        self._sessiontype = sessiontype

        self._editing_game = False
        self._editing_game_type: Optional[Type[ba.GameActivity]] = None
        self._pvars = playlistui.PlaylistTypeVars(sessiontype)
        self._existing_playlist_name = existing_playlist_name
        self._config_name_full = self._pvars.config_name + ' Playlists'

        # Make sure config exists.
        if self._config_name_full not in appconfig:
            appconfig[self._config_name_full] = {}

        self._selected_index = 0
        if existing_playlist_name:
            self._name = existing_playlist_name

            # Filter out invalid games.
            self._playlist = filter_playlist(
                appconfig[self._pvars.config_name +
                          ' Playlists'][existing_playlist_name],
                sessiontype=sessiontype,
                remove_unowned=False)
            self._edit_ui_selection = None
        else:
            if playlist is not None:
                self._playlist = playlist
            else:
                self._playlist = []
            if playlist_name is not None:
                self._name = playlist_name
            else:

                # Find a good unused name.
                i = 1
                while True:
                    self._name = (
                        self._pvars.default_new_list_name.evaluate() +
                        ((' ' + str(i)) if i > 1 else ''))
                    if self._name not in appconfig[self._pvars.config_name +
                                                   ' Playlists']:
                        break
                    i += 1

            # Also we want it to start with 'add' highlighted since its empty
            # and that's all they can do.
            self._edit_ui_selection = 'add_button'

        ba.app.main_menu_window = (peditui.PlaylistEditWindow(
            editcontroller=self, transition=transition).get_root_widget())