Esempio n. 1
0
    public override void OnKeyDown(Game game_, KeyEventArgs args)
    {
        if (game.guistate != GuiState.Normal)
        {
            //Don't open chat when not in normal game
            return;
        }
        int eKey = args.GetKeyCode();

        if (eKey == game.GetKey(GlKeys.Number7) && game.IsShiftPressed && game.GuiTyping == TypingState.None)         // don't need to hit enter for typing commands starting with slash
        {
            game.GuiTyping       = TypingState.Typing;
            game.IsTyping        = true;
            game.GuiTypingBuffer = "";
            game.IsTeamchat      = false;
            args.SetHandled(true);
            return;
        }
        if (eKey == game.GetKey(GlKeys.PageUp) && game.GuiTyping == TypingState.Typing)
        {
            ChatPageScroll++;
            args.SetHandled(true);
        }
        if (eKey == game.GetKey(GlKeys.PageDown) && game.GuiTyping == TypingState.Typing)
        {
            ChatPageScroll--;
            args.SetHandled(true);
        }
        ChatPageScroll = MathCi.ClampInt(ChatPageScroll, 0, game.ChatLinesCount / ChatLinesMaxToDraw);
        if (eKey == game.GetKey(GlKeys.Enter) || eKey == game.GetKey(GlKeys.KeypadEnter))
        {
            if (game.GuiTyping == TypingState.Typing)
            {
                game.typinglog[game.typinglogCount++] = game.GuiTypingBuffer;
                game.typinglogpos = game.typinglogCount;
                game.ClientCommand(game.GuiTypingBuffer);

                game.GuiTypingBuffer = "";
                game.IsTyping        = false;

                game.GuiTyping = TypingState.None;
                game.platform.ShowKeyboard(false);
            }
            else if (game.GuiTyping == TypingState.None)
            {
                game.StartTyping();
            }
            else if (game.GuiTyping == TypingState.Ready)
            {
                game.platform.ConsoleWriteLine("Keyboard_KeyDown ready");
            }
            args.SetHandled(true);
            return;
        }
        if (game.GuiTyping == TypingState.Typing)
        {
            int key = eKey;
            if (key == game.GetKey(GlKeys.BackSpace))
            {
                if (StringTools.StringLength(game.platform, game.GuiTypingBuffer) > 0)
                {
                    game.GuiTypingBuffer = StringTools.StringSubstring(game.platform, game.GuiTypingBuffer, 0, StringTools.StringLength(game.platform, game.GuiTypingBuffer) - 1);
                }
                args.SetHandled(true);
                return;
            }
            if (game.keyboardStateRaw[game.GetKey(GlKeys.ControlLeft)] || game.keyboardStateRaw[game.GetKey(GlKeys.ControlRight)])
            {
                if (key == game.GetKey(GlKeys.V))
                {
                    if (game.platform.ClipboardContainsText())
                    {
                        game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.GuiTypingBuffer, game.platform.ClipboardGetText());
                    }
                    args.SetHandled(true);
                    return;
                }
            }
            if (key == game.GetKey(GlKeys.Up))
            {
                game.typinglogpos--;
                if (game.typinglogpos < 0)
                {
                    game.typinglogpos = 0;
                }
                if (game.typinglogpos >= 0 && game.typinglogpos < game.typinglogCount)
                {
                    game.GuiTypingBuffer = game.typinglog[game.typinglogpos];
                }
                args.SetHandled(true);
            }
            if (key == game.GetKey(GlKeys.Down))
            {
                game.typinglogpos++;
                if (game.typinglogpos > game.typinglogCount)
                {
                    game.typinglogpos = game.typinglogCount;
                }
                if (game.typinglogpos >= 0 && game.typinglogpos < game.typinglogCount)
                {
                    game.GuiTypingBuffer = game.typinglog[game.typinglogpos];
                }
                if (game.typinglogpos == game.typinglogCount)
                {
                    game.GuiTypingBuffer = "";
                }
                args.SetHandled(true);
            }
            //Handles player name autocomplete in chat
            if (eKey == game.GetKey(GlKeys.Tab) && game.platform.StringTrim(game.GuiTypingBuffer) != "")
            {
                IntRef   partsLength = new IntRef();
                string[] parts       = game.platform.StringSplit(game.GuiTypingBuffer, " ", partsLength);
                string   completed   = DoAutocomplete(parts[partsLength.value - 1]);
                if (completed == "")
                {
                    //No completion available. Abort.
                    args.SetHandled(true);
                    return;
                }
                else if (partsLength.value == 1)
                {
                    //Part is first word. Format as "<name>: "
                    game.GuiTypingBuffer = StringTools.StringAppend(game.platform, completed, ": ");
                }
                else
                {
                    //Part is not first. Just complete "<name> "
                    parts[partsLength.value - 1] = completed;
                    game.GuiTypingBuffer         = StringTools.StringAppend(game.platform, game.platform.StringJoin(parts, " "), " ");
                }
                args.SetHandled(true);
                return;
            }
            args.SetHandled(true);
            return;
        }
    }
Esempio n. 2
0
    public override void OnKeyDown(Game game_, KeyEventArgs args)
    {
        if (game.guistate != GuiState.Normal)
        {
            //Don't open chat when not in normal game
            return;
        }
        int eKey = args.GetKeyCode();

        if (eKey == game.GetKey(GlKeys.Number7) && game.IsShiftPressed && game.GuiTyping == TypingState.None) // don't need to hit enter for typing commands starting with slash
        {
            game.GuiTyping       = TypingState.Typing;
            game.IsTyping        = true;
            game.GuiTypingBuffer = "";
            game.IsTeamchat      = false;
            args.SetHandled(true);
            return;
        }
        if (eKey == game.GetKey(GlKeys.PageUp) && game.GuiTyping == TypingState.Typing)
        {
            ChatPageScroll++;
            args.SetHandled(true);
        }
        if (eKey == game.GetKey(GlKeys.PageDown) && game.GuiTyping == TypingState.Typing)
        {
            ChatPageScroll--;
            args.SetHandled(true);
        }
        ChatPageScroll = MathCi.ClampInt(ChatPageScroll, 0, game.ChatLinesCount / ChatLinesMaxToDraw);
        if (eKey == game.GetKey(GlKeys.Enter) || eKey == game.GetKey(GlKeys.KeypadEnter))
        {
            if (game.GuiTyping == TypingState.Typing)
            {
                game.typinglog[game.typinglogCount++] = game.GuiTypingBuffer;
                game.typinglogpos = game.typinglogCount;
                game.ClientCommand(game.GuiTypingBuffer);

                game.GuiTypingBuffer = "";
                game.IsTyping        = false;

                game.GuiTyping = TypingState.None;
                game.platform.ShowKeyboard(false);
            }
            else if (game.GuiTyping == TypingState.None)
            {
                game.StartTyping();
            }
            else if (game.GuiTyping == TypingState.Ready)
            {
                game.platform.ConsoleWriteLine("Keyboard_KeyDown ready");
            }
            args.SetHandled(true);
            return;
        }
        if (game.GuiTyping == TypingState.Typing)
        {
            int key = eKey;
            if (key == game.GetKey(GlKeys.BackSpace))
            {
                if (StringTools.StringLength(game.platform, game.GuiTypingBuffer) > 0)
                {
                    game.GuiTypingBuffer = StringTools.StringSubstring(game.platform, game.GuiTypingBuffer, 0, StringTools.StringLength(game.platform, game.GuiTypingBuffer) - 1);
                }
                args.SetHandled(true);
                return;
            }
            if (game.keyboardStateRaw[game.GetKey(GlKeys.ControlLeft)] || game.keyboardStateRaw[game.GetKey(GlKeys.ControlRight)])
            {
                if (key == game.GetKey(GlKeys.V))
                {
                    if (game.platform.ClipboardContainsText())
                    {
                        game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.GuiTypingBuffer, game.platform.ClipboardGetText());
                    }
                    args.SetHandled(true);
                    return;
                }
            }
            if (key == game.GetKey(GlKeys.Up))
            {
                game.typinglogpos--;
                if (game.typinglogpos < 0)
                {
                    game.typinglogpos = 0;
                }
                if (game.typinglogpos >= 0 && game.typinglogpos < game.typinglogCount)
                {
                    game.GuiTypingBuffer = game.typinglog[game.typinglogpos];
                }
                args.SetHandled(true);
            }
            if (key == game.GetKey(GlKeys.Down))
            {
                game.typinglogpos++;
                if (game.typinglogpos > game.typinglogCount)
                {
                    game.typinglogpos = game.typinglogCount;
                }
                if (game.typinglogpos >= 0 && game.typinglogpos < game.typinglogCount)
                {
                    game.GuiTypingBuffer = game.typinglog[game.typinglogpos];
                }
                if (game.typinglogpos == game.typinglogCount)
                {
                    game.GuiTypingBuffer = "";
                }
                args.SetHandled(true);
            }
            args.SetHandled(true);
            return;
        }
    }