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 ucPlayerTurn.xaml /// public partial class ucPlayerTurn : LogSection { private int _CurrentInset = 0; private DominionBase.Players.Player _Player = null; public DominionBase.Players.Player Player { get { return _Player; } private set { _Player = value; } } private DominionBase.Players.Player _PreviousLinePlayer = null; public override Boolean IsExpanded { get { return expTurn.IsExpanded; } set { expTurn.IsExpanded = value; } } public ucPlayerTurn() { InitializeComponent(); this.spContainer = spArea; } public override void TearDown() { base.TearDown(); _Player = null; _PreviousLinePlayer = null; } protected override void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. } // Call the appropriate methods to clean up // unmanaged resources here. // If disposing is false, // only the following code is executed. //spContainer.Children.Clear(); _Player = null; _PreviousLinePlayer = null; // Note disposing has been done. disposed = true; } } public override void Push() { _CurrentInset++; } public override void Pop() { _CurrentInset--; } public override void End() { } private String DepthPrefix { get { StringBuilder sb = new StringBuilder(); for (int c = 0; c < _CurrentInset; c++) sb.Append("... "); return sb.ToString(); } } public override void New(DominionBase.Players.Player player, DominionBase.Cards.Card grantedBy) { this.Player = player; _CurrentInset = 0; PlayerSettings ps = wMain.Settings.PlayerSettings.Find(p => p.Name == player.Name); if (ps != null) { ColorHls hlsValue = HLSColor.RgbToHls(ps.UIColor); this.Background = new SolidColorBrush(HLSColor.HlsToRgb(hlsValue.H, Math.Min(1d, hlsValue.L * 1.125), hlsValue.S * 0.95, hlsValue.A)); this.BorderBrush = new SolidColorBrush(HLSColor.HlsToRgb(hlsValue.H, hlsValue.L * 0.25, hlsValue.S, hlsValue.A)); } Utilities.Log(this.LogFile, String.Format("{0} starting turn{1}", player, grantedBy == null ? "" : String.Format(" from {0}", grantedBy.Name))); DockPanel dp = new DockPanel(); TextBlock tbPlayerName = new TextBlock(); tbPlayerName.Text = player.Name; tbPlayerName.FontWeight = FontWeights.Bold; DockPanel.SetDock(tbPlayerName, Dock.Left); dp.Children.Add(tbPlayerName); tbPlayerName = new TextBlock(); tbPlayerName.Text = " starting turn"; DockPanel.SetDock(tbPlayerName, Dock.Left); dp.Children.Add(tbPlayerName); if (grantedBy != null) { TextBlock tbGrantedBy = new TextBlock(); tbGrantedBy.Text = " granted by "; DockPanel.SetDock(tbGrantedBy, Dock.Left); dp.Children.Add(tbGrantedBy); ucCardIcon icon = CardIconUtilities.CreateCardIcon(grantedBy); DockPanel.SetDock(icon, Dock.Left); dp.Children.Add(icon); TextBlock tbBlank = new TextBlock(); DockPanel.SetDock(tbBlank, Dock.Left); dp.Children.Add(tbBlank); } expTurn.Header = dp; } public override void Log(DominionBase.Players.Player player, params Object[] items) { StringBuilder sbFullLine = new StringBuilder(); DockPanel dp = new DockPanel(); dp.LastChildFill = true; sbFullLine.Append(this.DepthPrefix); //SolidColorBrush background = Brushes.Transparent; if (player != this.Player) { PlayerSettings ps = wMain.Settings.PlayerSettings.Find(p => p.Name == player.Name); if (ps != null) { ColorHls hlsValue = HLSColor.RgbToHls(ps.UIColor); dp.Background = new SolidColorBrush(HLSColor.HlsToRgb(hlsValue.H, Math.Min(1d, hlsValue.L * 1.1), hlsValue.S, hlsValue.A)); } } DominionBase.Players.Player linePlayer = null; 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).VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(elem, Dock.Left); dp.Children.Add(elem); } sbFullLine.Append(item); } else if (item is DominionBase.Players.Player) { linePlayer = item as DominionBase.Players.Player; TextBlock tbLine = new TextBlock(); tbLine.Text = linePlayer.Name; tbLine.VerticalAlignment = System.Windows.VerticalAlignment.Center; if (linePlayer != this.Player) tbLine.FontWeight = FontWeights.Bold; DockPanel.SetDock(tbLine, Dock.Left); dp.Children.Add(tbLine); sbFullLine.Append(linePlayer.Name); } else if (item is DominionBase.ICard) { ucCardIcon icon = CardIconUtilities.CreateCardIcon(item as DominionBase.ICard); icon.VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(icon, Dock.Left); dp.Children.Add(icon); sbFullLine.Append((item as DominionBase.ICard).Name); } else if (item is IEnumerable) { foreach (ucCardIcon icon in CardIconUtilities.CreateCardIcons(item as IEnumerable)) { icon.VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(icon, Dock.Left); dp.Children.Add(icon); if (icon.Count == 1) sbFullLine.Append(icon.Card.Name); else sbFullLine.AppendFormat("{0}x {1}", icon.Count, icon.Card.Name); TextBlock tbLine = new TextBlock(); tbLine.Text = ", "; tbLine.VerticalAlignment = System.Windows.VerticalAlignment.Center; DockPanel.SetDock(tbLine, Dock.Left); dp.Children.Add(tbLine); sbFullLine.Append(", "); } if ((item as IEnumerable).Count() > 0) { dp.Children.RemoveAt(dp.Children.Count - 1); sbFullLine = sbFullLine.Remove(sbFullLine.Length - 2, 2); } } } if (dp.Background != null && dp.Children.Count > 0) { if (dp.Children.Count == 1) { if (dp.Children[0] is TextBlock) ((TextBlock)dp.Children[0]).Padding = new Thickness(2, 1, 2, 1); else if (dp.Children[0] is ucCardIcon) ((ucCardIcon)dp.Children[0]).Padding = new Thickness(2, 1, 2, 1); } else { if (dp.Children[0] is TextBlock) ((TextBlock)dp.Children[0]).Padding = new Thickness(2, 1, 0, 1); else if (dp.Children[0] is ucCardIcon) ((ucCardIcon)dp.Children[0]).Padding = new Thickness(2, 1, 0, 1); if (dp.Children[dp.Children.Count - 1] is TextBlock) ((TextBlock)dp.Children[dp.Children.Count - 1]).Padding = new Thickness(0, 1, 2, 1); else if (dp.Children[dp.Children.Count - 1] is ucCardIcon) ((ucCardIcon)dp.Children[dp.Children.Count - 1]).Padding = new Thickness(0, 1, 2, 1); } } // Need something to fill the remaining gap Grid g = new Grid(); g.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; dp.Children.Add(g); Utilities.Log(this.LogFile, sbFullLine.ToString()); TreeViewItem tvi = new TreeViewItem(); int level = this._CurrentInset; ItemCollection lItems = tvArea.Items; while (level > 0) { TreeViewItem tviParent = lItems[lItems.Count - 1] as TreeViewItem; tviParent.IsExpanded = true; lItems = tviParent.Items; level--; } if (dp.Background == null) { tvi.Header = dp; tvi.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; } else { Border bDockPanel = new Border(); bDockPanel.BorderBrush = Brushes.Black; bDockPanel.BorderThickness = new Thickness(1, 1, 1, 1); bDockPanel.Child = dp; tvi.Header = bDockPanel; tvi.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; if (lItems.Count > 0 && ((TreeViewItem)lItems[lItems.Count - 1]).Header is Border) { Border bPrevious = ((TreeViewItem)lItems[lItems.Count - 1]).Header as Border; if (_PreviousLinePlayer == linePlayer) { bPrevious.BorderThickness = new Thickness(bPrevious.BorderThickness.Left, bPrevious.BorderThickness.Top, bPrevious.BorderThickness.Right, 0); bDockPanel.BorderThickness = new Thickness(bDockPanel.BorderThickness.Left, 0, bDockPanel.BorderThickness.Right, bDockPanel.BorderThickness.Bottom); } } } lItems.Add(tvi); dp.BringIntoView(); _PreviousLinePlayer = linePlayer; } private void tvArea_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { if (sender is TreeView && !e.Handled) { e.Handled = true; MouseWheelEventArgs mwea = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta); mwea.RoutedEvent = UIElement.MouseWheelEvent; mwea.Source = sender; (((Control)sender).Parent as UIElement).RaiseEvent(mwea); } } } }