예제 #1
0
        public SceneViewModel(Scene scene)
        {
            this.scene = scene;

            Entities = new ComputedObservableCollection<Entity, EntityViewModel>(scene.Entities, (entity) => new EntityViewModel(entity));

            scene.PropertyChanged += Scene_PropertyChanged;

            AddAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    scene.CreateAttribute();
                }
            );

            RemoveAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Attribute attribute = parameter as Attribute;
                    scene.RemoveAttribute(attribute);
                }
            );

            AddEntityCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity entity = new Entity();
                    scene.AddEntity(entity);
                }
            );

            RemoveEntityCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity entity = parameter as Entity;
                    scene.RemoveEntity(entity);
                }
            );
        }
예제 #2
0
        public GameViewModel(Game game)
        {
            this.game = game;

            game.PropertyChanged += Game_PropertyChanged;

            Prototypes = new ComputedObservableCollection<Entity, EntityViewModel>(game.Prototypes, (prototype) => new EntityViewModel(prototype));
            Scenes = new ComputedObservableCollection<Scene, SceneViewModel>(game.Scenes, (scene) => new SceneViewModel(scene));

            AddPrototypeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity prototype = new Entity();

                    DialogService.ShowDialog(DialogService.Constants.EntityDialog, prototype,
                        (result) =>
                        {
                            if (result == true)
                            {
                                game.AddPrototype(prototype);
                            }
                        }
                    );
                }
            );

            RemovePrototypeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity prototype = parameter as Entity;
                    game.RemovePrototype(prototype);
                }
            );

            AddSceneCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Scene scene = game.CreateScene();

                    DialogService.ShowDialog(DialogService.Constants.SceneDialog, scene,
                        (result) =>
                        {
                            if (result == true)
                            {
                                game.AddScene(scene);
                            }
                        }
                    );
                }
            );

            RemoveSceneCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Scene scene = parameter as Scene;
                    game.RemoveScene(scene);
                }
            );

            AddAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    game.CreateAttribute();
                }
            );

            RemoveAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Attribute attribute = parameter as Attribute;
                    game.RemoveAttribute(attribute);
                }
            );

            AddAssetCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    // TODO: File Chooser
                    Asset asset = new Asset("An Asset");
                    game.AddAsset(asset);
                }
            );

            RemoveAssetCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Asset asset = parameter as Asset;
                    game.RemoveAsset(asset);
                }
            );

            RemoveItemCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity prototype = parameter as Entity;
                    if (null != prototype)
                    {
                        game.RemovePrototype(prototype);
                    }
                    else
                    {
                        Scene scene = parameter as Scene;
                        if (null != scene)
                        {
                            game.RemoveScene(scene);
                        }
                    }
                }
            );
        }