def _update(self) -> None: # If they want us to close once we're signed in, do so. if self._close_once_signed_in and self._signed_in: self._back() return # Hmm should update this to use get_account_state_num. # Theoretically if we switch from one signed-in account to another # in the background this would break. account_state_num = _ba.get_account_state_num() account_state = _ba.get_account_state() show_linked = (self._signed_in and _ba.get_account_misc_read_val( 'allowAccountLinking2', False)) if (account_state_num != self._account_state_num or self._show_linked != show_linked or self._needs_refresh): self._show_linked = show_linked self._account_state_num = account_state_num self._signed_in = (account_state == 'signed_in') self._refresh() # Go ahead and refresh some individual things # that may change under us. self._update_linked_accounts_text() self._update_unlink_accounts_button() self._refresh_campaign_progress_text() self._refresh_achievements() self._refresh_tickets_text() self._refresh_account_name_text()
def __init__(self, transition: Optional[str] = 'in_right'): # pylint: disable=cyclic-import import threading from bastd.mainmenu import MainMenuSession self._in_game = not isinstance(_ba.get_foreground_host_session(), MainMenuSession) # Preload some modules we use in a background thread so we won't # have a visual hitch when the user taps them. threading.Thread(target=self._preload_modules).start() if not self._in_game: ba.set_analytics_screen('Main Menu') self._show_remote_app_info_on_first_launch() # Make a vanilla container; we'll modify it to our needs in refresh. super().__init__(root_widget=ba.containerwidget( transition=transition, toolbar_visibility='menu_minimal_no_back' if self. _in_game else 'menu_minimal_no_back')) # Grab this stuff in case it changes. self._is_demo = ba.app.demo_mode self._is_arcade = ba.app.arcade_mode self._is_iircade = ba.app.iircade_mode self._tdelay = 0.0 self._t_delay_inc = 0.02 self._t_delay_play = 1.7 self._p_index = 0 self._use_autoselect = True self._button_width = 200.0 self._button_height = 45.0 self._width = 100.0 self._height = 100.0 self._demo_menu_button: Optional[ba.Widget] = None self._gather_button: Optional[ba.Widget] = None self._start_button: Optional[ba.Widget] = None self._watch_button: Optional[ba.Widget] = None self._gc_button: Optional[ba.Widget] = None self._how_to_play_button: Optional[ba.Widget] = None self._credits_button: Optional[ba.Widget] = None self._settings_button: Optional[ba.Widget] = None self._store_char_tex = self._get_store_char_tex() self._refresh() self._restore_state() # Keep an eye on a few things and refresh if they change. self._account_state = _ba.get_account_state() self._account_state_num = _ba.get_account_state_num() self._account_type = (_ba.get_account_type() if self._account_state == 'signed_in' else None) self._refresh_timer = ba.Timer(1.0, ba.WeakCall(self._check_refresh), repeat=True, timetype=ba.TimeType.REAL)
def __init__(self, transition: Optional[str] = 'in_right'): # pylint: disable=cyclic-import from bastd import mainmenu self._in_game = not isinstance(_ba.get_foreground_host_session(), mainmenu.MainMenuSession) if not self._in_game: ba.set_analytics_screen('Main Menu') self._show_remote_app_info_on_first_launch() # Make a vanilla container; we'll modify it to our needs in refresh. super().__init__(root_widget=ba.containerwidget( transition=transition, toolbar_visibility='menu_minimal_no_back' if self. _in_game else 'menu_minimal_no_back')) self._is_kiosk = ba.app.kiosk_mode self._tdelay = 0.0 self._t_delay_inc = 0.02 self._t_delay_play = 1.7 self._p_index = 0 self._use_autoselect = True self._button_width = 200.0 self._button_height = 45.0 self._width = 100.0 self._height = 100.0 self._demo_menu_button: Optional[ba.Widget] = None self._gather_button: Optional[ba.Widget] = None self._start_button: Optional[ba.Widget] = None self._watch_button: Optional[ba.Widget] = None self._gc_button: Optional[ba.Widget] = None self._how_to_play_button: Optional[ba.Widget] = None self._credits_button: Optional[ba.Widget] = None self._store_char_tex = self._get_store_char_tex() self._refresh() self._restore_state() # Keep an eye on a few things and refresh if they change. self._account_state = _ba.get_account_state() self._account_state_num = _ba.get_account_state_num() self._account_type = (_ba.get_account_type() if self._account_state == 'signed_in' else None) self._refresh_timer = ba.Timer(1.0, ba.WeakCall(self._check_refresh), repeat=True, timetype=ba.TimeType.REAL)
def _update(self) -> None: cur_time = ba.time(ba.TimeType.REAL) # If our account state has changed, refresh our UI. account_state_num = _ba.get_account_state_num() if account_state_num != self._account_state_num: self._account_state_num = account_state_num # And power ranking too... if not self._doing_power_ranking_query: self._last_power_ranking_query_time = None # Send off a new power-ranking query if its been # long enough or whatnot. if not self._doing_power_ranking_query and ( self._last_power_ranking_query_time is None or cur_time - self._last_power_ranking_query_time > 30.0): self._last_power_ranking_query_time = cur_time self._doing_power_ranking_query = True _ba.power_ranking_query( callback=ba.WeakCall(self._on_power_ranking_query_response))
def _check_refresh(self) -> None: if not self._root_widget: return # Don't refresh for the first few seconds the game is up so we don't # interrupt the transition in. ba.app.main_menu_window_refresh_check_count += 1 if ba.app.main_menu_window_refresh_check_count < 4: return store_char_tex = self._get_store_char_tex() account_state_num = _ba.get_account_state_num() if (account_state_num != self._account_state_num or store_char_tex != self._store_char_tex): self._store_char_tex = store_char_tex self._account_state_num = account_state_num account_state = self._account_state = (_ba.get_account_state()) self._account_type = (_ba.get_account_type() if account_state == 'signed_in' else None) self._save_state() self._refresh() self._restore_state()
def __init__(self, parent: ba.Widget, position: Tuple[float, float], size: Tuple[float, float], scale: float, on_activate_call: Callable[[], Any] = None, transition_delay: float = None, color: Tuple[float, float, float] = None, textcolor: Tuple[float, float, float] = None, smooth_update_delay: float = None): if on_activate_call is None: on_activate_call = ba.WeakCall(self._default_on_activate_call) self._on_activate_call = on_activate_call if smooth_update_delay is None: smooth_update_delay = 1000 self._smooth_update_delay = smooth_update_delay self._size = size self._scale = scale if color is None: color = (0.5, 0.6, 0.5) if textcolor is None: textcolor = (1, 1, 1) self._color = color self._textcolor = textcolor self._header_color = (0.8, 0.8, 2.0) self._parent = parent self._position: Tuple[float, float] = (0.0, 0.0) self._button = ba.buttonwidget(parent=parent, size=size, label='', button_type='square', scale=scale, autoselect=True, on_activate_call=self._on_activate, transition_delay=transition_delay, color=color) self._title_text = ba.textwidget( parent=parent, size=(0, 0), draw_controller=self._button, h_align='center', v_align='center', maxwidth=size[0] * scale * 0.85, text=ba.Lstr( resource='league.leagueRankText', fallback_resource='coopSelectWindow.powerRankingText'), color=self._header_color, flatness=1.0, shadow=1.0, scale=scale * 0.5, transition_delay=transition_delay) self._value_text = ba.textwidget(parent=parent, size=(0, 0), h_align='center', v_align='center', maxwidth=size[0] * scale * 0.85, text='-', draw_controller=self._button, big=True, scale=scale, transition_delay=transition_delay, color=textcolor) self._smooth_percent: Optional[float] = None self._percent: Optional[int] = None self._smooth_rank: Optional[float] = None self._rank: Optional[int] = None self._ticking_node: Optional[ba.Node] = None self._smooth_increase_speed = 1.0 self._league: Optional[str] = None self._improvement_text: Optional[str] = None self._smooth_update_timer: Optional[ba.Timer] = None # Take note of our account state; we'll refresh later if this changes. self._account_state_num = _ba.get_account_state_num() self._last_power_ranking_query_time: Optional[float] = None self._doing_power_ranking_query = False self.set_position(position) self._bg_flash = False self._update_timer = ba.Timer(1.0, ba.WeakCall(self._update), timetype=ba.TimeType.REAL, repeat=True) self._update() # If we've got cached power-ranking data already, apply it. data = ba.app.accounts.get_cached_league_rank_data() if data is not None: self._update_for_league_rank_data(data)
def __init__(self, transition: str = 'in_right', modal: bool = False, origin_widget: ba.Widget = None, close_once_signed_in: bool = False): # pylint: disable=too-many-statements self._close_once_signed_in = close_once_signed_in ba.set_analytics_screen('Account Window') # If they provided an origin-widget, scale up from that. 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 self._r = 'accountSettingsWindow' self._modal = modal self._needs_refresh = False self._signed_in = (_ba.get_account_state() == 'signed_in') self._account_state_num = _ba.get_account_state_num() self._show_linked = (self._signed_in and _ba.get_account_misc_read_val( 'allowAccountLinking2', False)) self._check_sign_in_timer = ba.Timer(1.0, ba.WeakCall(self._update), timetype=ba.TimeType.REAL, repeat=True) # Currently we can only reset achievements on game-center. account_type: Optional[str] if self._signed_in: account_type = _ba.get_account_type() else: account_type = None self._can_reset_achievements = (account_type == 'Game Center') app = ba.app self._width = 760 if ba.app.small_ui else 660 x_offs = 50 if ba.app.small_ui else 0 self._height = (390 if ba.app.small_ui else 430 if ba.app.med_ui else 490) self._sign_in_button = None self._sign_in_text = None self._scroll_width = self._width - (100 + x_offs * 2) self._scroll_height = self._height - 120 self._sub_width = self._scroll_width - 20 # Determine which sign-in/sign-out buttons we should show. self._show_sign_in_buttons: List[str] = [] if app.platform == 'android' and app.subplatform == 'google': self._show_sign_in_buttons.append('Google Play') elif app.platform == 'android' and app.subplatform == 'amazon': self._show_sign_in_buttons.append('Game Circle') # Local accounts are generally always available with a few key # exceptions. self._show_sign_in_buttons.append('Local') top_extra = 15 if ba.app.small_ui else 0 super().__init__(root_widget=ba.containerwidget( size=(self._width, self._height + top_extra), transition=transition, toolbar_visibility='menu_minimal', scale_origin_stack_offset=scale_origin, scale=(2.09 if ba.app.small_ui else 1.4 if ba.app.med_ui else 1.0), stack_offset=(0, -19) if ba.app.small_ui else (0, 0))) if ba.app.small_ui and ba.app.toolbars: self._back_button = None ba.containerwidget(edit=self._root_widget, on_cancel_call=self._back) else: self._back_button = btn = ba.buttonwidget( parent=self._root_widget, position=(51 + x_offs, self._height - 62), size=(120, 60), scale=0.8, text_scale=1.2, autoselect=True, label=ba.Lstr( resource='doneText' if self._modal else 'backText'), button_type='regular' if self._modal else 'back', on_activate_call=self._back) ba.containerwidget(edit=self._root_widget, cancel_button=btn) if not self._modal: ba.buttonwidget(edit=btn, button_type='backSmall', size=(60, 56), label=ba.charstr(ba.SpecialChar.BACK)) ba.textwidget(parent=self._root_widget, position=(self._width * 0.5, self._height - 41), size=(0, 0), text=ba.Lstr(resource=self._r + '.titleText'), color=ba.app.title_color, maxwidth=self._width - 340, h_align='center', v_align='center') self._scrollwidget = ba.scrollwidget( parent=self._root_widget, highlight=False, position=((self._width - self._scroll_width) * 0.5, self._height - 65 - self._scroll_height), size=(self._scroll_width, self._scroll_height)) self._subcontainer: Optional[ba.Widget] = None self._refresh() self._restore_state()