Exemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            MSAABuffer = new MsaaFbo();
            Canvas     = GameCanvas.CreateCanvas(this);
            _input     = new Gwen.Input.OpenTK(this);
            _input.Initialize(Canvas);
            Canvas.ShouldDrawBackground = false;
            InitControls();
            Models.LoadModels();

            AddCursor("pencil", GameResources.pencil_icon, 3, 28);
            AddCursor("line", GameResources.line_cursor, 5, 5);
            AddCursor("eraser", GameResources.eraser_cursor, 5, 5);
            AddCursor("hand", GameResources.move_icon, 16, 16);
            AddCursor("closed_hand", GameResources.closed_move_icon, 16, 16);
            AddCursor("adjustline", GameResources.cursor_adjustline, 0, 0);
            Canvas.UpdateSaveNodes();
        }
Exemplo n.º 2
0
        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (linerider.TrackFiles.TrackRecorder.Recording)
            {
                return;
            }
            var openwindows = Canvas.GetOpenWindows();

            if (openwindows != null && openwindows.Count >= 1)
            {
                if (e.Key == Key.Escape)
                {
                    foreach (var v in openwindows)
                    {
                        ((WindowControl)v).Close();
                        Invalidate();
                    }
                    return;
                }
            }
            if (_input.ProcessKeyDown(e) || Canvas.IsModalOpen)
            {
                return;
            }
            if (_dragRider || OpenTK.Input.Mouse.GetState().IsButtonDown(MouseButton.Left))
            {
                if (!_handToolOverride && (!Track.Animating || (Track.Animating && Track.Paused)) &&
                    SelectedTool != null)
                {
                    if (SelectedTool.OnKeyDown(e.Key))
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            var input = e.Keyboard;

            #region CTRL+

            if (input.IsKeyDown(Key.ControlLeft) || input.IsKeyDown(Key.ControlRight))
            {
                if (e.Key == Key.Z)
                {
                    SelectedTool?.Stop(); //BUGFIX SLAGwell removal.
                    var u = Track.UndoManager.Undo();
                    Invalidate();
                    if (u)
                    {
                        Track.TrackUpdated();
                    }
                    return;
                }
                if (e.Key == Key.Y)
                {
                    SelectedTool?.Stop();
                    var r = Track.UndoManager.Redo();
                    Invalidate();
                    if (r)
                    {
                        Track.TrackUpdated();
                    }
                    return;
                }
                if (e.Key == Key.S)
                {
                    Canvas.ShowSaveWindow();
                    return;
                }
                if (e.Key == Key.O)
                {
                    SettingOnionSkinning = !SettingOnionSkinning;
                    Invalidate();
                    return;
                }
                if (e.Key == Key.P)
                {
                    Canvas.ShowPreferences();
                    return;
                }
            }
            #endregion
            #region ALT+

            else if (input.IsKeyDown(Key.AltLeft) || input.IsKeyDown(Key.AltRight))
            {
                if (input.IsKeyDown(Key.Y))
                {
                    Track.Start(true);
                    return;
                }
                if (SelectedTool == _lineadjusttool)
                {
                    Invalidate();
                }
                if (input.IsKeyDown(Key.Enter))
                {
                    if (WindowBorder == WindowBorder.Resizable)
                    {
                        WindowBorder = WindowBorder.Hidden;
                        X            = 0;
                        Y            = 0;
                        var area = Screen.PrimaryScreen.Bounds;
                        RenderSize = area.Size;
                    }
                    else
                    {
                        WindowBorder = WindowBorder.Resizable;
                    }
                    return;
                }
            }

            #endregion

            if (input.IsKeyDown(Key.ShiftLeft) || input.IsKeyDown(Key.ShiftRight))
            {
                if (input.IsKeyDown(Key.Y))
                {
                    Track.Start(false, true, false);
                    Scheduler.UpdatesPerSecond = SettingSlowmoSpeed;
                    UpdateSongPosition(Track.CurrentFrame / 40f);
                    return;
                }
                if (input.IsKeyDown(Key.I))
                {
                    Track.Start(true, true, true, true);
                    return;
                }

                if (Track.Animating && Track.Paused && Track.Frame != 0)
                {
                    if (input.IsKeyDown(Key.Right))
                    {
                        if (IterationsOffset < 6)
                        {
                            IterationsOffset++;
                            SetIteration(IterationsOffset, true);
                        }
                        else
                        {
                            Track.NextFrame();
                            Invalidate();
                            SetIteration(0, true);
                            Track.Camera.AimPosition = Track.CameraAroundRider(Track.RiderState);
                            Track.Camera.UpdateCamera();
                        }
                        return;
                    }
                    if (input.IsKeyDown(Key.Left))
                    {
                        if (IterationsOffset > 0)
                        {
                            IterationsOffset--;
                            SetIteration(IterationsOffset, true);
                        }
                        else
                        {
                            Track.PreviousFrame();
                            Invalidate();
                            SetIteration(6, true);
                            Track.Camera.AimPosition = Track.CameraAroundRider(Track.RiderState);
                            Track.Camera.UpdateCamera();
                        }
                        return;
                    }
                }
            }
            if (e.Key == Key.Q)
            {
                SetTool(Tools.PencilTool);
            }
            else if (e.Key == Key.W)
            {
                SetTool(Tools.LineTool);
            }
            else if (e.Key == Key.E)
            {
                SetTool(Tools.EraserTool);
            }
            else if (e.Key == Key.R)
            {
                SetTool(Tools.LineAdjustTool);
            }
            else if (e.Key == Key.T)
            {
                SetTool(Tools.HandTool);
            }
            else if (e.Key == Key.Y)
            {
                Track.Start();
            }
            else if (e.Key == Key.U)
            {
                Track.Stop();
            }
            else if (e.Key == Key.I)
            {
                Track.Flag();
            }
            else if (e.Key == Key.O)
            {
                Canvas.ShowLoadWindow();
            }
            else if (e.Key == Key.M)
            {
                if (Track.Animating)
                {
                    if (Math.Abs(Scheduler.UpdatesPerSecond - 40) < 0.01)
                    {
                        Scheduler.UpdatesPerSecond = SettingSlowmoSpeed;
                        if (EnableSong)
                        {
                            UpdateSongPosition(Track.CurrentFrame / 40f);
                        }
                    }
                    else
                    {
                        Scheduler.UpdatesPerSecond = 40;
                        if (EnableSong)
                        {
                            UpdateSongPosition(Track.CurrentFrame / 40f);
                        }
                    }
                }
            }
            else if (e.Key == Key.Z)
            {
                if (Track.Playing)
                {
                    _zoomPerTick = 0.08f;
                }
            }
            else if (e.Key == Key.X)
            {
                if (Track.Playing)
                {
                    _zoomPerTick = -0.08f;
                }
            }
            if (e.Key == Key.Space)
            {
                if (!Track.Animating)
                {
                    _handToolOverride = true;
                }
                else
                {
                    if (!SettingRecordingMode)
                    {
                        Track.TogglePause();
                    }
                }
            }
            else if (e.Key == Key.F1)
            {
                if (!Track.Animating)
                {
                    Track.Camera.SetPosition(Track.RiderState.ModelAnchors[4].Position);
                    Invalidate();
                }
            }
            else if (e.Key == Key.F2)
            {
                if (!Track.Animating)
                {
                    var flag = Track.GetFlag();
                    if (flag != null)
                    {
                        Track.Camera.SetPosition(flag.State.ModelAnchors[4].Position);
                        Invalidate();
                    }
                }
            }
            else if (e.Key == Key.F5)
            {
                Canvas.UpdateSaveNodes();
            }
            else if (e.Key == Key.Number1)
            {
                Canvas.ColorControls.Selected = LineType.Blue;
                Invalidate();
            }
            else if (e.Key == Key.Number2)
            {
                Canvas.ColorControls.Selected = LineType.Red;
                Invalidate();
            }
            else if (e.Key == Key.Number3)
            {
                Canvas.ColorControls.Selected = LineType.Scenery;
                Invalidate();
            }
            else if (e.Key == Key.Minus || e.Key == Key.KeypadMinus)
            {
                PlaybackDown();
            }
            else if (e.Key == Key.Plus || e.Key == Key.KeypadPlus)
            {
                PlaybackUp();
            }
            else if (e.Key == Key.BackSpace)
            {
                if (!Track.Animating || Track.Paused)
                {
                    SelectedTool?.Stop(); //BUGFIX SLAGwell removal.
                    var l = Track.GetLastLine();
                    if (l != null)
                    {
                        Track.RemoveLine(l);
                    }
                    Track.TrackUpdated();
                    Invalidate();
                }
            }
            else if (e.Key == Key.Right)
            {
                if (!Track.Animating)
                {
                    Track.Start();
                }
                if (!Track.Paused)
                {
                    Track.TogglePause();
                }
                Track.NextFrame();
                Invalidate();
                Track.Camera.AimPosition = Track.CameraAroundRider(Track.RiderState);
                Track.Camera.UpdateCamera();
            }
            else if (e.Key == Key.Left)
            {
                if (!Track.Paused)
                {
                    Track.TogglePause();
                }
                Track.PreviousFrame();
                Invalidate();
                Track.Camera.AimPosition = Track.CameraAroundRider(Track.RiderState);
                Track.Camera.UpdateCamera();
            }
            else if (e.Key == Key.Home)
            {
                var l = Track.GetFirstLine();
                if (l != null)
                {
                    Track.Camera.SetPosition(l.Position);
                    Invalidate();
                }
            }
            else if (e.Key == Key.End)
            {
                var l = Track.GetLastLine();
                if (l != null)
                {
                    Track.Camera.SetPosition(l.Position);
                    Invalidate();
                }
            }
            else if (e.Key == Key.Tab)
            {
                if (!Track.Playing)
                {
                    Canvas.ColorControls.OnTabButtonPressed();
                }
            }
            else if (e.Key == Key.Escape)
            {
                Canvas.ShowPreferences();
            }
            else if (e.Key == Key.F12)
            {
            }
        }