Updated: any graphic can be used as a skybox texture.

Fixed a crash when trying to get map title after closing Map options window.
Updated game configurations (Sector_SetPortal).
This commit is contained in:
MaxED 2016-01-13 09:34:32 +00:00
parent a4699e156d
commit 75b107ef2f
8 changed files with 134 additions and 104 deletions

View file

@ -3231,13 +3231,22 @@ zdoom
0 = "Link to portal with same tag"; 0 = "Link to portal with same tag";
1 = "Copy portal from second tag"; 1 = "Copy portal from second tag";
2 = "Eternity-style skybox portal"; 2 = "Eternity-style skybox portal";
3 = "Plane portal";
4 = "Horizon portal";
5 = "Copy portal to line";
} }
} }
arg2 arg2
{ {
title = "Floor / Ceiling"; title = "Plane";
type = 11; type = 11;
enum = "floorceilingboth"; enum
{
0 = "Floor";
1 = "Ceiling";
2 = "Both";
3 = "Any (Copy portal type only)";
}
} }
arg3 arg3
{ {

View file

@ -599,13 +599,6 @@ enums
1 = "Floor"; 1 = "Floor";
} }
floorceilingboth
{
0 = "Floor";
1 = "Ceiling";
2 = "Both";
}
sector_flags sector_flags
{ {
1 = "Silent"; 1 = "Silent";

View file

@ -999,7 +999,7 @@ namespace CodeImp.DoomBuilder.Data
// Go for all opened containers // Go for all opened containers
for(int i = containers.Count - 1; i >= 0; i--) for(int i = containers.Count - 1; i >= 0; i--)
{ {
// This contain provides this patch? // This container provides this patch?
Stream patch = containers[i].GetTextureData(pname, longname); Stream patch = containers[i].GetTextureData(pname, longname);
if(patch != null) return patch; if(patch != null) return patch;
} }
@ -1040,9 +1040,67 @@ namespace CodeImp.DoomBuilder.Data
return unknownimage; //mxd return unknownimage; //mxd
} }
//mxd. This tries to find and load any image with given name
internal Bitmap GetTextureBitmap(string name)
{
// Check the textures first...
ImageData img = GetTextureImage(name);
if(img is UnknownImage && !General.Map.Config.MixTexturesFlats)
img = GetFlatImage(name);
if(!(img is UnknownImage))
{
if(!img.IsImageLoaded) img.LoadImage();
if(!img.LoadFailed)
{
return new Bitmap(img.GetBitmap());
}
}
// Try to find any image...
for(int i = containers.Count - 1; i >= 0; i--)
{
// This container has a lump with given name?
if(containers[i] is PK3StructuredReader)
{
name = ((PK3StructuredReader)containers[i]).FindFirstFile(name, true);
}
else if(!(containers[i] is WADReader))
{
throw new NotImplementedException("Unsupported container type!");
}
if(!containers[i].FileExists(name)) continue;
MemoryStream mem = containers[i].LoadFile(name);
if(mem == null) continue;
// Is it an image?
IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
if(!(reader is UnknownImageReader))
{
// Load the image
mem.Seek(0, SeekOrigin.Begin);
Bitmap result;
try { result = reader.ReadAsBitmap(mem); }
catch(InvalidDataException)
{
// Data cannot be read!
result = null;
}
// Found it?
if(result != null) return result;
}
}
// No such image found
return null;
}
//mxd //mxd
public string GetFullTextureName(string name) public string GetFullTextureName(string name)
{ {
if(string.IsNullOrEmpty(name)) return name;
if(Path.GetFileNameWithoutExtension(name) == name && name.Length > CLASIC_IMAGE_NAME_LENGTH) if(Path.GetFileNameWithoutExtension(name) == name && name.Length > CLASIC_IMAGE_NAME_LENGTH)
name = name.Substring(0, CLASIC_IMAGE_NAME_LENGTH); name = name.Substring(0, CLASIC_IMAGE_NAME_LENGTH);
long hash = MurmurHash2.Hash(name.Trim().ToUpperInvariant()); long hash = MurmurHash2.Hash(name.Trim().ToUpperInvariant());
@ -2329,14 +2387,10 @@ namespace CodeImp.DoomBuilder.Data
else else
{ {
// Create classic texture // Create classic texture
ImageData tex = GetTextureImage(skytex); Bitmap img = GetTextureBitmap(skytex);
if(!(tex is UnknownImage)) if(img != null)
{ {
if(!tex.IsImageLoaded) tex.LoadImage(); skybox = MakeClassicSkyBox(img, true);
if(!tex.LoadFailed)
{
skybox = MakeClassicSkyBox(new Bitmap(tex.GetBitmap()), true);
}
} }
} }
} }
@ -2490,18 +2544,12 @@ namespace CodeImp.DoomBuilder.Data
int targetsize = 0; int targetsize = 0;
for(int i = 0; i < info.Textures.Count; i++) for(int i = 0; i < info.Textures.Count; i++)
{ {
ImageData tex = GetTextureImage(info.Textures[i]); sides[i] = GetTextureBitmap(info.Textures[i]);
if(!(tex is UnknownImage)) if(sides[i] != null)
{ {
if(!tex.IsImageLoaded) tex.LoadImage(); targetsize = Math.Max(targetsize, Math.Max(sides[i].Width, sides[i].Height));
if(!tex.LoadFailed)
{
sides[i] = new Bitmap(tex.GetBitmap());
targetsize = Math.Max(targetsize, Math.Max(sides[i].Width, sides[i].Height));
}
} }
else
if(sides[i] == null)
{ {
General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: unable to find \"" + info.Textures[i] + "\" texture"); General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: unable to find \"" + info.Textures[i] + "\" texture");
return null; return null;
@ -2536,45 +2584,40 @@ namespace CodeImp.DoomBuilder.Data
int targetsize = 0; int targetsize = 0;
// Create NWSE images from the side texture // Create NWSE images from the side texture
ImageData side = GetTextureImage(info.Textures[0]); Bitmap sideimg = GetTextureBitmap(info.Textures[0]);
if(!(side is UnknownImage)) if(sideimg != null)
{ {
if(!side.IsImageLoaded) side.LoadImage(); // This should be 4x1 format image. If it's not, we'll need to resize it
if(!side.LoadFailed) targetsize = Math.Max(sideimg.Width / 4, sideimg.Height);
if(targetsize == 0)
{ {
// This should be 4x1 format image. If it's not, resize it General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: invalid texture size");
Bitmap sideimg = new Bitmap(side.GetBitmap()); return null;
targetsize = Math.Max(sideimg.Width / 4, sideimg.Height); }
if(targetsize == 0) // Make it Po2
targetsize = General.NextPowerOf2(targetsize);
// Resize if needed
if(sideimg.Width != targetsize * 4 || sideimg.Height != targetsize)
{
sideimg = ResizeImage(sideimg, targetsize * 4, targetsize);
}
// Chop into tiny pieces
for(int i = 0; i < 4; i++)
{
// Create square image
Bitmap img = new Bitmap(targetsize, targetsize);
using(Graphics g = Graphics.FromImage(img))
{ {
General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: invalid texture size"); // Copy area from the side image
return null; g.DrawImage(sideimg, 0, 0, new Rectangle(targetsize * i, 0, targetsize, targetsize), GraphicsUnit.Pixel);
} }
// Make it Po2 // Add to collection
targetsize = General.NextPowerOf2(targetsize); sides[i] = img;
// Resize if needed
if(sideimg.Width != targetsize * 4 || sideimg.Height != targetsize)
{
sideimg = ResizeImage(sideimg, targetsize * 4, targetsize);
}
// Chop into tiny pieces
for(int i = 0; i < 4; i++)
{
// Create square image
Bitmap img = new Bitmap(targetsize, targetsize);
using(Graphics g = Graphics.FromImage(img))
{
// Copy area from the side image
g.DrawImage(sideimg, 0, 0, new Rectangle(targetsize * i, 0, targetsize, targetsize), GraphicsUnit.Pixel);
}
// Add to collection
sides[i] = img;
}
} }
} }
@ -2586,52 +2629,34 @@ namespace CodeImp.DoomBuilder.Data
} }
// Create top // Create top
ImageData top = GetTextureImage(info.Textures[1]); Bitmap topimg = GetTextureBitmap(info.Textures[1]);
if(!(top is UnknownImage)) if(topimg != null)
{ {
if(!top.IsImageLoaded) top.LoadImage(); // Resize if needed
if(!top.LoadFailed) if(topimg.Width != targetsize || topimg.Height != targetsize)
{ topimg = ResizeImage(topimg, targetsize, targetsize);
// Copy bitmap
Bitmap topimg = new Bitmap(top.GetBitmap());
// Resize if needed
if(topimg.Width != targetsize || topimg.Height != targetsize)
topimg = ResizeImage(topimg, targetsize, targetsize);
// Add to collection // Add to collection
sides[4] = topimg; sides[4] = topimg;
}
} }
else
// Sanity check...
if(sides[4] == null)
{ {
General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: unable to find \"" + info.Textures[1] + "\" texture"); General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: unable to find \"" + info.Textures[1] + "\" texture");
return null; return null;
} }
// Create bottom // Create bottom
ImageData bottom = GetTextureImage(info.Textures[2]); Bitmap bottomimg = GetTextureBitmap(info.Textures[2]);
if(!(bottom is UnknownImage)) if(bottomimg != null)
{ {
if(!bottom.IsImageLoaded) bottom.LoadImage(); // Resize if needed
if(!bottom.LoadFailed) if(bottomimg.Width != targetsize || bottomimg.Height != targetsize)
{ bottomimg = ResizeImage(bottomimg, targetsize, targetsize);
// Copy bitmap
Bitmap bottomimg = new Bitmap(bottom.GetBitmap());
// Resize if needed // Add to collection
if(bottomimg.Width != targetsize || bottomimg.Height != targetsize) sides[5] = bottomimg;
bottomimg = ResizeImage(bottomimg, targetsize, targetsize);
// Add to collection
sides[5] = bottomimg;
}
} }
else
// Sanity check...
if(sides[5] == null)
{ {
General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: unable to find \"" + info.Textures[2] + "\" texture"); General.ErrorLogger.Add(ErrorType.Error, "Unable to create \"" + info.Name + "\" skybox: unable to find \"" + info.Textures[2] + "\" texture");
return null; return null;

View file

@ -28,7 +28,7 @@ namespace CodeImp.DoomBuilder.Data
{ {
#region ================== Variables #region ================== Variables
private DirectoryFilesList files; private readonly DirectoryFilesList files;
#endregion #endregion
@ -359,7 +359,7 @@ namespace CodeImp.DoomBuilder.Data
} }
// This finds the first file that has the specific name, regardless of file extension // This finds the first file that has the specific name, regardless of file extension
protected override string FindFirstFile(string beginswith, bool subfolders) internal override string FindFirstFile(string beginswith, bool subfolders)
{ {
return files.GetFirstFile(beginswith, subfolders); return files.GetFirstFile(beginswith, subfolders);
} }

View file

@ -387,7 +387,7 @@ namespace CodeImp.DoomBuilder.Data
} }
// This finds the first file that has the specific name, regardless of file extension // This finds the first file that has the specific name, regardless of file extension
protected override string FindFirstFile(string beginswith, bool subfolders) internal override string FindFirstFile(string beginswith, bool subfolders)
{ {
return files.GetFirstFile(beginswith, subfolders); return files.GetFirstFile(beginswith, subfolders);
} }

View file

@ -727,7 +727,7 @@ namespace CodeImp.DoomBuilder.Data
protected abstract string[] GetFilesWithExt(string path, string extension, bool subfolders); protected abstract string[] GetFilesWithExt(string path, string extension, bool subfolders);
// This must find the first file that has the specific name, regardless of file extension // This must find the first file that has the specific name, regardless of file extension
protected abstract string FindFirstFile(string beginswith, bool subfolders); internal abstract string FindFirstFile(string beginswith, bool subfolders);
// This must find the first file that has the specific name, regardless of file extension // This must find the first file that has the specific name, regardless of file extension
protected abstract string FindFirstFile(string path, string beginswith, bool subfolders); protected abstract string FindFirstFile(string path, string beginswith, bool subfolders);

View file

@ -517,9 +517,9 @@ namespace CodeImp.DoomBuilder.Editing
{ {
PastePrefab(stream, options); PastePrefab(stream, options);
lastprefabfile = openfile.FileName; lastprefabfile = openfile.FileName;
stream.Dispose();
} }
General.MainWindow.UpdateInterface(); General.MainWindow.UpdateInterface();
stream.Dispose();
} }
Cursor.Current = oldcursor; Cursor.Current = oldcursor;
@ -573,8 +573,11 @@ namespace CodeImp.DoomBuilder.Editing
General.ShowErrorMessage("Error while reading prefab from file! See log file for error details.", MessageBoxButtons.OK); General.ShowErrorMessage("Error while reading prefab from file! See log file for error details.", MessageBoxButtons.OK);
} }
if(stream != null) PastePrefab(stream, options); if(stream != null)
stream.Dispose(); {
PastePrefab(stream, options);
stream.Dispose();
}
General.MainWindow.UpdateInterface(); General.MainWindow.UpdateInterface();
Cursor.Current = oldcursor; Cursor.Current = oldcursor;
} }

View file

@ -2210,15 +2210,15 @@ namespace CodeImp.DoomBuilder
} }
map.UpdateCustomLinedefColors(); map.UpdateCustomLinedefColors();
// Reload resources
ReloadResources();
// Update interface // Update interface
General.MainWindow.SetupInterface(); General.MainWindow.SetupInterface();
General.MainWindow.UpdateThingsFilters(); General.MainWindow.UpdateThingsFilters();
General.MainWindow.UpdateLinedefColorPresets(); //mxd General.MainWindow.UpdateLinedefColorPresets(); //mxd
General.MainWindow.UpdateInterface(); General.MainWindow.UpdateInterface();
// Reload resources
ReloadResources();
//mxd. Translate texture names //mxd. Translate texture names
bool nameschanged = map.TranslateTextureNames(config.UseLongTextureNames, false); bool nameschanged = map.TranslateTextureNames(config.UseLongTextureNames, false);
grid.TranslateBackgroundName(config.UseLongTextureNames); grid.TranslateBackgroundName(config.UseLongTextureNames);