Esempio n. 1
0
	def GenerateDialogResponse (self) -> ui_dialog.UiDialogResponse:
		if self.Selected:
			valueButtonStringTokens = ("> ", self.Text, " <")
		else:
			valueButtonStringTokens = ("", self.Text, "")

		if self.ChoiceButton.IdentifierIsRegistered():
			buttonTextString = self.ChoiceButton.GetCallableLocalizationString(*valueButtonStringTokens)
		else:
			buttonTextString = self.Text

		responseArguments = {
			"dialog_response_id": self.ResponseID,
			"sort_order": self.SortOrder,
			"text": buttonTextString
		}

		if self.SubText is not None:
			buttonSubTextString = lambda *args, **kwargs: self.SubText

			responseArguments["subtext"] = buttonSubTextString

		response = ui_dialog.UiDialogResponse(**responseArguments)

		return response
Esempio n. 2
0
def _ShowPromotionNotification(promotion: _Promotion) -> None:
    notificationArguments = {
        "text":
        lambda *args, **kwargs: Language.CreateLocalizationString(promotion.
                                                                  Text)
    }

    if promotion.Link is not None:
        if promotion.LinkButton is not None:
            linkResponseText = lambda *args, **kwargs: Language.CreateLocalizationString(
                promotion.LinkButton)
        else:
            linkResponseText = PromotionDefaultButton.GetCallableLocalizationString(
            )

        linkResponseCommand = collections.make_immutable_slots_class(
            ("command", "arguments"))

        linkResponseArguments = [
            collections.make_immutable_slots_class(("arg_value", "arg_type"))
        ]

        linkResponseArguments[0] = linkResponseArguments[0]({
            "arg_value":
            codecs.encode(bytearray(promotion.Link, "utf-8"),
                          "hex").decode("utf-8"),
            "arg_type":
            ui_dialog.CommandArgType.ARG_TYPE_STRING
        })

        linkResponseCommand = linkResponseCommand({
            "command":
            This.Mod.Namespace.lower() + ".distribution.show_url",
            "arguments":
            linkResponseArguments
        })

        linkResponse = ui_dialog.UiDialogResponse(
            text=linkResponseText,
            ui_request=ui_dialog.UiDialogResponse.UiDialogUiRequest.
            SEND_COMMAND,
            response_command=linkResponseCommand)

        notificationArguments["ui_responses"] = (linkResponse, )

    if promotion.Title is not None:
        notificationArguments[
            "title"] = lambda *args, **kwargs: Language.CreateLocalizationString(
                promotion.Title)
    else:
        notificationArguments[
            "title"] = PromotionDefaultTitle.GetCallableLocalizationString()

    Notifications.ShowNotification(queue=True, **notificationArguments)
Esempio n. 3
0
def _ShowPreviewUpdateNotification(mod: Mods.Mod,
                                   version: Version.Version) -> None:
    updateURL = Websites.GetNOSupportModPreviewPostsURL(mod)  # type: str

    showUpdateResponseCommand = collections.make_immutable_slots_class(
        ("command", "arguments"))

    showUpdateResponseArguments = [
        collections.make_immutable_slots_class(("arg_value", "arg_type"))
    ]

    showUpdateResponseArguments[0] = showUpdateResponseArguments[0]({
        "arg_value":
        codecs.encode(bytearray(updateURL, "utf-8"), "hex").decode("utf-8"),
        "arg_type":
        ui_dialog.CommandArgType.ARG_TYPE_STRING
    })

    showUpdateResponseCommand = showUpdateResponseCommand({
        "command":
        This.Mod.Namespace.lower() + ".distribution.show_url",
        "arguments":
        showUpdateResponseArguments
    })

    showUpdateResponse = ui_dialog.UiDialogResponse(
        text=UpdateNotificationButton.GetCallableLocalizationString(),
        ui_request=ui_dialog.UiDialogResponse.UiDialogUiRequest.SEND_COMMAND,
        response_command=showUpdateResponseCommand)

    notificationArguments = {
        "title":
        UpdateNotificationTitle.GetCallableLocalizationString(mod.Name),
        "text":
        UpdateNotificationReleaseText.GetCallableLocalizationString(
            str(version)),
        "ui_responses": (showUpdateResponse, )
    }

    Notifications.ShowNotification(queue=True, **notificationArguments)

    modShownPreviewVersions = _shownPreviewVersions.get(mod)  # type: list

    if modShownPreviewVersions is None:
        modShownPreviewVersions = list()
        _shownPreviewVersions[mod] = modShownPreviewVersions

    if not version in modShownPreviewVersions:
        modShownPreviewVersions.append(version)
Esempio n. 4
0
    def GenerateDialogResponse(self) -> ui_dialog.UiDialogResponse:
        buttonTextString = lambda *args, **kwargs: self.Text

        responseArguments = {
            "dialog_response_id": self.ResponseID,
            "sort_order": self.SortOrder,
            "text": buttonTextString
        }

        if self.SubText is not None:
            buttonSubTextString = lambda *args, **kwargs: self.SubText
            responseArguments["subtext"] = buttonSubTextString

        response = ui_dialog.UiDialogResponse(**responseArguments)

        return response
Esempio n. 5
0
def ShowResetDialog (mod: Mods.Mod) -> None:
	everythingResponseID = 20000  # type: int
	everythingResponse = ui_dialog.UiDialogResponse(
		sort_order = -2,
		dialog_response_id = everythingResponseID,
		text = DialogEverythingButton.GetCallableLocalizationString()
	)  # type: ui_dialog.UiDialogResponse

	settingsResponseID = 20001  # type: int
	settingsResponse = ui_dialog.UiDialogResponse(
		sort_order = -1,
		dialog_response_id = settingsResponseID,
		text = DialogSettingsButton.GetCallableLocalizationString()
	)  # type: ui_dialog.UiDialogResponse

	dialogArguments = {
		"title": DialogTitle.GetCallableLocalizationString(mod.Name),
		"text": DialogText.GetCallableLocalizationString(),
		"text_ok": DialogCancelButton.GetCallableLocalizationString(),
		"ui_responses": [everythingResponse, settingsResponse]
	}

	def ConfirmDialogEverythingCallback (dialogReference: ui_dialog.UiDialogOkCancel) -> None:
		try:
			if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
				ResetEverything(mod)
				return
		except Exception as e:
			Debug.Log("Failed to run the confirm dialog everything callback for the reset dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, exception = e)

	def ConfirmDialogSettingsCallback (dialogReference: ui_dialog.UiDialogOkCancel) -> None:
		try:
			if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
				ResetSettings(mod)
				return
		except Exception as e:
			Debug.Log("Failed to run the confirm dialog settings callback for the reset dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, exception = e)

	def DialogCallback (dialogReference: ui_dialog.UiDialogOkCancel) -> None:
		try:
			if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
				return

			confirmDialogCallback = None  # type: typing.Optional[typing.Callable]
			confirmDialogText = None  # type: typing.Optional[typing.Callable]

			if dialogReference.response == everythingResponseID:
				confirmDialogCallback = ConfirmDialogEverythingCallback
				confirmDialogText = ConfirmDialogEverythingText.GetCallableLocalizationString()
			elif dialogReference.response == settingsResponseID:
				confirmDialogCallback = ConfirmDialogSettingsCallback
				confirmDialogText = ConfirmDialogSettingsText.GetCallableLocalizationString()

			confirmDialogArguments = {
				"title": ConfirmDialogTitle.GetCallableLocalizationString(mod.Name),
				"text": confirmDialogText,
				"text_ok": ConfirmDialogYesButton.GetCallableLocalizationString(),
				"text_cancel": ConfirmDialogNoButton.GetCallableLocalizationString()
			}  # type: typing.Dict[str, ...]

			Dialogs.ShowOkCancelDialog(callback = confirmDialogCallback, queue = False, **confirmDialogArguments)
		except Exception as e:
			Debug.Log("Failed to run the callback for the reset dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, exception = e)

	Dialogs.ShowOkDialog(callback = DialogCallback, queue = False, **dialogArguments)
Esempio n. 6
0
def _ShowPrepareReportLocationDialog(_connection: int = None) -> None:
    try:
        reportFileName = "NeonOcean Sims 4 Bug Report.zip"  # type: str

        dialogResponses = list(
        )  # type: typing.List[ui_dialog.UiDialogResponse]

        gameUserDataDirectoryPath = Paths.UserDataPath  # type: str
        gameUserDataReportFilePath = os.path.join(gameUserDataDirectoryPath,
                                                  reportFileName)  # type: str
        gameUserDataReportResponseID = 1  # type: int

        if os.path.exists(gameUserDataDirectoryPath):
            gameUserDataResponseArguments = {
                "dialog_response_id":
                gameUserDataReportResponseID,
                "sort_order":
                -2,
                "text":
                PrepareReportLocationDialogGameUserDataButton.
                GetCallableLocalizationString()
            }

            dialogResponses.append(
                ui_dialog.UiDialogResponse(**gameUserDataResponseArguments))
        else:
            raise Exception("The game's user data path does not exist.")

        desktopDirectoryPath = os.path.expanduser("~/Desktop")  # type: str
        desktopReportFilePath = os.path.join(desktopDirectoryPath,
                                             reportFileName)  # type: str
        desktopReportResponseID = 2  # type: int

        if os.path.exists(desktopDirectoryPath):
            desktopResponseArguments = {
                "dialog_response_id":
                desktopReportResponseID,
                "sort_order":
                -2,
                "text":
                PrepareReportLocationDialogDesktopButton.
                GetCallableLocalizationString()
            }

            dialogResponses.append(
                ui_dialog.UiDialogResponse(**desktopResponseArguments))

        dialogArguments = {
            "title":
            PrepareReportLocationDialogTitle.GetCallableLocalizationString(),
            "text":
            PrepareReportLocationDialogText.GetCallableLocalizationString(),
            "text_ok":
            PrepareReportLocationDialogCancelButton.
            GetCallableLocalizationString(),
            "ui_responses":
            dialogResponses
        }

        def dialogCallback(closedDialog: ui_dialog.UiDialog) -> None:
            try:
                if closedDialog.response == gameUserDataReportResponseID:
                    Reporting.PrepareReportFiles(gameUserDataReportFilePath)
                    _ShowReportCreatedDialog()
                elif closedDialog.response == desktopReportResponseID:
                    Reporting.PrepareReportFiles(desktopReportFilePath)
                    _ShowReportCreatedDialog()
            except:
                commands.CheatOutput(
                    _connection
                )("Failed to run the callback for the prepare report location dialog."
                  )

                Debug.Log(
                    "Failed to run the callback for the prepare report location dialog.",
                    This.Mod.Namespace,
                    Debug.LogLevels.Exception,
                    group=This.Mod.Namespace,
                    owner=__name__)

        Dialogs.ShowOkDialog(callback=dialogCallback,
                             queue=False,
                             **dialogArguments)
    except:
        commands.CheatOutput(_connection)(
            "Failed to show the prepare report location dialog.")
        Debug.Log("Failed to show the prepare report location dialog.",
                  This.Mod.Namespace,
                  Debug.LogLevels.Exception,
                  group=This.Mod.Namespace,
                  owner=__name__)