Exemplo n.º 1
0
        /// <summary>
        /// Creates a new layer.
        /// </summary>
        public void NewLayer()
        {
            using (var dialog = new DialogLayer())
            {
                var result = dialog.ShowDialog();
                if (result != DialogResult.OK) return;

                var name = dialog.LayerName;
                var opacity = dialog.LayerOpacity;
                var visible = dialog.LayerVisible;

                if (CheckLayer(name))
                {
                    MessageBox.Show(@"A layer with this name already exists.", @"New Layer");
                    return;
                }

                using (UndoRedoArea.Start("New Layer"))
                {
                    var layer = new EditorTileLayer(name, opacity, visible);

                    Layers.Add(layer);

                    if (LayerAdded != null)
                        LayerAdded.Invoke(this, new LayerAddedEventArgs(layer));

                    SelectLayer(layer.Name);

                    UnsavedChanges = true;

                    UndoRedoArea.Commit();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Duplicates the currently selected layer.
        /// </summary>
        public void DuplicateLayer()
        {
            using (UndoRedoArea.Start("Duplicated Layer"))
            {
                var newLayer = SelectedLayer.Clone();
                newLayer.Name += " Copy";

                using (var dialog = new DialogLayer(newLayer.Name, newLayer.Opacity, newLayer.Visible))
                {
                    var result = dialog.ShowDialog();
                    if (result != DialogResult.OK) return;

                    var name = dialog.LayerName;
                    var opacity = dialog.LayerOpacity;
                    var visible = dialog.LayerVisible;

                    if (CheckLayer(name))
                    {
                        MessageBox.Show(@"A layer with this name already exists.", @"Duplicate Layer");
                        return;
                    }

                    newLayer.Name = name;
                    newLayer.Opacity = opacity;
                    newLayer.Visible = visible;

                    var index = Layers.IndexOf(SelectedLayer);
                    Layers.Insert(index + 1, newLayer);

                    if (LayerAdded != null)
                        LayerAdded.Invoke(this, new LayerAddedEventArgs(newLayer));

                    SelectLayer(newLayer.Name);

                    UnsavedChanges = true;
                }

                UndoRedoArea.Commit();
            }
        }