internal Card(Player owner, int id, ulong key, DataNew.Entities.Card model, bool mySecret) : base(owner) { _id = id; Type = new CardIdentity(id) { Key = key, Model = model.Clone(), MySecret = mySecret }; // var _definition = def; lock (All) { if (All.ContainsKey(id)) { All[id] = this; } else { All.Add(id, this); } } _alternateOf = null; numberOfSwitchWithAlternatesNotPerformed = 0; _isAlternateImage = false; _cardMoved = false; }
internal Card(Player owner, int id, DataNew.Entities.Card model, bool mySecret, string cardsize) : base(owner) { _id = id; Type = new CardIdentity(id) { Model = model.Clone() }; // var _definition = def; lock (All) { if (All.ContainsKey(id)) { All[id] = this; } else { All.Add(id, this); } } _alternateOf = null; //numberOfSwitchWithAlternatesNotPerformed = 0; //_isAlternateImage = false; _cardMoved = false; Size = Program.GameEngine.Definition.CardSizes[cardsize]; }
internal Card(Player owner, int id, ulong key, DataNew.Entities.Card model, bool mySecret) : base(owner) { _id = id; Type = new CardIdentity(id) {Alias = false, Key = key, Model = model.Clone() , MySecret = mySecret}; // var _definition = def; All.Add(id, this); _alternateOf = null; numberOfSwitchWithAlternatesNotPerformed = 0; _isAlternateImage = false; }
internal Card(Player owner, int id, ulong key, DataNew.Entities.Card model, bool mySecret) : base(owner) { _id = id; Type = new CardIdentity(id) { Alias = false, Key = key, Model = model.Clone(), MySecret = mySecret }; // var _definition = def; All.Add(id, this); _alternateOf = null; numberOfSwitchWithAlternatesNotPerformed = 0; _isAlternateImage = false; }
public static Card Clone(this Card card) { if (card == null) return null; var ret = new Card { Name = card.Name.Clone() as string, Alternate = card.Alternate.Clone() as string, Id = card.Id, ImageUri = card.ImageUri.Clone() as string, Properties = card.Properties.ToDictionary( x => x.Key.Clone() as string, x => x.Value.Clone() as CardPropertySet), SetId = card.SetId }; return ret; }
internal void AddRecentCard(DataNew.Entities.Card card) { int idx = _recentCards.FindIndex(c => c.Id == card.Id); if (idx == 0) { return; } if (idx > 0) { _recentCards.RemoveAt(idx); _recentCards.Insert(0, card); return; } if (_recentCards.Count == MaxRecentCards) { _recentCards.RemoveAt(MaxRecentCards - 1); } _recentCards.Insert(0, card); }
public virtual bool ExecuteDefaultCardAction(Card card) { var defaultCardAction = GetDefaultCardAction(); if (defaultCardAction == null || !card.TryToManipulate()) return false; group.KeepControl(); card.KeepControl(); if (defaultCardAction.Execute != null) ScriptEngine.ExecuteOnCards(defaultCardAction.Execute, Selection.ExtendToSelection(card)); else if (defaultCardAction.BatchExecute != null) ScriptEngine.ExecuteOnBatch(defaultCardAction.BatchExecute, Selection.ExtendToSelection(card)); group.ReleaseControl(); card.ReleaseControl(); return true; }
public virtual void ExecuteDefaultAction(Card card) { if (!ExecuteDefaultCardAction(card)) ExecuteDefaultGroupAction(); }
internal virtual void ShowContextMenu(Card card, bool showGroupActions = true) { // Modify selection if (card == null || !card.Selected) Selection.Clear(); var menuItems = new CompositeCollection(); ContextGroup = group; ContextMenu = new ContextMenu {ItemsSource = menuItems, Tag = card}; // card has to captured somehow, otherwise it may be overwritten before released in the OnClosed handler, e.g. when rightclicking on a card, then directly right-clicking on another card. ContextMenu.Opened += (sender, args) => { ContextGroup.KeepControl(); var c = ((ContextMenu) sender).Tag as Card; if (c != null) c.KeepControl(); }; ContextMenu.Closed += (sender, args) => { ContextGroup.ReleaseControl(); var c = ((ContextMenu) sender).Tag as Card; if (c != null) c.ReleaseControl(); }; ContextCard = card; menuItems.Clear(); if (group.CanManipulate()) { if (card != null) { if (card.CanManipulate()) { if (_cardHeader != null) { _cardHeader.Header = card.Name; _cardHeader.Background = card.Controller.TransparentBrush; menuItems.Add(_cardMenu); } } else { var item = new MenuItem {Header = card.Name, Background = card.Controller.TransparentBrush}; item.SetResourceReference(StyleProperty, "MenuHeader"); menuItems.Add(item); item = new MenuItem {Header = "Take control"}; item.Click += delegate { card.TakeControl(); }; menuItems.Add(item); } if (!card.FaceUp) { var peekItem = new MenuItem {Header = "Peek", InputGestureText = "Ctrl+P"}; peekItem.Click += delegate { ContextCard.Peek(); }; if (menuItems.Count == 0) { var item = new MenuItem {Header = card.Name, Background = card.Owner.TransparentBrush}; item.SetResourceReference(StyleProperty, "MenuHeader"); menuItems.Add(item); } menuItems.Add(peekItem); } } if (showGroupActions) menuItems.Add(_groupMenu); } else// if (!group.WantToShuffle) { menuItems.Add(CreateGroupHeader()); var item = new MenuItem {Header = "Take control"}; item.Click += delegate { group.TakeControl(); }; menuItems.Add(item); menuItems.Add(new Separator()); item = CreateLookAtCardsMenuItem(); if (item != null) menuItems.Add(item); } //else // Group is being shuffled // return; ContextMenu.IsOpen = false; // Required to trigger the ReleaseControl calls if the ContextMenu was already open ContextMenu.UpdateLayout(); // Required if the ContextMenu was already open ContextMenu.IsOpen = true; ContextMenu.FontFamily = groupFont; ContextMenu.FontSize = fontsize; }
public Card FromXmlReader(XmlReader reader, Game game, Set set, PackagePart definition, Package package) { var ret = new Card(); var Properties = new SortedList<PropertyDef, object>(game.CustomProperties.Count()); reader.MoveToAttribute("name"); ret.Name = reader.Value; reader.MoveToAttribute("id"); ret.Id = new Guid(reader.Value); // isMutable = false; if (reader.MoveToAttribute("alternate")) { try { ret.Alternate = new Guid(reader.Value); } catch (Exception e) { throw new ArgumentException(String.Format("The value {0} is not of expected type for property Alternate. Alternate must be a GUID.", reader.Value)); } } else { ret.Alternate = System.Guid.Empty; } if (reader.MoveToAttribute("dependent")) { try { ret.Dependent = new Guid(reader.Value).ToString(); } catch { try { ret.Dependent = Boolean.Parse(reader.Value).ToString(); } catch { throw new ArgumentException(String.Format("The value {0} is not of expected type for property Dependent. Dependent must be either true/false, or the Guid of the card to use instead.", reader.Value)); } } } else { ret.Dependent = String.Empty; } Uri cardImageUri = definition.GetRelationship("C" + ret.Id.ToString("N")).TargetUri; ret.ImageUri = cardImageUri.OriginalString; if (!package.PartExists(cardImageUri)) throw new Exception(string.Format("Image for card '{0}', with URI '{1}' was not found in the package.", ret.Name, ret.ImageUri)); reader.Read(); // <card> while (reader.IsStartElement("property")) { reader.MoveToAttribute("name"); PropertyDef prop = game.CustomProperties.FirstOrDefault(p => p.Name == reader.Value); if (prop == null) throw new ArgumentException(string.Format("The property '{0}' is unknown", reader.Value)); reader.MoveToAttribute("value"); try { switch (prop.Type) { case PropertyType.String: Properties.Add(prop, reader.Value); break; case PropertyType.Integer: Properties.Add(prop, Int32.Parse(reader.Value)); break; case PropertyType.Char: Properties.Add(prop, Char.Parse(reader.Value)); break; default: throw new NotImplementedException(); } } catch (FormatException) { throw new ArgumentException(String.Format("The value {0} is not of expected type for property {1}", reader.Value, prop.Name)); } reader.Read(); // <property/> } ret.Properties = Properties; reader.Read(); // </card> return ret; }
public void SetCard(Card c) { Card = c; Alternates.Clear(); if (Card == null) return; var i = 0; foreach (var a in c.Properties) { if (c.Alternate == a.Key) Index = i; Alternates.Add(new Alternate(this, a.Key, i)); i++; } }
public void Save(Card card) { try { // Need to do this so that it doesn't just duplicate the entry // Stupid db40 uses longs for ids var curCard = Cards.FirstOrDefault(x => x.Id == card.Id); if (curCard != null) { var id = this.Client.Ext().GetID(curCard); this.Client.Ext().Bind(card,id); } this.Client.Store(card); this.Client.Commit(); } catch (Exception e) { throw e; } }
protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def) { var items = new List<Control>(); if (!card.CanManipulate()) { var item = new MenuItem { Header = card.Name, Background = card.Controller.TransparentBrush }; item.SetResourceReference(StyleProperty, "MenuHeader"); items.Add(item); item = new MenuItem { Header = "Take control" }; item.Click += delegate { card.TakeControl(); }; items.Add(item); return items; } else { var actions = def.CardActions.ToList(); var nCardActions = actions.ToArray().Length; if (nCardActions > 0 || group.Controller == null) { var cardHeader = new MenuItem(); cardHeader.SetResourceReference(StyleProperty, "MenuHeader"); cardHeader.Header = card.Name; cardHeader.Background = card.Controller.TransparentBrush; items.Add(cardHeader); } if (nCardActions > 0) { items.AddRange(actions.Select(action => CreateActionMenuItem(action, CardActionClicked, card)).Where(x => x.Visibility == Visibility.Visible)); if (group.Controller == null) items.Add(new Separator()); } if (group.Controller == null) items.Add(CreateCardPassToItem()); } if (def.Id == Program.GameEngine.Definition.Table.Id) { var ami = new MenuItem() { Header = card.Anchored ? "Unanchor" : "Anchor" }; ami.Click += (sender, args) => ContextCard.SetAnchored(false, card.Anchored == false); items.Add(ami); } if (!card.FaceUp) { var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" }; peekItem.Click += delegate { ContextCard.Peek(); }; items.Add(peekItem); } return items; }
private void LoadClicked(object sender, RoutedEventArgs e) { if (setsCombo.SelectedItem == null) return; if (propertyCombo.SelectedItem == null) return; if (!Directory.Exists(FolderDir)) return; Items.Clear(); var selectedSet = setsCombo.SelectedItem as Set; var selectedProperty = propertyCombo.SelectedItem as PropertyDef; ImagePaths = new ObservableCollection<string>(Directory.EnumerateFiles(FolderDir).Where(file => Regex.IsMatch(file, @"^.+\.(jpg|jpeg|png)$"))); foreach (var c in selectedSet.Cards) { foreach (var alternate in c.Properties) { Card card = new Card(c); card.Alternate = alternate.Key; var cardPropertyValue = card.Properties[card.Alternate].Properties[selectedProperty].ToString(); var sanitizedValue = SanitizeString(cardPropertyValue); // first check for exact matches, then if none show up we check for partial matches var matchedImages = ImagePaths.Where(x => SanitizeString(Path.GetFileNameWithoutExtension(x)) == sanitizedValue).ToList(); if (matchedImages.Count() < 1) matchedImages = ImagePaths.Where(x => SanitizeString(Path.GetFileNameWithoutExtension(x)).Contains(sanitizedValue)).ToList(); var ret = new ImportImagesItem() { Path = null, Card = card, Filter = sanitizedValue, PossiblePaths = null }; if (matchedImages.Count() < 1) { } else if (matchedImages.Count() > 1) { ret.PossiblePaths = new ObservableCollection<string>(matchedImages); } else { var singleImage = matchedImages.First(); ret.Path = singleImage; ImagePaths.Remove(singleImage); ret.PossiblePaths = new ObservableCollection<string>(matchedImages); } Items.Add(ret); } } OnPropertyChanged("Items"); }
internal Card(Player owner, int id, DataNew.Entities.Card model, bool mySecret, string cardsize) : base(owner) { _id = id; Type = new CardIdentity(id) { Model = model.Clone() }; // var _definition = def; lock (All) { if (All.ContainsKey(id)) All[id] = this; else All.Add(id, this); } _alternateOf = null; //numberOfSwitchWithAlternatesNotPerformed = 0; //_isAlternateImage = false; _cardMoved = false; Size = Program.GameEngine.Definition.CardSizes[cardsize]; }
protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def) { var items = new List<Control>(); if (!card.CanManipulate()) { var item = new MenuItem { Header = card.Name, Background = card.Controller.TransparentBrush }; item.SetResourceReference(StyleProperty, "MenuHeader"); items.Add(item); item = new MenuItem { Header = "Take control" }; item.Click += delegate { card.TakeControl(); }; items.Add(item); return items; } else { var selection = Selection.ExtendToSelection(card); //actionFilter showCard = async (IGroupAction a) => actionFilter showCard = (IGroupAction a) => { if (a.ShowIf != null) { //return await CallActionShowIf(a.ShowIf, selection); return CallActionShowIf(a.ShowIf, selection); } return true; }; var visibleActionsTasks = def.CardActions.Select(item => new { Item = item, PredTask = showCard.Invoke(item) }).ToList(); //await TaskEx.WhenAll(visibleActionsTasks.Select(x => x.PredTask)); //var visibleActions = visibleActionsTasks.Where(x => x.PredTask.Result).Select(x => x.Item).ToArray(); var visibleActions = visibleActionsTasks.Where(x => x.PredTask).Select(x => x.Item).ToArray(); var nCardActions = visibleActions.Length; if (nCardActions > 0 || group.Controller == null) { var cardHeader = new MenuItem(); cardHeader.SetResourceReference(StyleProperty, "MenuHeader"); cardHeader.Header = card.Name; cardHeader.Background = card.Controller.TransparentBrush; items.Add(cardHeader); } if (nCardActions > 0) { items.AddRange(visibleActions.Select(action => CreateActionMenuItem(action, CardActionClicked))); if (group.Controller == null) items.Add(new Separator()); } if (group.Controller == null) items.Add(CreateCardPassToItem()); } if (!card.FaceUp) { var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" }; peekItem.Click += delegate { ContextCard.Peek(); }; items.Add(peekItem); } return items; }
public PackContent GetCards(Pack pack, Set set) { var ret = new PackContent(); var cardList = set.Cards.ToList(); // add the include cards to the set for this booster var cards = ( from qset in pack.Includes.Select(x=>x.SetId).Distinct().SelectMany(x=>DbContext.Get().SetsById(x)) from card in qset.Cards join inc in pack.Includes on qset.Id equals inc.SetId where card.Id == inc.Id select new { Card = card, Include = inc } ) .Select(dong => { var card = new Card(dong.Card); foreach (var p in dong.Include.Properties) { var key = dong.Card.Properties[""].Properties.Where(x => x.Key.Name.ToLower() == p.Item1.ToLower()).FirstOrDefault().Key; if (key != null) // if the include property name isn't a defined custom property, ignore it card.Properties[""].Properties[key] = p.Item2; } return card; }) ; cardList.AddRange(cards); foreach (var prop in Properties) { var Key = prop.Item1; var Value = prop.Item2; var list = ( from card in cardList where card.Properties.Where(x => x.Key == "").SelectMany(x => x.Value.Properties).Any( x => x.Key.Name.ToLower() == Key.ToLower() && x.Value.ToString().ToLower() == Value.ToLower()) select card).ToList(); cardList = list; } if (Quantity < 0) { ret.UnlimitedCards.AddRange(cardList); } else { for (var i = 0; i < Quantity; i++) { var pick = cardList.RandomElement(); if (pick != null) { ret.LimitedCards.Add(pick); cardList.Remove(pick); } else { Log.Warn(String.Format("Set {0} ({1}) does not contain enough cards to create this booster pack correctly.", set.Id, set.Name)); } } } return ret; }
public static Card Clone(this Card card) { if (card == null) return null; var ret = new Card(card); return ret; }
private Control CreateActionMenuItem(IGroupAction baseAction, RoutedEventHandler onClick, Card card) { var selection = card == null ? Enumerable.Empty<Card>() : Selection.ExtendToSelection(card); bool showAction = true; if (baseAction.ShowExecute != null) showAction = CallActionConditionalExecute(baseAction, selection); if (!showAction) return new MenuItem() { Visibility = Visibility.Collapsed }; //action is a separator var separatorAction = baseAction as GroupActionSeparator; if (separatorAction != null) return new Separator(); string newName = baseAction.Name; if (baseAction.HeaderExecute != null) { var name = CallActionNameExecute(baseAction, selection); if (name != null) newName = name; } var item = new MenuItem { Header = newName }; //action is a submenu var actionGroupDef = baseAction as GroupActionGroup; if (actionGroupDef != null) { foreach (var i in actionGroupDef.Children.Select(subAction => CreateActionMenuItem(subAction, onClick, card)).Where(x => x.Visibility == Visibility.Visible)) item.Items.Add(i); if (item.Items.Count == 0) return new MenuItem() { Visibility = Visibility.Collapsed }; return item; } //action is a proper action var action = baseAction as GroupAction; item.Tag = action; if (action != null) { item.InputGestureText = action.Shortcut; if (action.DefaultAction) { item.FontWeight = FontWeights.Bold; } } item.Click += onClick; return item; }
protected virtual bool ShouldShowGroupActions(Card card) { return true; }
protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def) { var items = new List<Control>(); var menuItem = new MenuItem { Header = card.Name, Background = card.Controller != null ? card.Controller.TransparentBrush : new SolidColorBrush(Color.FromArgb(100, 100, 100, 100)) }; menuItem.SetResourceReference(StyleProperty, "MenuHeader"); items.Add(menuItem); if (card.CanManipulate()) { var selection = Selection.ExtendToSelection(card); //actionFilter showCard = async (IGroupAction a) => actionFilter showCard = (IGroupAction a) => { if (a.ShowIf != null) { //return await CallActionShowIf(a.ShowIf, selection); return CallActionShowIf(a.ShowIf, selection); } return true; }; var visibleActionsTasks = def.CardActions.Select(item => new { Item = item, PredTask = showCard.Invoke(item) }).ToList(); //await TaskEx.WhenAll(visibleActionsTasks.Select(x => x.PredTask)); //var visibleActions = visibleActionsTasks.Where(x => x.PredTask.Result).Select(x => x.Item).ToArray(); var visibleActions = visibleActionsTasks.Where(x => x.PredTask).Select(x => x.Item).ToArray(); var nCardActions = visibleActions.Length; if (nCardActions > 0) { items.AddRange(visibleActions.Select(action => CreateActionMenuItem(action, CardActionClicked))); if (group.Controller == null) items.Add(new Separator()); } } if (card.Controller != Player.LocalPlayer) { var item = new MenuItem { Header = "Take control" }; item.Click += delegate { card.TakeControl(); }; items.Add(item); return items; } else { if (group.Controller == null) items.Add(CreateCardPassToItem()); } if (def.Id == Program.GameEngine.Definition.Table.Id) { var ami = new MenuItem() { Header = card.Anchored ? "Unanchor" : "Anchor" }; ami.Click += (sender, args) => ContextCard.SetAnchored(false, card.Anchored == false); items.Add(ami); } if (!card.FaceUp) { var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" }; peekItem.Click += delegate { ContextCard.Peek(); }; items.Add(peekItem); } return items; }
internal virtual void ShowContextMenu(Card card) { if (Player.LocalPlayer.Spectator) return; // Modify selection if (card == null || !card.Selected) Selection.Clear(); var menuItems = new CompositeCollection(); ContextGroup = group; ContextMenu = new ContextMenu {ItemsSource = menuItems, Tag = card}; // card has to captured somehow, otherwise it may be overwritten before released in the OnClosed handler, e.g. when rightclicking on a card, then directly right-clicking on another card. ContextMenu.Opened += (sender, args) => { ContextGroup.KeepControl(); var c = ((ContextMenu) sender).Tag as Card; if (c != null) c.KeepControl(); }; ContextMenu.Closed += (sender, args) => { ContextGroup.ReleaseControl(); var c = ((ContextMenu) sender).Tag as Card; if (c != null) c.ReleaseControl(); }; ContextCard = card; menuItems.Clear(); if (card != null) { //var cardMenuItems = await CreateCardMenuItems(card, group.Definition); var cardMenuItems = CreateCardMenuItems(card, group.Definition); var container = new CollectionContainer { Collection = cardMenuItems }; menuItems.Add(container); } if (ShouldShowGroupActions(card)) { var container = new CollectionContainer { Collection = CreateGroupMenuItems(group.Definition) }; menuItems.Add(container); } //else // Group is being shuffled // return; ContextMenu.IsOpen = false; // Required to trigger the ReleaseControl calls if the ContextMenu was already open ContextMenu.UpdateLayout(); // Required if the ContextMenu was already open ContextMenu.IsOpen = true; ContextMenu.FontFamily = groupFont; ContextMenu.FontSize = fontsize; }
internal Card(Player owner, int id, ulong key, DataNew.Entities.Card model, bool mySecret) : base(owner) { _id = id; Type = new CardIdentity(id) {Key = key, Model = model.Clone() , MySecret = mySecret}; // var _definition = def; lock (All) { if (All.ContainsKey(id)) All[id] = this; else All.Add(id, this); } _alternateOf = null; numberOfSwitchWithAlternatesNotPerformed = 0; _isAlternateImage = false; _cardMoved = false; }
//Temporarily store group visibility information for LoadDeck. //bug (google) #20 public void LoadDeck(IDeck deck) { var def = Program.GameEngine.Definition; int nCards = deck.CardCount(); var ids = new int[nCards]; var keys = new ulong[nCards]; var cards = new Card[nCards]; var groups = new Play.Group[nCards]; var gtmps = new List <GrpTmp>(); //for temp groups visibility int j = 0; foreach (ISection section in deck.Sections) { DeckSection sectionDef = null; sectionDef = section.Shared ? def.SharedDeckSections[section.Name] : def.DeckSections[section.Name]; if (sectionDef == null) { throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file."); } var player = section.Shared ? Player.GlobalPlayer : Player.LocalPlayer; Play.Group group = player.Groups.First(x => x.Name == sectionDef.Group); //In order to make the clients know what the card is (if visibility is set so that they can see it), //we have to set the visibility to Nobody, and then after the cards are sent, set the visibility back //to what it was. //bug (google) #20 var gt = new GrpTmp(group, group.Visibility, group.Viewers.ToList()); if (!gtmps.Contains(gt)) { gtmps.Add(gt); group.SetVisibility(false, false); } foreach (IMultiCard element in section.Cards) { DataNew.Entities.Card mod = Definition.GetCardById(element.Id); for (int i = 0; i < element.Quantity; i++) { //for every card in the deck, generate a unique key for it, ID for it ulong key = ((ulong)Crypto.PositiveRandom()) << 32 | element.Id.Condense(); int id = GenerateCardId(); ids[j] = id; keys[j] = Crypto.ModExp(key); groups[j] = group; var card = new Card(player, id, key, mod, true); cards[j++] = card; group.AddAt(card, group.Count); } // Load images in the background string pictureUri = element.GetPicture(); Dispatcher.CurrentDispatcher.BeginInvoke( new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap), DispatcherPriority.ApplicationIdle, pictureUri); } } Program.Client.Rpc.LoadDeck(ids, keys, groups); //reset the visibility to what it was before pushing the deck to everybody. //bug (google) #20 foreach (GrpTmp g in gtmps) { switch (g.Visibility) { case GroupVisibility.Everybody: g.Group.SetVisibility(true, false); break; case GroupVisibility.Nobody: g.Group.SetVisibility(false, false); break; default: foreach (Player p in g.Viewers) { g.Group.AddViewer(p, false); } break; } } gtmps.Clear(); gtmps.TrimExcess(); }
private void CardChangedHandler(object sender, DependencyPropertyChangedEventArgs e) { if (Card != null) Card.PropertyChanged -= PropertyChangeHandler; Card = DataContext as Card; if (Card == null) return; bool oldIsUp = IsUp; IsUp = IsAlwaysUp || Card.FaceUp; // If IsUp changes, it automatically updates the picture. // Otherwise do it explicitely if (oldIsUp == IsUp) SetDisplayedPicture(Card.GetBitmapImage(IsUp)); //SetDisplayedPicture(Card.GetPicture(IsUp)); IsAnchored = Card.Anchored; UpdateInvertedTransform(); Card.PropertyChanged += PropertyChangeHandler; InvalidateMeasure(); InvalidateVisual(); OnPropertyChanged("ActualWidth"); OnPropertyChanged("ActualHeight"); AnimateOrientation(Card.Orientation); }
private void RemoveCardHandler(object sender, RoutedEventArgs e) { if (Card == null) return; // Three cases are possible. // 1. The container is unloaded (e.g. one closes a GroupWindow). // This case is recognizable because GroupControl.IsLoaded is false. // We have to remove our listeners. // 2. The card is been moved to another group. // This is recognizable because GroupControl is null. // We have to remove our listeners. // 3. The card index changes (e.g. it's moved to top/bottom of a pile). // In this case WPF seems to unload and then reload the control at the correct position. // But in some weird cases WPF seems to call Unload WITHOUT a matching Load, // although the control ends up in the visual tree. E.g. when Moving several cards to the // top of a pile at once, with the GroupWindow open. // We can recognize this case because GroupControl.IsLoaded is true. // In this case we *keep* the listeners attached! GroupControl groupCtrl = GroupControl; if (groupCtrl != null && groupCtrl.IsLoaded) return; Card.PropertyChanged -= PropertyChangeHandler; img = null; this.DisplayedPicture = null; Card = null; }
public void Remove(Card card) { var c = Cards.FirstOrDefault(x => x.Id == card.Id); if (c == null) return; this.Client.Delete(c); this.Client.Commit(); }
public object Deserialize(string fileName) { //var timer = new Stopwatch(); //timer.Start(); var ret = new Set(); var directory = new FileInfo(fileName).Directory.FullName; using (var fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { var settings = new XmlReaderSettings(); settings.Schemas.Add(SetSchema); var doc = XDocument.Load(fs); doc.Validate(settings.Schemas, (a, b) => { Console.WriteLine(b.Exception); }); ret.Cards = new List<Card>(); var root = doc.Element("set"); ret.Id = new Guid(root.Attribute("id").Value); ret.Name = root.Attribute("name").Value; ret.Filename = fileName; ret.GameId = new Guid(root.Attribute("gameId").Value); ret.Cards = new List<Card>(); ret.GameVersion = new Version(root.Attribute("gameVersion").Value); ret.Markers = new List<Marker>(); ret.Packs = new List<Pack>(); ret.Version = new Version(root.Attribute("version").Value); ret.PackageName = ""; ret.InstallPath = directory; ret.DeckPath = Path.Combine(ret.InstallPath, "Decks"); ret.PackUri = Path.Combine(ret.InstallPath, "Cards"); var gameImageInstallPath = Path.Combine(Config.Instance.Paths.ImageDatabasePath, ret.GameId.ToString()); ret.ImageInstallPath = Path.Combine(gameImageInstallPath, "Sets", ret.Id.ToString()); ret.ImagePackUri = Path.Combine(ret.ImageInstallPath, "Cards"); ret.ProxyPackUri = Path.Combine(ret.ImagePackUri, "Proxies"); if (!Directory.Exists(ret.PackUri)) Directory.CreateDirectory(ret.PackUri); if (!Directory.Exists(ret.ImagePackUri)) Directory.CreateDirectory(ret.ImagePackUri); if (!Directory.Exists(ret.ProxyPackUri)) Directory.CreateDirectory(ret.ProxyPackUri); var game = DbContext.Get().Games.First(x => x.Id == ret.GameId); foreach (var c in doc.Document.Descendants("card")) { var card = new Card(new Guid(c.Attribute("id").Value), ret.Id, c.Attribute("name").Value,c.Attribute("id").Value, "",game.CardSizes["Default"],new Dictionary<string, CardPropertySet>()); //var card = new Card // { // Id = new Guid(c.Attribute("id").Value), // Name = c.Attribute("name").Value, // SetId = ret.Id, // Properties = new Dictionary<string, CardPropertySet>(), // ImageUri = c.Attribute("id").Value, // Alternate = "", // Size = game.CardSizes["Default"] // }; var cs = c.Attribute("size"); if (cs != null) { if(game.CardSizes.ContainsKey(cs.Value) == false) throw new UserMessageException(Octgn.Library.Localization.L.D.Exception__BrokenGameContactDev_Format, game.Name); card.Size = game.CardSizes[cs.Value]; } var defaultProperties = new CardPropertySet(); defaultProperties.Type = ""; defaultProperties.Properties = new Dictionary<PropertyDef, object>(); foreach (var p in c.Descendants("property").Where(x => x.Parent.Name == "card")) { var pd = game.CustomProperties.FirstOrDefault(x => x.Name == p.Attribute("name").Value); if (pd == null) { throw new UserMessageException(Octgn.Library.Localization.L.D.Exception__BrokenGameContactDev_Format, game.Name); } var newpd = pd.Clone() as PropertyDef; defaultProperties.Properties.Add(newpd, p.Attribute("value").Value); } foreach (var cp in game.CustomProperties) { if (!defaultProperties.Properties.ContainsKey(cp)) { var cpnew = cp.Clone() as PropertyDef; cpnew.IsUndefined = true; defaultProperties.Properties.Add(cpnew, ""); } } var np = new PropertyDef() { Hidden = false, Name = "Name", Type = PropertyType.String, TextKind = PropertyTextKind.FreeText, IgnoreText = false, IsUndefined = false }; if (defaultProperties.Properties.ContainsKey(np)) defaultProperties.Properties.Remove(np); defaultProperties.Properties.Add(np, card.Name); card.Properties.Add("", defaultProperties); // Add all of the other property sets foreach (var a in c.Descendants("alternate")) { var propset = new CardPropertySet(); propset.Properties = new Dictionary<PropertyDef, object>(); propset.Type = a.Attribute("type").Value; var thisName = a.Attribute("name").Value; foreach (var p in a.Descendants("property")) { var pd = game.CustomProperties.First(x => x.Name.Equals(p.Attribute("name").Value, StringComparison.InvariantCultureIgnoreCase)); var newprop = pd.Clone() as PropertyDef; var val = p.Attribute("value").Value; propset.Properties.Add(newprop, val); } foreach (var cp in game.CustomProperties) { if (!propset.Properties.ContainsKey(cp)) { var cpnew = cp.Clone() as PropertyDef; cpnew.IsUndefined = true; propset.Properties.Add(cpnew, ""); } } var np2 = new PropertyDef() { Hidden = false, Name = "Name", Type = PropertyType.String, TextKind = PropertyTextKind.FreeText, IgnoreText = false, IsUndefined = false }; if (propset.Properties.ContainsKey(np2)) propset.Properties.Remove(np2); propset.Properties.Add(np2, thisName); card.Properties.Add(propset.Type, propset); } (ret.Cards as List<Card>).Add(card); } foreach (var p in doc.Document.Descendants("pack")) { var pack = new Pack(); pack.Id = new Guid(p.Attribute("id").Value); pack.Name = p.Attribute("name").Value; pack.Definition = DeserializePack(p.Elements()); pack.SetId = ret.Id; (ret.Packs as List<Pack>).Add(pack); } foreach (var m in doc.Document.Descendants("marker")) { var marker = new Marker(); marker.Id = new Guid(m.Attribute("id").Value); marker.Name = m.Attribute("name").Value; var mpathd = new DirectoryInfo(Path.Combine(directory, "Markers")); var mpath = mpathd.Exists == false ? null : mpathd.GetFiles(marker.Id.ToString() + ".*", SearchOption.TopDirectoryOnly).First(); marker.IconUri = mpath == null ? null : Path.Combine(directory, "Markers", mpath.FullName); (ret.Markers as List<Marker>).Add(marker); } } if (ret.Cards == null) ret.Cards = new Card[0]; if (ret.Markers == null) ret.Markers = new Marker[0]; if (ret.Packs == null) ret.Packs = new Pack[0]; //Console.WriteLine(timer.ElapsedMilliseconds); return ret; }
public void ExecuteDefaultAction(Card card) { if (_defaultCardAction != null) { if (!card.TryToManipulate()) return; group.KeepControl(); card.KeepControl(); if (_defaultCardAction.Execute != null) ScriptEngine.ExecuteOnCards(_defaultCardAction.Execute, Selection.ExtendToSelection(card)); else if (_defaultCardAction.BatchExecute != null) ScriptEngine.ExecuteOnBatch(_defaultCardAction.BatchExecute, Selection.ExtendToSelection(card)); group.ReleaseControl(); card.ReleaseControl(); } else ExecuteDefaultAction(); }