def _notify_exception_occurred(file_path: str):
     from ui.ui_dialog_notification import UiDialogNotification
     from sims4communitylib.notifications.common_basic_notification import CommonBasicNotification
     from sims4communitylib.enums.strings_enum import CommonStringId
     from sims4communitylib.events.zone_spin.common_zone_spin_event_dispatcher import CommonZoneSpinEventDispatcher
     if not CommonZoneSpinEventDispatcher.get().game_loaded:
         return
     basic_notification = CommonBasicNotification(
         CommonStringId.EXCEPTION_OCCURRED_TITLE,
         CommonStringId.EXCEPTION_OCCURRED_TEXT,
         description_tokens=(file_path,),
         urgency=UiDialogNotification.UiDialogNotificationUrgency.URGENT
     )
     basic_notification.show()
 def on_started(self, interaction_sim: Sim,
                interaction_target: Any) -> bool:
     self.log.format_with_message('Running \'{}\' on_started.'.format(
         self.__class__.__name__),
                                  interaction_sim=interaction_sim,
                                  interaction_target=interaction_target)
     self.log.enable()
     self.log.debug('Interactions that can be performed on \'{}\':'.format(
         interaction_target))
     interactions = CommonObjectInteractionUtils.get_all_interactions_registered_to_object_gen(
         interaction_target)
     interaction_short_names: List[str] = list()
     for interaction in interactions:
         try:
             interaction_short_names.append(
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction))
         except Exception as ex:
             self.log.error(
                 'Problem while attempting to handle interaction {}'.format(
                     pformat(interaction)),
                 exception=ex)
             continue
     sorted_short_names = sorted(interaction_short_names, key=lambda x: x)
     self.log.debug(pformat(sorted_short_names))
     self.log.debug('Done Logging Available Interactions.'.format())
     self.log.disable()
     CommonBasicNotification(
         CommonStringId.S4CL_LOG_ALL_INTERACTIONS,
         CommonStringId.S4CL_DONE_LOGGING_ALL_INTERACTIONS,
         description_tokens=(CommonLogUtils.get_message_file_path(
             self.mod_identity), )).show()
     return True
        def _on_yes_selected(_: Any):
            from sims4controlmenu.dialogs.modify_sim_data.modify_skills.operations.set_skill_level import \
                S4CMSetSkillLevelsSimOp
            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
                if not S4CMSetSkillLevelsSimOp()._is_skill_allowed_for_modification(sim_info, skill):
                    continue
                if not skill.can_add(sim):
                    self.verbose_log.format_with_message('Failed, Skill is not allowed for Sim.', skill=skill, sim=sim_info)
                    continue
                skill_levels = tuple(range(0, skill.max_level + 1))
                chosen_skill_level = random.choice(skill_levels)
                if chosen_skill_level == 0:
                    if CommonSimSkillUtils.has_skill(sim_info, skill):
                        CommonSimSkillUtils.remove_skill(sim_info, skill)
                else:
                    CommonSimSkillUtils.set_current_skill_level(sim_info, skill, int(chosen_skill_level))

            CommonBasicNotification(
                S4CMSimModifySkillsStringId.RANDOMIZED_SKILL_LEVELS_OF_SIM_TITLE,
                S4CMSimModifySkillsStringId.RANDOMIZED_SKILL_LEVELS_OF_SIM_DESCRIPTION,
                title_tokens=(sim,),
                description_tokens=(sim,)
            ).show(icon=IconInfoData(obj_instance=sim))
            _on_close()
 def _notify_exception_occurred(file_path: str, mod_identifier: Union[str, CommonModIdentity]=None):
     from ui.ui_dialog_notification import UiDialogNotification
     from sims4communitylib.notifications.common_basic_notification import CommonBasicNotification
     from sims4communitylib.enums.strings_enum import CommonStringId
     from sims4communitylib.events.zone_spin.common_zone_spin_event_dispatcher import CommonZoneSpinEventDispatcher
     if not CommonZoneSpinEventDispatcher.get().game_loaded:
         return
     mod_identifier = CommonModIdentity._get_mod_name(mod_identifier)
     basic_notification = CommonBasicNotification(
         CommonStringId.EXCEPTION_OCCURRED_TITLE_FOR_MOD,
         CommonStringId.EXCEPTION_OCCURRED_TEXT,
         title_tokens=(mod_identifier,),
         description_tokens=(file_path,),
         urgency=UiDialogNotification.UiDialogNotificationUrgency.URGENT
     )
     basic_notification.show()
Exemple #5
0
 def on_started(self, interaction_sim: Sim,
                interaction_target: Sim) -> bool:
     self.log.format_with_message('Running \'{}\' on_started.'.format(
         self.__class__.__name__),
                                  interaction_sim=interaction_sim,
                                  interaction_target=interaction_target)
     target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
     target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
     from sims4communitylib.utils.sims.common_sim_interaction_utils import CommonSimInteractionUtils
     from sims4communitylib.utils.resources.common_interaction_utils import CommonInteractionUtils
     running_interaction_names = ', '.join(
         CommonInteractionUtils.get_interaction_short_names(
             CommonSimInteractionUtils.get_running_interactions_gen(
                 target_sim_info)))
     queued_interaction_names = ', '.join(
         CommonInteractionUtils.get_interaction_short_names(
             CommonSimInteractionUtils.get_queued_interactions_gen(
                 target_sim_info)))
     text = ''
     text += 'Running Interactions:\n{}\n\n'.format(
         running_interaction_names)
     text += 'Queued Interactions:\n{}\n\n'.format(queued_interaction_names)
     CommonBasicNotification(
         CommonLocalizationUtils.create_localized_string(
             '{} Running and Queued Interactions'.format(target_sim_name)),
         CommonLocalizationUtils.create_localized_string(text)).show(
             icon=IconInfoData(obj_instance=interaction_target))
     return True
 def _recollect_data() -> None:
     try:
         if show_loading_notification:
             CommonBasicNotification(
                 CSFStringId.LOADING_SLIDERS,
                 CSFStringId.LOADING_SLIDERS_DESCRIPTION).show()
         number_of_sliders = self._collect()
         if number_of_sliders == -1:
             return
         CommonBasicNotification(
             CSFStringId.FINISHED_LOADING_SLIDERS,
             CSFStringId.FINISHED_LOADING_SLIDERS_DESCRIPTION,
             description_tokens=(str(number_of_sliders), )).show()
     except Exception as ex:
         self.log.error('Error occurred while collecting sliders.',
                        exception=ex)
         self._collecting = False
 def _register_alarm() -> None:
     has_setup_alarm_before = False
     if _AutosaveHandler._AUTOSAVE_ALARM_HANDLE is not None:
         has_setup_alarm_before = True
         from alarms import _lookup_alarm_handle
         alarm_handle = _lookup_alarm_handle(_AutosaveHandler._AUTOSAVE_ALARM_HANDLE._element_handle)
         if alarm_handle is not None:
             return
         CommonBasicNotification(
             'S4ASM Autosaving Setup Again',
             'S4ASM will autosave every {} minutes real time. Look for the notification!'.format(_AutosaveHandler._AUTOSAVE_INTERVAL_MINUTES)
         ).show()
     from alarms import add_alarm_real_time
     from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
     _AutosaveHandler._AUTOSAVE_ALARM_HANDLE = add_alarm_real_time(CommonSimUtils.get_active_sim_info(), _AutosaveHandler._get_autosave_interval(), _AutosaveHandler._time_to_save, repeating=True, cross_zone=True)
     if not has_setup_alarm_before:
         CommonBasicNotification(
             'S4ASM Autosaving Setup',
             'S4ASM will autosave every {} minutes real time. Look for the notification!'.format(_AutosaveHandler._AUTOSAVE_INTERVAL_MINUTES)
         ).show()
 def _time_to_save(*_) -> bool:
     try:
         if CommonZoneSpinEventDispatcher().game_loading or not CommonZoneSpinEventDispatcher().game_loaded:
             return False
         CommonBasicNotification(
             'S4ASM Autosaving',
             0
         ).show()
         import sims4.commands
         save_game_data = SaveGameData(CommonSaveUtils.get_save_slot_id(), 'S4ASMAutosave', True, 500001)
         persistence_service = services.get_persistence_service()
         persistence_service.save_using(persistence_service.save_game_gen, save_game_data, send_save_message=True, check_cooldown=False)
         CommonBasicNotification(
             'S4ASM Finished Autosaving',
             0
         ).show()
         return True
     except Exception as ex:
         CommonBasicNotification(
             'Problem Occurred While S4ASM Autosaving',
             0
         ).show()
         CommonExceptionHandler.log_exception(ModInfo.get_identity(), 'An exception occurred while autosaving.', exception=ex)
         return False
Exemple #9
0
 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_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()
Exemple #11
0
 def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool:
     self.log.format_with_message(
         'Running \'{}\' on_started.'.format(self.__class__.__name__),
         interaction_sim=interaction_sim,
         interaction_target=interaction_target
     )
     target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
     target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
     sim_situations = ', '.join(CommonSituationUtils.get_situation_names(CommonSimSituationUtils.get_situations(target_sim_info)))
     text = ''
     text += 'Running Situations:\n{}\n\n'.format(sim_situations)
     CommonBasicNotification(
         CommonLocalizationUtils.create_localized_string('{} Running Situations'.format(target_sim_name)),
         CommonLocalizationUtils.create_localized_string(text)
     ).show(
         icon=IconInfoData(obj_instance=interaction_target)
     )
     return True
        def _on_yes_selected(_: Any):
            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
                if not CommonSimSkillUtils.has_skill(sim_info, skill):
                    continue
                CommonSimSkillUtils.remove_skill(sim_info, skill)

            CommonBasicNotification(
                S4CMSimModifySkillsStringId.REMOVED_ALL_SKILLS_TITLE,
                S4CMSimModifySkillsStringId.REMOVED_ALL_SKILLS_DESCRIPTION,
                title_tokens=(sim, ),
                description_tokens=(sim, )).show(icon=IconInfoData(
                    obj_instance=sim))
            _on_close()
    def on_started(self, interaction_sim: Sim,
                   interaction_target: Sim) -> bool:
        target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
        target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
        from sims4communitylib.utils.sims.common_sim_interaction_utils import CommonSimInteractionUtils
        from sims4communitylib.utils.resources.common_interaction_utils import CommonInteractionUtils
        running_interaction_strings: List[str] = list()
        for interaction in CommonSimInteractionUtils.get_running_interactions_gen(
                target_sim_info):
            interaction_name = CommonInteractionUtils.get_interaction_short_name(
                interaction)
            interaction_id = CommonInteractionUtils.get_interaction_id(
                interaction)
            running_interaction_strings.append('{} ({})'.format(
                interaction_name, interaction_id))
        running_interaction_strings = sorted(running_interaction_strings,
                                             key=lambda x: x)
        running_interaction_names = ', '.join(running_interaction_strings)

        queued_interaction_strings: List[str] = list()
        for interaction in CommonSimInteractionUtils.get_queued_interactions_gen(
                target_sim_info):
            interaction_name = CommonInteractionUtils.get_interaction_short_name(
                interaction)
            interaction_id = CommonInteractionUtils.get_interaction_id(
                interaction)
            queued_interaction_strings.append('{} ({})'.format(
                interaction_name, interaction_id))
        queued_interaction_strings = sorted(queued_interaction_strings,
                                            key=lambda x: x)
        queued_interaction_names = ', '.join(queued_interaction_strings)
        text = ''
        text += 'Running Interactions:\n{}\n\n'.format(
            running_interaction_names)
        text += 'Queued Interactions:\n{}\n\n'.format(queued_interaction_names)
        CommonBasicNotification(
            CommonLocalizationUtils.create_localized_string(
                '{} Running and Queued Interactions ({})'.format(
                    target_sim_name,
                    CommonSimUtils.get_sim_id(target_sim_info))),
            CommonLocalizationUtils.create_localized_string(text)).show(
                icon=IconInfoData(obj_instance=interaction_target))
        return True
    def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool:
        target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
        target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
        trait_strings: List[str] = list()
        for trait in CommonTraitUtils.get_traits(target_sim_info):
            trait_name = CommonTraitUtils.get_trait_name(trait)
            trait_id = CommonTraitUtils.get_trait_id(trait)
            trait_strings.append('{} ({})'.format(trait_name, trait_id))

        trait_strings = sorted(trait_strings, key=lambda x: x)
        sim_traits = ', '.join(trait_strings)
        text = ''
        text += 'Traits:\n{}\n\n'.format(sim_traits)
        CommonBasicNotification(
            CommonLocalizationUtils.create_localized_string('{} Traits ({})'.format(target_sim_name, CommonSimUtils.get_sim_id(target_sim_info))),
            CommonLocalizationUtils.create_localized_string(text)
        ).show(
            icon=IconInfoData(obj_instance=interaction_target)
        )
        return True
    def on_started(self, interaction_sim: Sim, interaction_target: Any) -> bool:
        self.log.enable()
        object_id = CommonObjectUtils.get_object_id(interaction_target) if interaction_target is not None else -1
        definition_id = -1
        if isinstance(interaction_target, Sim):
            object_id = CommonSimUtils.get_sim_id(interaction_target)
        elif isinstance(interaction_target, GameObject):
            definition = CommonObjectUtils.get_game_object_definition(interaction_target)
            if definition is not None:
                definition_id = definition.id
        self.log.debug('Interactions that can be performed on \'{}\' id:{} def_id:{}:'.format(interaction_target, object_id, definition_id))
        interactions = CommonObjectInteractionUtils.get_all_interactions_registered_to_object_gen(interaction_target)
        interaction_target: GameObject = interaction_target
        interaction_short_names: List[str] = list()
        for interaction in interactions:
            interaction: Interaction = interaction
            try:
                interaction_short_names.append('{} ({})'.format(CommonInteractionUtils.get_interaction_short_name(interaction), CommonInteractionUtils.get_interaction_id(interaction)))
            except Exception as ex:
                self.log.error('Problem while attempting to handle interaction {}'.format(pformat(interaction)), exception=ex)
                continue
        for component in interaction_target.components:
            if not hasattr(component, 'component_super_affordances_gen'):
                continue
            for affordance in component.component_super_affordances_gen():
                try:
                    interaction_short_names.append('{} ({})'.format(CommonInteractionUtils.get_interaction_short_name(affordance), CommonInteractionUtils.get_interaction_id(affordance)))
                except Exception as ex:
                    self.log.error('Problem while attempting to handle affordance {}'.format(pformat(affordance)), exception=ex)
                    continue

        sorted_short_names = sorted(interaction_short_names, key=lambda x: x)
        self.log.format(interactions=sorted_short_names)
        self.log.debug('Done Logging Available Interactions.')
        self.log.disable()
        CommonBasicNotification(
            CommonStringId.S4CL_LOG_ALL_INTERACTIONS,
            CommonStringId.S4CL_DONE_LOGGING_ALL_INTERACTIONS,
            description_tokens=(CommonLogUtils.get_message_file_path(self.mod_identity), )
        ).show()
        return True
 def on_started(self, interaction_sim: Sim,
                interaction_target: Sim) -> bool:
     target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
     target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
     sim_buff_strings: List[str] = list()
     for buff in CommonBuffUtils.get_buffs(target_sim_info):
         buff_name = CommonBuffUtils.get_buff_name(buff)
         buff_id = CommonBuffUtils.get_buff_id(buff)
         sim_buff_strings.append('{} ({})'.format(buff_name, buff_id))
     sim_buff_strings = sorted(sim_buff_strings, key=lambda x: x)
     sim_buffs = ', '.join(sim_buff_strings)
     text = ''
     text += 'Active Buffs:\n{}\n\n'.format(sim_buffs)
     CommonBasicNotification(
         CommonLocalizationUtils.create_localized_string(
             '{} Active Buffs ({})'.format(
                 target_sim_name,
                 CommonSimUtils.get_sim_id(target_sim_info))),
         CommonLocalizationUtils.create_localized_string(text)).show(
             icon=IconInfoData(obj_instance=interaction_target))
     return True
Exemple #17
0
 def show_loaded_notification() -> None:
     """ Show that the sample mod has loaded. """
     notification = CommonBasicNotification(
         S4CLSampleModStringId.SAMPLE_MOD_LOADED_NOTIFICATION_TITLE,
         S4CLSampleModStringId.SAMPLE_MOD_LOADED_NOTIFICATION_DESCRIPTION)
     notification.show()
 def _show_sliders_loading_notification_on_first_update() -> None:
     if CSFSliderQueryRegistry()._collecting:
         CommonBasicNotification(
             CSFStringId.LOADING_SLIDERS,
             CSFStringId.LOADING_SLIDERS_DESCRIPTION).show()