/// <summary> /// Finds the total range of values for the specified <see cref="VariableClass"/> across all /// map sites.</summary> /// <param name="variable"> /// The <see cref="VariableClass"/> whose values to examine.</param> /// <param name="sample"> /// A current sample value for the specified <paramref name="variable"/>.</param> /// <remarks> /// <b>FindValueRange</b> separately determines the minimum and maximum for both the basic /// and modifier values of the specified <paramref name="variable"/>. Before returning /// <b>FindValueRange</b> clears the <see cref="ValueRangeChanged"/> flag.</remarks> private void FindValueRange(VariableClass variable, PointI sample) { int minX = sample.X, maxX = sample.X; int minY = sample.Y, maxY = sample.Y; WorldState world = this._renderer.MapView.WorldState; foreach (Site site in world.Sites) { PointI value = site.AddVariables(world, variable); if (minX > value.X) { minX = value.X; } if (minY > value.Y) { minY = value.Y; } if (maxX < value.X) { maxX = value.X; } if (maxY < value.Y) { maxY = value.Y; } } this._minimum = new PointI(minX, minY); this._maximum = new PointI(maxX, maxY); ValueRangeChanged = false; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Remove Variable" <see /// cref="Button"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnVariableRemove</b> removes the first selected item in the "Variable" list view from /// that list view and from the <see cref="CurrentVariables"/> collection, and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</remarks> private void OnVariableRemove(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected faction, if any int index = VariableList.SelectedIndex; if (index < 0) { return; } VariableClass variable = (VariableClass)VariableList.Items[index]; // delete existing ID references var variables = CurrentVariables; if (!SectionTabItem.ProcessAllIdentifiers(variables, variable.Id, null)) { return; } // select item in the same position VariableList.Items.Refresh(); if (VariableList.Items.Count > 0) { VariableList.SelectAndShow(Math.Min(VariableList.Items.Count - 1, index)); } // broadcast data changes EnableListButtons(); SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Variables" <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 "Value" control with the data of the first /// selected item in the "Variables" list view.</remarks> private void OnVariableSelected(object sender, SelectionChangedEventArgs args) { args.Handled = true; if (!this._initialized) { return; } // retrieve selected variable entry, if any decimal value = 0m; int index = VariableList.SelectedIndex; if (index >= 0) { // update numeric control with variable value VariableListItem item = (VariableListItem)VariableList.Items[index]; if (item.Target == null) { value = VariableClass.ParseUnscaled(item.Value); } else { ModifierTarget target; if (!VariableClass.TryParseUnscaled(item.Value, out value, out target)) { Debug.Fail("OnVariableSelected: TryParseUnscaled failed."); } Debug.Assert(target == item.Target.Value); } } VariableUpDown.Value = value; }
/// <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(); }
void ReadVariables(List <VariableDetails> vars, List <LuaValue> path, int watchid, int count, int depth) { for (int index = 0; index < count; ++index) { LuaValue key = m_readBuffer.ReadValue(); LuaValue value = m_readBuffer.ReadValue(); VariableInfoFlag flags = (VariableInfoFlag)m_readBuffer.ReadInt16(); bool valid = (flags & VariableInfoFlag.Valid) != 0; bool expanded = (flags & VariableInfoFlag.Expanded) != 0; bool hasEntries = (flags & VariableInfoFlag.HasEntries) != 0; bool hasMetadata = (flags & VariableInfoFlag.HasMetadata) != 0; VariableClass varclass = (VariableClass)m_readBuffer.ReadInt16(); VariableDetails var = new VariableDetails(watchid, path.ToArray(), key, value, expanded, hasEntries, hasMetadata, valid, varclass); vars.Add(var); int expansionCount = m_readBuffer.ReadInt32(); if (expansionCount > 0) { path.Add(key); ReadVariables(vars, path, watchid, expansionCount, depth + 1); path.RemoveAt(path.Count - 1); } } }
/// <summary> /// 基础数据List的所有值的拼接 ,比如List<string> /// </summary> /// <param name="data"></param> /// <param name="varClass"></param> /// <returns></returns> private static string GetBaseListStr(object data, VariableClass varClass) { string str = ""; if (string.IsNullOrEmpty(varClass.SplitStr)) { Debug.LogError(varClass.Name + " 的分隔符为空,请补充"); return(str); } object listObj = GetMemberValue(data, varClass.Name); int listCount = (int)listObj.GetType().InvokeMember("get_Count", BindingFlags.Default | BindingFlags.InvokeMethod, null, listObj, new object[] { }); for (int i = 0; i < listCount; i++) { object item = listObj.GetType().InvokeMember("get_Item", BindingFlags.Default | BindingFlags.InvokeMethod, null, listObj, new object[] { i }); str += item.ToString(); if (i != listCount - 1) { str += varClass.SplitStr; } } return(str); }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Reset Variable" <see /// cref="Button"/> 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="RoutedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnResetValue</b> resets the current value of the first selected item in the /// "Variables" list view to its default value and updates all controls accordingly. /// </remarks> private void OnResetVariable(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected variable, if any if (VariableList.SelectedIndex < 0) { return; } var item = (VariableListItem)VariableList.SelectedItem; // extract decimal default value and modifier flag bool isModifier; decimal defaultValue = VariableClass.ParseUnscaled(item.DefaultValue, out isModifier); Debug.Assert(item.Target.HasValue == isModifier); /* * Changing the numeric control also updates the Variables list view * and the backing collection, thanks to the OnVariableChanged event. */ if (VariableUpDown.Value != defaultValue) { VariableUpDown.Value = defaultValue; } }
/// <summary> /// Handles the <see cref="NumericUpDown.ValueChanged"/> event for the "Value" <see /// cref="NumericUpDown"/> control on the <see cref="VariablesTab"/> page.</summary> /// <param name="sender"> /// The <see cref="NumericUpDown"/> control sending the event.</param> /// <param name="args"> /// An <see cref="EventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnVariableChanged</b> updates the "Value" column of the first selected item in the /// "Variables" list view, as well as the corresponding backing dictionary.</remarks> private void OnVariableChanged(object sender, EventArgs args) { if (!this._initialized) { return; } // retrieve selected variable entry, if any int index = VariableList.SelectedIndex; if (index < 0) { return; } var item = (VariableListItem)VariableList.Items[index]; // extract decimal value and modifier flag decimal oldValue; if (item.Target == null) { oldValue = VariableClass.ParseUnscaled(item.Value); } else { ModifierTarget target; if (!VariableClass.TryParseUnscaled(item.Value, out oldValue, out target)) { Debug.Fail("OnVariableChanged: TryParseUnscaled failed."); } Debug.Assert(target == item.Target.Value); } // check if variable value has actually changed if (VariableUpDown.Value == oldValue) { return; } int value = (int)VariableUpDown.Value; // update variable value in collection string formatValue; if (item.Target == null) { this._currentVariables[item.Id] = value; formatValue = VariableClass.FormatUnscaled(value, false); } else { this._currentVariableModifiers[item.Id].SetByTarget(item.Target.Value, value); formatValue = VariableClass.FormatUnscaled(value, item.Target.Value); } // update variable value in list view item.Value = formatValue; VariableList.Items.Refresh(); VariableList.SelectAndShow(index); }
private VariableInfo(RegType registerType, int size, VariableClass @class, VariableFlags flags, string name) { this._registerType = registerType; this._size = (byte)size; this._class = @class; this._flags = flags; this._name = name; }
/// <summary> /// Creates a new item for the "Variables" <see cref="ListView"/> on the <see /// cref="VariablesTab"/> page, containing the specified <see cref="VariableClass"/> /// identifier and associated modifier value for the specified <see cref="ModifierTarget"/>. /// </summary> /// <param name="id"> /// The <see cref="VariableClass.Id"/> string of a <see cref="VariableClass"/>.</param> /// <param name="target"> /// A <see cref="ModifierTarget"/> value indicating which modifier value to add.</param> /// <returns> /// The new <see cref="VariableListItem"/> if one was created and added to the "Variables" /// <see cref="ListView"/>; otherwise, a null reference.</returns> /// <remarks> /// <b>CreateVariableItem</b> immediately returns a null reference if the specified /// <paramref name="id"/> is not found in the currently selected default <see /// cref="VariableModifierDictionary"/>, or if the element that matches the specified /// <paramref name="id"/> does not define a modifier value for the specified <paramref /// name="target"/>.</remarks> private VariableListItem CreateVariableItem(string id, ModifierTarget target) { if (this._defaultVariableModifiers == null) { return(null); } // get default modifier if present VariableModifier defaultModifier; if (!this._defaultVariableModifiers.TryGetValue(id, out defaultModifier)) { return(null); } // get value for specified target, if any int?defaultValue = defaultModifier.GetByTarget(target); if (defaultValue == null) { return(null); } // add current modifier if necessary VariableModifier currentModifier; if (!this._currentVariableModifiers.TryGetValue(id, out currentModifier)) { currentModifier = (VariableModifier)defaultModifier.Clone(); this._currentVariableModifiers.Add(id, currentModifier); } // format variable as modifier value int?currentValue = currentModifier.GetByTarget(target); VariableListItem newItem = new VariableListItem(id, VariableClass.FormatUnscaled(currentValue, target), VariableClass.FormatUnscaled(defaultValue.Value, true), target); ItemCollection items = VariableList.Items; for (int i = 0; i < items.Count; i++) { VariableListItem item = (VariableListItem)items[i]; // sort alphabetically, with basic values before modifiers if (String.CompareOrdinal(item.Id, newItem.Id) > 0) { items.Insert(i, newItem); return(newItem); } } // append to end of list items.Add(newItem); return(newItem); }
/// <summary> /// Initializes a new instance of the <see cref="ConditionListItem"/> class with the /// specified <see cref="VariableClass"/>.</summary> /// <param name="variable"> /// The initial value for the <see cref="Parameter"/> and <see cref="ParameterText"/> /// properties.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="variable"/> is a null reference.</exception> public ConditionListItem(VariableClass variable) { if (variable == null) { ThrowHelper.ThrowArgumentNullException("variable"); } Parameter = variable; ParameterText = variable.Name; }
/// <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="ButtonBase.Click"/> event for the "Add Variable" <see /// cref="Button"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks><para> /// <b>OnVariableAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed /// by a <see cref="Dialog.ChangeVariable"/> dialog, allowing the user to define a new /// variable. The new variable copies the properties of the first selected item in the /// "Variable" list view, if any; otherwise, it is created with default properties. /// </para><para> /// If the user confirmed both dialogs, <b>OnVariableAdd</b> adds the new variable to the /// "Variable" list view and to the <see cref="CurrentVariables"/> collection, and sets the /// <see cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnVariableAdd(object sender, RoutedEventArgs args) { args.Handled = true; // ask user for new variable ID var variables = CurrentVariables; var dialog = new Dialog.ChangeIdentifier(CurrentDefaultId, Global.Strings.TitleVariableIdEnter, variables.ContainsKey, false); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new variable ID string id = String.Intern(dialog.Identifier); // create new variable based on selected variable, if any VariableClass variable, selection = VariableList.SelectedItem as VariableClass; if (selection == null) { variable = VariableClass.Create(id, CurrentCategory); } else { variable = (VariableClass)selection.Clone(); variable.Id = id; } // let user make changes to new variable var variableDialog = new Dialog.ChangeVariable(variable) { Owner = MainWindow.Instance }; if (variableDialog.ShowDialog() != true) { return; } // add variable to section table variables.Add(id, variable); // update list view and select new item VariableList.Items.Refresh(); VariableList.SelectAndShow(variable); // broadcast data changes EnableListButtons(); SectionTab.DataChanged = true; }
public VariableDetails(int watchid, LuaValue[] path, LuaValue key, LuaValue value, bool expanded, bool hasEntries, bool hasMetadata, bool valid, VariableClass varclass) { mWatchID = watchid; mPath = path; mKey = key; mValue = value; mExpanded = expanded; mHasEntries = hasEntries; mHasMetadata = hasMetadata; mValid = valid; mClass = varclass; }
/// <overloads> /// Validates the specified list of variable values.</overloads> /// <summary> /// Validates the specified <see cref="VariableModifierDictionary"/>.</summary> /// <param name="owner"> /// The parent <see cref="Window"/> for any dialogs.</param> /// <param name="variables"> /// A <see cref="VariableModifierDictionary"/> that maps <see cref="VariableClass.Id"/> /// string to the corresponding <see cref="VariableModifier"/> instance values.</param> /// <returns> /// <c>true</c> if the values of the specified <paramref name="variables"/> are valid; /// otherwise, <c>false</c>.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="variables"/> is a null reference.</exception> /// <remarks><para> /// <b>ValidateVariables</b> checks that every <see cref="ModifierTarget"/> value for each /// in the specified <paramref name="variables"/> collection is either an even multiple of /// the <see cref="VariableClass.Scale"/> of its <see cref="VariableClass"/>, or vice versa. /// </para><para> /// If this is not the case, <b>ValidateVariables</b> asks the user to confirm the value, /// and returns <c>false</c> if the user declines. <b>ValidateVariables</b> returns /// <c>true</c> if all <paramref name="variables"/> pass this test.</para></remarks> public static bool ValidateVariables(Window owner, VariableModifierDictionary variables) { if (variables == null) { ThrowHelper.ThrowArgumentNullException("variables"); } VariableSection variableSection = MasterSection.Instance.Variables; foreach (var pair in variables) { // get variable, display scale, and new value VariableClass variable = variableSection.GetVariable(pair.Key); if (variable == null) { continue; } int scale = variable.Scale; if (scale == 1) { continue; } foreach (ModifierTarget target in VariableModifier.AllModifierTargets) { int value = Math.Abs(pair.Value.GetByTarget(target).GetValueOrDefault()); if (value == 0) { continue; } // check that new value conforms to scale if ((value > scale && value % scale != 0) || (value < scale && scale % value != 0)) { string message = String.Format(ApplicationInfo.Culture, Global.Strings.DialogVariableScaleMismatch, pair.Key); MessageBoxResult result = MessageBox.Show(owner, message, Global.Strings.TitleVariableScaleMismatch, MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.Cancel) { return(false); } } } } return(true); }
/// <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); } }
/// <summary> /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see /// cref="ListViewItem"/> of the <see cref="PropertyListView"/>.</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><para> /// <b>OnItemActivate</b> should be called by the actual event handler defined for each /// concrete instance of <see cref="PropertyListView"/>. /// </para><para> /// If the current <see cref="MasterSection"/> instance is not a null reference, /// <b>OnItemActivate</b> shows a <see cref="Dialog.ShowVariables"/> dialog containing /// information on the double-clicked item, if any.</para></remarks> public void OnItemActivate(object sender, MouseButtonEventArgs args) { args.Handled = true; // quit if no current scenario instance if (MasterSection.Instance == null) { return; } // retrieve double-clicked item, if any var source = args.OriginalSource as DependencyObject; var listItem = ItemsControl.ContainerFromElement(this, source) as ListViewItem; if (listItem == null) { return; } // retrieve supported content, if any var item = listItem.Content as PropertyListItem; if (item == null) { return; } // show info dialog for unit abilities if (item.Tag is UnitClass) { MessageBox.Show(Window.GetWindow(this), Global.Strings.DialogUnitAbilites, Global.Strings.TitleAbilities, MessageBoxButton.OK, MessageBoxImage.Information); return; } // show info dialog for this variable VariableClass variable = item.Tag as VariableClass; if (variable != null) { var dialog = new Dialog.ShowVariables(variable); dialog.Owner = Window.GetWindow(this); dialog.ShowDialog(); } }
/// <overloads> /// Creates a new item for the "Variables" <see cref="ListView"/> on the <see /// cref="VariablesTab"/> page, containing the specified <see cref="VariableClass"/> /// identifier and associated value.</overloads> /// <summary> /// Creates a new item for the "Variables" <see cref="ListView"/> on the <see /// cref="VariablesTab"/> page, containing the specified <see cref="VariableClass"/> /// identifier and associated basic value.</summary> /// <param name="id"> /// The <see cref="VariableClass.Id"/> string of a <see cref="VariableClass"/>.</param> /// <returns> /// The new <see cref="VariableListItem"/> if one was created and added to the "Variables" /// <see cref="ListView"/>; otherwise, a null reference.</returns> /// <remarks> /// <b>CreateVariableItem</b> immediately returns a null reference if the specified /// <paramref name="id"/> is not found in the currently selected default <see /// cref="VariableValueDictionary"/>.</remarks> private VariableListItem CreateVariableItem(string id) { if (this._defaultVariables == null) { return(null); } // get default value if present int defaultValue; if (!this._defaultVariables.TryGetValue(id, out defaultValue)) { return(null); } // add current value if necessary int currentValue; if (!this._currentVariables.TryGetValue(id, out currentValue)) { currentValue = defaultValue; } // format variable as basic value VariableListItem newItem = new VariableListItem(id, VariableClass.FormatUnscaled(currentValue, false), VariableClass.FormatUnscaled(defaultValue, false), null); ItemCollection items = VariableList.Items; for (int i = 0; i < items.Count; i++) { VariableListItem item = (VariableListItem)items[i]; // sort alphabetically, with basic values before modifiers if (item.Id == newItem.Id || String.CompareOrdinal(item.Id, newItem.Id) > 0) { items.Insert(i, newItem); return(newItem); } } // append to end of list items.Add(newItem); return(newItem); }
/// <summary> /// Checks the "Category" <see cref="RadioButton"/> that corresponds to the specified <see /// cref="VariableClass"/>, which is also selected in the "Variable" <see cref="ListView"/>. /// </summary> /// <param name="variable"> /// The <see cref="VariableClass"/> to select.</param> /// <exception cref="InvalidEnumArgumentException"> /// <paramref name="variable"/> specifies an invalid <see cref="VariableClass.Category"/> /// value.</exception> /// <remarks> /// Checking a "Category" radio button automatically shows the corresponding <see /// cref="VariableClass"/> objects in the "Variable" list view, via <see /// cref="OnCategoryChecked"/>.</remarks> private void SelectVariable(VariableClass variable) { switch (variable.Category) { case VariableCategory.Attribute: AttributeToggle.IsChecked = true; break; case VariableCategory.Resource: ResourceToggle.IsChecked = true; break; default: ThrowHelper.ThrowInvalidEnumArgumentException("variable.Category", (int)variable.Category, typeof(VariableCategory)); break; } // list view was initialized by checking radio button VariableList.SelectAndShow(variable); }
/// <summary> /// Allows the user to change the specified <see cref="VariableClass"/>.</summary> /// <param name="variable"> /// The <see cref="VariableClass"/> to change.</param> /// <remarks><para> /// <b>ChangeVariable</b> displays a <see cref="Dialog.ChangeVariable"/> dialog for the /// specified <paramref name="variable"/>. /// </para><para> /// If the user made any changes, <b>ChangeVariable</b> propagates them to the <see /// cref="CurrentVariables"/> collection and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void ChangeVariable(VariableClass variable) { if (variable == null) { return; } // show dialog and let user make changes var dialog = new Dialog.ChangeVariable(variable) { Owner = MainWindow.Instance }; dialog.ShowDialog(); // broadcast data changes, if any if (dialog.DataChanged) { VariableList.Items.Refresh(); SectionTab.DataChanged = true; } }
/// <summary> /// Initializes a new instance of the <see cref="ShowVariables"/> class with the specified /// initially selected <see cref="VariableClass"/>.</summary> /// <param name="variable"><para> /// The <see cref="VariableClass"/> to select initially. /// </para><para>-or-</para><para> /// A null reference to select the first <see cref="AttributeClass"/> or <see /// cref="ResourceClass"/>, in that order.</para></param> /// <exception cref="ArgumentException"> /// <paramref name="variable"/> is neither a null reference nor an element of the <see /// cref="VariableSection"/> collection that matches its <see /// cref="VariableClass.Category"/>.</exception> public ShowVariables(VariableClass variable) { if (variable != null) { var dictionary = MasterSection.Instance.Variables.GetVariables(variable.Category); // specified variable must be part of its collection if (!dictionary.ContainsKey(variable.Id)) { ThrowHelper.ThrowArgumentException( "variable", Global.Strings.ArgumentNotNullOrVariable); } this._variable = variable; } InitializeComponent(); // adjust column width of Variable list view DependencyPropertyDescriptor.FromProperty( ListView.ActualWidthProperty, typeof(ListView)) .AddValueChanged(VariableList, OnVariableWidthChanged); }
/// <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> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change ID" <see /// cref="Button"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks><para> /// <b>OnVariableId</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog for the /// first selected item in the "Variable" list view. /// </para><para> /// If the user made any changes, <b>OnVariableId</b> propagates them to the <see /// cref="CurrentVariables"/> collection and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnVariableId(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected variable, if any VariableClass variable = VariableList.SelectedItem as VariableClass; if (variable == null) { return; } // let user enter new variable ID var variables = CurrentVariables; var dialog = new Dialog.ChangeIdentifier(variable.Id, Global.Strings.TitleVariableIdChange, variables.ContainsKey, true); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new faction ID string id = String.Intern(dialog.Identifier); // change existing ID references if (!SectionTabItem.ProcessAllIdentifiers(variables, variable.Id, id)) { return; } // broadcast data changes VariableList.Items.Refresh(); SectionTab.DataChanged = true; }
/// <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)); }
/// <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> /// Initializes a new instance of the <see cref="ShowVariable"/> class with the specified /// initially selected <see cref="VariableClass"/> and <see cref="VariableDisplay"/> flags. /// </summary> /// <param name="variable"><para> /// The <see cref="VariableClass"/> to select initially. /// </para><para>-or-</para><para> /// A null reference to select the first <see cref="AttributeClass"/>, <see /// cref="ResourceClass"/>, or <see cref="CounterClass"/>, in that order.</para></param> /// <param name="flags"> /// A <see cref="VariableDisplay"/> value indicating which display flags to select /// initially.</param> /// <exception cref="ArgumentException"> /// <paramref name="variable"/> is neither a null reference nor an element of the <see /// cref="VariableSection"/> collection that matches its <see /// cref="VariableClass.Category"/>.</exception> /// <exception cref="InvalidEnumArgumentException"> /// <paramref name="variable"/> specifies an invalid <see cref="VariableClass.Category"/>. /// </exception> public ShowVariable(VariableClass variable, VariableDisplay flags) { InitializeComponent(); if (variable != null) { VariableSection variables = MasterSection.Instance.Variables; var dictionary = variables.GetVariables(variable.Category); // specified variable must be part of its collection if (!dictionary.ContainsKey(variable.Id)) { ThrowHelper.ThrowArgumentException( "variable", Global.Strings.ArgumentNotNullOrVariable); } } Variable = variable; VariableFlags = flags; // read specified display flags into check boxes if ((flags & VariableDisplay.Basic) != 0) { BasicToggle.IsChecked = true; } if ((flags & VariableDisplay.Modifier) != 0) { ModifierToggle.IsChecked = true; } if ((flags & VariableDisplay.Numbers) != 0) { NumbersToggle.IsChecked = true; } if ((flags & VariableDisplay.Shades) != 0) { ShadesToggle.IsChecked = true; } // adjust column width of Variable list view DependencyPropertyDescriptor.FromProperty( ListView.ActualWidthProperty, typeof(ListView)) .AddValueChanged(VariableList, OnVariableWidthChanged); if (variable != null) { // select specified variable, if any switch (variable.Category) { case VariableCategory.Attribute: AttributeToggle.IsChecked = true; break; case VariableCategory.Counter: CounterToggle.IsChecked = true; break; case VariableCategory.Resource: ResourceToggle.IsChecked = true; break; default: ThrowHelper.ThrowInvalidEnumArgumentException("variable.Category", (int)variable.Category, typeof(VariableCategory)); break; } VariableList.SelectAndShow(variable); } else { // select category with defined variables if (MasterSection.Instance.Variables.Attributes.Count > 0) { AttributeToggle.IsChecked = true; } else if (MasterSection.Instance.Variables.Resources.Count > 0) { ResourceToggle.IsChecked = true; } else if (MasterSection.Instance.Variables.Counters.Count > 0) { CounterToggle.IsChecked = true; } else { AttributeToggle.IsChecked = true; } } }
/// <summary> /// 读取一张sheet的数据保存起来 /// </summary> /// <param name="obj"></param> /// <param name="sClass"></param> /// <param name="nameSheetClassDic"></param> /// <param name="nameSheetDataDic"></param> private static void ReadData(object obj, SheetClass sClass, Dictionary <string, SheetClass> nameSheetClassDic, Dictionary <string, SheetData> nameSheetDataDic, string theMainKey) { List <VariableClass> allVarList = sClass.AllVariableList; VariableClass parentVar = sClass.ParentVarClass; //通过反射获取list object dataList = GetMemberValue(obj, parentVar.Name); int listCount = (int)dataList.GetType().InvokeMember("get_Count", BindingFlags.Default | BindingFlags.InvokeMethod, null, dataList, new object[] { }); SheetData shtData = new SheetData(); string tmpMainKey = theMainKey; //在循环之前就要判断当前sheetclass是否是外联表, if (!string.IsNullOrEmpty(parentVar.Foreign)) { //如果是外联表,就需要在这张新的页签添加多一列(在第一列添加) //值对应的是parentVar的上一级list的mainKey对应的值 shtData.AllNameList.Add(parentVar.Foreign); //TODO,这里添加的类型应该是mainKey对应的类型 shtData.AllTypeList.Add(parentVar.Type); } for (int i = 0; i < allVarList.Count; i++) { if (!string.IsNullOrEmpty(allVarList[i].Col)) { shtData.AllNameList.Add(allVarList[i].Col); shtData.AllTypeList.Add(allVarList[i].Type); } } for (int i = 0; i < listCount; i++) { object item = dataList.GetType().InvokeMember("get_Item", BindingFlags.Default | BindingFlags.InvokeMethod, null, dataList, new object[] { i }); RowData rData = new RowData(); if (!string.IsNullOrEmpty(tmpMainKey)) { rData.OneRowDataDic.Add(parentVar.Foreign, tmpMainKey); } else { theMainKey = GetMemberValue(item, sClass.MainKey).ToString(); } for (int j = 0; j < allVarList.Count; j++) { VariableClass varClass = allVarList[j]; if (varClass.Type == "list") { //这种情况处理自定义类的List,(有两种方式处理:1。用分隔符, 2.用主外键的方式,为附加的sheet添加多一列(放在第一列)) //根据有没有外键值来决定用那种方式处理自定义类的list if (string.IsNullOrEmpty(varClass.SplitStr)) { SheetClass _shtC = nameSheetClassDic[varClass.ListSheetName]; ReadData(item, _shtC, nameSheetClassDic, nameSheetDataDic, theMainKey); /* * <data name = "CustomData" from = "自定义配置.xlsx" to = "CustomData.xml"> * <variable name = "customDataList" type = "list"> * <list name = "CustomDataStructure" sheetname = "用户配置" mainKey = "Id"> * <variable name = "Id" col = "ID" type = "int"/> * <variable name = "Name" col = "名字" type = "string"/> * <variable name = "TestCustomList" type = "list" foreign = "ID"> * <list name = "TestCustomData" sheetname = "id对应子表"> * <variable name = "Id" col = "SubID" type = "int"/> * <variable name = "Name" col = "名字" type = "string"/> * </list> * </variable> * </list> * </variable> * </data> */ } else { #region 1。用分隔符 对应的结构 以及处理方式 SheetClass _shtC = nameSheetClassDic[varClass.ListSheetName]; string str = GetCustomListStr(item, _shtC); rData.OneRowDataDic.Add(varClass.Col, str); /* * <data name = "CustomData" from = "自定义配置.xlsx" to = "CustomData.xml"> * <variable name = "customDataList" type = "list"> * <list name = "CustomDataStructure" sheetname = "用户配置" mainKey = "Id"> * <variable name = "Id" col = "ID" type = "int"/> * <variable name = "Name" col = "名字" type = "string"/> * <variable name = "TestCustomList" col = "TestCustomList" type = "list" split = "|"> * <list name = "TestCustomData" sheetname = "id对应子表"> * <variable name = "Id" col = "ID" type = "int"/> * <variable name = "Name" col = "名字" type = "string"/> * </list> * </variable> * </list> * </variable> * </data> */ #endregion } } else if (varClass.Type == "listStr" || varClass.Type == "listInt" || varClass.Type == "listFloat" || varClass.Type == "listBool") { //处理基础数据类型的list变量 比如List<string>, 处理方式是用分隔符连接所有的值,然后返回一个字符串 string str = GetBaseListStr(item, varClass); rData.OneRowDataDic.Add(varClass.Col, str); } else { object tempObj = GetMemberValue(item, varClass.Name); rData.OneRowDataDic.Add(varClass.Col, tempObj.ToString()); } } string sheetKey = sClass.SheetName; if (nameSheetDataDic.ContainsKey(sheetKey)) { nameSheetDataDic[sheetKey].AllRowDataList.Add(rData); } else { shtData.AllRowDataList.Add(rData); nameSheetDataDic.Add(sheetKey, shtData); } } }
/// <summary> /// 读取reg文件夹的xml文件, 主要是为了确定excel的数据结构 /// </summary> private static void ReadRegXmlNode(XmlElement xmlEle, Dictionary <string, SheetClass> nameSheetClassDic, int depth) { depth++; foreach (XmlNode node in xmlEle.ChildNodes) { XmlElement xe = (XmlElement)node; if (xe.GetAttribute("type") == "list") { XmlElement subEle = (XmlElement)xe.FirstChild; VariableClass varClass = new VariableClass() { Name = xe.GetAttribute("name"), Col = xe.GetAttribute("col"), Type = xe.GetAttribute("type"), SplitStr = xe.GetAttribute("split"), Foreign = xe.GetAttribute("foreign"), DefaultValue = xe.GetAttribute("defaultvalue"), ListName = ((XmlElement)xe.FirstChild).GetAttribute("name"), ListSheetName = ((XmlElement)xe.FirstChild).GetAttribute("sheetname"), }; SheetClass _sheetClass = new SheetClass() { ParentVarClass = varClass, Name = subEle.GetAttribute("name"), SheetName = subEle.GetAttribute("sheetname"), MainKey = subEle.GetAttribute("mainKey"), SplitStr = subEle.GetAttribute("split"), Depth = depth, }; if (!string.IsNullOrEmpty(_sheetClass.SheetName)) { if (!nameSheetClassDic.ContainsKey(_sheetClass.SheetName)) { foreach (XmlNode inNode in subEle.ChildNodes) { XmlElement inEle = (XmlElement)inNode; VariableClass inVarClass = new VariableClass() { Name = inEle.GetAttribute("name"), Col = inEle.GetAttribute("col"), Type = inEle.GetAttribute("type"), SplitStr = inEle.GetAttribute("split"), Foreign = inEle.GetAttribute("foreign"), DefaultValue = inEle.GetAttribute("defaultvalue"), }; if (inVarClass.Type == "list") { inVarClass.ListName = ((XmlElement)inEle.FirstChild).GetAttribute("name"); inVarClass.ListSheetName = ((XmlElement)inEle.FirstChild).GetAttribute("sheetname"); } _sheetClass.AllVariableList.Add(inVarClass); } nameSheetClassDic.Add(_sheetClass.SheetName, _sheetClass); } } ReadRegXmlNode(subEle, nameSheetClassDic, depth); } } }
public override string ToString() { var indentString = "// " + new string(Enumerable.Repeat(' ', _indent).ToArray()); var sb = new StringBuilder(); if (_isFirst) { sb.AppendLine(indentString); } switch (VariableClass) { case ShaderVariableClass.InterfacePointer: case ShaderVariableClass.MatrixColumns: case ShaderVariableClass.MatrixRows: { sb.Append(indentString); if (!string.IsNullOrEmpty(BaseTypeName)) // BaseTypeName is only populated in SM 5.0 { sb.Append(string.Format("{0}{1}", VariableClass.GetDescription(), BaseTypeName)); } else { sb.Append(VariableClass.GetDescription()); sb.Append(VariableType.GetDescription()); if (Columns > 1) { sb.Append(Columns); if (Rows > 1) { sb.Append("x" + Rows); } } } break; } case ShaderVariableClass.Vector: { sb.Append(indentString + VariableType.GetDescription()); sb.Append(Columns); break; } case ShaderVariableClass.Struct: { if (!_isFirst) { sb.AppendLine(indentString); } sb.AppendLine(indentString + "struct " + BaseTypeName); sb.AppendLine(indentString + "{"); foreach (var member in Members) { sb.AppendLine(member.ToString()); } sb.AppendLine("//"); sb.Append(indentString + "}"); break; } case ShaderVariableClass.Scalar: { sb.Append(indentString + VariableType.GetDescription()); break; } default: throw new InvalidOperationException(string.Format("Variable class '{0}' is not currently supported.", VariableClass)); } return(sb.ToString()); }
private static void WriteToClass(object classObj, string shtName, Dictionary <string, SheetClass> nameSheetClassDic, Dictionary <string, SheetData> nameSheetDataDic, string mainKeyValue) { SheetClass shtClass = nameSheetClassDic[shtName]; SheetData shtData = nameSheetDataDic[shtName]; object tempObj = CreateClassObjByName(shtClass.Name); object listObj = CreateListByType(tempObj.GetType()); for (int i = 0; i < shtData.AllRowDataList.Count; i++) { if (!string.IsNullOrEmpty(shtData.AllRowDataList[i].ForeignKey)) { if (shtData.AllRowDataList[i].ForeignKey != mainKeyValue) { //如果是子表,并且这个子表的ForeignKey不等于主表的mainKey,就continue //也就是不写进tObj中 continue; } } object tObj = CreateClassObjByName(shtClass.Name); for (int j = 0; j < shtClass.AllVariableList.Count; j++) { VariableClass varClass = shtClass.AllVariableList[j]; if (varClass.Type.Trim() == "list") { if (string.IsNullOrEmpty(varClass.SplitStr)) { string tmpMainKey = GetMemberValue(tObj, shtClass.MainKey).ToString(); WriteToClass(tObj, varClass.ListSheetName, nameSheetClassDic, nameSheetDataDic, tmpMainKey); } else { //用分隔符保存的excel数据 SheetClass tmpShtClass = nameSheetClassDic[varClass.ListSheetName]; object customClassObj = CreateClassObjByName(tmpShtClass.Name); object customListObj = CreateListByType(customClassObj.GetType()); string tmpStr = shtData.AllRowDataList[i].OneRowDataDic[varClass.Col]; if (string.IsNullOrEmpty(tmpStr)) { Debug.LogError("excel中没有值,对应列名: " + varClass.Col); return; } string[] tmpStrArray = tmpStr.Split('\n'); for (int tmpI = 0; tmpI < tmpStrArray.Length; tmpI++) { string oneStr = tmpStrArray[tmpI]; string[] oneStrArray = oneStr.Split(new string[] { varClass.SplitStr.Trim() }, StringSplitOptions.None); object oneCusClassObj = CreateClassObjByName(tmpShtClass.Name); for (int oneI = 0; oneI < oneStrArray.Length; oneI++) { PropertyInfo tmpInfo = oneCusClassObj.GetType().GetProperty(tmpShtClass.AllVariableList[oneI].Name); SetValueByType(tmpInfo, oneCusClassObj, oneStrArray[oneI], tmpShtClass.AllVariableList[oneI].Type); } customListObj.GetType().InvokeMember("Add", BindingFlags.Default | BindingFlags.InvokeMethod, null, customListObj, new object[] { oneCusClassObj }); } tObj.GetType().GetProperty(varClass.Name).SetValue(tObj, customListObj, new object[] { }); } } else if (varClass.Type == "listStr" || varClass.Type == "listInt" || varClass.Type == "listFloat" || varClass.Type == "listBool") { Type _tmpType = GetBaseTypeByType(varClass.Type); if (_tmpType == null) { Debug.LogError(varClass.Type + " 在已存在的类型中没有找到"); return; } object inlistObj = CreateListByType(_tmpType); string invalue = shtData.AllRowDataList[i].OneRowDataDic[varClass.Col]; if (string.IsNullOrEmpty(invalue)) { Debug.LogError("excel中没有值,对应列名: " + varClass.Col); return; } string[] strArray = invalue.Split(System.Convert.ToChar(varClass.SplitStr)); for (int strcount = 0; strcount < strArray.Length; strcount++) { string inlistValue = strArray[strcount].Trim(); if (!string.IsNullOrEmpty(inlistValue)) { inlistObj.GetType().InvokeMember("Add", BindingFlags.Default | BindingFlags.InvokeMethod, null, inlistObj, new object[] { inlistValue }); } else { Debug.Log("基础数据类型的List的值为null"); } } tObj.GetType().GetProperty(varClass.Name).SetValue(tObj, inlistObj, new object[] { }); } else { PropertyInfo pInfo = tObj.GetType().GetProperty(varClass.Name); string value = shtData.AllRowDataList[i].OneRowDataDic[varClass.Col]; if (string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(varClass.DefaultValue)) { value = varClass.DefaultValue; } if (string.IsNullOrEmpty(value)) { Debug.LogError(string.Format("当前列< {0} >下的值是空的,并且reg文件中也没有设置默认值", varClass.Col)); return; } SetValueByType(pInfo, tObj, value, shtData.AllTypeList[j]); } } listObj.GetType().InvokeMember("Add", BindingFlags.Default | BindingFlags.InvokeMethod, null, listObj, new object[] { tObj }); } classObj.GetType().GetProperty(shtClass.ParentVarClass.Name).SetValue(classObj, listObj, new object[] { }); }
/// <summary> /// Initializes a new instance of the <see cref="ChangeVariable"/> class with the specified /// <see cref="VariableClass"/>.</summary> /// <param name="variable"> /// The <see cref="VariableClass"/> whose data to change.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="variable"/> is a null reference.</exception> /// <remarks> /// The data of the specified <paramref name="variable"/> may be changed in the dialog, as /// indicated by the value of the <see cref="DataChanged"/> property.</remarks> public ChangeVariable(VariableClass variable) { if (variable == null) { ThrowHelper.ThrowArgumentNullException("variable"); } this._variable = variable; this._resource = variable as ResourceClass; // may be null InitializeComponent(); Title = Title + variable.Id; // assign strings to text controls NameBox.Text = this._variable.Name; DetailBox.Text = String.Join(Environment.NewLine, this._variable.Paragraphs); // retrieve maximum variable range int min = VariableClass.AbsoluteMinimum; int max = VariableClass.AbsoluteMaximum; // most numeric controls use maximum range MinimumUpDown.Minimum = min; MinimumUpDown.Maximum = max; MaximumUpDown.Minimum = min; MaximumUpDown.Maximum = max; DefeatUpDown.Minimum = min; DefeatUpDown.Maximum = max; VictoryUpDown.Minimum = min; VictoryUpDown.Maximum = max; // assign checked values to range and scale controls MinimumUpDown.Value = Math.Max(min, Math.Min(max, this._variable.Minimum)); MaximumUpDown.Value = Math.Max(min, Math.Min(max, this._variable.Maximum)); ScaleUpDown.Value = Math.Max(1, Math.Min(100, this._variable.Scale)); // disable Resource Options if not needed if (this._resource == null) { ResourceOptions.IsEnabled = false; } else { // assign resource flags to check boxes ResetToggle.IsChecked = this._resource.IsResetting; LimitToggle.IsChecked = this._resource.IsLimited; DepleteToggle.IsChecked = this._resource.IsDepletable; // assign Defeat value or disable control if (this._resource.Defeat != Int32.MinValue) { DefeatToggle.IsChecked = true; DefeatUpDown.Value = Math.Max(min, Math.Min(max, this._resource.Defeat)); } else { DefeatUpDown.Enabled = false; } // assign Victory value or disable control if (this._resource.Victory != Int32.MaxValue) { VictoryToggle.IsChecked = true; VictoryUpDown.Value = Math.Max(min, Math.Min(max, this._resource.Victory)); } else { VictoryUpDown.Enabled = false; } } // construction completed this._initialized = true; }