/// <summary> /// Initializes a new instance of the <see cref="StationaryGrhData"/> class. /// </summary> /// <param name="autoGrhData">The <see cref="AutomaticAnimatedGrhData"/>.</param> /// <param name="assetName">Name of the asset.</param> internal StationaryGrhData(AutomaticAnimatedGrhData autoGrhData, TextureAssetName assetName) : base(autoGrhData.Categorization) { _cm = autoGrhData.ContentManager; _textureName = assetName; AutomaticSize = true; }
/// <summary> /// Creates the <see cref="StationaryGrhData"/> frames for this <see cref="AutomaticAnimatedGrhData"/>. /// </summary> /// <param name="directory">The directory containing the frames.</param> /// <returns>An array of the <see cref="StationaryGrhData"/> frames.</returns> StationaryGrhData[] CreateFrames(string directory) { // Find all the valid content files var allFiles = Directory.GetFiles(directory, "*" + ContentPaths.ContentFileSuffix, SearchOption.TopDirectoryOnly); // Filter out the files with invalid naming conventions, and sort them so we animate in the correct order var files = SortAndFilterFrameFiles(allFiles); // Build the individual frames var frames = new StationaryGrhData[files.Length]; for (var i = 0; i < frames.Length; i++) { var contentAssetName = ContentAssetName.FromAbsoluteFilePath(files[i], ContentPaths.Build.Grhs).Value; var textureAssetName = new TextureAssetName(contentAssetName); var frameGrhData = new StationaryGrhData(this, textureAssetName); frames[i] = frameGrhData; } if (frames.Length == 0) { throw new Exception("Animation has no frames"); } return(frames); }
/// <summary> /// Updates the HashInfo for all of the files in the specified root directory. /// </summary> void UpdateHashes() { var files = GetFilesToHash(_rootTextureDir); foreach (var file in files) { try { // Get the current info var contentAssetName = ContentAssetName.FromAbsoluteFilePath(file, _rootTextureDir).Value; var textureName = new TextureAssetName(contentAssetName).Value; HashInfo hashInfo = null; if (Contains(textureName)) { hashInfo = this[textureName]; } // Get the file size and last modified time int size; long lastMod; GetFileSizeAndLastModified(file, out size, out lastMod); // If we already have the hash info, and the size and last modified time have not changed, // we can skip updating the hash if (hashInfo != null && hashInfo.FileSize == size && hashInfo.LastModifiedTime == lastMod) { continue; } // Get the new hash and add the new file or update the existing values var hash = GetFileHash(file); if (hashInfo == null) { hashInfo = new HashInfo(hash, size, lastMod); this[textureName] = hashInfo; } else { hashInfo.FileSize = size; hashInfo.Hash = hash; hashInfo.LastModifiedTime = lastMod; } } catch (IOException) { } catch (UnauthorizedAccessException) { } } // Write the updates Save(); }
/// <summary> /// When overridden in the derived class, checks if the <see cref="AutoValidateTextBox"/> is in a valid /// state and contains valid text. /// </summary> /// <returns>True if valid; otherwise false.</returns> protected override bool GetIsValid(string text) { var assetName = new TextureAssetName(text); if (!assetName.ContentExists()) { return(false); } return(base.GetIsValid(text)); }
/// <summary> /// Initializes a new instance of the <see cref="StationaryGrhData"/> class. /// </summary> /// <param name="r">The <see cref="IValueReader"/>.</param> /// <param name="cm">The <see cref="IContentManager"/>.</param> /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param> /// <param name="cat">The <see cref="SpriteCategorization"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception> StationaryGrhData(IValueReader r, IContentManager cm, GrhIndex grhIndex, SpriteCategorization cat) : base(grhIndex, cat) { _cm = cm; var automaticSize = r.ReadBool(_automaticSizeValueKey); var textureReader = r.ReadNode(_textureNodeName); var textureName = textureReader.ReadTextureAssetName(_textureNameValueKey); var textureSource = textureReader.ReadRectangle(_textureSourceValueKey); _textureName = textureName; SetSourceRect(textureSource); _automaticSize = automaticSize; }
/// <summary> /// Initializes a new instance of the <see cref="StationaryGrhData"/> class. /// </summary> /// <param name="cm">The <see cref="IContentManager"/>.</param> /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param> /// <param name="cat">The <see cref="SpriteCategorization"/>.</param> /// <param name="textureName">Name of the texture.</param> /// <param name="textureSource">The area of the texture to use, or null for the whole texture.</param> /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception> public StationaryGrhData(IContentManager cm, GrhIndex grhIndex, SpriteCategorization cat, TextureAssetName textureName, Rectangle?textureSource) : base(grhIndex, cat) { _cm = cm; _textureName = textureName; if (textureSource == null) { AutomaticSize = true; } else { SetSourceRect(textureSource.Value); } }
/// <summary> /// Changes the texture for a stationary <see cref="GrhData"/>. /// </summary> /// <param name="newTexture">Name of the new texture to use.</param> /// <param name="source">A <see cref="Rectangle"/> describing the source area of the texture to /// use for this <see cref="GrhData"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="newTexture" /> is <c>null</c>.</exception> public void ChangeTexture(TextureAssetName newTexture, Rectangle source) { if (newTexture == null) { throw new ArgumentNullException("newTexture"); } // Check that the values have changed if (source == SourceRect && TextureName == newTexture) { return; } SetSourceRect(source); // Check that it is actually a different texture TextureAssetName oldTextureName = null; if (TextureName != newTexture) { oldTextureName = _textureName; } // Apply the new texture _texture = null; _isUsingAtlas = false; _textureName = newTexture; ValidateTexture(); if (oldTextureName != null) { if (TextureChanged != null) { TextureChanged.Raise(this, EventArgsHelper.Create <ContentAssetName>(oldTextureName)); } } }
/// <summary> /// Changes the texture for a stationary <see cref="GrhData"/>. /// </summary> /// <param name="newTexture">Name of the new texture to use.</param> public void ChangeTexture(TextureAssetName newTexture) { ChangeTexture(newTexture, OriginalSourceRect); }