예제 #1
0
        public PreviewTabViewModel()
        {
            var _game = ViewModelLocator.GameLoader.Game;

            if (_game.GlobalPlayer == null)
            {
                _game.GlobalPlayer = new GlobalPlayer()
                {
                    Counters = new List <Counter>(),
                    Groups   = new List <Group>()
                };
            }
            Hand       = _game.Player.Hand == null ? null : new GroupItemViewModel(_game.Player.Hand);
            TableGroup = new GroupItemViewModel(_game.Table);
            Piles      = new ObservableCollection <IdeListBoxItemBase>();
            foreach (var pile in _game.Player.Groups)
            {
                Piles.Add(new GroupItemViewModel(pile)
                {
                    ItemSource = Piles
                });
            }
            Piles.CollectionChanged += (a, b) =>
            {
                _game.Player.Groups = Piles.Select(x => (x as GroupItemViewModel)._group).ToList();
                RaisePropertyChanged("CollapsedPiles");
                RaisePropertyChanged("VisiblePiles");
            };
            AddPileCommand = new RelayCommand(AddPile);

            Counters = new ObservableCollection <IdeListBoxItemBase>();
            foreach (var counter in _game.Player.Counters)
            {
                Counters.Add(new CounterItemViewModel(counter)
                {
                    ItemSource = Counters
                });
            }
            Counters.CollectionChanged += (a, b) =>
            {
                _game.Player.Counters = Counters.Select(x => (x as CounterItemViewModel)._counter).ToList();
            };
            AddCounterCommand = new RelayCommand(AddCounter);

            GlobalPiles = new ObservableCollection <IdeListBoxItemBase>();
            foreach (var pile in _game.GlobalPlayer.Groups)
            {
                GlobalPiles.Add(new GroupItemViewModel(pile)
                {
                    ItemSource = GlobalPiles
                });
            }
            GlobalPiles.CollectionChanged += (a, b) =>
            {
                _game.GlobalPlayer.Groups = Piles.Select(x => (x as GroupItemViewModel)._group).ToList();
                RaisePropertyChanged("CollapsedGlobalPiles");
                RaisePropertyChanged("VisibleGlobalPiles");
            };
            AddGlobalPileCommand = new RelayCommand(AddGlobalPile);

            GlobalCounters = new ObservableCollection <IdeListBoxItemBase>();
            foreach (var counter in _game.GlobalPlayer.Counters)
            {
                GlobalCounters.Add(new CounterItemViewModel(counter)
                {
                    ItemSource = GlobalCounters
                });
            }

            GlobalCounters.CollectionChanged += (a, b) =>
            {
                _game.GlobalPlayer.Counters = GlobalCounters.Select(x => (x as CounterItemViewModel)._counter).ToList();
            };
            AddGlobalCounterCommand = new RelayCommand(AddGlobalCounter);

            CardSizes = new ObservableCollection <IdeListBoxItemBase>();
            foreach (var sizeDef in _game.CardSizes)
            {
                var size = new SizeItemViewModel(sizeDef.Value)
                {
                    ItemSource = CardSizes
                };
                if (sizeDef.Key == "")
                {
                    size.IsDefault = true;
                    size.CanRemove = false;
                }
                CardSizes.Add(size);
            }
            CardSizes.CollectionChanged += (a, b) =>
            {
                UpdateSizes();
            };
            AddSizeCommand = new RelayCommand(AddSize);

            Phases = new ObservableCollection <IdeListBoxItemBase>();
            foreach (var phase in _game.Phases)
            {
                Phases.Add(new PhaseItemViewModel(phase)
                {
                    ItemSource = Phases
                });
            }
            Phases.CollectionChanged += (a, b) =>
            {
                _game.Phases = Phases.Select(x => (x as PhaseItemViewModel)._phase).ToList();
            };
            AddPhaseCommand = new RelayCommand(AddPhase);

            Boards = new ObservableCollection <IdeListBoxItemBase>();
            foreach (var boardDef in _game.GameBoards)
            {
                var board = new BoardItemViewModel(boardDef.Value)
                {
                    ItemSource = Boards
                };
                if (boardDef.Key == "")
                {
                    DefaultBoard = board;
                }
                Boards.Add(board);
            }
            ActiveBoard = DefaultBoard;
            Boards.CollectionChanged += (a, b) =>
            {
                UpdateBoards();
            };
            AddBoardCommand = new RelayCommand(AddBoard);

            Table = new TableItemViewModel();

            Cards = new ObservableCollection <CardViewModel>();
            var card = new CardViewModel
            {
                Size = DefaultSize
            };

            Cards.Add(card);

            RaisePropertyChanged("Cards");
        }