public void AddSize() { var ret = new SizeItemModel(CardSizes); CardSizes.Add(ret); Selection = ret; RaisePropertyChanged("CardSizes"); }
public void SaveSet() { foreach (var cardData in Cards) { var guid = (IdHeader?.Header == null) ? Guid.NewGuid() : Guid.Parse(cardData.GetProperty(IdHeader.Header)); var alternate = (AlternateHeader?.Header == null) ? "" : cardData.GetProperty(AlternateHeader.Header); var name = (NameHeader?.Header == null) ? "Card" : cardData.GetProperty(NameHeader.Header); SizeItemModel size = (SizeHeader?.Header == null) ? (SizeItemModel)ViewModelLocator.PreviewTabViewModel.CardSizes.DefaultItem : GetSize(cardData.GetProperty(SizeHeader.Header)); CardModel setCard = (CardModel)Parent.CardItems.FirstOrDefault(x => ((CardModel)x).Id == guid); if (setCard == null) //no card matches { setCard = new CardModel(Parent.CardItems); setCard._card.Id = guid; Parent.CardItems.Add(setCard); } AlternateModel cardAlternate = (string.IsNullOrEmpty(alternate)) ? (AlternateModel)setCard.Items.DefaultItem : (AlternateModel)setCard.Items.FirstOrDefault(x => ((AlternateModel)x).Type == alternate); if (cardAlternate == null) // no alternate matches { cardAlternate = new AlternateModel(Parent.CardItems) { Type = alternate, SizeProperty = size, Name = name }; if (string.IsNullOrEmpty(alternate)) { setCard.Items.DefaultItem = cardAlternate; } else { setCard.Items.Add(cardAlternate); } } foreach (var mapping in Mappings) { if (mapping.IsEnabled) { var propertyValue = cardData.GetProperty(mapping.Header); if (propertyValue == null) { continue; } var altProperty = cardAlternate._altDef.Properties.FirstOrDefault(x => x.Key == mapping.Property._property); // if (altProperty == null) // { // altProperty = new CardPropertyModel(cardAlternate, mapping.Property); // } // altProperty.Value = propertyValue; } } setCard.UpdateCardName(); } }
void IDropTarget.Drop(IDropInfo dropInfo) { if (dropInfo.Data is SizeItemModel) { SizeItemModel item = dropInfo.Data as SizeItemModel; var card = new SampleCardItemModel { Size = item }; ViewModelLocator.PreviewTabViewModel.Cards.Add(card); } }
public PreviewTabViewModel() { var _game = ViewModelLocator.GameLoader.Game; if (_game.GlobalPlayer == null) { _game.GlobalPlayer = new GlobalPlayer() { Counters = new List <Counter>(), Groups = new List <Group>() }; } Table = new TableItemModel(_game.Table, new IdeCollection <IdeBaseItem>(this)) { CanRemove = false, CanCopy = false, CanInsert = false }; Piles = new IdeCollection <IdeBaseItem>(this); foreach (var pile in _game.Player.Groups) { Piles.Add(new GroupItemModel(pile, Piles)); } Piles.CollectionChanged += (sender, args) => { _game.Player.Groups = Piles.Select(x => ((GroupItemModel)x)._group); RaisePropertyChanged("CollapsedPiles"); RaisePropertyChanged("VisiblePiles"); Messenger.Default.Send(new GroupChangedMessage(args)); }; AddPileCommand = new RelayCommand(AddPile); Counters = new IdeCollection <IdeBaseItem>(this); foreach (var counter in _game.Player.Counters) { Counters.Add(new CounterItemModel(counter, Counters)); } Counters.CollectionChanged += (sender, args) => { _game.Player.Counters = Counters.Select(x => ((CounterItemModel)x)._counter); }; AddCounterCommand = new RelayCommand(AddCounter); GlobalPiles = new IdeCollection <IdeBaseItem>(this); foreach (var pile in _game.GlobalPlayer.Groups) { GlobalPiles.Add(new GroupItemModel(pile, GlobalPiles)); } GlobalPiles.CollectionChanged += (sender, args) => { _game.GlobalPlayer.Groups = GlobalPiles.Select(x => ((GroupItemModel)x)._group); RaisePropertyChanged("CollapsedGlobalPiles"); RaisePropertyChanged("VisibleGlobalPiles"); Messenger.Default.Send(new GroupChangedMessage(args)); }; AddGlobalPileCommand = new RelayCommand(AddGlobalPile); GlobalCounters = new IdeCollection <IdeBaseItem>(this); foreach (var counter in _game.GlobalPlayer.Counters) { GlobalCounters.Add(new CounterItemModel(counter, GlobalCounters)); } GlobalCounters.CollectionChanged += (sender, args) => { _game.GlobalPlayer.Counters = GlobalCounters.Select(x => ((CounterItemModel)x)._counter); }; AddGlobalCounterCommand = new RelayCommand(AddGlobalCounter); CardSizes = new IdeCollection <IdeBaseItem>(this); foreach (var sizeDef in _game.CardSizes) { var size = new SizeItemModel(sizeDef.Value, CardSizes); CardSizes.Add(size); if (sizeDef.Key == "") { CardSizes.DefaultItem = size; } } CardSizes.CollectionChanged += (sender, args) => { UpdateCardSizesDef(); Messenger.Default.Send(new CardSizeChangedMesssage(args)); }; CardSizes.DefaultItemChanged += (sender, args) => { UpdateCardSizesDef(); }; AddSizeCommand = new RelayCommand(AddSize); Phases = new IdeCollection <IdeBaseItem>(this); foreach (var phase in _game.Phases) { Phases.Add(new PhaseItemModel(phase, Phases)); } Phases.CollectionChanged += (sender, args) => { _game.Phases = Phases.Select(x => ((PhaseItemModel)x)._phase).ToList(); }; AddPhaseCommand = new RelayCommand(AddPhase); Boards = new IdeCollection <IdeBaseItem>(this); foreach (var boardDef in _game.GameBoards) { var board = new BoardItemModel(boardDef.Value, Boards); Boards.Add(board); if (boardDef.Key == "") { Boards.DefaultItem = board; } } ActiveBoard = (BoardItemModel)Boards.DefaultItem; Boards.CollectionChanged += (sender, args) => { UpdateBoardsDef(); }; Boards.DefaultItemChanged += (sender, args) => { UpdateBoardsDef(); }; AddBoardCommand = new RelayCommand(AddBoard); Cards = new ObservableCollection <SampleCardItemModel>(); var card = new SampleCardItemModel { Size = (SizeItemModel)CardSizes.DefaultItem }; Cards.Add(card); RaisePropertyChanged("Cards"); }
public PreviewTabViewModel() { #region table if (_game.Table == null) { _game.Table = new Group() { Name = "Table", Width = 640, Height = 480 }; } Table = new TableItemModel(_game.Table, new IdeCollection <IdeBaseItem>(this)) { CanRemove = false, CanCopy = false, CanInsert = false }; #endregion #region piles if (_game.Player == null) { _game.Player = new Player(); } Piles = new IdeCollection <IdeBaseItem>(this); foreach (var pile in _game.Player.Groups) { Piles.Add(new GroupItemModel(pile, Piles)); } Piles.CollectionChanged += (sender, args) => { _game.Player.Groups = Piles.Select(x => ((GroupItemModel)x)._group); RaisePropertyChanged("CollapsedPiles"); RaisePropertyChanged("VisiblePiles"); Messenger.Default.Send(new GroupChangedMessage(args)); }; AddPileCommand = new RelayCommand(AddPile); #endregion #region counters Counters = new IdeCollection <IdeBaseItem>(this); foreach (var counter in _game.Player.Counters) { Counters.Add(new CounterItemModel(counter, Counters)); } Counters.CollectionChanged += (sender, args) => { _game.Player.Counters = Counters.Select(x => ((CounterItemModel)x)._counter); }; AddCounterCommand = new RelayCommand(AddCounter); #endregion #region globalpiles if (_game.GlobalPlayer == null) { _game.GlobalPlayer = new GlobalPlayer(); } GlobalPiles = new IdeCollection <IdeBaseItem>(this); foreach (var pile in _game.GlobalPlayer.Groups) { GlobalPiles.Add(new GroupItemModel(pile, GlobalPiles)); } GlobalPiles.CollectionChanged += (sender, args) => { _game.GlobalPlayer.Groups = GlobalPiles.Select(x => ((GroupItemModel)x)._group); RaisePropertyChanged("CollapsedGlobalPiles"); RaisePropertyChanged("VisibleGlobalPiles"); Messenger.Default.Send(new GroupChangedMessage(args)); }; AddGlobalPileCommand = new RelayCommand(AddGlobalPile); #endregion #region globalcounters GlobalCounters = new IdeCollection <IdeBaseItem>(this); foreach (var counter in _game.GlobalPlayer.Counters) { GlobalCounters.Add(new CounterItemModel(counter, GlobalCounters)); } GlobalCounters.CollectionChanged += (sender, args) => { _game.GlobalPlayer.Counters = GlobalCounters.Select(x => ((CounterItemModel)x)._counter); }; AddGlobalCounterCommand = new RelayCommand(AddGlobalCounter); #endregion #region sizes CardSizes = new IdeCollection <IdeBaseItem>(this); foreach (var sizeDef in _game.CardSizes) { var size = new SizeItemModel(sizeDef.Value, CardSizes); CardSizes.Add(size); if (sizeDef.Key == "") { CardSizes.DefaultItem = size; } } CardSizes.CollectionChanged += (sender, args) => { UpdateCardSizesDef(); Messenger.Default.Send(new CardSizeChangedMesssage(args)); }; CardSizes.DefaultItemChanged += (sender, args) => { UpdateCardSizesDef(); }; AddSizeCommand = new RelayCommand(AddSize); #endregion #region phases Phases = new IdeCollection <IdeBaseItem>(this); foreach (var phase in _game.Phases) { Phases.Add(new PhaseItemModel(phase, Phases)); } Phases.CollectionChanged += (sender, args) => { _game.Phases = Phases.Select(x => ((PhaseItemModel)x)._phase).ToList(); }; AddPhaseCommand = new RelayCommand(AddPhase); #endregion #region boards Boards = new IdeCollection <IdeBaseItem>(this); foreach (var boardDef in _game.GameBoards) { var board = new BoardItemModel(boardDef.Value, Boards); Boards.Add(board); if (boardDef.Key == "") { Boards.DefaultItem = board; } } Boards.CollectionChanged += (sender, args) => { UpdateBoardsDef(); }; Boards.DefaultItemChanged += (sender, args) => { UpdateBoardsDef(); }; AddBoardCommand = new RelayCommand(AddBoard); #endregion #region samplecards Cards = new ObservableCollection <SampleCardItemModel>(); if (CardSizes.DefaultItem != null) { var card = new SampleCardItemModel { Size = (SizeItemModel)CardSizes.DefaultItem }; Cards.Add(card); } #endregion #region activeboard if (Boards.DefaultItem != null) { ActiveBoard = (BoardItemModel)Boards.DefaultItem; } #endregion }