Exemple #1
0
        /// <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++;
                    }
                }
            }
        }
 /// <summary>
 /// Returns a boolean value indicating whether or not the processing unit should be available
 /// with the specified difficulty setting.
 /// TODO: Remove and use logic in AbstractProcessUnit.
 /// </summary>
 public virtual bool IsAvailableWithDifficulty(OptionDifficultySetting difficulty)
 {
     return(m_pu.IsAvailableWithDifficulty(difficulty));
 }