Beispiel #1
0
    def _pregnancy_options(self, on_close: Callable[[], Any] = None) -> None:
        def _on_close():
            if on_close is not None:
                on_close()

        def _reopen():
            self._pregnancy_options(on_close=on_close)

        option_dialog = CommonChooseObjectOptionDialog(
            CGSStringId.CGS_PREGNANCY_OPTIONS_NAME,
            CGSStringId.CGS_PREGNANCY_OPTIONS_DESCRIPTION,
            mod_identity=self.mod_identity,
            on_close=_on_close)

        def _can_impregnate_chosen(option_identifier: str,
                                   can_get_others_pregnant: bool):
            self.log.format(option_identifier=option_identifier,
                            can_get_others_pregnant=can_get_others_pregnant)
            value = not CommonSimGenderOptionUtils.can_impregnate(
                self._sim_info)
            CommonSimGenderOptionUtils.update_can_impregnate(
                self._sim_info, value)
            _reopen()

        option_dialog.add_option(
            CommonDialogToggleOption(
                'CanImpregnate',
                CommonSimGenderOptionUtils.can_impregnate(self._sim_info),
                CommonDialogOptionContext(
                    CGSStringId.CGS_CAN_GET_OTHERS_PREGNANT_NAME,
                    CGSStringId.CGS_CAN_GET_OTHERS_PREGNANT_DESCRIPTION),
                on_chosen=_can_impregnate_chosen))

        def _can_be_impregnated_chosen(option_identifier: str,
                                       can_get_pregnant: bool):
            self.log.format(option_identifier=option_identifier,
                            can_get_pregnant=can_get_pregnant)
            value = not CommonSimGenderOptionUtils.can_be_impregnated(
                self._sim_info)
            CommonSimGenderOptionUtils.update_can_be_impregnated(
                self._sim_info, value)
            _reopen()

        option_dialog.add_option(
            CommonDialogToggleOption(
                'CanBeImpregnated',
                CommonSimGenderOptionUtils.can_be_impregnated(self._sim_info),
                CommonDialogOptionContext(
                    CGSStringId.CGS_CAN_BECOME_PREGNANT_NAME,
                    CGSStringId.CGS_CAN_BECOME_PREGNANT_DESCRIPTION),
                on_chosen=_can_be_impregnated_chosen))

        option_dialog.show(sim_info=self._sim_info)
Beispiel #2
0
    def _add_picker_option(self, option_dialog: CommonChooseObjectOptionDialog,
                           title: int, description: LocalizedString,
                           setting_name: str, on_name: int, off_name: int,
                           on_chosen: Callable[[str, Union[bool, int]],
                                               Any], on_close: Callable[[],
                                                                        Any]):
        current_val = self._data_store.get_value_by_key(setting_name)
        selected_string = CGSStringId.DISABLED
        if current_val is True:
            selected_string = on_name
        elif current_val is False:
            selected_string = off_name

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(title,
                                          description,
                                          title_tokens=(selected_string, )),
                on_chosen=lambda *_, **__: self._select_option(
                    title,
                    description,
                    selected_string,
                    setting_name,
                    on_name,
                    off_name,
                    on_chosen=on_chosen,
                    on_close=on_close)))
Beispiel #3
0
    def _open_with_outfit_parts(self, outfit_parts: Tuple[OCOutfitPart], 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()

        option_dialog = CommonChooseObjectOptionDialog(
            OCStringId.OC_CUSTOMIZE_OUTFIT_OC,
            0,
            on_close=_on_close,
            mod_identity=self.mod_identity
        )

        def _reopen_dialog() -> None:
            option_dialog.show(sim_info=self._sim_info, picker_type=UiObjectPicker.UiObjectPickerObjectPickerType.OBJECT, page=option_dialog.current_page)

        def _on_option_chosen(option_identifier: str, chosen: str):
            self.log.debug('Chose tag: {}'.format(option_identifier))
            self._open_cas_part_selector(outfit_parts, chosen, on_close_callback=_reopen_dialog)

        def _no_outfit_parts_found() -> None:
            CommonOkDialog(
                OCStringId.OC_CUSTOMIZE_OUTFIT_OC,
                OCStringId.OC_NO_OUTFIT_PARTS_FOUND,
                mod_identity=self.mod_identity
            ).show(on_acknowledged=_on_close)

        if not outfit_parts:
            _no_outfit_parts_found()
            return

        object_categories: List[str] = list()
        for outfit_part in outfit_parts:
            for part_tag in outfit_part.tag_list:
                if str(part_tag) in object_categories:
                    continue
                object_categories.append(str(part_tag))

        sorted_object_categories = sorted(object_categories, key=lambda item: item)
        for object_category in sorted_object_categories:
            option_dialog.add_option(
                CommonDialogSelectOption(
                    object_category,
                    object_category,
                    CommonDialogOptionContext(
                        object_category,
                        0,
                        icon=CommonIconUtils.load_arrow_navigate_into_icon()
                    ),
                    on_chosen=_on_option_chosen
                )
            )

        option_dialog.show(
            sim_info=self._sim_info,
            picker_type=UiObjectPicker.UiObjectPickerObjectPickerType.OBJECT,
            page=current_page
        )
    def _select_template(self,
                         sim_info: SimInfo,
                         on_close: Callable[[], None] = None):
        self.log.format_with_message('Opening dialog.', sim=sim_info)

        def _on_close() -> None:
            self.log.debug('Slider Template dialog closed.')
            if on_close is not None:
                on_close()

        option_dialog = CommonChooseObjectOptionDialog(
            CSFStringId.SELECTED_TEMPLATE,
            CSFStringId.PLEASE_SELECT_A_TEMPLATE,
            mod_identity=self.mod_identity,
            on_close=_on_close,
            per_page=400)

        self.log.debug('Opening Customize Slider dialog.')

        def _on_chosen(_: str, _chosen_template: CSFSliderTemplate):
            if _chosen_template is None:
                self.log.debug('No template name entered, dialog closed.')
                _on_close()
                return
            self.log.format_with_message(
                'Template name entered.',
                template_name=_chosen_template.template_name)
            CSFSliderTemplateDialog._SELECTED_TEMPLATE = _chosen_template
            _on_close()

        for (template_name,
             template) in self._template_utils.template_library.items():
            template: CSFSliderTemplate = template
            option_dialog.add_option(
                CommonDialogObjectOption(
                    template_name,
                    template,
                    CommonDialogOptionContext(
                        template.display_name,
                        0,
                        icon=CommonIconUtils.load_filled_circle_icon() if
                        CSFSliderTemplateDialog._SELECTED_TEMPLATE == template
                        else CommonIconUtils.load_unfilled_circle_icon(),
                    ),
                    on_chosen=_on_chosen))

        if not option_dialog.has_options():

            def _on_acknowledge(_) -> None:
                _on_close()

            CommonOkDialog(CSFStringId.NO_TEMPLATES_DETECTED_NAME,
                           CSFStringId.NO_TEMPLATES_DETECTED_DESCRIPTION,
                           mod_identity=self.mod_identity).show(
                               on_acknowledged=_on_acknowledge)
            return

        option_dialog.show(sim_info=sim_info)
Beispiel #5
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 open(self,
             source_sim_info: SimInfo,
             target: Any = None,
             page: int = 1) -> None:
        """open(source_sim_info, target=None, page=1)

        Open the mod settings menu.

        :param source_sim_info: An instance of the Sim opening the dialog.
        :type source_sim_info: SimInfo
        :param target: An instance of an object. Default is None.
        :type target: Any, optional
        :param page: The page to open at. Default is 1.
        :type page: int, optional
        """
        self.log.debug('Opening Mod Settings Menu.')

        def _reopen(*_, **__) -> None:
            self.log.debug('Reopening MSM.')
            self.open(source_sim_info,
                      target=target,
                      page=option_dialog.current_page)

        def _on_close(*_, **__) -> None:
            self.log.debug('MSM closed.')
            if self._on_close is not None:
                self._on_close()

        option_dialog = CommonChooseObjectOptionDialog(
            S4MSMStringId.MOD_SETTINGS_MENU,
            S4MSMStringId.CHOOSE_SETTINGS_TO_MODIFY,
            on_close=_on_close,
            mod_identity=self.mod_identity)

        available_menu_items = self._menu_item_registry.get_menu_items_available_for(
            source_sim_info, target=target)

        sorted_available_menu_items = sorted(available_menu_items,
                                             key=lambda mi: mi.identifier)

        def _on_chosen(_: str, chosen_menu_item: S4MSMMenuItem):
            return chosen_menu_item.show(source_sim_info,
                                         target=target,
                                         on_close=_reopen)

        self.log.debug('Adding menu items.')
        for menu_item in sorted_available_menu_items:
            mod_name_and_version = CommonLocalizationUtils.combine_localized_strings(
                (menu_item.mod_name, menu_item.mod_version),
                separator=CommonLocalizedStringSeparator.SPACE)
            description = CommonLocalizationUtils.combine_localized_strings(
                (menu_item.description, mod_name_and_version),
                separator=CommonLocalizedStringSeparator.
                SPACE_PARENTHESIS_SURROUNDED)
            title = CommonLocalizationUtils.combine_localized_strings(
                (menu_item.title, menu_item.mod_version),
                separator=CommonLocalizedStringSeparator.
                SPACE_PARENTHESIS_SURROUNDED)
            option_dialog.add_option(
                CommonDialogSelectOption(
                    menu_item.identifier,
                    menu_item,
                    CommonDialogOptionContext(
                        title,
                        description,
                        tooltip_text_identifier=menu_item.tooltip_text,
                        tooltip_tokens=(source_sim_info,
                                        target) if target is not None else
                        (source_sim_info, ),
                        icon=menu_item.icon),
                    on_chosen=_on_chosen))

        if not option_dialog.has_options():
            self.log.debug(
                f'No menu items were available for \'{source_sim_info}\' and \'{target}\'.'
            )
            return

        option_dialog.show(sim_info=source_sim_info, page=page)
Beispiel #7
0
    def open(self) -> None:
        """ Open the dialog for customizing a sims outfit. """
        self.log.format_with_message('Opening customize outfit dialog.', sim=CommonSimNameUtils.get_full_name(self._sim_info))

        def _on_close() -> None:
            if self._on_close is not None:
                self._on_close()

        def _reopen_dialog() -> None:
            option_dialog.show(sim_info=self._sim_info, page=option_dialog.current_page)

        outfit_parts = OCCASPartQueryUtils().get_cas_parts_for_sim(self._sim_info)
        if not outfit_parts:
            CommonOkDialog(
                OCStringId.OC_CUSTOMIZE_OUTFIT_OC,
                OCStringId.OC_NO_OUTFIT_PARTS_FOUND,
                mod_identity=self.mod_identity
            ).show(on_acknowledged=_on_close)
            return

        option_dialog = CommonChooseObjectOptionDialog(
            OCStringId.OC_CUSTOMIZE_OUTFIT_OC,
            0,
            on_close=_on_close,
            mod_identity=self.mod_identity
        )

        def _on_option_chosen(option_identifier: str, choice: _OutfitPartsBy):
            self.log.debug('Opening Outfit Parts: {}'.format(option_identifier))
            self._open_outfit_parts_by(choice, outfit_parts, on_close=_reopen_dialog)

        option_dialog.add_option(
            CommonDialogObjectOption(
                'By Tag',
                _OutfitPartsBy.TAG,
                CommonDialogOptionContext(
                    OCStringId.OC_FILTER_BY_TAG,
                    0,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()
                ),
                on_chosen=_on_option_chosen
            )
        )

        option_dialog.add_option(
            CommonDialogObjectOption(
                'By Outfit Slot',
                _OutfitPartsBy.OUTFIT_SLOT,
                CommonDialogOptionContext(
                    OCStringId.OC_FILTER_BY_OUTFIT_SLOT,
                    0,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()
                ),
                on_chosen=_on_option_chosen
            )
        )

        option_dialog.add_option(
            CommonDialogObjectOption(
                'By Author',
                _OutfitPartsBy.AUTHOR,
                CommonDialogOptionContext(
                    OCStringId.OC_FILTER_BY_AUTHOR,
                    0,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()
                ),
                on_chosen=_on_option_chosen
            )
        )

        option_dialog.show(sim_info=self._sim_info)
Beispiel #8
0
    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)
Beispiel #9
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
Beispiel #10
0
def _common_testing_show_choose_objects_option_dialog(_connection: int = None):
    output = sims4.commands.CheatOutput(_connection)
    output('Showing test choose objects option dialog.')

    def _on_option_chosen(option_identifier: str, choice: str):
        output('Chose option {} with value: {}.'.format(
            pformat(option_identifier), pformat(choice)))

    def _on_submit(choices: Tuple[str]):
        output('Chose options {}.'.format(pformat(choices)))

    try:
        # LocalizedStrings within other LocalizedStrings
        title_tokens = (CommonLocalizationUtils.create_localized_string(
            CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
            text_color=CommonLocalizedStringColor.GREEN), )
        description_tokens = (CommonLocalizationUtils.create_localized_string(
            CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME,
            tokens=(CommonSimUtils.get_active_sim_info(), ),
            text_color=CommonLocalizedStringColor.BLUE), )
        option_dialog = CommonChooseObjectsOptionDialog(
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            title_tokens=title_tokens,
            description_tokens=description_tokens,
            per_page=2)

        from sims4communitylib.utils.common_icon_utils import CommonIconUtils

        option_dialog.add_option(
            CommonDialogObjectOption(
                'Option 1',
                'Value 1',
                CommonDialogOptionContext(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
                    CommonStringId.TESTING_TEST_BUTTON_ONE,
                    icon=CommonIconUtils.load_checked_square_icon()),
                on_chosen=_on_option_chosen))

        option_dialog.add_option(
            CommonDialogObjectOption(
                'Option 2',
                'Value 2',
                CommonDialogOptionContext(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
                    CommonStringId.TESTING_TEST_BUTTON_TWO,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                on_chosen=_on_option_chosen))

        option_dialog.add_option(
            CommonDialogObjectOption(
                'Option 3',
                'Value 3',
                CommonDialogOptionContext(
                    CommonLocalizationUtils.create_localized_string('Value 3'),
                    CommonStringId.TESTING_TEST_BUTTON_TWO,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                on_chosen=_on_option_chosen))

        option_dialog.show(on_submit=_on_submit,
                           sim_info=CommonSimUtils.get_active_sim_info(),
                           min_selectable=1,
                           max_selectable=2)
    except Exception as ex:
        CommonExceptionHandler.log_exception(ModInfo.get_identity(),
                                             'Failed to show dialog',
                                             exception=ex)
        output('Failed to show dialog, please locate your exception log file.')
    output('Done showing.')
    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
Beispiel #12
0
    def _settings_human(self, on_close: Callable[[], Any] = None) -> None:
        def _on_close() -> None:
            if on_close is not None:
                on_close()

        def _reopen():
            self._settings_human(on_close=on_close)

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

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CGSStringId.GLOBAL_SETTINGS_NAME,
                    CGSStringId.GLOBAL_SETTINGS_DESCRIPTION),
                on_chosen=CGSGlobalSettingsDialog(self._sim_info,
                                                  on_close=_reopen).open))

        def _set_to_vanilla_gender_chosen():
            if CommonGenderUtils.is_male(self._sim_info):
                CommonSimGenderOptionUtils.update_gender_options_to_vanilla_male(
                    self._sim_info)
            else:
                CommonSimGenderOptionUtils.update_gender_options_to_vanilla_female(
                    self._sim_info)
            _reopen()

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CGSStringId.CGS_SET_TO_VANILLA_GENDER_OPTIONS_NAME,
                CGSStringId.CGS_SET_TO_VANILLA_GENDER_OPTIONS_DESCRIPTION,
                icon=CommonIconUtils.load_arrow_right_icon()),
                                     on_chosen=_set_to_vanilla_gender_chosen))

        def _on_gender_chosen():
            CommonGenderUtils.swap_gender(self._sim_info,
                                          update_gender_options=False)
            _reopen()

        current_gender_string = CGSStringId.MALE
        if CommonGenderUtils.is_female(self._sim_info):
            current_gender_string = CGSStringId.FEMALE

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CGSStringId.CGS_SWAP_GENDER_NAME,
                CGSStringId.CGS_SWAP_GENDER_DESCRIPTION,
                title_tokens=(current_gender_string, ),
                icon=CommonIconUtils.load_arrow_right_icon()),
                                     on_chosen=_on_gender_chosen))

        def _on_physical_frame_chosen():
            value = not CommonSimGenderOptionUtils.has_masculine_frame(
                self._sim_info)
            CommonSimGenderOptionUtils.update_body_frame(self._sim_info, value)
            _reopen()

        current_body_frame = CommonStringId.FEMININE
        if CommonSimGenderOptionUtils.has_masculine_frame(self._sim_info):
            current_body_frame = CommonStringId.MASCULINE

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CommonStringId.PHYSICAL_FRAME,
                CGSStringId.CGS_CURRENT,
                description_tokens=(current_body_frame, ),
                icon=CommonIconUtils.load_arrow_right_icon()),
                                     on_chosen=_on_physical_frame_chosen))

        current_clothing = CommonStringId.FEMININE
        if CommonSimGenderOptionUtils.prefers_menswear(self._sim_info):
            current_clothing = CommonStringId.MASCULINE

        def _on_clothing_preference_chosen():
            value = not CommonSimGenderOptionUtils.prefers_menswear(
                self._sim_info)
            CommonSimGenderOptionUtils.update_clothing_preference(
                self._sim_info, value)
            _reopen()

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CommonStringId.CLOTHING_PREFERENCE,
                CGSStringId.CGS_CURRENT,
                description_tokens=(current_clothing, ),
                icon=CommonIconUtils.load_arrow_right_icon()),
                                     on_chosen=_on_clothing_preference_chosen))

        def _on_toggle_breasts_chosen(option_identifier: str,
                                      has_breasts: bool):
            self.log.format(option_identifier=option_identifier,
                            has_breasts=has_breasts)

            def _on_acknowledged(_):
                _reopen()

            CommonSimGenderOptionUtils.update_has_breasts(
                self._sim_info, has_breasts)
            CommonOkDialog(
                CGSStringId.CGS_SETTING_SAVE_RELOAD_ALERT_NAME,
                CGSStringId.CGS_SETTING_SAVE_RELOAD_ALERT_DESCRIPTION).show(
                    on_acknowledged=_on_acknowledged)

        has_vanilla_breasts = False
        if CommonGenderUtils.is_female(self._sim_info):
            has_vanilla_breasts = not CommonTraitUtils.has_trait(
                self._sim_info, CommonTraitId.BREASTS_FORCE_OFF)

        option_dialog.add_option(
            CommonDialogToggleOption(
                'ToggleBreasts',
                CommonTraitUtils.has_trait(self._sim_info,
                                           CommonTraitId.BREASTS_FORCE_ON)
                or has_vanilla_breasts,
                CommonDialogOptionContext(
                    CGSStringId.CGS_TOGGLE_BREASTS_NAME,
                    CGSStringId.CGS_TOGGLE_BREASTS_DESCRIPTION),
                on_chosen=_on_toggle_breasts_chosen))

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CGSStringId.CGS_PREGNANCY_OPTIONS_NAME,
                CGSStringId.CGS_PREGNANCY_OPTIONS_DESCRIPTION,
                icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                                     on_chosen=lambda *_, **__: self.
                                     _pregnancy_options(on_close=_reopen)))

        title = CGSStringId.CGS_TOGGLE_CAN_USE_TOILET_STANDING_NAME
        if CommonSimGenderOptionUtils.uses_toilet_standing(self._sim_info):
            title = CommonLocalizationUtils.create_localized_string(
                title, text_color=CommonLocalizedStringColor.GREEN)
            icon = CommonIconUtils.load_checked_square_icon()
        else:
            icon = CommonIconUtils.load_unchecked_square_icon()
        text = CGSStringId.CGS_TOGGLE_CAN_USE_TOILET_STANDING_DESCRIPTION

        def _on_toilet_usage_chosen():
            value = not CommonSimGenderOptionUtils.uses_toilet_standing(
                self._sim_info)
            CommonSimGenderOptionUtils.update_toilet_usage(
                self._sim_info, value)
            _reopen()

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(title,
                                                               text,
                                                               icon=icon),
                                     on_chosen=_on_toilet_usage_chosen))

        option_dialog.show(sim_info=self._sim_info)
Beispiel #13
0
    def open(self) -> None:
        """ Open Dialog. """
        def _on_close() -> None:
            if self._on_close is not None:
                self._on_close()

        def _reopen(*_, **__) -> None:
            self.open()

        option_dialog = CommonChooseObjectOptionDialog(
            CGSStringId.GLOBAL_SETTINGS_NAME,
            CGSStringId.GLOBAL_SETTINGS_DESCRIPTION,
            mod_identity=self.mod_identity,
            on_close=_on_close)

        @CommonExceptionHandler.catch_exceptions(self.mod_identity)
        def _on_force_all_chosen(_: str, picked_option: Union[int, bool]):
            if picked_option is None:
                return
            if picked_option == -1:
                self._data_store.set_value_by_key(_, None)
                _reopen()
                return

            @CommonExceptionHandler.catch_exceptions(self.mod_identity)
            def _on_ok(_d):
                self.log.debug('Ok chosen {}, \'{}\''.format(picked_option, _))
                self._data_store.set_value_by_key(_, picked_option)
                self.log.format_with_message(
                    'set value with', val=self._data_store.get_value_by_key(_))

                for sim_info in CommonSimUtils.get_instanced_sim_info_for_all_sims_generator(
                ):
                    _CGSUpdateGenderOptions()._update_gender_options(sim_info)
                _reopen()

            def _on_cancel(_d):
                self.log.debug('Cancel chosen')
                _reopen()

            CommonOkCancelDialog(
                CGSStringId.PLEASE_CONFIRM_NAME,
                CGSStringId.PLEASE_CONFIRM_DESCRIPTION,
                ok_text_identifier=CGSStringId.YES_UPDATE_ALL_SIMS,
                cancel_text_identifier=CGSStringId.NO).show(
                    on_ok_selected=_on_ok, on_cancel_selected=_on_cancel)

        current_force_all_val = self._data_store.get_value_by_key(
            CGSGlobalSetting.ALL_SIMS_FORCE_AS_MALE)
        force_all_selected_string = CGSStringId.DISABLED
        if current_force_all_val is True:
            force_all_selected_string = CGSStringId.MALE
        elif current_force_all_val is False:
            force_all_selected_string = CGSStringId.FEMALE

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_NAME,
                    CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_DESCRIPTION,
                    title_tokens=(force_all_selected_string, )),
                on_chosen=lambda *_, **__: self._select_option(
                    CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_NAME,
                    CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_DESCRIPTION,
                    force_all_selected_string,
                    CGSGlobalSetting.ALL_SIMS_FORCE_AS_MALE,
                    CGSStringId.MALE,
                    CGSStringId.FEMALE,
                    on_chosen=_on_force_all_chosen,
                    on_close=_reopen)))

        def _set_all_to_vanilla_gender_options_chosen():
            for sim_info in CommonSimUtils.get_instanced_sim_info_for_all_sims_generator(
            ):
                if CommonGenderUtils.is_male(sim_info):
                    CommonSimGenderOptionUtils.update_gender_options_to_vanilla_male(
                        sim_info)
                else:
                    CommonSimGenderOptionUtils.update_gender_options_to_vanilla_female(
                        sim_info)
            _reopen()

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CGSStringId.SET_ALL_SIMS_TO_VANILLA_GENDER_OPTIONS_NAME,
                    CGSStringId.
                    SET_ALL_SIMS_TO_VANILLA_GENDER_OPTIONS_DESCRIPTION,
                    icon=CommonIconUtils.load_arrow_right_icon()),
                on_chosen=_set_all_to_vanilla_gender_options_chosen))

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CGSStringId.ALL_MALE_SIM_OPTIONS,
                CGSStringId.ALL_MALE_SIM_OPTIONS_DESCRIPTION,
                icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                                     on_chosen=lambda *_, **__: self.
                                     _all_male_options(on_close=_reopen)))

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CGSStringId.ALL_FEMALE_SIM_OPTIONS,
                CGSStringId.ALL_FEMALE_SIM_OPTIONS_DESCRIPTION,
                icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                                     on_chosen=lambda *_, **__: self.
                                     _all_female_options(on_close=_reopen)))

        option_dialog.show()
Beispiel #14
0
    def _select_option(self,
                       title: int,
                       description: LocalizedString,
                       current_string: int,
                       setting_name: str,
                       on_name: int,
                       off_name: int,
                       on_chosen: Callable[[str, Union[bool, int]], Any],
                       on_close: Callable[[], Any] = None):
        def _on_close() -> None:
            if on_close is not None:
                on_close()

        option_dialog = CommonChooseObjectOptionDialog(
            title,
            description,
            title_tokens=(current_string, ),
            mod_identity=self.mod_identity,
            on_close=_on_close)

        current_val = self._data_store.get_value_by_key(setting_name)

        @CommonExceptionHandler.catch_exceptions(self.mod_identity)
        def _on_chosen(_: str, picked_option: bool):
            if picked_option is None:
                _on_close()
                return
            on_chosen(_, picked_option)

        option_dialog.add_option(
            CommonDialogSelectOption(
                setting_name,
                -1,
                CommonDialogOptionContext(
                    CGSStringId.DISABLED,
                    0,
                    icon=CommonIconUtils.load_filled_circle_icon()
                    if current_val is None else
                    CommonIconUtils.load_unfilled_circle_icon()),
                on_chosen=_on_chosen))

        option_dialog.add_option(
            CommonDialogSelectOption(
                setting_name,
                True,
                CommonDialogOptionContext(
                    on_name,
                    0,
                    icon=CommonIconUtils.load_filled_circle_icon()
                    if current_val is True else
                    CommonIconUtils.load_unfilled_circle_icon()),
                on_chosen=_on_chosen))

        option_dialog.add_option(
            CommonDialogSelectOption(
                setting_name,
                False,
                CommonDialogOptionContext(
                    off_name,
                    0,
                    icon=CommonIconUtils.load_filled_circle_icon()
                    if current_val is False else
                    CommonIconUtils.load_unfilled_circle_icon()),
                on_chosen=_on_chosen))

        option_dialog.show()
    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
    def _view_template(self,
                       sim_info: SimInfo,
                       on_close: Callable[[], None] = None):
        self.log.format_with_message('Opening view template dialog.',
                                     sim=sim_info)

        def _on_close() -> None:
            self.log.debug('Slider Template dialog closed.')
            if on_close is not None:
                on_close()

        def _reopen() -> None:
            self._view_template(sim_info, on_close=on_close)

        if CSFSliderTemplateDialog._SELECTED_TEMPLATE is None:

            def _on_acknowledge(_) -> None:
                _on_close()

            CommonOkDialog(CSFStringId.NO_TEMPLATE_SELECTED,
                           CSFStringId.PLEASE_SELECT_A_TEMPLATE,
                           mod_identity=self.mod_identity).show(
                               on_acknowledged=_on_acknowledge)
            return

        option_dialog = CommonChooseObjectOptionDialog(
            CSFStringId.VIEW_TEMPLATE_NAME,
            CSFStringId.VIEW_TEMPLATE_DESCRIPTION,
            mod_identity=self.mod_identity,
            on_close=_on_close,
            per_page=400)

        for (slider,
             amount) in CSFSliderTemplateDialog._SELECTED_TEMPLATE.get_sliders(
                 sim_info):
            slider: CSFSlider = slider
            option_dialog.add_option(
                CommonDialogObjectOption(
                    slider.unique_identifier,
                    slider,
                    CommonDialogOptionContext(
                        0,
                        CSFStringId.STRING_PLUS_STRING,
                        description_tokens=(
                            slider.display_name,
                            str(amount),
                        ),
                        icon=CommonIconUtils.load_arrow_right_icon(),
                        is_enabled=False),
                    on_chosen=lambda *_, **__: _reopen()))

        if not option_dialog.has_options():

            def _on_acknowledge(_) -> None:
                _on_close()

            CommonOkDialog(CSFStringId.NO_SLIDERS_DETECTED_NAME,
                           CSFStringId.NO_SLIDERS_DETECTED_DESCRIPTION,
                           mod_identity=self.mod_identity).show(
                               on_acknowledged=_on_acknowledge)
            return

        option_dialog.show(sim_info=sim_info)
    def open(self, sim_info: SimInfo, page: int = 1) -> None:
        """ Open the dialog. """
        self.log.format_with_message('Opening dialog.', sim=sim_info)

        def _on_close() -> None:
            self.log.debug('Slider Template dialog closed.')
            if self._on_close is not None:
                self._on_close()

        def _reopen() -> None:
            self.log.debug('Reopening slider template dialog.')
            self.open(sim_info, page=option_dialog.current_page)

        option_dialog = CommonChooseObjectOptionDialog(
            CSFStringId.SLIDER_TEMPLATES_NAME,
            CSFStringId.SLIDER_TEMPLATES_DESCRIPTION,
            mod_identity=self.mod_identity,
            on_close=_on_close,
            per_page=400)

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CSFStringId.SELECTED_TEMPLATE,
                0,
                title_tokens=(
                    CSFSliderTemplateDialog._SELECTED_TEMPLATE.template_name
                    if CSFSliderTemplateDialog._SELECTED_TEMPLATE is not None
                    else CSFStringId.NO_TEMPLATE_SELECTED, )),
                                     on_chosen=lambda *_, **__: self.
                                     _select_template(sim_info,
                                                      on_close=_reopen)))

        def _on_apply_template_to_sim() -> None:
            self.log.debug('Confirming all sliders reset.')
            if CSFSliderTemplateDialog._SELECTED_TEMPLATE is None:

                def _on_acknowledge(_) -> None:
                    _reopen()

                CommonOkDialog(CSFStringId.NO_TEMPLATE_SELECTED,
                               CSFStringId.PLEASE_SELECT_A_TEMPLATE,
                               mod_identity=self.mod_identity).show(
                                   on_acknowledged=_on_acknowledge)
                return

            def _on_confirm(_) -> None:
                self.log.debug('Applying template to Sim.')
                CSFSliderTemplateDialog._SELECTED_TEMPLATE.apply_to_sim(
                    sim_info)
                _reopen()

            def _on_cancel(_) -> None:
                self.log.debug('Cancelled template apply.')
                _reopen()

            CommonOkCancelDialog(
                CSFStringId.CONFIRMATION,
                CSFStringId.APPLY_TEMPLATE_TO_SIM_CONFIRMATION_DESCRIPTION,
                description_tokens=(sim_info, ),
                mod_identity=self.mod_identity).show(
                    on_ok_selected=_on_confirm, on_cancel_selected=_on_cancel)

        self.log.debug('Opening Customize Slider dialog.')

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CSFStringId.APPLY_TEMPLATE_TO_SIM_NAME,
                    CSFStringId.APPLY_TEMPLATE_TO_SIM_DESCRIPTION,
                    description_tokens=(sim_info, ),
                    is_enabled=CSFSliderTemplateDialog._SELECTED_TEMPLATE
                    is not None),
                on_chosen=lambda *_, **__: _on_apply_template_to_sim()))

        def _on_save_as_template(_: str, template_name: str,
                                 outcome: CommonChoiceOutcome):
            if _ is None or template_name is None or CommonChoiceOutcome.is_error_or_cancel(
                    outcome):
                self.log.debug('No template name entered, dialog closed.')
                _reopen()
                return
            self.log.format_with_message('Template name entered.',
                                         template_name=template_name)
            if template_name in self._template_utils.template_library:

                def _on_yes(_) -> None:
                    self.log.debug('Saving template.')
                    self._template_utils.save_sliders_of(
                        sim_info, template_name)
                    _reopen()

                def _on_no(_) -> None:
                    self.log.debug('Cancelled saving template.')
                    _reopen()

                CommonOkCancelDialog(
                    CSFStringId.TEMPLATE_ALREADY_EXISTS_NAME,
                    CSFStringId.TEMPLATE_ALREADY_EXISTS_DESCRIPTION,
                    description_tokens=(template_name, ),
                    ok_text_identifier=CSFStringId.YES,
                    cancel_text_identifier=CSFStringId.NO,
                    mod_identity=self.mod_identity).show(
                        on_ok_selected=_on_yes, on_cancel_selected=_on_no)
                return

            self._template_utils.save_sliders_of(sim_info, template_name)
            _reopen()

        option_dialog.add_option(
            CommonDialogInputTextOption(
                self.mod_identity,
                'Save Template From Sim',
                CommonSimNameUtils.get_full_name(sim_info),
                CommonDialogOptionContext(
                    CSFStringId.CREATE_TEMPLATE_FROM_SIM_NAME,
                    CSFStringId.CREATE_TEMPLATE_FROM_SIM_DESCRIPTION,
                    title_tokens=(sim_info, ),
                    description_tokens=(sim_info, )),
                on_chosen=_on_save_as_template,
                dialog_description_identifier=CSFStringId.
                ENTER_A_NAME_FOR_YOUR_NEW_TEMPLATE))

        option_dialog.add_option(
            CommonDialogActionOption(CommonDialogOptionContext(
                CSFStringId.VIEW_TEMPLATE_NAME,
                CSFStringId.VIEW_TEMPLATE_DESCRIPTION,
                is_enabled=CSFSliderTemplateDialog._SELECTED_TEMPLATE
                is not None,
                title_tokens=(
                    CSFSliderTemplateDialog._SELECTED_TEMPLATE.template_name
                    if CSFSliderTemplateDialog._SELECTED_TEMPLATE is not None
                    else CSFStringId.NO_TEMPLATE_SELECTED, )),
                                     on_chosen=lambda *_, **__: self
                                     ._view_template(sim_info,
                                                     on_close=_reopen)))

        option_dialog.show(sim_info=sim_info, page=page)
Beispiel #18
0
    def _open_outfit_parts_by(self, outfit_parts_by: _OutfitPartsBy, outfit_parts: Tuple[OCOutfitPart], on_close: Callable[[], None]):
        self.log.format_with_message('Opening outfit parts by', outfit_parts_by=outfit_parts_by)

        def _on_close() -> None:
            on_close()

        option_dialog = CommonChooseObjectOptionDialog(
            OCStringId.OC_CUSTOMIZE_OUTFIT_OC,
            0,
            on_close=_on_close,
            mod_identity=self.mod_identity
        )

        def _reopen_dialog() -> None:
            option_dialog.show(sim_info=self._sim_info, page=option_dialog.current_page)

        def _on_option_chosen(option_identifier: str, chosen: Tuple[OCOutfitPart]):
            self.log.debug('Opening Outfit Parts By: {}'.format(option_identifier))
            self._open_with_outfit_parts(chosen, on_close_callback=_reopen_dialog)

        def _no_outfit_parts_found() -> None:
            CommonOkDialog(
                OCStringId.OC_CUSTOMIZE_OUTFIT_OC,
                OCStringId.OC_NO_OUTFIT_PARTS_FOUND,
                mod_identity=self.mod_identity
            ).show(on_acknowledged=_on_close)

        if outfit_parts_by == _OutfitPartsBy.NONE:
            self.log.debug('outfit_parts_by was NONE')
            _no_outfit_parts_found()
            return

        self.log.format_with_message('Creating outfit parts by', outfit_parts_by=outfit_parts_by)
        if len(outfit_parts) == 0:
            self.log.debug('No outfit parts found!')
            _no_outfit_parts_found()
            return

        sorted_outfit_parts = sorted(outfit_parts, key=lambda op: op.raw_display_name)
        if not sorted_outfit_parts:
            self.log.debug('Failed to sort outfit parts by name')
            _no_outfit_parts_found()
            return

        self.log.format_with_message('Outfit parts sorted.', sorted_outfit_parts=sorted_outfit_parts)

        outfit_parts_by_value_dict = {}
        for outfit_part in sorted_outfit_parts:
            outfit_part: OCOutfitPart = outfit_part
            self.log.format_with_message('Looking at outfit part.', outfit_part=outfit_part)
            if not CommonCASUtils.is_cas_part_loaded(outfit_part.part_id):
                self.log.debug('Outfit part not loaded.')
                continue
            keys = self._get_outfit_part_key(outfit_part, outfit_parts_by=outfit_parts_by)
            if keys is None:
                self.log.debug('No key found.')
                continue
            for key in keys:
                str_key = str(key)
                by_value = outfit_parts_by_value_dict.get(str_key, list())
                by_value.append(outfit_part)
                outfit_parts_by_value_dict[str_key] = by_value
            self.log.debug('Outfit part loaded.')

        if len(outfit_parts_by_value_dict) == 0:
            self.log.format_with_message('No outfit parts found with outfit parts by!', outfit_parts_by=outfit_parts_by, outfit_parts_by_value_dict=outfit_parts_by_value_dict)
            self.log.debug('No outfit parts found!')
            _no_outfit_parts_found()
            return

        self.log.format_with_message('Finished filtering outfit parts.', outfit_parts_by_value_dict=outfit_parts_by_value_dict)

        sorted_keys = sorted(outfit_parts_by_value_dict.keys())
        self.log.format(sorted_keys=sorted_keys)
        for key in sorted_keys:
            self.log.format_with_message('Building key', key=key)
            outfit_parts_by_value: List[OCOutfitPart] = outfit_parts_by_value_dict[key]
            if len(outfit_parts_by_value) == 0:
                self.log.debug('No parts found in key.')
                continue
            outfit_parts_count = str(len(outfit_parts_by_value))
            self.log.format_with_message('Found outfit parts', count=outfit_parts_count)
            option_dialog.add_option(
                CommonDialogObjectOption(
                    key,
                    tuple(outfit_parts_by_value),
                    CommonDialogOptionContext(
                        key,
                        OCStringId.OC_OUTFIT_PARTS_COUNT,
                        description_tokens=(outfit_parts_count,),
                        icon=CommonIconUtils.load_arrow_navigate_into_icon()
                    ),
                    on_chosen=_on_option_chosen
                )
            )

        if not option_dialog.has_options():
            self.log.debug('No options found in dialog.')
            _no_outfit_parts_found()
            return

        self.log.debug('Showing dialog.')

        option_dialog.show(sim_info=self._sim_info)
Beispiel #19
0
    def open(self, sim_info: SimInfo, page: int = 1) -> None:
        """ Open the dialog. """
        self.log.format_with_message(
            'Opening customize sliders dialog for Sim.', sim=sim_info)

        def _on_close() -> None:
            self.log.debug('Customize Slider dialog closed.')
            if self._on_close is not None:
                self._on_close()

        option_dialog = CommonChooseObjectOptionDialog(
            CSFStringId.CUSTOMIZE_SLIDERS,
            CSFStringId.CHOOSE_SLIDERS_TO_MODIFY,
            mod_identity=self.mod_identity,
            on_close=_on_close,
            per_page=400)

        def _reopen_dialog() -> None:
            self.log.debug('Reopening customize sliders dialog.')
            self.open(sim_info, page=option_dialog.current_page)

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CSFStringId.SLIDER_TEMPLATES_NAME,
                    CSFStringId.SLIDER_TEMPLATES_DESCRIPTION,
                    tag_list=[
                        slider_category.name
                        for slider_category in CSFSliderCategory.values
                    ]),
                on_chosen=lambda *_, **__: CSFSliderTemplateDialog(
                    on_close=_reopen_dialog).open(sim_info),
                always_visible=True))

        def _on_reset_all_sliders() -> None:
            self.log.debug('Confirming all sliders reset.')

            def _on_confirm(_) -> None:
                self.log.debug('Resetting all sliders.')
                self.slider_application_service.reset_all_sliders(sim_info)
                _reopen_dialog()

            def _on_cancel(_) -> None:
                self.log.debug('Cancelled resetting of all sliders.')
                _reopen_dialog()

            CommonOkCancelDialog(
                CSFStringId.CONFIRMATION,
                CSFStringId.ARE_YOU_SURE_YOU_WANT_TO_RESET_ALL_SLIDERS,
                mod_identity=self.mod_identity).show(
                    on_ok_selected=_on_confirm, on_cancel_selected=_on_cancel)

        def _on_slider_changed(slider_unique_identifier: str, amount: float,
                               outcome: CommonChoiceOutcome):
            if slider_unique_identifier is None or amount is None or CommonChoiceOutcome.is_error_or_cancel(
                    outcome):
                self.log.debug(
                    'No slider chosen, dialog closed, or no amount specified.')
                _reopen_dialog()
                return
            self.log.debug('Slider changed, attempting to apply.')
            self.slider_application_service.apply_slider_by_identifier(
                sim_info, slider_unique_identifier, amount)
            _reopen_dialog()

        self.log.debug('Opening Customize Slider dialog.')

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CSFStringId.RESET_ALL_SLIDERS_NAME,
                    CSFStringId.RESET_ALL_SLIDERS_DESCRIPTION,
                    tag_list=[
                        slider_category.name
                        for slider_category in CSFSliderCategory.values
                    ]),
                on_chosen=lambda *_, **__: _on_reset_all_sliders(),
                always_visible=True))

        sliders: Tuple[
            CSFSlider] = self._slider_query_utils.get_sliders_for_sim(sim_info)

        if not sliders:
            from cncustomsliderframework.sliders.slider_query_registry import CSFSliderQueryRegistry
            if CSFSliderQueryRegistry()._collecting:
                CommonOkDialog(
                    CSFStringId.SLIDERS_ARE_STILL_LOADING,
                    CSFStringId.SLIDERS_ARE_STILL_LOADING_DESCRIPTION,
                    description_tokens=(
                        CSFStringId.FINISHED_LOADING_SLIDERS, ),
                    mod_identity=ModInfo.get_identity()).show()
            else:
                CommonOkDialog(CSFStringId.NO_SLIDERS_FOUND,
                               CSFStringId.NO_SLIDERS_FOUND,
                               mod_identity=ModInfo.get_identity()).show()
            _on_close()
            return

        self.log.debug('Adding slider count {}'.format(len(sliders)))
        sorted_sliders = sorted(sliders, key=lambda s: s.name)
        slider_categories: List[CSFSliderCategory] = list()
        object_categories: List[str] = list()
        for custom_slider in sorted_sliders:
            for slider_category in custom_slider.categories:
                if slider_category.name in object_categories:
                    continue
                slider_categories.append(slider_category)
                object_categories.append(slider_category.name)

        def _on_randomize_slider_category(category_name: str,
                                          category: CSFSliderCategory):
            self.log.debug(
                'Confirming reset of sliders in category {}.'.format(
                    category_name))

            def _on_confirm(_) -> None:
                self.log.debug(
                    'Randomizing all sliders in category {}.'.format(
                        category_name))
                for slider in sorted_sliders:
                    if category not in slider.categories:
                        continue
                    self.slider_application_service.apply_random(
                        sim_info, slider)
                _reopen_dialog()

            def _on_cancel(_) -> None:
                self.log.debug(
                    'Cancelled randomization of sliders in category {}.'.
                    format(category_name))
                _reopen_dialog()

            CommonOkCancelDialog(CSFStringId.CONFIRMATION,
                                 CSFStringId.RANDOMIZE_SLIDER_CONFIRMATION,
                                 mod_identity=self.mod_identity).show(
                                     on_ok_selected=_on_confirm,
                                     on_cancel_selected=_on_cancel)

        for slider_category in slider_categories:
            option_dialog.add_option(
                CommonDialogSelectOption(
                    slider_category.name,
                    slider_category,
                    CommonDialogOptionContext(
                        CSFStringId.RANDOMIZE_SLIDER_NAME,
                        CSFStringId.RANDOMIZE_SLIDER_DESCRIPTION,
                        title_tokens=(slider_category.name, ),
                        description_tokens=(slider_category.name, ),
                        tag_list=[
                            slider_category.name
                            for slider_category in CSFSliderCategory.values
                        ]),
                    on_chosen=_on_randomize_slider_category,
                    always_visible=True))

        for custom_slider in sorted_sliders:
            if custom_slider.description is not None:
                # noinspection PyTypeChecker
                option_description = CommonLocalizationUtils.create_localized_string(
                    custom_slider.description,
                    tokens=(str(0.0), str(custom_slider.minimum_value),
                            str(custom_slider.maximum_value)))
            else:
                # noinspection PyTypeChecker
                option_description = CommonLocalizationUtils.create_localized_string(
                    CSFStringId.CHANGE_THE_SLIDER,
                    tokens=(custom_slider.display_name, ))

            option_dialog.add_option(
                CommonDialogInputFloatOption(
                    custom_slider.unique_identifier,
                    self.slider_application_service.get_current_slider_value(
                        sim_info, custom_slider),
                    CommonDialogOptionContext(
                        custom_slider.display_name,
                        option_description,
                        icon=custom_slider.icon_id or None,
                        tag_list=tuple([
                            category.name
                            for category in custom_slider.categories
                        ])),
                    min_value=custom_slider.minimum_value,
                    max_value=custom_slider.maximum_value,
                    on_chosen=_on_slider_changed,
                    dialog_description_identifier=CSFStringId.DEFAULT_MIN_MAX,
                    dialog_description_tokens=(
                        option_description, str(0.0),
                        str(custom_slider.minimum_value),
                        str(custom_slider.maximum_value))))

        categories: List[CommonDialogObjectOptionCategory] = list()

        for category in object_categories:
            # noinspection PyTypeChecker
            categories.append(
                CommonDialogObjectOptionCategory(
                    category, icon=CommonIconId.S4CLIB_UNFILLED_CIRCLE_ICON))

        self.log.debug('Showing slider options.')

        option_dialog.show(sim_info=sim_info, page=page, categories=categories)
Beispiel #20
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 _common_testing_show_multi_pane_choose_option_dialog(
        _connection: int = None):
    output = sims4.commands.CheatOutput(_connection)
    output('Showing test multi pane choose option dialog.')

    def _on_option_chosen_in_dialog_one(option_identifier: str, choice: str):
        output('Chose option in dialog one {} with value: {}.'.format(
            pformat(option_identifier), pformat(choice)))

    def _on_option_chosen_in_dialog_two(option_identifier: str, choice: str):
        output('Chose option in dialog two {} with value: {}.'.format(
            pformat(option_identifier), pformat(choice)))

    def _on_submit(chosen_options: Dict[int, Any]):
        output('Chosen options from all dialogs {}.'.format(
            pformat(chosen_options)))

    try:
        # LocalizedStrings within other LocalizedStrings
        title_tokens = (CommonLocalizationUtils.create_localized_string(
            CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
            text_color=CommonLocalizedStringColor.GREEN), )
        description_tokens = (CommonLocalizationUtils.create_localized_string(
            CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME,
            tokens=(CommonSimUtils.get_active_sim_info(), ),
            text_color=CommonLocalizedStringColor.BLUE), )

        sub_dialog_one = CommonChooseObjectOptionDialog(
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            title_tokens=title_tokens,
            description_tokens=description_tokens,
            per_page=2)

        sub_dialog_one.add_option(
            CommonDialogObjectOption(
                'Option 1',
                'Value 1',
                CommonDialogOptionContext(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
                    CommonStringId.TESTING_TEST_BUTTON_ONE,
                    icon=CommonIconUtils.load_checked_square_icon()),
                on_chosen=_on_option_chosen_in_dialog_one))

        sub_dialog_one.add_option(
            CommonDialogObjectOption(
                'Option 2',
                'Value 2',
                CommonDialogOptionContext(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
                    CommonStringId.TESTING_TEST_BUTTON_TWO,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                on_chosen=_on_option_chosen_in_dialog_one))

        sub_dialog_one.add_option(
            CommonDialogObjectOption(
                'Option 3',
                'Value 3',
                CommonDialogOptionContext(
                    CommonLocalizationUtils.create_localized_string('Value 3'),
                    CommonStringId.TESTING_TEST_BUTTON_TWO,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                on_chosen=_on_option_chosen_in_dialog_one))

        sub_dialog_two = CommonChooseObjectOptionDialog(
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            title_tokens=title_tokens,
            description_tokens=description_tokens,
            per_page=2)

        sub_dialog_two.add_option(
            CommonDialogObjectOption(
                'Option 4',
                'Value 4',
                CommonDialogOptionContext(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
                    CommonStringId.TESTING_TEST_BUTTON_ONE,
                    icon=CommonIconUtils.load_checked_square_icon()),
                on_chosen=_on_option_chosen_in_dialog_two))

        sub_dialog_two.add_option(
            CommonDialogObjectOption(
                'Option 5',
                'Value 5',
                CommonDialogOptionContext(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
                    CommonStringId.TESTING_TEST_BUTTON_TWO,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                on_chosen=_on_option_chosen_in_dialog_two))

        sub_dialog_two.add_option(
            CommonDialogObjectOption(
                'Option 6',
                'Value 6',
                CommonDialogOptionContext(
                    CommonLocalizationUtils.create_localized_string('Value 3'),
                    CommonStringId.TESTING_TEST_BUTTON_TWO,
                    icon=CommonIconUtils.load_arrow_navigate_into_icon()),
                on_chosen=_on_option_chosen_in_dialog_two))

        option_dialog = CommonMultiPaneChooseOptionDialog(
            ModInfo.get_identity(),
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            title_tokens=title_tokens,
            description_tokens=description_tokens)

        option_dialog.add_sub_dialog(sub_dialog_one)
        option_dialog.add_sub_dialog(sub_dialog_two)

        option_dialog.show(on_submit=_on_submit,
                           sim_info=CommonSimUtils.get_active_sim_info())
    except Exception as ex:
        CommonExceptionHandler.log_exception(ModInfo.get_identity(),
                                             'Failed to show dialog',
                                             exception=ex)
        output('Failed to show dialog, please locate your exception log file.')
    output('Done showing.')
Beispiel #22
0
    def _settings(self, sim_info: SimInfo) -> CommonChooseObjectOptionDialog:
        self.log.debug('Building change motives dialog for \'{}\'.'.format(
            CommonSimNameUtils.get_full_name(sim_info)))

        def _on_close() -> None:
            self.log.debug('CM dialog closed.')
            if self._on_close is not None:
                self._on_close()

        option_dialog = CommonChooseObjectOptionDialog(
            CMStringId.CHANGE_MOTIVES,
            CMStringId.CHOOSE_MOTIVE_TO_SET,
            mod_identity=self.mod_identity,
            on_close=_on_close)

        def _reopen_dialog() -> None:
            self.log.debug('Reopening CM dialog.')
            self.open(sim_info)

        def _on_min_all_motives() -> None:
            def _on_confirm(_) -> None:
                self.log.debug(
                    'Setting all motives to their minimum! Sim Death incoming!'
                )
                self.motive_utils.min_all_motives(sim_info)
                _reopen_dialog()

            def _on_cancel(_) -> None:
                self.log.debug(
                    'Cancelled setting all motives to minimum. That was a close one!'
                )
                _reopen_dialog()

            self.log.debug(
                'Showing confirmation for setting all motives to minimum.')

            CommonOkCancelDialog(
                CMStringId.CONFIRMATION,
                CMStringId.SET_ALL_MOTIVE_LEVELS_TO_MINIMUM_CONFIRMATION,
                description_tokens=(sim_info, ),
                mod_identity=self.mod_identity).show(
                    on_ok_selected=_on_confirm, on_cancel_selected=_on_cancel)

        def _on_max_all_motives() -> None:
            self.log.debug('Setting all motives to their maximum.')
            self.motive_utils.max_all_motives(sim_info)

        def _on_changed(chosen_motive_name: str, amount: float,
                        outcome: CommonChoiceOutcome):
            if chosen_motive_name is None or amount is None or CommonChoiceOutcome.is_error_or_cancel(
                    outcome):
                self.log.debug('Cancelled changing motive level.')
                _reopen_dialog()
                return
            self.log.debug('Changing motive \'{}\' to amount {}'.format(
                chosen_motive_name, amount))
            self.motive_utils.change_motive_level(sim_info, chosen_motive_name,
                                                  amount)
            _reopen_dialog()

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CMStringId.SET_ALL_MOTIVE_LEVELS_TO_MINIMUM,
                    0,
                ),
                on_chosen=lambda *_, **__: _on_min_all_motives(),
                always_visible=True), )

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    CMStringId.SET_ALL_MOTIVE_LEVELS_TO_MAXIMUM,
                    0,
                ),
                on_chosen=lambda *_, **__: _on_max_all_motives(),
                always_visible=True), )

        motive_names: Tuple[str] = CMMotiveUtils().get_valid_motives(sim_info)
        sorted_motive_names = sorted(motive_names, key=lambda s: s)
        for motive_name in sorted_motive_names:
            if motive_name is None:
                continue

            motive_string_id = CMMotiveUtils().get_motive_string(
                sim_info, motive_name)
            if motive_string_id == -1:
                motive_string_id = motive_name.upper()

            # noinspection PyTypeChecker
            option_dialog.add_option(
                CommonDialogInputFloatOption(
                    motive_name,
                    self.motive_utils.get_motive_level(sim_info, motive_name),
                    CommonDialogOptionContext(
                        motive_string_id,
                        CMStringId.SET_MOTIVE_LEVEL_OF_SIM,
                        description_tokens=(motive_string_id, sim_info)),
                    min_value=-100.0,
                    max_value=100.0,
                    on_chosen=_on_changed,
                    dialog_description_identifier=CMStringId.MIN_AND_MAX,
                    dialog_description_tokens=(
                        CommonLocalizationUtils.create_localized_string(
                            CMStringId.SET_MOTIVE_LEVEL_OF_SIM,
                            tokens=(motive_string_id, sim_info)), )))

        return option_dialog