示例#1
0
    def _settings_pet(self, on_close: Callable[[], Any] = None) -> None:
        def _reopen() -> None:
            self._settings_pet(on_close=on_close)

        def _on_close(*_, **__) -> None:
            if on_close is not None:
                on_close()

        def _on_chosen(_: str, picked_option: bool):
            if picked_option is None:
                _on_close()
                return
            value = not CommonSimGenderOptionUtils.can_reproduce(
                self._sim_info)
            CommonSimGenderOptionUtils.update_can_reproduce(
                self._sim_info, value)
            _reopen()

        option_dialog = CommonChooseObjectOptionDialog(
            CommonStringId.CUSTOM_GENDER_SETTINGS,
            CGSStringId.CGS_CUSTOM_GENDER_SETTINGS_DESCRIPTION,
            mod_identity=self.mod_identity,
            on_close=_on_close)

        current_selected = CGSStringId.NATURAL
        can_reproduce = CommonSimGenderOptionUtils.can_reproduce(
            self._sim_info)
        if not can_reproduce:
            current_selected = CGSStringId.FIXED

        option_dialog.add_option(
            CommonDialogToggleOption(
                'Reproductive Settings',
                can_reproduce,
                CommonDialogOptionContext(
                    CGSStringId.REPRODUCTIVE_SETTINGS,
                    CGSStringId.CGS_CURRENT,
                    description_tokens=(current_selected, ),
                    icon=CommonIconUtils.load_question_mark_icon()),
                on_chosen=_on_chosen))

        option_dialog.show(sim_info=self._sim_info)
    def run(
        self,
        sim_info: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        def _reopen() -> None:
            self.run(sim_info, on_completed=on_completed)

        def _on_close() -> None:
            on_completed(False)

        option_dialog = CommonChooseObjectOptionDialog(
            S4CMSimModifySkillsStringId.SET_SKILL_LEVELS,
            0,
            on_close=_on_close,
            mod_identity=self.mod_identity,
            per_page=20000)

        def _on_input_setting_changed(_skill: Skill, new_skill_level: int,
                                      outcome: CommonChoiceOutcome):
            if new_skill_level is None or CommonChoiceOutcome.is_error_or_cancel(
                    outcome):
                _reopen()
                return
            self.log.format_with_message('Setting skill level for Sim.',
                                         _skill=_skill,
                                         new_skill_level=new_skill_level)
            CommonSimSkillUtils.set_current_skill_level(
                sim_info, _skill, new_skill_level)
            if new_skill_level == 0:
                CommonSimSkillUtils.remove_skill(sim_info, _skill)
            _reopen()

        skill_manager = CommonResourceUtils.get_instance_manager(
            Types.STATISTIC)
        sim = CommonSimUtils.get_sim_instance(sim_info)
        for skill in skill_manager.get_ordered_types(only_subclasses_of=Skill):
            skill: Skill = skill
            skill_id = CommonSkillUtils.get_skill_id(skill)
            if skill_id is None:
                self.log.format_with_message('Missing skill id for Skill.',
                                             skill=skill)
                continue
            try:
                self.verbose_log.format_with_message(
                    'Attempting to display skill',
                    skill=skill,
                    skill_id=skill_id,
                    sim=sim_info)
                if not skill.can_add(sim):
                    self.verbose_log.format_with_message(
                        'Failed, Skill is not allowed for Sim.',
                        skill=skill,
                        skill_id=skill_id,
                        sim=sim_info)
                    continue
                if not CommonSimSkillUtils.has_skill(sim_info, skill_id):
                    current_skill_level = 0
                else:
                    current_skill_level = int(
                        CommonSimSkillUtils.get_current_skill_level(
                            sim_info,
                            skill_id,
                            use_effective_skill_level=False))
                stat_name = getattr(skill, 'stat_name', None)
                # noinspection PyUnresolvedReferences
                if stat_name and skill.stat_name.hash is not 0:
                    # noinspection PyUnresolvedReferences
                    display_name = skill.stat_name
                else:
                    skill_name = skill.__name__ or 'Unknown Skill Name'
                    skill_name = skill_name[0].upper() + skill_name[1:]
                    display_name = LocalizationHelperTuning.get_raw_text(
                        skill_name)

                # noinspection PyUnresolvedReferences
                if skill.hidden:
                    display_name = CommonLocalizationUtils.create_localized_string(
                        S4CMSimControlMenuStringId.STRING_SPACE_PAREN_STRING,
                        tokens=(display_name,
                                S4CMSimControlMenuStringId.HIDDEN))

                display_name = CommonLocalizationUtils.create_localized_string(
                    S4CMSimControlMenuStringId.STRING_COLON_SPACE_STRING,
                    tokens=(display_name, str(current_skill_level)))
                # noinspection PyUnresolvedReferences
                description = CommonLocalizationUtils.create_localized_string(
                    skill.skill_description, tokens=(sim_info, ))
                # noinspection PyUnresolvedReferences
                icon = skill.icon or CommonIconUtils.load_question_mark_icon()
                # MISSING ICON Identifier
                _MISSING_IMAGE_ICON_ID = 3526464109639239417
                if icon.instance == 0 or icon.instance == _MISSING_IMAGE_ICON_ID:
                    icon = CommonIconUtils.load_question_mark_icon()
                option_dialog.add_option(
                    CommonDialogInputIntegerOption(
                        self.mod_identity,
                        skill,
                        current_skill_level,
                        CommonDialogOptionContext(
                            display_name,
                            description,
                            icon=icon,
                            is_enabled=self._is_skill_allowed_for_modification(
                                sim_info, skill)),
                        dialog_description_identifier=S4CMSimModifySkillsStringId
                        .ENTER_A_VALE_BETWEEN_MIN_AND_MAX_FOR_SKILL,
                        dialog_description_tokens=(str(0),
                                                   str(int(skill.max_level)),
                                                   str(current_skill_level)),
                        min_value=0,
                        max_value=int(skill.max_level),
                        on_chosen=_on_input_setting_changed))
            except Exception as ex:
                self.log.format_error_with_message('Failed to display skill.',
                                                   skill=skill,
                                                   skill_name=skill.__name__,
                                                   skill_id=skill_id,
                                                   exception=ex)

        if not option_dialog.has_options():
            self.log.format_with_message('No skills available for the Sim!')
            on_completed(False)
            return False
        option_dialog.show(sim_info=sim_info, sort_options=True)
        return True
示例#3
0
    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
        )
    def run(self,
            sim_info: SimInfo,
            on_completed: Callable[[bool], None] = CommonFunctionUtils.noop,
            current_page: int = 1) -> bool:
        def _reopen() -> None:
            self.run(sim_info,
                     on_completed=on_completed,
                     current_page=option_dialog.current_page)

        def _on_close() -> None:
            on_completed(False)

        @CommonExceptionHandler.catch_exceptions(self.mod_identity,
                                                 fallback_return=False)
        def _on_submit(chosen_traits: Tuple[Trait]):
            trait_tracker: TraitTracker = sim_info.trait_tracker
            for personality_trait in trait_tracker.personality_traits:
                CommonTraitUtils.remove_trait(sim_info, personality_trait)

            for chosen_trait in chosen_traits:
                CommonTraitUtils.add_trait(sim_info, chosen_trait)

            # noinspection PyUnresolvedReferences
            CommonBasicNotification(
                S4CMSimControlMenuStringId.SET_PERSONALITY_TRAITS_TITLE,
                S4CMSimControlMenuStringId.SET_PERSONALITY_TRAITS_DESCRIPTION,
                description_tokens=(
                    CommonSimUtils.get_sim_instance(sim_info),
                )).show(icon=IconInfoData(
                    obj_instance=CommonSimUtils.get_sim_instance(sim_info)))
            _reopen()

        option_dialog = CommonChooseObjectsOptionDialog(
            S4CMSimControlMenuStringId.SET_PERSONALITY_TRAITS_MAX,
            0,
            title_tokens=(str(sim_info.trait_tracker.equip_slot_number), ),
            on_close=_on_close,
            mod_identity=self.mod_identity,
            per_page=20000)

        current_personality_trait_ids = [
            CommonTraitUtils.get_trait_id(pers_trait)
            for pers_trait in sim_info.trait_tracker.personality_traits
        ]
        self.log.format_with_message(
            'current_personality_traits',
            current_personality_trait_ids=current_personality_trait_ids)
        all_traits = [
            personality_trait
            for (trait_type, personality_trait
                 ) in CommonResourceUtils.load_all_instances(Types.TRAIT)
            if personality_trait.is_personality_trait
            and personality_trait.is_valid_trait(sim_info)
        ]
        for trait in sorted(all_traits,
                            key=lambda _trait: CommonTraitUtils.get_trait_name(
                                _trait).lower()):
            trait: Trait = trait
            trait_id = CommonTraitUtils.get_trait_id(trait)
            if trait_id is None:
                self.log.format_with_message('Missing trait id for Trait.',
                                             trait=trait)
                continue
            try:
                # noinspection PyUnresolvedReferences
                display_name = trait.display_name(sim_info)
                if display_name.hash == 0:
                    trait_name = CommonTraitUtils.get_trait_name(
                        trait) or 'Unknown Trait Name'
                    trait_name = trait_name[0].upper() + trait_name[1:]
                    # noinspection PyUnresolvedReferences
                    display_name = CommonLocalizationUtils.create_localized_string(
                        S4CMSimControlMenuStringId.STRING_SPACE_PAREN_STRING,
                        tokens=(trait_name, trait.trait_type.name))
                else:
                    # noinspection PyUnresolvedReferences
                    display_name = CommonLocalizationUtils.create_localized_string(
                        S4CMSimControlMenuStringId.STRING_SPACE_PAREN_STRING,
                        tokens=(
                            CommonLocalizationUtils.create_localized_string(
                                display_name,
                                tokens=(sim_info, )), trait.trait_type.name))
                display_name = CommonLocalizationUtils.colorize(
                    display_name, CommonLocalizedStringColor.GREEN
                ) if CommonTraitUtils.has_trait(sim_info,
                                                trait_id) else display_name
                # noinspection PyUnresolvedReferences
                description = CommonLocalizationUtils.create_localized_string(
                    trait.trait_description._string_id, tokens=(sim_info, ))
                # noinspection PyUnresolvedReferences
                icon = trait.icon or CommonIconUtils.load_question_mark_icon()
                # MISSING ICON Identifier
                _MISSING_IMAGE_ICON_ID = 3526464109639239417
                if icon.instance == 0 or icon.instance == _MISSING_IMAGE_ICON_ID:
                    icon = CommonIconUtils.load_question_mark_icon()
                option_dialog.add_option(
                    CommonDialogSelectOption(
                        trait_id, trait,
                        CommonDialogOptionContext(
                            display_name,
                            description,
                            icon=icon,
                            is_selected=trait_id
                            in current_personality_trait_ids)))
            except Exception as ex:
                self.log.format_error_with_message(
                    'Failed to display trait.',
                    trait=trait,
                    trait_name=CommonTraitUtils.get_trait_name(trait),
                    trait_id=trait_id,
                    exception=ex)

        if not option_dialog.has_options():
            on_completed(False)
            return False
        option_dialog.show(
            sim_info=sim_info,
            page=current_page,
            min_selectable=0,
            max_selectable=sim_info.trait_tracker.equip_slot_number,
            on_submit=_on_submit,
            allow_no_selection=True)
        return True
示例#5
0
    def run(
        self,
        sim_info: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        def _reopen() -> None:
            self.run(sim_info, on_completed=on_completed)

        def _on_close() -> None:
            on_completed(False)

        @CommonExceptionHandler.catch_exceptions(self.mod_identity,
                                                 fallback_return=False)
        def _on_chosen(_buff_id: int, chosen_buff: Buff):
            if chosen_buff is None:
                on_completed(False)
                return

            def _on_yes_selected(_: Any):
                CommonBuffUtils.remove_buff(sim_info, _buff_id)
                # noinspection PyUnresolvedReferences
                CommonBasicNotification(
                    S4CMSimControlMenuStringId.REMOVED_BUFF_TITLE,
                    S4CMSimControlMenuStringId.REMOVED_BUFF_DESCRIPTION,
                    title_tokens=(chosen_buff.buff_name(sim_info),
                                  str(_buff_id)),
                    description_tokens=(
                        CommonSimUtils.get_sim_instance(sim_info),
                        chosen_buff.buff_name(sim_info), str(_buff_id),
                        CommonBuffUtils.get_buff_name(chosen_buff))).show(
                            icon=IconInfoData(obj_instance=CommonSimUtils.
                                              get_sim_instance(sim_info)))
                _reopen()

            def _on_no_selected(_: Any):
                _reopen()

            # noinspection PyUnresolvedReferences
            confirmation = CommonOkCancelDialog(
                S4CMStringId.CONFIRMATION,
                S4CMSimControlMenuStringId.
                ARE_YOU_SURE_YOU_WANT_TO_REMOVE_BUFF,
                description_tokens=(chosen_buff.buff_name(sim_info),
                                    str(_buff_id),
                                    CommonBuffUtils.get_buff_name(chosen_buff),
                                    CommonSimUtils.get_sim_instance(sim_info)),
                ok_text_identifier=S4CMStringId.YES,
                cancel_text_identifier=S4CMStringId.NO,
                mod_identity=self.mod_identity)
            confirmation.show(on_ok_selected=_on_yes_selected,
                              on_cancel_selected=_on_no_selected)

        option_dialog = CommonChooseObjectOptionDialog(
            S4CMSimControlMenuStringId.REMOVE_BUFFS,
            0,
            on_close=_on_close,
            mod_identity=self.mod_identity,
            per_page=20000)

        for buff in CommonBuffUtils.get_buffs(sim_info):
            buff: Buff = buff
            buff_id = CommonBuffUtils.get_buff_id(buff)
            if buff_id is None:
                self.log.format_with_message('Missing buff id for Buff.',
                                             buff=buff)
                continue
            try:
                # noinspection PyUnresolvedReferences
                display_name = buff.buff_name(sim_info)
                if display_name.hash == 0:
                    buff_name = CommonBuffUtils.get_buff_name(
                        buff) or 'Unknown Buff Name'
                    buff_name = buff_name[0].upper() + buff_name[1:]
                    # noinspection PyUnresolvedReferences
                    display_name = CommonLocalizationUtils.create_localized_string(
                        S4CMSimControlMenuStringId.STRING_SPACE_PAREN_STRING,
                        tokens=(buff_name, str(buff_id)))
                else:
                    # noinspection PyUnresolvedReferences
                    display_name = CommonLocalizationUtils.create_localized_string(
                        S4CMSimControlMenuStringId.STRING_SPACE_PAREN_STRING,
                        tokens=(display_name, str(buff_id)))
                # noinspection PyUnresolvedReferences
                description = CommonLocalizationUtils.create_localized_string(
                    buff.buff_description, tokens=(sim_info, ))
                # noinspection PyUnresolvedReferences
                icon = buff.icon or CommonIconUtils.load_question_mark_icon()
                # MISSING ICON Identifier
                _MISSING_IMAGE_ICON_ID = 3526464109639239417
                if icon.instance == 0 or icon.instance == _MISSING_IMAGE_ICON_ID:
                    icon = CommonIconUtils.load_question_mark_icon()
                option_dialog.add_option(
                    CommonDialogSelectOption(
                        buff_id,
                        buff,
                        CommonDialogOptionContext(
                            display_name,
                            description,
                            icon=icon,
                            is_enabled=self._is_buff_allowed_for_removal(
                                buff)),
                        on_chosen=_on_chosen))
            except Exception as ex:
                self.log.format_error_with_message(
                    'Failed to display buff.',
                    buff=buff,
                    buff_name=CommonBuffUtils.get_buff_name(buff),
                    buff_id=buff_id,
                    exception=ex)

        if not option_dialog.has_options():
            on_completed(False)
            return False
        option_dialog.show(sim_info=sim_info, sort_options=True)
        return True