Esempio n. 1
0
        public override void OnActionBegin(CodeImp.DoomBuilder.Actions.Action action)
        {
            base.OnActionBegin(action);

            string[] monitoractions =
            {
                "buildermodes_raisesector8", "buildermodes_lowersector8", "buildermodes_raisesector1",
                "buildermodes_lowersector1", "builder_visualedit",        "builder_classicedit"
            };

            if (General.Editing.Mode is SlopeMode)
            {
                return;
            }

            if (monitoractions.Contains(action.Name))
            {
                updateafteraction     = true;
                updateafteractionname = action.Name;
            }
            //else
            //	updateafteraction = false;
        }
Esempio n. 2
0
        public override void OnActionEnd(CodeImp.DoomBuilder.Actions.Action action)
        {
            base.OnActionEnd(action);

            if (!updateafteraction && action.Name != updateafteractionname)
            {
                return;
            }

            updateafteraction = false;

            Dictionary <SlopeVertexGroup, int> updatesvgs = new Dictionary <SlopeVertexGroup, int>();

            // Find SVGs that needs to be updated, and change the SV z positions
            foreach (SlopeVertexGroup svg in slopevertexgroups)
            {
                bool update = false;
                Dictionary <int, List <Sector> > newheights = new Dictionary <int, List <Sector> >();

                foreach (Sector s in svg.Sectors)
                {
                    if (s.Fields == null)
                    {
                        continue;
                    }

                    if ((svg.SectorPlanes[s] & PlaneType.Floor) == PlaneType.Floor)
                    {
                        if (s.Fields.ContainsKey("user_floorplane_id") && s.Fields.GetValue("user_floorplane_id", -1) == svg.Id)
                        {
                            if (svg.Height != s.FloorHeight)
                            {
                                int diff = s.FloorHeight - svg.Height;

                                if (!newheights.ContainsKey(diff))
                                {
                                    newheights.Add(diff, new List <Sector>()
                                    {
                                        s
                                    });
                                }
                                else
                                {
                                    newheights[diff].Add(s);
                                }

                                update = true;
                                //break;
                            }
                        }
                    }

                    if ((svg.SectorPlanes[s] & PlaneType.Ceiling) == PlaneType.Ceiling)
                    {
                        if (s.Fields.ContainsKey("user_ceilingplane_id") && s.Fields.GetValue("user_ceilingplane_id", -1) == svg.Id)
                        {
                            if (svg.Height != s.CeilHeight)
                            {
                                int diff = s.CeilHeight - svg.Height;

                                if (!newheights.ContainsKey(diff))
                                {
                                    newheights.Add(diff, new List <Sector>()
                                    {
                                        s
                                    });
                                }
                                else
                                {
                                    newheights[diff].Add(s);
                                }

                                update = true;
                                //break;
                            }
                        }
                    }
                }

                // Debug.WriteLine(String.Format("floordiff: {0} / ceilingdiff: {1} / height: {2}", floordiff, ceilingdiff, svg.Height));

                if (update)
                {
                    if (newheights.Count > 1)
                    {
                        Debug.WriteLine(String.Format("Slope: multiple new heights, doing nothing. Your map is f****d!"));
                    }
                    else if (!updatesvgs.ContainsKey(svg))
                    {
                        updatesvgs.Add(svg, newheights.First().Key);
                    }
                }
            }

            // Update the slopes, and also update the view if in visual mode
            foreach (SlopeVertexGroup svg in updatesvgs.Keys)
            {
                foreach (SlopeVertex sv in svg.Vertices)
                {
                    sv.Z += updatesvgs[svg];
                }

                svg.ComputeHeight();

                foreach (Sector s in svg.Sectors)
                {
                    UpdateSlopes(s);
                }

                // Save the updated data in the sector
                svg.StoreInSector(slopedatasector);

                if (General.Editing.Mode is BaseVisualMode)
                {
                    List <Sector>       sectors       = new List <Sector>();
                    List <VisualSector> visualsectors = new List <VisualSector>();
                    BaseVisualMode      mode          = ((BaseVisualMode)General.Editing.Mode);

                    foreach (Sector s in svg.Sectors)
                    {
                        sectors.Add(s);

                        // Get neighbouring sectors and add them to the list
                        foreach (Sidedef sd in s.Sidedefs)
                        {
                            if (sd.Other != null && !sectors.Contains(sd.Other.Sector))
                            {
                                sectors.Add(sd.Other.Sector);
                            }
                        }
                    }

                    foreach (Sector s in svg.TaggedSectors)
                    {
                        if (!sectors.Contains(s))
                        {
                            sectors.Add(s);
                        }

                        // Get neighbouring sectors and add them to the list
                        foreach (Sidedef sd in s.Sidedefs)
                        {
                            if (sd.Other != null && !sectors.Contains(sd.Other.Sector))
                            {
                                sectors.Add(sd.Other.Sector);
                            }
                        }
                    }

                    foreach (Sector s in sectors)
                    {
                        visualsectors.Add(mode.GetVisualSector(s));
                    }

                    foreach (VisualSector vs in visualsectors)
                    {
                        vs.UpdateSectorGeometry(true);
                    }
                    foreach (VisualSector vs in visualsectors)
                    {
                        vs.UpdateSectorData();
                    }
                }
            }
        }