def _open_body_type_selection(self, outfit_part: OCOutfitPart, outfit_io: CommonSimOutfitIO, on_close_callback: Callable[[], None]=None): def _on_close() -> None: if on_close_callback is not None: on_close_callback() def _reopen_dialog() -> None: self._open_body_type_selection(outfit_part, outfit_io, on_close_callback=on_close_callback) def _on_option_chosen(option_identifier: str, picked_body_type: BodyType): self.log.debug('Chose body type: {}'.format(option_identifier)) if outfit_io.is_cas_part_attached(outfit_part.part_id): outfit_io.detach_cas_part(outfit_part.part_id) outfit_io.attach_cas_part(outfit_part.part_id, body_type=picked_body_type) outfit_io.apply() _reopen_dialog() def _on_remove_chosen() -> None: if outfit_io.is_cas_part_attached(outfit_part.part_id): outfit_io.detach_cas_part(outfit_part.part_id) outfit_io.apply() _reopen_dialog() option_dialog = CommonChooseObjectOptionDialog( OCStringId.OC_CHOOSE_BODY_LOCATION, OCStringId.OC_WHERE_SHOULD_IT_BE_WORN_AT, mod_identity=self.mod_identity, per_page=25, on_close=_on_close ) if CommonCASUtils.has_cas_part_attached(self._sim_info, outfit_part.part_id, body_type=None): option_dialog.add_option( CommonDialogActionOption( CommonDialogOptionContext( OCStringId.OC_REMOVE, 0, icon=CommonIconUtils.load_x_icon(), tooltip_text_identifier=OCStringId.OC_REMOVE ), on_chosen=_on_remove_chosen, always_visible=True ) ) default_body_type = CommonCASUtils.get_body_type_of_cas_part(outfit_part.part_id) option_dialog.add_option( CommonDialogObjectOption( 'Default', default_body_type, CommonDialogOptionContext( OCStringId.OC_DEFAULT_VALUE, 0, title_tokens=(str(default_body_type).replace('BodyType.', ''),), icon=CommonIconUtils.load_arrow_right_icon() ), on_chosen=_on_option_chosen ) ) sorted_body_types = sorted(BodyType.values, key=lambda bt: str(bt)) for body_type in sorted_body_types: if body_type == BodyType.NONE or body_type == default_body_type: continue cas_part_id = CommonCASUtils.get_cas_part_id_at_body_type(self._sim_info, body_type) if cas_part_id != -1: cas_part_id_at_body_type = str(cas_part_id) else: cas_part_id_at_body_type = OCStringId.OC_NONE name = CommonLocalizationUtils.create_localized_string(OCStringId.OC_LOCATION, tokens=(str(body_type).replace('BodyType.', ''),)) row_description = CommonLocalizationUtils.create_localized_string(OCStringId.OC_CURRENT, tokens=(cas_part_id_at_body_type,)) if cas_part_id == outfit_part.part_id: name = CommonLocalizationUtils.colorize(name, text_color=CommonLocalizedStringColor.GREEN) row_description = CommonLocalizationUtils.colorize(row_description, text_color=CommonLocalizedStringColor.GREEN) option_dialog.add_option( CommonDialogObjectOption( str(body_type), body_type, CommonDialogOptionContext( name, row_description, icon=CommonIconUtils.load_arrow_right_icon(), tooltip_text_identifier=name ), on_chosen=_on_option_chosen ) ) option_dialog.show(sim_info=self._sim_info)
def _open_cas_part_selector(self, outfit_parts: Tuple[OCOutfitPart], tag: str, on_close_callback: Callable[[], None]=None, current_page: int=1): self.log.format_with_message('Opening with outfit parts.', outfit_parts=outfit_parts) def _on_close() -> None: if on_close_callback is not None: on_close_callback() def _reopen_dialog() -> None: self._open_cas_part_selector(outfit_parts, tag, on_close_callback=on_close_callback, current_page=option_dialog.current_page) option_dialog = CommonChooseObjectOptionDialog( OCStringId.OC_CUSTOMIZE_OUTFIT_OC, 0, mod_identity=self.mod_identity, on_close=_on_close ) outfit_io = CommonSimOutfitIO(self._sim_info, mod_identity=self.mod_identity) def _on_option_chosen(option_identifier: str, picked_outfit_part: OCOutfitPart): self.log.debug('Chose outfit part: {}'.format(option_identifier)) self._open_body_type_selection(picked_outfit_part, outfit_io, on_close_callback=_reopen_dialog) def _on_remove_chosen() -> None: OCOutfitPartUtils.remove_outfit_parts(self._sim_info, outfit_parts) _reopen_dialog() def _no_outfit_parts_found() -> None: CommonOkDialog( OCStringId.OC_CUSTOMIZE_OUTFIT_OC, OCStringId.OC_NO_OUTFIT_PARTS_FOUND ).show(on_acknowledged=_on_close) if not outfit_parts: _no_outfit_parts_found() return sorted_outfit_parts = sorted(outfit_parts, key=lambda item: item.raw_display_name) option_dialog.add_option( CommonDialogActionOption( CommonDialogOptionContext( OCStringId.OC_REMOVE_ALL, 0, icon=CommonIconUtils.load_x_icon(), tooltip_text_identifier=OCStringId.OC_REMOVE_ALL, ), on_chosen=_on_remove_chosen, always_visible=True ) ) for outfit_part in sorted_outfit_parts: if tag not in outfit_part.tag_list: continue part_id = outfit_part.part_id author = outfit_part.author icon = CommonIconUtils._load_icon(outfit_part.icon_id) or CommonIconUtils.load_question_mark_icon() outfit_part_name = outfit_part.display_name # If outfit part is already equipped if outfit_io.is_cas_part_attached(part_id): outfit_part_name = CommonLocalizationUtils.create_localized_string(CommonStringId.TEXT_WITH_GREEN_COLOR, tokens=(outfit_part_name,)) option_dialog.add_option( CommonDialogObjectOption( str(part_id), outfit_part, CommonDialogOptionContext( outfit_part_name, OCStringId.OC_AUTHOR, description_tokens=(author,), icon=icon, ), on_chosen=_on_option_chosen ) ) # noinspection PyTypeChecker option_dialog.show( sim_info=self._sim_info, picker_type=UiObjectPicker.UiObjectPickerObjectPickerType.OBJECT, page=current_page )