This class extends the information and functionality if an Image.
Ideally this class would extend Image, but all of Image's constructors are internal, making extension pointless.
		/// <summary>
		/// Displays a selection form to the user.
		/// </summary>
		/// <param name="p_sopOptions">The options from which to select.</param>
		/// <param name="p_strTitle">The title of the selection form.</param>
		/// <param name="p_booSelectMany">Whether more than one item can be selected.</param>
		/// <returns>The indices of the selected items.</returns>
		public int[] Select(SelectOption[] p_sopOptions, string p_strTitle, bool p_booSelectMany)
		{
			bool booHasPreviews = false;
			bool booHasDescriptions = false;
			foreach (SelectOption so in p_sopOptions)
			{
				if (so.Preview != null)
					booHasPreviews = true;
				if (so.Desc != null)
					booHasDescriptions = true;
			}
			string[] strItems = new string[p_sopOptions.Length];
			Image[] imgPreviews = booHasPreviews ? new Image[p_sopOptions.Length] : null;
			string[] strDescriptions = booHasDescriptions ? new string[p_sopOptions.Length] : null;
			for (int i = 0; i < p_sopOptions.Length; i++)
			{
				strItems[i] = p_sopOptions[i].Item;
				if (booHasPreviews)
					imgPreviews[i] = new ExtendedImage(Mod.GetFile(p_sopOptions[i].Preview));
				if (booHasDescriptions)
					strDescriptions[i] = p_sopOptions[i].Desc;
			}
			return Select(strItems, imgPreviews, strDescriptions, p_strTitle, p_booSelectMany);
		}
Esempio n. 2
0
		/// <summary>
		/// Deserializes an <see cref="IModInfo"/> from the given XML fragment into the
		/// given <see cref="IModInfo"/>.
		/// </summary>
		/// <param name="p_xndInfo">The XML fragment from which to deserialize the <see cref="IModInfo"/>.</param>
		/// <param name="p_booFillOnlyEmptyValues">Whether to only overwrite <c>null</c> or empty values.</param>
		protected void LoadInfo(XmlNode p_xndInfo, bool p_booFillOnlyEmptyValues)
		{
			XmlNode xndModName = p_xndInfo.SelectSingleNode("ModName");
			if ((xndModName != null) && (!p_booFillOnlyEmptyValues || String.IsNullOrEmpty(ModName)))
				ModName = xndModName.InnerText;

			XmlNode xndHumanReadableVersion = p_xndInfo.SelectSingleNode("HumanReadableVersion");
			if ((xndHumanReadableVersion != null) && (!p_booFillOnlyEmptyValues || String.IsNullOrEmpty(HumanReadableVersion)))
				HumanReadableVersion = xndHumanReadableVersion.InnerText;

			XmlNode xndMachineVersion = p_xndInfo.SelectSingleNode("MachineVersion");
			if ((xndMachineVersion != null) && (!p_booFillOnlyEmptyValues || (MachineVersion == null)))
				MachineVersion = new Version(xndMachineVersion.InnerText);

			XmlNode xndAuthor = p_xndInfo.SelectSingleNode("Author");
			if ((xndAuthor != null) && (!p_booFillOnlyEmptyValues || String.IsNullOrEmpty(Author)))
				Author = xndAuthor.InnerText;

			XmlNode xndDescription = p_xndInfo.SelectSingleNode("Description");
			if ((xndDescription != null) && (!p_booFillOnlyEmptyValues || String.IsNullOrEmpty(Description)))
				Description = xndDescription.InnerText;

			XmlNode xndWebsite = p_xndInfo.SelectSingleNode("Website");
			if ((xndWebsite != null) && (!p_booFillOnlyEmptyValues || (Website == null)))
				Website = new Uri(xndWebsite.InnerText);

			XmlNode xndScreenshot = p_xndInfo.SelectSingleNode("Screenshot");
			if ((xndScreenshot != null) && (!p_booFillOnlyEmptyValues || (Screenshot == null)))
				Screenshot = new ExtendedImage(Convert.FromBase64String(xndScreenshot.InnerText));
		}
Esempio n. 3
0
		/// <summary>
		/// Sets all of the properties of the object.
		/// </summary>
		/// <param name="p_booOverwriteAllValues">Whether to overwrite the current info values,
		/// or just the empty ones.</param>
		/// <param name="p_strId">The id of the mod.</param>
		/// <param name="p_strModName">The name of the mod.</param>
		/// <param name="p_strHumanReadableVersion">The human readable form of the mod's version.</param>
		/// <param name="p_strLastKnownVersion">The last known mod version.</param>
		/// <param name="p_booIsEndorsed">The Endorsement state of the mod.</param>
		/// <param name="p_verMachineVersion">The version of the mod.</param>
		/// <param name="p_strAuthor">The author of the mod.</param>
		/// <param name="p_strCategoryId">The category of the mod.</param>
		/// <param name="p_strCustomCategoryId">The custom category of the mod.</param>
		/// <param name="p_strDescription">The description of the mod.</param>
		/// <param name="p_strInstallDate">The install date of the mod.</param>
		/// <param name="p_uriWebsite">The website of the mod.</param>
		/// <param name="p_eimScreenshot">The mod's screenshot.</param>
		protected void SetAllInfo(bool p_booOverwriteAllValues, string p_strId, string p_strModName, string p_strHumanReadableVersion, string p_strLastKnownVersion, bool? p_booIsEndorsed, Version p_verMachineVersion, string p_strAuthor, Int32 p_intCategoryId, Int32 p_intCustomCategoryId, string p_strDescription, string p_strInstallDate, Uri p_uriWebsite, ExtendedImage p_eimScreenshot)
		{
			if (p_booOverwriteAllValues || String.IsNullOrEmpty(Id))
				Id = p_strId;
			if (p_booOverwriteAllValues || String.IsNullOrEmpty(ModName))
				ModName = p_strModName;
			if (p_booOverwriteAllValues || String.IsNullOrEmpty(HumanReadableVersion))
				HumanReadableVersion = p_strHumanReadableVersion;
			if (p_booOverwriteAllValues || String.IsNullOrEmpty(LastKnownVersion))
				LastKnownVersion = p_strLastKnownVersion;
			if (p_booOverwriteAllValues || (IsEndorsed != p_booIsEndorsed))
				IsEndorsed = p_booIsEndorsed;
			if (p_booOverwriteAllValues || (MachineVersion == null))
				MachineVersion = p_verMachineVersion;
			if (p_booOverwriteAllValues || String.IsNullOrEmpty(Author))
				Author = p_strAuthor;
			if (p_booOverwriteAllValues || (CategoryId != p_intCategoryId))
				CategoryId = p_intCategoryId;
			if (p_booOverwriteAllValues || (CustomCategoryId != p_intCustomCategoryId))
				CustomCategoryId = p_intCustomCategoryId;
			if (p_booOverwriteAllValues || String.IsNullOrEmpty(Description))
				Description = p_strDescription;
			if (p_booOverwriteAllValues || String.IsNullOrEmpty(InstallDate))
				InstallDate = p_strInstallDate;
			if (p_booOverwriteAllValues || (Website == null))
				Website = p_uriWebsite;
			if (p_booOverwriteAllValues || (Screenshot == null))
				Screenshot = p_eimScreenshot;
		}
Esempio n. 4
0
		/// <summary>
		/// A simple constructor that initializes the object with the given values.
		/// </summary>
		/// <param name="p_strId">The id of the mod.</param>
		/// <param name="p_strModName">The name of the mod.</param>
		/// <param name="p_strHumanReadableVersion">The human readable form of the mod's version.</param>
		/// <param name="p_strLastKnownVersion">The last known mod version.</param>
		/// <param name="p_booIsEndorsed">The Endorsement state of the mod.</param>
		/// <param name="p_verMachineVersion">The version of the mod.</param>
		/// <param name="p_strAuthor">The author of the mod.</param>
		/// <param name="p_strCategoryId">The category of the mod.</param>
		/// <param name="p_strCustomCategoryId">The custom category of the mod.</param>
		/// <param name="p_strDescription">The description of the mod.</param>
		/// <param name="p_strInstallDate">The install date of the mod.</param>
		/// <param name="p_uriWebsite">The website of the mod.</param>
		/// <param name="p_eimScreenshot">The mod's screenshot.</param>
		public ModInfo(string p_strId, string p_strModName, string p_strHumanReadableVersion, string p_strLastKnownVersion, bool? p_booIsEndorsed, Version p_verMachineVersion, string p_strAuthor, Int32 p_intCategoryId, Int32 p_intCustomCategoryId, string p_strDescription, string p_strInstallDate, Uri p_uriWebsite, ExtendedImage p_eimScreenshot)
		{
			SetAllInfo(true, p_strId, p_strModName, p_strHumanReadableVersion, p_strLastKnownVersion, p_booIsEndorsed, p_verMachineVersion, p_strAuthor, p_intCategoryId, p_intCustomCategoryId, p_strDescription, p_strInstallDate, p_uriWebsite, p_eimScreenshot);
		}
		/// <summary>
		/// Gets the specified image from the mod against which the script is running.
		/// </summary>
		/// <param name="p_strPath">The path to the image in the mod to retrieve.</param>
		/// <returns>The specified image from the mod against which the script is running.</returns>
		public Image GetImage(string p_strPath)
		{
			if (String.IsNullOrEmpty(p_strPath))
				return null;
			if (!m_dicImageCache.ContainsKey(p_strPath))
			{
				try
				{
					m_dicImageCache[p_strPath] = new ExtendedImage(Mod.GetFile(p_strPath));
				}
				catch (FileNotFoundException)
				{
					return Properties.Resources.notFoundJPG;
				}
			}
			return m_dicImageCache[p_strPath];
		}
		/// <summary>
		/// Displays a selection form to the user.
		/// </summary>
		/// <remarks>
		/// The items, previews, and descriptions are repectively ordered. In other words,
		/// the i-th item in <paramref name="p_strItems"/> uses the i-th preview in
		/// <paramref name="p_strPreviewPaths"/> and the i-th description in <paramref name="p_strDescriptions"/>.
		/// 
		/// Similarly, the idices return as results correspond to the indices of the items in
		/// <paramref name="p_strItems"/>.
		/// </remarks>
		/// <param name="p_strItems">The items from which to select.</param>
		/// <param name="p_strPreviewPaths">The preview image file names for the items.</param>
		/// <param name="p_strDescriptions">The descriptions of the items.</param>
		/// <param name="p_strTitle">The title of the selection form.</param>
		/// <param name="p_booSelectMany">Whether more than one item can be selected.</param>
		/// <returns>The indices of the selected items.</returns>
		public int[] Select(string[] p_strItems, string[] p_strPreviewPaths, string[] p_strDescriptions, string p_strTitle, bool p_booSelectMany)
		{
			Image[] imgPreviews = null;
			if (p_strPreviewPaths != null)
			{
				imgPreviews = new Image[p_strPreviewPaths.Length];
				for (Int32 i = 0; i < p_strPreviewPaths.Length; i++)
					if (!String.IsNullOrEmpty(p_strPreviewPaths[i]))
						imgPreviews[i] = new ExtendedImage(Mod.GetFile(p_strPreviewPaths[i]));
			}
			return Select(p_strItems, imgPreviews, p_strDescriptions, p_strTitle, p_booSelectMany);
		}
		/// <summary>
		/// Displays the given image.
		/// </summary>
		/// <param name="p_strImagePath">The path to the image in the mod to display.</param>
		/// <param name="p_strTitle">The title to display in the image viewer.</param>
		public void DisplayImage(string p_strImagePath, string p_strTitle)
		{
			Image imgImage = new ExtendedImage(Mod.GetFile(p_strImagePath));
			((ModScriptUIUtil)UIManager).ShowImage(imgImage, p_strTitle);

		}