Ejemplo n.º 1
0
        public static void DrawCurveLines(Rect rect, SimpleCurveDrawInfo curve, bool drawPoints, Rect viewRect, bool useAALines, bool pointsRemoveOptimization)
        {
            if (curve.curve == null || curve.curve.PointsCount == 0)
            {
                return;
            }
            Rect position = rect;

            position.yMin -= 1f;
            position.yMax += 1f;
            GUI.BeginGroup(position);
            if (Event.current.type == EventType.Repaint)
            {
                if (useAALines)
                {
                    bool    flag       = true;
                    Vector2 start      = default(Vector2);
                    Vector2 curvePoint = default(Vector2);
                    int     num        = curve.curve.Points.Count((CurvePoint x) => x.x >= viewRect.xMin && x.x <= viewRect.xMax);
                    int     num2       = RemovePointsOptimizationFreq(num);
                    for (int i = 0; i < curve.curve.PointsCount; i++)
                    {
                        CurvePoint curvePoint2 = curve.curve[i];
                        if (!pointsRemoveOptimization || i % num2 != 0 || i == 0 || i == num - 1)
                        {
                            curvePoint.x = curvePoint2.x;
                            curvePoint.y = curvePoint2.y;
                            Vector2 vector = CurveToScreenCoordsInsideScreenRect(rect, viewRect, curvePoint);
                            if (flag)
                            {
                                flag = false;
                            }
                            else if ((start.x >= 0f && start.x <= rect.width) || (vector.x >= 0f && vector.x <= rect.width))
                            {
                                Widgets.DrawLine(start, vector, curve.color, 1f);
                            }
                            start = vector;
                        }
                    }
                    Vector2 start2 = CurveToScreenCoordsInsideScreenRect(rect, viewRect, curve.curve[0]);
                    Vector2 start3 = CurveToScreenCoordsInsideScreenRect(rect, viewRect, curve.curve[curve.curve.PointsCount - 1]);
                    Widgets.DrawLine(start2, new Vector2(0f, start2.y), curve.color, 1f);
                    Widgets.DrawLine(start3, new Vector2(rect.width, start3.y), curve.color, 1f);
                }
                else
                {
                    GUI.color = curve.color;
                    float num3 = viewRect.x;
                    float num4 = rect.width / 1f;
                    float num5 = viewRect.width / num4;
                    while (num3 < viewRect.xMax)
                    {
                        num3 += num5;
                        Vector2 vector2 = CurveToScreenCoordsInsideScreenRect(rect, viewRect, new Vector2(num3, curve.curve.Evaluate(num3)));
                        GUI.DrawTexture(new Rect(vector2.x, vector2.y, 1f, 1f), BaseContent.WhiteTex);
                    }
                }
                GUI.color = Color.white;
            }
            if (drawPoints)
            {
                for (int j = 0; j < curve.curve.PointsCount; j++)
                {
                    DrawPoint(CurveToScreenCoordsInsideScreenRect(curvePoint: curve.curve[j].Loc, rect: rect, viewRect: viewRect));
                }
            }
            foreach (float debugInputValue in curve.curve.View.DebugInputValues)
            {
                GUI.color = new Color(0f, 1f, 0f, 0.25f);
                DrawInfiniteVerticalLine(rect, viewRect, debugInputValue);
                float   y           = curve.curve.Evaluate(debugInputValue);
                Vector2 screenPoint = CurveToScreenCoordsInsideScreenRect(curvePoint: new Vector2(debugInputValue, y), rect: rect, viewRect: viewRect);
                GUI.color = Color.green;
                DrawPoint(screenPoint);
                GUI.color = Color.white;
            }
            GUI.EndGroup();
        }
Ejemplo n.º 2
0
 public static object FromString(string str, Type itemType)
 {
     try
     {
         itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
         if (itemType == typeof(string))
         {
             str = str.Replace("\\n", "\n");
             return(str);
         }
         if (itemType == typeof(int))
         {
             return(ParseIntPermissive(str));
         }
         if (itemType == typeof(float))
         {
             return(float.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(bool))
         {
             return(bool.Parse(str));
         }
         if (itemType == typeof(long))
         {
             return(long.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(double))
         {
             return(double.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(sbyte))
         {
             return(sbyte.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType.IsEnum)
         {
             try
             {
                 object obj = BackCompatibility.BackCompatibleEnum(itemType, str);
                 if (obj != null)
                 {
                     return(obj);
                 }
                 return(Enum.Parse(itemType, str));
             }
             catch (ArgumentException innerException)
             {
                 string str2 = "'" + str + "' is not a valid value for " + itemType + ". Valid values are: \n";
                 str2 += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                 ArgumentException ex = new ArgumentException(str2, innerException);
                 throw ex;
             }
         }
         if (itemType == typeof(Type))
         {
             if (str == "null" || str == "Null")
             {
                 return(null);
             }
             Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
             if (typeInAnyAssembly == null)
             {
                 Log.Error("Could not find a type named " + str);
             }
             return(typeInAnyAssembly);
         }
         if (itemType == typeof(Action))
         {
             string[] array      = str.Split('.');
             string   methodName = array[array.Length - 1];
             string   empty      = string.Empty;
             empty = ((array.Length != 3) ? array[0] : (array[0] + "." + array[1]));
             Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(empty);
             MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
             return((Action)Delegate.CreateDelegate(typeof(Action), method));
         }
         if (itemType == typeof(Vector3))
         {
             return(FromStringVector3(str));
         }
         if (itemType == typeof(Vector2))
         {
             return(FromStringVector2(str));
         }
         if (itemType == typeof(Rect))
         {
             return(FromStringRect(str));
         }
         if (itemType == typeof(Color))
         {
             str = str.TrimStart('(', 'R', 'G', 'B', 'A');
             str = str.TrimEnd(')');
             string[] array2 = str.Split(',');
             float    num    = (float)FromString(array2[0], typeof(float));
             float    num2   = (float)FromString(array2[1], typeof(float));
             float    num3   = (float)FromString(array2[2], typeof(float));
             bool     flag   = num > 1f || num3 > 1f || num2 > 1f;
             float    num4   = (float)((!flag) ? 1 : 255);
             if (array2.Length == 4)
             {
                 num4 = (float)FromString(array2[3], typeof(float));
             }
             Color color = default(Color);
             if (!flag)
             {
                 color.r = num;
                 color.g = num2;
                 color.b = num3;
                 color.a = num4;
             }
             else
             {
                 color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
             }
             return(color);
         }
         if (itemType == typeof(PublishedFileId_t))
         {
             return(new PublishedFileId_t(ulong.Parse(str)));
         }
         if (itemType == typeof(IntVec2))
         {
             return(IntVec2.FromString(str));
         }
         if (itemType == typeof(IntVec3))
         {
             return(IntVec3.FromString(str));
         }
         if (itemType == typeof(Rot4))
         {
             return(Rot4.FromString(str));
         }
         if (itemType == typeof(CellRect))
         {
             return(CellRect.FromString(str));
         }
         if (itemType != typeof(CurvePoint))
         {
             if (itemType == typeof(NameTriple))
             {
                 NameTriple nameTriple = NameTriple.FromString(str);
                 nameTriple.ResolveMissingPieces();
             }
             else
             {
                 if (itemType == typeof(FloatRange))
                 {
                     return(FloatRange.FromString(str));
                 }
                 if (itemType == typeof(IntRange))
                 {
                     return(IntRange.FromString(str));
                 }
                 if (itemType == typeof(QualityRange))
                 {
                     return(QualityRange.FromString(str));
                 }
                 if (itemType == typeof(ColorInt))
                 {
                     str = str.TrimStart('(', 'R', 'G', 'B', 'A');
                     str = str.TrimEnd(')');
                     string[] array3   = str.Split(',');
                     ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                     colorInt.r = (int)FromString(array3[0], typeof(int));
                     colorInt.g = (int)FromString(array3[1], typeof(int));
                     colorInt.b = (int)FromString(array3[2], typeof(int));
                     if (array3.Length == 4)
                     {
                         colorInt.a = (int)FromString(array3[3], typeof(int));
                     }
                     else
                     {
                         colorInt.a = 255;
                     }
                     return(colorInt);
                 }
             }
             throw new ArgumentException("Trying to parse to unknown data type " + itemType.Name + ". Content is '" + str + "'.");
         }
         return(CurvePoint.FromString(str));
     }
     catch (Exception innerException2)
     {
         ArgumentException ex2 = new ArgumentException("Exception parsing " + itemType + " from \"" + str + "\"", innerException2);
         throw ex2;
     }
 }
 internal bool <> m__0(CurvePoint x)
 {
     return(x.x >= this.viewRect.xMin && x.x <= this.viewRect.xMax);
 }
Ejemplo n.º 4
0
 public static CurvePoint ParseCurvePoint(string str)
 {
     return(CurvePoint.FromString(str));
 }
Ejemplo n.º 5
0
        private void DoCurveEditor(Rect screenRect)
        {
            Widgets.DrawMenuSection(screenRect);
            SimpleCurveDrawer.DrawCurve(screenRect, this.curve, null, null, default(Rect));
            Vector2 mousePosition = Event.current.mousePosition;

            if (Mouse.IsOver(screenRect))
            {
                Rect    rect = new Rect(mousePosition.x + 8f, mousePosition.y + 18f, 100f, 100f);
                Vector2 v    = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, this.curve.View.rect, mousePosition);
                Widgets.Label(rect, v.ToStringTwoDigits());
            }
            Rect rect2 = new Rect(0f, 0f, 50f, 24f);

            rect2.x = screenRect.x;
            rect2.y = screenRect.y + screenRect.height / 2f - 12f;
            string s = Widgets.TextField(rect2, this.curve.View.rect.x.ToString());
            float  num;

            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.x = num;
            }
            rect2.x = screenRect.xMax - rect2.width;
            rect2.y = screenRect.y + screenRect.height / 2f - 12f;
            s       = Widgets.TextField(rect2, this.curve.View.rect.xMax.ToString());
            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.xMax = num;
            }
            rect2.x = screenRect.x + screenRect.width / 2f - rect2.width / 2f;
            rect2.y = screenRect.yMax - rect2.height;
            s       = Widgets.TextField(rect2, this.curve.View.rect.y.ToString());
            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.y = num;
            }
            rect2.x = screenRect.x + screenRect.width / 2f - rect2.width / 2f;
            rect2.y = screenRect.y;
            s       = Widgets.TextField(rect2, this.curve.View.rect.yMax.ToString());
            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.yMax = num;
            }
            if (Mouse.IsOver(screenRect))
            {
                if (Event.current.type == EventType.ScrollWheel)
                {
                    float           num2          = -1f * Event.current.delta.y * 0.025f;
                    float           num3          = this.curve.View.rect.center.x - this.curve.View.rect.x;
                    float           num4          = this.curve.View.rect.center.y - this.curve.View.rect.y;
                    SimpleCurveView expr_37D_cp_0 = this.curve.View;
                    expr_37D_cp_0.rect.xMin = expr_37D_cp_0.rect.xMin + num3 * num2;
                    SimpleCurveView expr_39E_cp_0 = this.curve.View;
                    expr_39E_cp_0.rect.xMax = expr_39E_cp_0.rect.xMax - num3 * num2;
                    SimpleCurveView expr_3BF_cp_0 = this.curve.View;
                    expr_3BF_cp_0.rect.yMin = expr_3BF_cp_0.rect.yMin + num4 * num2;
                    SimpleCurveView expr_3E0_cp_0 = this.curve.View;
                    expr_3E0_cp_0.rect.yMax = expr_3E0_cp_0.rect.yMax - num4 * num2;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseDown && (Event.current.button == 0 || Event.current.button == 2))
                {
                    List <int> list = this.PointsNearMouse(screenRect).ToList <int>();
                    if (list.Any <int>())
                    {
                        this.draggingPointIndex = list[0];
                    }
                    else
                    {
                        this.draggingPointIndex = -1;
                    }
                    if (this.draggingPointIndex < 0)
                    {
                        this.draggingButton = Event.current.button;
                    }
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
                {
                    Vector2 mouseCurveCoords     = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, this.curve.View.rect, Event.current.mousePosition);
                    List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                    list2.Add(new FloatMenuOption("Add point at " + mouseCurveCoords.ToString(), delegate
                    {
                        this.curve.Add(new CurvePoint(mouseCurveCoords), true);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    foreach (int current in this.PointsNearMouse(screenRect))
                    {
                        CurvePoint point = this.curve[current];
                        list2.Add(new FloatMenuOption("Remove point at " + point.ToString(), delegate
                        {
                            this.curve.RemovePointNear(point);
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(list2));
                    Event.current.Use();
                }
            }
            if (this.draggingPointIndex >= 0)
            {
                this.curve[this.draggingPointIndex] = new CurvePoint(SimpleCurveDrawer.ScreenToCurveCoords(screenRect, this.curve.View.rect, Event.current.mousePosition));
                this.curve.SortPoints();
                if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    this.draggingPointIndex = -1;
                    Event.current.Use();
                }
            }
            if (this.DraggingView)
            {
                if (Event.current.type == EventType.MouseDrag)
                {
                    Vector2         delta         = Event.current.delta;
                    SimpleCurveView expr_691_cp_0 = this.curve.View;
                    expr_691_cp_0.rect.x = expr_691_cp_0.rect.x - delta.x * this.curve.View.rect.width * 0.002f;
                    SimpleCurveView expr_6D0_cp_0 = this.curve.View;
                    expr_6D0_cp_0.rect.y = expr_6D0_cp_0.rect.y + delta.y * this.curve.View.rect.height * 0.002f;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseUp && Event.current.button == this.draggingButton)
                {
                    this.draggingButton = -1;
                }
            }
        }
Ejemplo n.º 6
0
        private void DoCurveEditor(Rect screenRect)
        {
            Widgets.DrawMenuSection(screenRect);
            SimpleCurveDrawer.DrawCurve(screenRect, curve);
            Vector2 mousePosition = Event.current.mousePosition;

            if (Mouse.IsOver(screenRect))
            {
                Rect    rect = new Rect(mousePosition.x + 8f, mousePosition.y + 18f, 100f, 100f);
                Vector2 v    = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, curve.View.rect, mousePosition);
                Widgets.Label(rect, v.ToStringTwoDigits());
            }
            Rect rect2 = new Rect(0f, 0f, 50f, 24f);

            rect2.x = screenRect.x;
            rect2.y = screenRect.y + screenRect.height / 2f - 12f;
            if (float.TryParse(Widgets.TextField(rect2, curve.View.rect.x.ToString()), out float result))
            {
                curve.View.rect.x = result;
            }
            rect2.x = screenRect.xMax - rect2.width;
            rect2.y = screenRect.y + screenRect.height / 2f - 12f;
            if (float.TryParse(Widgets.TextField(rect2, curve.View.rect.xMax.ToString()), out result))
            {
                curve.View.rect.xMax = result;
            }
            rect2.x = screenRect.x + screenRect.width / 2f - rect2.width / 2f;
            rect2.y = screenRect.yMax - rect2.height;
            if (float.TryParse(Widgets.TextField(rect2, curve.View.rect.y.ToString()), out result))
            {
                curve.View.rect.y = result;
            }
            rect2.x = screenRect.x + screenRect.width / 2f - rect2.width / 2f;
            rect2.y = screenRect.y;
            if (float.TryParse(Widgets.TextField(rect2, curve.View.rect.yMax.ToString()), out result))
            {
                curve.View.rect.yMax = result;
            }
            if (Mouse.IsOver(screenRect))
            {
                if (Event.current.type == EventType.ScrollWheel)
                {
                    float num  = -1f * Event.current.delta.y * 0.025f;
                    float num2 = curve.View.rect.center.x - curve.View.rect.x;
                    float num3 = curve.View.rect.center.y - curve.View.rect.y;
                    curve.View.rect.xMin += num2 * num;
                    curve.View.rect.xMax -= num2 * num;
                    curve.View.rect.yMin += num3 * num;
                    curve.View.rect.yMax -= num3 * num;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseDown && (Event.current.button == 0 || Event.current.button == 2))
                {
                    List <int> list = PointsNearMouse(screenRect).ToList();
                    if (list.Any())
                    {
                        draggingPointIndex = list[0];
                    }
                    else
                    {
                        draggingPointIndex = -1;
                    }
                    if (draggingPointIndex < 0)
                    {
                        draggingButton = Event.current.button;
                    }
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
                {
                    Vector2 mouseCurveCoords     = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, curve.View.rect, Event.current.mousePosition);
                    List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                    list2.Add(new FloatMenuOption("Add point at " + mouseCurveCoords.ToString(), delegate
                    {
                        curve.Add(new CurvePoint(mouseCurveCoords));
                    }));
                    foreach (int item in PointsNearMouse(screenRect))
                    {
                        CurvePoint point = curve[item];
                        list2.Add(new FloatMenuOption("Remove point at " + point.ToString(), delegate
                        {
                            curve.RemovePointNear(point);
                        }));
                    }
                    Find.WindowStack.Add(new FloatMenu(list2));
                    Event.current.Use();
                }
            }
            if (draggingPointIndex >= 0)
            {
                curve[draggingPointIndex] = new CurvePoint(SimpleCurveDrawer.ScreenToCurveCoords(screenRect, curve.View.rect, Event.current.mousePosition));
                curve.SortPoints();
                if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    draggingPointIndex = -1;
                    Event.current.Use();
                }
            }
            if (DraggingView)
            {
                if (Event.current.type == EventType.MouseDrag)
                {
                    Vector2 delta = Event.current.delta;
                    curve.View.rect.x -= delta.x * curve.View.rect.width * 0.002f;
                    curve.View.rect.y += delta.y * curve.View.rect.height * 0.002f;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseUp && Event.current.button == draggingButton)
                {
                    draggingButton = -1;
                }
            }
        }
Ejemplo n.º 7
0
        public static object FromString(string str, Type itemType)
        {
            object result;

            try
            {
                itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
                if (itemType == typeof(string))
                {
                    str    = str.Replace("\\n", "\n");
                    result = str;
                }
                else if (itemType == typeof(int))
                {
                    result = int.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(float))
                {
                    result = float.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(bool))
                {
                    result = bool.Parse(str);
                }
                else if (itemType == typeof(long))
                {
                    result = long.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(double))
                {
                    result = double.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(sbyte))
                {
                    result = sbyte.Parse(str, CultureInfo.InvariantCulture);
                }
                else
                {
                    if (itemType.IsEnum)
                    {
                        try
                        {
                            result = Enum.Parse(itemType, str);
                            return(result);
                        }
                        catch (ArgumentException innerException)
                        {
                            string text = string.Concat(new object[]
                            {
                                "'",
                                str,
                                "' is not a valid value for ",
                                itemType,
                                ". Valid values are: \n"
                            });
                            text += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                            ArgumentException ex = new ArgumentException(text, innerException);
                            throw ex;
                        }
                    }
                    if (itemType == typeof(Type))
                    {
                        if (str == "null" || str == "Null")
                        {
                            result = null;
                        }
                        else
                        {
                            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
                            if (typeInAnyAssembly == null)
                            {
                                Log.Error("Could not find a type named " + str);
                            }
                            result = typeInAnyAssembly;
                        }
                    }
                    else if (itemType == typeof(Action))
                    {
                        string[] array = str.Split(new char[]
                        {
                            '.'
                        });
                        string methodName = array[array.Length - 1];
                        string typeName   = string.Empty;
                        if (array.Length == 3)
                        {
                            typeName = array[0] + "." + array[1];
                        }
                        else
                        {
                            typeName = array[0];
                        }
                        Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(typeName);
                        MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
                        result = (Action)Delegate.CreateDelegate(typeof(Action), method);
                    }
                    else if (itemType == typeof(Vector3))
                    {
                        result = ParseHelper.FromStringVector3(str);
                    }
                    else if (itemType == typeof(Vector2))
                    {
                        result = ParseHelper.FromStringVector2(str);
                    }
                    else if (itemType == typeof(Rect))
                    {
                        result = ParseHelper.FromStringRect(str);
                    }
                    else if (itemType == typeof(Color))
                    {
                        str = str.TrimStart(new char[]
                        {
                            '(',
                            'R',
                            'G',
                            'B',
                            'A'
                        });
                        str = str.TrimEnd(new char[]
                        {
                            ')'
                        });
                        string[] array2 = str.Split(new char[]
                        {
                            ','
                        });
                        float num  = (float)ParseHelper.FromString(array2[0], typeof(float));
                        float num2 = (float)ParseHelper.FromString(array2[1], typeof(float));
                        float num3 = (float)ParseHelper.FromString(array2[2], typeof(float));
                        bool  flag = num > 1f || num3 > 1f || num2 > 1f;
                        float num4 = (float)((!flag) ? 1 : 255);
                        if (array2.Length == 4)
                        {
                            num4 = (float)ParseHelper.FromString(array2[3], typeof(float));
                        }
                        Color color;
                        if (!flag)
                        {
                            color.r = num;
                            color.g = num2;
                            color.b = num3;
                            color.a = num4;
                        }
                        else
                        {
                            color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
                        }
                        result = color;
                    }
                    else if (itemType == typeof(PublishedFileId_t))
                    {
                        result = new PublishedFileId_t(ulong.Parse(str));
                    }
                    else if (itemType == typeof(IntVec2))
                    {
                        result = IntVec2.FromString(str);
                    }
                    else if (itemType == typeof(IntVec3))
                    {
                        result = IntVec3.FromString(str);
                    }
                    else if (itemType == typeof(Rot4))
                    {
                        result = Rot4.FromString(str);
                    }
                    else if (itemType == typeof(CellRect))
                    {
                        result = CellRect.FromString(str);
                    }
                    else
                    {
                        if (itemType != typeof(CurvePoint))
                        {
                            if (itemType == typeof(NameTriple))
                            {
                                NameTriple nameTriple = NameTriple.FromString(str);
                                nameTriple.ResolveMissingPieces(null);
                            }
                            else
                            {
                                if (itemType == typeof(FloatRange))
                                {
                                    result = FloatRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(IntRange))
                                {
                                    result = IntRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(QualityRange))
                                {
                                    result = QualityRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(ColorInt))
                                {
                                    str = str.TrimStart(new char[]
                                    {
                                        '(',
                                        'R',
                                        'G',
                                        'B',
                                        'A'
                                    });
                                    str = str.TrimEnd(new char[]
                                    {
                                        ')'
                                    });
                                    string[] array3 = str.Split(new char[]
                                    {
                                        ','
                                    });
                                    ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                                    colorInt.r = (int)ParseHelper.FromString(array3[0], typeof(int));
                                    colorInt.g = (int)ParseHelper.FromString(array3[1], typeof(int));
                                    colorInt.b = (int)ParseHelper.FromString(array3[2], typeof(int));
                                    if (array3.Length == 4)
                                    {
                                        colorInt.a = (int)ParseHelper.FromString(array3[3], typeof(int));
                                    }
                                    else
                                    {
                                        colorInt.a = 255;
                                    }
                                    result = colorInt;
                                    return(result);
                                }
                            }
                            throw new ArgumentException(string.Concat(new string[]
                            {
                                "Trying to parse to unknown data type ",
                                itemType.Name,
                                ". Content is '",
                                str,
                                "'."
                            }));
                        }
                        result = CurvePoint.FromString(str);
                    }
                }
            }
            catch (Exception innerException2)
            {
                ArgumentException ex2 = new ArgumentException(string.Concat(new object[]
                {
                    "Exception parsing ",
                    itemType,
                    " from \"",
                    str,
                    "\""
                }), innerException2);
                throw ex2;
            }
            return(result);
        }
        public static void DrawCurveLines(Rect rect, SimpleCurveDrawInfo curve, bool drawPoints, Rect viewRect, bool useAALines, bool pointsRemoveOptimization)
        {
            if (curve.curve != null && curve.curve.PointsCount != 0)
            {
                Rect position = rect;
                position.yMin -= 1f;
                position.yMax += 1f;
                GUI.BeginGroup(position);
                if (Event.current.type == EventType.Repaint)
                {
                    if (useAALines)
                    {
                        bool    flag       = true;
                        Vector2 start      = default(Vector2);
                        Vector2 curvePoint = default(Vector2);
                        int     num        = curve.curve.AllPoints.Count((CurvePoint x) => x.x >= viewRect.xMin && x.x <= viewRect.xMax);
                        int     num2       = SimpleCurveDrawer.RemovePointsOptimizationFreq(num);
                        for (int i = 0; i < curve.curve.PointsCount; i++)
                        {
                            CurvePoint curvePoint2 = curve.curve[i];
                            if (pointsRemoveOptimization && i % num2 == 0 && i != 0 && i != num - 1)
                            {
                                continue;
                            }
                            curvePoint.x = curvePoint2.x;
                            curvePoint.y = curvePoint2.y;
                            Vector2 vector = SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(rect, viewRect, curvePoint);
                            if (flag)
                            {
                                flag = false;
                            }
                            else
                            {
                                if (start.x >= 0.0 && start.x <= rect.width)
                                {
                                    goto IL_0168;
                                }
                                if (vector.x >= 0.0 && vector.x <= rect.width)
                                {
                                    goto IL_0168;
                                }
                            }
                            goto IL_017b;
IL_017b:
                            start = vector;
                            continue;
IL_0168:
                            Widgets.DrawLine(start, vector, curve.color, 1f);
                            goto IL_017b;
                        }
                        Vector2 start2 = SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(rect, viewRect, curve.curve.AllPoints.First());
                        Vector2 start3 = SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(rect, viewRect, curve.curve.AllPoints.Last());
                        Widgets.DrawLine(start2, new Vector2(0f, start2.y), curve.color, 1f);
                        Widgets.DrawLine(start3, new Vector2(rect.width, start3.y), curve.color, 1f);
                    }
                    else
                    {
                        GUI.color = curve.color;
                        float num3 = viewRect.x;
                        float num4 = (float)(rect.width / 1.0);
                        float num5 = viewRect.width / num4;
                        while (num3 < viewRect.xMax)
                        {
                            num3 += num5;
                            Vector2 vector2 = SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(rect, viewRect, new Vector2(num3, curve.curve.Evaluate(num3)));
                            GUI.DrawTexture(new Rect(vector2.x, vector2.y, 1f, 1f), BaseContent.WhiteTex);
                        }
                    }
                    GUI.color = Color.white;
                }
                if (drawPoints)
                {
                    for (int j = 0; j < curve.curve.PointsCount; j++)
                    {
                        CurvePoint curvePoint3 = curve.curve[j];
                        Vector2    screenPoint = SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(rect, viewRect, curvePoint3.Loc);
                        SimpleCurveDrawer.DrawPoint(screenPoint);
                    }
                }
                foreach (float debugInputValue in curve.curve.View.DebugInputValues)
                {
                    float num6 = debugInputValue;
                    GUI.color = new Color(0f, 1f, 0f, 0.25f);
                    SimpleCurveDrawer.DrawInfiniteVerticalLine(rect, viewRect, num6);
                    float   y            = curve.curve.Evaluate(num6);
                    Vector2 curvePoint4  = new Vector2(num6, y);
                    Vector2 screenPoint2 = SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(rect, viewRect, curvePoint4);
                    GUI.color = Color.green;
                    SimpleCurveDrawer.DrawPoint(screenPoint2);
                    GUI.color = Color.white;
                }
                GUI.EndGroup();
            }
        }
 private static float <SetViewRectAround> m__3(CurvePoint pt)
 {
     return(pt.Loc.y);
 }
        private void DoCurveEditor(Rect screenRect)
        {
            Widgets.DrawMenuSection(screenRect);
            SimpleCurveDrawer.DrawCurve(screenRect, this.curve, null, null, default(Rect));
            Vector2 mousePosition = Event.current.mousePosition;

            if (Mouse.IsOver(screenRect))
            {
                Rect    rect = new Rect((float)(mousePosition.x + 8.0), (float)(mousePosition.y + 18.0), 100f, 100f);
                Vector2 v    = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, this.curve.View.rect, mousePosition);
                Widgets.Label(rect, v.ToStringTwoDigits());
            }
            Rect rect2 = new Rect(0f, 0f, 50f, 24f);

            rect2.x = screenRect.x;
            rect2.y = (float)(screenRect.y + screenRect.height / 2.0 - 12.0);
            string s   = Widgets.TextField(rect2, this.curve.View.rect.x.ToString());
            float  num = default(float);

            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.x = num;
            }
            rect2.x = screenRect.xMax - rect2.width;
            rect2.y = (float)(screenRect.y + screenRect.height / 2.0 - 12.0);
            s       = Widgets.TextField(rect2, this.curve.View.rect.xMax.ToString());
            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.xMax = num;
            }
            rect2.x = (float)(screenRect.x + screenRect.width / 2.0 - rect2.width / 2.0);
            rect2.y = screenRect.yMax - rect2.height;
            s       = Widgets.TextField(rect2, this.curve.View.rect.y.ToString());
            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.y = num;
            }
            rect2.x = (float)(screenRect.x + screenRect.width / 2.0 - rect2.width / 2.0);
            rect2.y = screenRect.y;
            s       = Widgets.TextField(rect2, this.curve.View.rect.yMax.ToString());
            if (float.TryParse(s, out num))
            {
                this.curve.View.rect.yMax = num;
            }
            if (Mouse.IsOver(screenRect))
            {
                if (Event.current.type == EventType.ScrollWheel)
                {
                    Vector2 delta   = Event.current.delta;
                    float   num2    = (float)(-1.0 * delta.y * 0.02500000037252903);
                    Vector2 center  = this.curve.View.rect.center;
                    float   num3    = center.x - this.curve.View.rect.x;
                    Vector2 center2 = this.curve.View.rect.center;
                    float   num4    = center2.y - this.curve.View.rect.y;
                    this.curve.View.rect.xMin += num3 * num2;
                    this.curve.View.rect.xMax -= num3 * num2;
                    this.curve.View.rect.yMin += num4 * num2;
                    this.curve.View.rect.yMax -= num4 * num2;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseDown && (Event.current.button == 0 || Event.current.button == 2))
                {
                    List <int> list = this.PointsNearMouse(screenRect).ToList();
                    if (list.Any())
                    {
                        this.draggingPointIndex = list[0];
                    }
                    else
                    {
                        this.draggingPointIndex = -1;
                    }
                    if (this.draggingPointIndex < 0)
                    {
                        this.draggingButton = Event.current.button;
                    }
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
                {
                    Vector2 mouseCurveCoords     = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, this.curve.View.rect, Event.current.mousePosition);
                    List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                    list2.Add(new FloatMenuOption("Add point at " + mouseCurveCoords.ToString(), delegate
                    {
                        this.curve.Add(new CurvePoint(mouseCurveCoords), true);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    foreach (int item in this.PointsNearMouse(screenRect))
                    {
                        CurvePoint point = this.curve[item];
                        list2.Add(new FloatMenuOption("Remove point at " + point.ToString(), delegate
                        {
                            this.curve.RemovePointNear(point);
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(list2));
                    Event.current.Use();
                }
            }
            if (this.draggingPointIndex >= 0)
            {
                this.curve[this.draggingPointIndex] = new CurvePoint(SimpleCurveDrawer.ScreenToCurveCoords(screenRect, this.curve.View.rect, Event.current.mousePosition));
                this.curve.SortPoints();
                if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    this.draggingPointIndex = -1;
                    Event.current.Use();
                }
            }
            if (this.DraggingView)
            {
                if (Event.current.type == EventType.MouseDrag)
                {
                    Vector2 delta2 = Event.current.delta;
                    this.curve.View.rect.x -= (float)(delta2.x * this.curve.View.rect.width * 0.0020000000949949026);
                    this.curve.View.rect.y += (float)(delta2.y * this.curve.View.rect.height * 0.0020000000949949026);
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseUp && Event.current.button == this.draggingButton)
                {
                    this.draggingButton = -1;
                }
            }
        }