private FrameworkElement CreateButton(Boolean isICard, ICommand command, Boolean isRequired) { if (isICard) { ucICardButton icb = new ucICardButton(); icb.ICardButtonClick += new RoutedEventHandler(toggleButton_Checked); icb.IsOrdered = Choice.IsOrdered; return(icb); } else { ToggleButton tb = new ToggleButton() { Margin = new Thickness(5, 0, 5, 0), Height = double.NaN, Width = double.NaN, MinHeight = 40, MinWidth = 40, MaxHeight = 100, MaxWidth = 200, Background = (VisualBrush)FindResource("NormalBrush"), VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch }; Border border = new Border() { Padding = new Thickness(10, 0, 10, 0) }; tb.Content = border; WrapPanel wp = new WrapPanel() { Orientation = Orientation.Horizontal, VerticalAlignment = System.Windows.VerticalAlignment.Center }; border.Child = wp; if (isRequired) { border.BorderThickness = new Thickness(2); border.BorderBrush = Brushes.Crimson; } else { tb.ToolTip = "Optional"; } wp.Children.Add(new TextBlock() { TextWrapping = TextWrapping.Wrap }); wp.Children.Add(new AccessText() { Width = 0 }); wp.Children.Add(new TextBlock() { TextWrapping = TextWrapping.Wrap }); if (command == null) { tb.Click += new RoutedEventHandler(toggleButton_Checked); } else { tb.Command = command; } return(tb); } }
private static void OnICardChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ucICardButton ctrl = d as ucICardButton; ctrl.ICard = (DominionBase.ICard)e.NewValue; }
void toggleButton_Checked(object sender, RoutedEventArgs e) { bool? isChecked = false; Object tag = null; if (sender is ToggleButton) { ToggleButton tb = sender as ToggleButton; isChecked = tb.IsChecked; tag = tb.Tag; } else if (sender is ucICardButton) { ucICardButton icb = sender as ucICardButton; isChecked = icb.IsChecked; tag = icb.Tag; } bOK.IsEnabled = false; switch (Choice.ChoiceType) { case DominionBase.ChoiceType.Options: if (this.ChoiceResult == null) { this.ChoiceResult = new DominionBase.ChoiceResult(new List <String>()); } String option = ((DominionBase.Option)tag).Text; if (this.Choice.Maximum == 1) { foreach (ToggleButton chkdToggleButton in wrapPanel1.Children.OfType <ToggleButton>().Where(tb => this.ChoiceResult.Options.Contains(((DominionBase.Option)tb.Tag).Text))) { chkdToggleButton.IsChecked = false; this.ChoiceResult.Options.Remove(((DominionBase.Option)chkdToggleButton.Tag).Text); } } if (isChecked == true) { this.ChoiceResult.Options.Add(option); } else if (this.ChoiceResult.Options.Contains(option)) { this.ChoiceResult.Options.Remove(option); } if ((Choice.Minimum > 0 || this.ChoiceResult.Options.Count > 0) && this.ChoiceResult.Options.Count >= Choice.Minimum && this.ChoiceResult.Options.Count <= Choice.Maximum) { bOK.IsEnabled = true; } break; case DominionBase.ChoiceType.Cards: case DominionBase.ChoiceType.SuppliesAndCards: //case DominionBase.ChoiceType.Pile: if (this.ChoiceResult == null) { this.ChoiceResult = new DominionBase.ChoiceResult(new DominionBase.Cards.CardCollection()); } DominionBase.Cards.Card card = tag as DominionBase.Cards.Card; if (isChecked == true) { this.ChoiceResult.Cards.Add(card); } else if (this.ChoiceResult.Cards.Contains(card)) { this.ChoiceResult.Cards.Remove(card); } if ((Choice.Minimum > 0 || this.ChoiceResult.Cards.Count > 0) && this.ChoiceResult.Cards.Count >= Choice.Minimum && this.ChoiceResult.Cards.Count <= Choice.Maximum) { bOK.IsEnabled = true; } break; case DominionBase.ChoiceType.Supplies: if (isChecked == true) { this.ChoiceResult = new DominionBase.ChoiceResult(tag as DominionBase.Piles.Supply); } else { this.ChoiceResult = null; } if (this.ChoiceResult != null) { bOK.IsEnabled = true; } break; } foreach (ToggleButton control in wrapPanel1.Children.OfType <ToggleButton>()) { Panel pButtonText = (Panel)((Border)control.Content).Child; String option = ((DominionBase.Option)control.Tag).Text; if (Choice.IsOrdered) { pButtonText.Visibility = System.Windows.Visibility.Visible; String ordinal = String.Empty; switch (Choice.ChoiceType) { case DominionBase.ChoiceType.Options: if (this.ChoiceResult.Options.Contains(option)) { ordinal = Utilities.Ordinal(this.ChoiceResult.Options.IndexOf(option) + 1); } break; } if (ordinal != String.Empty) { (pButtonText.Children[0] as TextBlock).Text = String.Format("{0}: ", ordinal); } else { (pButtonText.Children[0] as TextBlock).Text = String.Empty; } } } foreach (ucICardButton control in wrapPanel1.Children.OfType <ucICardButton>()) { DominionBase.Cards.Card card = control.Tag as DominionBase.Cards.Card; if (Choice.IsOrdered) { String ordinal = String.Empty; switch (Choice.ChoiceType) { case DominionBase.ChoiceType.Cards: //case DominionBase.ChoiceType.Pile: if (this.ChoiceResult.Cards.Contains(card)) { control.Order = this.ChoiceResult.Cards.IndexOf(card) + 1; } else { control.Order = 0; } break; } } } if (bOK.IsEnabled && (this.ChoiceResult.Supply != null || (this.ChoiceResult.Cards != null && (this.ChoiceResult.Cards.Count == Choice.Maximum || this.ChoiceResult.Cards.Count == this.Choice.Cards.Count())) || (this.ChoiceResult.Options != null && (this.ChoiceResult.Options.Count == Choice.Maximum || this.ChoiceResult.Options.Count == this.Choice.Options.Count)) ) && cbAutoClick.IsChecked == true) { bOK_Click(bOK, null); } }
private FrameworkElement CreateButton(Boolean isICard, ICommand command, Boolean isRequired) { if (isICard) { ucICardButton icb = new ucICardButton(); icb.ICardButtonClick += new RoutedEventHandler(toggleButton_Checked); icb.IsOrdered = Choice.IsOrdered; return icb; } else { ToggleButton tb = new ToggleButton() { Margin = new Thickness(5, 0, 5, 0), Height = double.NaN, Width = double.NaN, MinHeight = 40, MinWidth = 40, MaxHeight = 100, MaxWidth = 200, Background = (VisualBrush)FindResource("NormalBrush"), VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch }; Border border = new Border() { Padding = new Thickness(10, 0, 10, 0) }; tb.Content = border; WrapPanel wp = new WrapPanel() { Orientation = Orientation.Horizontal, VerticalAlignment = System.Windows.VerticalAlignment.Center }; border.Child = wp; if (isRequired) { border.BorderThickness = new Thickness(2); border.BorderBrush = Brushes.Crimson; } else { tb.ToolTip = "Optional"; } wp.Children.Add(new TextBlock() { TextWrapping = TextWrapping.Wrap }); wp.Children.Add(new AccessText() { Width = 0 }); wp.Children.Add(new TextBlock() { TextWrapping = TextWrapping.Wrap }); if (command == null) tb.Click += new RoutedEventHandler(toggleButton_Checked); else tb.Command = command; return tb; } }