using DominionBase; using DominionBase.Cards; using DominionBase.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; using System.Windows.Shapes; namespace Dominion.NET_WPF { /// /// Interaction logic for ToolTipCard.xaml /// public partial class ToolTipCard : UserControl { private bool _isSetup; public ToolTipCard() { InitializeComponent(); } private void SetupDisplay() { if (Card == null) return; var fullCardFound = false; if (WMain.Settings.UseCustomToolTips) { iFullCard.Visibility = Visibility.Visible; dpCardFace.Visibility = Visibility.Hidden; var repo = Caching.ImageRepository.Acquire(); var im = repo.GetBitmapImage(Card.ImageName, "full"); if (im != null) { iFullCard.Source = im; fullCardFound = true; } Caching.ImageRepository.Release(); } if (!fullCardFound) { iFullCard.Visibility = Visibility.Hidden; dpCardFace.Visibility = Visibility.Visible; tbCardName.Text = string.Empty; Run rName = null; foreach (var letter in Card.Name) { if (rName == null || char.IsUpper(rName.Text[0]) != char.IsUpper(letter)) { if (rName != null) tbCardName.Inlines.Add(rName); rName = new Run {FontSize = char.IsUpper(letter) ? 14 : 11}; } rName.Text += char.ToUpper(letter); } if (rName != null) tbCardName.Inlines.Add(rName); var repo = Caching.ImageRepository.Acquire(); var im = repo.GetBitmapImage(Card.ImageName, "medium"); imCardLarge.Source = im; if (Card.Edition == Edition.Second) im = repo.GetBitmapImage($"{Card.Source}-{Card.Edition}", "set") ?? repo.GetBitmapImage(Card.Source.ToString(), "set"); else im = (repo.GetBitmapImage(Card.ImageName.Replace(" ", "").Replace("'", ""), "set") ?? repo.GetBitmapImage($"{Card.Source}-{Card.Edition}", "set")) ?? repo.GetBitmapImage(Card.Source.ToString(), "set"); imSource.Source = im; Caching.ImageRepository.Release(); var categories = new List(); if (Card.Category.HasFlag(Categories.Action)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Action)); if (Card.Category.HasFlag(Categories.Curse)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Curse)); if (Card.Category.HasFlag(Categories.Treasure)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Treasure)); if (Card.Category.HasFlag(Categories.Night)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Night)); // Attack comes *after* Duration for Night cards for some reason if (Card.Category.HasFlag(Categories.Attack) && !Card.Category.HasFlag(Categories.Night)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Attack)); if (Card.Category.HasFlag(Categories.Duration)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Duration)); // Attack comes *after* Duration for Night cards for some reason if (Card.Category.HasFlag(Categories.Attack) && Card.Category.HasFlag(Categories.Night)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Attack)); if (Card.Category.HasFlag(Categories.Knight)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Knight)); if (Card.Category.HasFlag(Categories.Reserve)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Reserve)); if (Card.Category.HasFlag(Categories.Victory)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Victory)); if (Card.Category.HasFlag(Categories.Reaction)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Reaction)); if (Card.Category.HasFlag(Categories.Prize)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Prize)); if (Card.Category.HasFlag(Categories.Shelter)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Shelter)); if (Card.Category.HasFlag(Categories.Looter)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Looter)); if (Card.Category.HasFlag(Categories.Ruins)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Ruins)); if (Card.Category.HasFlag(Categories.Traveller)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Traveller)); if (Card.Category.HasFlag(Categories.Castle)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Castle)); if (Card.Category.HasFlag(Categories.Gathering)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Gathering)); if (Card.Category.HasFlag(Categories.Spirit)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Spirit)); if (Card.Category.HasFlag(Categories.Heirloom)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Heirloom)); if (Card.Category.HasFlag(Categories.Fate)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Fate)); if (Card.Category.HasFlag(Categories.Boon)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Boon)); if (Card.Category.HasFlag(Categories.State)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.State)); if (Card.Category.HasFlag(Categories.Doom)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Doom)); if (Card.Category.HasFlag(Categories.Hex)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Hex)); if (Card.Category.HasFlag(Categories.Zombie)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Zombie)); if (Card.Category.HasFlag(Categories.Command)) categories.Add(DominionBase.ResourcesHelper.Get(Categories.Command)); tbTreasureValueLeft.Inlines.Clear(); tbTreasureValueRight.Inlines.Clear(); tbCardCost.Inlines.Clear(); //tbCardCostModified.Inlines.Clear(); spCardText.Children.Clear(); if (Card.Category.HasFlag(Categories.Treasure) && !Card.Category.HasFlag(Categories.Action) && Card is Card) { lblTreasureValueLeft.Visibility = lblTreasureValueRight.Visibility = Visibility.Visible; var tbTreasureValue = (TextBlock)Utilities.RenderText(((Card)Card).Benefit.Currency.ToStringInline(), NET_WPF.RenderSize.Small, false)[0]; while (tbTreasureValue.Inlines.Any()) tbTreasureValueLeft.Inlines.Add(tbTreasureValue.Inlines.ElementAt(0)); tbTreasureValue = (TextBlock)Utilities.RenderText(((Card)Card).Benefit.Currency.ToStringInline(), NET_WPF.RenderSize.Small, false)[0]; while (tbTreasureValue.Inlines.Any()) tbTreasureValueRight.Inlines.Add(tbTreasureValue.Inlines.ElementAt(0)); } else { lblTreasureValueLeft.Visibility = lblTreasureValueRight.Visibility = Visibility.Hidden; } gCardText.Background = Brushes.Transparent; if (Card.Category.HasFlag(Categories.Traveller)) { repo = Caching.ImageRepository.Acquire(); im = repo.GetBitmapImage("traveller", string.Empty); if (im != null) { var brush = new ImageBrush(im) { Stretch = Stretch.None, TileMode = TileMode.None }; gCardText.Background = brush; } Caching.ImageRepository.Release(); } var tbTemp = (TextBlock)Utilities.RenderText(Card.BaseCost.ToString(), NET_WPF.RenderSize.Small, false)[0]; while (tbTemp.Inlines.Any()) tbCardCost.Inlines.Add(tbTemp.Inlines.ElementAt(0)); if (Card.BaseCost.Special) { var special = new Run("*") {FontWeight = FontWeights.Bold}; tbCardCost.Inlines.Add(special); } if (Card.BaseCost.CanOverpay) { var canOverpay = new Run("+") {FontWeight = FontWeights.Bold}; tbCardCost.Inlines.Add(canOverpay); } //var currentCost = Card is ICost ? WMain.Game.ComputeCost((ICost)Card) : Card.BaseCost; //if (currentCost != Card.BaseCost) //{ // Brush costColorModified = null; // if (currentCost > Card.BaseCost) // costColorModified = Brushes.Red; // else if (currentCost < Card.BaseCost) // costColorModified = Brushes.Green; // var tbTempModified = (TextBlock)Utilities.RenderText(currentCost.ToString(), NET_WPF.RenderSize.Small, false, costColorModified)[0]; // while (tbTempModified.Inlines.Any()) // tbCardCostModified.Inlines.Add(tbTempModified.Inlines.ElementAt(0)); // if (Card.BaseCost.Special) // { // var special = new Run("*") { FontWeight = FontWeights.Bold }; // tbCardCostModified.Inlines.Add(special); // } // if (Card.BaseCost.CanOverpay) // { // var canOverpay = new Run("+") { FontWeight = FontWeights.Bold }; // tbCardCostModified.Inlines.Add(canOverpay); // } // gBottomAreaModified.Visibility = Visibility.Visible; // //Height = 342; //} //else //{ // //Height = 320; // gBottomAreaModified.Visibility = Visibility.Collapsed; //} tbType.Text = string.Empty; Run rType = null; foreach (var letter in string.Join(" - ", categories.ToArray())) { if (rType == null || char.IsUpper(rType.Text[0]) != char.IsUpper(letter)) { if (rType != null) tbType.Inlines.Add(rType); rType = new Run {FontSize = char.IsUpper(letter) ? 12 : 10}; } rType.Text += char.ToUpper(letter); } if (rType != null) tbType.Inlines.Add(rType); if (!string.IsNullOrEmpty(Card.SetupText)) { bSetupBanner.Visibility = Visibility.Visible; bSetupBanner.Background = Caching.BrushRepository.GetBackgroundBrush(Categories.Treasure, true); tbSetup.Text = string.Empty; var tbSetupTemp = (TextBlock)Utilities.RenderText(Card.SetupText, NET_WPF.RenderSize.Small, false)[0]; while (tbSetupTemp.Inlines.Any()) tbSetup.Inlines.Add(tbSetupTemp.Inlines.ElementAt(0)); } var category = Card.Category; //if (this.Card is DominionBase.Cards.Card) // category = ((DominionBase.Cards.Card)this.Card).PhysicalCategory; lblCardName.Background = bBottomArea.Background = Caching.BrushRepository.GetBackgroundBrush(category, true); rBackground.Fill = Caching.BrushRepository.GetBackgroundBrush(category); lblCardName.Foreground = lblType.Foreground = Caching.BrushRepository.GetForegroundBrush(category, true, lblCardName.Background); if (category.HasFlag(Categories.Reaction)) tbCardName.Effect = tbType.Effect = Caching.DropShadowRepository.GetDSE(8, Colors.White, 1d); if (lblCardName.Foreground.CanFreeze) lblCardName.Foreground.Freeze(); if (lblType.Foreground.CanFreeze) lblType.Foreground.Freeze(); if (lblCardCost.Foreground.CanFreeze) lblCardCost.Foreground.Freeze(); var textColor = Caching.BrushRepository.GetForegroundBrush(category); var text = Card.Text.Split(new[] { "
" }, StringSplitOptions.RemoveEmptyEntries); for (var index = 0; index < text.Length; index++) { if (text[index].StartsWith(Environment.NewLine)) text[index] = text[index].Substring(Environment.NewLine.Length); if (index > 0) { var newLine = new Line { Stretch = Stretch.Fill, Stroke = Brushes.Black, StrokeThickness = 2, X2 = 1, Margin = new Thickness(20, 6, 20, 6) }; spCardText.Children.Add(newLine); } var t = text[index]; var elements = Utilities.RenderText(t, (Card.Location == Location.General ? NET_WPF.RenderSize.ExtraLarge : NET_WPF.RenderSize.Small), false, textColor: textColor); foreach (var tb in elements.OfType()) { tb.HorizontalAlignment = HorizontalAlignment.Center; tb.VerticalAlignment = VerticalAlignment.Center; tb.Margin = new Thickness(10, 0, 10, 0); tb.Padding = new Thickness(0); tb.TextWrapping = TextWrapping.Wrap; tb.TextAlignment = TextAlignment.Center; } elements.ForEach(e => spCardText.Children.Add(e)); } } //_IsSetup = true; } public static readonly DependencyProperty ICardProperty = DependencyProperty.Register("Card", typeof(IDisplayable), typeof(ToolTipCard), new PropertyMetadata(null)); public IDisplayable Card { get { return (IDisplayable)GetValue(ICardProperty); } set { if (((Card == null || value == null) && Card != value) || (Card != null && value != null && Card.Name != value.Name)) _isSetup = false; SetValue(ICardProperty, value); if (IsVisible) SetupDisplay(); } } private delegate void IsVisibleChanged_Delegate(object sender, DependencyPropertyChangedEventArgs e); private void ToolTipCard_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (Dispatcher.CheckAccess()) { if (((bool)e.NewValue) && !_isSetup) SetupDisplay(); } else { Dispatcher.BeginInvoke(new IsVisibleChanged_Delegate(ToolTipCard_IsVisibleChanged), System.Windows.Threading.DispatcherPriority.Normal, sender, e); } } } }