def __init__(self, title_identifier: Union[int, LocalizedString], description_identifier: Union[int, LocalizedString], title_tokens: Tuple[Any] = (), description_tokens: Tuple[Any] = (), urgency: UiDialogNotification. UiDialogNotificationUrgency = UiDialogNotification. UiDialogNotificationUrgency.DEFAULT, information_level: UiDialogNotification. UiDialogNotificationLevel = UiDialogNotification. UiDialogNotificationLevel.SIM, expand_behavior: UiDialogNotification. UiDialogNotificationExpandBehavior = UiDialogNotification. UiDialogNotificationExpandBehavior.USER_SETTING): """ Create a notification :param title_identifier: A decimal identifier of the title text. :param description_identifier: A decimal identifier of the description text. :param title_tokens: Tokens to format into the title. :param description_tokens: Tokens to format into the description. :param urgency: The urgency to which the notification will appear. (URGENT makes it orange) :param information_level: The information level of the notification. :param expand_behavior: Specify how the notification will expand. """ self.title = CommonLocalizationUtils.create_localized_string( title_identifier, tokens=title_tokens) self.description = CommonLocalizationUtils.create_localized_string( description_identifier, tokens=description_tokens) self.visual_type = UiDialogNotification.UiDialogNotificationVisualType.INFORMATION self.urgency = urgency self.information_level = information_level self.expand_behavior = expand_behavior self.ui_responses = ()
def _common_testing_show_ok_cancel_dialog(_connection: int=None): output = sims4.commands.CheatOutput(_connection) output('Showing test ok cancel dialog.') def _ok_chosen(_: UiDialogOkCancel): output('Ok option chosen.') def _cancel_chosen(_: UiDialogOkCancel): output('Cancel option chosen.') 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),) dialog = CommonOkCancelDialog(CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, title_tokens=title_tokens, description_tokens=description_tokens, ok_text_identifier=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE, text_color=CommonLocalizedStringColor.RED), cancel_text_identifier=CommonStringId.TESTING_TEST_BUTTON_TWO) dialog.show(on_ok_selected=_ok_chosen, on_cancel_selected=_cancel_chosen) except Exception as ex: log.format_error_with_message('Failed to show ok cancel dialog', exception=ex) output('Failed to show ok cancel dialog, please locate your exception log file.') output('Done showing.')
def __init__( self, question_text: Union[int, LocalizedString], question_tokens: Iterator[Any] = (), ok_text_identifier: Union[int, LocalizedString] = CommonStringId.OK, ok_text_tokens: Iterator[Any] = (), cancel_text_identifier: Union[ int, LocalizedString] = CommonStringId.CANCEL, cancel_text_tokens: Iterator[Any] = (), mod_identity: CommonModIdentity = None): """Create a dialog that prompts the player with a question. :param question_text: A decimal identifier of the question text. :param question_tokens: Tokens to format into the question text. :param ok_text_identifier: A decimal identifier for the Ok text. :param ok_text_tokens: Tokens to format into the Ok text. :param cancel_text_identifier: A decimal identifier for the Cancel text. :param cancel_text_tokens: Tokens to format into the Cancel text. """ super().__init__(0, question_text, description_tokens=question_tokens, mod_identity=mod_identity) self.ok_text = CommonLocalizationUtils.create_localized_string( ok_text_identifier, tokens=tuple(ok_text_tokens)) self.cancel_text = CommonLocalizationUtils.create_localized_string( cancel_text_identifier, tokens=tuple(cancel_text_tokens))
def _common_testing_show_ok_dialog(_connection: int=None): output = sims4.commands.CheatOutput(_connection) output('Showing test ok dialog.') def _on_acknowledged(_dialog: UiDialogOk): if _dialog.accepted: output('Ok option chosen.') else: output('Dialog closed.') 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),) dialog = CommonOkDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, title_tokens=title_tokens, description_tokens=description_tokens, ok_text_identifier=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE, text_color=CommonLocalizedStringColor.RED) ) dialog.show(on_acknowledged=_on_acknowledged) except Exception as ex: CommonExceptionHandler.log_exception(ModInfo.get_identity(), 'Failed to show dialog', exception=ex) output('Failed to show ok dialog, please locate your exception log file.') output('Done showing.')
def __init__(self, mod_identity: CommonModIdentity, title_identifier: Union[int, str, LocalizedString, CommonStringId], description_identifier: Union[int, str, LocalizedString, CommonStringId], responses: Iterator[CommonUiDialogResponse], title_tokens: Iterator[Any] = (), description_tokens: Iterator[Any] = (), next_button_text: Union[int, str, LocalizedString, CommonStringId] = CommonStringId.NEXT, previous_button_text: Union[ int, str, LocalizedString, CommonStringId] = CommonStringId.PREVIOUS, per_page: int = 10): super().__init__(title_identifier, description_identifier, title_tokens=title_tokens, description_tokens=description_tokens, mod_identity=mod_identity) if per_page <= 0: raise AssertionError('\'per_page\' must be greater than zero.') self._responses = tuple(responses) self._per_page = per_page self._current_page = 1 self._next_button_text = CommonLocalizationUtils.create_localized_string( next_button_text) self._previous_button_text = CommonLocalizationUtils.create_localized_string( previous_button_text) self._always_visible_responses = tuple()
def _common_testing_show_basic_notification(_connection: int = None): output = sims4.commands.CheatOutput(_connection) output('Showing test basic notification.') try: # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string( CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.BLUE), ) 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), ) dialog = CommonBasicNotification( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, title_tokens=title_tokens, description_tokens=description_tokens, urgency=UiDialogNotification.UiDialogNotificationUrgency.URGENT) dialog.show() except Exception as ex: log.format_error_with_message('Failed to show a basic notification', exception=ex) output( 'Failed to show a basic notification, please locate your exception log file.' ) output('Done showing.')
def __init__( self, title_identifier: Union[int, LocalizedString], description_identifier: Union[int, LocalizedString], title_tokens: Iterator[Any]=(), description_tokens: Iterator[Any]=(), ok_text_identifier: Union[int, LocalizedString]=CommonStringId.OK, ok_text_tokens: Iterator[Any]=(), cancel_text_identifier: Union[int, LocalizedString]=CommonStringId.CANCEL, cancel_text_tokens: Iterator[Any]=(), mod_identity: CommonModIdentity=None ): """Create a dialog with two buttons: Ok and Cancel. :param title_identifier: A decimal identifier of the title text. :param description_identifier: A decimal identifier of the description text. :param title_tokens: Tokens to format into the title. :param description_tokens: Tokens to format into the description. :param ok_text_identifier: A decimal identifier for the Ok text. :param ok_text_tokens: Tokens to format into the Ok text. :param cancel_text_identifier: A decimal identifier for the Cancel text. :param cancel_text_tokens: Tokens to format into the Cancel text. """ super().__init__( title_identifier, description_identifier, title_tokens=title_tokens, description_tokens=description_tokens, mod_identity=mod_identity ) self.ok_text = CommonLocalizationUtils.create_localized_string(ok_text_identifier, tokens=tuple(ok_text_tokens)) self.cancel_text = CommonLocalizationUtils.create_localized_string(cancel_text_identifier, tokens=tuple(cancel_text_tokens))
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 get_disabled_text( self, grandparent_sim_info: SimInfo, grandchild_sim_info: SimInfo) -> Union[LocalizedString, None]: if not CommonSimGenealogyUtils.has_mother(grandchild_sim_info): return CommonLocalizationUtils.create_localized_string( S4CMSimControlMenuStringId. SIM_NEEDS_TO_HAVE_A_RELATION_BEFORE_YOU_CAN_ADD_A_RELATION_TO_THEM, tokens=(grandchild_sim_info, S4CMSimControlMenuStringId.MOTHER, self.get_display_name(grandparent_sim_info, grandchild_sim_info))) if CommonSimGenealogyUtils.is_father_of(grandparent_sim_info, grandchild_sim_info): return CommonLocalizationUtils.create_localized_string( S4CMSimControlMenuStringId. SIM_CANNOT_BE_BOTH_RELATION_AND_RELATION_OF_SIM, tokens=(grandparent_sim_info, S4CMSimControlMenuStringId.FATHER, self.get_display_name(grandchild_sim_info, grandparent_sim_info), grandchild_sim_info)) if CommonSimGenealogyUtils.is_mother_of(grandparent_sim_info, grandchild_sim_info): return CommonLocalizationUtils.create_localized_string( S4CMSimControlMenuStringId. SIM_CANNOT_BE_BOTH_RELATION_AND_RELATION_OF_SIM, tokens=(grandparent_sim_info, S4CMSimControlMenuStringId.MOTHER, self.get_display_name(grandchild_sim_info, grandparent_sim_info), grandchild_sim_info)) return super().get_disabled_text(grandparent_sim_info, grandchild_sim_info)
def __init__(self, title_identifier: Union[int, str, LocalizedString, CommonStringId], description_identifier: Union[int, str, LocalizedString, CommonStringId], title_tokens: Iterator[Any] = (), description_tokens: Iterator[Any] = (), urgency: UiDialogNotification. UiDialogNotificationUrgency = UiDialogNotification. UiDialogNotificationUrgency.DEFAULT, information_level: UiDialogNotification. UiDialogNotificationLevel = UiDialogNotification. UiDialogNotificationLevel.SIM, expand_behavior: UiDialogNotification. UiDialogNotificationExpandBehavior = UiDialogNotification. UiDialogNotificationExpandBehavior.USER_SETTING): self.title = CommonLocalizationUtils.create_localized_string( title_identifier, tokens=tuple(title_tokens)) self.description = CommonLocalizationUtils.create_localized_string( description_identifier, tokens=tuple(description_tokens)) self.visual_type = UiDialogNotification.UiDialogNotificationVisualType.INFORMATION self.urgency = urgency self.information_level = information_level self.expand_behavior = expand_behavior self.ui_responses = ()
def _common_testing_show_input_float_dialog(_connection: int = None): output = sims4.commands.CheatOutput(_connection) output('Showing test input float dialog.') def _on_chosen(choice: float, outcome: CommonChoiceOutcome): output('Chose {} with result: {}.'.format(pformat(choice), 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 dialog = CommonInputFloatDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, 2.0, title_tokens=title_tokens, description_tokens=description_tokens) dialog.show(on_submit=_on_chosen) 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 _common_testing_show_targeted_question_dialog(_connection: int=None): output = sims4.commands.CheatOutput(_connection) output('Showing test targeted question dialog.') def _ok_chosen(_: UiDialogOkCancel): output('Ok option chosen.') def _cancel_chosen(_: UiDialogOkCancel): output('Cancel option chosen.') try: # LocalizedStrings within other LocalizedStrings 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),) dialog = CommonTargetedQuestionDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, question_tokens=description_tokens, ok_text_identifier=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE, text_color=CommonLocalizedStringColor.RED), cancel_text_identifier=CommonStringId.TESTING_TEST_BUTTON_TWO ) dialog.show( CommonSimUtils.get_active_sim_info(), tuple(CommonSimUtils.get_sim_info_for_all_sims_generator())[0], on_ok_selected=_ok_chosen, on_cancel_selected=_cancel_chosen ) except Exception as ex: CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Failed to show dialog', exception=ex) output('Failed to show ok cancel dialog, please locate your exception log file.') output('Done showing.')
def __init__( self, dialog_response_id: int, value: Any, sort_order: int = 0, text: Union[int, str, LocalizedString, CommonStringId] = None, subtext: Union[int, str, LocalizedString, CommonStringId] = None, ui_request: UiDialogResponse.UiDialogUiRequest = UiDialogResponse. UiDialogUiRequest.NO_REQUEST, response_command: Any = None, disabled_text: Union[int, str, LocalizedString, CommonStringId] = None): super().__init__( sort_order=sort_order, dialog_response_id=dialog_response_id, text=lambda *_, **__: CommonLocalizationUtils. create_localized_string(text) if text is not None else None, subtext=CommonLocalizationUtils.create_localized_string(subtext) if subtext is not None else None, ui_request=ui_request, response_command=response_command, disabled_text=CommonLocalizationUtils.create_localized_string( disabled_text) if disabled_text is not None else None) self.response_id = int(dialog_response_id) self.value = value
def __init__(self) -> None: super().__init__() self._default_title = CommonLocalizationUtils.create_localized_string( S4MSMStringId.MOD_SETTINGS, tokens=(self.mod_name, )) self._default_description = CommonLocalizationUtils.create_localized_string( S4MSMStringId.ALL_SETTINGS_RELATED_TO_MOD, tokens=(self.mod_name, ))
def _common_testing_show_choose_sim_option_dialog(_connection: int=None): output = sims4.commands.CheatOutput(_connection) output('Showing test choose sim option dialog.') def _on_chosen(_sim_info: SimInfo): output('Chose Sim with name \'{}\''.format(CommonSimNameUtils.get_full_name(_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 ), ) # Create the dialog and show a number of Sims in 4 columns. option_dialog = CommonChooseSimOptionDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, title_tokens=title_tokens, description_tokens=description_tokens, mod_identity=ModInfo.get_identity() ) current_count = 0 count = 25 for sim_info in CommonSimUtils.get_sim_info_for_all_sims_generator(): if current_count >= count: break should_select = random.choice((True, False)) is_enabled = random.choice((True, False)) option_dialog.add_option( CommonDialogSimOption( sim_info, CommonDialogSimOptionContext( is_enabled=is_enabled, is_selected=should_select ), on_chosen=_on_chosen ) ) option_dialog.show( sim_info=CommonSimUtils.get_active_sim_info(), column_count=4 ) 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 __init__(self, title_identifier: Union[int, LocalizedString], description_identifier: Union[int, LocalizedString], list_items: Tuple[ObjectPickerRow], title_tokens: Tuple[Any] = (), description_tokens: Tuple[Any] = ()): self.title = CommonLocalizationUtils.create_localized_string( title_identifier, tokens=title_tokens) self.description = CommonLocalizationUtils.create_localized_string( description_identifier, tokens=description_tokens) self.list_items = list_items
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: 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 __init__(self, title_identifier: Union[int, LocalizedString], description_identifier: Union[int, LocalizedString], title_tokens: Iterator[Any] = (), description_tokens: Iterator[Any] = (), mod_identity: CommonModIdentity = None): super().__init__() self.title = CommonLocalizationUtils.create_localized_string( title_identifier, tokens=tuple(title_tokens)) self.description = CommonLocalizationUtils.create_localized_string( description_identifier, tokens=tuple(description_tokens)) self._mod_identity = mod_identity
def _common_testing_show_choose_sims_dialog(_connection: int = None): output = sims4.commands.CheatOutput(_connection) output('Showing test choose sims dialog.') def _on_chosen(choice: Union[Tuple[SimInfo], None], outcome: CommonChoiceOutcome): output('Chose {} with result: {}.'.format( CommonSimNameUtils.get_full_names(choice), 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 current_count = 0 count = 25 options = [] for sim_info in CommonSimUtils.get_sim_info_for_all_sims_generator(): if current_count >= count: break sim_id = CommonSimUtils.get_sim_id(sim_info) is_enabled = random.choice((True, False)) options.append( SimPickerRow(sim_id, select_default=False, tag=sim_info, is_enable=is_enabled)) current_count += 1 dialog = CommonChooseSimsDialog( 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_chosen=_on_chosen, column_count=5, min_selectable=2, max_selectable=6) except Exception as ex: CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Failed to show dialog', exception=ex) output( 'Failed to show dialog, please locate your exception log file and upload it to the appropriate thread.' ) output('Done showing.')
def _common_testing_show_choose_response_dialog(_connection: int = None): output = sims4.commands.CheatOutput(_connection) output('Showing test choose response dialog.') def _on_chosen(choice: str, outcome: CommonChoiceOutcome): output('Chose {} with result: {}.'.format(pformat(choice), pformat(outcome))) try: responses: Tuple[CommonUiDialogResponse] = ( CommonUiDialogResponse( 1, 'Value 1', text=CommonLocalizationUtils.create_localized_string( CommonStringId.TESTING_TEST_BUTTON_ONE)), CommonUiDialogResponse( 2, 'Value 2', text=CommonLocalizationUtils.create_localized_string( CommonStringId.TESTING_TEST_BUTTON_TWO)), CommonUiDialogResponse( 3, 'Value 3', text=CommonLocalizationUtils.create_localized_string( 'Test Button 3'))) 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), ) active_sim_info = CommonSimUtils.get_active_sim_info() dialog = CommonChooseResponseDialog( ModInfo.get_identity(), CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, responses, title_tokens=title_tokens, description_tokens=description_tokens, per_page=2) dialog.show(sim_info=active_sim_info, on_chosen=_on_chosen, include_previous_button=False) 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 __init__(self, mod_identity: CommonModIdentity, option_identifier: DialogOptionIdentifierType, initial_value: str, context: CommonDialogOptionContext, on_chosen: Callable[ [DialogOptionIdentifierType, str, CommonChoiceOutcome], None] = CommonFunctionUtils.noop, always_visible: bool = False, dialog_description_identifier: Union[int, str, LocalizedString, CommonStringId] = None, dialog_description_tokens: Iterator[Any] = ()): if dialog_description_identifier is not None: dialog_description = CommonLocalizationUtils.create_localized_string( dialog_description_identifier, tokens=tuple(dialog_description_tokens)) else: dialog_description = context.description self._dialog = CommonInputTextDialog(mod_identity, context.title, dialog_description, initial_value) def _on_submit(_: str, __: CommonChoiceOutcome): on_chosen(self.option_identifier, _, __) def _on_chosen(_, __) -> None: self._dialog.show(on_submit=_on_submit) super().__init__(option_identifier, None, context, on_chosen=_on_chosen, always_visible=always_visible)
def __init__(self, option_identifier: str, initial_value: float, context: CommonDialogOptionContext, min_value: float = 0.0, max_value: float = 2147483647.0, on_chosen: Callable[[str, float, CommonChoiceOutcome], Any] = CommonFunctionUtils.noop, always_visible: bool = False, dialog_description_identifier: Union[int, str, LocalizedString] = None, dialog_description_tokens: Iterator[Any] = ()): if dialog_description_identifier is not None: dialog_description = CommonLocalizationUtils.create_localized_string( dialog_description_identifier, tokens=tuple(dialog_description_tokens)) else: dialog_description = context.description self._dialog = CommonInputFloatDialog(context.title, dialog_description, initial_value, min_value=min_value, max_value=max_value) def _on_submit(_: float, __: CommonChoiceOutcome): on_chosen(self.option_identifier, _, __) def _on_chosen(_, __) -> None: self._dialog.show(on_submit=_on_submit) super().__init__(option_identifier, None, context, on_chosen=_on_chosen, always_visible=always_visible)
def add_buff(sim_info: SimInfo, *buff_ids: int, buff_reason: Union[int, str, LocalizedString]=None) -> bool: """add_buff(sim_info, *buff_ids, buff_reason=None) Add the specified buffs to a sim. :param sim_info: The sim to add the specified buffs to. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of buffs to add. :type buff_ids: int :param buff_reason: The text that will display when the player hovers over the buffs. What caused the buffs to be added. :type buff_reason: Union[int, str, LocalizedString], optional :return: True, if all of the specified buffs were successfully added. False, if not. :rtype: bool """ if sim_info is None: CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''.format(CommonBuffUtils.add_buff.__name__, CommonBuffUtils.__name__)) return False if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False localized_buff_reason = CommonLocalizationUtils.create_localized_string(buff_reason) success = True for buff_identifier in buff_ids: buff_instance = CommonBuffUtils._load_buff_instance(buff_identifier) if buff_instance is None: continue if not sim_info.add_buff_from_op(buff_instance, buff_reason=localized_buff_reason): success = False return success
def add_buff( sim_info: SimInfo, *buff_ids: Union[int, CommonBuffId], buff_reason: Union[int, str, LocalizedString, CommonStringId] = None ) -> bool: """add_buff(sim_info, *buff_ids, buff_reason=None) Add the specified buffs to a sim. :param sim_info: The sim to add the specified buffs to. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of buffs to add. :type buff_ids: int :param buff_reason: The text that will display when the player hovers over the buffs. What caused the buffs to be added. :type buff_reason: Union[int, str, LocalizedString, CommonStringId], optional :return: True, if all of the specified buffs were successfully added. False, if not. :rtype: bool """ if sim_info is None: raise AssertionError('Argument sim_info was None') if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False localized_buff_reason = CommonLocalizationUtils.create_localized_string( buff_reason) success = True for buff_identifier in buff_ids: buff_instance = CommonBuffUtils.load_buff_by_id(buff_identifier) if buff_instance is None: continue if not sim_info.add_buff_from_op( buff_instance, buff_reason=localized_buff_reason): success = False return success
def __init__(self, title_identifier: Union[int, LocalizedString], description_identifier: Union[int, LocalizedString], list_items: Tuple[ObjectPickerRow], title_tokens: Tuple[Any]=(), description_tokens: Tuple[Any]=()): """ Create a dialog displaying a list of items to choose from. :param title_identifier: A decimal identifier of the title text. :param description_identifier: A decimal identifier of the description text. :param list_items: The items to display in the dialog. :param title_tokens: Tokens to format into the title. :param description_tokens: Tokens to format into the description. """ self.title = CommonLocalizationUtils.create_localized_string(title_identifier, tokens=title_tokens) self.description = CommonLocalizationUtils.create_localized_string(description_identifier, tokens=description_tokens) self.list_items = list_items
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 __init__( self, question_text: Union[int, LocalizedString], question_tokens: Iterator[Any]=(), ok_text_identifier: Union[int, LocalizedString]=CommonStringId.OK, ok_text_tokens: Iterator[Any]=(), cancel_text_identifier: Union[int, LocalizedString]=CommonStringId.CANCEL, cancel_text_tokens: Iterator[Any]=(), mod_identity: CommonModIdentity=None ): super().__init__( 0, question_text, description_tokens=question_tokens, mod_identity=mod_identity ) self.ok_text = CommonLocalizationUtils.create_localized_string(ok_text_identifier, tokens=tuple(ok_text_tokens)) self.cancel_text = CommonLocalizationUtils.create_localized_string(cancel_text_identifier, tokens=tuple(cancel_text_tokens))
def __init__(self, text_identifier: Union[int, str, LocalizedString, CommonStringId], text_tokens: Iterator[Any] = (), subtext_identifier: Union[int, str, LocalizedString, CommonStringId] = None, subtext_tokens: Iterator[Any] = (), disabled_text_identifier: Union[int, str, LocalizedString, CommonStringId] = None, disabled_text_tokens: Iterator[Any] = ()): self._text = CommonLocalizationUtils.create_localized_string( text_identifier, tokens=tuple(text_tokens)) self._subtext = CommonLocalizationUtils.create_localized_string( subtext_identifier, tokens=tuple( subtext_tokens)) if subtext_identifier is not None else None self._disabled_text = CommonLocalizationUtils.create_localized_string( disabled_text_identifier, tokens=tuple(disabled_text_tokens) ) if disabled_text_identifier is not None else None
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 build_msg(self, text_input_overrides=None, additional_tokens: Tuple[Any]=(), **kwargs): """Build the message. """ msg = super().build_msg(additional_tokens=(), **kwargs) text_input_msg = msg.text_input.add() text_input_msg.text_input_name = 'text_input' if additional_tokens and additional_tokens[0] is not None: text_input_msg.initial_value = CommonLocalizationUtils.create_localized_string(additional_tokens[0]) return msg