Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowGauges"/> class with the specified
        /// initially selected <see cref="ResourceClass"/> and <see cref="GaugeDisplay"/> flags.
        /// </summary>
        /// <param name="resource"><para>
        /// The identifier of the <see cref="ResourceClass"/> to select initially. Possible values
        /// include the pseudo-resources <see cref="ResourceClass.StandardMorale"/> and <see
        /// cref="ResourceClass.StandardStrength"/>.
        /// </para><para>-or-</para><para>
        /// A null reference to select the <see cref="ResourceClass.StandardStrength"/>
        /// pseudo-resource.</para></param>
        /// <param name="flags">
        /// A <see cref="GaugeDisplay"/> value indicating which display flags to select initially.
        /// </param>

        public ShowGauges(string resource, GaugeDisplay flags)
        {
            InitializeComponent();

            Resource      = resource;
            ResourceFlags = flags;

            // read specified display flags into check boxes
            NeverToggle.IsChecked  = String.IsNullOrEmpty(resource);
            AlwaysToggle.IsChecked = ((flags & GaugeDisplay.Always) != 0);
            StackToggle.IsChecked  = ((flags & GaugeDisplay.Stack) != 0);

            // adjust column width of Resource list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(VariableList, OnVariableWidthChanged);

            // show standard unit resources
            VariableList.Items.Add(ResourceClass.StandardStrength);
            VariableList.Items.Add(ResourceClass.StandardMorale);
            VariableList.AddSeparator();

            // show all scenario resources
            foreach (VariableClass variable in MasterSection.Instance.Variables.Resources.Values)
            {
                VariableList.Items.Add(variable);
            }

            // select specified resource, if any
            if (resource != null)
            {
                foreach (object item in VariableList.Items)
                {
                    VariableClass variable = item as VariableClass;
                    if (variable != null && variable.Id == resource)
                    {
                        VariableList.SelectAndShow(variable);
                        break;
                    }
                }
            }

            // select standard strength by default
            if (VariableList.SelectedItems.Count == 0)
            {
                VariableList.SelectAndShow(0);
            }
        }