// Flood-fill textures
        public virtual void OnTextureFloodfill()
        {
            if (BuilderPlug.Me.CopiedTexture != null)
            {
                string oldtexture     = GetTextureName();
                long   oldtexturelong = Lump.MakeLongName(oldtexture);
                string newtexture     = BuilderPlug.Me.CopiedTexture;
                if (newtexture != oldtexture)
                {
                    mode.CreateUndo("Flood-fill textures with " + newtexture);
                    mode.SetActionResult("Flood-filled textures with " + newtexture + ".");

                    mode.Renderer.SetCrosshairBusy(true);
                    General.Interface.RedrawDisplay();

                    // Get the texture
                    ImageData newtextureimage = General.Map.Data.GetTextureImage(newtexture);
                    if (newtextureimage != null)
                    {
                        if (mode.IsSingleSelection)
                        {
                            // Clear all marks, this will align everything it can
                            General.Map.Map.ClearMarkedSidedefs(false);
                        }
                        else
                        {
                            // Limit the alignment to selection only
                            General.Map.Map.ClearMarkedSidedefs(true);
                            List <Sidedef> sides = mode.GetSelectedSidedefs();
                            foreach (Sidedef sd in sides)
                            {
                                sd.Marked = false;
                            }
                        }

                        // Do the alignment
                        Tools.FloodfillTextures(this.Sidedef, oldtexturelong, newtextureimage, false);

                        // Get the changed sidedefs
                        List <Sidedef> changes = General.Map.Map.GetMarkedSidedefs(true);
                        foreach (Sidedef sd in changes)
                        {
                            // Update the parts for this sidedef!
                            if (mode.VisualSectorExists(sd.Sector))
                            {
                                BaseVisualSector   vs    = (mode.GetVisualSector(sd.Sector) as BaseVisualSector);
                                VisualSidedefParts parts = vs.GetSidedefParts(sd);
                                parts.SetupAllParts();
                            }
                        }

                        General.Map.Data.UpdateUsedTextures();
                        mode.Renderer.SetCrosshairBusy(false);
                        mode.ShowTargetInfo();
                    }
                }
            }
        }
Example #2
0
        // This updates this virtual the sector and neightbours if needed
        public void UpdateSectorGeometry(bool includeneighbours)
        {
            if (isupdating)
            {
                return;
            }

            isupdating = true;
            changed    = true;

            // Not sure what from this part we need, so commented out for now
            SectorData data = GetSectorData();

            data.Reset();

            // Update sectors that rely on this sector
            foreach (KeyValuePair <Sector, bool> s in data.UpdateAlso)
            {
                if (mode.VisualSectorExists(s.Key))
                {
                    BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(s.Key);
                    vs.UpdateSectorGeometry(s.Value);
                }
            }

            // Go for all things in this sector
            foreach (Thing t in General.Map.Map.Things)
            {
                if (t.Sector == this.Sector)
                {
                    if (mode.VisualThingExists(t))
                    {
                        // Update thing
                        BaseVisualThing vt = (mode.GetVisualThing(t) as BaseVisualThing);
                        vt.Changed = true;
                    }
                }
            }

            if (includeneighbours)
            {
                // Also rebuild surrounding sectors, because outside sidedefs may need to be adjusted
                foreach (Sidedef sd in this.Sector.Sidedefs)
                {
                    if (sd.Other != null)
                    {
                        if (mode.VisualSectorExists(sd.Other.Sector))
                        {
                            BaseVisualSector bvs = (BaseVisualSector)mode.GetVisualSector(sd.Other.Sector);
                            bvs.Changed = true;
                        }
                    }
                }
            }

            isupdating = false;
        }
Example #3
0
        // This resets this sector data and all sectors that require updating after me
        public void Reset()
        {
            if (isupdating)
            {
                return;
            }

            isupdating = true;

            // This is set to false so that this sector is rebuilt the next time it is needed!
            updated = false;

            // The visual sector associated is now outdated
            if (mode.VisualSectorExists(sector))
            {
                BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(sector);
                vs.UpdateSectorGeometry(false);
            }

            // Also reset the sectors that depend on this sector
            foreach (KeyValuePair <Sector, bool> s in updatesectors)
            {
                SectorData sd = mode.GetSectorData(s.Key);
                sd.Reset();
            }

            isupdating = false;
        }
Example #4
0
        // Raise/lower thing
        public virtual void OnChangeTargetHeight(int amount)
        {
            if (General.Map.FormatInterface.HasThingHeight)
            {
                if ((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket))
                {
                    undoticket = mode.CreateUndo("Change thing height");
                }

                Thing.Move(Thing.Position + new Vector3D(0.0f, 0.0f, (float)amount));

                mode.SetActionResult("Changed thing height to " + Thing.Position.z + ".");

                // Update what must be updated
                ThingData td = mode.GetThingData(this.Thing);
                foreach (KeyValuePair <Sector, bool> s in td.UpdateAlso)
                {
                    if (mode.VisualSectorExists(s.Key))
                    {
                        BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(s.Key);
                        vs.UpdateSectorGeometry(s.Value);
                    }
                }

                this.Changed = true;
            }
        }
        public static void ApplySlope(SectorLevel level, Plane plane, BaseVisualMode mode)
        {
            bool applytoceiling = false;

            Vector2D center = new Vector2D(level.sector.BBox.X + level.sector.BBox.Width / 2,
                                           level.sector.BBox.Y + level.sector.BBox.Height / 2);

            if (level.extrafloor)
            {
                // The top side of 3D floors is the ceiling of the sector, but it's a "floor" in UDB, so the
                // ceiling of the control sector has to be modified
                if (level.type == SectorLevelType.Floor)
                {
                    applytoceiling = true;
                }
            }
            else
            {
                if (level.type == SectorLevelType.Ceiling)
                {
                    applytoceiling = true;
                }
            }

            if (applytoceiling)
            {
                Plane downplane = plane.GetInverted();
                level.sector.CeilSlope       = downplane.Normal;
                level.sector.CeilSlopeOffset = downplane.Offset;
                level.sector.CeilHeight      = (int)new Plane(level.sector.CeilSlope, level.sector.CeilSlopeOffset).GetZ(center);
            }
            else
            {
                level.sector.FloorSlope       = plane.Normal;
                level.sector.FloorSlopeOffset = plane.Offset;
                level.sector.FloorHeight      = (int)new Plane(level.sector.FloorSlope, level.sector.FloorSlopeOffset).GetZ(center);
            }

            // Rebuild sector
            BaseVisualSector vs;

            if (mode.VisualSectorExists(level.sector))
            {
                vs = (BaseVisualSector)mode.GetVisualSector(level.sector);
            }
            else
            {
                vs = mode.CreateBaseVisualSector(level.sector);
            }

            if (vs != null)
            {
                vs.UpdateSectorGeometry(true);
            }
        }
Example #6
0
        public static void ApplySlope(SectorLevel level, Plane plane, BaseVisualMode mode)
        {
            bool applytoceiling = false;
            bool reset          = false;
            int  height         = 0;


            Vector2D center = new Vector2D(level.sector.BBox.X + level.sector.BBox.Width / 2,
                                           level.sector.BBox.Y + level.sector.BBox.Height / 2);

            if (level.extrafloor)
            {
                // The top side of 3D floors is the ceiling of the sector, but it's a "floor" in UDB, so the
                // ceiling of the control sector has to be modified
                if (level.type == SectorLevelType.Floor)
                {
                    applytoceiling = true;
                }
            }
            else
            {
                if (level.type == SectorLevelType.Ceiling)
                {
                    applytoceiling = true;
                }
            }

            // If the plane horizontal remove the slope and set the sector height instead
            // Rounding errors can result in offsets of horizontal planes to be a tiny, tiny bit off a whole number,
            // assume we want to remove the plane in this case
            double diff = Math.Abs(Math.Round(plane.d) - plane.d);

            if (plane.Normal.z == 1.0 && diff < 0.000000001)
            {
                reset  = true;
                height = -Convert.ToInt32(plane.d);
            }

            if (applytoceiling)
            {
                if (reset)
                {
                    level.sector.CeilHeight      = height;
                    level.sector.CeilSlope       = new Vector3D();
                    level.sector.CeilSlopeOffset = double.NaN;
                }
                else
                {
                    Plane downplane = plane.GetInverted();
                    level.sector.CeilSlope       = downplane.Normal;
                    level.sector.CeilSlopeOffset = downplane.Offset;
                }
            }
            else
            {
                if (reset)
                {
                    level.sector.FloorHeight      = height;
                    level.sector.FloorSlope       = new Vector3D();
                    level.sector.FloorSlopeOffset = double.NaN;
                }
                else
                {
                    level.sector.FloorSlope       = plane.Normal;
                    level.sector.FloorSlopeOffset = plane.Offset;
                }
            }

            // Rebuild sector
            BaseVisualSector vs;

            if (mode.VisualSectorExists(level.sector))
            {
                vs = (BaseVisualSector)mode.GetVisualSector(level.sector);
            }
            else
            {
                vs = mode.CreateBaseVisualSector(level.sector);
            }

            if (vs != null)
            {
                vs.UpdateSectorGeometry(true);
            }
        }
Example #7
0
        // Flood-fill textures
        public virtual void OnTextureFloodfill()
        {
            if (BuilderPlug.Me.CopiedFlat != null)
            {
                string oldtexture     = GetTextureName();
                long   oldtexturelong = Lump.MakeLongName(oldtexture);
                string newtexture     = BuilderPlug.Me.CopiedFlat;
                if (newtexture != oldtexture)
                {
                    // Get the texture
                    ImageData newtextureimage = General.Map.Data.GetFlatImage(newtexture);
                    if (newtextureimage != null)
                    {
                        bool fillceilings = (this is VisualCeiling);

                        if (fillceilings)
                        {
                            mode.CreateUndo("Flood-fill ceilings with " + newtexture);
                            mode.SetActionResult("Flood-filled ceilings with " + newtexture + ".");
                        }
                        else
                        {
                            mode.CreateUndo("Flood-fill floors with " + newtexture);
                            mode.SetActionResult("Flood-filled floors with " + newtexture + ".");
                        }

                        mode.Renderer.SetCrosshairBusy(true);
                        General.Interface.RedrawDisplay();

                        if (mode.IsSingleSelection)
                        {
                            // Clear all marks, this will align everything it can
                            General.Map.Map.ClearMarkedSectors(false);
                        }
                        else
                        {
                            // Limit the alignment to selection only
                            General.Map.Map.ClearMarkedSectors(true);
                            List <Sector> sectors = mode.GetSelectedSectors();
                            foreach (Sector s in sectors)
                            {
                                s.Marked = false;
                            }
                        }

                        // Do the fill
                        Tools.FloodfillFlats(this.Sector.Sector, fillceilings, oldtexturelong, newtextureimage, false);

                        // Get the changed sectors
                        List <Sector> changes = General.Map.Map.GetMarkedSectors(true);
                        foreach (Sector s in changes)
                        {
                            // Update the visual sector
                            if (mode.VisualSectorExists(s))
                            {
                                BaseVisualSector vs = (mode.GetVisualSector(s) as BaseVisualSector);
                                if (fillceilings)
                                {
                                    vs.Ceiling.Setup();
                                }
                                else
                                {
                                    vs.Floor.Setup();
                                }
                            }
                        }

                        General.Map.Data.UpdateUsedTextures();
                        mode.Renderer.SetCrosshairBusy(false);
                        mode.ShowTargetInfo();
                    }
                }
            }
        }