public void Log(string sawmillName, LogEvent message)
        {
            if (sawmillName == "CON")
            {
                return;
            }

            var formatted   = new FormattedMessage(8);
            var robustLevel = message.Level.ToRobust();

            formatted.PushColor(Color.DarkGray);
            formatted.AddText("[");
            formatted.PushColor(LogLevelToColor(robustLevel));
            formatted.AddText(LogMessage.LogLevelToName(robustLevel));
            formatted.Pop();
            formatted.AddText($"] {sawmillName}: ");
            formatted.Pop();
            formatted.AddText(message.RenderMessage());
            if (message.Exception != null)
            {
                formatted.AddText("\n");
                formatted.AddText(message.Exception.ToString());
            }
            Console.AddFormattedLine(formatted);
        }
Esempio n. 2
0
 public void Examine(FormattedMessage message)
 {
     message.AddText("A dice with ");
     message.PushColor(new Color(1F, 0.75F, 0.75F));
     message.AddText(_sides.ToString());
     message.Pop();
     message.AddText(" sides.\nIt has landed on a ");
     message.PushColor(new Color(1F, 1F, 1F));
     message.AddText(_currentSide.ToString());
     message.Pop();
     message.AddText(".");
 }
        public void Log(LogMessage message)
        {
            var formatted = new FormattedMessage(8);

            formatted.PushColor(Color.DarkGray);
            formatted.AddText("[");
            formatted.PushColor(LogLevelToColor(message.Level));
            formatted.AddText(message.LogLevelToName());
            formatted.Pop();
            formatted.AddText($"] {message.SawmillName}: ");
            formatted.Pop();
            formatted.AddText(message.Message);
            Console.AddFormattedLine(formatted);
        }
        public FormattedMessage GetExamineText(EntityUid entity, EntityUid?examiner)
        {
            var message = new FormattedMessage();

            if (examiner == null)
            {
                return(message);
            }

            var doNewline = false;

            //Add an entity description if one is declared
            if (!string.IsNullOrEmpty(EntityManager.GetComponent <MetaDataComponent>(entity).EntityDescription))
            {
                message.AddText(EntityManager.GetComponent <MetaDataComponent>(entity).EntityDescription);
                doNewline = true;
            }

            message.PushColor(Color.DarkGray);

            // Raise the event and let things that subscribe to it change the message...
            var isInDetailsRange = IsInDetailsRange(examiner.Value, entity);
            var examinedEvent    = new ExaminedEvent(message, entity, examiner.Value, isInDetailsRange, doNewline);

            RaiseLocalEvent(entity, examinedEvent, true);

            message.Pop();

            return(message);
        }
        public void AddLine(string text, ChatChannel channel, Color color)
        {
            if (!ThreadUtility.IsOnMainThread())
            {
                var formatted = new FormattedMessage(3);
                formatted.PushColor(color);
                formatted.AddText(text);
                formatted.Pop();
                _messageQueue.Enqueue(formatted);
                return;
            }

            _flushQueue();
            if (!firstLine)
            {
                Contents.NewLine();
            }
            else
            {
                firstLine = false;
            }

            Contents.PushColor(color);
            Contents.AddText(text);
            Contents.Pop(); // Pop the color off.
        }
Esempio n. 6
0
        public override void Output(string value, string data)
        {
            var msg = new FormattedMessage(2);

            msg.PushColor(Color.Black);
            msg.AddText(value);
            _textBox.AddMessage(msg);
        }
Esempio n. 7
0
        public void AddLine(string text, ChatChannel channel, Color color)
        {
            var formatted = new FormattedMessage(3);

            formatted.PushColor(color);
            formatted.AddText(text);
            formatted.Pop();
            AddFormattedLine(formatted);
        }
Esempio n. 8
0
        public void AddLine(FormattedMessage message, Color color)
        {
            if (Disposed)
            {
                return;
            }

            var formatted = new FormattedMessage(3);

            formatted.PushColor(color);
            formatted.AddMessage(message);
            formatted.Pop();
            Contents.AddMessage(formatted);
        }
Esempio n. 9
0
        public void AddLine(string message, ChatChannel channel, Color color)
        {
            if (Disposed)
            {
                return;
            }

            var formatted = new FormattedMessage(3);

            formatted.PushColor(color);
            formatted.AddText(message);
            formatted.Pop();
            contents.AddMessage(formatted);
        }
Esempio n. 10
0
        public FormattedMessage GetExamineText(EntityUid entity, EntityUid?examiner)
        {
            var message = new FormattedMessage();

            if (examiner == null)
            {
                return(message);
            }

            var doNewline = false;

            //Add an entity description if one is declared
            if (!string.IsNullOrEmpty(EntityManager.GetComponent <MetaDataComponent>(entity).EntityDescription))
            {
                message.AddText(EntityManager.GetComponent <MetaDataComponent>(entity).EntityDescription);
                doNewline = true;
            }

            message.PushColor(Color.DarkGray);

            // Raise the event and let things that subscribe to it change the message...
            var isInDetailsRange = IsInDetailsRange(examiner.Value, entity);
            var examinedEvent    = new ExaminedEvent(message, entity, examiner.Value, isInDetailsRange, doNewline);

            RaiseLocalEvent(entity, examinedEvent);

            //Add component statuses from components that report one
            foreach (var examineComponent in EntityManager.GetComponents <IExamine>(entity))
            {
                var subMessage = new FormattedMessage();
                examineComponent.Examine(subMessage, isInDetailsRange);
                if (subMessage.Tags.Count == 0)
                {
                    continue;
                }

                if (doNewline)
                {
                    message.AddText("\n");
                }

                message.AddMessage(subMessage);
                doNewline = true;
            }

            message.Pop();

            return(message);
        }
Esempio n. 11
0
        public FormattedMessage GetExamineText(IEntity entity, IEntity?examiner)
        {
            var message = new FormattedMessage();

            if (examiner == null)
            {
                return(message);
            }

            var doNewline = false;

            //Add an entity description if one is declared
            if (!string.IsNullOrEmpty(entity.Description))
            {
                message.AddText(entity.Description);
                doNewline = true;
            }

            message.PushColor(Color.DarkGray);

            // Raise the event and let things that subscribe to it change the message...
            RaiseLocalEvent(entity.Uid, new ExaminedEvent(message, entity, examiner, IsInDetailsRange(examiner, entity)));

            //Add component statuses from components that report one
            foreach (var examineComponent in entity.GetAllComponents <IExamine>())
            {
                var subMessage = new FormattedMessage();
                examineComponent.Examine(subMessage, IsInDetailsRange(examiner, entity));
                if (subMessage.Tags.Count == 0)
                {
                    continue;
                }

                if (doNewline)
                {
                    message.AddText("\n");
                }

                message.AddMessage(subMessage);
                doNewline = true;
            }

            message.Pop();

            return(message);
        }
            public void ReceiveResponse(MsgScriptResponse response)
            {
                RunButton.Disabled = false;

                // Remove > or . at the end of the output panel.
                OutputPanel.RemoveEntry(^ 1);
                _linesEntered += 1;

                if (!response.WasComplete)
                {
                    if (_linesEntered == 1)
                    {
                        OutputPanel.AddText($"> {_lastEnteredText}");
                    }
                    else
                    {
                        OutputPanel.AddText($". {_lastEnteredText}");
                    }

                    OutputPanel.AddText(".");
                    return;
                }

                // Remove echo of partial submission from the output panel.
                for (var i = 1; i < _linesEntered; i++)
                {
                    OutputPanel.RemoveEntry(^ 1);
                }

                _linesEntered = 0;

                // Echo entered script.
                var echoMessage = new FormattedMessage();

                echoMessage.PushColor(Color.FromHex("#D4D4D4"));
                echoMessage.AddText("> ");
                echoMessage.AddMessage(response.Echo);
                OutputPanel.AddMessage(echoMessage);

                OutputPanel.AddMessage(response.Response);

                OutputPanel.AddText(">");
            }
        public static FormattedMessage GetExamineText(IEntity entity, IEntity examiner)
        {
            var message = new FormattedMessage();

            var doNewline = false;

            //Add an entity description if one is declared
            if (!string.IsNullOrEmpty(entity.Description))
            {
                message.AddText(entity.Description);
                doNewline = true;
            }

            message.PushColor(Color.DarkGray);

            var inDetailsRange = Get <SharedInteractionSystem>()
                                 .InRangeUnobstructed(examiner.Transform.MapPosition, entity.Transform.MapPosition,
                                                      ExamineDetailsRange, predicate: entity0 => entity0 == examiner || entity0 == entity, ignoreInsideBlocker: true);

            //Add component statuses from components that report one
            foreach (var examineComponent in entity.GetAllComponents <IExamine>())
            {
                var subMessage = new FormattedMessage();
                examineComponent.Examine(subMessage, inDetailsRange);
                if (subMessage.Tags.Count == 0)
                {
                    continue;
                }

                if (doNewline)
                {
                    message.AddText("\n");
                }

                message.AddMessage(subMessage);
                doNewline = true;
            }

            message.Pop();

            return(message);
        }
Esempio n. 14
0
        public static FormattedMessage GetExamineText(IEntity entity, IEntity examiner)
        {
            var message = new FormattedMessage();

            var doNewline = false;

            //Add an entity description if one is declared
            if (!string.IsNullOrEmpty(entity.Description))
            {
                message.AddText(entity.Description);
                doNewline = true;
            }

            message.PushColor(Color.DarkGray);

            //Add component statuses from components that report one
            foreach (var examineComponent in entity.GetAllComponents <IExamine>())
            {
                var subMessage = new FormattedMessage();
                examineComponent.Examine(subMessage, IsInDetailsRange(examiner, entity));
                if (subMessage.Tags.Count == 0)
                {
                    continue;
                }

                if (doNewline)
                {
                    message.AddText("\n");
                }

                message.AddMessage(subMessage);
                doNewline = true;
            }

            message.Pop();

            return(message);
        }
Esempio n. 15
0
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            var window = new DefaultWindow {
                MinSize = (500, 400)
            };
            var tabContainer = new TabContainer();

            window.Contents.AddChild(tabContainer);
            var scroll = new ScrollContainer();

            tabContainer.AddChild(scroll);
            //scroll.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide);
            var vBox = new BoxContainer
            {
                Orientation = LayoutOrientation.Vertical
            };

            scroll.AddChild(vBox);

            var progressBar = new ProgressBar {
                MaxValue = 10, Value = 5
            };

            vBox.AddChild(progressBar);

            var optionButton = new OptionButton();

            optionButton.AddItem("Honk");
            optionButton.AddItem("Foo");
            optionButton.AddItem("Bar");
            optionButton.AddItem("Baz");
            optionButton.OnItemSelected += eventArgs => optionButton.SelectId(eventArgs.Id);
            vBox.AddChild(optionButton);

            var tree = new Tree {
                VerticalExpand = true
            };
            var root = tree.CreateItem();

            root.Text = "Honk!";
            var child = tree.CreateItem();

            child.Text = "Foo";
            for (var i = 0; i < 20; i++)
            {
                child      = tree.CreateItem();
                child.Text = $"Bar {i}";
            }

            vBox.AddChild(tree);

            var rich    = new RichTextLabel();
            var message = new FormattedMessage();

            message.AddText("Foo\n");
            message.PushColor(Color.Red);
            message.AddText("Bar");
            message.Pop();
            rich.SetMessage(message);
            vBox.AddChild(rich);

            var itemList = new ItemList();

            tabContainer.AddChild(itemList);
            for (var i = 0; i < 10; i++)
            {
                itemList.AddItem(i.ToString());
            }

            var grid = new GridContainer {
                Columns = 3
            };

            tabContainer.AddChild(grid);
            for (var y = 0; y < 3; y++)
            {
                for (var x = 0; x < 3; x++)
                {
                    grid.AddChild(new Button
                    {
                        MinSize = (50, 50),
                        Text    = $"{x}, {y}"
                    });
Esempio n. 16
0
        public bool Execute(IDebugConsole console, params string[] args)
        {
            var window = new SS14Window("UITest");

            window.AddToScreen();
            var tabContainer = new TabContainer();

            window.Contents.AddChild(tabContainer);
            var scroll = new ScrollContainer();

            tabContainer.AddChild(scroll);
            scroll.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide);
            var vBox = new VBoxContainer();

            scroll.AddChild(vBox);

            var progressBar = new ProgressBar {
                MaxValue = 10, Value = 5
            };

            vBox.AddChild(progressBar);

            var optionButton = new OptionButton();

            optionButton.AddItem("Honk");
            optionButton.AddItem("Foo");
            optionButton.AddItem("Bar");
            optionButton.AddItem("Baz");
            optionButton.OnItemSelected += eventArgs => optionButton.SelectId(eventArgs.Id);
            vBox.AddChild(optionButton);

            var tree = new Tree {
                SizeFlagsVertical = Control.SizeFlags.FillExpand
            };
            var root = tree.CreateItem();

            root.Text = "Honk!";
            var child = tree.CreateItem();

            child.Text = "Foo";
            for (var i = 0; i < 20; i++)
            {
                child      = tree.CreateItem();
                child.Text = $"Bar {i}";
            }
            vBox.AddChild(tree);

            var rich    = new RichTextLabel();
            var message = new FormattedMessage();

            message.AddText("Foo\n");
            message.PushColor(Color.Red);
            message.AddText("Bar");
            message.Pop();
            rich.SetMessage(message);
            vBox.AddChild(rich);

            var itemList = new ItemList();

            tabContainer.AddChild(itemList);
            for (var i = 0; i < 10; i++)
            {
                itemList.AddItem(i.ToString());
            }

            var grid = new GridContainer {
                Columns = 3
            };

            tabContainer.AddChild(grid);
            for (var y = 0; y < 3; y++)
            {
                for (var x = 0; x < 3; x++)
                {
                    grid.AddChild(new Button
                    {
                        CustomMinimumSize = (50, 50),
                        Text = $"{x}, {y}"
                    });
Esempio n. 17
0
        private async void ReceiveScriptEval(MsgScriptEval message)
        {
            if (!_playerManager.TryGetSessionByChannel(message.MsgChannel, out var session))
            {
                return;
            }

            if (!_conGroupController.CanViewVar(session))
            {
                Logger.WarningS("script", "Client {0} tried to access Scripting without permissions.", session);
                return;
            }

            if (!_instances.TryGetValue(session, out var instances) ||
                !instances.TryGetValue(message.ScriptSession, out var instance))
            {
                return;
            }

            var replyMessage = _netManager.CreateNetMessage <MsgScriptResponse>();

            replyMessage.ScriptSession = message.ScriptSession;

            var code = message.Code;

            instance.InputBuffer.AppendLine(code);

            var tree = SyntaxFactory.ParseSyntaxTree(SourceText.From(instance.InputBuffer.ToString()),
                                                     ScriptInstanceShared.ParseOptions);

            if (!SyntaxFactory.IsCompleteSubmission(tree))
            {
                replyMessage.WasComplete = false;
                _netManager.ServerSendMessage(replyMessage, message.MsgChannel);
                return;
            }

            replyMessage.WasComplete = true;

            code = instance.InputBuffer.ToString().Trim();

            instance.InputBuffer.Clear();

            Script newScript;

            if (instance.State != null)
            {
                newScript = instance.State.Script.ContinueWith(code);
            }
            else
            {
                var options = ScriptInstanceShared.GetScriptOptions(_reflectionManager);
                newScript = CSharpScript.Create(code, options, typeof(ScriptGlobals));
            }

            // Compile ahead of time so that we can do syntax highlighting correctly for the echo.
            newScript.Compile();

            // Echo entered script.
            var echoMessage = new FormattedMessage();

            ScriptInstanceShared.AddWithSyntaxHighlighting(newScript, echoMessage, code, instance.HighlightWorkspace);

            replyMessage.Echo = echoMessage;

            var msg = new FormattedMessage();

            try
            {
                instance.RunningScript = true;
                if (instance.State != null)
                {
                    instance.State = await newScript.RunFromAsync(instance.State, _ => true);
                }
                else
                {
                    instance.State = await newScript.RunAsync(instance.Globals, _ => true);
                }
            }
            catch (CompilationErrorException e)
            {
                msg.PushColor(Color.Crimson);

                foreach (var diagnostic in e.Diagnostics)
                {
                    msg.AddText(diagnostic.ToString());
                    msg.AddText("\n");
                }

                replyMessage.Response = msg;
                _netManager.ServerSendMessage(replyMessage, message.MsgChannel);
                return;
            }
            finally
            {
                instance.RunningScript = false;
            }

            if (instance.OutputBuffer.Length != 0)
            {
                msg.AddText(instance.OutputBuffer.ToString());
                instance.OutputBuffer.Clear();
            }

            if (instance.State.Exception != null)
            {
                msg.PushColor(Color.Crimson);
                msg.AddText(CSharpObjectFormatter.Instance.FormatException(instance.State.Exception));
            }
            else if (ScriptInstanceShared.HasReturnValue(newScript))
            {
                msg.AddText(CSharpObjectFormatter.Instance.FormatObject(instance.State.ReturnValue));
            }

            replyMessage.Response = msg;
            _netManager.ServerSendMessage(replyMessage, message.MsgChannel);
        }
Esempio n. 18
0
        protected override async void Run()
        {
            var code = InputBar.Text;

            InputBar.Clear();

            // Remove > or . at the end of the output panel.
            OutputPanel.RemoveEntry(^ 1);

            _inputBuffer.AppendLine(code);
            _linesEntered += 1;

            var tree = SyntaxFactory.ParseSyntaxTree(SourceText.From(_inputBuffer.ToString()), ScriptInstanceShared.ParseOptions);

            if (!SyntaxFactory.IsCompleteSubmission(tree))
            {
                if (_linesEntered == 1)
                {
                    OutputPanel.AddText($"> {code}");
                }
                else
                {
                    OutputPanel.AddText($". {code}");
                }
                OutputPanel.AddText(".");
                return;
            }

            code = _inputBuffer.ToString().Trim();

            // Remove echo of partial submission from the output panel.
            for (var i = 1; i < _linesEntered; i++)
            {
                OutputPanel.RemoveEntry(^ 1);
            }

            _inputBuffer.Clear();
            _linesEntered = 0;

            Script newScript;

            if (_state != null)
            {
                newScript = _state.Script.ContinueWith(code);
            }
            else
            {
                var options = ScriptInstanceShared.GetScriptOptions(_reflectionManager);
                newScript = CSharpScript.Create(code, options, typeof(ScriptGlobals));
            }

            // Compile ahead of time so that we can do syntax highlighting correctly for the echo.
            newScript.Compile();

            // Echo entered script.
            var echoMessage = new FormattedMessage();

            echoMessage.PushColor(Color.FromHex("#D4D4D4"));
            echoMessage.AddText("> ");
            ScriptInstanceShared.AddWithSyntaxHighlighting(newScript, echoMessage, code, _highlightWorkspace);

            OutputPanel.AddMessage(echoMessage);

            try
            {
                if (_state != null)
                {
                    _state = await newScript.RunFromAsync(_state, _ => true);
                }
                else
                {
                    _state = await newScript.RunAsync(_globals, _ => true);
                }
            }
            catch (CompilationErrorException e)
            {
                var msg = new FormattedMessage();

                msg.PushColor(Color.Crimson);

                foreach (var diagnostic in e.Diagnostics)
                {
                    msg.AddText(diagnostic.ToString());
                    msg.AddText("\n");
                }

                OutputPanel.AddMessage(msg);
                OutputPanel.AddText(">");
                return;
            }

            if (_state.Exception != null)
            {
                var msg = new FormattedMessage();
                msg.PushColor(Color.Crimson);
                msg.AddText(CSharpObjectFormatter.Instance.FormatException(_state.Exception));
                OutputPanel.AddMessage(msg);
            }
            else if (ScriptInstanceShared.HasReturnValue(newScript))
            {
                var msg = new FormattedMessage();
                msg.AddText(CSharpObjectFormatter.Instance.FormatObject(_state.ReturnValue));
                OutputPanel.AddMessage(msg);
            }

            OutputPanel.AddText(">");
        }
Esempio n. 19
0
            public Entry(LiteResult result)
            {
                MouseFilter = MouseFilterMode.Stop;
                Result      = result;
                var compl = new FormattedMessage();
                var dim   = Color.FromHsl((0f, 0f, 0.8f, 1f));

                // warning: ew ahead
                string basen = "default";

                if (Result.Tags.Contains("Interface"))
                {
                    basen = "interface name";
                }
                else if (Result.Tags.Contains("Class"))
                {
                    basen = "class name";
                }
                else if (Result.Tags.Contains("Struct"))
                {
                    basen = "struct name";
                }
                else if (Result.Tags.Contains("Keyword"))
                {
                    basen = "keyword";
                }
                else if (Result.Tags.Contains("Namespace"))
                {
                    basen = "namespace name";
                }
                else if (Result.Tags.Contains("Method"))
                {
                    basen = "method name";
                }
                else if (Result.Tags.Contains("Property"))
                {
                    basen = "property name";
                }
                else if (Result.Tags.Contains("Field"))
                {
                    basen = "field name";
                }

                Color basec = ScriptingColorScheme.ColorScheme[basen];

                compl.PushColor(basec * dim);
                compl.AddText(Result.DisplayTextPrefix);
                compl.PushColor(basec);
                compl.AddText(Result.DisplayText);
                compl.PushColor(basec * dim);
                compl.AddText(Result.DisplayTextSuffix);
                compl.AddText(" [" + String.Join(", ", Result.Tags) + "]");
                if (Result.InlineDescription.Length != 0)
                {
                    compl.PushNewline();
                    compl.AddText(": ");
                    compl.PushColor(Color.LightSlateGray);
                    compl.AddText(Result.InlineDescription);
                }
                SetMessage(compl);
            }