Exemple #1
0
        public static Func <bool> GUI_Edit(SingleSlotBox container, FoodWorld world)
        {
            var builder = new FieldBuilder();

            builder.BuildSessionStart(container);

            Panel panel = new Panel();

            panel.Initialize();
            builder.AddDrawBoxAsField(panel, DrawBoxAlignment.GetFull());

            Func <bool> isReadyFunc = World.GUI_Edit(panel, world);

            var minFood = builder.AddIntegerField("Minimum Food: ");

            minFood.Value = world.MinimumFood;
            var foodSpawnRate = builder.AddIntegerField("Food Spawn-rate: ");

            foodSpawnRate.Value = world.FoodSpawnRate;

            builder.AddResizableButtonField("Edit Food", delegate(object sender)
            {
                EditEntityForm.ShowDialogue(container.Parent, world.FoodToClone);
            }, FieldBuilder.ResizableButtonOrientation.FillWidth);

            container.IsClosing += delegate(object sender)
            {
                world.MinimumFood   = (int)minFood.Value;
                world.FoodSpawnRate = (int)foodSpawnRate.Value;
            };

            builder.BuildSessionEnd();

            return(delegate()
            {
                return isReadyFunc();
            });
        }
Exemple #2
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);
                            }
                        }
                    }
                });
            }));
        }