def _cancel(self) -> None: from bastd.ui.profile import browser as pbrowser ba.containerwidget(edit=self._root_widget, transition='out_right') ba.app.main_menu_window = pbrowser.ProfileBrowserWindow( 'in_left', selected_profile=self._existing_profile, in_main_menu=self._in_main_menu).get_root_widget()
def _player_profiles_press(self) -> None: # pylint: disable=cyclic-import from bastd.ui.profile import browser as pbrowser self._save_state() ba.containerwidget(edit=self._root_widget, transition='out_left') pbrowser.ProfileBrowserWindow( origin_widget=self._player_profiles_button)
def save(self, transition_out: bool = True) -> bool: """Save has been selected.""" from bastd.ui.profile import browser as pbrowser new_name = self.get_name().strip() if not new_name: ba.screenmessage(ba.Lstr(resource='nameNotEmptyText')) ba.playsound(ba.getsound('error')) return False if transition_out: ba.playsound(ba.getsound('gunCocking')) # Delete old in case we're renaming. if self._existing_profile and self._existing_profile != new_name: _ba.add_transaction({ 'type': 'REMOVE_PLAYER_PROFILE', 'name': self._existing_profile }) # Also lets be aware we're no longer global if we're taking a # new name (will need to re-request it). self._global = False _ba.add_transaction({ 'type': 'ADD_PLAYER_PROFILE', 'name': new_name, 'profile': { 'character': self._spazzes[self._icon_index], 'color': self._color, 'global': self._global, 'icon': self._icon, 'highlight': self._highlight } }) if transition_out: _ba.run_transactions() ba.containerwidget(edit=self._root_widget, transition='out_right') ba.app.main_menu_window = (pbrowser.ProfileBrowserWindow( 'in_left', selected_profile=new_name, in_main_menu=self._in_main_menu).get_root_widget()) return True
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))