Пример #1
0
    def _new_profile(self) -> None:
        # pylint: disable=cyclic-import
        from ba.internal import have_pro_options
        from bastd.ui.profile.edit import EditProfileWindow
        from bastd.ui.purchase import PurchaseWindow

        # 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):
            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.ui.set_main_menu_window(
            EditProfileWindow(
                existing_profile=None,
                in_main_menu=self._in_main_menu).get_root_widget())
Пример #2
0
 def _edit_profile(self) -> None:
     # pylint: disable=cyclic-import
     from bastd.ui.profile.edit import EditProfileWindow
     if self._selected_profile is None:
         ba.playsound(ba.getsound('error'))
         ba.screenmessage(ba.Lstr(resource='nothingIsSelectedErrorText'),
                          color=(1, 0, 0))
         return
     self._save_state()
     ba.containerwidget(edit=self._root_widget, transition='out_left')
     ba.app.ui.set_main_menu_window(
         EditProfileWindow(
             self._selected_profile,
             in_main_menu=self._in_main_menu).get_root_widget())
Пример #3
0
    def __init__(self,
                 edit_profile_window: EditProfileWindow,
                 transition: str = 'in_right'):
        from ba.internal import master_server_get
        self._r = 'editProfileWindow'

        self._width = 680
        self._height = 350
        uiscale = ba.app.uiscale
        self._base_scale = (2.05 if uiscale is ba.UIScale.SMALL else
                            1.5 if uiscale is ba.UIScale.MEDIUM else 1.2)
        self._upgrade_start_time: Optional[float] = None
        self._name = edit_profile_window.getname()
        self._edit_profile_window = weakref.ref(edit_profile_window)

        top_extra = 15 if uiscale is ba.UIScale.SMALL else 15
        super().__init__(root_widget=ba.containerwidget(
            size=(self._width, self._height + top_extra),
            toolbar_visibility='menu_currency',
            transition=transition,
            scale=self._base_scale,
            stack_offset=(0, 15) if uiscale is ba.UIScale.SMALL else (0, 0)))
        cancel_button = ba.buttonwidget(parent=self._root_widget,
                                        position=(52, 30),
                                        size=(155, 60),
                                        scale=0.8,
                                        autoselect=True,
                                        label=ba.Lstr(resource='cancelText'),
                                        on_activate_call=self._cancel)
        self._upgrade_button = ba.buttonwidget(
            parent=self._root_widget,
            position=(self._width - 190, 30),
            size=(155, 60),
            scale=0.8,
            autoselect=True,
            label=ba.Lstr(resource='upgradeText'),
            on_activate_call=self._on_upgrade_press)
        ba.containerwidget(edit=self._root_widget,
                           cancel_button=cancel_button,
                           start_button=self._upgrade_button,
                           selected_child=self._upgrade_button)

        ba.textwidget(parent=self._root_widget,
                      position=(self._width * 0.5, self._height - 38),
                      size=(0, 0),
                      text=ba.Lstr(resource=self._r +
                                   '.upgradeToGlobalProfileText'),
                      color=ba.app.title_color,
                      maxwidth=self._width * 0.45,
                      scale=1.0,
                      h_align='center',
                      v_align='center')

        ba.textwidget(parent=self._root_widget,
                      position=(self._width * 0.5, self._height - 100),
                      size=(0, 0),
                      text=ba.Lstr(resource=self._r +
                                   '.upgradeProfileInfoText'),
                      color=ba.app.infotextcolor,
                      maxwidth=self._width * 0.8,
                      scale=0.7,
                      h_align='center',
                      v_align='center')

        self._status_text = ba.textwidget(
            parent=self._root_widget,
            position=(self._width * 0.5, self._height - 160),
            size=(0, 0),
            text=ba.Lstr(resource=self._r + '.checkingAvailabilityText',
                         subs=[('${NAME}', self._name)]),
            color=(0.8, 0.4, 0.0),
            maxwidth=self._width * 0.8,
            scale=0.65,
            h_align='center',
            v_align='center')

        self._price_text = ba.textwidget(parent=self._root_widget,
                                         position=(self._width * 0.5,
                                                   self._height - 230),
                                         size=(0, 0),
                                         text='',
                                         color=(0.2, 1, 0.2),
                                         maxwidth=self._width * 0.8,
                                         scale=1.5,
                                         h_align='center',
                                         v_align='center')

        self._tickets_text: Optional[ba.Widget]
        if not ba.app.toolbars:
            self._tickets_text = ba.textwidget(
                parent=self._root_widget,
                position=(self._width * 0.9 - 5, self._height - 30),
                size=(0, 0),
                text=ba.charstr(ba.SpecialChar.TICKET) + '123',
                color=(0.2, 1, 0.2),
                maxwidth=100,
                scale=0.5,
                h_align='right',
                v_align='center')
        else:
            self._tickets_text = None

        master_server_get('bsGlobalProfileCheck', {
            'name': self._name,
            'b': ba.app.build_number
        },
                          callback=ba.WeakCall(self._profile_check_result))
        self._cost = _ba.get_account_misc_read_val('price.global_profile', 500)
        self._status: Optional[str] = 'waiting'
        self._update_timer = ba.Timer(1.0,
                                      ba.WeakCall(self._update),
                                      timetype=ba.TimeType.REAL,
                                      repeat=True)
        self._update()