/// <summary> /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Variable" <see /// cref="ListView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnVariableSelected</b> updates all dialog controls to reflect the selected item in /// the "Variable" list view.</remarks> private void OnVariableSelected(object sender, SelectionChangedEventArgs args) { args.Handled = true; // clear data display VariableInfo.Clear(); MinimumInfo.Clear(); MaximumInfo.Clear(); StepSizeInfo.Clear(); // disable resource display ResourceGroup.IsEnabled = false; DefeatInfo.Text = "—"; // em dash VictoryInfo.Text = "—"; // em dash ResetToggle.IsChecked = false; LimitToggle.IsChecked = false; // retrieve selected item, if any VariableClass variable = VariableList.SelectedItem as VariableClass; if (variable == null) { return; } // show target range and step size MinimumInfo.Text = variable.Format(variable.Minimum, false); MaximumInfo.Text = variable.Format(variable.Maximum, false); StepSizeInfo.Text = variable.Format(1, false); // show additional data for resources ResourceClass resource = variable as ResourceClass; if (resource != null) { ResourceGroup.IsEnabled = true; ResetToggle.IsChecked = resource.IsResetting; LimitToggle.IsChecked = resource.IsLimited; if (resource.Defeat != Int32.MinValue) { DefeatInfo.Text = resource.Format(resource.Defeat, false); } if (resource.Victory != Int32.MaxValue) { VictoryInfo.Text = resource.Format(resource.Victory, false); } } // show associated informational text VariableInfo.Text = String.Join(Environment.NewLine, variable.Paragraphs); }
/// <summary> /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Variable" <see /// cref="ListView"/> on the <see cref="VariablesTab"/> page.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnVariableSelected</b> updates the "Modifier" list view to reflect the selected item /// in the "Variable" list view.</remarks> private void OnVariableSelected(object sender, SelectionChangedEventArgs args) { // retrieve selected variable class, if any VariableClass variable = null; int index = VariableList.SelectedIndex; if (index >= 0) { var item = (VariableListItem)VariableList.Items[index]; variable = item.Item1; } // initialize all counters to dashes string[] values = new string[7] { "—", "—", "—", "—", "—", "", "—" }; CategorizedValue value; // show categorized modifiers to selected variable, if any if (variable != null && this._modifiers.TryGetValue(variable.Id, out value)) { values[0] = FormatModifier(variable, value.Unit); values[1] = FormatModifier(variable, value.Terrain); values[2] = FormatModifier(variable, value.Effect); values[3] = FormatModifier(variable, value.Upgrade); values[4] = FormatModifier(variable, value.Other); values[6] = variable.Format(value.Total, true); } // copy formatted values to Modifier list view for (int i = 0; i < values.Length; i++) { ModifierListItem item = (ModifierListItem)ModifierList.Items[i]; ModifierList.Items[i] = new ModifierListItem(item.Item1, values[i]); } }
/// <summary> /// Draws variable values on the specified <see cref="Site"/>.</summary> /// <param name="context"> /// The <see cref="DrawingContext"/> for the drawing.</param> /// <param name="site"> /// The <see cref="Site"/> to receive the variable values.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="site"/> is a null reference.</exception> /// <remarks> /// The origin of the specified <paramref name="context"/> must have been centered on the /// specified <paramref name="site"/>.</remarks> public void Draw(DrawingContext context, Site site) { if (context == null) { ThrowHelper.ThrowArgumentNullException("context"); } if (site == null) { ThrowHelper.ThrowArgumentNullException("site"); } // get current variable and display flags MapView mapView = this._renderer.MapView; VariableClass variable = mapView.ShownVariable; PointI value = site.AddVariables(mapView.WorldState, variable); VariableDisplay flags = mapView.ShownVariableFlags; // draw value as shade if desired if ((flags & VariableDisplay.Shades) != 0) { int index, shadeMinimum, shadeMaximum, shadeValue; Brush[] brushes = MediaObjects.ShadeGrayBrushes; // update minimum and maximum values if necessary if (ValueRangeChanged) { FindValueRange(variable, value); } // default to basic values unless only Modifier is selected if ((flags & VariableDisplay.BasicAndModifier) == VariableDisplay.Modifier) { shadeMinimum = this._minimum.Y; shadeMaximum = this._maximum.Y; shadeValue = value.Y; } else { shadeMinimum = this._minimum.X; shadeMaximum = this._maximum.X; shadeValue = value.X; } /* * Always use a medium shade if the total range is one. * Otherwise, calculate appropriate shade and restrict index to legal range, * just in case ValueRangeChanged should have been set but wasn't. */ if (shadeMinimum == shadeMaximum) { index = brushes.Length / 2; } else { double range = shadeMaximum - shadeMinimum + 1; index = (int)((shadeValue - shadeMinimum) / range * brushes.Length); index = Math.Max(0, Math.Min(brushes.Length - 1, index)); } context.DrawGeometry(brushes[index], null, mapView.ElementGeometry); } // draw value as number if desired if ((flags & VariableDisplay.Numbers) != 0) { // check if output must be recreated if (this._lastText == null || value != this._lastValue || (flags & VariableDisplay.BasicAndModifier) != (this._lastFlags & VariableDisplay.BasicAndModifier)) { // store current input and display flags this._lastValue = value; this._lastFlags = flags; // default to no output this._lastText = null; string text = ""; // always output basic value if desired if ((flags & VariableDisplay.Basic) != 0) { text = variable.Format(value.X, false); } // output modifier value only if non-zero if ((flags & VariableDisplay.Modifier) != 0 && value.Y != 0) { if (text.Length > 0) { text += Environment.NewLine + variable.Format(value.Y, true); } else { text = variable.Format(value.Y, true); } } // create formatted text if required if (text.Length > 0) { if (this._typeface == null) { this._typeface = this._renderer.Control.GetTypeface(); this._emSize = this._renderer.Control.FontSize; } this._lastText = new FormattedText(text, ApplicationInfo.Culture, FlowDirection.LeftToRight, this._typeface, this._emSize, Brushes.White); // center text horizontally & vertically this._lastText.TextAlignment = TextAlignment.Center; this._lastTextOrigin = new Point(0, -this._lastText.Height / 2.0); } } // draw formatted output text, if any if (this._lastText != null) { context.DrawText(this._lastText, this._lastTextOrigin); } } }
/// <summary> /// Formats the specified value as a modifier for the specified <see cref="VariableClass"/>. /// </summary> /// <param name="variable"> /// The <see cref="VariableClass"/> that defines the <paramref name="value"/>.</param> /// <param name="value"> /// The instance value of the specified <paramref name="variable"/> to format.</param> /// <returns> /// An em dash (—) if <paramref name="value"/> is zero; otherwise, the result of <see /// cref="VariableClass.Format"/> for the specified <paramref name="variable"/> and /// <paramref name="value"/>.</returns> private static string FormatModifier(VariableClass variable, int value) { return(value == 0 ? "—" : variable.Format(value, true)); }