private void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (_allowAltF4 && e.Key == OpenTK.Input.Key.F4 && keys.Contains(Keys.LeftAlt))
            {
                window.Close();
                return;
            }
            Keys xnaKey = KeyboardUtil.ToXna(e.Key);

            if (!keys.Contains(xnaKey))
            {
                keys.Add(xnaKey);
            }
        }
Example #2
0
        protected void OnKeydown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case OpenTK.Input.Key.F1:
                gui.ToggleHelp();
                break;

            case OpenTK.Input.Key.Escape:
                this.Exit();
                break;

            default:
                break;
            }
        }
Example #3
0
 public override void OnKeyDown(OpenTK.Input.KeyboardKeyEventArgs key)
 {
     if (key.Key == OpenTK.Input.Key.N)
     {
         Program.aw.scene = new HostJoin();
     }
     if (key.Key == OpenTK.Input.Key.O)
     {
         Program.aw.scene = new OptionsScene();
     }
     if (key.Key == OpenTK.Input.Key.Escape)
     {
         Environment.Exit(0);
     }
     dm.OnKeyDown(key);
 }
Example #4
0
 private void OnKeyUp(object sender, TkKeyArgs args)
 {
     _keyModifier = KeyModifier.None;
     if (args.Control)
     {
         _keyModifier |= KeyModifier.Control;
     }
     if (args.Shift)
     {
         _keyModifier |= KeyModifier.Shift;
     }
     if (args.Alt)
     {
         _keyModifier |= KeyModifier.Alt;
     }
 }
Example #5
0
        public override bool OnKeyDown(OpenTK.Input.KeyboardKeyEventArgs e)
        {
            foreach (Widget c in Children)
            {
                if (c.Visible && c.Enabled && c.OnKeyDown(e))
                {
                    return(true);
                }
            }

            if (base.OnKeyDown(e))
            {
                return(true);
            }

            return(false);
        }
Example #6
0
        public override void OnKeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (Enabled)
            {
                if (e.Key == OpenTK.Input.Key.BracketLeft)
                {
                    TotalSampleCount /= 2;
                    return;
                }
                else if (e.Key == OpenTK.Input.Key.BracketRight)
                {
                    TotalSampleCount *= 2;
                    return;
                }
            }

            base.OnKeyUp(sender, e);
        }
Example #7
0
        void CrowIDE_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
//			if (e.Key == OpenTK.Input.Key.Escape) {
//				Quit (null, null);
//			} else
            if (e.Key == OpenTK.Input.Key.F5)
            {
                try {
                    CurrentSolution.StartupProject.Compile();
                } catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                }
            }            // else if (e.Key == OpenTK.Input.Key.F6) {
//				loadWindow ("#Crow.Coding.ui.LQIsExplorer.crow");
//			} else if (e.Key == OpenTK.Input.Key.F7) {
//				loadWindow ("#Crow.Coding.ui.CSProjExplorer.crow");
//			}
        }
        protected override void OnKeyDown(OpenTK.Input.KeyboardKeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Keyboard[OpenTK.Input.Key.Escape])
            {
                this.Exit();
            }
            if (e.Keyboard[OpenTK.Input.Key.Space])
            {
                Trace.WriteLine("GL: " + GL.GetError());
            }
            if (e.Keyboard[OpenTK.Input.Key.Q])
            {
                MaterialScaleAndBiasAndShininess.X += 0.01f;
                Trace.WriteLine("Scale: " + MaterialScaleAndBiasAndShininess.X + " Bias: " + MaterialScaleAndBiasAndShininess.Y);
            }
            if (e.Keyboard[OpenTK.Input.Key.A])
            {
                MaterialScaleAndBiasAndShininess.X -= 0.01f;
                Trace.WriteLine("Scale: " + MaterialScaleAndBiasAndShininess.X + " Bias: " + MaterialScaleAndBiasAndShininess.Y);
            }
            if (e.Keyboard[OpenTK.Input.Key.W])
            {
                MaterialScaleAndBiasAndShininess.Y += 0.01f;
                Trace.WriteLine("Scale: " + MaterialScaleAndBiasAndShininess.X + " Bias: " + MaterialScaleAndBiasAndShininess.Y);
            }
            if (e.Keyboard[OpenTK.Input.Key.S])
            {
                MaterialScaleAndBiasAndShininess.Y -= 0.01f;
                Trace.WriteLine("Scale: " + MaterialScaleAndBiasAndShininess.X + " Bias: " + MaterialScaleAndBiasAndShininess.Y);
            }
            if (e.Keyboard[OpenTK.Input.Key.E])
            {
                MaterialScaleAndBiasAndShininess.Z += 1f;
                Trace.WriteLine("Shininess: " + MaterialScaleAndBiasAndShininess.Z);
            }
            if (e.Keyboard[OpenTK.Input.Key.D])
            {
                MaterialScaleAndBiasAndShininess.Z -= 1f;
                Trace.WriteLine("Shininess: " + MaterialScaleAndBiasAndShininess.Z);
            }
        }
Example #9
0
        public override bool OnKeyDown(OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (base.OnKeyDown(e))
            {
                return(true);
            }

            if (!IsFocused)
            {
                return(false);
            }

            if (e.Key == OpenTK.Input.Key.Enter)
            {
                OnClick(null);
                return(true);
            }

            return(false);
        }
Example #10
0
        void KeyUp(object Sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case OpenTK.Input.Key.Number0: Keys["0"] = false; break;

            case OpenTK.Input.Key.Number1: Keys["1"] = false; break;

            case OpenTK.Input.Key.Number2: Keys["2"] = false; break;

            case OpenTK.Input.Key.Number3: Keys["3"] = false; break;

            case OpenTK.Input.Key.Number4: Keys["4"] = false; break;

            case OpenTK.Input.Key.Number5: Keys["5"] = false; break;

            case OpenTK.Input.Key.Number6: Keys["6"] = false; break;

            case OpenTK.Input.Key.Number7: Keys["7"] = false; break;

            case OpenTK.Input.Key.Number8: Keys["8"] = false; break;

            case OpenTK.Input.Key.Number9: Keys["9"] = false; break;

            case OpenTK.Input.Key.ShiftLeft: Keys["Shift"] = false; break;

            case OpenTK.Input.Key.ControlLeft: Keys["Control"] = false; break;

            case OpenTK.Input.Key.BackSpace: Keys["BackSpace"] = false; break;

            case OpenTK.Input.Key.Up: Keys["Up"] = false; break;

            case OpenTK.Input.Key.Down: Keys["Down"] = false; break;

            case OpenTK.Input.Key.Left: Keys["Left"] = false; break;

            case OpenTK.Input.Key.Right: Keys["Right"] = false; break;

            case OpenTK.Input.Key.Enter: Keys["Enter"] = false; break;
            }
        }
Example #11
0
        void window_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case OpenTK.Input.Key.W:
                keys[0] = true;
                break;

            case OpenTK.Input.Key.S:
                keys[1] = true;
                break;

            case OpenTK.Input.Key.A:
                keys[2] = true;
                break;

            case OpenTK.Input.Key.D:
                keys[3] = true;
                break;
            }
        }
Example #12
0
        private void gameWindow_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.NumLock)
            {
                numLock = !numLock;
            }
            else if (e.Key == OpenTK.Input.Key.CapsLock)
            {
                capsLock = !capsLock;
            }
            else if (e.Key == OpenTK.Input.Key.ScrollLock)
            {
                scrollLock = !scrollLock;
            }
            RLKeyPress newKeyPress = new RLKeyPress((RLKey)e.Key, e.Alt, e.Shift, e.Control, e.IsRepeat, numLock, capsLock, scrollLock);

            if (keyPress != newKeyPress)
            {
                keyPress = newKeyPress;
            }
        }
Example #13
0
 protected override void OnKeyDown(OpenTK.Input.KeyboardKeyEventArgs e)
 {
     base.OnKeyDown(e);
     try
     {
         input.ProcessKeyDown(e);
     }
     catch (Exception ex)
     {
         //sdl eats exceptions
         Console.WriteLine(ex.ToString());
         throw ex;
     }
     if (e.Key == OpenTK.Input.Key.F5)
     {
         skinpng.Dispose();
         skinpng = new Texture(Canvas.Skin.Renderer);
         var skinimg  = new Bitmap(Image.FromFile("DefaultSkin.png"));
         var colorxml = System.IO.File.ReadAllText("DefaultColors.xml");
         Gwen.Renderer.OpenTK.LoadTextureInternal(
             skinpng,
             skinimg);
         var skin = new Gwen.Skin.TexturedBase(Canvas.Skin.Renderer, skinpng, colorxml)
         {
             DefaultFont = Canvas.Skin.DefaultFont
         };
         // Canvas.Skin = skin;
         Canvas.SetSkin(skin, true);
         skinimg.Dispose();
     }
     if (e.Key == OpenTK.Input.Key.F12)
     {
         _slow = !_slow;
     }
     if (e.Key == OpenTK.Input.Key.F11)
     {
         _steps = true;
     }
 }
Example #14
0
 private void Window_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     if (currently_editing)
     {
         OnInput?.Invoke(this, e);
         if (e.Key == OpenTK.Input.Key.BackSpace && quads.Count > 0)
         {
             RemoveText(cursor_index - 1, 1);
         }
         else
         {
             if (e.Key == OpenTK.Input.Key.Left && cursor_index != 0)
             {
                 cursor_index--; Apply();
             }
             else if (e.Key == OpenTK.Input.Key.Right && cursor_index != text.Length)
             {
                 cursor_index++; Apply();
             }
         }
     }
 }
Example #15
0
        private void OnKeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            float diff = 1.0f;

            if (e.Key == OpenTK.Input.Key.S)
            {
                cameraZ -= diff;
            }
            else if (e.Key == OpenTK.Input.Key.W)
            {
                cameraZ += diff;
            }
            else if (e.Key == OpenTK.Input.Key.A)
            {
                cameraX += diff;
            }
            else if (e.Key == OpenTK.Input.Key.D)
            {
                cameraX -= diff;
            }
            else if (e.Key == OpenTK.Input.Key.Q)
            {
                cameraY += diff;
            }
            else if (e.Key == OpenTK.Input.Key.E)
            {
                cameraY -= diff;
            }
            else if (e.Key == OpenTK.Input.Key.KeypadPlus)
            {
                fov += 10.0f;
            }
            else if (e.Key == OpenTK.Input.Key.KeypadMinus)
            {
                fov -= 10.0f;
            }
            Console.WriteLine("camera = {0}, fov = {1}", cameraZ, fov);
        }
        protected virtual void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.LShift)
            {
                _modifierKeys -= ModifierKeys.LShift;
            }
            if (e.Key == OpenTK.Input.Key.RShift)
            {
                _modifierKeys -= ModifierKeys.RShift;
            }
            if (e.Key == OpenTK.Input.Key.LControl)
            {
                _modifierKeys -= ModifierKeys.LControl;
            }
            if (e.Key == OpenTK.Input.Key.RControl)
            {
                _modifierKeys -= ModifierKeys.RControl;
            }
            if (e.Key == OpenTK.Input.Key.LAlt)
            {
                _modifierKeys -= ModifierKeys.LAlt;
            }
            if (e.Key == OpenTK.Input.Key.RAlt)
            {
                _modifierKeys -= ModifierKeys.RAlt;
            }

            if (FocusedElement != null && FocusedElement.ReceiveKeys)
            {
                FocusedElement.KeyUp(e, _modifierKeys);
            }

            if (Receiver != null && ShouldNotifyReceiver())
            {
                Receiver.KeyUp(e, _modifierKeys);
            }
        }
Example #17
0
 void CrowIDE_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     if (e.Key == OpenTK.Input.Key.Escape)
     {
         Quit(null, null);
         return;
     }
     else if (e.Key == OpenTK.Input.Key.F4)
     {
         loadWindow("#CrowIDE.ui.MemberView.crow");
     }
     else if (e.Key == OpenTK.Input.Key.F5)
     {
         loadWindow("#CrowIDE.ui.GTreeExplorer.crow");
     }
     else if (e.Key == OpenTK.Input.Key.F6)
     {
         loadWindow("#CrowIDE.ui.LQIsExplorer.crow");
     }
     else if (e.Key == OpenTK.Input.Key.F7)
     {
         loadWindow("#CrowIDE.ui.CSProjExplorer.crow");
     }
 }
 private void KeyboardDevice_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     KeyUp?.Invoke(this, new KeyEventArgs(KeyboardState.Empty, Keys.A, ' '));
 }
Example #19
0
 public abstract void KeyUp(OpenTK.Input.KeyboardKeyEventArgs e, WidgetController.ModifierKeys k);
Example #20
0
        private void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            KeyBoardEvent keyBoardEvent = new KeyBoardEvent(true, e.Key);

            OnEvent(this, keyBoardEvent);
        }
 public override void KeyUp(OpenTK.Input.KeyboardKeyEventArgs e, WidgetController.ModifierKeys k)
 {
 }
        void FrameTick(FrameEventArgs e)
        {
            //if ((DateTime.Now - lasttodo).TotalSeconds > BuildDelay && todo.Count > 0)
            UpdateTerrain();
            OnNewFrame(e.Time);
            UpdateMousePosition();
            if (guistate == GuiState.Normal)
            {
                UpdateMouseViewportControl(e);
            }
            NetworkProcess();
            if (guistate == GuiState.MapLoading) { return; }

            bool angleup = false;
            bool angledown = false;
            float overheadcameraanglemovearea = 0.05f;
            float overheadcameraspeed = 3;
            if (guistate == GuiState.Normal && d_MainWindow.Focused && cameratype == CameraType.Overhead)
            {
                if (mouse_current.X > Width - Width * overheadcameraanglemovearea)
                {
                    overheadcameraK.TurnLeft((float)e.Time * overheadcameraspeed);
                }
                if (mouse_current.X < Width * overheadcameraanglemovearea)
                {
                    overheadcameraK.TurnRight((float)e.Time * overheadcameraspeed);
                }
                if (mouse_current.Y < Height * overheadcameraanglemovearea)
                {
                    angledown = true;
                }
                if (mouse_current.Y > Height - Height * overheadcameraanglemovearea)
                {
                    angleup = true;
                }
            }
            bool wantsjump = GuiTyping == TypingState.None && Keyboard[GetKey(OpenTK.Input.Key.Space)];
            int movedx = 0;
            int movedy = 0;
            bool moveup = false;
            bool movedown = false;
            if (guistate == GuiState.Normal)
            {
                if (GuiTyping == TypingState.None)
                {
                    if (overheadcamera)
                    {
                        CameraMove m = new CameraMove();
                        if (Keyboard[GetKey(OpenTK.Input.Key.A)]) { overheadcameraK.TurnRight((float)e.Time * overheadcameraspeed); }
                        if (Keyboard[GetKey(OpenTK.Input.Key.D)]) { overheadcameraK.TurnLeft((float)e.Time * overheadcameraspeed); }
                        if (Keyboard[GetKey(OpenTK.Input.Key.W)]) { angleup = true; }
                        if (Keyboard[GetKey(OpenTK.Input.Key.S)]) { angledown = true; }
                        overheadcameraK.Center = player.playerposition;
                        m.Distance = overheadcameradistance;
                        m.AngleUp = angleup;
                        m.AngleDown = angledown;
                        overheadcameraK.Move(m, (float)e.Time);
                        if ((player.playerposition - playerdestination).Length >= 1f)
                        {
                            movedy += 1;
                            if (d_Physics.reachedwall)
                            {
                                wantsjump = true;
                            }
                            //player orientation
                            Vector3 q = playerdestination - player.playerposition;
                            float angle = VectorAngleGet(q);
                            player.playerorientation.Y = (float)Math.PI / 2 + angle;
                            player.playerorientation.X = (float)Math.PI;
                        }
                    }
                    else if (ENABLE_MOVE)
                    {
                        if (Keyboard[GetKey(OpenTK.Input.Key.W)]) { movedy += 1; }
                        if (Keyboard[GetKey(OpenTK.Input.Key.S)]) { movedy += -1; }
                        if (Keyboard[GetKey(OpenTK.Input.Key.A)]) { movedx += -1; }
                        if (Keyboard[GetKey(OpenTK.Input.Key.D)]) { movedx += 1; }
                    }
                }
                if (ENABLE_FREEMOVE || Swimming)
                {
                    if (GuiTyping == TypingState.None && Keyboard[GetKey(OpenTK.Input.Key.Space)])
                    {
                        moveup = true;
                    }
                    if (GuiTyping == TypingState.None && Keyboard[GetKey(OpenTK.Input.Key.ControlLeft)])
                    {
                        movedown = true;
                    }
                }
            }
            else if (guistate == GuiState.EscapeMenu)
            {
            }
            else if (guistate == GuiState.Inventory)
            {
            }
            else if (guistate == GuiState.MapLoading)
            {
                //todo back to game when escape key pressed.
            }
            else if (guistate == GuiState.CraftingRecipes)
            {
            }
            else throw new Exception();
            float movespeednow = MoveSpeedNow();
            Acceleration acceleration = new Acceleration();
            int? blockunderplayer = BlockUnderPlayer();
            {
                //slippery walk on ice and when swimming
                if ((blockunderplayer != null && d_Data.IsSlipperyWalk[blockunderplayer.Value]) || Swimming)
                {
                    acceleration = new Acceleration()
                    {
                        acceleration1 = 0.99f,
                        acceleration2 = 0.2f,
                        acceleration3 = 70,
                    };
                }
            }
            float jumpstartacceleration = 2.1f * d_Physics.gravity;
            if (blockunderplayer != null && blockunderplayer == d_Data.BlockIdTrampoline
                && (!player.isplayeronground))
            {
                wantsjump = true;
                jumpstartacceleration = 5f * d_Physics.gravity;
            }
            Vector3 push = new Vector3();
            foreach (var k in d_Clients.Players)
            {
                if ((k.Key == 255) ||
                    (k.Value.Position == LocalPlayerPosition)
                     || (float.IsNaN(LocalPlayerPosition.X)))
                {
                    continue;
                }
                if ((k.Value.Position - LocalPlayerPosition).Length < PlayerPushDistance)
                {
                    Vector3 diff = LocalPlayerPosition - k.Value.Position;
                    push += diff;
                }
            }
            var move = new CharacterPhysics.MoveInfo()
            {
                movedx = movedx,
                movedy = movedy,
                acceleration = acceleration,
                ENABLE_FREEMOVE = ENABLE_FREEMOVE,
                ENABLE_NOCLIP = ENABLE_NOCLIP,
                jumpstartacceleration = jumpstartacceleration,
                movespeednow = movespeednow,
                moveup = moveup,
                movedown = movedown,
                Swimming = Swimming,
                wantsjump = wantsjump,
            };
            bool soundnow;
            d_Physics.Move(player, move, e.Time, out soundnow, push);
            if (soundnow)
            {
                UpdateWalkSound(-1);
            }
            if (player.isplayeronground && movedx != 0 || movedy != 0)
            {
                UpdateWalkSound(e.Time);
            }
            UpdateBlockDamageToPlayer();
            UpdateFallDamageToPlayer();
            if (guistate == GuiState.CraftingRecipes)
            {
                CraftingMouse();
            }
            if (guistate == GuiState.EscapeMenu)
            {
                //EscapeMenuMouse();
            }
            if (guistate == GuiState.Normal)
            {
                UpdatePicking();
            }
            //must be here because frametick can be called more than once per render frame.
            keyevent = null;
            keyeventup = null;
        }
Example #23
0
 public override void OnKeyUp(OpenTK.Input.KeyboardKeyEventArgs key)
 {
     dm.OnKeyUp(key);
 }
Example #24
0
 private void Parent_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     Parent.CurrentMenu?.PerformKeyUp(e);
 }
Example #25
0
 KeyDownEventArgs(OpenTK.Input.KeyboardKeyEventArgs someKeyArgs)
 {
     this.KeyArgs = someKeyArgs;
 }
        void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == GetKey(OpenTK.Input.Key.F11))
            {
                if (d_MainWindow.WindowState == WindowState.Fullscreen)
                {
                    d_MainWindow.WindowState = WindowState.Normal;
                }
                else
                {
                    d_MainWindow.WindowState = WindowState.Fullscreen;
                }
            }
            if (GuiTyping == TypingState.None)
            {
                keyevent = e;
            }
            if (guistate == GuiState.Normal)
            {
                if (Keyboard[GetKey(OpenTK.Input.Key.Escape)])
                {
                    guistate = GuiState.EscapeMenu;
                    menustate = new MenuState();
                    FreeMouse = true;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.PageUp) && GuiTyping == TypingState.Typing)
                {
                    d_HudChat.ChatPageScroll++;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.PageDown) && GuiTyping == TypingState.Typing)
                {
                    d_HudChat.ChatPageScroll--;
                }
                d_HudChat.ChatPageScroll = MyMath.Clamp(d_HudChat.ChatPageScroll, 0, d_HudChat.ChatLines.Count / d_HudChat.ChatLinesMaxToDraw);
                if (e.Key == GetKey(OpenTK.Input.Key.Enter) || e.Key == GetKey(OpenTK.Input.Key.KeypadEnter))
                {
                    if (GuiTyping == TypingState.Typing)
                    {
                        typinglog.Add(d_HudChat.GuiTypingBuffer);
                        typinglogpos = typinglog.Count;
                        ClientCommand(d_HudChat.GuiTypingBuffer);

                        d_HudChat.GuiTypingBuffer = "";
                        d_HudChat.IsTyping = false;

                        GuiTyping = TypingState.None;
                    }
                    else if (GuiTyping == TypingState.None)
                    {
                        GuiTyping = TypingState.Typing;
                        d_HudChat.IsTyping = true;
                        d_HudChat.GuiTypingBuffer = "";
                    }
                    else if (GuiTyping == TypingState.Ready)
                    {
                        Console.WriteLine("Keyboard_KeyDown ready");
                    }
                    return;
                }
                if (GuiTyping == TypingState.Typing)
                {
                    var key = e.Key;
                    string c = "";
                    if (key == GetKey(OpenTK.Input.Key.BackSpace))
                    {
                        if (d_HudChat.GuiTypingBuffer.Length > 0)
                        {
                            d_HudChat.GuiTypingBuffer = d_HudChat.GuiTypingBuffer.Substring(0, d_HudChat.GuiTypingBuffer.Length - 1);
                        }
                        return;
                    }
                    if (Keyboard[GetKey(OpenTK.Input.Key.ControlLeft)] || Keyboard[GetKey(OpenTK.Input.Key.ControlRight)])
                    {
                        if (key == GetKey(OpenTK.Input.Key.V))
                        {
                            if (Clipboard.ContainsText())
                            {
                                d_HudChat.GuiTypingBuffer += Clipboard.GetText();
                            }
                            return;
                        }
                    }
                    if (key == GetKey(OpenTK.Input.Key.Up))
                    {
                        typinglogpos--;
                        if (typinglogpos < 0) { typinglogpos = 0; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            d_HudChat.GuiTypingBuffer = typinglog[typinglogpos];
                        }
                    }
                    if (key == GetKey(OpenTK.Input.Key.Down))
                    {
                        typinglogpos++;
                        if (typinglogpos > typinglog.Count) { typinglogpos = typinglog.Count; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            d_HudChat.GuiTypingBuffer = typinglog[typinglogpos];
                        }
                        if (typinglogpos == typinglog.Count)
                        {
                            d_HudChat.GuiTypingBuffer = "";
                        }
                    }
                    return;
                }
                string strFreemoveNotAllowed = "Freemove is not allowed on this server.";
                if (e.Key == GetKey(OpenTK.Input.Key.F1))
                {
                    if (!AllowFreemove)
                    {
                        Log(strFreemoveNotAllowed);
                        return;
                    }
                    movespeed = basemovespeed * 1;
                    Log("Move speed: 1x.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F2))
                {
                    if (!AllowFreemove)
                    {
                        Log(strFreemoveNotAllowed);
                        return;
                    }
                    movespeed = basemovespeed * 10;
                    Log("Move speed: 10x.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F3))
                {
                    if (!AllowFreemove)
                    {
                        Log(strFreemoveNotAllowed);
                        return;
                    }
                    player.movedz = 0;
                    if (!ENABLE_FREEMOVE)
                    {
                        ENABLE_FREEMOVE = true;
                        Log("Move: Free.");
                    }
                    else if (ENABLE_FREEMOVE && (!ENABLE_NOCLIP))
                    {
                        ENABLE_NOCLIP = true;
                        Log("Move: Free, Noclip.");
                    }
                    else if (ENABLE_FREEMOVE && ENABLE_NOCLIP)
                    {
                        ENABLE_FREEMOVE = false;
                        ENABLE_NOCLIP = false;
                        Log("Move: Normal.");
                    }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.I))
                {
                    drawblockinfo = !drawblockinfo;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F5))
                {
                    if (cameratype == CameraType.Fpp)
                    {
                        cameratype = CameraType.Tpp;
                        ENABLE_TPP_VIEW = true;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        cameratype = CameraType.Overhead;
                        overheadcamera = true;
                        FreeMouse = true;
                        ENABLE_TPP_VIEW = true;
                        playerdestination = player.playerposition;
                    }
                    else if (cameratype == CameraType.Overhead)
                    {
                        cameratype = CameraType.Fpp;
                        FreeMouse = false;
                        ENABLE_TPP_VIEW = false;
                        overheadcamera = false;
                    }
                    else throw new Exception();
                }
                if (e.Key == GetKey(OpenTK.Input.Key.Plus) || e.Key == GetKey(OpenTK.Input.Key.KeypadPlus))
                {
                    if (cameratype == CameraType.Overhead)
                    {
                        overheadcameradistance -= 1;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        tppcameradistance -= 1;
                    }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.Minus) || e.Key == GetKey(OpenTK.Input.Key.KeypadMinus))
                {
                    if (cameratype == CameraType.Overhead)
                    {
                        overheadcameradistance += 1;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        tppcameradistance += 1;
                    }
                }
                if (overheadcameradistance < TPP_CAMERA_DISTANCE_MIN) { overheadcameradistance = TPP_CAMERA_DISTANCE_MIN; }
                if (overheadcameradistance > TPP_CAMERA_DISTANCE_MAX) { overheadcameradistance = TPP_CAMERA_DISTANCE_MAX; }

                if (tppcameradistance < TPP_CAMERA_DISTANCE_MIN) { tppcameradistance = TPP_CAMERA_DISTANCE_MIN; }
                if (tppcameradistance > TPP_CAMERA_DISTANCE_MAX) { tppcameradistance = TPP_CAMERA_DISTANCE_MAX; }

                if (e.Key == GetKey(OpenTK.Input.Key.F6))
                {
                    RedrawAllBlocks();
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F7))
                {
                    if (ENABLE_DRAWFPSHISTORY)
                    {
                        ENABLE_DRAWFPS = ENABLE_DRAWFPSHISTORY = false;
                    }
                    else
                    {
                        ENABLE_DRAWFPS = ENABLE_DRAWFPSHISTORY = true;
                    }
                }
                if (e.Key == OpenTK.Input.Key.F8)
                {
                    ENABLE_LAG++;
                    ENABLE_LAG = ENABLE_LAG % 3;
                    d_MainWindow.VSync = (ENABLE_LAG == 1) ? VSyncMode.Off : VSyncMode.On;
                    if (ENABLE_LAG == 0) { Log("Frame rate: vsync."); }
                    if (ENABLE_LAG == 1) { Log("Frame rate: unlimited."); }
                    if (ENABLE_LAG == 2) { Log("Frame rate: lag simulation."); }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F12))
                {
                    d_Screenshot.SaveScreenshot();
                    screenshotflash = 5;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.E))
                {
                    if (currentAttackedBlock != null)
                    {
                        Vector3 pos = new Vector3(currentAttackedBlock.Value.x, currentAttackedBlock.Value.y, currentAttackedBlock.Value.z);
                        int blocktype = d_Map.GetBlock(currentAttackedBlock.Value.x, currentAttackedBlock.Value.y, currentAttackedBlock.Value.z);
                        if (IsUsableBlock(blocktype))
                        {
                            if (GameDataManicDigger.IsRailTile(blocktype))
                            {
                                player.playerposition.X = pos.X + .5f;
                                player.playerposition.Y = pos.Z + 1;
                                player.playerposition.Z = pos.Y + .5f;
                                ENABLE_FREEMOVE = false;
                            }
                            else
                            {
                                SendSetBlock(pos, BlockSetMode.Use, 0, ActiveMaterial);
                            }
                        }
                    }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.R))
                {
                    Respawn();
                    Log("Respawn.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.P))
                {
                    PlayerPositionSpawn = player.playerposition;
                    player.playerposition = new Vector3((int)player.playerposition.X + 0.5f, player.playerposition.Y, (int)player.playerposition.Z + 0.5f);
                    Log("Spawn position set.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F))
                {
                    ToggleFog();
                    Log("Fog distance: " + d_Config3d.viewdistance);
                    OnResize(new EventArgs());
                }
                if (e.Key == GetKey(OpenTK.Input.Key.B))
                {
                    guistate = GuiState.Inventory;
                    menustate = new MenuState();
                    FreeMouse = true;
                }
                HandleMaterialKeys(e);
                if (e.Key == GetKey(OpenTK.Input.Key.Escape))
                {
                    EscapeMenuStart();
                }
            }
            else if (guistate == GuiState.EscapeMenu)
            {
                EscapeMenuKeyDown(e);
                return;
            }
            else if (guistate == GuiState.Inventory)
            {
                if (e.Key == GetKey(OpenTK.Input.Key.B)
                    || e.Key == GetKey(OpenTK.Input.Key.Escape))
                {
                    GuiStateBackToGame();
                }
                return;
            }
            else if (guistate == GuiState.MapLoading)
            {
            }
            else if (guistate == GuiState.CraftingRecipes)
            {
                if (e.Key == GetKey(OpenTK.Input.Key.Escape))
                {
                    GuiStateBackToGame();
                }
            }
            else throw new Exception();
        }
 public virtual void KeyUp(OpenTK.Input.KeyboardKeyEventArgs e, InputController.ModifierKeys k)
 {
 }
Example #28
0
 public virtual void OnKeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
 }
 private void device_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     this.repeatCounter++;
 }
 private void window_KeyUp(object sender, TKKeyboardKeyEventArgs e)
 {
     this.keyStateBuffer = e.Keyboard;
 }
 void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     if (e.Key == OpenTK.Input.Key.F11)
     {
         if (WindowState == WindowState.Fullscreen)
         {
             WindowState = WindowState.Normal;
         }
         else
         {
             WindowState = WindowState.Fullscreen;
         }
     }
     if (GuiTyping == TypingState.None)
     {
         keyevent = e;
     }
     if (guistate == GuiState.Normal)
     {
         if (Keyboard[OpenTK.Input.Key.Escape])
         {
             guistate = GuiState.EscapeMenu;
             menustate = new MenuState();
             FreeMouse = true;
         }
         if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
         {
             if (GuiTyping == TypingState.Typing)
             {
                 typinglog.Add(GuiTypingBuffer);
                 typinglogpos = typinglog.Count;
                 ClientCommand(GuiTypingBuffer);
                 GuiTypingBuffer = "";
                 GuiTyping = TypingState.None;
             }
             else if (GuiTyping == TypingState.None)
             {
                 GuiTyping = TypingState.Typing;
                 GuiTypingBuffer = "";
             }
             else if (GuiTyping == TypingState.Ready)
             {
                 Console.WriteLine("Keyboard_KeyDown ready");
             }
             return;
         }
         if (GuiTyping == TypingState.Typing)
         {
             var key = e.Key;
             string c = "";
             if (key == OpenTK.Input.Key.BackSpace)
             {
                 if (GuiTypingBuffer.Length > 0)
                 {
                     GuiTypingBuffer = GuiTypingBuffer.Substring(0, GuiTypingBuffer.Length - 1);
                 }
                 return;
             }
             if (Keyboard[OpenTK.Input.Key.ControlLeft] || Keyboard[OpenTK.Input.Key.ControlRight])
             {
                 if (key == OpenTK.Input.Key.V)
                 {
                     if (Clipboard.ContainsText())
                     {
                         GuiTypingBuffer += Clipboard.GetText();
                     }
                     return;
                 }
             }
             if (key == OpenTK.Input.Key.Up)
             {
                 typinglogpos--;
                 if (typinglogpos < 0) { typinglogpos = 0; }
                 if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                 {
                     GuiTypingBuffer = typinglog[typinglogpos];
                 }
             }
             if (key == OpenTK.Input.Key.Down)
             {
                 typinglogpos++;
                 if (typinglogpos > typinglog.Count) { typinglogpos = typinglog.Count; }
                 if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                 {
                     GuiTypingBuffer = typinglog[typinglogpos];
                 }
                 if (typinglogpos == typinglog.Count)
                 {
                     GuiTypingBuffer = "";
                 }
             }
             return;
         }
         if (e.Key == OpenTK.Input.Key.F1)
         {
             movespeed = basemovespeed * 1;
             Log("Move speed: 1x.");
         }
         if (e.Key == OpenTK.Input.Key.F2)
         {
             movespeed = basemovespeed * 10;
             Log("Move speed: 10x.");
         }
         if (e.Key == OpenTK.Input.Key.F9)
         {
             string defaultserverfile = "defaultserver.txt";
             if (File.Exists(defaultserverfile))
             {
                 ConnectToInternetGame(username, pass, File.ReadAllText(defaultserverfile));
                 Log("Connected to default server.");
             }
             else
             {
                 Log(string.Format("File {0} not found.", defaultserverfile));
             }
         }
         if (e.Key == OpenTK.Input.Key.F3)
         {
             ENABLE_FREEMOVE = !ENABLE_FREEMOVE;
             if (ENABLE_FREEMOVE) { Log("Freemove enabled."); }
             else { Log("Freemove disabled."); }
         }
         if (e.Key == OpenTK.Input.Key.F4)
         {
             ENABLE_NOCLIP = !ENABLE_NOCLIP;
             if (ENABLE_NOCLIP) { Log("Noclip enabled."); }
             else { Log("Noclip disabled."); }
         }
         if (e.Key == OpenTK.Input.Key.I)
         {
             drawblockinfo = !drawblockinfo;
         }
         if (e.Key == OpenTK.Input.Key.F5)
         {
             if (cameratype == CameraType.Fpp)
             {
                 cameratype = CameraType.Tpp;
                 ENABLE_TPP_VIEW = true;
             }
             else if (cameratype == CameraType.Tpp)
             {
                 cameratype = CameraType.Overhead;
                 overheadcamera = true;
                 ENABLE_TPP_VIEW = true;
                 playerdestination = player.playerposition;
             }
             else if (cameratype == CameraType.Overhead)
             {
                 cameratype = CameraType.Fpp;
                 ENABLE_TPP_VIEW = false;
                 overheadcamera = false;
             }
             else throw new Exception();
         }
         if (e.Key == OpenTK.Input.Key.F12)
         {
             using (Bitmap bmp = GrabScreenshot())
             {
                 string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                 string time = string.Format("{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now);
                 string filename = Path.Combine(path, time + ".png");
                 bmp.Save(filename);
                 screenshotflash = 5;
             }
         }
         if (e.Key == OpenTK.Input.Key.R)
         {
             player.playerposition = game.PlayerPositionSpawn;
             player.movedz = 0;
             Log("Respawn.");
         }
         if (e.Key == OpenTK.Input.Key.P)
         {
             game.PlayerPositionSpawn = player.playerposition;
             player.playerposition = new Vector3((int)player.playerposition.X + 0.5f, player.playerposition.Y, (int)player.playerposition.Z + 0.5f);
             Log("Spawn position set.");
         }
         if (e.Key == OpenTK.Input.Key.F)
         {
             if (terrain.DrawDistance == 64) { terrain.DrawDistance = 128; }
             else if (terrain.DrawDistance == 128) { terrain.DrawDistance = 256; }
             else if (terrain.DrawDistance == 256) { terrain.DrawDistance = 512; }
             else if (terrain.DrawDistance == 512) { terrain.DrawDistance = 64; }
             else { terrain.DrawDistance = 64; }
             Log("Fog distance: " + terrain.DrawDistance);
         }
         if (e.Key == OpenTK.Input.Key.B)
         {
             //EscapeMenuWasFreemove = ENABLE_FREEMOVE;
             guistate = GuiState.Inventory;
             menustate = new MenuState();
             FreeMouse = true;
         }
         HandleMaterialKeys(e);
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             GuiStateEscapeMenu();
         }
     }
     else if (guistate == GuiState.EscapeMenu)
     {
         int menuelements = 3;
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             escapemenuOptions = false;
             GuiStateBackToGame();
         }
         if (e.Key == OpenTK.Input.Key.Up)
         {
             menustate.selected--;
             menustate.selected = Math.Max(0, menustate.selected);
         }
         if (e.Key == OpenTK.Input.Key.Down)
         {
             menustate.selected++;
             menustate.selected = Math.Min(menuelements - 1, menustate.selected);
         }
         if (menustate.selected != -1
             && (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter))
         {
             EscapeMenuAction();
         }
         return;
     }
     else if (guistate == GuiState.MainMenu)
     {
         int menuelements = 3;
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             exit = true;
             Exit();
         }
         if (e.Key == OpenTK.Input.Key.Up)
         {
             menustate.selected--;
             menustate.selected = Math.Max(0, menustate.selected);
         }
         if (e.Key == OpenTK.Input.Key.Down)
         {
             menustate.selected++;
             menustate.selected = Math.Min(menuelements - 1, menustate.selected);
         }
         if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
         {
             MainMenuAction();
         }
         return;
     }
     else if (guistate == GuiState.Inventory)
     {
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             GuiStateBackToGame();
         }
         Direction4? dir = null;
         if (e.Key == OpenTK.Input.Key.Left) { dir = Direction4.Left; }
         if (e.Key == OpenTK.Input.Key.Right) { dir = Direction4.Right; }
         if (e.Key == OpenTK.Input.Key.Up) { dir = Direction4.Up; }
         if (e.Key == OpenTK.Input.Key.Down) { dir = Direction4.Down; }
         if (dir != null)
         {
             InventorySelectionMove(dir.Value);
         }
         if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
         {
             var sel = InventoryGetSelected();
             if (sel != null)
             {
                 materialSlots[activematerial] = sel.Value;
                 GuiStateBackToGame();
             }
         }
         HandleMaterialKeys(e);
         return;
     }
     else if (guistate == GuiState.MapLoading)
     {
     }
     else if (guistate == GuiState.CraftingRecipes)
     {
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             GuiStateBackToGame();
         }
     }
     else throw new Exception();
 }
        private void KeyboardDevice_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            var key = OpenTKHelpers.KeyToKeys(e.Key);

            KeyDown?.Invoke(this, new KeyEventArgs(KeyboardState.Empty, key, ' '));
        }
        void FrameTick(FrameEventArgs e)
        {
            //if ((DateTime.Now - lasttodo).TotalSeconds > BuildDelay && todo.Count > 0)
            game.OnNewFrame(e.Time);
            while (todo.Count > 0)
            {
                lasttodo = DateTime.Now;
                var task = todo.Dequeue();
                task();
            }
            lock (frametickmainthreadtodo)
            {
                for (int i = 0; i < frametickmainthreadtodo.Count; i++)
                {
                    frametickmainthreadtodo[i].Invoke();
                }
                frametickmainthreadtodo.Clear();
            }
            network.Process();
            if (newnetwork != null)
            {
                newnetwork.Process();
            }
            UpdateMousePosition();

            bool angleup = false;
            bool angledown = false;
            float overheadcameraanglemovearea = 0.05f;
            float overheadcameraspeed = 3;
            if (guistate == GuiState.Normal && Focused && cameratype == CameraType.Overhead)
            {
                if (mouse_current.X > Width - Width * overheadcameraanglemovearea)
                {
                    overheadcameraK.TurnLeft((float)e.Time * overheadcameraspeed);
                }
                if (mouse_current.X < Width * overheadcameraanglemovearea)
                {
                    overheadcameraK.TurnRight((float)e.Time * overheadcameraspeed);
                }
                if (mouse_current.Y < Height * overheadcameraanglemovearea)
                {
                    angledown = true;
                }
                if (mouse_current.Y > Height - Height * overheadcameraanglemovearea)
                {
                    angleup = true;
                }
            }
            bool wantsjump = GuiTyping == TypingState.None && Keyboard[OpenTK.Input.Key.Space];
            int movedx = 0;
            int movedy = 0;
            bool moveup = false;
            if (guistate == GuiState.Normal)
            {
                if (GuiTyping == TypingState.None)
                {
                    if (overheadcamera)
                    {
                        CameraMove m = new CameraMove();
                        if (Keyboard[OpenTK.Input.Key.A]) { overheadcameraK.TurnRight((float)e.Time * overheadcameraspeed); }
                        if (Keyboard[OpenTK.Input.Key.D]) { overheadcameraK.TurnLeft((float)e.Time * overheadcameraspeed); }
                        if (Keyboard[OpenTK.Input.Key.W]) { angleup = true; }
                        if (Keyboard[OpenTK.Input.Key.S]) { angledown = true; }
                        overheadcameraK.Center = player.playerposition;
                        m.Distance = overheadcameradistance;
                        m.AngleUp = angleup;
                        m.AngleDown = angledown;
                        overheadcameraK.Move(m, (float)e.Time);
                        if ((player.playerposition - playerdestination).Length >= 1f)
                        {
                            movedy += 1;
                            if (physics.reachedwall)
                            {
                                wantsjump = true;
                            }
                            //player orientation
                            Vector3 q = playerdestination - player.playerposition;
                            float angle = VectorAngleGet(q);
                            player.playerorientation.Y = (float)Math.PI / 2 + angle;
                            player.playerorientation.X = (float)Math.PI;
                        }
                    }
                    else if (ENABLE_MOVE)
                    {
                        if (Keyboard[OpenTK.Input.Key.W]) { movedy += 1; }
                        if (Keyboard[OpenTK.Input.Key.S]) { movedy += -1; }
                        if (Keyboard[OpenTK.Input.Key.A]) { movedx += -1; }
                        if (Keyboard[OpenTK.Input.Key.D]) { movedx += 1; }
                    }
                }
                if (ENABLE_FREEMOVE || Swimming)
                {
                    if (GuiTyping == TypingState.None && Keyboard[OpenTK.Input.Key.Space])
                    {
                        moveup = true;
                    }
                }
            }
            else if (guistate == GuiState.EscapeMenu)
            {
            }
            else if (guistate == GuiState.MainMenu)
            {
            }
            else if (guistate == GuiState.Inventory)
            {
            }
            else if (guistate == GuiState.MapLoading)
            {
                //todo back to game when escape key pressed.
            }
            else if (guistate == GuiState.CraftingRecipes)
            {
            }
            else throw new Exception();
            float movespeednow = MoveSpeedNow();
            Acceleration acceleration = new Acceleration();
            int? blockunderplayer = BlockUnderPlayer();
            {
                //slippery walk on ice and when swimming
                if ((blockunderplayer != null && data.IsSlipperyWalk(blockunderplayer.Value)) || Swimming)
                {
                    acceleration = new Acceleration()
                    {
                        acceleration1 = 0.99f,
                        acceleration2 = 0.2f,
                        acceleration3 = 70,
                    };
                }
            }
            float jumpstartacceleration = 2.1f * physics.gravity;
            if (blockunderplayer != null && blockunderplayer == data.TileIdTrampoline
                && (!player.isplayeronground))
            {
                wantsjump = true;
                jumpstartacceleration = 5f * physics.gravity;
            }
            var move = new CharacterPhysics.MoveInfo()
            {
                movedx = movedx,
                movedy = movedy,
                acceleration = acceleration,
                ENABLE_FREEMOVE = ENABLE_FREEMOVE,
                ENABLE_NOCLIP = ENABLE_NOCLIP,
                jumpstartacceleration = jumpstartacceleration,
                movespeednow = movespeednow,
                moveup = moveup,
                Swimming = Swimming,
                wantsjump = wantsjump,
            };
            bool soundnow;
            physics.Move(player, move, e.Time, out soundnow);
            if (soundnow)
            {
                UpdateWalkSound(-1);
            }
            if (player.isplayeronground && movedx != 0 || movedy != 0)
            {
                UpdateWalkSound(e.Time);
            }
            if (guistate == GuiState.Inventory)
            {
                InventoryMouse();
            }
            if (guistate == GuiState.CraftingRecipes)
            {
                CraftingMouse();
            }
            if (guistate == GuiState.EscapeMenu)
            {
                EscapeMenuMouse();
            }
            if (guistate == GuiState.Normal)
            {
                UpdateMouseViewportControl(e);
            }
            //must be here because frametick can be called more than once per render frame.
            keyevent = null;
            keyeventup = null;
        }
Example #34
0
        private KeyboardEventArgs ConvertKeyboardEvents(TkKeyArgs args)
        {
            switch (args.Key)
            {
            case TkKey.F1: return(new KeyboardEventArgs(Key.F1, _keyModifier));

            case TkKey.F2: return(new KeyboardEventArgs(Key.F2, _keyModifier));

            case TkKey.F3: return(new KeyboardEventArgs(Key.F3, _keyModifier));

            case TkKey.F4: return(new KeyboardEventArgs(Key.F4, _keyModifier));

            case TkKey.F5: return(new KeyboardEventArgs(Key.F5, _keyModifier));

            case TkKey.F6: return(new KeyboardEventArgs(Key.F6, _keyModifier));

            case TkKey.F7: return(new KeyboardEventArgs(Key.F7, _keyModifier));

            case TkKey.F8: return(new KeyboardEventArgs(Key.F8, _keyModifier));

            case TkKey.F9: return(new KeyboardEventArgs(Key.F9, _keyModifier));

            case TkKey.F10: return(new KeyboardEventArgs(Key.F10, _keyModifier));

            case TkKey.F11: return(new KeyboardEventArgs(Key.F11, _keyModifier));

            case TkKey.F12: return(new KeyboardEventArgs(Key.F12, _keyModifier));

            case TkKey.Keypad0: return(new KeyboardEventArgs(Key.NumPad0, _keyModifier));

            case TkKey.Keypad1: return(new KeyboardEventArgs(Key.NumPad1, _keyModifier));

            case TkKey.Keypad2: return(new KeyboardEventArgs(Key.NumPad2, _keyModifier));

            case TkKey.Keypad3: return(new KeyboardEventArgs(Key.NumPad3, _keyModifier));

            case TkKey.Keypad4: return(new KeyboardEventArgs(Key.NumPad4, _keyModifier));

            case TkKey.Keypad5: return(new KeyboardEventArgs(Key.NumPad5, _keyModifier));

            case TkKey.Keypad6: return(new KeyboardEventArgs(Key.NumPad6, _keyModifier));

            case TkKey.Keypad7: return(new KeyboardEventArgs(Key.NumPad7, _keyModifier));

            case TkKey.Keypad8: return(new KeyboardEventArgs(Key.NumPad8, _keyModifier));

            case TkKey.Keypad9: return(new KeyboardEventArgs(Key.NumPad9, _keyModifier));

            case TkKey.Up: return(new KeyboardEventArgs(Key.Up, _keyModifier));

            case TkKey.Left: return(new KeyboardEventArgs(Key.Left, _keyModifier));

            case TkKey.Right: return(new KeyboardEventArgs(Key.Right, _keyModifier));

            case TkKey.Down: return(new KeyboardEventArgs(Key.Down, _keyModifier));

            case TkKey.Unknown:                     // Somehow, the keypad enter key registers as Unknown on some systems
            case TkKey.KeypadEnter:
            case TkKey.Enter: return(new KeyboardEventArgs(Key.Enter, _keyModifier));

            case TkKey.Space: return(new KeyboardEventArgs(Key.Space, _keyModifier));

            case TkKey.Escape: return(new KeyboardEventArgs(Key.Escape, _keyModifier));

            case TkKey.Delete: return(new KeyboardEventArgs(Key.Delete, _keyModifier));

            case TkKey.Home: return(new KeyboardEventArgs(Key.Home, _keyModifier));

            case TkKey.End: return(new KeyboardEventArgs(Key.End, _keyModifier));

            case TkKey.Back: return(new KeyboardEventArgs(Key.Backspace, _keyModifier));

            case TkKey.KeypadPlus:
            case TkKey.Plus: return(new KeyboardEventArgs(Key.Plus, _keyModifier));

            case TkKey.KeypadMinus:
            case TkKey.Minus: return(new KeyboardEventArgs(Key.Minus, _keyModifier));

            case TkKey.Number0: return(new KeyboardEventArgs('0', _keyModifier));

            case TkKey.Number1: return(new KeyboardEventArgs('1', _keyModifier));

            case TkKey.Number2: return(new KeyboardEventArgs('2', _keyModifier));

            case TkKey.Number3: return(new KeyboardEventArgs('3', _keyModifier));

            case TkKey.Number4: return(new KeyboardEventArgs('4', _keyModifier));

            case TkKey.Number5: return(new KeyboardEventArgs('5', _keyModifier));

            case TkKey.Number6: return(new KeyboardEventArgs('6', _keyModifier));

            case TkKey.Number7: return(new KeyboardEventArgs('7', _keyModifier));

            case TkKey.Number8: return(new KeyboardEventArgs('8', _keyModifier));

            case TkKey.Number9: return(new KeyboardEventArgs('9', _keyModifier));

            case TkKey.KeypadDivide:
            case TkKey.Slash: return(new KeyboardEventArgs(Key.Slash, _keyModifier));
            }

            return(null);
        }
 void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     if (GuiTyping == TypingState.None)
     {
         keyeventup = e;
     }
 }
Example #36
0
        void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.F10)
            {
                if (!SkySphereNight)
                {
                    SkySphereNight = true;
                    return;
                }
                else
                {
                    SkySphereNight = false;
                    return;
                }
            }
            if (e.Key == OpenTK.Input.Key.F11)
            {
                if (WindowState == WindowState.Fullscreen)
                {
                    WindowState = WindowState.Normal;
                }
                else
                {
                    WindowState = WindowState.Fullscreen;
                }
            }
            if (GuiTyping == TypingState.None)
            {
                keyevent = e;
            }
            if (Keyboard[OpenTK.Input.Key.PageUp] && GuiTyping == TypingState.Typing)
            {
                ChatPageScroll++;
            }
            if (Keyboard[OpenTK.Input.Key.PageDown] && GuiTyping == TypingState.Typing)
            {
                if(ChatPageScroll > 0)
                ChatPageScroll--;
            }
            if (Keyboard[OpenTK.Input.Key.KeypadMinus])
            {
                if (ChatFontSize > 6)
                {
                    ChatFontSize--;
                    fn = new Font(ff, ChatFontSize, FontStyle.Bold);
                }
            }
            if (Keyboard[OpenTK.Input.Key.KeypadPlus])
            {
                if (ChatFontSize < 25)
                {
                    ChatFontSize++;
                    fn = new Font(ff, ChatFontSize, FontStyle.Bold);
                }
            }
            if (guistate == GuiState.Normal)
            {

                if (Keyboard[OpenTK.Input.Key.Escape])
                {
                    if (GuiTyping == TypingState.Typing)
                    {
                        GuiTyping = TypingState.None;
                        GuiStateBackToGame();
                        return;
                    }
                    guistate = GuiState.EscapeMenu;
                    menustate = new MenuState();
                    FreeMouse = true;
                }

                if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
                {
                    if (GuiTyping == TypingState.Typing)
                    {
                        if (!Disconnected)
                        {
                            typinglog.Add(GuiTypingBuffer);
                            typinglogpos = typinglog.Count;
                            ClientCommand(GuiTypingBuffer);
                            GuiTypingBuffer = "";
                            FreeMouse = false;
                        }
                        GuiTyping = TypingState.None;
                    }
                    else if (GuiTyping == TypingState.None)
                    {
                        GuiTyping = TypingState.Typing;
                    }
                    else if (GuiTyping == TypingState.Ready)
                    {
                        Console.WriteLine("Keyboard_KeyDown ready");
                    }
                    return;
                }
                if (GuiTyping == TypingState.Typing)
                {
                    if (Disconnected) return;
                    var key = e.Key;
                    if (key == OpenTK.Input.Key.BackSpace)
                    {
                        if (GuiTypingBuffer.Length > 0)
                        {
                            GuiTypingBuffer = GuiTypingBuffer.Substring(0, GuiTypingBuffer.Length - 1);
                        }
                        return;
                    }
                    if (Keyboard[OpenTK.Input.Key.ControlLeft] || Keyboard[OpenTK.Input.Key.ControlRight])
                    {
                        if (key == OpenTK.Input.Key.V)
                        {
                            if (Clipboard.ContainsText())
                            {
                                GuiTypingBuffer += Clipboard.GetText();
                            }
                            return;
                        }
                    }
                    if (key == OpenTK.Input.Key.Up)
                    {
                        typinglogpos--;
                        if (typinglogpos < 0) { typinglogpos = 0; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            GuiTypingBuffer = typinglog[typinglogpos];
                        }
                    }
                    if (key == OpenTK.Input.Key.Down)
                    {
                        typinglogpos++;
                        if (typinglogpos > typinglog.Count) { typinglogpos = typinglog.Count; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            GuiTypingBuffer = typinglog[typinglogpos];
                        }
                        if (typinglogpos == typinglog.Count)
                        {
                            GuiTypingBuffer = "";
                        }
                    }
                    return;
                }
                if (e.Key == OpenTK.Input.Key.F9)
                {
                    string defaultserverfile = "defaultserver.txt";
                    if (File.Exists(defaultserverfile))
                    {
                        string Text = File.ReadAllText(defaultserverfile);
                        if (Text == null || !Text.StartsWith("http://"))
                        {
                            Log("Invalid server url in defaultserver.txt.");
                            return;
                        }
                        LoadPassword();
                        ConnectToInternetGame(username, pass, Text);
                        Log("Connected to default server.");
                    }
                    else
                    {
                        Log(string.Format("File {0} not found.", defaultserverfile));
                        File.Create("defaultserver.txt");
                        Log(string.Format("Created file {0}, you can add your favorite server url in it!", defaultserverfile));
                    }
                }
                if (e.Key == OpenTK.Input.Key.Z)
                {
                    player.movedz = 0;
                    ENABLE_FREEMOVE = !ENABLE_FREEMOVE;
                }

                if (e.Key == OpenTK.Input.Key.F4)
                {
                    ENABLE_NOCLIP = !ENABLE_NOCLIP;
                }
                if (e.Key == OpenTK.Input.Key.F1)
                {
                    drawblockinfo = !drawblockinfo;
                }
                if (e.Key == OpenTK.Input.Key.F5)
                {
                    if (cameratype == CameraType.Fpp)
                    {
                        cameratype = CameraType.Tpp;
                        ENABLE_TPP_VIEW = true;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        cameratype = CameraType.Overhead;
                        overheadcamera = true;
                        ENABLE_TPP_VIEW = true;
                        playerdestination = player.playerposition;
                    }
                    else if (cameratype == CameraType.Overhead)
                    {
                        cameratype = CameraType.Fpp;
                        ENABLE_TPP_VIEW = false;
                        overheadcamera = false;
                    }
                    else throw new Exception();
                }
                if (e.Key == OpenTK.Input.Key.F12)
                {
                    using (Bitmap bmp = GrabScreenshot())
                    {
                        string path = "Screenshots";
                        string time = string.Format("{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now);
                        string filename = Path.Combine(path, time + ".jpg");
                        bmp.Save(filename, ImageFormat.Jpeg);
                        screenshotflash = 5;
                        Log("Screenshot saved to the Screenshots folder");
                    }
                }
                if (e.Key == OpenTK.Input.Key.R)
                {
                    player.playerposition = game.PlayerPositionSpawn;
                    player.movedz = 0;
                }
                if (e.Key == OpenTK.Input.Key.P)
                {
                    game.PlayerPositionSpawn = player.playerposition;
                    player.playerposition = new Vector3((int)player.playerposition.X + 0.5f, player.playerposition.Y, (int)player.playerposition.Z + 0.5f);
                }
                if (e.Key == OpenTK.Input.Key.F)
                {
                    int[] drawDistances = { 32, 64, 128, 256, 512 };
                    for (int i = 0; i < drawDistances.Length; i++)
                    {
                        if (the3d.config3d.viewdistance == drawDistances[i])
                        {
                            the3d.config3d.viewdistance = drawDistances[(i + 1) % drawDistances.Length];
                            goto done;
                        }
                    }
                    the3d.config3d.viewdistance = drawDistances[0];
                done:
                    OnResize(new EventArgs());
                 }
                if (e.Key == OpenTK.Input.Key.B)
                {
                    //EscapeMenuWasFreemove = ENABLE_FREEMOVE;
                    guistate = GuiState.Inventory;
                    menustate = new MenuState();
                    FreeMouse = true;
                }
                HandleMaterialKeys(e);
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    GuiStateEscapeMenu();
                }
            }
            else if (guistate == GuiState.EscapeMenu)
            {
                int menuelements = 3;
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    escapemenuOptions = false;
                    GuiStateBackToGame();
                }
                if (e.Key == OpenTK.Input.Key.Up)
                {
                    menustate.selected--;
                    menustate.selected = Math.Max(0, menustate.selected);
                }
                if (e.Key == OpenTK.Input.Key.Down)
                {
                    menustate.selected++;
                    menustate.selected = Math.Min(menuelements - 1, menustate.selected);
                }
                if (menustate.selected != -1
                    && (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter))
                {
                    EscapeMenuAction();
                }
                return;
            }
            else if (guistate == GuiState.MainMenu)
            {
                int menuelements = 3;
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    exit = true;
                    Exit();
                }
                if (e.Key == OpenTK.Input.Key.Up)
                {
                    menustate.selected--;
                    menustate.selected = Math.Max(0, menustate.selected);
                }
                if (e.Key == OpenTK.Input.Key.Down)
                {
                    menustate.selected++;
                    menustate.selected = Math.Min(menuelements - 1, menustate.selected);
                }
                if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
                {
                    MainMenuAction();
                }
                return;
            }
            else if (guistate == GuiState.Inventory)
            {
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    GuiStateBackToGame();
                }
                Direction4? dir = null;
                if (e.Key == OpenTK.Input.Key.Left) { dir = Direction4.Left; }
                if (e.Key == OpenTK.Input.Key.Right) { dir = Direction4.Right; }
                if (e.Key == OpenTK.Input.Key.Up) { dir = Direction4.Up; }
                if (e.Key == OpenTK.Input.Key.Down) { dir = Direction4.Down; }
                if (dir != null)
                {
                    InventorySelectionMove(dir.Value);
                }
                if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
                {
                    var sel = InventoryGetSelected();
                    if (sel != null)
                    {
                        materialSlots[activematerial] = sel.Value;
                        GuiStateBackToGame();
                    }
                }
                HandleMaterialKeys(e);
                return;
            }
            else if (guistate == GuiState.MapLoading)
            {
                DrawMapLoading();
            }
            else if (guistate == GuiState.CraftingRecipes)
            {
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    GuiStateBackToGame();
                }
            }
            else throw new Exception();
        }