From 81169e84fee232006c19b3d3bad6f43ea107f90c Mon Sep 17 00:00:00 2001 From: codeimp Date: Fri, 9 Jan 2009 22:04:24 +0000 Subject: [PATCH] drawing a new sector completely inside a parent sector now takes the properties of the parent sector --- .../ClassicModes/MakeSectorMode.cs | 42 ++++++++++++------- Source/Geometry/Tools.cs | 38 +++++++++++++++-- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/Source/BuilderModes/ClassicModes/MakeSectorMode.cs b/Source/BuilderModes/ClassicModes/MakeSectorMode.cs index 99b293d0..d78d6c15 100644 --- a/Source/BuilderModes/ClassicModes/MakeSectorMode.cs +++ b/Source/BuilderModes/ClassicModes/MakeSectorMode.cs @@ -227,13 +227,22 @@ namespace CodeImp.DoomBuilder.BuilderModes } } - // Start select - protected override void OnSelectBegin() + // This makes this highlighted potential sector + private Sector MakeSector() { - // Select pressed in this mode - selectpressed = true; - editside = nearestside; - base.OnEditBegin(); + General.Interface.SetCursor(Cursors.WaitCursor); + General.Settings.FindDefaultDrawSettings(); + General.Map.UndoRedo.CreateUndo("Make Sector"); + + // Mark the lines we are going to use for this sector + General.Map.Map.ClearAllMarks(true); + foreach(LinedefSide ls in allsides) ls.Line.Marked = false; + List oldlines = General.Map.Map.GetMarkedLinedefs(true); + + // Make the sector + Sector s = Tools.MakeSector(allsides, oldlines); + General.Interface.SetCursor(Cursors.Default); + return s; } #endregion @@ -325,6 +334,15 @@ namespace CodeImp.DoomBuilder.BuilderModes renderer.Present(); } + // Start select + protected override void OnSelectBegin() + { + // Select pressed in this mode + selectpressed = true; + editside = nearestside; + base.OnEditBegin(); + } + // Done selecting protected override void OnSelectEnd() { @@ -335,11 +353,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(allsides != null) { // Make the sector - General.Interface.SetCursor(Cursors.WaitCursor); - General.Settings.FindDefaultDrawSettings(); - General.Map.UndoRedo.CreateUndo("Make Sector"); - Sector s = Tools.MakeSector(allsides); - General.Interface.SetCursor(Cursors.Default); + Sector s = MakeSector(); // Quickly flash this sector to indicate it was created General.Map.IsChanged = true; @@ -381,11 +395,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(allsides != null) { // Make the sector - General.Interface.SetCursor(Cursors.WaitCursor); - General.Settings.FindDefaultDrawSettings(); - General.Map.UndoRedo.CreateUndo("Make Sector"); - Sector s = Tools.MakeSector(allsides); - General.Interface.SetCursor(Cursors.Default); + Sector s = MakeSector(); // Edit the sector List secs = new List(); secs.Add(s); diff --git a/Source/Geometry/Tools.cs b/Source/Geometry/Tools.cs index 3911a0b6..d4bb0088 100644 --- a/Source/Geometry/Tools.cs +++ b/Source/Geometry/Tools.cs @@ -441,12 +441,16 @@ namespace CodeImp.DoomBuilder.Geometry #region ================== Sector Making // This makes the sector from the given lines and sides - public static Sector MakeSector(List alllines) + // If nearbylines is not null, then this method will find the default + // properties from the nearest line in this collection when the + // default properties can't be found in the alllines collection. + public static Sector MakeSector(List alllines, List nearbylines) { Sector newsector = General.Map.Map.CreateSector(); Sector sourcesector = null; SidedefSettings sourceside = new SidedefSettings(); bool removeuselessmiddle; + bool foundsidedefaults = false; // Check if any of the sides already has a sidedef // Then we use information from that sidedef to make the others @@ -459,6 +463,7 @@ namespace CodeImp.DoomBuilder.Geometry // Copy sidedef information if not already found if(sourcesector == null) sourcesector = ls.Line.Front.Sector; TakeSidedefSettings(ref sourceside, ls.Line.Front); + foundsidedefaults = true; break; } } @@ -469,11 +474,12 @@ namespace CodeImp.DoomBuilder.Geometry // Copy sidedef information if not already found if(sourcesector == null) sourcesector = ls.Line.Back.Sector; TakeSidedefSettings(ref sourceside, ls.Line.Back); + foundsidedefaults = true; break; } } } - + // Now do the same for the other sides // Note how information is only copied when not already found // so this won't override information from the sides searched above @@ -486,6 +492,7 @@ namespace CodeImp.DoomBuilder.Geometry // Copy sidedef information if not already found if(sourcesector == null) sourcesector = ls.Line.Back.Sector; TakeSidedefSettings(ref sourceside, ls.Line.Back); + foundsidedefaults = true; break; } } @@ -496,11 +503,34 @@ namespace CodeImp.DoomBuilder.Geometry // Copy sidedef information if not already found if(sourcesector == null) sourcesector = ls.Line.Front.Sector; TakeSidedefSettings(ref sourceside, ls.Line.Front); + foundsidedefaults = true; break; } } } + // Use default settings from neares linedef, if settings have been found yet + if( (nearbylines != null) && (alllines.Count > 0) && (!foundsidedefaults || (sourcesector == null)) ) + { + Vector2D testpoint = alllines[0].Line.GetSidePoint(alllines[0].Front); + Linedef nearest = MapSet.NearestLinedef(nearbylines, testpoint); + if(nearest != null) + { + Sidedef defaultside; + float side = nearest.SideOfLine(testpoint); + if(side < 0.0f) + defaultside = nearest.Front; + else + defaultside = nearest.Back; + + if(defaultside != null) + { + if(sourcesector == null) sourcesector = defaultside.Sector; + TakeSidedefSettings(ref sourceside, defaultside); + } + } + } + // Use defaults where no settings could be found TakeSidedefDefaults(ref sourceside); @@ -1057,7 +1087,7 @@ namespace CodeImp.DoomBuilder.Geometry // Find our new lines again, because they have been merged with the other geometry // but their Marked property is copied where they have joined. newlines = map.GetMarkedLinedefs(true); - + /***************************************************\ STEP 3: Join and create new sectors \***************************************************/ @@ -1082,7 +1112,7 @@ namespace CodeImp.DoomBuilder.Geometry sidescreated = true; // Make the new sector - Sector newsector = Tools.MakeSector(sectorlines); + Sector newsector = Tools.MakeSector(sectorlines, oldlines); // Go for all sidedefs in this new sector foreach(Sidedef sd in newsector.Sidedefs)