/// <summary> /// Binds the <see cref="ConditionalOptionTypeResolver"/> being edited to the UI. /// </summary> /// <param name="p_ctpTypeResolver">The <see cref="ConditionalOptionTypeResolver"/> being edited.</param> protected void BindTypeResolver(ConditionalOptionTypeResolver p_ctpTypeResolver) { m_otrTypeResolver = p_ctpTypeResolver; cbxDefaultType.DataBindings.Clear(); BindingHelper.CreateFullBinding(cbxDefaultType, () => cbxDefaultType.SelectedItem, p_ctpTypeResolver, () => p_ctpTypeResolver.DefaultType); lvwConditionalTypes.Items.Clear(); foreach (ConditionalOptionTypeResolver.ConditionalTypePattern ctpPattern in p_ctpTypeResolver.ConditionalTypePatterns) AddConditionalTypePattern(ctpPattern); }
/// <summary> /// A simple constructor that initializes the view model with its dependencies. /// </summary> /// <param name="p_tpeConditionalTypePatternEditorVM">The <see cref="NodeEditors.ConditionalTypePatternEditorVM"/> that encapsulates the data /// and operations for diaplying the <see cref="ConditionalTypePattern"/> editor.</param> /// <param name="p_ctrCPLConverter">The <see cref="CPLConverter"/> to use to convert <see cref="ICondition"/>s /// conditions to a string.</param> /// <param name="p_ctrTypeResolver">The <see cref="ConditionalOptionTypeResolver"/> being edited.</param> public ConditionalTypeEditorVM(ConditionalTypePatternEditorVM p_tpeConditionalTypePatternEditorVM, CPLConverter p_ctrCPLConverter, ConditionalOptionTypeResolver p_ctrTypeResolver) { ConditionalTypePatternEditorVM = p_tpeConditionalTypePatternEditorVM; Converter = p_ctrCPLConverter; TypeResolver = p_ctrTypeResolver; OptionTypes = Enum.GetValues(typeof(OptionType)); EditCommand = new Command <ConditionalTypePattern>("Edit", "Edit the selected conditional type.", EditConditionalTypePattern, false); AddCommand = new Command <ConditionalTypePattern>("Add", "Add a conditional type.", AddConditionalTypePattern); DeleteCommand = new Command <ConditionalTypePattern>("Delete", "Delete the selected conditional type.", DeleteConditionalTypePattern, false); }
/// <summary> /// Binds the <see cref="ConditionalOptionTypeResolver"/> being edited to the UI. /// </summary> /// <param name="p_ctpTypeResolver">The <see cref="ConditionalOptionTypeResolver"/> being edited.</param> protected void BindTypeResolver(ConditionalOptionTypeResolver p_ctpTypeResolver) { m_otrTypeResolver = p_ctpTypeResolver; cbxDefaultType.DataBindings.Clear(); BindingHelper.CreateFullBinding(cbxDefaultType, () => cbxDefaultType.SelectedItem, p_ctpTypeResolver, () => p_ctpTypeResolver.DefaultType); lvwConditionalTypes.Items.Clear(); foreach (ConditionalOptionTypeResolver.ConditionalTypePattern ctpPattern in p_ctpTypeResolver.ConditionalTypePatterns) { AddConditionalTypePattern(ctpPattern); } }
/// <summary> /// Reads a option's information from the script file. /// </summary> /// <param name="p_xelOption">The script file node corresponding to the option to read.</param> /// <returns>The option information.</returns> protected override Option ParseOption(XElement p_xelOption) { string strName = p_xelOption.Attribute("name").Value; string strDesc = p_xelOption.Element("description").Value.Trim(); IOptionTypeResolver iptType = null; XElement xelTypeDescriptor = p_xelOption.Element("typeDescriptor").Elements().First(); switch (xelTypeDescriptor.Name.LocalName) { case "type": iptType = new StaticOptionTypeResolver((OptionType)Enum.Parse(typeof(OptionType), xelTypeDescriptor.Attribute("name").Value)); break; case "dependencyType": OptionType ptpDefaultType = (OptionType)Enum.Parse(typeof(OptionType), xelTypeDescriptor.Element("defaultType").Attribute("name").Value); iptType = new ConditionalOptionTypeResolver(ptpDefaultType); ConditionalOptionTypeResolver cotConditionalType = (ConditionalOptionTypeResolver)iptType; IEnumerable <XElement> xeePatterns = xelTypeDescriptor.XPathSelectElements("patterns/*"); foreach (XElement xelPattern in xeePatterns) { OptionType ptpType = (OptionType)Enum.Parse(typeof(OptionType), xelPattern.Element("type").Attribute("name").Value); ICondition cpcCondition = LoadCondition(xelPattern.Element("dependencies")); cotConditionalType.AddPattern(ptpType, cpcCondition); } break; default: throw new ParserException("Invalid option type descriptor node: " + xelTypeDescriptor.Name + ". At this point the config file has been validated against the schema, so there's something wrong with the parser."); } XElement xelImage = p_xelOption.Element("image"); string strImageFilePath = null; if (xelImage != null) { strImageFilePath = xelImage.Attribute("path").Value; } Option optOption = new Option(strName, strDesc, strImageFilePath, iptType); IEnumerable <XElement> xeeOptionFiles = p_xelOption.XPathSelectElements("files/*"); optOption.Files.AddRange(ReadFileInfo(xeeOptionFiles)); IEnumerable <XElement> xeePluginFlags = p_xelOption.XPathSelectElements("conditionFlags/*"); optOption.Flags.AddRange(ReadFlagInfo(xeePluginFlags)); return(optOption); }
public OptionTypeResolverEditorVM(ConditionalTypeEditorVM p_tvmConditionResolverVM, Option p_optOption) { ConditionalTypeEditorVM = p_tvmConditionResolverVM; Option = p_optOption; OptionTypes = Enum.GetValues(typeof(OptionType)); if (Option.OptionTypeResolver is StaticOptionTypeResolver) { StaticOptionTypeResolver = (StaticOptionTypeResolver)Option.OptionTypeResolver; ConditionalOptionTypeResolver = new ConditionalOptionTypeResolver(OptionType.NotUsable); } if (Option.OptionTypeResolver is ConditionalOptionTypeResolver) { StaticOptionTypeResolver = new StaticOptionTypeResolver(OptionType.NotUsable); ConditionalOptionTypeResolver = (ConditionalOptionTypeResolver)Option.OptionTypeResolver; } p_tvmConditionResolverVM.TypeResolver = ConditionalOptionTypeResolver; }
public OptionTypeResolverEditorVM(ConditionalTypeEditorVM p_tvmConditionResolverVM, Option p_optOption) { ConditionalTypeEditorVM = p_tvmConditionResolverVM; Option = p_optOption; OptionTypes = Enum.GetValues(typeof(OptionType)); if (Option.OptionTypeResolver is StaticOptionTypeResolver) { StaticOptionTypeResolver = (StaticOptionTypeResolver)Option.OptionTypeResolver; ConditionalOptionTypeResolver = new ConditionalOptionTypeResolver(OptionType.NotUsable); } if (Option.OptionTypeResolver is ConditionalOptionTypeResolver) { StaticOptionTypeResolver = new StaticOptionTypeResolver(OptionType.NotUsable); ConditionalOptionTypeResolver = (ConditionalOptionTypeResolver)Option.OptionTypeResolver; } p_tvmConditionResolverVM.TypeResolver = ConditionalOptionTypeResolver; }
/// <summary> /// Reads a option's information from the script file. /// </summary> /// <param name="p_xelOption">The script file node corresponding to the option to read.</param> /// <returns>The option information.</returns> protected override Option ParseOption(XElement p_xelOption) { string strName = p_xelOption.Attribute("name").Value; string strDesc = p_xelOption.Element("description").Value.Trim(); IOptionTypeResolver iptType = null; XElement xelTypeDescriptor = p_xelOption.Element("typeDescriptor").Elements().First(); switch (xelTypeDescriptor.Name.LocalName) { case "type": iptType = new StaticOptionTypeResolver((OptionType)Enum.Parse(typeof(OptionType), xelTypeDescriptor.Attribute("name").Value)); break; case "dependencyType": OptionType ptpDefaultType = (OptionType)Enum.Parse(typeof(OptionType), xelTypeDescriptor.Element("defaultType").Attribute("name").Value); iptType = new ConditionalOptionTypeResolver(ptpDefaultType); ConditionalOptionTypeResolver cotConditionalType = (ConditionalOptionTypeResolver)iptType; IEnumerable<XElement> xeePatterns = xelTypeDescriptor.XPathSelectElements("patterns/*"); foreach (XElement xelPattern in xeePatterns) { OptionType ptpType = (OptionType)Enum.Parse(typeof(OptionType), xelPattern.Element("type").Attribute("name").Value); ICondition cpcCondition = LoadCondition(xelPattern.Element("dependencies")); cotConditionalType.AddPattern(ptpType, cpcCondition); } break; default: throw new ParserException("Invalid option type descriptor node: " + xelTypeDescriptor.Name + ". At this point the config file has been validated against the schema, so there's something wrong with the parser."); } XElement xelImage = p_xelOption.Element("image"); string strImageFilePath = null; if (xelImage != null) strImageFilePath = xelImage.Attribute("path").Value; Option optOption = new Option(strName, strDesc, strImageFilePath, iptType); IEnumerable<XElement> xeeOptionFiles = p_xelOption.XPathSelectElements("files/*"); optOption.Files.AddRange(ReadFileInfo(xeeOptionFiles)); IEnumerable<XElement> xeePluginFlags = p_xelOption.XPathSelectElements("conditionFlags/*"); optOption.Flags.AddRange(ReadFlagInfo(xeePluginFlags)); return optOption; }
/// <summary> /// Unparses the given <see cref="ConditionalOptionTypeResolver.ConditionalTypePattern"/>. /// </summary> /// <remarks> /// This method can be overidden to provide game-specific or newer-version unparsing. /// </remarks> /// <param name="p_ctpPattern">The <see cref="ConditionalOptionTypeResolver.ConditionalTypePattern"/> for which to generate XML.</param> /// <returns>The XML representation of the given <see cref="ConditionalOptionTypeResolver.ConditionalTypePattern"/>.</returns> protected virtual XElement UnparseConditionalTypePattern(ConditionalOptionTypeResolver.ConditionalTypePattern p_ctpPattern) { XElement xelPattern = new XElement("pattern"); if (p_ctpPattern.Condition is CompositeCondition) xelPattern.Add(UnparseCondition(p_ctpPattern.Condition)); else { XElement xelCompositeCondition = new XElement("dependancies", UnparseCondition(p_ctpPattern.Condition)); xelPattern.Add(xelCompositeCondition); } XElement xelType = new XElement("type", new XAttribute("name", UnparseOptionType(p_ctpPattern.Type))); xelPattern.Add(xelType); return xelPattern; }
/// <summary> /// A simple constructor that initializes the view model with its dependencies. /// </summary> /// <param name="p_tpeConditionalTypePatternEditorVM">The <see cref="NodeEditors.ConditionalTypePatternEditorVM"/> that encapsulates the data /// and operations for diaplying the <see cref="ConditionalTypePattern"/> editor.</param> /// <param name="p_ctrCPLConverter">The <see cref="CPLConverter"/> to use to convert <see cref="ICondition"/>s /// conditions to a string.</param> /// <param name="p_ctrTypeResolver">The <see cref="ConditionalOptionTypeResolver"/> being edited.</param> public ConditionalTypeEditorVM(ConditionalTypePatternEditorVM p_tpeConditionalTypePatternEditorVM, CPLConverter p_ctrCPLConverter, ConditionalOptionTypeResolver p_ctrTypeResolver) { ConditionalTypePatternEditorVM = p_tpeConditionalTypePatternEditorVM; Converter = p_ctrCPLConverter; TypeResolver = p_ctrTypeResolver; OptionTypes = Enum.GetValues(typeof(OptionType)); EditCommand = new Command<ConditionalTypePattern>("Edit", "Edit the selected conditional type.", EditConditionalTypePattern, false); AddCommand = new Command<ConditionalTypePattern>("Add", "Add a conditional type.", AddConditionalTypePattern); DeleteCommand = new Command<ConditionalTypePattern>("Delete", "Delete the selected conditional type.", DeleteConditionalTypePattern, false); }