コード例 #1
0
ファイル: LuaMap.cs プロジェクト: volte/doombuilderx
 public static LuaThing NearestThing(LuaVector2D pos)
 {
     Thing t = MapSet.NearestThing(General.Map.Map.Things, pos.vec);
     if (t == null)
     {
         return null;
     }
     return new LuaThing(t);
 }
コード例 #2
0
        // Constructor to start dragging immediately
        public DragThingsMode(EditMode basemode, Vector2D dragstartmappos, bool makeundo)
        {
            // Initialize
            this.dragstartmappos = dragstartmappos;
            this.basemode        = basemode;
            this.makeundo        = makeundo;      //mxd

            Cursor.Current = Cursors.AppStarting;

            // Mark what we are dragging
            General.Map.Map.ClearAllMarks(false);
            General.Map.Map.MarkSelectedThings(true, true);

            // Get selected things
            selectedthings   = General.Map.Map.GetMarkedThings(true);
            unselectedthings = new List <Thing>();
            foreach (Thing t in General.Map.ThingsFilter.VisibleThings)
            {
                if (!t.Marked)
                {
                    unselectedthings.Add(t);
                }
            }

            // Get the nearest thing for snapping
            dragitem = MapSet.NearestThing(selectedthings, dragstartmappos);

            // Make old positions list
            // We will use this as reference to move the vertices, or to move them back on cancel
            oldpositions = new List <Vector2D>(selectedthings.Count);
            foreach (Thing t in selectedthings)
            {
                oldpositions.Add(t.Position);
            }

            // Also keep old position of the dragged item
            dragitemposition = dragitem.Position;

            //mxd. Get drag offset
            dragstartoffset = General.Map.Grid.SnappedToGrid(dragitem.Position) - dragitemposition;

            // Keep view information
            lastoffsetx = renderer.OffsetX;
            lastoffsety = renderer.OffsetY;
            lastscale   = renderer.Scale;

            Cursor.Current = Cursors.Default;

            // We have no destructor
            GC.SuppressFinalize(this);
        }
コード例 #3
0
        public JitterThingsForm(string editingModeName)
        {
            this.editingModeName = editingModeName;
            this.HelpRequested  += JitterThingsForm_HelpRequested;

            InitializeComponent();

            //have thing height?
            heightJitterAmmount.Enabled = General.Map.FormatInterface.HasThingHeight;
            bUpdateHeight.Enabled       = General.Map.FormatInterface.HasThingHeight;

            //disable pitch/roll/scale?
            if (!General.Map.UDMF)
            {
                pitchAmmount.Enabled    = false;
                rollAmmount.Enabled     = false;
                bUpdatePitch.Enabled    = false;
                bUpdateRoll.Enabled     = false;
                scalegroup.Enabled      = false;
                cbRelativePitch.Enabled = false;
                cbRelativeRoll.Enabled  = false;
                cbNegativePitch.Enabled = false;
                cbNegativeRoll.Enabled  = false;
            }

            //get selection
            selection = new List <Thing>();

            if (editingModeName == "BaseVisualMode")
            {
                visualSelection = ((VisualMode)General.Editing.Mode).GetSelectedVisualThings(false);
                foreach (VisualThing t in visualSelection)
                {
                    selection.Add(t.Thing);
                }
            }
            else
            {
                ICollection <Thing> list = General.Map.Map.GetSelectedThings(true);
                foreach (Thing t in list)
                {
                    selection.Add(t);
                }
            }

            //update window header
            this.Text = "Randomize " + selection.Count + (selection.Count > 1 ? " things" : " thing");

            //store intial properties
            thingData = new List <ThingData>();

            foreach (Thing t in selection)
            {
                ThingData d = new ThingData();

                Thing closest = MapSet.NearestThing(General.Map.Map.Things, t);

                if (closest != null)
                {
                    d.SafeDistance = (int)Math.Round(Vector2D.Distance(t.Position, closest.Position));
                }
                else
                {
                    d.SafeDistance = 512;
                }

                if (d.SafeDistance > 0)
                {
                    d.SafeDistance /= 2;
                }
                if (MaxSafeDistance < d.SafeDistance)
                {
                    MaxSafeDistance = d.SafeDistance;
                }
                d.Position = t.Position;
                d.Angle    = t.AngleDoom;
                d.Pitch    = t.Pitch;
                d.Roll     = t.Roll;
                d.ScaleX   = t.ScaleX;
                d.ScaleY   = t.ScaleY;

                if (General.Map.FormatInterface.HasThingHeight)
                {
                    if (t.Sector == null)
                    {
                        t.DetermineSector();
                    }
                    if (t.Sector != null)
                    {
                        d.SectorHeight = Math.Max(0, t.Sector.CeilHeight - (int)t.Height - t.Sector.FloorHeight);
                        if (MaxSafeHeightDistance < d.SectorHeight)
                        {
                            MaxSafeHeightDistance = d.SectorHeight;
                        }
                        d.ZOffset = (int)t.Position.z;
                    }
                }

                thingData.Add(d);
            }

            positionJitterAmmount.Maximum = MaxSafeDistance;
            heightJitterAmmount.Maximum   = MaxSafeHeightDistance;

            //create undo
            General.Map.UndoRedo.ClearAllRedos();
            General.Map.UndoRedo.CreateUndo("Randomize " + selection.Count + (selection.Count > 1 ? " things" : " thing"));

            //update controls
            UpdateOffsetAngles();
            UpdateHeights();
            UpdateRotationAngles();
            UpdatePitchAngles();
            UpdateRollAngles();
            UpdateScaleX();
            UpdateScaleY();

            //apply settings
            cbRelativeScale.Checked  = relativeScale;
            cbUniformScale.Checked   = uniformScale;
            cbNegativeScaleX.Checked = allowNegativeScaleX;
            cbNegativeScaleY.Checked = allowNegativeScaleY;
            cbRelativePitch.Checked  = relativePitch;
            cbRelativeRoll.Checked   = relativeRoll;
            cbNegativePitch.Checked  = allowNegativePitch;
            cbNegativeRoll.Checked   = allowNegativeRoll;


            //add event listeners
            cbRelativeScale.CheckedChanged  += cbRelativeScale_CheckedChanged;
            cbUniformScale.CheckedChanged   += cbUniformScale_CheckedChanged;
            cbNegativeScaleX.CheckedChanged += cbNegativeScaleX_CheckedChanged;
            cbNegativeScaleY.CheckedChanged += cbNegativeScaleY_CheckedChanged;
            cbRelativePitch.CheckedChanged  += cbRelativePitch_CheckedChanged;
            cbRelativeRoll.CheckedChanged   += cbRelativeRoll_CheckedChanged;
            cbNegativePitch.CheckedChanged  += cbNegativePitch_CheckedChanged;
            cbNegativeRoll.CheckedChanged   += cbNegativeRoll_CheckedChanged;

            //disable controls if necessary
            if (uniformScale)
            {
                cbUniformScale_CheckedChanged(cbUniformScale, EventArgs.Empty);
            }

            //tricky way to actually store undo information...
            foreach (Thing t in selection)
            {
                t.Move(t.Position);
            }
        }
コード例 #4
0
        // Constructor to start dragging immediately
        public DuplicateThingsMode(EditMode basemode, Vector2D dragstartmappos)
        {
            // Initialize
            this.dragstartmappos = dragstartmappos;
            this.basemode        = basemode;

            Cursor.Current = Cursors.AppStarting;

            // Make undo for the dragging
            General.Map.UndoRedo.CreateUndo("Duplicate things");

            // Mark what we are dragging
            General.Map.Map.ClearAllMarks(false);
            General.Map.Map.MarkSelectedThings(true, true);

            // Get selected things
            List <Thing> oldthings = General.Map.Map.GetMarkedThings(true);

            selectedthings = new List <Thing>(oldthings.Count);

            foreach (Thing t in oldthings)
            {
                Thing newt = General.Map.Map.CreateThing();
                t.CopyPropertiesTo(newt);
                t.Selected = false;
                t.Marked   = false;
                selectedthings.Add(newt);
                newt.Marked = true;
                newt.Marked = true;
            }

            unselectedthings = new List <Thing>();
            foreach (Thing t in General.Map.ThingsFilter.VisibleThings)
            {
                if (!t.Marked)
                {
                    unselectedthings.Add(t);
                }
            }

            // Get the nearest thing for snapping
            dragitem = MapSet.NearestThing(selectedthings, dragstartmappos);

            // Make old positions list
            // We will use this as reference to move the vertices, or to move them back on cancel
            oldpositions = new List <Vector2D>(selectedthings.Count);
            foreach (Thing t in selectedthings)
            {
                oldpositions.Add(t.Position);
            }

            // Also keep old position of the dragged item
            dragitemposition = dragitem.Position;

            // Keep view information
            lastoffsetx = renderer.OffsetX;
            lastoffsety = renderer.OffsetY;
            lastscale   = renderer.Scale;

            Cursor.Current = Cursors.Default;

            // We have no destructor
            GC.SuppressFinalize(this);
        }