def load_selected_bot(self): """ Loads all the values belonging to the new selected agent into the bot_config_groupbox :return: """ # prevent processing from itself (clearing the other one processes this) if not self.sender().selectedItems(): return blue = True if self.sender() is self.blue_listwidget else False if blue: # deselect the other listbox self.orange_listwidget.clearSelection() else: self.blue_listwidget.clearSelection() item_name = self.sender().selectedItems()[0].text() agent = self.bot_names_to_agent_dict[item_name] if agent is None: # something went wrong if agent is None return self.current_bot = agent self.bot_config_groupbox.setEnabled( True) # Make sure that you can edit the bot # enable [-] for right listwidget if blue: self.blue_minus_toolbutton.setDisabled(False) self.orange_minus_toolbutton.setDisabled(True) else: self.orange_minus_toolbutton.setDisabled(False) self.blue_minus_toolbutton.setDisabled(True) # load the bot parameters into the edit frame agent_type = agent.get_participant_type() known_types = ['human', 'psyonix', 'rlbot', 'party_member_bot'] assert agent_type in known_types, 'Bot has unknown type: %s' % agent_type self.bot_type_combobox.setCurrentIndex(known_types.index(agent_type)) if blue: self.blue_radiobutton.setChecked(True) else: self.orange_radiobutton.setChecked(True) self.ign_lineedit.setText(agent.ingame_name) loadout_index = index_of_config_path_in_combobox( self.loadout_preset_combobox, agent.get_loadout_preset().config_path) self.loadout_preset_combobox.setCurrentIndex(loadout_index or 0) self.agent_preset_combobox.blockSignals(True) self.agent_preset_combobox.setCurrentText( agent.get_agent_preset().get_name()) self.agent_preset_combobox.blockSignals(False) self.bot_level_slider.setValue(int(agent.get_bot_skill() * 100))
def load_preset_toplevel(self): preset = self.agent_customisation.load_preset_cfg() if preset is None: return self.agent_preset_combobox.setCurrentText(preset.get_name()) loadout_preset = self.add_loadout_preset(preset.looks_path) self.car_customisation.update_presets_widgets() loadout_index = index_of_config_path_in_combobox(self.loadout_preset_combobox, loadout_preset.config_path) self.loadout_preset_combobox.setCurrentIndex(loadout_index) self.current_bot.set_loadout_preset(loadout_preset)
def bot_config_edit_event(self, value=None): """ Handles the events called when editing a value regarding the bot configuration :param value: the new value to store in the config :return: """ sender = self.sender() if value is None: value = sender.text() agent = self.current_bot if sender is self.bot_type_combobox: self.update_bot_type_combobox() elif sender is self.blue_radiobutton and value: # 'and value' check to make sure that one got selected if agent.get_team() != 0: agent.set_team(0) self.update_teams_listwidgets() self.blue_listwidget.setCurrentItem(self.blue_listwidget.findItems( self.validate_name(agent.get_name(), agent), QtCore.Qt.MatchExactly)[0]) elif sender is self.orange_radiobutton and value: if agent.get_team() != 1: agent.set_team(1) self.update_teams_listwidgets() self.orange_listwidget.setCurrentItem(self.orange_listwidget.findItems( self.validate_name(agent.get_name(), agent), QtCore.Qt.MatchExactly)[0]) elif sender is self.ign_lineedit: if agent not in self.agents: return if not agent.get_team(): listwidget = self.blue_listwidget else: listwidget = self.orange_listwidget name = self.validate_name(value, agent) old_name = self.validate_name(agent.ingame_name, agent) row = listwidget.currentRow() del self.bot_names_to_agent_dict[old_name] agent.set_name(value) self.bot_names_to_agent_dict[name] = agent self.update_teams_listwidgets() listwidget.setCurrentRow(row) elif sender is self.loadout_preset_combobox: if self.bot_config_groupbox.isEnabled() and self.current_bot is not None: index = self.loadout_preset_combobox.currentIndex() preset = self.loadout_preset_combobox.itemData(index) self.current_bot.set_loadout_preset(preset) elif sender is self.agent_preset_combobox: if value and self.bot_config_groupbox.isEnabled() and self.current_bot is not None: preset = self.agent_preset_combobox.currentData() self.current_bot.set_agent_preset(preset) agent.set_name(agent.agent_preset.config.get(BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY)) self.ign_lineedit.setText(agent.ingame_name) if not agent.get_team(): listwidget = self.blue_listwidget else: listwidget = self.orange_listwidget row = listwidget.currentRow() self.update_teams_listwidgets() listwidget.setCurrentRow(row) loadout_index = index_of_config_path_in_combobox(self.loadout_preset_combobox, preset.looks_path) if loadout_index is not None: self.loadout_preset_combobox.setCurrentIndex(loadout_index) elif sender is self.bot_level_slider: agent.set_bot_skill(value / 100) if self.cfg_autosave_checkbutton.isChecked() and os.path.isfile(self.overall_config_path): self.save_overall_config(10)