/// <summary> /// Refreshes the control palette with appropriate controls based on the difficulty setting. This /// must be called each time the user changes the difficulty setting in the application. /// </summary> public void RefreshPalette(OptionDifficultySetting setting) { // Show or hide the heat stream button based on the setting if ((new HeatStream(-1)).IsAvailableWithDifficulty(setting)) { HeatStreamButton.Visibility = System.Windows.Visibility.Visible; } else { HeatStreamButton.Visibility = System.Windows.Visibility.Collapsed; } // Now we use reflection to create the process unit buttons // First clear the content in the process unit stack panel ProcessUnitsPanel.Children.Clear(); // We will create potentially multiple stack panels for rows of buttons StackPanel spPUs = null; // Keep track of how many buttons we create int puBtns = 0; // Use reflection to find appropriate process units and streams for the palette Assembly a = typeof(Logic.AbstractProcessUnit).Assembly; foreach (Type t in a.GetTypes()) { // Ignore abstract types if (t.IsAbstract) { continue; } // We only are interested in types that inherit from AbstractProcessUnit if (t.IsSubclassOf(typeof(AbstractProcessUnit)) && !t.IsAbstract) { // We've found a potential process unit, but we need to make sure that // it can be created under the specified difficulty setting AbstractProcessUnit unit = Activator.CreateInstance(t, (int)-1) as AbstractProcessUnit; if (unit.IsAvailableWithDifficulty(setting)) { if (0 == (puBtns % m_buttonsPerRow)) { // Create a new row spPUs = new StackPanel(); spPUs.Orientation = Orientation.Horizontal; // Add the first button to it spPUs.Children.Add(CreateButton( ProcessUnitControl.GetIconSource(t), unit.Description, t)); ProcessUnitsPanel.Children.Add(spPUs); } else { spPUs.Children.Add(CreateButton( ProcessUnitControl.GetIconSource(t), unit.Description, t)); } puBtns++; } } } }
public void SetCommentObject(StickyNote comment, object parent) { if (null != m_sticky) { // Remove event handler before changing this value m_sticky.PropertyChanged -= this.StickyNote_PropertyChanged; } if (null != m_basic) { m_basic.OnTextChanged -= this.BasicComment_OnTextChanged; } // IMPORTANT: Unsubscribe from parent control property changes (if applicable) if (null != m_parentObject) { if (m_parentObject is AbstractProcessUnit) { (m_parentObject as AbstractProcessUnit).PropertyChanged -= this.ParentPU_PropertyChanged; } else if (m_parentObject is AbstractStream) { (m_parentObject as AbstractStream).PropertyChanged -= this.ParentStream_PropertyChanged; } } // Store references m_basic = null; m_sticky = comment; m_parentObject = parent; AbstractStream parentStream = parent as AbstractStream; AbstractProcessUnit parentAPU = parent as AbstractProcessUnit; // Update the UI elements if the comment is not null if (null != m_sticky) { CommentTextBox.Text = m_sticky.Text; UserNameLabel.Content = m_sticky.UserName; // Subsribe to property changes m_sticky.PropertyChanged += this.StickyNote_PropertyChanged; // Allow editing but not deletion CommentTextBox.IsReadOnly = false; XLabel.Visibility = System.Windows.Visibility.Collapsed; // Show or hide the icon based on the parent if (null != parentStream) { // Get the right icon for this type of stream string iconSource = PFD.Streams.StreamControl.GetIconSource(parent.GetType()); BitmapImage bmp = new BitmapImage(); bmp.UriSource = new Uri(iconSource, UriKind.Relative); IconImage.SetValue(Image.SourceProperty, bmp); // Make sure the icon is visible IconImage.Visibility = System.Windows.Visibility.Visible; TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(20.0); // Give the icon a tooltip that tells what this is a comment for ToolTipService.SetToolTip(IconImage, "Comment for stream #" + parentStream.Id); // Subscribe to property changes for the stream parentStream.PropertyChanged += new PropertyChangedEventHandler(ParentStream_PropertyChanged); } else if (null != parentAPU) { // Get the right icon for this type of process unit string iconSource = ProcessUnitControl.GetIconSource(parent.GetType()); BitmapImage bmp = new BitmapImage(); bmp.UriSource = new Uri(iconSource, UriKind.Relative); IconImage.SetValue(Image.SourceProperty, bmp); // Make sure the icon is visible IconImage.Visibility = System.Windows.Visibility.Visible; TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(20.0); // Give the icon a tooltip that tells what this is a comment for ToolTipService.SetToolTip(IconImage, "Comment for " + (m_parentObject as AbstractProcessUnit).Label); // Subscribe to property changes for the process unit parentAPU.PropertyChanged += new PropertyChangedEventHandler(ParentPU_PropertyChanged); } else { // Make sure the icon is hidden IconImage.Visibility = System.Windows.Visibility.Collapsed; TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(0.0); } } }