예제 #1
0
        public void SelectEditor(ItemEditor editor)
        {
            LayerEditor parentLayer = editor.ParentLayer;

            editor.IsSelected = true;

            ActiveLayer = parentLayer;
        }
예제 #2
0
        public void MoveItemToLayer(ItemEditor itemToMove, LayerEditor layer, ItemEditor itemToMoveNewItemUnder)
        {
            int insertPosition = itemToMoveNewItemUnder == null ? 0 : layer.Items.IndexOf(itemToMoveNewItemUnder);

            itemToMove.ParentLayer.Items.Remove(itemToMove);

            layer.Items.Insert(insertPosition, itemToMove);

            itemToMove.ParentLayer = layer;
        }
예제 #3
0
        public void SelectLayer(LayerEditor layer)
        {
            if (Level.SelectedEditors.Any( ))
            {
                Level.ClearSelectedEditors( );
            }

            setActiveLayerIfItsDifferent(layer);

            tryFire(() => SelectionChanged, (ITreeItem)layer);
        }
예제 #4
0
 public void MoveLayerDown(LayerEditor layer)
 {
     _memento.Record(@"Move Up Layer '{0}'".FormatWith(layer.Name), () =>
     {
         int index               = Level.Layers.IndexOf(layer);
         Level.Layers[index]     = Level.Layers[index + 1];
         Level.Layers[index + 1] = layer;
         tryFire(() => ItemsRearrangedInLayer, (ITreeItem)layer);
         SelectLayer(layer);
     });
 }
예제 #5
0
        public void DeleteLayer(LayerEditor layer)
        {
            _memento.Record(@"Delete Layer '{0}'".FormatWith(layer.Name), () => Level.Layers.Remove(layer));

            tryFire(() => ItemsAddedOrRemoved, (ITreeItem)layer);

            LayerEditor nextChoiceOfLayerToSelect = Level.Layers.Count > 0 ? Level.Layers.Last( ) : null;

            if (nextChoiceOfLayerToSelect != null)
            {
                setActiveLayerIfItsDifferent(nextChoiceOfLayerToSelect);
            }
        }
예제 #6
0
        public void MoveSelectedIditorsToLayer(LayerEditor chosenLayer)
        {
            var selected = SelectedEditors.ToList(  );

            foreach (var eachSelectedEditor in selected)
            {
                ActiveLayer.RemoveEditor(eachSelectedEditor);

                eachSelectedEditor.ParentLayer = chosenLayer;

                chosenLayer.AddEditor(eachSelectedEditor);
            }
        }
예제 #7
0
        public void MoveSelectedItemsToLayer(LayerEditor chosenLayer)
        {
            if (chosenLayer == Level.ActiveLayer)
            {
                return;
            }

            _memento.BeginCommand(@"Move Item(s) To Layer '{0}'".FormatWith(chosenLayer.Name));

            Level.MoveSelectedIditorsToLayer(chosenLayer);

            tryFire(() => ItemsMoved, Level.SelectedEditors);
        }
예제 #8
0
        public void CopySelectedItemsToLayer(LayerEditor layer)
        {
            if (layer == ActiveLayer)
            {
                return;
            }

            List <ItemEditor> clonedEditors = null;

            _memento.Record(@"Copy Item(s) To Layer '{0}'".FormatWith(layer.Name), () => { clonedEditors = Level.CopySelectedEditorsToLayer(layer).ToList( ); });

            Level.SelectEditors(new SelectedEditors(clonedEditors));

            tryFire(() => ItemsAddedOrRemoved, clonedEditors);
        }
예제 #9
0
        public void AddNewLayer(LayerEditor layer)
        {
            layer.ParentLevel = Level;

            Level.Layers.Add(layer);

            tryFire(
                () => ItemsAddedOrRemoved,
                new[]
            {
                layer
            });

            SelectLayer(layer);
        }
예제 #10
0
        public static LayerEditor FromXml(LevelEditor level, XElement xml)
        {
            var layerProperties = xml.CertainElement(@"LayerProperties").DeserializedAs <LayerProperties>( );
            var layer           = new LayerEditor(level, xml.CertainAttribute(@"Name").Value)
            {
                _properties = layerProperties,
                _behaviours = new BehaviourCollection(layerProperties, xml)
            };

            layer.Items =
                new List <ItemEditor>(
                    xml.CertainElement(@"Editors").Elements(@"Editor").Select(x => createEditor(layer, x)));

            return(layer);
        }
예제 #11
0
        void setActiveLayerIfItsDifferent(LayerEditor layer)
        {
            if (ActiveLayer == layer)
            {
                return;
            }

            Level.SelectLayer(layer);

            var eventHandler = ActiveLayerChanged;

            if (eventHandler != null)
            {
                eventHandler(this, EventArgs.Empty);
            }
        }
예제 #12
0
        LayerEditor copyLayer(Legacy.Layer oldLayer)
        {
            var newLayer = new LayerEditor(null, oldLayer.Name)
            {
                Visible     = oldLayer.Visible,
                ScrollSpeed = oldLayer.ScrollSpeed
            };

            convertCustomProperties(oldLayer.CustomProperties, newLayer.ItemProperties.CustomProperties);

            newLayer.Items.AddRange(oldLayer.Items.Select(convertItem));

            newLayer.Items.ForEach(i => i.ParentLayer = newLayer);

            return(newLayer);
        }
예제 #13
0
        public IEnumerable <ItemEditor> CopySelectedEditorsToLayer(LayerEditor destinationLayer)
        {
            var selectedEditors = SelectedEditors.ToList(  );

            foreach (ItemEditor eachEditor in selectedEditors)
            {
                ItemEditor clonedEditor = eachEditor.Clone( );

                clonedEditor.ParentLayer         = destinationLayer;
                clonedEditor.ItemProperties.Name = destinationLayer.ParentLevel.GetUniqueNameBasedOn(clonedEditor.ItemProperties.Name);

                destinationLayer.AddEditor(clonedEditor);

                clonedEditor.ItemProperties.Id = generateId( );

                yield return(clonedEditor);
            }
        }
예제 #14
0
        static ItemEditor createEditor(LayerEditor layer, XElement xml)
        {
            string typeName = xml.CertainAttribute(@"ClrTypeOfEditor").Value;

            Type type = Type.GetType(typeName);

            if (type == null)
            {
                throw new InvalidOperationException(
                          @"Cannot construct an editor from the XML as the type '{0}' cannot be created.".FormatWith(typeName));
            }

            var editor = (ItemEditor)Activator.CreateInstance(type);

            editor.RecreateFromXml(layer, xml);

            return(editor);
        }
예제 #15
0
        public void DuplicateLayer(LayerEditor layer)
        {
            LayerEditor copiedLayer = layer.Clone( );

            copiedLayer.Name = layer.ParentLevel.GetUniqueNameBasedOn(copiedLayer.Name);

            foreach (ItemEditor eachCopiedItem in copiedLayer.Items)
            {
                eachCopiedItem.ItemProperties.Name = layer.ParentLevel.GetUniqueNameBasedOn(eachCopiedItem.ItemProperties.Name);
            }

            IMainForm mainForm = IoC.MainForm;

            _memento.Record(@"Duplicate Layer '{0}'".FormatWith(layer.Name), () => AddNewLayer(copiedLayer));

            tryFire(() => ItemsAddedOrRemoved, (ITreeItem)copiedLayer);

            mainForm.LevelExplorer.Rebuild( );
        }
예제 #16
0
 public virtual void RecreateFromXml(LayerEditor parentLayer, XElement xml)
 {
     Behaviours = new BehaviourCollection(ItemProperties, xml);
 }
예제 #17
0
        public void SelectLayer(LayerEditor value)
        {
            clearAllSelections( );

            ActiveLayer = value;
        }
예제 #18
0
        public LevelEditor(XElement xml)
        {
            TypeLookup.Rehydrate(xml);

            _properties = xml.Element(@"LevelProperties").DeserializedAs <LevelProperties>( );

            _previousContentRootFolder = _properties.ContentRootFolder;

            if (!Directory.Exists(_properties.ContentRootFolder))
            {
                string message = @"The level file has a content root folder that does not exist.
It says the content root is at ""{0}"". Images specified in this level file are relative to this folder so you should change it in order to load this level file correctly.
Would you like to change it?".FormatWith(_properties.ContentRootFolder);

                if (MessageBox.Show(message, @"Content root folder not found.", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var folderBrowserDialog = new Ookii.Dialogs.VistaFolderBrowserDialog( );

                    DialogResult dialogResult = folderBrowserDialog.ShowDialog( );

                    if (dialogResult == DialogResult.OK)
                    {
                        _properties.ContentRootFolder = folderBrowserDialog.SelectedPath;
                    }
                }
            }

            if (_properties.ContentRootFolder != _previousContentRootFolder)
            {
                //ObjectFactory.GetInstance<IEventHub>().Publish(new ContentRootChanged(_previousContentRootFolder, _properties.ContentRootFolder));
            }

            Behaviours = new BehaviourCollection(_properties, xml);

            Layers = new List <LayerEditor>(xml.CertainElement(@"Layers").Elements(@"Layer").Select(x => LayerEditor.FromXml(this, x)));

            ActiveLayer = Layers.FirstOrDefault( );
        }
예제 #19
0
 /// <summary>
 /// Called when the user starts creating something, e.g. a Rectangle will have a position but no height or width as this is
 /// set when the user moves the pointer around.
 /// Another example is the Path object.  This initially just has 1 point (that start point) and
 /// the user add points by clicking around.
 /// </summary>
 /// <param name="parentLayer"></param>
 /// <param name="creationProperties"></param>
 public abstract void CreateInDesignMode(LayerEditor parentLayer, IEntityCreationProperties creationProperties);