コード例 #1
0
        //Parses a #FEATURES text block
        public static UIFeature[] GetUIFeatures(StringReader reader)
        {
            var    uiFeaturesList = new List <UIFeature>();
            string subline;
            var    overflow = 0;

            while ((subline = reader.ReadLine()) != "#END")
            {
                //Just in case template file is badly written
                overflow++;
                if (overflow > 99999)
                {
                    break;
                }

                //Empty line
                if (string.IsNullOrEmpty(subline))
                {
                    continue;
                }

                var data = subline.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                //Skip empty or comment # lines
                if (data == null || data.Length == 0 || (data.Length > 0 && data[0].StartsWith("#")))
                {
                    continue;
                }

                var kvpList = new List <KeyValuePair <string, string> >();
                for (var i = 1; i < data.Length; i++)
                {
                    var sdata = data[i].Split('=');
                    if (sdata.Length == 2)
                    {
                        kvpList.Add(new KeyValuePair <string, string>(sdata[0], sdata[1]));
                    }
                    else if (sdata.Length == 1)
                    {
                        kvpList.Add(new KeyValuePair <string, string>(sdata[0], null));
                    }
                    else
                    {
                        Debug.LogError("Couldn't parse UI property from Template:\n" + data[i]);
                    }
                }

                UIFeature feature = null;
                switch (data[0])
                {
                case "---": feature = new UIFeature_Separator(); break;

                case "space": feature = new UIFeature_Space(kvpList); break;

                case "flag": feature = new UIFeature_Flag(kvpList); break;

                case "float": feature = new UIFeature_Float(kvpList); break;

                case "subh": feature = new UIFeature_SubHeader(kvpList); break;

                case "header": feature = new UIFeature_Header(kvpList); break;

                case "warning": feature = new UIFeature_Warning(kvpList); break;

                case "sngl": feature = new UIFeature_Single(kvpList); break;

                case "mult": feature = new UIFeature_Multiple(kvpList); break;

                case "keyword": feature = new UIFeature_Keyword(kvpList); break;

                case "mask": feature = new UIFeature_Mask(kvpList); break;

                case "shader_target": feature = new UIFeature_ShaderTarget(); break;

                case "dd_start": feature = new UIFeature_DropDownStart(kvpList); break;

                case "dd_end": feature = new UIFeature_DropDownEnd(); break;
                //case "texture_list": feature = new UIFeature_TextureList(); break;
                //case "tex": feature = new UIFeature_Texture(kvpList); break;

                default: feature = new UIFeature(kvpList); break;
                }

                uiFeaturesList.Add(feature);
            }
            return(uiFeaturesList.ToArray());
        }
コード例 #2
0
 public static void ClearFoldoutStack()
 {
     UIFeature_DropDownStart.ClearDropDownsList();
     FoldoutStack.Clear();
 }
コード例 #3
0
            //Parses a #FEATURES text block
            internal static UIFeature[] GetUIFeatures(string[] lines, ref int i, Template template)
            {
                var    uiFeaturesList = new List <UIFeature>();
                string subline;

                do
                {
                    subline = lines[i];
                    i++;

                    //Empty line
                    if (string.IsNullOrEmpty(subline))
                    {
                        continue;
                    }

                    var data = subline.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    //Skip empty or comment # lines
                    if (data == null || data.Length == 0 || (data.Length > 0 && data[0].StartsWith("#")))
                    {
                        continue;
                    }

                    var kvpList = new List <KeyValuePair <string, string> >();
                    for (var j = 1; j < data.Length; j++)
                    {
                        var sdata = data[j].Split('=');
                        if (sdata.Length == 2)
                        {
                            kvpList.Add(new KeyValuePair <string, string>(sdata[0], sdata[1]));
                        }
                        else if (sdata.Length == 1)
                        {
                            kvpList.Add(new KeyValuePair <string, string>(sdata[0], null));
                        }
                        else
                        {
                            Debug.LogError("Couldn't parse UI property from Template:\n" + data[j]);
                        }
                    }

                    // Discard the UIFeature if not for this template:
                    var templateCompatibility = kvpList.Find(kvp => kvp.Key == "templates");
                    if (templateCompatibility.Key == "templates")
                    {
                        if (!templateCompatibility.Value.Contains(template.id))
                        {
                            continue;
                        }
                    }

                    UIFeature feature = null;
                    switch (data[0])
                    {
                    case "---": feature = new UIFeature_Separator(); break;

                    case "space": feature = new UIFeature_Space(kvpList); break;

                    case "flag": feature = new UIFeature_Flag(kvpList, false); break;

                    case "nflag": feature = new UIFeature_Flag(kvpList, true); break;

                    case "float": feature = new UIFeature_Float(kvpList); break;

                    case "subh": feature = new UIFeature_SubHeader(kvpList); break;

                    case "header": feature = new UIFeature_Header(kvpList); break;

                    case "warning": feature = new UIFeature_Warning(kvpList); break;

                    case "sngl": feature = new UIFeature_Single(kvpList); break;

                    case "mult": feature = new UIFeature_Multiple(kvpList); break;

                    case "keyword": feature = new UIFeature_Keyword(kvpList); break;

                    case "keyword_str": feature = new UIFeature_KeywordString(kvpList); break;

                    case "dd_start": feature = new UIFeature_DropDownStart(kvpList); break;

                    case "dd_end": feature = new UIFeature_DropDownEnd(); break;

                    case "mult_fs": feature = new UIFeature_MultipleFixedFunction(kvpList); break;

                    default: feature = new UIFeature(kvpList); break;
                    }

                    uiFeaturesList.Add(feature);
                }while(subline != "#END" && i < lines.Length);

                var uiFeaturesArray = uiFeaturesList.ToArray();

                // Build hierarchy from the parsed UIFeatures
                // note: simple hierarchy, where only a top-level element can be parent (one level only)
                UIFeature lastParent = null;

                for (int j = 0; j < uiFeaturesArray.Length; j++)
                {
                    var uiFeature = uiFeaturesArray[j];
                    if (uiFeature.indentLevel == 0 && !(uiFeature is UIFeature_Header) && !(uiFeature is UIFeature_Warning) && !uiFeature.inline)
                    {
                        lastParent = uiFeature;
                    }
                    else if (uiFeature.indentLevel > 0)
                    {
                        uiFeature.parent = lastParent;
                    }
                }

                return(uiFeaturesList.ToArray());
            }