Ejemplo n.º 1
0
def _common_testing_show_choose_item_dialog(_connection: int=None):
    output = sims4.commands.CheatOutput(_connection)
    output('Showing test choose item dialog.')

    def _item_chosen(chosen_item: str, result: CommonChooseItemResult):
        output('Item chosen {} with result: {}.'.format(pformat(chosen_item), pformat(result)))

    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),)
        from sims4communitylib.utils.common_icon_utils import CommonIconUtils
        options = [ObjectPickerRow(option_id=1, name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING),
                                   row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE),
                                   row_tooltip=None,
                                   icon=CommonIconUtils.load_checked_square_icon(),
                                   tag='Value 1'),
                   ObjectPickerRow(option_id=2, name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING),
                                   row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO),
                                   row_tooltip=None,
                                   icon=CommonIconUtils.load_arrow_navigate_into_icon(),
                                   tag='Value 2')]
        dialog = CommonChooseItemDialog(CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
                                        CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
                                        tuple(options),
                                        title_tokens=title_tokens,
                                        description_tokens=description_tokens)
        dialog.show(on_item_chosen=_item_chosen)
    except Exception as ex:
        log.format_error_with_message('Failed to show dialog', exception=ex)
        output('Failed to show dialog, please locate your exception log file.')
    output('Done showing.')
    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)
Ejemplo n.º 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
        )
Ejemplo n.º 4
0
    def _create_dialog(
        self,
        picker_type: UiObjectPicker.
        UiObjectPickerObjectPickerType = UiObjectPicker.
        UiObjectPickerObjectPickerType.OBJECT,
        target_sim_info_to_receive_objects: SimInfo = None,
        categories: Iterator[CommonDialogObjectOptionCategory] = (),
        object_delivery_method:
        CommonObjectDeliveryMethod = CommonObjectDeliveryMethod.INVENTORY
    ) -> Union[UiPurchasePicker, None]:
        try:
            category_type = namedtuple('category_type',
                                       ('tag', 'icon', 'tooltip'))
            dialog_categories = list()
            for category in tuple(categories):
                dialog_categories.append(
                    category_type(
                        category.object_category,
                        CommonIconUtils._load_icon(category.icon),
                        CommonLocalizationUtils.create_localized_string(
                            category.category_name)))

            inventory_target_id = CommonSimUtils.get_sim_id(
                target_sim_info_to_receive_objects
                or CommonSimUtils.get_active_sim_info())
            purchase_objects: List[int] = list()
            dialog = UiPurchasePicker.TunableFactory().default(
                target_sim_info_to_receive_objects
                or CommonSimUtils.get_active_sim_info(),
                text=lambda *_, **__: self.description,
                title=lambda *_, **__: self.title,
                categories=dialog_categories,
                max_selectable=UiDialogObjectPicker._MaxSelectableUnlimited())
            purchase_picker_data = PurchasePickerData()
            if object_delivery_method == CommonObjectDeliveryMethod.MAIL:
                purchase_picker_data.mailmain_delivery = True
            elif object_delivery_method == CommonObjectDeliveryMethod.INVENTORY:
                purchase_picker_data.inventory_owner_id_to_purchase_to = inventory_target_id
            for purchase_object in purchase_objects:
                purchase_picker_data.add_definition_to_purchase(
                    purchase_object)
            dialog.object_id = purchase_picker_data.inventory_owner_id_to_purchase_to
            dialog.mailman_purchase = purchase_picker_data.mailmain_delivery
            dialog.inventory_object_id = purchase_picker_data.inventory_owner_id_to_purchase_from
            dialog.purchase_by_object_ids = purchase_picker_data.use_obj_ids_in_response
            dialog.show_description = 1
            dialog.show_description_tooltip = 1
            dialog.use_dialog_pick_response = False
            dialog.max_selectable_num = len(self.rows)
            dialog.use_dropdown_filter = len(dialog_categories) > 0
            right_custom_text = None
            if right_custom_text is not None:
                dialog.right_custom_text = right_custom_text
            return dialog
        except Exception as ex:
            self.log.error('_create_dialog', exception=ex)
        return None
    def _create_dialog(
            self,
            picker_type: UiObjectPicker.
        UiObjectPickerObjectPickerType = UiObjectPicker.
        UiObjectPickerObjectPickerType.OBJECT,
            sim_info: SimInfo = None,
            categories: Iterator[CommonDialogObjectOptionCategory] = (),
            min_selectable: int = 1,
            max_selectable: int = 1) -> Union[UiObjectPicker, None]:
        try:
            from collections import namedtuple
            object_category_type = namedtuple(
                'object_category_type',
                ('object_category', 'icon', 'category_name'))
            object_categories = list()
            for category in tuple(categories):
                object_categories.append(
                    object_category_type(
                        category.object_category, lambda *_, **__:
                        IconInfoData(icon_resource=CommonIconUtils._load_icon(
                            category.icon)),
                        CommonLocalizationUtils.create_localized_string(
                            category.category_name)))

            if len(object_categories) > 0:
                self.log.debug('Building dialog with categories.')
                return CommonUiObjectCategoryPicker.TunableFactory().default(
                    sim_info or CommonSimUtils.get_active_sim_info(),
                    text=lambda *_, **__: self.description,
                    title=lambda *_, **__: self.title,
                    picker_type=picker_type,
                    use_dropdown_filter=True,
                    object_categories=tuple(object_categories),
                    min_selectable=min_selectable,
                    max_selectable=max_selectable)
            else:
                self.log.debug('Building dialog without categories.')
                return UiObjectPicker.TunableFactory().default(
                    sim_info or CommonSimUtils.get_active_sim_info(),
                    text=lambda *_, **__: self.description,
                    title=lambda *_, **__: self.title,
                    picker_type=picker_type,
                    min_selectable=min_selectable,
                    max_selectable=max_selectable)
        except Exception as ex:
            self.log.error('_create_dialog', exception=ex)
        return None
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def _setup_dialog_rows(
        self,
        _dialog: UiObjectPicker,
        page: int=1,
        categories: Iterator[CommonDialogObjectOptionCategory]=()
    ):
        if page < 0:
            raise AssertionError('page cannot be less than zero.')

        number_of_rows = len(self.rows)
        self.log.format(number_of_rows=number_of_rows, per_page=self._per_page)
        if number_of_rows > self._per_page:
            number_of_pages = math.ceil(number_of_rows / self._per_page)

            if page > number_of_pages:
                raise AssertionError('page was out of range. Number of Pages: {}, Requested Page: {}'.format(str(number_of_pages), str(page)))
            # Add the rows that are always visible.
            for always_visible_rows in self.always_visible_rows:
                _dialog.add_row(always_visible_rows)

            # Add the rows that should show on the current page.
            start_index = (page - 1) * self._per_page
            end_index = page * self._per_page
            self.log.format(start_index=start_index, end_index=end_index)
            current_choices = self.rows[start_index:end_index]
            self.log.format(current_rows=current_choices)
            for row in current_choices:
                _dialog.add_row(row)

            tag_list = [(abs(hash(category.object_category)) % (10 ** 8)) for category in categories]
            self.log.format_with_message('Found tags.', tag_list=tag_list)

            if page > 1:
                self.log.format_with_message('Adding Previous row.', page=page, number_of_pages=number_of_pages)
                previous_choice = ObjectPickerRow(
                    option_id=len(self.rows) + 2,
                    name=CommonLocalizationUtils.create_localized_string(CommonStringId.PREVIOUS),
                    row_description=None,
                    row_tooltip=CommonLocalizationUtils.create_localized_tooltip(CommonStringId.PREVIOUS),
                    icon=CommonIconUtils.load_arrow_left_icon(),
                    tag_list=tag_list,
                    tag=CommonDialogNavigationButtonTag.PREVIOUS
                )
                _dialog.add_row(previous_choice)
            else:
                self.log.format_with_message('Not adding Previous row.', page=page)
            if page < number_of_pages:
                self.log.format_with_message('Adding Next row.', page=page, number_of_pages=number_of_pages)
                next_choice = ObjectPickerRow(
                    option_id=len(self.rows) + 1,
                    name=CommonLocalizationUtils.create_localized_string(CommonStringId.NEXT),
                    row_description=None,
                    row_tooltip=CommonLocalizationUtils.create_localized_tooltip(CommonStringId.NEXT),
                    icon=CommonIconUtils.load_arrow_right_icon(),
                    tag_list=tag_list,
                    tag=CommonDialogNavigationButtonTag.NEXT
                )
                _dialog.add_row(next_choice)
            else:
                self.log.format_with_message('Not adding Next.', page=page, number_of_pages=number_of_pages)
        else:
            self.log.debug('Adding always visible rows.')
            for always_visible_rows in self.always_visible_rows:
                _dialog.add_row(always_visible_rows)
            self.log.debug('Adding rows.')
            for row in self.rows:
                _dialog.add_row(row)
    def show(self,
             on_chosen: Callable[[Any, CommonChoiceOutcome],
                                 Any] = CommonFunctionUtils.noop,
             picker_type: UiObjectPicker.
             UiObjectPickerObjectPickerType = UiObjectPicker.
             UiObjectPickerObjectPickerType.OBJECT,
             page: int = 1):
        """
            Show the dialog and invoke the callbacks upon the player making a choice.
        :param on_chosen: A callback invoked upon the player choosing something from the list.
        :param picker_type: The layout of the dialog.
        :param page: The page to display. Ignored if there is only one page of choices.
        """
        log.format_with_message('Attempting to display choices.', page=page)
        _dialog = self._create_dialog(picker_type=picker_type)
        if _dialog is None:
            log.error('_dialog was None for some reason.')
            return

        if on_chosen is None:
            raise ValueError('on_chosen was None.')

        if len(self._choices) == 0:
            raise AssertionError(
                'No rows have been provided. Add rows to the dialog before attempting to display it.'
            )

        if page < 0:
            raise AssertionError('page cannot be less than zero.')

        @CommonExceptionHandler.catch_exceptions(ModInfo.get_identity().name)
        def _on_chosen(dialog: UiObjectPicker):
            if not dialog.accepted:
                log.debug('Dialog cancelled.')
                return on_chosen(None, CommonChoiceOutcome.CANCEL)
            choice = CommonDialogUtils.get_chosen_item(dialog)
            if choice == 'S4CL_NEXT':
                log.debug('Next chosen.')
                self.show(on_chosen=on_chosen,
                          picker_type=picker_type,
                          page=page + 1)
                return True
            elif choice == 'S4CL_PREVIOUS':
                log.debug('Previous chosen.')
                self.show(on_chosen=on_chosen,
                          picker_type=picker_type,
                          page=page - 1)
                return True
            log.format_with_message('Choice made.', choice=choice)
            result = on_chosen(choice, CommonChoiceOutcome.CHOICE_MADE)
            log.format_with_message('Finished handling choice.', result=result)
            return result

        number_of_rows = len(self._choices)
        log.format(number_of_rows=number_of_rows, per_page=self._per_page)
        if number_of_rows > self._per_page:
            number_of_pages = math.ceil(number_of_rows / self._per_page)

            if page > number_of_pages:
                raise AssertionError(
                    'page was out of range. Number of Pages: {}, Requested Page: {}'
                    .format(str(number_of_pages), str(page)))

            start_index = (page - 1) * self._per_page
            end_index = page * self._per_page
            log.format(start_index=start_index, end_index=end_index)
            current_choices = self._choices[start_index:end_index]
            log.format(current_rows=current_choices)
            for row in current_choices:
                _dialog.add_row(row)

            if page < number_of_pages:
                log.format_with_message('Adding Next.',
                                        page=page,
                                        number_of_pages=number_of_pages)
                next_choice = ObjectPickerRow(
                    option_id=len(self._choices) + 1,
                    name=CommonLocalizationUtils.create_localized_string(
                        CommonStringId.NEXT),
                    row_description=None,
                    row_tooltip=None,
                    icon=CommonIconUtils.load_arrow_right_icon(),
                    tag='S4CL_NEXT')
                _dialog.add_row(next_choice)
            else:
                log.format_with_message('Not adding Next.',
                                        page=page,
                                        number_of_pages=number_of_pages)
            if page > 1:
                log.format_with_message('Adding Previous.',
                                        page=page,
                                        number_of_pages=number_of_pages)
                previous_choice = ObjectPickerRow(
                    option_id=len(self._choices) + 2,
                    name=CommonLocalizationUtils.create_localized_string(
                        CommonStringId.PREVIOUS),
                    row_description=None,
                    row_tooltip=None,
                    icon=CommonIconUtils.load_arrow_right_icon(),
                    tag='S4CL_PREVIOUS')
                _dialog.add_row(previous_choice)
            else:
                log.format_with_message('Not adding Previous.', page=page)
        else:
            log.debug('Adding all choices')
            for row in self._choices:
                _dialog.add_row(row)

        _dialog.add_listener(_on_chosen)
        _dialog.show_dialog()
    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 _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.')
 def icon(self) -> Any:
     if super().icon is not None:
         return super().icon
     return CommonIconUtils.load_arrow_right_icon()
    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
Ejemplo n.º 13
0
 def icon(self) -> Any:
     if super().icon is not None:
         return super().icon
     if self.value is True:
         return CommonIconUtils.load_checked_square_icon()
     return CommonIconUtils.load_unchecked_square_icon()
Ejemplo n.º 14
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)
Ejemplo n.º 15
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()
Ejemplo n.º 16
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 _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)
Ejemplo n.º 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)
def _common_testing_show_multi_pane_choose_dialog(_connection: int=None):
    output = sims4.commands.CheatOutput(_connection)
    output('Showing test multi-pane choose dialog.')

    def _on_submit(choices_made: Dict[int, Any], outcome: CommonChoiceOutcome) -> None:
        output('On Submit choices_made: {} and outcome: {}'.format(pformat(choices_made), pformat(outcome)))

    def _on_sub_dialog_one_chosen(choice: Any, outcome: CommonChoiceOutcome) -> None:
        output('Sub Dialog one choice made: {} outcome: {}'.format(pformat(choice), pformat(outcome)))

    def _on_sub_dialog_two_chosen(choice: Any, outcome: CommonChoiceOutcome) -> None:
        output('Sub Dialog two choice made: {} outcome: {}'.format(pformat(choice), pformat(outcome)))

    sim_info = CommonSimUtils.get_active_sim_info()

    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),)
        from sims4communitylib.utils.common_icon_utils import CommonIconUtils
        # Create the dialog.
        dialog = CommonMultiPaneChooseDialog(
            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
        )

        sub_dialog_one_options = [
            ObjectPickerRow(
                option_id=1,
                name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING),
                row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE),
                row_tooltip=None,
                icon=CommonIconUtils.load_checked_square_icon(),
                tag='Value 1'
            ),
            ObjectPickerRow(
                option_id=2,
                name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING),
                row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO),
                row_tooltip=None,
                icon=CommonIconUtils.load_arrow_navigate_into_icon(),
                tag='Value 2'
            ),
            ObjectPickerRow(
                option_id=3,
                name=CommonLocalizationUtils.create_localized_string('Value 3'),
                row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO),
                row_tooltip=None,
                icon=CommonIconUtils.load_arrow_navigate_into_icon(),
                tag='Value 3'
            )
        ]

        # Add sub dialog one.
        sub_dialog_one = CommonChooseObjectDialog(
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            tuple(sub_dialog_one_options),
            title_tokens=title_tokens,
            description_tokens=description_tokens
        )
        dialog.add_sub_dialog(sub_dialog_one, on_chosen=_on_sub_dialog_one_chosen, sim_info=sim_info)

        # Add sub dialog two.
        sub_dialog_two_options = [
            ObjectPickerRow(
                option_id=4,
                name=CommonLocalizationUtils.create_localized_string('Value 4'),
                row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE),
                row_tooltip=None,
                icon=CommonIconUtils.load_checked_square_icon(),
                tag='Value 4'
            ),
            ObjectPickerRow(
                option_id=5,
                name=CommonLocalizationUtils.create_localized_string('Value 5'),
                row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO),
                row_tooltip=None,
                icon=CommonIconUtils.load_arrow_navigate_into_icon(),
                tag='Value 5'
            ),
            ObjectPickerRow(
                option_id=6,
                name=CommonLocalizationUtils.create_localized_string('Value 6'),
                row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO),
                row_tooltip=None,
                icon=CommonIconUtils.load_arrow_navigate_into_icon(),
                tag='Value 6'
            )
        ]

        sub_dialog_two = CommonChooseObjectDialog(
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            tuple(sub_dialog_two_options),
            title_tokens=title_tokens,
            description_tokens=description_tokens
        )

        dialog.add_sub_dialog(sub_dialog_two, on_chosen=_on_sub_dialog_two_chosen, include_pagination=True)

        # Show the dialog.
        dialog.show(on_submit=_on_submit)
    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.')
Ejemplo n.º 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_choose_objects_dialog(_connection: int = None):
    output = sims4.commands.CheatOutput(_connection)
    output('Showing test choose objects dialog.')

    def _on_chosen(choices: Tuple[str], outcome: CommonChoiceOutcome):
        output('Chose {} with result: {}.'.format(pformat(choices),
                                                  pformat(outcome)))

    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), )
        from sims4communitylib.utils.common_icon_utils import CommonIconUtils
        options = [
            ObjectPickerRow(
                option_id=1,
                name=CommonLocalizationUtils.create_localized_string(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING),
                row_description=CommonLocalizationUtils.
                create_localized_string(
                    CommonStringId.TESTING_TEST_BUTTON_ONE),
                row_tooltip=None,
                icon=CommonIconUtils.load_checked_square_icon(),
                tag='Value 1'),
            ObjectPickerRow(
                option_id=2,
                name=CommonLocalizationUtils.create_localized_string(
                    CommonStringId.TESTING_SOME_TEXT_FOR_TESTING),
                row_description=CommonLocalizationUtils.
                create_localized_string(
                    CommonStringId.TESTING_TEST_BUTTON_TWO),
                row_tooltip=None,
                icon=CommonIconUtils.load_arrow_navigate_into_icon(),
                tag='Value 2'),
            ObjectPickerRow(
                option_id=3,
                name=CommonLocalizationUtils.create_localized_string(
                    'Value 3'),
                row_description=CommonLocalizationUtils.
                create_localized_string(
                    CommonStringId.TESTING_TEST_BUTTON_TWO),
                row_tooltip=None,
                icon=CommonIconUtils.load_arrow_navigate_into_icon(),
                tag='Value 3')
        ]
        dialog = CommonChooseObjectsDialog(
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            tuple(options),
            title_tokens=title_tokens,
            description_tokens=description_tokens,
            per_page=2)
        dialog.show(on_chosen=_on_chosen, 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.')
Ejemplo n.º 22
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)
Ejemplo n.º 23
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.')
Ejemplo n.º 24
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)
 def icon(self) -> Any:
     if super().icon is not None:
         return super().icon
     return CommonIconUtils.load_arrow_navigate_into_icon()
Ejemplo n.º 26
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