internal void InitControls()
        {
            var ctrl = new ControlBase(Canvas);

            ctrl.Name = "buttons";
            var pos = 0;
            Func <Bitmap, Bitmap, string, string, ImageButton> createbutton =
                delegate(Bitmap bmp, Bitmap bmp2, string tooltip, string name)
            {
                var ret = new ImageButton(ctrl)
                {
                    Name = name
                };
                if (tooltip != null)
                {
                    ret.SetToolTipText(tooltip);
                }
                ret.SetImage(bmp, bmp2);
                ret.SetSize(32, 32);
                ret.X = pos;
                pos  += 32;
                return(ret);
            };
            //Warning:
            //the name parameter needs to stay consistent for these buttons
            //other parts of code reference it.
            var btn = createbutton(GameResources.pencil_icon, GameResources.pencil_icon_white, "Pencil Tool (Q)", "penciltool");

            btn.Clicked += (o, e) => { SetTool(Tools.PencilTool); };
            btn          = createbutton(GameResources.line_icon, GameResources.line_icon_white, "Line Tool (W)", "linetool");
            btn.Clicked += (o, e) => { SetTool(Tools.LineTool); };
            btn          = createbutton(GameResources.eraser_icon, GameResources.eraser_icon_white, "Eraser Tool (E)", "erasertool");
            btn.Clicked += (o, e) => { SetTool(Tools.EraserTool); };
            btn          = createbutton(GameResources.movetool_icon, GameResources.movetool_icon_white, "Line Adjustment Tool (R)",
                                        "lineadjusttool");
            btn.Clicked += (o, e) => { SetTool(Tools.MoveTool); };
            //  btn = createbutton(Content.gwell_tool, Content.gwell_tool, "Gravity Well Tool (T)",
            //       "gwelltool");
            //   btn.Clicked += (o, e) => { SetTool(Tools.GwellTool); };
            btn          = createbutton(GameResources.pantool_icon, GameResources.pantool_icon_white, "Hand Tool (Space) (T)", "handtool");
            btn.Clicked += (o, e) =>
            {
                SetTool(Tools.HandTool);
                _handToolOverride = false;
            };
            btn          = createbutton(GameResources.play_icon, GameResources.play_icon_white, "Start (Y)", "start");
            btn.Clicked += (o, e) =>
            {
                StopTools();
                if (UI.InputUtils.Check(Hotkey.PlayButtonIgnoreFlag))
                {
                    Track.StartIgnoreFlag();
                }
                else
                {
                    Track.StartFromFlag();
                }
                Scheduler.DefaultSpeed();
            };
            pos         -= 32; //occupy same space as the start button
            btn          = createbutton(GameResources.pause, GameResources.pause_white, null, "pause");
            btn.IsHidden = true;
            btn.Clicked += (o, e) =>
            {
                StopTools();
                Track.TogglePause();
            };
            btn          = createbutton(GameResources.stop_icon, GameResources.stop_icon_white, "Stop (U)", "stop");
            btn.Clicked += (o, e) =>
            {
                StopTools();
                Track.Stop();
            };
            btn = createbutton(GameResources.flag_icon, GameResources.flag_icon_white, "Flag (I)", "flag");
            btn.SetOverride(GameResources.flag_invalid_icon);
            btn.Clicked      += (o, e) => { Track.Flag(); };
            btn.RightClicked += (o, e) => { Canvas.CalculateFlag(Track.GetFlag()); };
            Canvas.FlagTool   = btn;
            btn = createbutton(GameResources.menu_icon, GameResources.menu_icon_white, "Menu", "menu");
            var _menuEdit = new Menu(Canvas);
            var item      = _menuEdit.AddItem("Save");

            item.AutoSizeToContents = false;
            item.Clicked           += (snd, evt) => { Canvas.ShowSaveWindow(); };
            item = _menuEdit.AddItem("Load");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, evt) => { Canvas.ShowLoadWindow(); };
            item = _menuEdit.AddItem("New");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, evt) => { Canvas.ShowNewTrack(); };
            item = _menuEdit.AddItem("Preferences");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) => { Canvas.ShowPreferences(); };
            item = _menuEdit.AddItem("Song");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) => { Canvas.ShowSongWindow(); };
            item = _menuEdit.AddItem("Export SOL");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) =>
            {
                Canvas.ExportAsSol();
            };
            item = _menuEdit.AddItem("Export Video");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) =>
            {
                if (SafeFrameBuffer.CanRecord)
                {
                    ExportVideoWindow.Create(this);
                }
                else
                {
                    PopupWindow.Error("This computer does not support recording.\nTry updating your graphics drivers.");
                }
            };
            btn.Clicked += (o, e) =>
            {
                var canvaspos = ctrl.LocalPosToCanvas(new Point(btn.X, btn.Y));
                _menuEdit.MoveTo(canvaspos.X, canvaspos.Y + 32);
                _menuEdit.Show();
            };
            _menuEdit.DeleteOnClose = false;
            _menuEdit.Close();
            var cc = new ColorControls(ctrl, new Vector2(0, 32 + 3));

            cc.Selected          = LineType.Blue;
            Canvas.ColorControls = cc;
            ctrl.SizeToChildren();
            ctrl.ShouldCacheToTexture = true;
            ctrl.Position(Pos.CenterH);

            Canvas.ButtonsToggleNightmode();
        }
예제 #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)
            {
            }
        }