@ work in progress, may crash or not even compile

This commit is contained in:
codeimp 2009-03-30 07:45:39 +00:00
parent bf4b898aba
commit 71b80f9f50
8 changed files with 209 additions and 117 deletions

View file

@ -435,12 +435,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
SelectSector(highlighted, true, false);
}
}
// Going to SectorsMode?
else if(General.Editing.NewMode is SectorsMode)
{
// Pass on the ordered selection
(General.Editing.NewMode as SectorsMode).SetOrderedSelection(orderedselection);
}
// Hide highlight info
General.Interface.HideInfo();

View file

@ -61,11 +61,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Interface
protected bool editpressed;
// The methods GetSelected* and MarkSelected* on the MapSet do not
// retain the order in which items were selected.
// This list keeps in order while sectors are selected/deselected.
protected List<Sector> orderedselection;
// Labels
private Dictionary<Sector, TextLabel[]> labels;
@ -73,8 +68,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Properties
public ICollection<Sector> OrderedSelection { get { return orderedselection; } }
#endregion
#region ================== Constructor / Disposer
@ -82,8 +75,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Constructor
public SectorsMode()
{
// Make ordered selection list
orderedselection = new List<Sector>();
}
// Disposer
@ -96,9 +87,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
foreach(KeyValuePair<Sector, TextLabel[]> lbl in labels)
foreach(TextLabel l in lbl.Value) l.Dispose();
// Clean up
orderedselection = null;
// Dispose base
base.Dispose();
}
@ -112,6 +100,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
public int CreateSelectionCRC()
{
CRC crc = new CRC();
ICollection<Sector> orderedselection = General.Map.Map.GetSelectedSectors(true);
crc.Add(orderedselection.Count);
foreach(Sector s in orderedselection)
{
@ -120,12 +109,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
return (int)(crc.Value & 0xFFFFFFFF);
}
// This sets the ordered selection
public void SetOrderedSelection(ICollection<Sector> list)
{
orderedselection = new List<Sector>(list);
}
// This sets up new labels
private void SetupLabels()
{
@ -166,6 +149,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(BuilderPlug.Me.ViewSelectionNumbers)
{
// Go for all selected sectors
ICollection<Sector> orderedselection = General.Map.Map.GetSelectedSectors(true);
foreach(Sector s in orderedselection)
{
// Render labels
@ -210,6 +194,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
// Find the first sector that is not disposed
List<Sector> orderedselection = new List<Sector>(General.Map.Map.GetSelectedSectors(true));
Sector first = null;
foreach(Sector s in orderedselection)
if(!s.IsDisposed) { first = s; break; }
@ -322,7 +307,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Select the sector?
if(selectstate && !s.Selected)
{
orderedselection.Add(s);
s.Selected = true;
selectionchanged = true;
@ -330,14 +314,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
TextLabel[] labelarray = labels[s];
foreach(TextLabel l in labelarray)
{
l.Text = orderedselection.Count.ToString();
l.Text = General.Map.Map.GetSelectedSectors(true).Count.ToString();
l.Color = General.Colors.Selection;
}
}
// Deselect the sector?
else if(!selectstate && s.Selected)
{
orderedselection.Remove(s);
s.Selected = false;
selectionchanged = true;
@ -368,28 +351,25 @@ namespace CodeImp.DoomBuilder.BuilderModes
renderer.Present();
}
}
else
{
// Remove from list
orderedselection.Remove(s);
}
}
// This updates labels from the selected sectors
private void UpdateSelectedLabels()
{
// Go for all labels in all selected sectors
for(int i = 0; i < orderedselection.Count; i++)
ICollection<Sector> orderedselection = General.Map.Map.GetSelectedSectors(true);
int index = 0;
foreach(Sector s in orderedselection)
{
Sector s = orderedselection[i];
TextLabel[] labelarray = labels[s];
foreach(TextLabel l in labelarray)
{
// Make sure the text and color are right
int labelnum = i + 1;
int labelnum = index + 1;
l.Text = labelnum.ToString();
l.Color = General.Colors.Selection;
}
index++;
}
}
@ -446,14 +426,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Make text labels for sectors
SetupLabels();
// Fill the list with selected sectors (these are not in order, but we have no other choice)
ICollection<Sector> selectedsectors = General.Map.Map.GetSelectedSectors(true);
if(orderedselection.Count < selectedsectors.Count)
{
General.Map.Map.ClearSelectedSectors();
foreach(Sector s in selectedsectors) SelectSector(s, true, false);
}
// Update
UpdateSelectedLabels();
UpdateOverlay();
@ -481,12 +453,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
SelectSector(highlighted, true, false);
}
}
// Going to BrightnessMode?
else if(General.Editing.NewMode is BrightnessMode)
{
// Pass on the ordered selection
(General.Editing.NewMode as BrightnessMode).SetOrderedSelection(orderedselection);
}
// Hide highlight info
General.Interface.HideInfo();
@ -649,7 +615,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
// When a single sector was selected, deselect it now
if(selected.Count == 1)
{
orderedselection.Clear();
General.Map.Map.ClearSelectedSectors();
General.Map.Map.ClearSelectedLinedefs();
}
@ -806,11 +771,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(!sd.Sector.Selected && ((sd.Other == null) || !sd.Other.Sector.Selected))
sd.Line.Selected = false;
// Fill the list with selected sectors (these are not in order, but we have no other choice)
orderedselection.Clear();
ICollection<Sector> selectedsectors = General.Map.Map.GetSelectedSectors(true);
foreach(Sector s in selectedsectors) orderedselection.Add(s);
base.OnEndMultiSelection();
if(renderer.StartOverlay(true)) renderer.Finish();
General.Interface.RedrawDisplay();
@ -861,7 +821,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
// Clear ordered selection
General.Map.Map.ClearAllSelected();
orderedselection.Clear();
return base.OnUndoBegin();
}
@ -878,7 +837,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
// Clear ordered selection
General.Map.Map.ClearAllSelected();
orderedselection.Clear();
return base.OnRedoBegin();
}
@ -927,6 +885,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
// Anything selected?
ICollection<Sector> orderedselection = General.Map.Map.GetSelectedSectors(true);
if(orderedselection.Count > 0)
{
string doortex = "";
@ -1159,18 +1118,21 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Need at least 3 selected sectors
// The first and last are not modified
ICollection<Sector> orderedselection = General.Map.Map.GetSelectedSectors(true);
if(orderedselection.Count > 2)
{
float startbrightness = (float)orderedselection[0].Brightness;
float endbrightness = (float)orderedselection[orderedselection.Count - 1].Brightness;
float startbrightness = (float)General.GetByIndex(orderedselection, 0).Brightness;
float endbrightness = (float)General.GetByIndex(orderedselection, orderedselection.Count - 1).Brightness;
float delta = endbrightness - startbrightness;
// Go for all sectors in between first and last
for(int i = 1; i < (orderedselection.Count - 1); i++)
int index = 0;
foreach(Sector s in orderedselection)
{
float u = (float)i / (float)(orderedselection.Count - 1);
float u = (float)index / (float)(orderedselection.Count - 1);
float b = startbrightness + delta * u;
orderedselection[i].Brightness = (int)b;
s.Brightness = (int)b;
index++;
}
}
@ -1192,18 +1154,21 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Need at least 3 selected sectors
// The first and last are not modified
ICollection<Sector> orderedselection = General.Map.Map.GetSelectedSectors(true);
if(orderedselection.Count > 2)
{
float startlevel = (float)orderedselection[0].FloorHeight;
float endlevel = (float)orderedselection[orderedselection.Count - 1].FloorHeight;
float startlevel = (float)General.GetByIndex(orderedselection, 0).FloorHeight;
float endlevel = (float)General.GetByIndex(orderedselection, orderedselection.Count - 1).FloorHeight;
float delta = endlevel - startlevel;
// Go for all sectors in between first and last
for(int i = 1; i < (orderedselection.Count - 1); i++)
int index = 0;
foreach(Sector s in orderedselection)
{
float u = (float)i / (float)(orderedselection.Count - 1);
float u = (float)index / (float)(orderedselection.Count - 1);
float b = startlevel + delta * u;
orderedselection[i].FloorHeight = (int)b;
s.FloorHeight = (int)b;
index++;
}
}
@ -1212,6 +1177,38 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Map.IsChanged = true;
}
// Make gradient ceilings
[BeginAction("gradientceilings")]
public void MakeGradientCeilings()
{
General.Interface.DisplayStatus(StatusType.Action, "Created gradient ceiling heights over selected sectors.");
General.Map.UndoRedo.CreateUndo("Gradient ceiling heights");
// Need at least 3 selected sectors
// The first and last are not modified
ICollection<Sector> orderedselection = General.Map.Map.GetSelectedSectors(true);
if(orderedselection.Count > 2)
{
float startlevel = (float)General.GetByIndex(orderedselection, 0).CeilHeight;
float endlevel = (float)General.GetByIndex(orderedselection, orderedselection.Count - 1).CeilHeight;
float delta = endlevel - startlevel;
// Go for all sectors in between first and last
int index = 0;
foreach(Sector s in orderedselection)
{
float u = (float)index / (float)(orderedselection.Count - 1);
float b = startlevel + delta * u;
s.CeilHeight = (int)b;
index++;
}
}
// Update
General.Interface.RefreshInfo();
General.Map.IsChanged = true;
}
// Change heights
[BeginAction("lowerfloor8")]
public void LowerFloors8()
@ -1292,42 +1289,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Map.IsChanged = true;
}
// Make gradient ceilings
[BeginAction("gradientceilings")]
public void MakeGradientCeilings()
{
General.Interface.DisplayStatus(StatusType.Action, "Created gradient ceiling heights over selected sectors.");
General.Map.UndoRedo.CreateUndo("Gradient ceiling heights");
// Need at least 3 selected sectors
// The first and last are not modified
if(orderedselection.Count > 2)
{
float startlevel = (float)orderedselection[0].CeilHeight;
float endlevel = (float)orderedselection[orderedselection.Count - 1].CeilHeight;
float delta = endlevel - startlevel;
// Go for all sectors in between first and last
for(int i = 1; i < (orderedselection.Count - 1); i++)
{
float u = (float)i / (float)(orderedselection.Count - 1);
float b = startlevel + delta * u;
orderedselection[i].CeilHeight = (int)b;
}
}
// Update
General.Interface.RefreshInfo();
General.Map.IsChanged = true;
}
// This clears the selection
[BeginAction("clearselection", BaseAction = true)]
public void ClearSelection()
{
// Clear selection
General.Map.Map.ClearAllSelected();
orderedselection.Clear();
// Clear labels
foreach(TextLabel[] labelarray in labels.Values)

View file

@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder.Map
private LinkedListNode<Linedef> mainlistitem;
private LinkedListNode<Linedef> startvertexlistitem;
private LinkedListNode<Linedef> endvertexlistitem;
private LinkedListNode<Linedef> selecteditem;
// Vertices
private Vertex start;
@ -446,6 +447,21 @@ namespace CodeImp.DoomBuilder.Map
if(foundactivation) break;
}
}
// Selected
protected override void DoSelect()
{
base.DoSelect();
selecteditem = map.SelectedLinedefs.AddLast(this);
}
// Deselect
protected override void DoUnselect()
{
base.DoUnselect();
if(selecteditem.List != null) selecteditem.List.Remove(selecteditem);
selecteditem = null;
}
#endregion

View file

@ -68,7 +68,13 @@ namespace CodeImp.DoomBuilder.Map
private LinkedList<Sidedef> sidedefs;
private LinkedList<Sector> sectors;
private LinkedList<Thing> things;
// Selected elements
private LinkedList<Vertex> sel_vertices;
private LinkedList<Linedef> sel_linedefs;
private LinkedList<Sector> sel_sectors;
private LinkedList<Thing> sel_things;
// Statics
private static long emptylongname;
private static UniValue virtualsectorvalue;
@ -86,6 +92,11 @@ namespace CodeImp.DoomBuilder.Map
public ICollection<Sector> Sectors { get { return sectors; } }
public ICollection<Thing> Things { get { return things; } }
public bool IsDisposed { get { return isdisposed; } }
internal LinkedList<Vertex> SelectedVertices { get { return sel_vertices; } }
internal LinkedList<Linedef> SelectedLinedefs { get { return sel_linedefs; } }
internal LinkedList<Sector> SelectedSectors { get { return sel_sectors; } }
internal LinkedList<Thing> SelectedThings { get { return sel_things; } }
public static long EmptyLongName { get { return emptylongname; } }
public static string VirtualSectorField { get { return VIRTUAL_SECTOR_FIELD; } }
@ -106,6 +117,10 @@ namespace CodeImp.DoomBuilder.Map
sidedefs = new LinkedList<Sidedef>();
sectors = new LinkedList<Sector>();
things = new LinkedList<Thing>();
sel_vertices = new LinkedList<Vertex>();
sel_linedefs = new LinkedList<Linedef>();
sel_sectors = new LinkedList<Sector>();
sel_things = new LinkedList<Thing>();
indexholes = new List<int>();
lastsectorindex = 0;
@ -122,6 +137,10 @@ namespace CodeImp.DoomBuilder.Map
sidedefs = new LinkedList<Sidedef>();
sectors = new LinkedList<Sector>();
things = new LinkedList<Thing>();
sel_vertices = new LinkedList<Vertex>();
sel_linedefs = new LinkedList<Linedef>();
sel_sectors = new LinkedList<Sector>();
sel_things = new LinkedList<Thing>();
indexholes = new List<int>();
lastsectorindex = 0;
@ -169,6 +188,10 @@ namespace CodeImp.DoomBuilder.Map
sidedefs = null;
sectors = null;
things = null;
sel_vertices = null;
sel_linedefs = null;
sel_sectors = null;
sel_things = null;
indexholes = null;
// Done
@ -861,57 +884,89 @@ namespace CodeImp.DoomBuilder.Map
// This clears selected vertices
public void ClearSelectedVertices()
{
sel_vertices.Clear();
foreach(Vertex v in vertices) v.Selected = false;
}
// This clears selected things
public void ClearSelectedThings()
{
sel_things.Clear();
foreach(Thing t in things) t.Selected = false;
}
// This clears selected linedefs
public void ClearSelectedLinedefs()
{
sel_linedefs.Clear();
foreach(Linedef l in linedefs) l.Selected = false;
}
// This clears selected sectors
public void ClearSelectedSectors()
{
sel_sectors.Clear();
foreach(Sector s in sectors) s.Selected = false;
}
// Returns a collection of vertices that match a selected state
public ICollection<Vertex> GetSelectedVertices(bool selected)
{
List<Vertex> list = new List<Vertex>(things.Count >> 1);
foreach(Vertex v in vertices) if(v.Selected == selected) list.Add(v);
return list;
if(selected)
{
return sel_vertices;
}
else
{
List<Vertex> list = new List<Vertex>(vertices.Count - sel_vertices.Count);
foreach(Vertex v in vertices) if(!v.Selected) list.Add(v);
return list;
}
}
// Returns a collection of things that match a selected state
public ICollection<Thing> GetSelectedThings(bool selected)
{
List<Thing> list = new List<Thing>(things.Count >> 1);
foreach(Thing t in things) if(t.Selected == selected) list.Add(t);
return list;
if(selected)
{
return sel_things;
}
else
{
List<Thing> list = new List<Thing>(things.Count - sel_things.Count);
foreach(Thing t in things) if(!t.Selected) list.Add(t);
return list;
}
}
// Returns a collection of linedefs that match a selected state
public ICollection<Linedef> GetSelectedLinedefs(bool selected)
{
List<Linedef> list = new List<Linedef>(linedefs.Count >> 1);
foreach(Linedef l in linedefs) if(l.Selected == selected) list.Add(l);
return list;
if(selected)
{
return sel_linedefs;
}
else
{
List<Linedef> list = new List<Linedef>(linedefs.Count - sel_linedefs.Count);
foreach(Linedef l in linedefs) if(!l.Selected) list.Add(l);
return list;
}
}
// Returns a collection of sectors that match a selected state
public ICollection<Sector> GetSelectedSectors(bool selected)
{
List<Sector> list = new List<Sector>(sectors.Count >> 1);
foreach(Sector s in sectors) if(s.Selected == selected) list.Add(s);
return list;
if(selected)
{
return sel_sectors;
}
else
{
List<Sector> list = new List<Sector>(sectors.Count - sel_sectors.Count);
foreach(Sector s in sectors) if(!s.Selected) list.Add(s);
return list;
}
}
// This selects geometry based on the marking

View file

@ -46,6 +46,7 @@ namespace CodeImp.DoomBuilder.Map
// List items
private LinkedListNode<Sector> mainlistitem;
private LinkedListNode<Sector> selecteditem;
// Sidedefs
private LinkedList<Sidedef> sidedefs;
@ -449,6 +450,21 @@ namespace CodeImp.DoomBuilder.Map
UpdateFloorSurface();
UpdateCeilingSurface();
}
// Selected
protected override void DoSelect()
{
base.DoSelect();
selecteditem = map.SelectedSectors.AddLast(this);
}
// Deselect
protected override void DoUnselect()
{
base.DoUnselect();
if(selecteditem.List != null) selecteditem.List.Remove(selecteditem);
selecteditem = null;
}
#endregion

View file

@ -47,8 +47,8 @@ namespace CodeImp.DoomBuilder.Map
#endregion
#region ================== Properties
public bool Selected { get { return selected; } set { selected = value; } }
public bool Selected { get { return selected; } set { if(value && !selected) DoSelect(); else if(!value && selected) DoUnselect(); } }
#endregion
@ -64,8 +64,8 @@ namespace CodeImp.DoomBuilder.Map
{
if(!isdisposed)
{
// Clean up
// Remove from selection
if(selected) Selected = false;
// Done
base.Dispose();
@ -75,12 +75,24 @@ namespace CodeImp.DoomBuilder.Map
#endregion
#region ================== Methods
// This makes the selection
protected virtual void DoSelect()
{
selected = true;
}
// This removes the selection
protected virtual void DoUnselect()
{
selected = false;
}
// This copies properties to any other element
new public void CopyPropertiesTo(SelectableElement element)
public void CopyPropertiesTo(SelectableElement element)
{
element.groups = this.groups;
element.selected = this.selected;
element.Selected = this.selected;
base.CopyPropertiesTo(element);
}
@ -99,7 +111,7 @@ namespace CodeImp.DoomBuilder.Map
// This selects by group
public void SelectByGroup(int groupsmask)
{
selected = ((groups & groupsmask) != 0);
this.Selected = ((groups & groupsmask) != 0);
}
#endregion

View file

@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder.Map
// List items
private LinkedListNode<Thing> mainlistitem;
private LinkedListNode<Thing> selecteditem;
// Properties
private int type;
@ -310,6 +311,21 @@ namespace CodeImp.DoomBuilder.Map
}
}
}
// Selected
protected override void DoSelect()
{
base.DoSelect();
selecteditem = map.SelectedThings.AddLast(this);
}
// Deselect
protected override void DoUnselect()
{
base.DoUnselect();
if(selecteditem.List != null) selecteditem.List.Remove(selecteditem);
selecteditem = null;
}
#endregion

View file

@ -47,6 +47,7 @@ namespace CodeImp.DoomBuilder.Map
// List items
private LinkedListNode<Vertex> mainlistitem;
private LinkedListNode<Vertex> selecteditem;
// Position
private Vector2D pos;
@ -158,6 +159,21 @@ namespace CodeImp.DoomBuilder.Map
s.rwVector2D(ref pos);
}
// Selected
protected override void DoSelect()
{
base.DoSelect();
selecteditem = map.SelectedVertices.AddLast(this);
}
// Deselect
protected override void DoUnselect()
{
base.DoUnselect();
if(selecteditem.List != null) selecteditem.List.Remove(selecteditem);
selecteditem = null;
}
#endregion
#region ================== Methods