Example #1
0
        public void Write(char value)
        {
            _consoleText += value;

            _textAdded = TextAdded.Yes;

            TruncateConsoleText();
        }
Example #2
0
 private void bAdd_Click(object sender, RoutedEventArgs e)
 {
     if (tbText.Text != null && tbText.Text.Length > 0)
     {
         var elem = AddTextToList(tbText.Text);
         TextAdded?.Invoke(elem);
         tbText.Text = "";
     }
 }
Example #3
0
        public void Write(char[] buffer, int index, int count)
        {
            var text = new string(buffer, index, count);

            _consoleText += text;

            _textAdded = TextAdded.Yes;

            TruncateConsoleText();
        }
Example #4
0
        public Result <IDisposable> AddText(Identity identity, RenderedText text)
        {
            if (renderedText.ContainsKey(identity))
            {
                return(Result.FailWith <IDisposable>(State.Forbidden, $"TargetRenderer already contains text {identity.Id}."));
            }
            renderedText.Add(identity, text);
            TextAdded?.Invoke(this, new RenderedTextEventArgs(identity, text));

            return(Result.Ok(Disposable.For(() =>
            {
                if (renderedText.ContainsKey(identity))
                {
                    renderedText.Remove(identity);
                    TextRemoved?.Invoke(this, new RenderedTextEventArgs(identity, text));
                }
            })));
        }
        public bool SendMessage(string username, string message)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(message))
            {
                return(false);
            }

            string line = $"<{username}> {message}";

            TextAdded?.Invoke(null, line);

            ChatHistory.Enqueue(line);
            if (ChatHistory.Count > 100)
            {
                RemoveHistory();
            }

            return(true);
        }
        public bool SendMessage(string username, string message)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(message))
            {
                return(false);
            }

            string line = $"<{username}> {message}";

            lock (SyncRoot)
            {
                ChatHistory.Add(line);
                while (ChatHistory.Count > 50)
                {
                    ChatHistory.RemoveAt(0);
                }

                ChatWindowText = string.Join("\r\n", ChatHistory.Take(50));
            }

            TextAdded?.Invoke(this, EventArgs.Empty);
            return(true);
        }
 protected virtual void OnTextAdded(string npcId, int numChars)
 {
     TextAdded?.Invoke(this, string.Format("NpcID {0} ({1} chars)", npcId, numChars));
 }
Example #8
0
        private void DrawConsole()
        {
            if (_consoleVisible && ImGui.BeginWindow("Console", ref _consoleVisible, WindowFlags.NoCollapse))
            {
                var textHeight = ImGuiNative.igGetTextLineHeight();

                var contentMin = ImGui.GetWindowContentRegionMin();
                var contentMax = ImGui.GetWindowContentRegionMax();

                var wrapWidth = contentMax.X - contentMin.X;
                //Leave some space at the bottom
                var maxHeight = contentMax.Y - contentMin.Y - (textHeight * 3);

                //Convert the text to UTF8
                //Acount for null terminator
                var byteCount = Encoding.UTF8.GetByteCount(_consoleText) + 1;

                //Resize on demand
                if (_consoleTextUTF8 == null || _consoleTextUTF8.Length < byteCount)
                {
                    _consoleTextUTF8 = new byte[byteCount];
                }

                var bytesWritten = StringUtils.EncodeNullTerminatedString(Encoding.UTF8, _consoleText, _consoleTextUTF8);

                //Display as input text area to allow text selection
                var pinnedBuffer  = GCHandle.Alloc(_consoleTextUTF8, GCHandleType.Pinned);
                var bufferAddress = pinnedBuffer.AddrOfPinnedObject();

                ImGui.InputTextMultiline("##consoleText", bufferAddress, (uint)bytesWritten + 1, new Vector2(wrapWidth, maxHeight), InputTextFlags.ReadOnly, null);

                //Scroll to bottom when new text is added
                ImGuiNative.igBeginGroup();
                var id = ImGui.GetID("##consoleText");
                ImGui.BeginChildFrame(id, new Vector2(wrapWidth, maxHeight), WindowFlags.Default);

                switch (_textAdded)
                {
                case TextAdded.Yes:
                {
                    _textAdded = TextAdded.ApplyScroll;
                    break;
                }

                case TextAdded.ApplyScroll:
                {
                    _textAdded = TextAdded.No;

                    var yPos = ImGuiNative.igGetScrollMaxY();

                    ImGuiNative.igSetScrollY(yPos);
                    break;
                }
                }

                ImGui.EndChildFrame();
                ImGuiNative.igEndGroup();

                pinnedBuffer.Free();

                ImGui.Text("Command:");
                ImGui.SameLine();

                //Max width for the input
                ImGui.PushItemWidth(-1);

                if (ImGui.InputText("##consoleInput", _consoleInputBuffer, (uint)_consoleInputBuffer.Length, InputTextFlags.EnterReturnsTrue, null))
                {
                    //Needed since GetString doesn't understand null terminated strings
                    var stringLength = StringUtils.NullTerminatedByteLength(_consoleInputBuffer);

                    if (stringLength > 0)
                    {
                        var commandText = Encoding.UTF8.GetString(_consoleInputBuffer, 0, stringLength);
                        _logger.Information($"] {commandText}");
                        _engine.CommandContext.QueueCommands(commandText);
                    }

                    Array.Fill <byte>(_consoleInputBuffer, 0, 0, stringLength);
                }

                ImGui.PopItemWidth();

                ImGui.EndWindow();
            }
        }
Example #9
0
        public void Draw()
        {
            if (_consoleVisible && ImGui.Begin("Console", ref _consoleVisible, ImGuiWindowFlags.NoCollapse))
            {
                var textHeight = ImGuiNative.igGetTextLineHeight();

                var contentMin = ImGui.GetWindowContentRegionMin();
                var contentMax = ImGui.GetWindowContentRegionMax();

                var wrapWidth = contentMax.X - contentMin.X;
                //Leave some space at the bottom
                var maxHeight = contentMax.Y - contentMin.Y - (textHeight * 3);

                //Display as input text area to allow text selection
                ImGui.InputTextMultiline("##consoleText", ref _consoleText, _maxConsoleChars, new Vector2(wrapWidth, maxHeight), ImGuiInputTextFlags.ReadOnly, null);

                //Scroll to bottom when new text is added
                ImGuiNative.igBeginGroup();
                var id = ImGui.GetID("##consoleText");
                ImGui.BeginChildFrame(id, new Vector2(wrapWidth, maxHeight), ImGuiWindowFlags.None);

                switch (_textAdded)
                {
                case TextAdded.Yes:
                {
                    _textAdded = TextAdded.ApplyScroll;
                    break;
                }

                case TextAdded.ApplyScroll:
                {
                    _textAdded = TextAdded.No;

                    var yPos = ImGuiNative.igGetScrollMaxY();

                    ImGuiNative.igSetScrollY(yPos);
                    break;
                }
                }

                ImGui.EndChildFrame();
                ImGuiNative.igEndGroup();

                ImGui.Text("Command:");
                ImGui.SameLine();

                //Max width for the input
                ImGui.PushItemWidth(-1);

                if (ImGui.InputText("##consoleInput", _consoleInputBuffer, (uint)_consoleInputBuffer.Length, ImGuiInputTextFlags.EnterReturnsTrue, null))
                {
                    //Needed since GetString doesn't understand null terminated strings
                    var stringLength = StringUtils.NullTerminatedByteLength(_consoleInputBuffer);

                    if (stringLength > 0)
                    {
                        var commandText = Encoding.UTF8.GetString(_consoleInputBuffer, 0, stringLength);
                        _logger.Information($"] {commandText}");
                        _client.CommandContext.QueueCommands(commandText);
                    }

                    Array.Fill <byte>(_consoleInputBuffer, 0, 0, stringLength);
                }

                ImGui.PopItemWidth();

                ImGui.End();
            }
        }
Example #10
0
 protected virtual void OnTextAdded(TextAddedEventArgs e)
 {
     TextAdded?.Invoke(this, e);
 }