private void UpdateGeometry() { // Update what must be updated if (editingModeName == "BaseVisualMode") { VisualMode vm = ((VisualMode)General.Editing.Mode); for (int i = 0; i < selection.Count; i++) { visualSelection[i].SetPosition(new Vector3D(selection[i].Position.x, selection[i].Position.y, selection[i].Sector.FloorHeight + selection[i].Position.z)); visualSelection[i].Update(); if (vm.VisualSectorExists(visualSelection[i].Thing.Sector)) { vm.GetVisualSector(visualSelection[i].Thing.Sector).UpdateSectorGeometry(true); } } } else { //update view General.Interface.RedrawDisplay(); } }
public JitterSectorsForm(string editingModeName) { this.editingModeName = editingModeName; InitializeComponent(); //get selection List <Vertex> verts = new List <Vertex>(); List <Sector> sectors = new List <Sector>(); if (editingModeName == "BaseVisualMode") { VisualMode vm = (VisualMode)General.Editing.Mode; List <VisualGeometry> visualGeometry = vm.GetSelectedSurfaces(); visualSectors = new List <VisualSector>(); //get selected visual and regular sectors foreach (VisualGeometry vg in visualGeometry) { if (vg.GeometryType != VisualGeometryType.CEILING && vg.GeometryType != VisualGeometryType.FLOOR) { continue; } if (vg.Sector != null && vg.Sector.Sector != null) { foreach (Sidedef sd in vg.Sector.Sector.Sidedefs) { if (!verts.Contains(sd.Line.Start)) { verts.Add(sd.Line.Start); } if (!verts.Contains(sd.Line.End)) { verts.Add(sd.Line.End); } } sectors.Add(vg.Sector.Sector); visualSectors.Add(vg.Sector); } } //also get visual sectors around selected ones (because they also may be affected) List <Vertex> affectedVerts = new List <Vertex>(); foreach (Sector s in sectors) { foreach (Sidedef sd in s.Sidedefs) { if (!affectedVerts.Contains(sd.Line.Start)) { affectedVerts.Add(sd.Line.Start); } if (!affectedVerts.Contains(sd.Line.End)) { affectedVerts.Add(sd.Line.End); } } } List <Sector> affectedSectors = new List <Sector>(); foreach (Vertex v in affectedVerts) { foreach (Linedef l in v.Linedefs) { if (l.Front != null && !sectors.Contains(l.Front.Sector) && !affectedSectors.Contains(l.Front.Sector) && vm.VisualSectorExists(l.Front.Sector)) { visualSectors.Add(vm.GetVisualSector(l.Front.Sector)); affectedSectors.Add(l.Front.Sector); } if (l.Back != null && !sectors.Contains(l.Back.Sector) && !affectedSectors.Contains(l.Back.Sector) && vm.VisualSectorExists(l.Back.Sector)) { visualSectors.Add(vm.GetVisualSector(l.Back.Sector)); affectedSectors.Add(l.Back.Sector); } } } visualVerts = new List <VisualVertexPair>(); foreach (Vertex vert in affectedVerts) { if (vm.VisualVertices.ContainsKey(vert)) { visualVerts.Add(vm.VisualVertices[vert]); } } } else if (editingModeName == "SectorsMode") { ICollection <Sector> list = General.Map.Map.GetSelectedSectors(true); foreach (Sector s in list) { foreach (Sidedef sd in s.Sidedefs) { if (!verts.Contains(sd.Line.Start)) { verts.Add(sd.Line.Start); } if (!verts.Contains(sd.Line.End)) { verts.Add(sd.Line.End); } } sectors.Add(s); } } if (verts.Count == 0 || sectors.Count == 0) { General.Interface.DisplayStatus(StatusType.Warning, "Unable to get sectors from selection!"); return; } //create undo General.Map.UndoRedo.ClearAllRedos(); General.Map.UndoRedo.CreateUndo("Randomize " + sectors.Count + (sectors.Count > 1 ? " sectors" : " sector")); //update window header this.Text = "Randomize " + sectors.Count + (sectors.Count > 1 ? " sectors" : " sector"); //store intial properties //process verts... Dictionary <Vertex, TranslationOffsetVertexData> data = new Dictionary <Vertex, TranslationOffsetVertexData>(); foreach (Vertex v in verts) { TranslationOffsetVertexData vd = new TranslationOffsetVertexData(); vd.Vertex = v; vd.InitialPosition = v.Position; data.Add(v, vd); } foreach (Vertex v in verts) { if (v.Linedefs == null) { continue; } //get nearest linedef Linedef closestLine = null; double distance = double.MaxValue; // Go for all linedefs in selection foreach (Linedef l in General.Map.Map.Linedefs) { if (v.Linedefs.Contains(l)) { continue; } // Calculate distance and check if closer than previous find double d = l.SafeDistanceToSq(v.Position, true); if (d < distance) { // This one is closer closestLine = l; distance = d; } } if (closestLine == null) { continue; } double closestLineDistance = Vector2D.Distance(v.Position, closestLine.NearestOnLine(v.Position)); //check SafeDistance of closest line if (data.ContainsKey(closestLine.Start) && data[closestLine.Start].SafeDistance > closestLineDistance) { TranslationOffsetVertexData vd = data[closestLine.Start]; vd.SafeDistance = (int)Math.Floor(closestLineDistance); data[closestLine.Start] = vd; } if (data.ContainsKey(closestLine.End) && data[closestLine.End].SafeDistance > closestLineDistance) { TranslationOffsetVertexData vd = data[closestLine.End]; vd.SafeDistance = (int)Math.Floor(closestLineDistance); data[closestLine.End] = vd; } //save SafeDistance int dist = (int)Math.Floor(closestLineDistance); if (data[v].SafeDistance == 0 || data[v].SafeDistance > dist) { TranslationOffsetVertexData vd = data[v]; vd.SafeDistance = dist; data[v] = vd; } } //store properties vertexData = new TranslationOffsetVertexData[data.Values.Count]; data.Values.CopyTo(vertexData, 0); for (int i = 0; i < data.Count; i++) { if (vertexData[i].SafeDistance > 0) { vertexData[i].SafeDistance /= 2; } if (MaxSafeDistance < vertexData[i].SafeDistance) { MaxSafeDistance = vertexData[i].SafeDistance; } } //process sectors and linedes sectorData = new List <SectorData>(); sidedefData = new List <SidedefData>(); foreach (Sector s in sectors) { SectorData sd = new SectorData(); sd.Sector = s; sd.InitialCeilingHeight = s.CeilHeight; sd.InitialFloorHeight = s.FloorHeight; sd.Triangular = General.Map.UDMF && s.Sidedefs.Count == 3; if (sd.Triangular) { Vertex[] sectorverts = GetSectorVerts(s); sd.Verts = new HeightOffsetVertexData[sectorverts.Length]; for (int i = 0; i < sectorverts.Length; i++) { HeightOffsetVertexData vd = new HeightOffsetVertexData(); vd.Vertex = sectorverts[i]; vd.ZFloor = sectorverts[i].ZFloor; vd.ZCeiling = sectorverts[i].ZCeiling; vd.InitialFloorHeight = double.IsNaN(vd.ZFloor) ? GetHighestFloor(sectorverts[i]) : sectorverts[i].ZFloor; vd.InitialCeilingHeight = double.IsNaN(vd.ZCeiling) ? GetLowestCeiling(sectorverts[i]) : sectorverts[i].ZCeiling; sd.Verts[i] = vd; } } sd.SafeDistance = (s.CeilHeight - s.FloorHeight) / 2; if (sd.SafeDistance > MaxSafeHeightDistance) { MaxSafeHeightDistance = sd.SafeDistance; } sectorData.Add(sd); foreach (Sidedef side in s.Sidedefs) { //store initial sidedef properties SidedefData sdd = new SidedefData(); sdd.Side = side; sdd.LowTexture = side.LowTexture; sdd.HighTexture = side.HighTexture; sdd.PegBottom = side.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag); sdd.PegTop = side.Line.IsFlagSet(General.Map.Config.UpperUnpeggedFlag); if (side.Other != null && !sectors.Contains(side.Other.Sector)) { sdd.UpdateTextureOnOtherSide = true; sdd.OtherHighTexture = side.Other.HighTexture; sdd.OtherLowTexture = side.Other.LowTexture; } sidedefData.Add(sdd); } } positionJitterAmmount.Maximum = MaxSafeDistance; floorHeightAmmount.Maximum = MaxSafeHeightDistance; ceilingHeightAmmount.Maximum = MaxSafeHeightDistance; //set editing settings cbKeepExistingTextures.Checked = keepExistingSideTextures; ceiloffsetmode.SelectedIndex = storedceiloffsetmode; flooroffsetmode.SelectedIndex = storedflooroffsetmode; //vertex heights can not be set in non-UDMF maps if (General.Map.UDMF) { cbUseFloorVertexHeights.Checked = useFloorVertexHeights; cbUseCeilingVertexHeights.Checked = useCeilingVertexHeights; } else { useFloorVertexHeights = false; cbUseFloorVertexHeights.Checked = false; cbUseFloorVertexHeights.Enabled = false; useCeilingVertexHeights = false; cbUseCeilingVertexHeights.Checked = false; cbUseCeilingVertexHeights.Enabled = false; } //texture pickers textureLower.Initialize(); textureUpper.Initialize(); //We can't use floor/ceiling textures when MixTexturesFlats is disabled if (General.Map.Config.MixTexturesFlats) { textureLower.TextureName = General.Settings.DefaultFloorTexture; textureUpper.TextureName = General.Settings.DefaultCeilingTexture; } else { textureLower.TextureName = General.Settings.DefaultTexture; textureUpper.TextureName = General.Settings.DefaultTexture; cbUpperTexStyle.Items[1] = "Use default texture"; cbLowerTexStyle.Items[1] = "Use default texture"; } cbUpperTexStyle.SelectedIndex = 0; cbLowerTexStyle.SelectedIndex = 0; UpdateTextureSelectors(); //update interface //create random values UpdateAngles(); UpdateFloorHeights(); UpdateCeilingHeights(); }
public JitterVerticesForm(string editingModeName) { this.editingModeName = editingModeName; this.HelpRequested += JitterVerticesForm_HelpRequested; InitializeComponent(); //get selection selection = new List <Vertex>(); if (editingModeName == "BaseVisualMode") { VisualMode vm = (VisualMode)General.Editing.Mode; List <VisualGeometry> visualSelection = vm.GetSelectedSurfaces(); visualSectors = new List <VisualSector>(); int linesCount = 0; foreach (VisualGeometry vg in visualSelection) { if (vg.Sidedef != null && vm.VisualSectorExists(vg.Sidedef.Sector)) { if (!selection.Contains(vg.Sidedef.Line.Start)) { selection.Add(vg.Sidedef.Line.Start); } if (!selection.Contains(vg.Sidedef.Line.End)) { selection.Add(vg.Sidedef.Line.End); } linesCount++; visualSectors.Add(vm.GetVisualSector(vg.Sidedef.Sector)); if (vg.Sidedef.Other != null && vg.Sidedef.Other.Sector != null && vm.VisualSectorExists(vg.Sidedef.Other.Sector)) { visualSectors.Add(vm.GetVisualSector(vg.Sidedef.Other.Sector)); } } } visualVerts = new List <VisualVertexPair>(); foreach (Vertex vert in selection) { if (vm.VisualVertices.ContainsKey(vert)) { visualVerts.Add(vm.VisualVertices[vert]); } } //update window header this.Text = "Randomize " + linesCount + (linesCount > 1 ? " linedefs" : " linedef"); } else if (editingModeName == "LinedefsMode") { ICollection <Linedef> list = General.Map.Map.GetSelectedLinedefs(true); int linesCount = 0; foreach (Linedef l in list) { if (!selection.Contains(l.Start)) { selection.Add(l.Start); } if (!selection.Contains(l.End)) { selection.Add(l.End); } linesCount++; } //update window header this.Text = "Randomize " + linesCount + (linesCount > 1 ? " linedefs" : " linedef"); } else { ICollection <Vertex> list = General.Map.Map.GetSelectedVertices(true); foreach (Vertex v in list) { selection.Add(v); } //update window header this.Text = "Randomize " + selection.Count + (selection.Count > 1 ? " vertices" : " vertex"); } if (selection.Count == 0) { General.Interface.DisplayStatus(StatusType.Warning, "Unable to get vertices from selection!"); return; } //create undo General.Map.UndoRedo.ClearAllRedos(); General.Map.UndoRedo.CreateUndo("Randomize " + selection.Count + (selection.Count > 1 ? " vertices" : " vertex")); Dictionary <Vertex, VertexData> data = new Dictionary <Vertex, VertexData>(); foreach (Vertex v in selection) { VertexData vd = new VertexData { Position = v.Position }; data.Add(v, vd); } foreach (Vertex v in selection) { if (v.Linedefs == null) { continue; } //get nearest linedef Linedef closestLine = null; float distance = float.MaxValue; // Go for all linedefs in selection foreach (Linedef l in General.Map.Map.Linedefs) { if (v.Linedefs.Contains(l)) { continue; } // Calculate distance and check if closer than previous find float d = l.SafeDistanceToSq(v.Position, true); if (d < distance) { // This one is closer closestLine = l; distance = d; } } if (closestLine == null) { continue; } float closestLineDistance = Vector2D.Distance(v.Position, closestLine.NearestOnLine(v.Position)); //check SafeDistance of closest line if (data.ContainsKey(closestLine.Start) && data[closestLine.Start].SafeDistance > closestLineDistance) { VertexData vd = data[closestLine.Start]; vd.SafeDistance = (int)Math.Floor(closestLineDistance); data[closestLine.Start] = vd; } if (data.ContainsKey(closestLine.End) && data[closestLine.End].SafeDistance > closestLineDistance) { VertexData vd = data[closestLine.End]; vd.SafeDistance = (int)Math.Floor(closestLineDistance); data[closestLine.End] = vd; } //save SafeDistance int dist = (int)Math.Floor(closestLineDistance); if (data[v].SafeDistance == 0 || data[v].SafeDistance > dist) { VertexData vd = data[v]; vd.SafeDistance = dist; data[v] = vd; } } //store properties vertexData = new VertexData[data.Values.Count]; data.Values.CopyTo(vertexData, 0); for (int i = 0; i < vertexData.Length; i++) { if (vertexData[i].SafeDistance > 0) { vertexData[i].SafeDistance /= 2; } if (MaxSafeDistance < vertexData[i].SafeDistance) { MaxSafeDistance = vertexData[i].SafeDistance; } } positionJitterAmmount.Maximum = MaxSafeDistance; UpdateAngles(); }
public bool Setup(string editingModeName) { mode = editingModeName; if (mode == "SectorsMode") { selection = (List <Sector>)(General.Map.Map.GetSelectedSectors(true)); } else //should be Visual mode { selection = new List <Sector>(); VisualMode vm = (VisualMode)General.Editing.Mode; visualSelection = vm.GetSelectedVisualSectors(false); if (visualSelection.Count > 0) { foreach (VisualSector vs in visualSelection) { selection.Add(vs.Sector); } } else //should be some sectors selected in 2d-mode... { visualSelection = new List <VisualSector>(); selection = (List <Sector>)(General.Map.Map.GetSelectedSectors(true)); foreach (Sector s in selection) { if (vm.VisualSectorExists(s)) { visualSelection.Add(vm.GetVisualSector(s)); } } } } //create undo string rest = selection.Count + " sector" + (selection.Count > 1 ? "s" : ""); General.Map.UndoRedo.CreateUndo("Edit color of " + rest); foreach (Sector s in selection) { s.Fields.BeforeFieldsChange(); } //set colors curSectorColor = selection[0].Fields.GetValue("lightcolor", DEFAULT_LIGHT_COLOR); curFadeColor = selection[0].Fields.GetValue("fadecolor", DEFAULT_FADE_COLOR); //check that all sectors in selection have "lightcolor" and "fadecolor" fields for (int i = 0; i < selection.Count; i++) { if (!selection[i].Fields.ContainsKey("lightcolor")) { selection[i].Fields.Add("lightcolor", new UniValue(UniversalType.Color, curSectorColor)); } if (!selection[i].Fields.ContainsKey("fadecolor")) { selection[i].Fields.Add("fadecolor", new UniValue(UniversalType.Color, curFadeColor)); } } initialSectorColor = curSectorColor; initialFadeColor = curFadeColor; InitializeComponent(); colorPickerControl1.Initialize(Color.FromArgb(currentColorTag == "lightcolor" ? curSectorColor : curFadeColor)); colorPickerControl1.OnColorChanged += OnColorPickerControl1OnColorChanged; colorPickerControl1.OnOkPressed += colorPickerControl1_OnOkPressed; colorPickerControl1.OnCancelPressed += colorPickerControl1_OnCancelPressed; if (currentColorTag == "lightcolor") { rbSectorColor.Checked = true; } else { rbFadeColor.Checked = true; } rbSectorColor.CheckedChanged += rbColor_CheckedChanged; rbFadeColor.CheckedChanged += rbColor_CheckedChanged; Text = "Editing " + rest; //cannot fail here :) return(true); }