예제 #1
0
 def check_special_offer() -> None:
     from bastd.ui.specialoffer import show_offer
     config = self.config
     if ('pendingSpecialOffer' in config and _ba.get_public_login_id()
             == config['pendingSpecialOffer']['a']):
         self.special_offer = config['pendingSpecialOffer']['o']
         show_offer()
예제 #2
0
    def _update_linked_accounts_text(self) -> None:
        if self._linked_accounts_text is None:
            return

        # if this is not present, we haven't had contact from the server so
        # let's not proceed..
        if _ba.get_public_login_id() is None:
            num = int(time.time()) % 4
            accounts_str = num * '.' + (4 - num) * ' '
        else:
            accounts = _ba.get_v1_account_misc_read_val_2('linkedAccounts', [])
            # our_account = _bs.get_v1_account_display_string()
            # accounts = [a for a in accounts if a != our_account]
            # accounts_str = u', '.join(accounts) if accounts else
            # ba.Lstr(translate=('settingNames', 'None'))
            # UPDATE - we now just print the number here; not the actual
            # accounts
            # (they can see that in the unlink section if they're curious)
            accounts_str = str(max(0, len(accounts) - 1))
        ba.textwidget(edit=self._linked_accounts_text,
                      text=ba.Lstr(value='${L} ${A}',
                                   subs=[('${L}',
                                          ba.Lstr(resource=self._r +
                                                  '.linkedAccountsText')),
                                         ('${A}', accounts_str)]))
예제 #3
0
 def _have_unlinkable_accounts(self) -> bool:
     # if this is not present, we haven't had contact from the server so
     # let's not proceed..
     if _ba.get_public_login_id() is None:
         return False
     accounts = _ba.get_v1_account_misc_read_val_2('linkedAccounts', [])
     return len(accounts) > 1
예제 #4
0
 def _on_more_press(self) -> None:
     our_login_id = _ba.get_public_login_id()
     # our_login_id = _bs.get_account_misc_read_val_2(
     #     'resolvedAccountID', None)
     if not self._can_do_more_button or our_login_id is None:
         ba.playsound(ba.getsound('error'))
         ba.screenmessage(ba.Lstr(resource='unavailableText'),
                          color=(1, 0, 0))
         return
     if self._season is None:
         season_str = ''
     else:
         season_str = (
             '&season=' +
             ('all_time' if self._season == 'a' else self._season))
     if self._league_url_arg != '':
         league_str = '&league=' + self._league_url_arg
     else:
         league_str = ''
     ba.open_url(_ba.get_master_server_address() +
                 '/highscores?list=powerRankings&v=2' + league_str +
                 season_str + '&player=' + our_login_id)
예제 #5
0
def show_offer() -> bool:
    """(internal)"""
    try:
        from bastd.ui import feedback
        app = ba.app

        # Space things out a bit so we don't hit the poor user with an ad and
        # then an in-game offer.
        has_been_long_enough_since_ad = True
        if (app.ads.last_ad_completion_time is not None and
            (ba.time(ba.TimeType.REAL) - app.ads.last_ad_completion_time <
             30.0)):
            has_been_long_enough_since_ad = False

        if app.special_offer is not None and has_been_long_enough_since_ad:

            # Special case: for pro offers, store this in our prefs so we
            # can re-show it if the user kills us (set phasers to 'NAG'!!!).
            if app.special_offer.get('item') == 'pro_fullprice':
                cfg = app.config
                cfg['pendingSpecialOffer'] = {
                    'a': _ba.get_public_login_id(),
                    'o': app.special_offer
                }
                cfg.commit()

            with ba.Context('ui'):
                if app.special_offer['item'] == 'rating':
                    feedback.ask_for_rating()
                else:
                    SpecialOfferWindow(app.special_offer)

            app.special_offer = None
            return True
    except Exception:
        ba.print_exception('Error showing offer.')

    return False
    def __init__(self, origin_widget: ba.Widget = None):
        scale_origin: Optional[tuple[float, float]]
        if origin_widget is not None:
            self._transition_out = 'out_scale'
            scale_origin = origin_widget.get_screen_space_center()
            transition = 'in_scale'
        else:
            self._transition_out = 'out_right'
            scale_origin = None
            transition = 'in_right'
        bg_color = (0.4, 0.4, 0.5)
        self._width = 540
        self._height = 350
        self._scroll_width = 400
        self._scroll_height = 200
        uiscale = ba.app.ui.uiscale
        base_scale = (2.0 if uiscale is ba.UIScale.SMALL else
                      1.6 if uiscale is ba.UIScale.MEDIUM else 1.1)
        super().__init__(root_widget=ba.containerwidget(
            size=(self._width, self._height),
            transition=transition,
            scale=base_scale,
            scale_origin_stack_offset=scale_origin,
            stack_offset=(0, -10) if uiscale is ba.UIScale.SMALL else (0, 0)))
        self._cancel_button = ba.buttonwidget(parent=self._root_widget,
                                              position=(30, self._height - 50),
                                              size=(50, 50),
                                              scale=0.7,
                                              label='',
                                              color=bg_color,
                                              on_activate_call=self._cancel,
                                              autoselect=True,
                                              icon=ba.gettexture('crossOut'),
                                              iconscale=1.2)
        ba.textwidget(
            parent=self._root_widget,
            position=(self._width * 0.5, self._height * 0.88),
            size=(0, 0),
            text=ba.Lstr(
                resource='accountSettingsWindow.unlinkAccountsInstructionsText'
            ),
            maxwidth=self._width * 0.7,
            color=ba.app.ui.infotextcolor,
            h_align='center',
            v_align='center')
        ba.containerwidget(edit=self._root_widget,
                           cancel_button=self._cancel_button)

        self._scrollwidget = ba.scrollwidget(
            parent=self._root_widget,
            highlight=False,
            position=((self._width - self._scroll_width) * 0.5,
                      self._height - 85 - self._scroll_height),
            size=(self._scroll_width, self._scroll_height))
        ba.containerwidget(edit=self._scrollwidget, claims_left_right=True)
        self._columnwidget = ba.columnwidget(parent=self._scrollwidget,
                                             border=2,
                                             margin=0,
                                             left_border=10)

        our_login_id = _ba.get_public_login_id()
        if our_login_id is None:
            entries = []
        else:
            account_infos = _ba.get_account_misc_read_val_2(
                'linkedAccounts2', [])
            entries = [{
                'name': ai['d'],
                'id': ai['id']
            } for ai in account_infos if ai['id'] != our_login_id]

        # (avoid getting our selection stuck on an empty column widget)
        if not entries:
            ba.containerwidget(edit=self._scrollwidget, selectable=False)
        for i, entry in enumerate(entries):
            txt = ba.textwidget(parent=self._columnwidget,
                                selectable=True,
                                text=entry['name'],
                                size=(self._scroll_width - 30, 30),
                                autoselect=True,
                                click_activate=True,
                                on_activate_call=ba.Call(
                                    self._on_entry_selected, entry))
            ba.widget(edit=txt, left_widget=self._cancel_button)
            if i == 0:
                ba.widget(edit=txt, up_widget=self._cancel_button)