OSDN Git Service

-Add RLV @FindFolder command support
[radegast/radegast.git] / Radegast / Core / ChatTextManager.cs
index 7465f76..0053d1f 100644 (file)
@@ -1,6 +1,6 @@
 // 
 // Radegast Metaverse Client
-// Copyright (c) 2009-2011, Radegast Development Team
+// Copyright (c) 2009-2014, Radegast Development Team
 // All rights reserved.
 // 
 // Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,8 @@ namespace Radegast
 {
     public class ChatTextManager : IDisposable
     {
+        public event EventHandler<ChatLineAddedArgs> ChatLineAdded;
+
         private RadegastInstance instance;
         private RadegastNetcom netcom { get { return instance.Netcom; } }
         private GridClient client { get { return instance.Client; } }
@@ -103,7 +105,7 @@ namespace Radegast
             if (e.Message.ToLower().Contains("autopilot canceled")) return; //workaround the stupid autopilot alerts
 
             ChatBufferItem item = new ChatBufferItem(
-                DateTime.Now, "Alert message: " + e.Message, ChatBufferTextStyle.Alert);
+                DateTime.Now, "Alert message", UUID.Zero, ": " + e.Message, ChatBufferTextStyle.Alert);
 
             ProcessBufferItem(item, true);
         }
@@ -116,10 +118,10 @@ namespace Radegast
         public void PrintStartupMessage()
         {
             ChatBufferItem title = new ChatBufferItem(
-                DateTime.Now, Properties.Resources.RadegastTitle + "." + RadegastBuild.CurrentRev, ChatBufferTextStyle.StartupTitle);
+                DateTime.Now, "", UUID.Zero, Properties.Resources.RadegastTitle + "." + RadegastBuild.CurrentRev, ChatBufferTextStyle.StartupTitle);
 
             ChatBufferItem ready = new ChatBufferItem(
-                DateTime.Now, "Ready.", ChatBufferTextStyle.StatusBlue);
+                DateTime.Now, "", UUID.Zero, "Ready.", ChatBufferTextStyle.StatusBlue);
 
             ProcessBufferItem(title, true);
             ProcessBufferItem(ready, true);
@@ -129,9 +131,14 @@ namespace Radegast
 
         public void ProcessBufferItem(ChatBufferItem item, bool addToBuffer)
         {
+            if (ChatLineAdded != null)
+            {
+                ChatLineAdded(this, new ChatLineAddedArgs(item));
+            }
+
             lock (SyncChat)
             {
-                instance.LogClientMessage("chat.txt", item.Text);
+                instance.LogClientMessage("chat.txt", item.From + item.Text);
                 if (addToBuffer) textBuffer.Add(item);
 
                 if (showTimestamps)
@@ -180,7 +187,15 @@ namespace Radegast
                         break;
                 }
 
-                textPrinter.PrintTextLine(item.Text);
+                if (item.Style == ChatBufferTextStyle.Normal && item.ID != UUID.Zero && instance.GlobalSettings["av_name_link"])
+                {
+                    textPrinter.InsertLink(item.From, string.Format("secondlife:///app/agent/{0}/about", item.ID));
+                    textPrinter.PrintTextLine(item.Text);
+                }
+                else
+                {
+                    textPrinter.PrintTextLine(item.From + item.Text);
+                }
             }
         }
 
@@ -189,8 +204,6 @@ namespace Radegast
         {
             StringBuilder sb = new StringBuilder();
 
-            sb.AppendFormat("(channel {0}) {1}", e.Channel, client.Self.Name);
-
             switch (e.Type)
             {
                 case ChatType.Normal:
@@ -209,7 +222,7 @@ namespace Radegast
             sb.Append(e.Message);
 
             ChatBufferItem item = new ChatBufferItem(
-                DateTime.Now, sb.ToString(), ChatBufferTextStyle.StatusDarkBlue);
+                DateTime.Now, string.Format("(channel {0}) {1}", e.Channel, client.Self.Name), client.Self.AgentID, sb.ToString(), ChatBufferTextStyle.StatusDarkBlue);
 
             ProcessBufferItem(item, true);
 
@@ -225,6 +238,12 @@ namespace Radegast
                 null != client.Self.MuteList.Find(me => me.Type == MuteType.Resident && me.ID == e.SourceID)
                 ) return;
 
+            // Check if it's script debug
+            if (e.Type == ChatType.Debug && !instance.GlobalSettings["show_script_errors"])
+            {
+                return;
+            }
+
             // Check if sender object is muted
             if (e.SourceType == ChatSourceType.Object &&
                 null != client.Self.MuteList.Find(me =>
@@ -237,24 +256,27 @@ namespace Radegast
             {
                 instance.RLV.TryProcessCMD(e);
 #if !DEBUG
-                return;
+                if (!instance.RLV.EnabledDebugCommands) {
+                    return;
+                }
 #endif
             }
 
+            ChatBufferItem item = new ChatBufferItem();
+            item.ID = e.SourceID;
+            item.RawMessage = e;
             StringBuilder sb = new StringBuilder();
-            // if (e.SourceType == ChatSourceType.Object) {
-            //    sb.Append(e.Position + " ");
-            // }
+
             if (e.SourceType == ChatSourceType.Agent)
             {
-                sb.Append(instance.Names.Get(e.SourceID, e.FromName));
+                item.From = instance.Names.Get(e.SourceID, e.FromName);
             }
             else
             {
-                sb.Append(e.FromName);
+                item.From = e.FromName;
             }
 
-            bool isEmote = e.Message.StartsWith("/me ");
+            bool isEmote = e.Message.ToLower().StartsWith("/me ");
 
             if (!isEmote)
             {
@@ -287,7 +309,6 @@ namespace Radegast
                     sb.Append(e.Message);
             }
 
-            ChatBufferItem item = new ChatBufferItem();
             item.Timestamp = DateTime.Now;
             item.Text = sb.ToString();
 
@@ -304,6 +325,10 @@ namespace Radegast
                     {
                         item.Style = ChatBufferTextStyle.OwnerSay;
                     }
+                    else if (e.Type == ChatType.Debug)
+                    {
+                        item.Style = ChatBufferTextStyle.Error;
+                    }
                     else
                     {
                         item.Style = ChatBufferTextStyle.ObjectChat;
@@ -338,4 +363,15 @@ namespace Radegast
             set { textPrinter = value; }
         }
     }
+
+    public class ChatLineAddedArgs : EventArgs
+    {
+        ChatBufferItem mItem;
+        public ChatBufferItem Item { get { return mItem; } }
+
+        public ChatLineAddedArgs(ChatBufferItem item)
+        {
+            mItem = item;
+        }
+    }
 }