def device_menu_press(device: ba.InputDevice) -> None: from bastd.ui.mainmenu import MainMenuWindow in_main_menu = _ba.app.ui.has_main_menu_window() if not in_main_menu: _ba.set_ui_input_device(device) _ba.playsound(_ba.getsound('swish')) _ba.app.ui.set_main_menu_window(MainMenuWindow().get_root_widget())
def _set_ready(self, ready: bool) -> None: # pylint: disable=cyclic-import from bastd.ui.profile import browser as pbrowser from ba._general import Call profilename = self._profilenames[self._profileindex] # Handle '_edit' as a special case. if profilename == '_edit' and ready: with _ba.Context('ui'): pbrowser.ProfileBrowserWindow(in_main_menu=False) # Give their input-device UI ownership too # (prevent someone else from snatching it in crowded games) _ba.set_ui_input_device(self._sessionplayer.inputdevice) return if not ready: self._sessionplayer.assigninput( InputType.LEFT_PRESS, Call(self.handlemessage, ChangeMessage('team', -1))) self._sessionplayer.assigninput( InputType.RIGHT_PRESS, Call(self.handlemessage, ChangeMessage('team', 1))) self._sessionplayer.assigninput( InputType.BOMB_PRESS, Call(self.handlemessage, ChangeMessage('character', 1))) self._sessionplayer.assigninput( InputType.UP_PRESS, Call(self.handlemessage, ChangeMessage('profileindex', -1))) self._sessionplayer.assigninput( InputType.DOWN_PRESS, Call(self.handlemessage, ChangeMessage('profileindex', 1))) self._sessionplayer.assigninput( (InputType.JUMP_PRESS, InputType.PICK_UP_PRESS, InputType.PUNCH_PRESS), Call(self.handlemessage, ChangeMessage('ready', 1))) self._ready = False self._update_text() self._sessionplayer.setname('untitled', real=False) else: self._sessionplayer.assigninput( (InputType.LEFT_PRESS, InputType.RIGHT_PRESS, InputType.UP_PRESS, InputType.DOWN_PRESS, InputType.JUMP_PRESS, InputType.BOMB_PRESS, InputType.PICK_UP_PRESS), self._do_nothing) self._sessionplayer.assigninput( (InputType.JUMP_PRESS, InputType.BOMB_PRESS, InputType.PICK_UP_PRESS, InputType.PUNCH_PRESS), Call(self.handlemessage, ChangeMessage('ready', 0))) # Store the last profile picked by this input for reuse. input_device = self._sessionplayer.inputdevice name = input_device.name unique_id = input_device.unique_identifier device_profiles = _ba.app.config.setdefault( 'Default Player Profiles', {}) # Make an exception if we have no custom profiles and are set # to random; in that case we'll want to start picking up custom # profiles if/when one is made so keep our setting cleared. special = ('_random', '_edit', '__account__') have_custom_profiles = any(p not in special for p in self._profiles) profilekey = name + ' ' + unique_id if profilename == '_random' and not have_custom_profiles: if profilekey in device_profiles: del device_profiles[profilekey] else: device_profiles[profilekey] = profilename _ba.app.config.commit() # Set this player's short and full name. self._sessionplayer.setname(self._getname(), self._getname(full=True), real=True) self._ready = True self._update_text() # Inform the session that this player is ready. _ba.getsession().handlemessage(PlayerReadyMessage(self))