diff --git a/Source/Core/Data/DirectoryReader.cs b/Source/Core/Data/DirectoryReader.cs index 392ea594..aecaf126 100644 --- a/Source/Core/Data/DirectoryReader.cs +++ b/Source/Core/Data/DirectoryReader.cs @@ -80,12 +80,24 @@ namespace CodeImp.DoomBuilder.Data try { - //mxd. Find in directories ZDoom expects them to be - foreach(string loc in PatchLocations) + if (General.Map.Config.MixTexturesFlats) { - string path = Path.Combine(loc, Path.GetDirectoryName(pname)); + //mxd. Find in directories ZDoom expects them to be + string dir = Path.GetDirectoryName(pname); + string name = Path.GetFileName(pname); + foreach (string loc in PatchLocations) + { + string path = Path.Combine(loc, dir); + string filename = FindFirstFile(path, name, true); + if (!string.IsNullOrEmpty(filename) && FileExists(filename)) + return LoadFile(filename); + } + } + else + { + // Find in patches directory + string path = Path.Combine(PATCHES_DIR, Path.GetDirectoryName(pname)); string filename = FindFirstFile(path, Path.GetFileName(pname), true); - if(!string.IsNullOrEmpty(filename) && FileExists(filename)) return LoadFile(filename); } @@ -115,12 +127,25 @@ namespace CodeImp.DoomBuilder.Data try { - //mxd. Find in directories ZDoom expects them to be - foreach(string loc in TextureLocations) + if (General.Map.Config.MixTexturesFlats) { - string path = Path.Combine(loc, Path.GetDirectoryName(pname)); + //mxd. Find in directories ZDoom expects them to be + string dir = Path.GetDirectoryName(pname); + string name = Path.GetFileName(pname); + foreach (string loc in TextureLocations) + { + string path = Path.Combine(loc, dir); + string filename = FindFirstFile(path, name, true); + if(!string.IsNullOrEmpty(filename) && FileExists(filename)) + return LoadFile(filename); + } + } + else + { + // Find in textures directory + string path = Path.Combine(TEXTURES_DIR, Path.GetDirectoryName(pname)); string filename = FindFirstFile(path, Path.GetFileName(pname), true); - if(!string.IsNullOrEmpty(filename) && FileExists(filename)) + if(!string.IsNullOrEmpty(filename) && FileExists(filename)) return LoadFile(filename); } } diff --git a/Source/Core/Data/FlatImage.cs b/Source/Core/Data/FlatImage.cs index 5a6da909..3e6158af 100644 --- a/Source/Core/Data/FlatImage.cs +++ b/Source/Core/Data/FlatImage.cs @@ -45,29 +45,24 @@ namespace CodeImp.DoomBuilder.Data // This loads the image protected override void LocalLoadImage() { - Stream lumpdata; - MemoryStream mem; - IImageReader reader; - byte[] membytes; - // Leave when already loaded if(this.IsImageLoaded) return; lock(this) { // Get the lump data stream - lumpdata = General.Map.Data.GetFlatData(Name); + Stream lumpdata = General.Map.Data.GetFlatData(Name); if(lumpdata != null) { // Copy lump data to memory lumpdata.Seek(0, SeekOrigin.Begin); - membytes = new byte[(int)lumpdata.Length]; + byte[] membytes = new byte[(int)lumpdata.Length]; lumpdata.Read(membytes, 0, (int)lumpdata.Length); - mem = new MemoryStream(membytes); + MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); // Get a reader for the data - reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette); + IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette); if(reader is UnknownImageReader) { // Data is in an unknown format! diff --git a/Source/Core/Data/PK3Reader.cs b/Source/Core/Data/PK3Reader.cs index e63f3fab..be76781c 100644 --- a/Source/Core/Data/PK3Reader.cs +++ b/Source/Core/Data/PK3Reader.cs @@ -122,10 +122,20 @@ namespace CodeImp.DoomBuilder.Data if(data != null) return data; } - //mxd. Find in directories ZDoom expects them to be - foreach(string loc in PatchLocations) + if (General.Map.Config.MixTexturesFlats) { - string filename = FindFirstFile(loc, pname, true); + //mxd. Find in directories ZDoom expects them to be + foreach (string loc in PatchLocations) + { + string filename = FindFirstFile(loc, pname, true); + if ((filename != null) && FileExists(filename)) + return LoadFile(filename); + } + } + else + { + // Find in patches directory + string filename = FindFirstFile(PATCHES_DIR, pname, true); if((filename != null) && FileExists(filename)) return LoadFile(filename); } @@ -148,10 +158,20 @@ namespace CodeImp.DoomBuilder.Data if(data != null) return data; } - //mxd. Find in directories ZDoom expects them to be - foreach(string loc in TextureLocations) + if(General.Map.Config.MixTexturesFlats) { - string filename = FindFirstFile(loc, pname, true); + //mxd. Find in directories ZDoom expects them to be + foreach(string loc in TextureLocations) + { + string filename = FindFirstFile(loc, pname, true); + if(!string.IsNullOrEmpty(filename) && FileExists(filename)) + return LoadFile(filename); + } + } + else + { + // Find in textures directory + string filename = FindFirstFile(TEXTURES_DIR, pname, true); if(!string.IsNullOrEmpty(filename) && FileExists(filename)) return LoadFile(filename); } diff --git a/Source/Core/Data/PK3StructuredReader.cs b/Source/Core/Data/PK3StructuredReader.cs index 8295749f..1131dc95 100644 --- a/Source/Core/Data/PK3StructuredReader.cs +++ b/Source/Core/Data/PK3StructuredReader.cs @@ -54,8 +54,8 @@ namespace CodeImp.DoomBuilder.Data #region ================== Properties - protected readonly string[] PatchLocations = { PATCHES_DIR, TEXTURES_DIR, FLATS_DIR, SPRITES_DIR, GRAPHICS_DIR }; //mxd. Because ZDoom looks for patches and sprites in this order - protected readonly string[] TextureLocations = { TEXTURES_DIR, PATCHES_DIR, FLATS_DIR, SPRITES_DIR, GRAPHICS_DIR }; //mxd. Because ZDoom looks for textures in this order + protected readonly string[] PatchLocations = { TEXTURES_DIR, PATCHES_DIR, FLATS_DIR, SPRITES_DIR, GRAPHICS_DIR }; //mxd. Because ZDoom looks for patches and sprites in this order + protected readonly string[] TextureLocations = { TEXTURES_DIR, FLATS_DIR, SPRITES_DIR, PATCHES_DIR, GRAPHICS_DIR }; //mxd. Because ZDoom looks for textures in this order #endregion @@ -268,10 +268,21 @@ namespace CodeImp.DoomBuilder.Data // Error when suspended if (issuspended) throw new Exception("Data reader is suspended"); - // Find in directories ZDoom expects them to be - foreach (string loc in PatchLocations) + if (General.Map.Config.MixTexturesFlats) { - string path = Path.Combine(loc, Path.GetDirectoryName(pname)); + // Find in directories ZDoom expects them to be + foreach (string loc in PatchLocations) + { + string path = Path.Combine(loc, Path.GetDirectoryName(pname)); + string filename = FindFirstFile(path, Path.GetFileName(pname), true); + if (!string.IsNullOrEmpty(filename) && FileExists(filename)) + return filename; + } + } + else + { + // Find in patches directory + string path = Path.Combine(PATCHES_DIR, Path.GetDirectoryName(pname)); string filename = FindFirstFile(path, Path.GetFileName(pname), true); if (!string.IsNullOrEmpty(filename) && FileExists(filename)) return filename; diff --git a/Source/Core/Windows/TextureBrowserForm.cs b/Source/Core/Windows/TextureBrowserForm.cs index f3f6a308..72960181 100644 --- a/Source/Core/Windows/TextureBrowserForm.cs +++ b/Source/Core/Windows/TextureBrowserForm.cs @@ -79,7 +79,8 @@ namespace CodeImp.DoomBuilder.Windows foreach(IFilledTextureSet ts in General.Map.Data.TextureSets) { count = (browseFlats ? ts.Flats.Count : ts.Textures.Count); - if(count == 0 && !General.Map.Config.MixTexturesFlats) continue; + if((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0)) + continue; item = tvTextureSets.Nodes.Add(ts.Name + " [" + count + "]"); item.Name = ts.Name; @@ -91,7 +92,8 @@ namespace CodeImp.DoomBuilder.Windows foreach(ResourceTextureSet ts in General.Map.Data.ResourceTextureSets) { count = (browseFlats ? ts.Flats.Count : ts.Textures.Count); - if(count == 0 && !General.Map.Config.MixTexturesFlats) continue; + if((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0)) + continue; item = tvTextureSets.Nodes.Add(ts.Name + " [" + count + "]"); item.Name = ts.Name; @@ -99,7 +101,8 @@ namespace CodeImp.DoomBuilder.Windows item.ImageIndex = 2 + ts.Location.type; item.SelectedImageIndex = item.ImageIndex; - if (ts.Location.type != DataLocation.RESOURCE_WAD) { + if (ts.Location.type != DataLocation.RESOURCE_WAD) + { createNodes(item); item.Expand(); } @@ -146,8 +149,11 @@ namespace CodeImp.DoomBuilder.Windows selectedset = match; //mxd. Select found node or "All" node, if none were found - if (tvTextureSets.Nodes.Count > 0) - tvTextureSets.SelectedNode = (selectedset ?? tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1]); + if (tvTextureSets.Nodes.Count > 0) + { + if (selectedset == null) selectedset = tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1]; + tvTextureSets.SelectedNode = selectedset; + } tvTextureSets.EndUpdate();//mxd