Пример #1
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainViewModel()
        {
            //設定ファイルの読み込み
            Settings = new Settings();

            //セレクターのサイズの初期化
            MouseSelectorPosition.GridSize = Settings.PalletCellSize;
            FontSize = 9;
            StageModel.Dir = new DirectoryInfo(Settings.StageDataDirectory);

            _model = new MainModel(Settings);

            MapChipPalletViewModel = new MapChipPalletViewModel(Settings);
            ObjectChipPalletViewModel = new ObjectChipPalletViewModel(Settings);

            MapChipPalletViewModel.PalletEnterEvent += chip => _model.CurrentPositionMapChip = chip.ID == 0 ? null : chip;
            ObjectChipPalletViewModel.PalletEnterEvent += chip => _model.CurrentPositionObjectChip = chip.ID == 0 ? null : chip;

            PalletViewModelManager = new PalletViewModelManager(MapChipPalletViewModel, ObjectChipPalletViewModel);

            StageViewModels = ViewModelHelper.CreateReadOnlyDispatcherCollection(
                _model.StageModels,
                m =>
                {
                    var vm = new StageViewModel(m, this);
                    vm.PropertyChanged += (sender, args) => RaiseModelPropertyChanged(args.PropertyName);
                    return vm;
                },
                DispatcherHelper.UIDispatcher);

            //TreeViewの要素リストを監視
            MapViewModels = ViewModelHelper.CreateReadOnlyDispatcherCollection(
                _model.MapModels,
                model =>
                {
                    var vm = new MapViewModel(model);
                    vm.PropertyChanged += (sender, args) => RaiseModelPropertyChanged(args.PropertyName);
                    return vm;
                },
                DispatcherHelper.UIDispatcher);

            //MainModelのプロパティ変更を監視
            Listener = new PropertyChangedEventListener(_model);
            Listener.RegisterHandler((sender, args) => RaisePropertyChanged(args.PropertyName));
            Listener.RegisterHandler("CurrentMap", (sender, args) => CurrentMapChenged());
            Listener.RegisterHandler("Scale", (sender, args) =>
            {
                RaisePropertyChanged("MapWidth");
                RaisePropertyChanged("MapHeight");
            });
            Listener.RegisterHandler("CurrentPosition", (sender, args) => _model.UpdateMousePositionProperty());
            CompositeDisposable.Add(Listener);

            ChangeMapInitialize();
        }
        public PalletViewModelManager(MapChipPalletViewModel mapChipPaletteViewModel, ObjectChipPalletViewModel objectChipPaletteViewModel)
        {
            mapChipPaletteViewModel.Parent = this;
            objectChipPaletteViewModel.Parent = this;

            MapChipPalletViewModel = mapChipPaletteViewModel;
            ObjectChipPalletViewModel = objectChipPaletteViewModel;

            _current = MapChipPalletViewModel;

            PaletteViewModels = new HashSet<IPalletViewModel> { MapChipPalletViewModel, ObjectChipPalletViewModel };

            Clipboard = new Clipboard();
        }