Example #1
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'))
Example #2
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())
Example #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()
Example #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)
Example #5
0
 def _custom_colors_names_press(self) -> None:
     from ba.internal import have_pro
     from bastd.ui import account as accountui
     from bastd.ui import teamnamescolors
     from bastd.ui import purchase
     if not have_pro():
         if _ba.get_account_state() != 'signed_in':
             accountui.show_sign_in_prompt()
         else:
             purchase.PurchaseWindow(items=['pro'])
         self._transition_out()
         return
     assert self._custom_colors_names_button
     teamnamescolors.TeamNamesColorsWindow(
         scale_origin=self._custom_colors_names_button.
         get_screen_space_center())
Example #6
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)
Example #7
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)
Example #8
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')
Example #9
0
    def _select_other(self) -> None:
        from bastd.ui import purchase

        # Requires pro.
        if not ba.app.accounts_v1.have_pro():
            purchase.PurchaseWindow(items=['pro'])
            self._transition_out()
            return
        ColorPickerExact(parent=self._parent,
                         position=self._position,
                         initial_color=self._initial_color,
                         delegate=self._delegate,
                         scale=self._scale,
                         offset=self._offset,
                         tag=self._tag)

        # New picker now 'owns' the delegate; we shouldn't send it any
        # more messages.
        self._delegate = None
        self._transition_out()
Example #10
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())
Example #11
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')
Example #12
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)