using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Dominion.NET_WPF.Controls.GameLog
{
///
/// Interaction logic for ucGameMessage.xaml
///
public partial class ucGameMessage : LogSection
{
public ucGameMessage()
{
InitializeComponent();
this.spContainer = spArea;
}
public override Boolean IsExpanded { get { return expTurn.IsExpanded; } set { expTurn.IsExpanded = value; } }
public override void New(String title)
{
DockPanel dp = new DockPanel();
TextBlock tbTitle = new TextBlock();
tbTitle.Text = title;
DockPanel.SetDock(tbTitle, Dock.Left);
dp.Children.Add(tbTitle);
expTurn.Header = dp;
}
public override void TearDown()
{
base.TearDown();
spArea.Children.Clear();
}
public override void Log(params Object[] items)
{
StringBuilder sbFullLine = new StringBuilder();
DockPanel dp = new DockPanel();
SolidColorBrush background = Brushes.Transparent;
foreach (Object item in items)
{
if (item is String)
{
foreach (UIElement elem in Utilities.RenderText(item as String, NET_WPF.RenderSize.Tiny, true))
{
if (elem is TextBlock)
(elem as TextBlock).Background = background;
DockPanel.SetDock(elem, Dock.Left);
dp.Children.Add(elem);
}
sbFullLine.Append((item as String).Replace("", "*").Replace("", "*"));
}
else if (item is DominionBase.Players.Player)
{
TextBlock tbLine = new TextBlock();
tbLine.Text = (item as DominionBase.Players.Player).Name;
tbLine.Background = background;
tbLine.FontWeight = FontWeights.Bold;
DockPanel.SetDock(tbLine, Dock.Left);
dp.Children.Add(tbLine);
sbFullLine.Append((item as DominionBase.Players.Player).Name);
}
else if (item is DominionBase.ICard)
{
ucCardIcon icon = CardIconUtilities.CreateCardIcon(item as DominionBase.ICard);
icon.Background = background;
DockPanel.SetDock(icon, Dock.Left);
dp.Children.Add(icon);
sbFullLine.Append((item as DominionBase.ICard).Name);
}
else if (item is IEnumerable)
{
foreach (UserControl uc in CardIconUtilities.CreateCardIcons(item as IEnumerable))
{
ucCardIcon icon = uc as ucCardIcon;
uc.Background = background;
DockPanel.SetDock(uc, Dock.Left);
dp.Children.Add(uc);
if (uc is ucCardIcon)
{
if ((uc as ucCardIcon).Count == 1)
sbFullLine.Append(icon.Card.Name);
else
sbFullLine.AppendFormat("{0}x {1}", (uc as ucCardIcon).Count, (uc as ucCardIcon).Card.Name);
TextBlock tbLine = new TextBlock();
tbLine.Text = ", ";
tbLine.Background = background;
DockPanel.SetDock(tbLine, Dock.Left);
dp.Children.Add(tbLine);
sbFullLine.Append(", ");
}
else if (uc is ucTokenIcon)
{
sbFullLine.AppendFormat("({0})", (uc as ucTokenIcon).Token.LongDisplayString);
}
}
if ((item as IEnumerable).Count() > 0)
{
dp.Children.RemoveAt(dp.Children.Count - 1);
sbFullLine = sbFullLine.Remove(sbFullLine.Length - 2, 2);
}
}
}
TextBlock g = new TextBlock();
g.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
g.Background = background;
DockPanel.SetDock(g, Dock.Left);
dp.Children.Add(g);
Utilities.Log(this.LogFile, sbFullLine.ToString());
spArea.Children.Add(dp);
dp.BringIntoView();
}
}
}