Ejemplo n.º 1
0
        //Entities
        void setUpEntitiesMenuItem()
        {
            var menuItem = new MenuBar.MenuItem("Entities");

            MenuBar.MenuItems.Add(menuItem);

            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Add Entity", delegate(object sender)
            {
                AddEntitiesForm.ShowDialogue(Parent, Simulation.World);
            }));
            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Edit Entity", delegate(object sender)
            {
                if (WorldBox.SelectedEntity == null)
                {
                    return;
                }

                if (typeof(ICreature).IsAssignableFrom(WorldBox.SelectedEntity.GetType()))
                {
                    return;
                }

                EditEntityForm.ShowDialogue(Parent, WorldBox.SelectedEntity);
            }));
            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Delete Entity", delegate(object sender)
            {
                if (WorldBox.SelectedEntity == null)
                {
                    return;
                }

                if (typeof(ICreature).IsAssignableFrom(WorldBox.SelectedEntity.GetType()))
                {
                    return;
                }

                Simulation.World.RemoveEntity(WorldBox.SelectedEntity);
            }));
            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Delete All Entities", delegate(object sender)
            {
                YesNoForm.ShowDialogue(Parent, null, "Do you really want to remove all entities?", delegate(object _sender)
                {
                    var form = (YesNoForm)_sender;

                    if (form.DialogResult == DialogResult.Yes)
                    {
                        var creatureType = typeof(ICreature);
                        foreach (var e in new List <IEntity>(WorldBox.World.EntityList))
                        {
                            var type = e.GetType();

                            if (!creatureType.IsAssignableFrom(type))
                            {
                                WorldBox.World.RemoveEntity(e);
                            }
                        }
                    }
                });
            }));

            menuItem.Elements.Add(MenuBar.MenuItem.MenuElement.GetSeparator());

            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Add Creatures", delegate(object sender)
            {
                AddCreaturesForm.ShowDialogue(Parent, Simulation.World);
            }));
            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Edit Creature", delegate(object sender)
            {
                if (WorldBox.SelectedEntity == null)
                {
                    return;
                }

                if (typeof(ICreature).IsAssignableFrom(WorldBox.SelectedEntity.GetType()))
                {
                    EditCreatureForm.ShowDialogue(Parent, (ICreature)WorldBox.SelectedEntity);
                }
            }));
            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Delete Creature", delegate(object sender)
            {
                if (WorldBox.SelectedEntity == null)
                {
                    return;
                }

                if (typeof(ICreature).IsAssignableFrom(WorldBox.SelectedEntity.GetType()))
                {
                    Simulation.World.RemoveEntity(WorldBox.SelectedEntity);
                }
            }));
            menuItem.Elements.Add(new MenuBar.MenuItem.MenuElement("Delete All Creatures", delegate(object sender)
            {
                YesNoForm.ShowDialogue(Parent, null, "Do you really want to remove all creatures?", delegate(object _sender)
                {
                    var form = (YesNoForm)_sender;

                    if (form.DialogResult == DialogResult.Yes)
                    {
                        var creatureType = typeof(ICreature);
                        foreach (var e in new List <IEntity>(WorldBox.World.EntityList))
                        {
                            var type = e.GetType();

                            if (creatureType.IsAssignableFrom(type))
                            {
                                WorldBox.World.RemoveEntity(e);
                            }
                        }
                    }
                });
            }));
        }