示例#1
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
示例#3
0
    def _open_cas_part_selector(self, outfit_parts: Tuple[OCOutfitPart], tag: str, on_close_callback: Callable[[], None]=None, current_page: int=1):
        self.log.format_with_message('Opening with outfit parts.', outfit_parts=outfit_parts)

        def _on_close() -> None:
            if on_close_callback is not None:
                on_close_callback()

        def _reopen_dialog() -> None:
            self._open_cas_part_selector(outfit_parts, tag, on_close_callback=on_close_callback, current_page=option_dialog.current_page)

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

        outfit_io = CommonSimOutfitIO(self._sim_info, mod_identity=self.mod_identity)

        def _on_option_chosen(option_identifier: str, picked_outfit_part: OCOutfitPart):
            self.log.debug('Chose outfit part: {}'.format(option_identifier))
            self._open_body_type_selection(picked_outfit_part, outfit_io, on_close_callback=_reopen_dialog)

        def _on_remove_chosen() -> None:
            OCOutfitPartUtils.remove_outfit_parts(self._sim_info, outfit_parts)
            _reopen_dialog()

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

        if not outfit_parts:
            _no_outfit_parts_found()
            return

        sorted_outfit_parts = sorted(outfit_parts, key=lambda item: item.raw_display_name)

        option_dialog.add_option(
            CommonDialogActionOption(
                CommonDialogOptionContext(
                    OCStringId.OC_REMOVE_ALL,
                    0,
                    icon=CommonIconUtils.load_x_icon(),
                    tooltip_text_identifier=OCStringId.OC_REMOVE_ALL,
                ),
                on_chosen=_on_remove_chosen,
                always_visible=True
            )
        )

        for outfit_part in sorted_outfit_parts:
            if tag not in outfit_part.tag_list:
                continue
            part_id = outfit_part.part_id
            author = outfit_part.author
            icon = CommonIconUtils._load_icon(outfit_part.icon_id) or CommonIconUtils.load_question_mark_icon()
            outfit_part_name = outfit_part.display_name
            # If outfit part is already equipped
            if outfit_io.is_cas_part_attached(part_id):
                outfit_part_name = CommonLocalizationUtils.create_localized_string(CommonStringId.TEXT_WITH_GREEN_COLOR, tokens=(outfit_part_name,))

            option_dialog.add_option(
                CommonDialogObjectOption(
                    str(part_id),
                    outfit_part,
                    CommonDialogOptionContext(
                        outfit_part_name,
                        OCStringId.OC_AUTHOR,
                        description_tokens=(author,),
                        icon=icon,
                    ),
                    on_chosen=_on_option_chosen
                )
            )

        # noinspection PyTypeChecker
        option_dialog.show(
            sim_info=self._sim_info,
            picker_type=UiObjectPicker.UiObjectPickerObjectPickerType.OBJECT,
            page=current_page
        )