diff --git a/Build/Configurations/Boom.cfg b/Build/Configurations/Boom.cfg index c6ab764f..d89fd375 100644 --- a/Build/Configurations/Boom.cfg +++ b/Build/Configurations/Boom.cfg @@ -154,7 +154,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -166,6 +166,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Doom.cfg b/Build/Configurations/Doom.cfg index 6fc6807d..05bf94e4 100644 --- a/Build/Configurations/Doom.cfg +++ b/Build/Configurations/Doom.cfg @@ -149,6 +149,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -160,6 +161,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Doom2.cfg b/Build/Configurations/Doom2.cfg index 931ffac9..63bb2b00 100644 --- a/Build/Configurations/Doom2.cfg +++ b/Build/Configurations/Doom2.cfg @@ -149,7 +149,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -161,6 +161,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Edge.cfg b/Build/Configurations/Edge.cfg index 55df0584..efa0c5c6 100644 --- a/Build/Configurations/Edge.cfg +++ b/Build/Configurations/Edge.cfg @@ -152,7 +152,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -164,6 +164,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Eternity.cfg b/Build/Configurations/Eternity.cfg index 7e52d4f8..08a2d321 100644 --- a/Build/Configurations/Eternity.cfg +++ b/Build/Configurations/Eternity.cfg @@ -149,7 +149,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -161,6 +161,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Heretic.cfg b/Build/Configurations/Heretic.cfg index 683c3617..69ff58b6 100644 --- a/Build/Configurations/Heretic.cfg +++ b/Build/Configurations/Heretic.cfg @@ -150,7 +150,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -162,6 +162,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Hexen.cfg b/Build/Configurations/Hexen.cfg index d480d07e..483d3aaf 100644 --- a/Build/Configurations/Hexen.cfg +++ b/Build/Configurations/Hexen.cfg @@ -149,7 +149,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -161,6 +161,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Legacy.cfg b/Build/Configurations/Legacy.cfg index 69c4d582..079ff1fd 100644 --- a/Build/Configurations/Legacy.cfg +++ b/Build/Configurations/Legacy.cfg @@ -138,7 +138,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -150,9 +150,9 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { - ~ + ~MAP { - required = false; + required = true; nodebuild = false; script = "Legacy_FS.cfg"; } diff --git a/Build/Configurations/Risen3D.cfg b/Build/Configurations/Risen3D.cfg index 2ae40d04..3e3b535b 100644 --- a/Build/Configurations/Risen3D.cfg +++ b/Build/Configurations/Risen3D.cfg @@ -150,7 +150,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -162,6 +162,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Skulltag_Doom.cfg b/Build/Configurations/Skulltag_Doom.cfg index f0dafd2d..2dec9d41 100644 --- a/Build/Configurations/Skulltag_Doom.cfg +++ b/Build/Configurations/Skulltag_Doom.cfg @@ -154,7 +154,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -166,6 +166,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Skulltag_DoomHexen.cfg b/Build/Configurations/Skulltag_DoomHexen.cfg index b9a987f5..c3c3ca3b 100644 --- a/Build/Configurations/Skulltag_DoomHexen.cfg +++ b/Build/Configurations/Skulltag_DoomHexen.cfg @@ -154,7 +154,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -166,6 +166,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/Strife.cfg b/Build/Configurations/Strife.cfg index 8f96c4d9..da2c9da6 100644 --- a/Build/Configurations/Strife.cfg +++ b/Build/Configurations/Strife.cfg @@ -149,7 +149,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -161,6 +161,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/UltDoom.cfg b/Build/Configurations/UltDoom.cfg index df205f8e..970b795d 100644 --- a/Build/Configurations/UltDoom.cfg +++ b/Build/Configurations/UltDoom.cfg @@ -149,7 +149,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -161,6 +161,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/ZDoom_Doom.cfg b/Build/Configurations/ZDoom_Doom.cfg index dd1b824d..7a06f49b 100644 --- a/Build/Configurations/ZDoom_Doom.cfg +++ b/Build/Configurations/ZDoom_Doom.cfg @@ -154,7 +154,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -166,6 +166,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/ZDoom_DoomHexen.cfg b/Build/Configurations/ZDoom_DoomHexen.cfg index 1821cf5a..6aa9f189 100644 --- a/Build/Configurations/ZDoom_DoomHexen.cfg +++ b/Build/Configurations/ZDoom_DoomHexen.cfg @@ -154,7 +154,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -166,6 +166,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/ZDoom_HereticHexen.cfg b/Build/Configurations/ZDoom_HereticHexen.cfg index 28fda14a..eda6c140 100644 --- a/Build/Configurations/ZDoom_HereticHexen.cfg +++ b/Build/Configurations/ZDoom_HereticHexen.cfg @@ -154,7 +154,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -166,6 +166,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/ZDoom_Hexen.cfg b/Build/Configurations/ZDoom_Hexen.cfg index ce93ebb9..3b39d4b2 100644 --- a/Build/Configurations/ZDoom_Hexen.cfg +++ b/Build/Configurations/ZDoom_Hexen.cfg @@ -154,7 +154,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -166,6 +166,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/ZDoom_StrifeHexen.cfg b/Build/Configurations/ZDoom_StrifeHexen.cfg index 36d94af9..3b4c633d 100644 --- a/Build/Configurations/ZDoom_StrifeHexen.cfg +++ b/Build/Configurations/ZDoom_StrifeHexen.cfg @@ -153,7 +153,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -165,6 +165,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Build/Configurations/jDoom.cfg b/Build/Configurations/jDoom.cfg index e34094ea..ef6eed39 100644 --- a/Build/Configurations/jDoom.cfg +++ b/Build/Configurations/jDoom.cfg @@ -150,7 +150,7 @@ MAP LUMP NAMES Map lumps are loaded with the map as long as they are right after each other. When the editor meets a lump which is not defined in this list it will ignore the map if not satisfied. The order of items defines the order in which lumps will be written to WAD file on save. -To indicate the map header lump, use tilde: ~ +To indicate the map header lump, use ~MAP Legenda: required = Lump is required to exist. @@ -162,6 +162,13 @@ script = This lump is a text-based script. Specify the filename of the script co maplumpnames { + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + THINGS { required = true; diff --git a/Source/General/General.cs b/Source/General/General.cs index 53a61bb0..938714c6 100644 --- a/Source/General/General.cs +++ b/Source/General/General.cs @@ -621,6 +621,10 @@ namespace CodeImp.DoomBuilder openfile = new OpenFileDialog(); openfile.Filter = "Doom WAD Files (*.wad)|*.wad"; openfile.Title = "Open Map"; + openfile.AddExtension = false; + openfile.CheckFileExists = true; + openfile.Multiselect = false; + openfile.ValidateNames = true; if(openfile.ShowDialog(mainwindow) == DialogResult.OK) { // Update main window @@ -685,7 +689,8 @@ namespace CodeImp.DoomBuilder // Check if a wad file is known if(map.FilePathName == "") { - // TODO: Call to SaveMapAs! + // Call to SaveMapAs + SaveMapAs(); } else { @@ -693,6 +698,27 @@ namespace CodeImp.DoomBuilder map.SaveMap(map.FilePathName, MapManager.SAVE_NORMAL); } } + + // This saves the current map as a different file + [Action(Action.SAVEMAPAS)] + public static void SaveMapAs() + { + SaveFileDialog savefile; + + // Show save as dialog + savefile = new SaveFileDialog(); + savefile.Filter = "Doom WAD Files (*.wad)|*.wad"; + savefile.Title = "Save Map As"; + savefile.AddExtension = true; + savefile.CheckPathExists = true; + savefile.OverwritePrompt = true; + savefile.ValidateNames = true; + if(savefile.ShowDialog(mainwindow) == DialogResult.OK) + { + // Save the map + map.SaveMap(savefile.FileName, MapManager.SAVE_AS); + } + } // This asks to save the map if needed // Returns false when action was cancelled diff --git a/Source/General/MapManager.cs b/Source/General/MapManager.cs index 823b3f35..8af38041 100644 --- a/Source/General/MapManager.cs +++ b/Source/General/MapManager.cs @@ -43,6 +43,7 @@ namespace CodeImp.DoomBuilder // Map header name in temporary file private const string TEMP_MAP_HEADER = "TEMPMAP"; private const string BUILD_MAP_HEADER = "MAP01"; + public const string CONFIG_MAP_HEADER = "~MAP"; // Save modes public const int SAVE_NORMAL = 0; @@ -137,7 +138,7 @@ namespace CodeImp.DoomBuilder #endregion - #region ================== Initialize + #region ================== New / Open // Initializes for a new map public bool InitializeNewMap(MapOptions options) @@ -274,11 +275,12 @@ namespace CodeImp.DoomBuilder #region ================== Save // Initializes for an existing map - public bool SaveMap(string filepathname, int savemode) + public bool SaveMap(string newfilepathname, int savemode) { MapSet outputset; - int insertindex; string nodebuildername; + WAD targetwad; + int index; // Make a copy of the map data outputset = map.Clone(); @@ -302,9 +304,9 @@ namespace CodeImp.DoomBuilder // Write to temporary file General.WriteLogLine("Writing map data structures to file..."); - insertindex = tempwad.FindLumpIndex(TEMP_MAP_HEADER); - if(insertindex == -1) insertindex = 0; - io.Write(outputset, TEMP_MAP_HEADER, insertindex); + index = tempwad.FindLumpIndex(TEMP_MAP_HEADER); + if(index == -1) index = 0; + io.Write(outputset, TEMP_MAP_HEADER, index); // Get the corresponding nodebuilder if(savemode == SAVE_TEST) nodebuildername = configinfo.NodebuilderTest; @@ -317,11 +319,52 @@ namespace CodeImp.DoomBuilder // Suspend data resources data.Suspend(); + // On save AS we have to copy the previous file to the new file + if((savemode == SAVE_AS) && (filepathname != "")) + { + // Copy if oriignal file still exists + if(File.Exists(filepathname)) + File.Copy(filepathname, newfilepathname, true); + } + + // Open the target file + targetwad = new WAD(newfilepathname); + + // Copy map lumps to target file + CopyLumpsByType(tempwad, TEMP_MAP_HEADER, targetwad, options.CurrentName, true, true, true, true); + + // Was the map lump name renamed? + if((options.PreviousName != options.CurrentName) && + (options.PreviousName != "")) + { + General.WriteLogLine("Renaming map lump name from " + options.PreviousName + " to " + options.CurrentName); + + // Find the map header in target + index = targetwad.FindLumpIndex(options.PreviousName); + if(index > -1) + { + // Rename the map lump name + targetwad.Lumps[index].Rename(options.CurrentName); + options.PreviousName = ""; + } + else + { + // Houston, we've got a problem! + General.ShowErrorMessage("Error renaming map lump name: the original map lump could not be found!", MessageBoxButtons.OK); + options.CurrentName = options.PreviousName; + options.PreviousName = ""; + } + } + + // Done with the target file + targetwad.Dispose(); // Resume data resources data.Resume(); // Success! + filepathname = newfilepathname; + filetitle = Path.GetFileName(filepathname); changed = false; return true; } @@ -448,7 +491,7 @@ namespace CodeImp.DoomBuilder #endregion - #region ================== Methods + #region ================== Lumps // This copies specific map lumps from one WAD to another private void CopyLumpsByType(WAD source, string sourcemapname, @@ -457,33 +500,30 @@ namespace CodeImp.DoomBuilder bool copynodebuild, bool copyscript) { bool lumprequired, lumpblindcopy, lumpnodebuild; - string lumpscript; - int srcindex, tgtindex; + string lumpscript, srclumpname, tgtlumpname; + int srcheaderindex, tgtheaderindex, targetindex, sourceindex, lumpindex; IDictionary maplumps; Lump lump, newlump; // Find the map header in target - tgtindex = target.FindLumpIndex(targetmapname); - if(tgtindex > -1) - { - // Remove the lumps from target - RemoveLumpsByType(target, targetmapname, copyrequired, - copyblindcopy, copynodebuild, copyscript); - } - else + tgtheaderindex = target.FindLumpIndex(targetmapname); + if(tgtheaderindex == -1) { // If this header doesnt exists in the target // then insert at the end of the target - tgtindex = target.Lumps.Count; + tgtheaderindex = target.Lumps.Count; } + + // Begin inserting at target header index + targetindex = tgtheaderindex; // Find the map header in source - srcindex = source.FindLumpIndex(sourcemapname); - if(srcindex > -1) + srcheaderindex = source.FindLumpIndex(sourcemapname); + if(srcheaderindex > -1) { // Copy the map header from source to target - newlump = target.Insert(targetmapname, tgtindex++, source.Lumps[srcindex].Length); - source.Lumps[srcindex].CopyTo(newlump); + //newlump = target.Insert(targetmapname, tgtindex++, source.Lumps[srcindex].Length); + //source.Lumps[srcindex].CopyTo(newlump); // Go for all the map lump names maplumps = config.ReadSetting("maplumpnames", new Hashtable()); @@ -499,13 +539,29 @@ namespace CodeImp.DoomBuilder if((lumprequired && copyrequired) || (lumpblindcopy && copyblindcopy) || (lumpnodebuild && copynodebuild) || ((lumpscript != "") && copyscript)) { + // Get the lump name + srclumpname = ml.Key.ToString(); + tgtlumpname = ml.Key.ToString(); + if(srclumpname == CONFIG_MAP_HEADER) srclumpname = sourcemapname; + if(tgtlumpname == CONFIG_MAP_HEADER) tgtlumpname = targetmapname; + // Find the lump in the source - lump = source.FindLump(ml.Key.ToString(), srcindex, srcindex + maplumps.Count + 2); - if(lump != null) + sourceindex = FindSpecificLump(source, srclumpname, srcheaderindex, sourcemapname, maplumps); + if(sourceindex > -1) { + // Remove lump at target + lumpindex = RemoveSpecificLump(target, tgtlumpname, tgtheaderindex, targetmapname, maplumps); + + // Determine target index + // When original lump was found and removed then insert at that position + // otherwise insert after last insertion position + if(lumpindex > -1) targetindex = lumpindex; else targetindex++; + if(targetindex > target.Lumps.Count) targetindex = target.Lumps.Count; + // Copy the lump to the target - //General.WriteLogLine(ml.Key.ToString() + " copying"); - newlump = target.Insert(ml.Key.ToString(), tgtindex++, lump.Length); + //General.WriteLogLine(srclumpname + " copying as " + tgtlumpname); + lump = source.Lumps[sourceindex]; + newlump = target.Insert(tgtlumpname, targetindex, lump.Length); lump.CopyTo(newlump); } else @@ -517,55 +573,69 @@ namespace CodeImp.DoomBuilder } } - // This copies specific map lumps from one WAD to another - private void RemoveLumpsByType(WAD source, string sourcemapname, - bool removerequired, bool removeblindcopy, - bool removenodebuild, bool removescript) + // This finds a lump within the range of known lump names + // Returns -1 when the lump cannot be found + private int FindSpecificLump(WAD source, string lumpname, int mapheaderindex, string mapheadername, IDictionary maplumps) { - bool lumprequired, lumpblindcopy, lumpnodebuild; - string nextlumpname, lumpscript; - int index; - - // Find the map header in target - index = source.FindLumpIndex(sourcemapname); - if(index > -1) + // Use the configured map lump names to find the specific lump within range, + // because when an unknown lump is met, this search must stop. + + // Go for all lumps in order to find the specified lump + for(int i = 0; i < maplumps.Count + 1; i++) { - // Remove the header from target - source.RemoveAt(index); - - // Get the name of the next lump - if(index < source.Lumps.Count) nextlumpname = source.Lumps[index].Name; - else nextlumpname = ""; - - // Do we recognize this lump type? - while(config.ReadSetting("maplumpnames." + nextlumpname, (IDictionary)null) != null) + // Still within bounds? + if((mapheaderindex + i) < source.Lumps.Count) { - // Read lump settings from map config - lumprequired = config.ReadSetting("maplumpnames." + nextlumpname + ".required", false); - lumpblindcopy = config.ReadSetting("maplumpnames." + nextlumpname + ".blindcopy", false); - lumpnodebuild = config.ReadSetting("maplumpnames." + nextlumpname + ".nodebuild", false); - lumpscript = config.ReadSetting("maplumpnames." + nextlumpname + ".script", ""); - - // Check if this lump will be removed from target - if((lumprequired && removerequired) || (lumpblindcopy && removeblindcopy) || - (lumpnodebuild && removenodebuild) || ((lumpscript != "") && removescript)) + // Check if this is a known lump name + if(maplumps.Contains(source.Lumps[mapheaderindex + i].Name) || + (maplumps.Contains(CONFIG_MAP_HEADER) && (source.Lumps[mapheaderindex + i].Name == mapheadername))) { - // Then remove it from target - //General.WriteLogLine(nextlumpname + " removing"); - source.RemoveAt(index); + // Is this the lump we are looking for? + if(source.Lumps[mapheaderindex + i].Name == lumpname) + { + // Return this index + return mapheaderindex + i; + } } else { - // Advance to the next lump - index++; + // Unknown lump hit, abort search + break; } - - // Get the name of the next lump - if(index < source.Lumps.Count) nextlumpname = source.Lumps[index].Name; - else nextlumpname = ""; } } + + // Nothing found + return -1; } + + // This removes a specific lump and returns the position where the lump was removed + // Returns -1 when the lump could not be found + private int RemoveSpecificLump(WAD source, string lumpname, int mapheaderindex, string mapheadername, IDictionary maplumps) + { + int lumpindex; + + // Find the specific lump index + lumpindex = FindSpecificLump(source, lumpname, mapheaderindex, mapheadername, maplumps); + if(lumpindex > -1) + { + // Remove this lump + //General.WriteLogLine(lumpname + " removed"); + source.RemoveAt(lumpindex); + } + else + { + // Lump not found + General.WriteLogLine("WARNING: " + lumpname + " should be removed but was not found!"); + } + + // Return result + return lumpindex; + } + + #endregion + + #region ================== Methods // This changes editing mode public void ChangeMode(Type modetype, params object[] args) @@ -580,7 +650,7 @@ namespace CodeImp.DoomBuilder // Redraw the display General.MainWindow.RedrawDisplay(); } - + #endregion } } diff --git a/Source/IO/DoomMapSetIO.cs b/Source/IO/DoomMapSetIO.cs index 49e61ac1..d6a00c7e 100644 --- a/Source/IO/DoomMapSetIO.cs +++ b/Source/IO/DoomMapSetIO.cs @@ -196,7 +196,7 @@ namespace CodeImp.DoomBuilder.IO // Create new item s = map.CreateSector(); - s.Update(hfloor, hceil, tfloor, tceil, special, tag); + s.Update(hfloor, hceil, tfloor, tceil, special, tag, bright); // Add it to the lookup table link.Add(i, s); @@ -340,9 +340,9 @@ namespace CodeImp.DoomBuilder.IO // Write properties to stream writer.Write((Int16)t.Position.x); writer.Write((Int16)t.Position.y); - writer.Write((Int16)0); // TODO: Fix this! + writer.Write((Int16)t.Angle); // TODO: Fix this! writer.Write((UInt16)t.Type); - writer.Write((UInt16)0); // TODO: Fix this! + writer.Write((UInt16)t.Flags); } // Find insert position and remove old lump @@ -404,9 +404,9 @@ namespace CodeImp.DoomBuilder.IO // Write properties to stream writer.Write((UInt16)vertexids[l.Start]); writer.Write((UInt16)vertexids[l.End]); - writer.Write((UInt16)0); // TODO: Fix this! - writer.Write((UInt16)0); // TODO: Fix this! - writer.Write((UInt16)0); // TODO: Fix this! + writer.Write((UInt16)l.Flags); + writer.Write((UInt16)l.Action); + writer.Write((UInt16)l.Tag); // Front sidedef if(l.Front == null) sid = ushort.MaxValue; @@ -445,11 +445,11 @@ namespace CodeImp.DoomBuilder.IO foreach(Sidedef sd in map.Sidedefs) { // Write properties to stream - writer.Write((Int16)0); // TODO: Fix this! - writer.Write((Int16)0); // TODO: Fix this! - writer.Write(Lump.MakeFixedName("", WAD.ENCODING)); // TODO: Fix this! - writer.Write(Lump.MakeFixedName("", WAD.ENCODING)); // TODO: Fix this! - writer.Write(Lump.MakeFixedName("", WAD.ENCODING)); // TODO: Fix this! + writer.Write((Int16)sd.OffsetX); + writer.Write((Int16)sd.OffsetY); + writer.Write(Lump.MakeFixedName(sd.HighTexture, WAD.ENCODING)); + writer.Write(Lump.MakeFixedName(sd.MiddleTexture, WAD.ENCODING)); + writer.Write(Lump.MakeFixedName(sd.LowTexture, WAD.ENCODING)); writer.Write((UInt16)sectorids[sd.Sector]); } @@ -479,13 +479,13 @@ namespace CodeImp.DoomBuilder.IO foreach(Sector s in map.Sectors) { // Write properties to stream - writer.Write((Int16)0); // TODO: Fix this! - writer.Write((Int16)0); // TODO: Fix this! - writer.Write(Lump.MakeFixedName("", WAD.ENCODING)); // TODO: Fix this! - writer.Write(Lump.MakeFixedName("", WAD.ENCODING)); // TODO: Fix this! - writer.Write((Int16)0); // TODO: Fix this! - writer.Write((UInt16)0); // TODO: Fix this! - writer.Write((UInt16)0); // TODO: Fix this! + writer.Write((Int16)s.FloorHeight); + writer.Write((Int16)s.CeilHeight); + writer.Write(Lump.MakeFixedName(s.FloorTexture, WAD.ENCODING)); + writer.Write(Lump.MakeFixedName(s.CeilTexture, WAD.ENCODING)); + writer.Write((Int16)s.Brightness); + writer.Write((UInt16)s.Special); + writer.Write((UInt16)s.Tag); } // Find insert position and remove old lump diff --git a/Source/IO/Lump.cs b/Source/IO/Lump.cs index 22bac768..25efa910 100644 --- a/Source/IO/Lump.cs +++ b/Source/IO/Lump.cs @@ -162,6 +162,18 @@ namespace CodeImp.DoomBuilder.IO return name; } + // This renames the lump + public void Rename(string newname) + { + // Make name + this.fixedname = MakeFixedName(newname, WAD.ENCODING); + this.name = MakeNormalName(this.fixedname, WAD.ENCODING).ToUpperInvariant(); + this.longname = MakeLongName(newname); + + // Write changes + owner.WriteHeaders(); + } + #endregion } } diff --git a/Source/IO/WAD.cs b/Source/IO/WAD.cs index 75ae3fb0..b076ba62 100644 --- a/Source/IO/WAD.cs +++ b/Source/IO/WAD.cs @@ -218,7 +218,7 @@ namespace CodeImp.DoomBuilder.IO } // This reads the WAD header and lumps table - private void WriteHeaders() + public void WriteHeaders() { // Seek to beginning file.Seek(0, SeekOrigin.Begin); @@ -312,7 +312,7 @@ namespace CodeImp.DoomBuilder.IO // Write the new headers WriteHeaders(); } - + // This finds a lump by name, returns null when not found public Lump FindLump(string name) { diff --git a/Source/Interface/MainForm.Designer.cs b/Source/Interface/MainForm.Designer.cs index abbde5c0..8b26b6c1 100644 --- a/Source/Interface/MainForm.Designer.cs +++ b/Source/Interface/MainForm.Designer.cs @@ -178,6 +178,7 @@ namespace CodeImp.DoomBuilder.Interface // this.itemsavemapas.Name = "itemsavemapas"; this.itemsavemapas.Size = new System.Drawing.Size(201, 22); + this.itemsavemapas.Tag = "savemapas"; this.itemsavemapas.Text = "Save Map As..."; this.itemsavemapas.Click += new System.EventHandler(this.InvokeTaggedAction); // @@ -263,7 +264,7 @@ namespace CodeImp.DoomBuilder.Interface this.buttonnewmap.Name = "buttonnewmap"; this.buttonnewmap.Size = new System.Drawing.Size(23, 22); this.buttonnewmap.Tag = "newmap"; - this.buttonnewmap.Text = "toolStripButton1"; + this.buttonnewmap.Text = "New Map"; this.buttonnewmap.Click += new System.EventHandler(this.InvokeTaggedAction); // // buttonopenmap @@ -274,7 +275,7 @@ namespace CodeImp.DoomBuilder.Interface this.buttonopenmap.Name = "buttonopenmap"; this.buttonopenmap.Size = new System.Drawing.Size(23, 22); this.buttonopenmap.Tag = "openmap"; - this.buttonopenmap.Text = "toolStripButton1"; + this.buttonopenmap.Text = "Open Map"; this.buttonopenmap.Click += new System.EventHandler(this.InvokeTaggedAction); // // buttonsavemap @@ -285,7 +286,7 @@ namespace CodeImp.DoomBuilder.Interface this.buttonsavemap.Name = "buttonsavemap"; this.buttonsavemap.Size = new System.Drawing.Size(23, 22); this.buttonsavemap.Tag = "savemap"; - this.buttonsavemap.Text = "toolStripButton1"; + this.buttonsavemap.Text = "Save Map"; this.buttonsavemap.Click += new System.EventHandler(this.InvokeTaggedAction); // // statusbar diff --git a/Source/Interface/MainForm.cs b/Source/Interface/MainForm.cs index c3beab25..78a1bd24 100644 --- a/Source/Interface/MainForm.cs +++ b/Source/Interface/MainForm.cs @@ -492,6 +492,11 @@ namespace CodeImp.DoomBuilder.Interface itemsavemap.Enabled = (General.Map != null); itemsavemapas.Enabled = (General.Map != null); itemsavemapinto.Enabled = (General.Map != null); + + // Toolbar icons + buttonnewmap.Enabled = itemnewmap.Enabled; + buttonopenmap.Enabled = itemopenmap.Enabled; + buttonsavemap.Enabled = itemsavemap.Enabled; } // This sets the recent files from configuration diff --git a/Source/Interface/OpenMapOptionsForm.cs b/Source/Interface/OpenMapOptionsForm.cs index 7141b530..f4ca1853 100644 --- a/Source/Interface/OpenMapOptionsForm.cs +++ b/Source/Interface/OpenMapOptionsForm.cs @@ -210,8 +210,12 @@ namespace CodeImp.DoomBuilder.Interface // Count how many required lumps we have to find foreach(DictionaryEntry ml in maplumpnames) { - // Read lump setting and count it - if(cfg.ReadSetting("maplumpnames." + ml.Key + ".required", false)) lumpsrequired++; + // Ignore the map header (it will not be found because the name is different) + if(ml.Key.ToString() != MapManager.CONFIG_MAP_HEADER) + { + // Read lump setting and count it + if(cfg.ReadSetting("maplumpnames." + ml.Key + ".required", false)) lumpsrequired++; + } } // Go for all the lumps in the wad diff --git a/Source/Map/Linedef.cs b/Source/Map/Linedef.cs index be244fa8..8d9a2030 100644 --- a/Source/Map/Linedef.cs +++ b/Source/Map/Linedef.cs @@ -83,6 +83,9 @@ namespace CodeImp.DoomBuilder.Map public Sidedef Front { get { return front; } } public Sidedef Back { get { return back; } } public bool IsDisposed { get { return isdisposed; } } + public int Flags { get { return flags; } } + public int Action { get { return action; } } + public int Tag { get { return tag; } } #endregion diff --git a/Source/Map/MapOptions.cs b/Source/Map/MapOptions.cs index da25ea83..fcdd90f5 100644 --- a/Source/Map/MapOptions.cs +++ b/Source/Map/MapOptions.cs @@ -42,7 +42,7 @@ namespace CodeImp.DoomBuilder.Map // Map header name private string currentname; - private string previousname; + private string previousname; // When zero length string, map has not renamed // Additional resources private DataLocationList resources; @@ -53,7 +53,7 @@ namespace CodeImp.DoomBuilder.Map public string ConfigFile { get { return configfile; } set { configfile = value; } } public DataLocationList Resources { get { return resources; } } - public string PreviousName { get { return previousname; } } + public string PreviousName { get { return previousname; } set { previousname = value; } } public string CurrentName { get { return currentname; } diff --git a/Source/Map/Sector.cs b/Source/Map/Sector.cs index a9831647..74868435 100644 --- a/Source/Map/Sector.cs +++ b/Source/Map/Sector.cs @@ -53,6 +53,7 @@ namespace CodeImp.DoomBuilder.Map private string ceiltexname; private int special; private int tag; + private int brightness; // Disposing private bool isdisposed = false; @@ -63,6 +64,13 @@ namespace CodeImp.DoomBuilder.Map public MapSet Map { get { return map; } } public bool IsDisposed { get { return isdisposed; } } + public int FloorHeight { get { return floorheight; } } + public int CeilHeight { get { return ceilheight; } } + public string FloorTexture { get { return floortexname; } } + public string CeilTexture { get { return ceiltexname; } } + public int Special { get { return special; } } + public int Tag { get { return tag; } } + public int Brightness { get { return brightness; } } #endregion @@ -156,7 +164,7 @@ namespace CodeImp.DoomBuilder.Map #region ================== Changes // This updates all properties - public void Update(int hfloor, int hceil, string tfloor, string tceil, int special, int tag) + public void Update(int hfloor, int hceil, string tfloor, string tceil, int special, int tag, int brightness) { // Apply changes this.floorheight = hfloor; @@ -165,6 +173,7 @@ namespace CodeImp.DoomBuilder.Map this.ceiltexname = tceil; this.special = special; this.tag = tag; + this.brightness = brightness; } #endregion diff --git a/Source/Map/Sidedef.cs b/Source/Map/Sidedef.cs index b9fbcfbb..35b602e7 100644 --- a/Source/Map/Sidedef.cs +++ b/Source/Map/Sidedef.cs @@ -67,7 +67,12 @@ namespace CodeImp.DoomBuilder.Map public Sidedef Other { get { if(this == linedef.Front) return linedef.Back; else return linedef.Front; } } public Sector Sector { get { return sector; } } public bool IsDisposed { get { return isdisposed; } } - + public int OffsetX { get { return offsetx; } } + public int OffsetY { get { return offsety; } } + public string HighTexture { get { return texnamehigh; } } + public string MiddleTexture { get { return texnamemid; } } + public string LowTexture { get { return texnamelow; } } + #endregion #region ================== Constructor / Disposer diff --git a/Source/Map/Thing.cs b/Source/Map/Thing.cs index 0541ae49..fe6ad5d3 100644 --- a/Source/Map/Thing.cs +++ b/Source/Map/Thing.cs @@ -67,6 +67,8 @@ namespace CodeImp.DoomBuilder.Map public int Type { get { return type; } } public Vector3D Position { get { return pos; } } public bool IsDisposed { get { return isdisposed; } } + public float Angle { get { return angle; } } + public int Flags { get { return flags; } } #endregion diff --git a/Source/Resources/Actions.cfg b/Source/Resources/Actions.cfg index 9de45bac..bb19dc3c 100644 --- a/Source/Resources/Actions.cfg +++ b/Source/Resources/Actions.cfg @@ -41,6 +41,15 @@ savemap allowscroll = false; } +savemapas +{ + title = "File: Save Map As"; + description = "Saves the current map and all resources from the source WAD file to a new WAD file."; + allowkeys = true; + allowmouse = false; + allowscroll = false; +} + scrollwest { title = "2D: Scroll West";