Exemplo n.º 1
0
        /// <summary>
        /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see
        /// cref="ListViewItem"/> of the "Condition" <see cref="ListView"/> on the <see
        /// cref="ConditionsTab"/> page.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="MouseButtonEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnConditionActivate</b> displays a <see cref="ShowVariables"/> dialog containing
        /// information on the double-clicked item in the "Conditions" list view if it indicates a
        /// <see cref="VariableClass"/>.</remarks>

        private void OnConditionActivate(object sender, MouseButtonEventArgs args)
        {
            args.Handled = true;

            // retrieve double-clicked item, if any
            var source   = args.OriginalSource as DependencyObject;
            var listItem = ItemsControl.ContainerFromElement(VariableList, source) as ListViewItem;

            if (listItem == null)
            {
                return;
            }

            // check if parameter is a variable class
            ConditionListItem item     = (ConditionListItem)listItem.Content;
            VariableClass     variable = item.Parameter as VariableClass;

            if (variable == null)
            {
                return;
            }

            // show info dialog for variable class
            var dialog = new ShowVariables(variable)
            {
                Owner = this
            };

            dialog.ShowDialog();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds one <see cref="ConditionListItem"/> for each condition that applies to the selected
        /// <see cref="Faction"/> to the "Condition" <see cref="ListView"/> on the <see
        /// cref="ConditionsTab"/> page.</summary>
        /// <remarks>
        /// <b>CreateConditionRows</b> adds one row for each possible <see
        /// cref="ConditionParameter"/>, plus one row for each resource defined in the current <see
        /// cref="VariableSection"/> that appears in the <see cref="Faction.Resources"/> collection
        /// of the selected <see cref="Faction"/>, if any.</remarks>

        private void CreateConditionRows()
        {
            var defeatConditions  = this._faction.FactionClass.DefeatConditions;
            var victoryConditions = this._faction.FactionClass.VictoryConditions;

            // process all non-resource conditions
            foreach (ConditionParameter parameter in FactionClass.AllConditionParameters)
            {
                // get current value for this faction
                int    currentValue = this._faction.GetConditionValue(this._worldState, parameter);
                string current      = currentValue.ToString("N0", ApplicationInfo.Culture);

                // get individual defeat & victory thresholds
                string    defeat = "—", victory = "—";
                Condition condition;
                if (defeatConditions.TryGetValue(parameter, out condition))
                {
                    defeat = condition.Threshold.ToString("N0", ApplicationInfo.Culture);
                }
                if (victoryConditions.TryGetValue(parameter, out condition))
                {
                    victory = condition.Threshold.ToString("N0", ApplicationInfo.Culture);
                }

                var item = new ConditionListItem(parameter)
                {
                    Current = current, Defeat = defeat, Victory = victory
                };

                ConditionList.Items.Add(item);
            }

            ConditionList.Items.Add(new ConditionListItem());

            // process all resources defined by scenario
            foreach (var pair in MasterSection.Instance.Variables.Resources)
            {
                // skip resources not owned by faction
                if (!this._faction.Resources.Variables.ContainsKey(pair.Key))
                {
                    continue;
                }

                // get current value for this faction
                int    currentValue = this._faction.Resources.Variables[pair.Key].Value;
                string current      = currentValue.ToString("N0", ApplicationInfo.Culture);

                // get global defeat & victory thresholds
                ResourceClass resource = (ResourceClass)pair.Value;
                string        defeat = "—", victory = "—";
                if (resource.Defeat > Int32.MinValue)
                {
                    defeat = resource.Defeat.ToString("N0", ApplicationInfo.Culture);
                }
                if (resource.Victory < Int32.MaxValue)
                {
                    victory = resource.Victory.ToString("N0", ApplicationInfo.Culture);
                }

                var item = new ConditionListItem(pair.Value)
                {
                    Current = current, Defeat = defeat, Victory = victory
                };

                ConditionList.Items.Add(item);
            }
        }