mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-17 01:22:18 +00:00
Fixed, "Flip Linedefs" action: in some cases my sector based flipping logic was behaving incorrectly.
This commit is contained in:
parent
42dbec728c
commit
d71b5814e1
2 changed files with 38 additions and 15 deletions
|
@ -2140,14 +2140,21 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
{
|
||||
List<Linedef> frontlines = new List<Linedef>();
|
||||
List<Linedef> backlines = new List<Linedef>();
|
||||
int unselectedfrontlines = 0;
|
||||
int unselectedbacklines = 0;
|
||||
|
||||
//sort lines
|
||||
foreach (Sidedef side in s.Sidedefs)
|
||||
foreach(Sidedef side in s.Sidedefs)
|
||||
{
|
||||
if (processed.ContainsKey(side.Line)
|
||||
|| (selectedlinesonly && !side.Line.Selected)) continue;
|
||||
if(processed.ContainsKey(side.Line)) continue;
|
||||
if(selectedlinesonly && !side.Line.Selected)
|
||||
{
|
||||
if(side == side.Line.Front) unselectedfrontlines++;
|
||||
else unselectedbacklines++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (side == side.Line.Front)
|
||||
if(side == side.Line.Front)
|
||||
frontlines.Add(side.Line);
|
||||
else
|
||||
backlines.Add(side.Line);
|
||||
|
@ -2156,9 +2163,9 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
}
|
||||
|
||||
//flip lines
|
||||
if (frontlines.Count == 0 || (frontlines.Count > backlines.Count && backlines.Count > 0))
|
||||
if(frontlines.Count == 0 || (frontlines.Count + unselectedfrontlines > backlines.Count + unselectedbacklines && backlines.Count > 0))
|
||||
{
|
||||
foreach (Linedef l in backlines)
|
||||
foreach(Linedef l in backlines)
|
||||
{
|
||||
l.FlipVertices();
|
||||
l.FlipSidedefs();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using CodeImp.DoomBuilder.Windows;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
@ -1186,21 +1187,36 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
}
|
||||
|
||||
//mxd. Do it sector-wise
|
||||
List<Sector> sectors = new List<Sector>(1);
|
||||
Dictionary<Sector, int> sectors = new Dictionary<Sector, int>();
|
||||
|
||||
foreach(Linedef l in selected)
|
||||
{
|
||||
if (l.Front != null && l.Front.Sector != null && !sectors.Contains(l.Front.Sector))
|
||||
sectors.Add(l.Front.Sector);
|
||||
|
||||
if (l.Back != null && l.Back.Sector != null && !sectors.Contains(l.Back.Sector))
|
||||
sectors.Add(l.Back.Sector);
|
||||
if(l.Front != null && l.Front.Sector != null)
|
||||
{
|
||||
if(!sectors.ContainsKey(l.Front.Sector)) sectors.Add(l.Front.Sector, 0);
|
||||
sectors[l.Front.Sector]++;
|
||||
}
|
||||
|
||||
if(l.Back != null && l.Back.Sector != null)
|
||||
{
|
||||
if(!sectors.ContainsKey(l.Back.Sector)) sectors.Add(l.Back.Sector, 0);
|
||||
sectors[l.Back.Sector]++;
|
||||
}
|
||||
}
|
||||
|
||||
//mxd. Flip the lines
|
||||
Tools.FlipSectorLinedefs(sectors, true);
|
||||
//mxd. Sort the collection so sectors with the most selected linedefs go first
|
||||
List<KeyValuePair<Sector, int>> sortedlist = sectors.ToList();
|
||||
sortedlist.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value));
|
||||
sortedlist.Reverse();
|
||||
|
||||
// Remove selection if only one was selected
|
||||
//mxd. Gather our ordered sectors
|
||||
List<Sector> sectorslist = new List<Sector>(sortedlist.Count());
|
||||
sectorslist.AddRange(sortedlist.Select(pair => pair.Key));
|
||||
|
||||
//mxd. Flip the lines
|
||||
Tools.FlipSectorLinedefs(sectorslist, true);
|
||||
|
||||
// Remove selection if only one linedef was selected
|
||||
if(selected.Count == 1)
|
||||
{
|
||||
foreach(Linedef ld in selected) ld.Selected = false;
|
||||
|
|
Loading…
Reference in a new issue