Skip to content

Commit

Permalink
Changed the way tooltip is handeled. Now you need to click on the lin…
Browse files Browse the repository at this point in the history
…e. More line inspection stuff to follow.
  • Loading branch information
luaye committed Mar 21, 2013
1 parent 697b80c commit a20087a
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Assets/ConsoleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Update()
if(delay >= 0.25f)
{
delay = 0;
//JBLogger.Log(ConsoleLevel.Info, "Test " + count + " - " + Random.value);
JBLogger.Log(ConsoleLevel.Info, "Test " + count + " - " + Random.value);
count ++;
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/JBConsole/JBCEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ string URLPart(string prefix, string body)

private string DefaultFormatter(ConsoleLog log)
{
return log.channel + " " + log.level + " " + log.content.text + "\n";
return log.channel + " " + log.level + " " + log.message + "\n";
}

public static JBCEmail RegisterToConsole(string to = null, string subject = null)
Expand Down
259 changes: 154 additions & 105 deletions Assets/JBConsole/JBConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,35 @@ public class JBConsole : MonoBehaviour
{
delegate void SubMenuHandler(int index);

private static JBConsole _instance;

public static JBConsole Start()
{
if(_instance == null)
{
GameObject go = new GameObject("JBConsole");
_instance = go.AddComponent<JBConsole>();
}
return _instance;
}

public static JBConsole instance
public static JBConsole Start()
{
get
if(instance == null)
{
return _instance;
var go = new GameObject("JBConsole");
instance = go.AddComponent<JBConsole>();
}
return instance;
}

public static bool exists

public static JBConsole instance { get; private set; }

public static bool exists
{
get { return _instance != null; }
}
get { return instance != null; }
}

public static void AddMenu(string name, JBConsoleMenuHandler callback)
{
if (!exists) return;
instance.AddCustomMenu(name, callback);
}

public static void RemoveMenu(string name)
{
if (!exists) return;
instance.RemoveCustomMenu(name);
}


private JBLogger logger;
private JBCStyle style;
Expand Down Expand Up @@ -64,15 +69,13 @@ public static bool exists
Vector2 scrollPosition;

int stateHash;

public JBConsole()
{

}

private ConsoleLog focusedLog;


void Awake ()
{
if(_instance == null) _instance = this;
if(instance == null) instance = this;


DontDestroyOnLoad(gameObject);
Expand All @@ -94,18 +97,6 @@ void Update ()
clearCache();
}
}

public static void AddMenu(string name, JBConsoleMenuHandler callback)
{
if(!exists) return;
instance.AddCustomMenu(name, callback);
}

public static void RemoveMenu(string name)
{
if(!exists) return;
instance.RemoveCustomMenu(name);
}

public void AddCustomMenu(string name, JBConsoleMenuHandler callback)
{
Expand Down Expand Up @@ -264,16 +255,14 @@ public void DrawGUI(float width, float height, float scale = 1)
{
if (style == null) style = new JBCStyle();

GUILayoutOption maxwidthscreen = GUILayout.MaxWidth(width);


GUILayout.BeginVertical(style.BoxStyle);

//GUILayout.BeginHorizontal();
//GUILayout.FlexibleSpace();
int selection = GUILayout.Toolbar(-1, currentTopMenu, style.MenuStyle, GUILayout.MinWidth(280 * scale), GUILayout.MaxWidth(380 * scale));
if (selection >= 0)
{
Defocus();
OnMenuSelection(selection);
}
//GUILayout.EndHorizontal();
Expand All @@ -289,6 +278,7 @@ public void DrawGUI(float width, float height, float scale = 1)
selection = GUILayout.SelectionGrid(-1, currentSubMenu, (int)(width / (menuItemWidth * scale)), style.MenuStyle);
if (selection >= 0 && subMenuHandler != null)
{
Defocus();
subMenuHandler(selection);
}
}
Expand All @@ -306,103 +296,162 @@ public void DrawGUI(float width, float height, float scale = 1)

GUI.FocusControl("SearchTF");
}

bool wasForcedBottom = scrollPosition.y == float.MaxValue;

if(autoScrolling)
{
if(cachedLogs == null && Event.current.type == EventType.Layout)
{
scrollPosition.y = float.MaxValue;
}
scrollPosition = GUILayout.BeginScrollView(scrollPosition, maxwidthscreen);
if (cachedLogs == null)
{
CacheBottomOfLogs(width, height);
}
PrintCachedLogs(maxwidthscreen);
}

if (focusedLog != null)
{
DrawFocusedLog(width, height);
}
else
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, maxwidthscreen);
if (cachedLogs == null)
{
CacheAllOfLogs();
}
PrintCachedLogs(maxwidthscreen);
}
Rect lastContentRect = GUILayoutUtility.GetLastRect();
GUILayout.EndScrollView();

Rect scrollViewRect = GUILayoutUtility.GetLastRect();
if(Event.current.type == EventType.Repaint)
{
float maxscroll = lastContentRect.y + lastContentRect.height - scrollViewRect.height;

bool atbottom = maxscroll <= 0 || scrollPosition.y > maxscroll - 4; // where 4 = scroll view's skin bound size?
if(!autoScrolling && wasForcedBottom)
{
scrollPosition.y = maxscroll - 3;
}
else if(autoScrolling != atbottom)
{
autoScrolling = atbottom;
scrollPosition.y = float.MaxValue;
clearCache();
}
}

GUILayout.EndVertical();

if(!autoScrolling)
{
autoscrolltogglerect.x = width - autoscrolltogglerect.width;
autoscrolltogglerect.y = height - autoscrolltogglerect.height;
{
DrawLogScroll(width, height);
}

GUILayout.EndVertical();

if(GUI.Button(autoscrolltogglerect, "Scroll to bottom"))
{
autoScrolling = true;
}
}

if(GUI.tooltip.Length > 0)
{
GUIContent content = new GUIContent(GUI.tooltip);
{
if (Event.current.type == EventType.MouseUp)
{

}
/*
GUIContent content = new GUIContent(GUI.tooltip);
float tooltiph = style.BoxStyle.CalcHeight(content, width);
GUI.Label(new Rect(0, Screen.height - Input.mousePosition.y + 16, width, tooltiph), GUI.tooltip, style.BoxStyle);
*/
}
}

void EnsureScrollPosition()

private void DrawLogScroll(float width, float height)
{
GUILayoutOption maxwidthscreen = GUILayout.MaxWidth(width);

bool wasForcedBottom = scrollPosition.y == float.MaxValue;

ConsoleLog clickedLog;
if (autoScrolling)
{
if (cachedLogs == null && Event.current.type == EventType.Layout)
{
scrollPosition.y = float.MaxValue;
}
scrollPosition = GUILayout.BeginScrollView(scrollPosition, maxwidthscreen);
if (cachedLogs == null)
{
CacheBottomOfLogs(width, height);
}
clickedLog = PrintCachedLogs(maxwidthscreen);
}
else
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, maxwidthscreen);
if (cachedLogs == null)
{
CacheAllOfLogs();
}
clickedLog = PrintCachedLogs(maxwidthscreen);
}

if (clickedLog != null)
{
focusedLog = clickedLog;
}

Rect lastContentRect = GUILayoutUtility.GetLastRect();
GUILayout.EndScrollView();

Rect scrollViewRect = GUILayoutUtility.GetLastRect();
if (Event.current.type == EventType.Repaint)
{
float maxscroll = lastContentRect.y + lastContentRect.height - scrollViewRect.height;

bool atbottom = maxscroll <= 0 || scrollPosition.y > maxscroll - 4; // where 4 = scroll view's skin bound size?
if (!autoScrolling && wasForcedBottom)
{
scrollPosition.y = maxscroll - 3;
}
else if (autoScrolling != atbottom)
{
autoScrolling = atbottom;
scrollPosition.y = float.MaxValue;
clearCache();
}
}


if (!autoScrolling)
{
autoscrolltogglerect.x = width - autoscrolltogglerect.width;
autoscrolltogglerect.y = height - autoscrolltogglerect.height;

if (GUI.Button(autoscrolltogglerect, "Scroll to bottom"))
{
autoScrolling = true;
}
}
}

private void DrawFocusedLog(float width, float height)
{
GUILayoutOption maxwidthscreen = GUILayout.MaxWidth(width);

if (GUILayout.Button("Back", style.MenuStyle))
{
Defocus();
}
else
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, maxwidthscreen);
GUILayout.Label(focusedLog.message, style.GetStyleForLogLevel(focusedLog.level), maxwidthscreen);
GUILayout.Label(focusedLog.stack, maxwidthscreen);
GUILayout.EndScrollView();
}
}

private void Defocus()
{
autoScrolling = true;
scrollPosition.y = float.MaxValue;
focusedLog = null;
}

void EnsureScrollPosition()
{
if(autoScrolling)
{
scrollPosition.y = float.MaxValue;
}
}

void PrintCachedLogs(GUILayoutOption maxwidthscreen)
ConsoleLog PrintCachedLogs(GUILayoutOption maxwidthscreen)
{
ConsoleLog log;
ConsoleLog clicked = null;
for (int i = cachedLogs.Count - 1; i >= 0; i--)
{
log = cachedLogs[i];
if(log.repeats > 0)
{
GUILayout.Label(log.repeats + "x " +log.content.text, style.GetStyleForLogLevel(log.level), maxwidthscreen);
GUILayout.Label(log.repeats + "x " + log.message, style.GetStyleForLogLevel(log.level), maxwidthscreen);
}
else
{
GUILayout.Label(log.content, style.GetStyleForLogLevel(log.level), maxwidthscreen);
}
GUILayout.Label(log.message, style.GetStyleForLogLevel(log.level), maxwidthscreen);
}
if (Event.current.type == EventType.MouseUp && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
{
clicked = log;
}
}
return clicked;
}

bool ShouldShow(ConsoleLog log)
{
return (log.level >= viewingLevel
&& (viewingChannels == null || Array.IndexOf(viewingChannels, log.channel) >= 0)
&& (searchTerm == "" || log.content.text.ToLower().Contains(searchTerm)));
&& (searchTerm == "" || log.message.ToLower().Contains(searchTerm)));
}

void CacheBottomOfLogs(float width, float height)
Expand Down
Loading

0 comments on commit a20087a

Please sign in to comment.