Exemple #1
0
 private static void SetNotifications()
 {
     EditorApplication.update -= SetNotifications;
     _notificationInfo         = (NotificationInfo)JsonUtility.FromJson(_notificationString, typeof(NotificationInfo));
     if (_notificationInfo.GetActiveNotifications().Count > 0)
     {
         MenuEnable();
     }
 }
Exemple #2
0
        /// <summary>
        /// Displays the window
        /// </summary>
        /// <param name="windowID">ID of the window</param>
        public static void DoWindow(int windowID)
        {
            BorderColor = Color.Lerp(new Color(1, 1, 1, 1), new Color(0, 0, 0, 1), Mathf.Sin((float)EditorApplication.timeSinceStartup));
            UpdateRect();
            EditorGUILayout.BeginVertical();
            Undo.RecordObject(SKSGlobalRenderSettings.Instance, "SKSGlobalRenderSettings");
            //Header controls
            UnityEditor.EditorGUI.BeginChangeCheck();
            if (GUI.Button(new Rect(3, 3, 15, 15), "X", Styles.menuOptionsStyle))
            {
                SKSGlobalRenderSettings.MenuClosed = true;
                Disable();
            }
            if (GUI.Button(new Rect(20, 3, 15, 15), SKSGlobalRenderSettings.Minimized ? "□" : "_", Styles.menuOptionsStyle))
            {
                SKSGlobalRenderSettings.Minimized = !SKSGlobalRenderSettings.Minimized;
                startTime = EditorApplication.timeSinceStartup;
            }


            Color guiColor = GUI.color;

            var activeNotifications = _notificationInfo.GetActiveNotifications();

            if (activeNotifications.Count == 0)
            {
                GUILayout.FlexibleSpace();
                {
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.FlexibleSpace();
                        GUILayout.Label("No notifications to display");
                        GUILayout.FlexibleSpace();
                    }
                    GUILayout.EndHorizontal();
                }
                //GUILayout.FlexibleSpace();
            }
            else if (SKSGlobalRenderSettings.Minimized)
            {
                int messages = 0;
                int warnings = 0;
                int errors   = 0;
                foreach (NotificationInfo.Notification n in activeNotifications)
                {
                    switch (n.Type)
                    {
                    case 1:
                        messages++;
                        break;

                    case 2:
                        warnings++;
                        break;

                    case 3:
                        errors++;
                        break;

                    default:
                        messages++;
                        break;
                    }
                }

                Func <int, int, Rect> getInfoIconPos = (index, total) => {
                    int hsize   = 16;
                    int vsize   = 16;
                    int padding = 3;
                    int vOffset = 10;
                    return(new Rect(
                               0, vOffset + (((vsize + padding) * index) - ((vsize * total + (padding - 1) * total) / 2)) +
                               (windowRect.height / 2), hsize, vsize));
                };
                GUILayout.BeginHorizontal();
                {
                    int number = 0, index = 0;
                    if (messages > 0)
                    {
                        number++;
                    }
                    if (warnings > 0)
                    {
                        number++;
                    }
                    if (errors > 0)
                    {
                        number++;
                    }

                    Rect positionRect;
                    if (errors > 0)
                    {
                        positionRect = getInfoIconPos(index++, number);
                        GUI.DrawTexture(positionRect, Content.ErrorIconSmall);
                        positionRect.x    += positionRect.width;
                        positionRect.width = 400;
                        GUI.Label(positionRect, String.Format("{0} new critical notifications", errors), Styles.notificationTextStyle);
                    }


                    if (warnings > 0)
                    {
                        positionRect = getInfoIconPos(index++, number);
                        GUI.DrawTexture(positionRect, Content.WarnIconSmall);
                        positionRect.x    += positionRect.width;
                        positionRect.width = 400;
                        GUI.Label(positionRect, String.Format("{0} new important notifications", warnings), Styles.notificationTextStyle);
                    }


                    if (messages > 0)
                    {
                        positionRect = getInfoIconPos(index++, number);
                        GUI.DrawTexture(positionRect, Content.InfoIconSmall);
                        positionRect.x    += positionRect.width;
                        positionRect.width = 400;
                        GUI.Label(positionRect, String.Format("{0} new information notifications", messages), Styles.notificationTextStyle);
                    }
                }
                GUILayout.EndHorizontal();
                GUI.color = guiColor;
                return;
            }
            else
            {
                GUI.color = Color.white;
                if (time >= 1)
                {
                    try
                    {
                        scrollPos = GUILayout.BeginScrollView(scrollPos, false, false,
                                                              GUILayout.Width(windowRect.width - 20), GUILayout.Height(windowRect.height - 20));
                    }
                    catch (System.InvalidCastException) { }
                }

                foreach (var n in activeNotifications)
                {
                    String  message = n.Message;
                    Vector2 size    = Styles.bgStyle.CalcSize(new GUIContent(message));
                    GUILayout.Box(message, Styles.bgStyle, GUILayout.MinHeight(Mathf.Max(size.y, 32)));

                    Rect labelFieldRect = GUILayoutUtility.GetLastRect();
                    GUI.DrawTexture(new Rect(labelFieldRect.x, labelFieldRect.y, 32, 32), Content.GetIcon(n.Type, true));
                    GUILayout.Space(10);
                    int width = 15;
                    if (GUI.Button(new Rect(labelFieldRect.x + labelFieldRect.width - width, labelFieldRect.y, width, width), "X",
                                   Styles.notificationCloseStyle))
                    {
                        _notificationInfo.IgnoreMessage(n.Id);
                    }
                }
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Restore all notifications",
                                     Styles.menuOptionsStyle, GUILayout.MaxWidth(200)))
                {
                    SKSGlobalRenderSettings.IgnoredNotifications = new List <int>();
                }
#if SKS_DEV
                /*
                 * if (GUILayout.Button("Re-scan server for notifications",
                 *  Styles.menuOptionsStyle, GUILayout.MaxWidth(200)))
                 *  AutoOpen();*/
#endif
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();

            if (activeNotifications.Count != 0 && !SKSGlobalRenderSettings.Minimized && time >= 1)
            {
                GUILayout.EndScrollView();
            }


            GUI.color = guiColor;
            //GUILayout.FlexibleSpace();

            EditorGUILayout.EndVertical();
        }