public SerializableWaypoint CreateWaypoint(WaypointTypes type, Vector3 pos, Entity ent)
        {
            var wpy = new SerializableWaypoint();

            wpy.Type         = type;
            wpy.Position     = pos;
            wpy.Duration     = 0;
            wpy.VehicleSpeed = 20f;
            wpy.DrivingStyle = 0xC00AB;

            switch (type)
            {
            case WaypointTypes.EnterVehicle:
                if (ent != null && ent.IsValid() && ent.IsVehicle())
                {
                    wpy.VehicleTargetModel = ent.Model.Hash;
                }
                break;
            }


            if (_mainPed != null)
            {
                _mainPed.Waypoints.Add(wpy);
            }
            else
            {
                _mainActorObjective.Waypoints.Add(wpy);
            }

            return(wpy);
        }
        public void RebuildWaypointPropertiesMenu(SerializableWaypoint waypoint)
        {
            _children.Clear();
            _waypointPropertiesMenu.Clear();
            _waypointPropertiesMenu.Subtitle.Caption = waypoint.Type.ToString().ToUpper() + " PROPERTIES";

            {
                var item = new NativeMenuItem("Duration", "Task duration in seconds. Leave blank to wait until the task is done.");
                _waypointPropertiesMenu.AddItem(item);

                item.SetRightLabel(waypoint.Duration == 0 ? "Wait Until Done" : waypoint.Duration.ToString());


                item.Activated += (sender, selectedItem) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        _waypointPropertiesMenu.ResetKey(Common.MenuControls.Back);
                        Editor.Editor.DisableControlEnabling = true;
                        string title = Util.GetUserInput();

                        Editor.Editor.DisableControlEnabling = false;
                        _waypointPropertiesMenu.SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);

                        if (string.IsNullOrEmpty(title))
                        {
                            waypoint.Duration = 0;
                            selectedItem.SetRightLabel("Wait Until Done");
                            return;
                        }
                        float duration;
                        if (!float.TryParse(title, NumberStyles.Float, CultureInfo.InvariantCulture, out duration))
                        {
                            waypoint.Duration = 0;
                            selectedItem.SetRightLabel("Wait Until Done");
                            Game.DisplayNotification("Incorrect format.");
                        }
                        waypoint.Duration = (int)(duration * 1000);
                        selectedItem.SetRightLabel(duration.ToString());
                    });
                };
            }

            if (waypoint.Type == WaypointTypes.Animation)
            {
                var db   = StaticData.AnimData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray());
                var menu = new CategorySelectionMenu(db, "Animation", true, "SELECT ANIMATION");
                var item = new NativeMenuItem("Select Animation");
                menu.Build(db.ElementAt(0).Key);

                if (!string.IsNullOrEmpty(waypoint.AnimName))
                {
                    var categName = StaticData.AnimData.Database.FirstOrDefault(cats =>
                    {
                        return(cats.Value.Any(v => v.Item3 == waypoint.AnimName));
                    }).Key;

                    var humanName = StaticData.AnimData.Database[categName].FirstOrDefault(v => v.Item3 == waypoint.AnimName)?.Item1;
                    if (!string.IsNullOrEmpty(humanName))
                    {
                        item.SetRightLabel(humanName);
                    }
                }

                menu.SelectionChanged += (sender, args) =>
                {
                    var pair =
                        StaticData.AnimData.Database[menu.CurrentSelectedCategory].First(
                            m => m.Item1 == menu.CurrentSelectedItem);
                    waypoint.AnimDict = pair.Item2;
                    waypoint.AnimName = pair.Item3;
                };

                _waypointPropertiesMenu.AddItem(item);
                _waypointPropertiesMenu.BindMenuToItem(menu, item);

                _children.Add(menu);
            }

            if (waypoint.Type == WaypointTypes.Drive)
            {
                {
                    var item = new NativeMenuItem("Driving Speed", "Driving speed in meters per second.");
                    _waypointPropertiesMenu.AddItem(item);

                    item.SetRightLabel(waypoint.VehicleSpeed == 0 ? "Default" : waypoint.VehicleSpeed.ToString());


                    item.Activated += (sender, selectedItem) =>
                    {
                        GameFiber.StartNew(delegate
                        {
                            _waypointPropertiesMenu.ResetKey(Common.MenuControls.Back);
                            Editor.Editor.DisableControlEnabling = true;
                            string title = Util.GetUserInput();

                            Editor.Editor.DisableControlEnabling = false;
                            _waypointPropertiesMenu.SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);

                            if (string.IsNullOrEmpty(title))
                            {
                                waypoint.VehicleSpeed = 20;
                                selectedItem.SetRightLabel("Default");
                                return;
                            }
                            float duration;
                            if (!float.TryParse(title, NumberStyles.Float, CultureInfo.InvariantCulture, out duration))
                            {
                                waypoint.VehicleSpeed = 20;
                                selectedItem.SetRightLabel("Default");
                                Game.DisplayNotification("Incorrect format.");
                            }
                            waypoint.VehicleSpeed = duration;
                            selectedItem.SetRightLabel(duration.ToString());
                        });
                    };
                }

                {
                    var parsedList = StaticData.StaticLists.DrivingStylesList.Select(t => (dynamic)t.Item1);
                    var indexOf    =
                        StaticData.StaticLists.DrivingStylesList.FindIndex(tup => tup.Item2 == waypoint.DrivingStyle);
                    var item = new MenuListItem("Driving Style", parsedList.ToList(), indexOf);
                    _waypointPropertiesMenu.AddItem(item);

                    item.OnListChanged += (sender, index) =>
                    {
                        waypoint.DrivingStyle = StaticData.StaticLists.DrivingStylesList[index].Item2;
                    };
                }
            }

            _waypointPropertiesMenu.RefreshIndex();
        }