예제 #1
0
        protected override void OnEnterKeyPressed()
        {
            if (_selectedLog == null)
            {
                return;
            }

            BluUtils.JumpToSourceFile(_selectedLog, SelectedMessage == 0 ? SelectedMessage : SelectedMessage - 1);
        }
        protected override void OnEnterKeyPressed()
        {
            BluLog log = null;

            if (SelectedMessage != -1 &&
                SelectedMessage >= 0 &&
                SelectedMessage < QtLogs)
            {
                log = GetCompleteLog(Rows[SelectedMessage]);
            }

            if (log != null)
            {
                BluUtils.JumpToSourceFile(log, 0);
            }
        }
예제 #3
0
        public override void OnGUI(int id)
        {
            base.OnGUI(id);

            UnityLoggerServer.StartGettingLogs();

            GUI.DrawTexture(WindowRect, BluConsoleSkin.OddBackTexture);

            if (ListWindowSelectedMessage != -1 &&
                ListWindowSelectedMessage >= 0 &&
                ListWindowSelectedMessage < QtLogs)
            {
                _selectedLog = GetCompleteLog(Rows[ListWindowSelectedMessage]);
            }

            if (_selectedLog != null)
            {
                SelectedMessage = Mathf.Clamp(SelectedMessage, 0, _selectedLog.StackTrace.Count);
            }
            else
            {
                SelectedMessage = -1;
            }

            if (ListWindowSelectedMessage == -1 ||
                QtLogs == 0 ||
                ListWindowSelectedMessage >= QtLogs ||
                _selectedLog == null ||
                _selectedLog.StackTrace == null)
            {
                UnityLoggerServer.StopGettingsLogs();
                return;
            }

            float buttonWidth = DefaultButtonWidth;

            var cells = GetCells(_selectedLog);

            foreach (var cell in cells)
            {
                cell.Message = GetTruncatedDetailMessage(cell.Message);
            }
            sums    = new float[cells.Count + 1];
            sums[0] = 0;
            for (int i = 1; i <= cells.Count; i++)
            {
                sums[i] = cells[i - 1].GetHeight(buttonWidth) + sums[i - 1];
            }

            float viewHeight = sums[cells.Count];

            if (viewHeight > WindowRect.height)
            {
                buttonWidth -= 15f;
            }

            for (int i = 1; i <= cells.Count; i++)
            {
                sums[i] = cells[i - 1].GetHeight(buttonWidth) + sums[i - 1];
            }
            viewHeight = sums[cells.Count];

            float viewWidth = buttonWidth;

            Rect scrollViewPosition = WindowRect;
            Rect scrollViewViewRect = new Rect(x: 0f, y: 0f, width: viewWidth, height: viewHeight);

            ScrollPosition = GUI.BeginScrollView(position: scrollViewPosition,
                                                 scrollPosition: ScrollPosition,
                                                 viewRect: scrollViewViewRect);

            int firstRenderLogIndex = GetFirstGreaterCellIndex(cells, ScrollPosition.y, 0f) - 1;

            firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, cells.Count - 1);
            int lastRenderLogIndex = GetFirstGreaterCellIndex(cells, ScrollPosition.y, WindowRect.height);

            lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, cells.Count - 1);

            float buttonY = sums[firstRenderLogIndex];

            // Handling up/down arrow keys
            if (HasKeyboardArrowKeyInput)
            {
                float lo = ScrollPosition.y;
                float hi = ScrollPosition.y + WindowRect.height;
                float selectedMessageLo = sums[SelectedMessage];
                float selectedMessageHi = sums[SelectedMessage + 1];

                bool isFrameOutsideOfRange = !(selectedMessageLo >= lo && selectedMessageHi <= hi);
                if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Up)
                {
                    ScrollPosition.y = selectedMessageLo;
                }
                else if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Down)
                {
                    ScrollPosition.y = selectedMessageHi - WindowRect.height;
                }
            }

            for (int i = firstRenderLogIndex; i <= lastRenderLogIndex; i++)
            {
                float cellHeight = sums[i + 1] - sums[i];
                var   rectButton = new Rect(x: 0, y: buttonY, width: viewWidth, height: cellHeight);
                var   isSelected = cells[i].SelectedMessageWhenClicked == SelectedMessage;
                DrawBackground(rectButton, cells[i].BackgroundStyle, isSelected);
                if (IsRepaintEvent)
                {
                    cells[i].MessageStyle.Draw(rectButton, cells[i].Message, false, false, isSelected, false);
                }

                bool messageClicked = IsClicked(rectButton);
                if (messageClicked)
                {
                    bool isLeftClick = Event.current.button == 0;
                    if (!isSelected)
                    {
                        LastTimeClicked = 0.0f;
                    }
                    if (isLeftClick && !IsDoubleClick)
                    {
                        SelectedMessage = cells[i].SelectedMessageWhenClicked;
                    }
                    if (!isLeftClick)
                    {
                        DrawPopup(cells[i].Message);
                    }
                    if (isLeftClick && SelectedMessage == cells[i].SelectedMessageWhenClicked)
                    {
                        if (IsDoubleClick)
                        {
                            LastTimeClicked = 0.0f;
                            BluUtils.JumpToSourceFile(_selectedLog, cells[i].StackTraceIndex);
                        }
                        else
                        {
                            LastTimeClicked = EditorApplication.timeSinceStartup;
                        }
                    }
                }

                buttonY += cellHeight;
            }

            GUI.EndScrollView();

            UnityLoggerServer.StopGettingsLogs();
        }
        public override void OnGUI(int id)
        {
            base.OnGUI(id);

            UnityLoggerServer.StartGettingLogs();

            SelectedMessage = Mathf.Clamp(SelectedMessage, -1, QtLogs - 1);

            float buttonWidth = DefaultButtonWidth;

            if (QtLogs * DefaultButtonHeight > WindowRect.height)
            {
                buttonWidth -= 15f;
            }

            float viewWidth  = buttonWidth;
            float viewHeight = QtLogs * DefaultButtonHeight;

            Rect scrollWindowRect = WindowRect;
            Rect scrollViewRect   = new Rect(x: 0f, y: 0f, width: viewWidth, height: viewHeight);

            GUI.DrawTexture(scrollWindowRect, BluConsoleSkin.EvenBackTexture);

            Vector2 oldScrollPosition = ScrollPosition;

            ScrollPosition = GUI.BeginScrollView(position: scrollWindowRect,
                                                 scrollPosition: ScrollPosition,
                                                 viewRect: scrollViewRect);

            GUI.DrawTexture(WindowRect, BluConsoleSkin.OddBackTexture);

            int firstRenderLogIndex = (int)(ScrollPosition.y / DefaultButtonHeight);

            firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, QtLogs);

            int lastRenderLogIndex = firstRenderLogIndex + (int)(WindowRect.height / DefaultButtonHeight) + 2;

            lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, QtLogs);

            // Handling up/down arrow keys
            if (HasKeyboardArrowKeyInput)
            {
                bool isFrameOutsideOfRange = SelectedMessage <firstRenderLogIndex + 1 ||
                                                              SelectedMessage> lastRenderLogIndex - 3;
                if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Up)
                {
                    ScrollPosition.y = DefaultButtonHeight * SelectedMessage;
                }
                else if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Down)
                {
                    int   md = lastRenderLogIndex - firstRenderLogIndex - 3;
                    float ss = md * DefaultButtonHeight;
                    float sd = WindowRect.height - ss;
                    ScrollPosition.y = (DefaultButtonHeight * (SelectedMessage + 1) - ss - sd);
                }
            }

            float buttonY      = firstRenderLogIndex * DefaultButtonHeight;
            bool  hasCollapse  = UnityLoggerServer.HasFlag(ConsoleWindowFlag.Collapse);
            bool  hasSomeClick = false;

            for (int i = firstRenderLogIndex; i < lastRenderLogIndex; i++)
            {
                int    row       = Rows[i];
                BluLog log       = Logs[i];
                var    styleBack = BluConsoleSkin.GetLogBackStyle(i);

                var    styleMessage   = BluConsoleSkin.GetLogListStyle(log.LogType);
                string showMessage    = GetTruncatedListMessage(log);
                var    contentMessage = new GUIContent(showMessage);
                var    rectMessage    = new Rect(x: 0, y: buttonY, width: viewWidth, height: DefaultButtonHeight);
                bool   isSelected     = i == SelectedMessage;

                DrawBackground(rectMessage, styleBack, isSelected);
                if (IsRepaintEvent)
                {
                    styleMessage.Draw(rectMessage, contentMessage, false, false, isSelected, false);
                }

                bool messageClicked = IsClicked(rectMessage);
                bool isLeftClick    = messageClicked && Event.current.button == 0;

                if (hasCollapse)
                {
                    int quantity      = UnityLoggerServer.GetLogCount(row);
                    var collapseCount = Mathf.Min(quantity, LogConfiguration.MaxAmountOfLogsCollapse);
                    var collapseText  = collapseCount.ToString();
                    if (collapseCount >= LogConfiguration.MaxAmountOfLogsCollapse)
                    {
                        collapseText += "+";
                    }
                    var collapseContent = new GUIContent(collapseText);
                    var collapseSize    = BluConsoleSkin.CollapseStyle.CalcSize(collapseContent);

                    var collapseRect = new Rect(x: viewWidth - collapseSize.x - 5f,
                                                y: (buttonY + buttonY + DefaultButtonHeight - collapseSize.y) * 0.5f,
                                                width: collapseSize.x,
                                                height: collapseSize.y);

                    GUI.Label(collapseRect, collapseContent, BluConsoleSkin.CollapseStyle);
                }

                if (messageClicked)
                {
                    hasSomeClick = true;
                    if (SelectedMessage != i)
                    {
                        LastTimeClicked = 0.0f;
                    }
                    if (isLeftClick)
                    {
                        BluUtils.PingLog(GetCompleteLog(row));
                        SelectedMessage = i;
                    }
                    if (!isLeftClick)
                    {
                        DrawPopup(log);
                    }
                    if (isLeftClick && i == SelectedMessage)
                    {
                        if (IsDoubleClick)
                        {
                            LastTimeClicked = 0.0f;
                            var completeLog = GetCompleteLog(row);
                            BluUtils.JumpToSourceFile(completeLog, 0);
                        }
                        else
                        {
                            LastTimeClicked = EditorApplication.timeSinceStartup;
                        }
                    }
                }

                buttonY += DefaultButtonHeight;
            }

            GUI.EndScrollView();

            if (IsScrollUp || hasSomeClick)
            {
                IsFollowScroll = false;
            }
            else if (ScrollPosition != oldScrollPosition)
            {
                IsFollowScroll = false;
                float topOffset = viewHeight - WindowRect.height;
                if (ScrollPosition.y >= topOffset)
                {
                    IsFollowScroll = true;
                }
            }

            if (IsFollowScroll)
            {
                ScrollPosition.y = viewHeight - WindowRect.height;
            }

            UnityLoggerServer.StopGettingsLogs();
        }