Exemplo n.º 1
0
 def GenerateRow(self) -> ui_dialog_picker.ObjectPickerRow:
     row = ui_dialog_picker.ObjectPickerRow(
         option_id=self.OptionID,
         name=self.Text,
         row_description=self.Description,
         icon=self.Icon)
     return row
Exemplo n.º 2
0
def ShowUpdatesList(
        updatedMods: typing.List[DistributionShared.UpdateInformation]
) -> None:
    dialogArguments = {
        "title": UpdatesListTitle.GetCallableLocalizationString(),
        "text": UpdatesListText.GetCallableLocalizationString()
    }

    options = {}  # type: typing.Dict[int, str]

    dialogRows = list()  # type: typing.List

    for updatedModIndex in range(len(updatedMods)):  # type: int
        updatedMod = updatedMods[
            updatedModIndex]  # type: DistributionShared.UpdateInformation

        optionID = 5000 + updatedModIndex  # type: int

        dialogRowArguments = {
            "option_id":
            optionID,
            "name":
            UpdatesListRowText.GetLocalizationString(updatedMod.ModName,
                                                     updatedMod.ModAuthor),
            "icon":
            resources.ResourceKeyWrapper(UIResources.PickerDownloadIconKey)
        }

        if not updatedMod.IsPreview:
            descriptionTypeText = UpdatesListRowDescriptionReleaseType.GetLocalizationString(
            )  # type: localization.LocalizedString
        else:
            descriptionTypeText = UpdatesListRowDescriptionPreviewType.GetLocalizationString(
            )  # type: localization.LocalizedString

        dialogRowArguments[
            "row_description"] = UpdatesListRowDescription.GetLocalizationString(
                descriptionTypeText, updatedMod.CurrentVersion,
                updatedMod.NewVersion, updatedMod.DownloadURL)
        dialogRows.append(
            ui_dialog_picker.ObjectPickerRow(**dialogRowArguments))

        options[optionID] = updatedMod.DownloadURL

    def OpenBrowserDialogCallback() -> None:
        ShowUpdatesList(updatedMods)

    def DialogCallback(
            dialogReference: ui_dialog_picker.UiObjectPicker) -> None:
        if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_CANCEL:
            return

        resultRows = dialogReference.picked_results  # type: typing.Tuple[int]

        if len(resultRows) == 0:
            return

        selectedModURL = options.get(
            resultRows[0])  # type: typing.Optional[str]

        if selectedModURL is None:
            return

        Generic.ShowOpenBrowserDialog(selectedModURL,
                                      returnCallback=OpenBrowserDialogCallback)

    Dialogs.ShowObjectPickerDialog(callback=DialogCallback,
                                   pickerRows=dialogRows,
                                   **dialogArguments)
Exemplo n.º 3
0
def ShowSelectSaveDialog () -> None:
	gameSaveSlotID = str(services.get_persistence_service().get_save_slot_proto_buff().slot_id)  # type: str
	gameSaveGUID = str(services.get_persistence_service().get_save_slot_proto_guid())  # type: str

	dialogArguments = {
		"owner": services.get_active_sim().sim_info,
		"title": SelectSaveDialogTitle,
		"text": SelectSaveDialogText.GetCallableLocalizationString(*(gameSaveSlotID, gameSaveGUID))
	}

	dialogRows = list()

	options = { }  # type: typing.Dict[int, str]

	loadedSaveDirectoryPath = Save.GetLoadedDirectoryPath()  # type: typing.Optional[str]
	loadedSaveDirectoryPathObject = pathlib.Path(Save.GetLoadedDirectoryPath()) if loadedSaveDirectoryPath is not None else None  # type: typing.Optional[pathlib.Path]

	for saveDirectoryName in os.listdir(Paths.SavesPath):  # type: str
		saveDirectoryPath = os.path.join(Paths.SavesPath, saveDirectoryName)  # type: str

		if os.path.isdir(saveDirectoryPath):
			saveDirectoryPathObject = pathlib.Path(saveDirectoryPath)  # type: pathlib.Path

			currentOptionID = 50000 + len(options)
			options[currentOptionID] = saveDirectoryPath

			saveDirectoryMetaData = Save.GetSaveMetaData(saveDirectoryPath)  # type: typing.Optional[Save.ModSaveMetaData]

			rowDescriptionTokens = (SelectSaveDialogDescriptionMatchUnknown.GetLocalizationString(),)

			if saveDirectoryMetaData is not None:
				saveDirectoryMatchType = saveDirectoryMetaData.MatchesGameSave()  # type: Save.ModSaveMatchTypes

				if saveDirectoryMatchType in Save.ModSaveMatchTypes.Match:
					rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMatches.GetLocalizationString(),)
				elif saveDirectoryMatchType in Save.ModSaveMatchTypes.MismatchedGUID:
					rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMismatchGUID.GetLocalizationString(),)
				elif saveDirectoryMatchType in Save.ModSaveMatchTypes.MismatchedGameTick:
					rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMismatchGameTick.GetLocalizationString(),)

			if loadedSaveDirectoryPathObject is not None:
				if loadedSaveDirectoryPathObject == saveDirectoryPathObject:
					rowDescription = SelectSaveDialogDescriptionCurrentlyLoaded.GetLocalizationString(*rowDescriptionTokens)
				else:
					rowDescription = SelectSaveDialogDescriptionNormal.GetLocalizationString(*rowDescriptionTokens)
			else:
				rowDescription = SelectSaveDialogDescriptionNormal.GetLocalizationString(*rowDescriptionTokens)

			if saveDirectoryMetaData is None:
				rowNameTokens = (saveDirectoryName,)
			else:
				rowNameTokens = (saveDirectoryName + " (" + saveDirectoryMetaData.Name + ")",)

			dialogRows.append(ui_dialog_picker.ObjectPickerRow(
				option_id = currentOptionID,
				name = Language.CreateLocalizationString(*rowNameTokens),
				row_description = rowDescription))

	def DialogCallback (dialogReference: ui_dialog_picker.UiObjectPicker) -> None:
		try:
			if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_CANCEL:
				return

			resultRows = dialogReference.picked_results  # type: typing.Tuple[int]

			if len(resultRows) == 0:
				return

			selectedSaveDirectory = options.get(resultRows[0])  # type: typing.Optional[str]

			if selectedSaveDirectory is None:
				return

			Save.Load(services.get_persistence_service().get_save_slot_proto_buff().slot_id, selectedSaveDirectory, changingSave = True)
		except Exception as e:
			Debug.Log("Failed to run the callback for the select save dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, exception = e)

	Dialogs.ShowObjectPickerDialog(DialogCallback, dialogRows, **dialogArguments)