private void AddBlock(string blockName, int templateIndex) { Template.Block templateBlock = Helper.Template.Data.Files[this.Data.TemplateIndex].Blocks.Values[templateIndex]; // add options to new block EditorIniBlock editorBlock = new EditorIniBlock(blockName, templateIndex); for (int i = 0; i < templateBlock.Options.Count; ++i) { Template.Option option = templateBlock.Options[i]; editorBlock.Options.Add(new EditorIniOption(option.Name, i)); if (templateBlock.Identifier != null && templateBlock.Identifier.Equals(editorBlock.Options[editorBlock.Options.Count - 1].Name, StringComparison.OrdinalIgnoreCase)) { editorBlock.MainOptionIndex = editorBlock.Options.Count - 1; editorBlock.Options[editorBlock.Options.Count - 1].Values.Add(new EditorIniEntry(blockName)); } } // add actual block this.AddBlocks(new List <TableBlock> { new TableBlock(this.GetNewBlockId(), this.Data.MaxId++, editorBlock, this.Data.TemplateIndex) }); }
public PropertyOption(List <EditorINIEntry> options, Template.Option templateOption, bool children) { Name = templateOption.Name; Category = templateOption.Category; Description = templateOption.Description; if (templateOption.Multiple) { Attributes = new Attribute[] { new EditorAttribute(typeof(UITypeEditor), typeof(UITypeEditor)), new TypeConverterAttribute(typeof(PropertyOptionCollectionConverter)) }; Value = new PropertySubOptions(templateOption.Name, options, children); } else { Value = options.Count > 0 ? options[0].Value : string.Empty; } }
private static EditorIniData GetEditorData(List <IniBlock> iniData, int templateFileIndex) { #if DEBUG Stopwatch st = new Stopwatch(); st.Start(); #endif EditorIniData editorData = new EditorIniData(templateFileIndex); Template.File templateFile = Helper.Template.Data.Files[templateFileIndex]; // loop each ini block foreach (IniBlock iniBlock in iniData) { Template.Block templateBlock; int templateBlockIndex; // get template block based on ini block name if (templateFile.Blocks.TryGetValue(iniBlock.Name, out templateBlock, out templateBlockIndex)) { EditorIniBlock editorBlock = new EditorIniBlock(templateBlock.Name, templateBlockIndex) { Comments = iniBlock.Comments }; // loop each template option for (int j = 0; j < templateBlock.Options.Count; ++j) { // handle nested options Template.Option childTemplateOption = null; if (j < templateBlock.Options.Count - 1 && templateBlock.Options[j + 1].Parent != null) { // next option is child of current option childTemplateOption = templateBlock.Options[j + 1]; } Template.Option templateOption = templateBlock.Options[j]; EditorIniOption editorOption = new EditorIniOption(templateOption.Name, j); // get ini options based on all possible template option names List <IniOption> iniOptions; iniBlock.Options.TryGetValue(templateOption.Name, out iniOptions); // search for options with alternative names if (templateOption.RenameFrom != null) { string[] namesFromRename = templateOption.RenameFrom.Split(new[] { ',' }); for (int nameIndex = 0; nameIndex < namesFromRename.Length; ++nameIndex) { List <IniOption> alternativeOptions; if (iniBlock.Options.TryGetValue(namesFromRename[nameIndex], out alternativeOptions)) { iniOptions.AddRange(alternativeOptions); // stop searching after we found the first option group with the correct name break; } } } if (iniOptions != null) { // h is used to start again at last child option in order to provide better performance int h = 0; if (templateOption.Multiple) { // loop each ini option for (int k = 0; k < iniOptions.Count; ++k) { List <object> editorChildOptions = null; List <IniOption> iniChildOptions; // get ini options of child based on child's template option name if (childTemplateOption != null && iniBlock.Options.TryGetValue(childTemplateOption.Name, out iniChildOptions)) { editorOption.ChildTemplateIndex = j + 1; editorOption.ChildName = childTemplateOption.Name; editorChildOptions = new List <object>(); // loop each ini option of child for (; h < iniChildOptions.Count; ++h) { IniOption childOption = iniChildOptions[h]; if (k < iniOptions.Count - 1 && childOption.Index > iniOptions[k + 1].Index) { break; } if (childOption.Index > iniOptions[k].Index) { editorChildOptions.Add(childOption.Value); } } } // add entry of multiple option editorOption.Values.Add(new EditorIniEntry(iniOptions[k].Value, editorChildOptions)); } } else { // single option if (iniOptions.Count > 0) { if (iniOptions[0].Value.Length > 0) { // just add the last option (Freelancer like) if aviable to prevent multiple options which should be single editorOption.Values.Add(new EditorIniEntry(iniOptions[iniOptions.Count - 1].Value)); } else { // use '=' for options which dont have values and are simply defined when using the option key followed by a colon equal editorOption.Values.Add(new EditorIniEntry("=")); } } } // add option editorBlock.Options.Add(editorOption); } else { // add empty option based on template editorBlock.Options.Add(new EditorIniOption(templateOption.Name, j)); } // set index of main option (value displayed in table view) if (templateBlock.Identifier != null && templateBlock.Identifier.Equals(editorBlock.Options[editorBlock.Options.Count - 1].Name, StringComparison.OrdinalIgnoreCase)) { editorBlock.MainOptionIndex = editorBlock.Options.Count - 1; } // ignore next option because we already added it as children to the current option if (childTemplateOption != null) { ++j; } } // add block editorData.Blocks.Add(editorBlock); } } #if DEBUG st.Stop(); Debug.WriteLine("typecast data: " + st.ElapsedMilliseconds + "ms"); #endif return(editorData); }
EditorINIData GetEditorData(INIBlocks iniData, int templateFileIndex) { #if DEBUG System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch(); st.Start(); #endif EditorINIData editorData = new EditorINIData(templateFileIndex); //loop each template block for (int i = 0; i < Helper.Template.Data.Files[templateFileIndex].Blocks.Count; i++) { Template.Block templateBlock = Helper.Template.Data.Files[templateFileIndex].Blocks[i]; List <INIOptions> iniBlocks; if (iniData.TryGetValue(templateBlock.Name, out iniBlocks)) { //loop each ini block foreach (INIOptions iniBlock in iniBlocks) { EditorINIBlock editorBlock = new EditorINIBlock(templateBlock.Name, i); //loop each template option for (int j = 0; j < templateBlock.Options.Count; j++) { Template.Option childTemplateOption = null; if (j < templateBlock.Options.Count - 1 && templateBlock.Options[j + 1].Parent != null) { //next option is child of current option childTemplateOption = templateBlock.Options[j + 1]; } Template.Option templateOption = templateBlock.Options[j]; EditorINIOption editorOption = new EditorINIOption(templateOption.Name, j); List <INIOption> iniOptions; if (iniBlock.TryGetValue(templateOption.Name, out iniOptions)) { //h is used to start again at last child option in order to provide better performance int h = 0; if (templateOption.Multiple) { //loop each ini option for (int k = 0; k < iniOptions.Count; k++) { List <object> editorChildOptions = null; List <INIOption> iniChildOptions; if (childTemplateOption != null && iniBlock.TryGetValue(childTemplateOption.Name, out iniChildOptions)) { editorOption.ChildTemplateIndex = j + 1; editorOption.ChildName = childTemplateOption.Name; editorChildOptions = new List <object>(); //loop each ini option of child for (; h < iniChildOptions.Count; h++) { INIOption childOption = iniChildOptions[h]; if (k < iniOptions.Count - 1 && childOption.Index > iniOptions[k + 1].Index) { break; } if (childOption.Index > iniOptions[k].Index) { editorChildOptions.Add(ConvertToTemplate(childTemplateOption.Type, childOption.Value)); } } } //add entry editorOption.Values.Add(new EditorINIEntry(ConvertToTemplate(templateOption.Type, iniOptions[k].Value), editorChildOptions)); } } else { //just add the first option if aviable to prevent multiple options which should be single if (iniBlock[templateOption.Name].Count > 0) { editorOption.Values.Add(new EditorINIEntry(ConvertToTemplate(templateOption.Type, iniOptions[0].Value))); } } //add option editorBlock.Options.Add(editorOption); } else { //add empty option editorBlock.Options.Add(new EditorINIOption(templateOption.Name, j)); } //set index of main option (value displayed in table view) if (templateBlock.Identifier != null && templateBlock.Identifier.ToLower() == editorBlock.Options[editorBlock.Options.Count - 1].Name.ToLower()) { editorBlock.MainOptionIndex = editorBlock.Options.Count - 1; } //ignore next option because we already added it as children to the current option if (childTemplateOption != null) { j++; } } //add block editorData.Blocks.Add(editorBlock); } } } #if DEBUG st.Stop(); System.Diagnostics.Debug.WriteLine("typecast data: " + st.ElapsedMilliseconds + "ms"); #endif return(editorData); }