Esempio n. 1
0
        public MenuHandler()
        {
            // Menus
            menu             = new Menu("Roleplay Menu");
            destinationsMenu = new Menu("Destinations");
            miscSettingsMenu = new Menu("Misc Settings");

            // Create menu controller
            if (menuController == null)
            {
                menuController = new MenuController();
                MenuController.AddMenu(menu);
                MenuController.AddMenu(destinationsMenu);
                MenuController.AddMenu(miscSettingsMenu);
                MenuController.MenuAlignment = MenuController.MenuAlignmentOption.Right;
                MenuController.MenuToggleKey = Control.MultiplayerInfo;
                MenuController.EnableMenuToggleKeyOnController = false;
                MenuController.MainMenu = menu;
                MenuController.AddSubmenu(menu, miscSettingsMenu);
            }

            // Main menu items
            MenuItem taxiItem = new MenuItem("Call Taxi", "Dispatches a taxi to your current location")
            {
                Enabled  = true,
                LeftIcon = MenuItem.Icon.CAR
            };

            menu.AddMenuItem(taxiItem);

            MenuItem miscSettingsItem = new MenuItem("Miscellaneous Settings", "Configure various miscellaneous settings.")
            {
                Enabled = true,
            };

            menu.AddMenuItem(miscSettingsItem);

            // Misc Settings items
            MenuCheckboxItem seatShuffleItem = new MenuCheckboxItem("Disable passenger seat shuffling",
                                                                    "Disables the automatic seat shuffling the passenger performs if the driver seat is empty", true)
            {
                Enabled = true,
                Checked = false
            };

            miscSettingsMenu.AddMenuItem(seatShuffleItem);

            // Main menu events
            menu.OnItemSelect += (_menu, _item, _index) =>
            {
                if (_item == taxiItem)
                {
                    UIHandler.ShowNotificationWithIcon("CHAR_TAXI", "CHAR_TAXI", "A taxi will be dispatched to your location shortly.", "Downtown Cab & Co.");
                    menu.CloseMenu();
                    TriggerEvent("RoleplayMenu:SendTaxiToPlayer");
                }
                else if (_item == miscSettingsItem)
                {
                    menu.CloseMenu();
                    miscSettingsMenu.OpenMenu();
                }
            };

            // Misc settings menu events

            miscSettingsMenu.OnCheckboxChange += (_sender, _item, _index, _checked) =>
            {
                Debug.WriteLine("Shitty");
                if (_item == seatShuffleItem)
                {
                    Debug.WriteLine("Selected item");
                    VehicleSettings.DisableSeatShuffle = seatShuffleItem.Checked;
                }
            };

            miscSettingsMenu.OnMenuClose += (_sender) =>
            {
                miscSettingsMenu.ParentMenu.OpenMenu();
            };

            // Destination menu events
            destinationsMenu.OnItemSelect += (_menu, _item, _index) =>
            {
                if (_index == 0)
                {
                    if (IsWaypointActive())
                    {
                        TaxiHandler.GetCurrentTaxi().DriveToDestination(World.GetNextPositionOnStreet(World.WaypointPosition));
                    }
                }
                else
                {
                    foreach (int p in GetActivePlayers())
                    {
                        if (_item.Text == GetPlayerName(p))
                        {
                            TaxiHandler.GetCurrentTaxi().DriveToDestination(World.GetNextPositionOnStreet(GetEntityCoords(GetPlayerPed(p), true)));
                        }
                    }
                }
            };
        }
Esempio n. 2
0
        public async Task TaxiTick()
        {
            if (TaxiVehicle == null || TaxiDriver == null)
            {
                return;
            }

            await Delay(0);

            if (Game.PlayerPed.IsInRangeOf(TaxiVehicle.Position, 7f) && !Game.PlayerPed.IsInVehicle())
            {
                Screen.DisplayHelpTextThisFrame("Press ~INPUT_CONTEXT~ to enter this taxi.");
                if (Game.IsControlJustPressed(1, (Control)38))
                {
                    Game.PlayerPed.Task.EnterVehicle(TaxiVehicle, VehicleSeat.RightRear);
                    await TaxiHandler.UpdatePlayerDestinations();

                    while (!Game.PlayerPed.IsInVehicle())
                    {
                        await Delay(0);
                    }
                    MenuHandler.destinationsMenu.Visible = true;
                }
                else
                {
                    MenuHandler.destinationsMenu.Visible = false;
                }
            }

            if (TaxiVehicle.IsInRangeOf(Destination, 10f))
            {
                TaxiVehicle.IsHandbrakeForcedOn = true;
                while (TaxiVehicle.Speed > 0)
                {
                    await Delay(0);
                }
                await Delay(1000);

                Game.PlayerPed.Task.LeaveVehicle();
                await Delay(2000);

                Debug.WriteLine("[Taxi Arrived]");
                TaxiVehicle.IsHandbrakeForcedOn = false;
                isActive = false;
            }

            if ((TaxiDriver.IsDead ||
                 TaxiVehicle.IsDead ||
                 TaxiDriver.IsFleeing) &&
                !TaxiVehicle.IsInRangeOf(Destination, 10f))
            {
                Debug.WriteLine("[Taxi Disturbed]");
                isActive = false;
            }

            if (!isActive)
            {
                MarkAsNoLongerNeeded();
            }

            if (Game.PlayerPed.CurrentVehicle == TaxiVehicle)
            {
                Screen.DisplayHelpTextThisFrame("Press ~INPUT_VEH_HEADLIGHT~ to hurry up.");
                if (Game.IsControlJustPressed(1, (Control)74))
                {
                    TaskVehicleGotoNavmesh(TaxiDriver.Handle, TaxiVehicle.Handle, Destination.X, Destination.Y, Destination.Z, 200f, 156, 5.0f);
                }
            }
        }