def _choose_playlist(self) -> None: if self._selected_playlist_name is None: return self._save_playlist_selection() ba.containerwidget(edit=self._root_widget, transition='out_left') _ba.fade_screen(False, endcall=self._run_selected_playlist) _ba.lock_all_input()
def return_to_main_menu_session_gracefully(self) -> None: """Attempt to cleanly get back to the main menu.""" # pylint: disable=cyclic-import from ba import _benchmark from ba._general import Call from bastd.mainmenu import MainMenuSession _ba.app.main_window = None if isinstance(_ba.get_foreground_host_session(), MainMenuSession): # It may be possible we're on the main menu but the screen is faded # so fade back in. _ba.fade_screen(True) return _benchmark.stop_stress_test() # Stop stress-test if in progress. # If we're in a host-session, tell them to end. # This lets them tear themselves down gracefully. host_session: Optional[ba.Session] = _ba.get_foreground_host_session() if host_session is not None: # Kick off a little transaction so we'll hopefully have all the # latest account state when we get back to the menu. _ba.add_transaction({ 'type': 'END_SESSION', 'sType': str(type(host_session)) }) _ba.run_transactions() host_session.end() # Otherwise just force the issue. else: _ba.pushcall(Call(_ba.new_host_session, MainMenuSession))
def _fade_and_quit(self) -> None: _ba.fade_screen(False, time=0.2, endcall=lambda: ba.quit(soft=True, back=self._back)) _ba.lock_all_input() # Unlock and fade back in shortly.. just in case something goes wrong # (or on android where quit just backs out of our activity and # we may come back) ba.timer(0.3, _ba.unlock_all_input, timetype=ba.TimeType.REAL)
def do_it() -> None: try: # reset to normal speed _ba.set_replay_speed_exponent(0) _ba.fade_screen(True) assert self._my_replay_selected is not None _ba.new_replay_session(_ba.get_replays_dir() + '/' + self._my_replay_selected) except Exception: ba.print_exception('exception running replay session') # drop back into a fresh main menu session # in case we half-launched or something.. from bastd import mainmenu _ba.new_host_session(mainmenu.MainMenuSession)
def launch_coop_game(self, game: str, force: bool = False, args: Dict = None) -> bool: """High level way to launch a local co-op session.""" # pylint: disable=cyclic-import from ba._campaign import get_campaign from bastd.ui.coop.level import CoopLevelLockedWindow if args is None: args = {} if game == '': raise ValueError('empty game name') campaignname, levelname = game.split(':') campaign = get_campaign(campaignname) levels = campaign.get_levels() # If this campaign is sequential, make sure we've completed the # one before this. if campaign.sequential and not force: for level in levels: if level.name == levelname: break if not level.complete: CoopLevelLockedWindow( campaign.get_level(levelname).displayname, campaign.get_level(level.name).displayname) return False # Ok, we're good to go. self.coop_session_args = { 'campaign': campaignname, 'level': levelname, } for arg_name, arg_val in list(args.items()): self.coop_session_args[arg_name] = arg_val def _fade_end() -> None: from ba import _coopsession try: _ba.new_host_session(_coopsession.CoopSession) except Exception: from ba import _error _error.print_exception() from bastd.mainmenu import MainMenuSession _ba.new_host_session(MainMenuSession) _ba.fade_screen(False, endcall=_fade_end) return True
def _on_ok_press(self) -> None: # Disallow if our playlist has disappeared. if not self._does_target_playlist_exist(): return # Disallow if we have no unlocked games. if not self._have_at_least_one_owned: ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr(resource='playlistNoValidGamesErrorText'), color=(1, 0, 0)) return cfg = ba.app.config cfg[self._pvars.config_name + ' Playlist Selection'] = self._playlist # Head back to the gather window in playlist-select mode # or start the game in regular mode. if self._selecting_mode: from bastd.ui.gather import GatherWindow if self._sessiontype is ba.FreeForAllSession: typename = 'ffa' elif self._sessiontype is ba.DualTeamSession: typename = 'teams' else: raise RuntimeError('Only teams and ffa currently supported') cfg['Private Party Host Session Type'] = typename ba.playsound(ba.getsound('gunCocking')) ba.app.ui.set_main_menu_window( GatherWindow(transition='in_right').get_root_widget()) self._transition_out(transition='out_left') if self._delegate is not None: self._delegate.on_play_options_window_run_game() else: _ba.fade_screen(False, endcall=self._run_selected_playlist) _ba.lock_all_input() self._transition_out(transition='out_left') if self._delegate is not None: self._delegate.on_play_options_window_run_game() cfg.commit()
def _on_play_press(self) -> None: # Disallow if our playlist has disappeared. if not self._does_target_playlist_exist(): return # Disallow if we have no unlocked games. if not self._have_at_least_one_owned: ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr(resource='playlistNoValidGamesErrorText'), color=(1, 0, 0)) return cfg = ba.app.config cfg[self._pvars.config_name + ' Playlist Selection'] = self._playlist cfg.commit() _ba.fade_screen(False, endcall=self._run_selected_playlist) _ba.lock_all_input() self._transition_out(transition='out_left') if self._delegate is not None: self._delegate.on_play_options_window_run_game()
def _on_my_replay_play_press(self) -> None: if self._my_replay_selected is None: self._no_replay_selected_error() return _ba.increment_analytics_count('Replay watch') def do_it() -> None: try: # reset to normal speed _ba.set_replay_speed_exponent(0) _ba.fade_screen(True) assert self._my_replay_selected is not None _ba.new_replay_session(_ba.get_replays_dir() + '/' + self._my_replay_selected) except Exception: ba.print_exception('exception running replay session') # drop back into a fresh main menu session # in case we half-launched or something.. from bastd import mainmenu _ba.new_host_session(mainmenu.MainMenuSession) _ba.fade_screen(False, endcall=ba.Call(ba.pushcall, do_it)) ba.containerwidget(edit=self._root_widget, transition='out_left')
def _do_game(self, mode: str) -> None: self._save_state() if mode in ['epic', 'ctf', 'hockey']: bs_config = ba.app.config if 'Team Tournament Playlists' not in bs_config: bs_config['Team Tournament Playlists'] = {} if 'Free-for-All Playlists' not in bs_config: bs_config['Free-for-All Playlists'] = {} bs_config['Show Tutorial'] = False if mode == 'epic': bs_config['Free-for-All Playlists']['Just Epic Elim'] = [{ 'settings': { 'Epic Mode': 1, 'Lives Per Player': 1, 'Respawn Times': 1.0, 'Time Limit': 0, 'map': 'Tip Top' }, 'type': 'bs_elimination.EliminationGame' }] bs_config['Free-for-All Playlist Selection'] = 'Just Epic Elim' _ba.fade_screen(False, endcall=ba.Call( ba.pushcall, ba.Call(_ba.new_host_session, ba.FreeForAllSession))) else: if mode == 'ctf': bs_config['Team Tournament Playlists']['Just CTF'] = [{ 'settings': { 'Epic Mode': False, 'Flag Idle Return Time': 30, 'Flag Touch Return Time': 0, 'Respawn Times': 1.0, 'Score to Win': 3, 'Time Limit': 0, 'map': 'Bridgit' }, 'type': 'bs_capture_the_flag.CTFGame' }] bs_config[ 'Team Tournament Playlist Selection'] = 'Just CTF' else: bs_config['Team Tournament Playlists']['Just Hockey'] = [{ 'settings': { 'Respawn Times': 1.0, 'Score to Win': 1, 'Time Limit': 0, 'map': 'Hockey Stadium' }, 'type': 'bs_hockey.HockeyGame' }] bs_config['Team Tournament Playlist Selection'] = \ 'Just Hockey' _ba.fade_screen(False, endcall=ba.Call( ba.pushcall, ba.Call(_ba.new_host_session, ba.TeamsSession))) ba.containerwidget(edit=self._root_widget, transition='out_left') return game = ('Easy:Onslaught Training' if mode == 'easy' else 'Easy:Rookie Football' if mode == 'medium' else 'Easy:Uber Onslaught') cfg = ba.app.config cfg['Selected Coop Game'] = game cfg.commit() if ba.app.launch_coop_game(game, force=True): ba.containerwidget(edit=self._root_widget, transition='out_left')
def on_transition_in(self) -> None: super().on_transition_in() _ba.fade_screen(False) _ba.lock_all_input()