示例#1
0
    def _new_profile(self) -> None:
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui.profile import edit as pedit
        from bastd.ui import purchase

        # Limit to a handful profiles if they don't have pro-options.
        max_non_pro_profiles = _ba.get_account_misc_read_val('mnpp', 5)
        assert self._profiles is not None
        if (not have_pro_options()
                and len(self._profiles) >= max_non_pro_profiles):
            purchase.PurchaseWindow(items=['pro'],
                                    header_text=ba.Lstr(
                                        resource='unlockThisProfilesText',
                                        subs=[('${NUM}',
                                               str(max_non_pro_profiles))]))
            return

        # Clamp at 100 profiles (otherwise the server will and that's less
        # elegant looking).
        if len(self._profiles) > 100:
            ba.screenmessage(
                ba.Lstr(translate=('serverResponses',
                                   'Max number of profiles reached.')),
                color=(1, 0, 0))
            ba.playsound(ba.getsound('error'))
            return

        self._save_state()
        ba.containerwidget(edit=self._root_widget, transition='out_left')
        ba.app.main_menu_window = (pedit.EditProfileWindow(
            existing_profile=None,
            in_main_menu=self._in_main_menu).get_root_widget())
示例#2
0
    def _share_playlist(self) -> None:
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui import purchase
        if not have_pro_options():
            purchase.PurchaseWindow(items=['pro'])
            return

        # Gotta be signed in for this to work.
        if _ba.get_account_state() != 'signed_in':
            ba.screenmessage(ba.Lstr(resource='notSignedInErrorText'),
                             color=(1, 0, 0))
            ba.playsound(ba.getsound('error'))
            return
        if self._selected_playlist_name == '__default__':
            ba.playsound(ba.getsound('error'))
            ba.screenmessage(ba.Lstr(resource=self._r +
                                     '.cantShareDefaultText'),
                             color=(1, 0, 0))
            return

        if self._selected_playlist_name is None:
            return

        _ba.add_transaction(
            {
                'type': 'SHARE_PLAYLIST',
                'expire_time': time.time() + 5,
                'playlistType': self._pvars.config_name,
                'playlistName': self._selected_playlist_name
            },
            callback=ba.WeakCall(self._on_share_playlist_response,
                                 self._selected_playlist_name))
        _ba.run_transactions()
        ba.screenmessage(ba.Lstr(resource='sharingText'))
示例#3
0
 def _edit_soundtrack_with_sound(self) -> None:
     # pylint: disable=cyclic-import
     from ba.internal import have_pro_options
     from bastd.ui import purchase
     if not have_pro_options():
         purchase.PurchaseWindow(items=['pro'])
         return
     ba.playsound(ba.getsound('swish'))
     self._edit_soundtrack()
示例#4
0
 def _new_soundtrack(self) -> None:
     # pylint: disable=cyclic-import
     from ba.internal import have_pro_options
     from bastd.ui import purchase
     from bastd.ui.soundtrack import edit as stedit
     if not have_pro_options():
         purchase.PurchaseWindow(items=['pro'])
         return
     self._save_state()
     ba.containerwidget(edit=self._root_widget, transition='out_left')
     stedit.SoundtrackEditWindow(existing_soundtrack=None)
示例#5
0
    def _duplicate_soundtrack(self) -> None:
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui import purchase
        if not have_pro_options():
            purchase.PurchaseWindow(items=['pro'])
            return
        cfg = ba.app.config
        cfg.setdefault('Soundtracks', {})

        if self._selected_soundtrack is None:
            return
        sdtk: Dict[str, Any]
        if self._selected_soundtrack == '__default__':
            sdtk = {}
        else:
            sdtk = cfg['Soundtracks'][self._selected_soundtrack]

        # Find a valid dup name that doesn't exist.
        test_index = 1
        copy_text = ba.Lstr(resource='copyOfText').evaluate()
        # Get just 'Copy' or whatnot.
        copy_word = copy_text.replace('${NAME}', '').strip()
        base_name = self._get_soundtrack_display_name(
            self._selected_soundtrack).evaluate()
        assert isinstance(base_name, str)

        # If it looks like a copy, strip digits and spaces off the end.
        if copy_word in base_name:
            while base_name[-1].isdigit() or base_name[-1] == ' ':
                base_name = base_name[:-1]
        while True:
            if copy_word in base_name:
                test_name = base_name
            else:
                test_name = copy_text.replace('${NAME}', base_name)
            if test_index > 1:
                test_name += ' ' + str(test_index)
            if test_name not in cfg['Soundtracks']:
                break
            test_index += 1

        cfg['Soundtracks'][test_name] = copy.deepcopy(sdtk)
        cfg.commit()
        self._refresh(select_soundtrack=test_name)
示例#6
0
    def _delete_playlist(self) -> None:
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui import purchase
        from bastd.ui import confirm
        if not have_pro_options():
            purchase.PurchaseWindow(items=['pro'])
            return

        if self._selected_playlist_name is None:
            return
        if self._selected_playlist_name == '__default__':
            ba.playsound(ba.getsound('error'))
            ba.screenmessage(
                ba.Lstr(resource=self._r + '.cantDeleteDefaultText'))
        else:
            confirm.ConfirmWindow(
                ba.Lstr(resource=self._r + '.deleteConfirmText',
                        subs=[('${LIST}', self._selected_playlist_name)]),
                self._do_delete_playlist, 450, 150)
示例#7
0
 def _edit_playlist(self) -> None:
     # pylint: disable=cyclic-import
     from ba.internal import have_pro_options
     from bastd.ui.playlist import editcontroller
     from bastd.ui import purchase
     if not have_pro_options():
         purchase.PurchaseWindow(items=['pro'])
         return
     if self._selected_playlist_name is None:
         return
     if self._selected_playlist_name == '__default__':
         ba.playsound(ba.getsound('error'))
         ba.screenmessage(ba.Lstr(resource=self._r +
                                  '.cantEditDefaultText'))
         return
     self._save_playlist_selection()
     editcontroller.PlaylistEditController(
         existing_playlist_name=self._selected_playlist_name,
         sessiontype=self._sessiontype)
     ba.containerwidget(edit=self._root_widget, transition='out_left')
示例#8
0
    def _edit_soundtrack(self) -> None:
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui import purchase
        from bastd.ui.soundtrack import edit as stedit
        if not have_pro_options():
            purchase.PurchaseWindow(items=['pro'])
            return
        if self._selected_soundtrack is None:
            return
        if self._selected_soundtrack == '__default__':
            ba.playsound(ba.getsound('error'))
            ba.screenmessage(ba.Lstr(resource=self._r +
                                     '.cantEditDefaultText'),
                             color=(1, 0, 0))
            return

        self._save_state()
        ba.containerwidget(edit=self._root_widget, transition='out_left')
        ba.app.main_menu_window = (stedit.SoundtrackEditWindow(
            existing_soundtrack=self._selected_soundtrack).get_root_widget())
示例#9
0
    def _new_playlist(self) -> None:
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui.playlist import editcontroller
        from bastd.ui import purchase
        if not have_pro_options():
            purchase.PurchaseWindow(items=['pro'])
            return

        # Clamp at our max playlist number.
        if len(ba.app.config[self._config_name_full]) > self._max_playlists:
            ba.screenmessage(
                ba.Lstr(translate=('serverResponses',
                                   'Max number of playlists reached.')),
                color=(1, 0, 0))
            ba.playsound(ba.getsound('error'))
            return

        # In case they cancel so we can return to this state.
        self._save_playlist_selection()

        # Kick off the edit UI.
        editcontroller.PlaylistEditController(sessiontype=self._sessiontype)
        ba.containerwidget(edit=self._root_widget, transition='out_left')
示例#10
0
    def _duplicate_playlist(self) -> None:
        # pylint: disable=too-many-branches
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui import purchase
        if not have_pro_options():
            purchase.PurchaseWindow(items=['pro'])
            return
        if self._selected_playlist_name is None:
            return
        plst: Optional[List[Dict[str, Any]]]
        if self._selected_playlist_name == '__default__':
            plst = self._pvars.get_default_list_call()
        else:
            plst = ba.app.config[self._config_name_full].get(
                self._selected_playlist_name)
            if plst is None:
                ba.playsound(ba.getsound('error'))
                return

        # clamp at our max playlist number
        if len(ba.app.config[self._config_name_full]) > self._max_playlists:
            ba.screenmessage(
                ba.Lstr(translate=('serverResponses',
                                   'Max number of playlists reached.')),
                color=(1, 0, 0))
            ba.playsound(ba.getsound('error'))
            return

        copy_text = ba.Lstr(resource='copyOfText').evaluate()
        # get just 'Copy' or whatnot
        copy_word = copy_text.replace('${NAME}', '').strip()
        # find a valid dup name that doesn't exist

        test_index = 1
        base_name = self._get_playlist_display_name(
            self._selected_playlist_name).evaluate()

        # If it looks like a copy, strip digits and spaces off the end.
        if copy_word in base_name:
            while base_name[-1].isdigit() or base_name[-1] == ' ':
                base_name = base_name[:-1]
        while True:
            if copy_word in base_name:
                test_name = base_name
            else:
                test_name = copy_text.replace('${NAME}', base_name)
            if test_index > 1:
                test_name += ' ' + str(test_index)
            if test_name not in ba.app.config[self._config_name_full]:
                break
            test_index += 1

        _ba.add_transaction({
            'type': 'ADD_PLAYLIST',
            'playlistType': self._pvars.config_name,
            'playlistName': test_name,
            'playlist': copy.deepcopy(plst)
        })
        _ba.run_transactions()

        ba.playsound(ba.getsound('gunCocking'))
        self._refresh(select_playlist=test_name)
示例#11
0
 def _update(self) -> None:
     from ba.internal import have_pro_options
     have = have_pro_options()
     for lock in self._lock_images:
         ba.imagewidget(edit=lock, opacity=0.0 if have else 1.0)