Ejemplo n.º 1
0
        public void MakeHollow()
        {
            if (_document.Selection.IsEmpty() || _document.Selection.InFaceSelection) return;

            var solids = _document.Selection.GetSelectedObjects().OfType<Solid>().ToList();
            if (!solids.Any()) return;

            if (solids.Count > 1)
            {
                if (MessageBox.Show("This will hollow out every selected solid, are you sure?", "Multiple solids selected", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }
            }

            var qf = new QuickForm("Select wall width") { UseShortcutKeys = true } .NumericUpDown("Wall width (negative to hollow outwards)", -1024, 1024, 0, 32).OkCancel();

            decimal width;
            do
            {
                if (qf.ShowDialog() == DialogResult.Cancel) return;
                width = qf.Decimal("Wall width (negative to hollow outwards)");
                if (width == 0) MessageBox.Show("Please select a non-zero value.");
            } while (width == 0);

            _document.PerformAction("Make objects hollow", new MakeHollow(solids, width));
        }
Ejemplo n.º 2
0
        public void GoToBrushID()
        {
            using (var qf = new QuickForm("Enter Brush ID") { LabelWidth = 100, UseShortcutKeys = true }
                .TextBox("Brush ID")
                .OkCancel())
            {
                qf.ClientSize = new Size(230, qf.ClientSize.Height);

                if (qf.ShowDialog() != DialogResult.OK) return;

                long id;
                if (!long.TryParse(qf.String("Brush ID"), out id)) return;

                var obj = _document.Map.WorldSpawn.FindByID(id);
                if (obj == null) return;

                // Select and go to the brush
                _document.PerformAction("Select brush ID " + id, new ChangeSelection(new[] { obj }, _document.Selection.GetSelectedObjects()));
                ViewportManager.Viewports.ForEach(x => x.FocusOn(obj.BoundingBox));
            }
        }
Ejemplo n.º 3
0
        public void GoToCoordinates()
        {
            using (var qf = new QuickForm("Enter Coordinates") { LabelWidth = 50, UseShortcutKeys = true }
                .TextBox("X", "0")
                .TextBox("Y", "0")
                .TextBox("Z", "0")
                .OkCancel())
            {
                qf.ClientSize = new Size(180, qf.ClientSize.Height);
                if (qf.ShowDialog() != DialogResult.OK) return;

                decimal x, y, z;
                if (!Decimal.TryParse(qf.String("X"), out x)) return;
                if (!Decimal.TryParse(qf.String("Y"), out y)) return;
                if (!Decimal.TryParse(qf.String("Z"), out z)) return;

                var coordinate = new Coordinate(x, y, z);

                ViewportManager.Viewports.ForEach(vp => vp.FocusOn(coordinate));
            }
        }
Ejemplo n.º 4
0
 private void SaveProfileAsButtonClicked(object sender, EventArgs e)
 {
     using (var qf = new QuickForm("Save Build Profile As...").TextBox("Name").OkCancel())
     {
         if (qf.ShowDialog() == DialogResult.OK)
         {
             var name = qf.String("Name");
             if (_build.Profiles.Any(x => String.Equals(name, x.Name, StringComparison.InvariantCultureIgnoreCase)))
             {
                 MessageBox.Show("There is already a profile with that name, please type a unique name.", "Cannot create profile");
                 name = null;
             }
             if (!String.IsNullOrWhiteSpace(name))
             {
                 _profile = SaveAsProfile(name);
                 UpdateProfiles();
             }
         }
     }
 }
Ejemplo n.º 5
0
 private void RenameProfileButtonClicked(object sender, EventArgs e)
 {
     if (_profile == null) return;
     using (var qf = new QuickForm("Rename Build Profile").TextBox("Name", _profile.Name).OkCancel())
     {
         if (qf.ShowDialog() == DialogResult.OK)
         {
             var name = qf.String("Name");
             if (_build.Profiles.Any(x => String.Equals(name, x.Name, StringComparison.InvariantCultureIgnoreCase)))
             {
                 MessageBox.Show("There is already a profile with that name, please type a unique name.", "Cannot rename profile");
                 name = null;
             }
             if (!String.IsNullOrWhiteSpace(name) && _profile.Name != name)
             {
                 _profile.Name = name;
                 SettingsManager.Write();
                 UpdateProfiles();
             }
         }
     }
 }
Ejemplo n.º 6
0
        public void ScreenshotViewport(object parameter)
        {
            var focused = (parameter as ViewportBase) ?? ViewportManager.Viewports.FirstOrDefault(x => x.IsFocused);
            if (focused == null) return;

            var screen = Screen.FromControl(this);
            var area = screen.Bounds;

            using (var qf = new QuickForm("Select screenshot size") {UseShortcutKeys = true}
                .NumericUpDown("Width", 640, 5000, 0, area.Width)
                .NumericUpDown("Height", 480, 5000, 0, area.Height)
                .OkCancel())
            {
                if (qf.ShowDialog() != DialogResult.OK) return;

                var shot = ViewportManager.CreateScreenshot(focused, (int) qf.Decimal("Width"), (int) qf.Decimal("Height"));
                if (shot == null) return;

                var ext = focused is Viewport2D || (focused is Viewport3D && ((Viewport3D)focused).Type != Viewport3D.ViewType.Textured) ? ".png" : ".jpg";

                using (var sfd = new SaveFileDialog())
                {
                    sfd.FileName = "Sledge - "
                                   + (DocumentManager.CurrentDocument != null ? DocumentManager.CurrentDocument.MapFileName : "untitled")
                                   + " - " + DateTime.Now.ToString("yyyy-MM-ddThh-mm-ss") + ext;
                    sfd.Filter = "Image Files (*.png, *.jpg, *.bmp)|*.png;*.jpg;*.bmp";
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        if (sfd.FileName.EndsWith("jpg"))
                        {
                            var encoder = GetJpegEncoder();
                            if (encoder != null)
                            {
                                var p = new EncoderParameter(Encoder.Quality, 90L);
                                var ep = new EncoderParameters(1);
                                ep.Param[0] = p;
                                shot.Save(sfd.FileName, encoder, ep);
                            }
                            else
                            {
                                shot.Save(sfd.FileName);
                            }
                        }
                        else
                        {
                            shot.Save(sfd.FileName);
                        }
                    }
                }
                shot.Dispose();
            }
        }
Ejemplo n.º 7
0
        private void AddPropertyClicked(object sender, EventArgs e)
        {
            if (_changingClass) return;

            using (var qf = new QuickForm("Add Property") { UseShortcutKeys = true }.TextBox("Key").TextBox("Value").OkCancel())
            {
                if (qf.ShowDialog(this) != DialogResult.OK) return;

                var name = qf.String("Key");
                var newName = name;
                var num = 1;
                while (_values.Any(x => String.Equals(x.OriginalKey, newName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    newName = name + "#" + (num++);
                }

                _values.Add(new TableValue
                {
                    Class = Class.Text,
                    OriginalKey = newName,
                    NewKey = newName,
                    Value = qf.String("Value"),
                    IsAdded = true,
                    IsModified = true,
                    IsRemoved = false
                });
                PropertyValueChanged(this, newName, qf.String("Value"));
            }
        }
Ejemplo n.º 8
0
        public void VisgroupCreateNew()
        {
            using (var qf = new QuickForm("Create New Visgroup") {UseShortcutKeys = true}.TextBox("Name").CheckBox("Add selection to visgroup", true).OkCancel())
            {
                if (qf.ShowDialog() != DialogResult.OK) return;

                var ids = _document.Map.Visgroups.Where(x => !x.IsAutomatic).Select(x => x.ID).ToList();
                var id = Math.Max(1, ids.Any() ? ids.Max() + 1 : 1);

                var name = qf.String("Name");
                if (String.IsNullOrWhiteSpace(name)) name = "Visgroup " + id.ToString(CultureInfo.InvariantCulture);

                var vg = new Visgroup
                {
                    ID = id,
                    Colour = Colour.GetRandomLightColour(),
                    Name = name,
                    Visible = true
                };
                IAction action = new CreateEditDeleteVisgroups(new[] {vg}, new Visgroup[0], new Visgroup[0]);
                if (qf.Bool("Add selection to visgroup") && !_document.Selection.IsEmpty())
                {
                    action = new ActionCollection(action, new EditObjectVisgroups(_document.Selection.GetSelectedObjects(), new[] {id}, new int[0]));
                }
                _document.PerformAction("Create visgroup", action);
            }
        }