Esempio n. 1
0
        public void ShowNewTrack()
        {
            game.StopTools();
            var window = PopupWindow.Create("Do you want to start a new track? Your current progress will not be saved.", "New Track", true, true);

            window.Dismissed += (o, e) =>
            {
                if (window.Result == System.Windows.Forms.DialogResult.OK)
                {
                    game.Track.Stop();
                    game.Track.ChangeTrack(new Track()
                    {
                        Name = Utils.Constants.DefaultTrackName
                    });
                    Settings.LastSelectedTrack = "";
                    Settings.Save();
                    game.Invalidate();
                }
            };
        }
Esempio n. 2
0
        public void ExportAsSol()
        {
            Dictionary <string, bool> features;

            using (var trk = game.Track.CreateTrackReader())
            {
                if (trk.GetOldestLine() == null)
                {
                    return;
                }
                features = trk.GetFeatures();
            }
            bool six_one;
            bool redmultiplier;
            bool scenerywidth;

            features.TryGetValue("SIX_ONE", out six_one);
            features.TryGetValue("REDMULTIPLIER", out redmultiplier);
            features.TryGetValue("SCENERYWIDTH", out scenerywidth);
            if (six_one || redmultiplier || scenerywidth)
            {
                var window = PopupWindow.Error("Unable to export SOL file due to it containing special LRA specific features.\n" + (six_one ? "\nthe track is based on 6.1, " : "") + (redmultiplier ? "\nthe track uses red multiplier lines, " : "") + (scenerywidth ? "\nthe track uses varying scenery line width " : "") + "\n\nand therefore cannot be loaded");
            }
            else
            {
                var window = PopupWindow.Create("Are you sure you wish to save this track as an SOL file? It will overwrite any file with its name. (trackname+savedLines.sol)", "Are you sure?", true, true);
                window.Dismissed += (o, e) =>
                {
                    if (window.Result == System.Windows.Forms.DialogResult.OK)
                    {
                        using (var track = game.Track.CreateTrackReader())
                        {
                            track.SaveTrackAsSol();
                        }
                    }
                };
            }
        }
Esempio n. 3
0
        public void ExportAsSol()
        {
            if (_track.Lines.Count != 0)
            {
                var  features = TrackLoader.TrackFeatures(_track);
                bool six_one;
                bool redmultiplier;
                bool scenerywidth;
                features.TryGetValue("SIX_ONE", out six_one);
                features.TryGetValue("REDMULTIPLIER", out redmultiplier);
                features.TryGetValue("SCENERY_WIDTH", out scenerywidth);
                if (six_one || redmultiplier || scenerywidth)
                {
                    var window = PopupWindow.Create(game.Canvas, game, "Unable to export SOL file due to it containing special LRA specific features,\nspecifically, " + (six_one ? "\nthe track is based on 6.1, " : "") + (redmultiplier ? "\nthe track uses red multiplier lines, " : "") + (scenerywidth ? "\nthe track uses varying scenery line width " : "") + "\nand therefore cannot be loaded", "Error!", true, false);

                    window.FindChildByName("Okay", true).Clicked += (o, e) =>
                    {
                        window.Close();
                    };
                }
                else
                {
                    var window = PopupWindow.Create(game.Canvas, game, "Are you sure you wish to save this track as an SOL file? It will overwrite any file named savedLines.sol", "Are you sure?", true, true);

                    window.FindChildByName("Okay", true).Clicked += (o, e) =>
                    {
                        window.Close();
                        TrackLoader.SaveTrackSol(_track);
                        game.Canvas.UpdateSaveNodes();
                    };
                    window.FindChildByName("Cancel", true).Clicked += (o, e) =>
                    {
                        window.Close();
                    };
                }
            }
        }
Esempio n. 4
0
        public void ShowOutOfDate()
        {
            if (Program.NewVersion == null)
            {
                return;
            }
            var window = PopupWindow.Create("Would you like to download the latest version?", "Update Available! v" + Program.NewVersion, true, true);

            window.Dismissed += (o, e) =>
            {
                if (window.Result == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        OpenUrl(@"https://github.com/jealouscloud/linerider-advanced/releases/latest");
                    }
                    catch
                    {
                        PopupWindow.Error("Unable to open the browser.");
                    }
                }
            };
            Program.NewVersion = null;
        }
        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();
        }
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            try
            {
                InputUtils.UpdateMouse(e.Mouse);
                if (linerider.IO.TrackRecorder.Recording)
                {
                    return;
                }
                var r = _input.ProcessMouseMessage(e);
                if (Canvas.GetOpenWindows().Count != 0)
                {
                    return;
                }

                if (!r && !Track.Playing)
                {
                    bool dragstart = false;
                    if (!Track.Paused &&
                        e.Button == MouseButton.Left &&
                        OpenTK.Input.Keyboard.GetState()[Key.D])
                    {
                        var pos     = new Vector2d(e.X, e.Y) / Track.Zoom;
                        var gamepos = (ScreenPosition + pos);
                        dragstart = Game.Rider.GetBounds(
                            Track.GetStart()).Contains(
                            gamepos.X,
                            gamepos.Y);
                        if (dragstart)
                        {
                            // 5 is arbitrary, but i assume that's a decent
                            // place to assume the user has done "work"
                            if (!Track.MoveStartWarned && Track.LineCount > 5)
                            {
                                var popup = PopupWindow.Create(
                                    "You're about to move the start position of the rider." +
                                    " This cannot be undone, and may drastically change how your track plays." +
                                    "\nAre you sure you want to do this?", "Warning", true, true);
                                popup.Dismissed += (o, args) =>
                                {
                                    if (popup.Result == DialogResult.OK)
                                    {
                                        Track.MoveStartWarned = true;
                                    }
                                };
                            }
                            else
                            {
                                _dragRider = dragstart;
                            }
                        }
                    }
                    if (!_dragRider && !dragstart)
                    {
                        if (e.Button == MouseButton.Left)
                        {
                            if (_handToolOverride)
                            {
                                HandTool.OnMouseDown(new Vector2d(e.X, e.Y));
                            }
                            else
                            {
                                SelectedTool.OnMouseDown(new Vector2d(e.X, e.Y));
                            }
                        }
                        else if (e.Button == MouseButton.Right)
                        {
                            if (_handToolOverride)
                            {
                                HandTool.OnMouseRightDown(new Vector2d(e.X, e.Y));
                            }
                            else
                            {
                                SelectedTool.OnMouseRightDown(new Vector2d(e.X, e.Y));
                            }
                        }
                        else if (e.Button == MouseButton.Middle)
                        {
                            _handToolOverride = true;
                            HandTool.OnMouseDown(new Vector2d(e.X, e.Y));
                        }
                    }
                    if (e.Button != MouseButton.Right)
                    {
                        UpdateCursor();
                    }
                }
                else
                {
                    Cursor = Cursors["default"];
                }
                Invalidate();
            }
            catch (Exception ex)
            {
                // SDL2 backend eats exceptions.
                // we have to manually crash.
                Program.Crash(ex, true);
                Close();
            }
        }