Example #1
0
    public void AddActorActionToMenu(UIMenu menu, String name, Action <UIMenuItem, int> action, Func <int, bool> ticked)
    {
        var submenu = AddSubMenu(menu, name);

        for (int i = 0; i < 10; i++)
        {
            var subsubmenu = AddSubMenu(submenu, String.Format("Actors {0}-{1}", 1 + i * 10, 10 + i * 10));
            for (int j = 0; j < 10; j++)
            {
                var slot     = 1 + j + i * 10;
                var slotitem = new UIMenuItem(String.Format("Actor {0}", slot));
                subsubmenu.AddItem(slotitem);
                if (ticked(slot))
                {
                    slotitem.SetLeftBadge(UIMenuItem.BadgeStyle.Tick);
                }
                subsubmenu.OnItemSelect += (sender, item, index) =>
                {
                    if (item == slotitem)
                    {
                        action(slotitem, slot);
                    }
                };
            }
        }
    }
Example #2
0
        private void CraftAmmo()
        {
            _craftWeaponsMenu.Clear();
            WeaponGroup[] weaponGroups3 = (WeaponGroup[])Enum.GetValues(typeof(WeaponGroup));
            weaponGroups3 = (from w in weaponGroups3
                             where (int)w != 1595662460 && (int)w != -1609580060 && (int)w != -728555052 && (int)w != -942583726
                             select w).ToArray();
            List <WeaponGroup> list = weaponGroups3.ToList();

            list.Add(GTA.WeaponGroup.AssaultRifle);
            weaponGroups3 = list.ToArray();
            WeaponGroup[] array = weaponGroups3;
            for (int i = 0; i < array.Length; i++)
            {
                WeaponGroup weaponGroup = array[i];
                UIMenuItem  menuItem    = new UIMenuItem(string.Format("{0}", ((int)weaponGroup == 970310034) ? "Assult Rifle" : ((object)weaponGroup).ToString()), $"Craft ammo for {weaponGroup}");
                menuItem.SetLeftBadge(UIMenuItem.BadgeStyle.Ammo);
                int required = GetRequiredPartsForWeaponGroup(weaponGroup);
                menuItem.Description = $"Required Weapon Parts: ~y~{required}~s~";
                _craftWeaponsMenu.AddItem(menuItem);
                menuItem.Activated += delegate
                {
                    InventoryItemBase inventoryItemBase = PlayerInventory.Instance.ItemFromName("Weapon Parts");
                    if (inventoryItemBase != null)
                    {
                        if (inventoryItemBase.Amount >= required)
                        {
                            WeaponHash[] array2 = (WeaponHash[])Enum.GetValues(typeof(WeaponHash));
                            WeaponHash   val    = Array.Find(array2, (WeaponHash h) => PlayerPed.Weapons.HasWeapon(h) && PlayerPed.Weapons[h].Group == weaponGroup);
                            GTA.Weapon   val2   = PlayerPed.Weapons[val];
                            if (val2 != null)
                            {
                                int num = 10 * required;
                                if (val2.Ammo + num <= val2.MaxAmmo)
                                {
                                    PlayerPed.Weapons.Select(val2);
                                    if (val2.Ammo + num > val2.MaxAmmo)
                                    {
                                        val2.Ammo = val2.MaxAmmo;
                                    }
                                    else
                                    {
                                        GTA.Weapon obj = val2;
                                        obj.Ammo = obj.Ammo + num;
                                    }
                                    PlayerInventory.Instance.AddItem(inventoryItemBase, -required, ItemType.Resource);
                                }
                            }
                        }
                        else
                        {
                            UI.Notify("Not enough weapon parts.");
                        }
                    }
                };
            }
            _craftWeaponsMenu.Visible = !_craftWeaponsMenu.Visible;
        }
Example #3
0
        private bool toggle(UIMenuItem item)
        {
            if (!props.ContainsKey(item))
            {
                props[item] = false;
            }

            if (!props[item])
            {
                item.SetLeftBadge(UIMenuItem.BadgeStyle.Tick);
            }
            else
            {
                item.SetLeftBadge(UIMenuItem.BadgeStyle.None);
            }
            props[item] = !props[item];
            return(props[item]);
        }
Example #4
0
    public void AddMenuCook(UIMenu menu)
    {
        var newitem = new UIMenuItem("Cook!", "Cook the dish with the appropiate ingredients and ketchup.");

        newitem.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
        newitem.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
        menu.AddItem(newitem);
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == newitem)
            {
                string output = ketchup ? "You have ordered ~b~{0}~w~ ~r~with~w~ ketchup." : "You have ordered ~b~{0}~w~ ~r~without~w~ ketchup.";
                CitizenFX.Core.UI.Screen.ShowSubtitle(String.Format(output, dish));
            }
        };
        menu.OnIndexChange += (sender, index) =>
        {
            if (sender.MenuItems[index] == newitem)
            {
                newitem.SetLeftBadge(UIMenuItem.BadgeStyle.None);
            }
        };
    }
        private void CraftAmmo()
        {
            this._craftWeaponsMenu.Clear();
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            List <WeaponGroup> list = ((IEnumerable <WeaponGroup>)((IEnumerable <WeaponGroup>)Enumerable.Where <WeaponGroup>((IEnumerable <M0>)Enum.GetValues(typeof(WeaponGroup)), (Func <M0, bool>)(MapInteraction.\u003C\u003Ec.\u003C\u003E9__15_0 ?? (MapInteraction.\u003C\u003Ec.\u003C\u003E9__15_0 = new Func <WeaponGroup, bool>((object)MapInteraction.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CCraftAmmo\u003Eb__15_0)))))).ToArray <WeaponGroup>()).ToList <WeaponGroup>();

            list.Add((WeaponGroup)970310034);
            foreach (uint num in list.ToArray())
            {
                // ISSUE: object of a compiler-generated type is created
                // ISSUE: variable of a compiler-generated type
                MapInteraction.\u003C\u003Ec__DisplayClass15_1 cDisplayClass151 = new MapInteraction.\u003C\u003Ec__DisplayClass15_1();
                // ISSUE: reference to a compiler-generated field
                cDisplayClass151.weaponGroup = (WeaponGroup)(int)num;
                // ISSUE: object of a compiler-generated type is created
                // ISSUE: variable of a compiler-generated type
                MapInteraction.\u003C\u003Ec__DisplayClass15_0 cDisplayClass150 = new MapInteraction.\u003C\u003Ec__DisplayClass15_0();
                // ISSUE: reference to a compiler-generated field
                cDisplayClass150.CS\u0024\u003C\u003E8__locals1 = cDisplayClass151;
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                UIMenuItem uiMenuItem = new UIMenuItem(string.Format("{0}", cDisplayClass150.CS\u0024\u003C\u003E8__locals1.weaponGroup == 970310034 ? (object)"Assult Rifle" : (object)cDisplayClass150.CS\u0024\u003C\u003E8__locals1.weaponGroup.ToString()), string.Format("Craft ammo for {0}", (object)cDisplayClass150.CS\u0024\u003C\u003E8__locals1.weaponGroup));
                uiMenuItem.SetLeftBadge((UIMenuItem.BadgeStyle) 6);
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated field
                cDisplayClass150.required = this.GetRequiredPartsForWeaponGroup(cDisplayClass150.CS\u0024\u003C\u003E8__locals1.weaponGroup);
                // ISSUE: reference to a compiler-generated field
                uiMenuItem.set_Description(string.Format("Required Weapon Parts: ~y~{0}~s~", (object)cDisplayClass150.required));
                this._craftWeaponsMenu.AddItem(uiMenuItem);
                // ISSUE: method pointer
                uiMenuItem.add_Activated(new ItemActivatedEvent((object)cDisplayClass150, __methodptr(\u003CCraftAmmo\u003Eb__1)));
            }
            this._craftWeaponsMenu.set_Visible(!this._craftWeaponsMenu.get_Visible());
        }
        public UIMenuItem AddMenuItem(UIMenu menu, string title = "Menu", string subTitle = "", string rightLabel = "", UIMenuItem.BadgeStyle badge = UIMenuItem.BadgeStyle.None, bool isBadgeLeft = true)
        {
            var menuItem = new UIMenuItem(title, subTitle);

            if (rightLabel != "")
            {
                menuItem.SetRightLabel(rightLabel);
            }

            if (isBadgeLeft)
            {
                menuItem.SetLeftBadge(badge);
            }
            else
            {
                menuItem.SetRightBadge(badge);
            }

            menu.AddItem(menuItem);
            return(menuItem);
        }
Example #7
0
        /// <summary>
        /// Creates the menu.
        /// </summary>
        private void CreateMenu()
        {
            string menuTitle = "Saved Vehicles";

            #region Create menus and submenus
            // Create the menu.
            menu = new UIMenu(menuTitle, "Manage Saved Vehicles", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            // Create submenus.
            UIMenu spawnSavedVehicles = new UIMenu(menuTitle, "Spawn Saved Vehicle", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            UIMenu deleteSavedVehicles = new UIMenu(menuTitle, "~r~Delete Saved Vehicle", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            #endregion

            #region Create, add and bind buttons to the menus.
            // Create menu buttons.
            UIMenuItem saveVeh = new UIMenuItem("Save Current Vehicle", "Save the vehicle you are currently in.");
            saveVeh.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
            UIMenuItem savedVehiclesBtn = new UIMenuItem("Spawn Saved Vehicle", "Select a vehicle from your saved vehicles list.");
            savedVehiclesBtn.SetRightLabel("→→→");
            UIMenuItem deleteSavedVehiclesBtn = new UIMenuItem("~r~Delete Saved Vehicle", "~r~Delete ~s~a saved vehicle.");
            deleteSavedVehiclesBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Alert);
            deleteSavedVehiclesBtn.SetRightLabel("→→→");

            // Add buttons to the menu.
            menu.AddItem(saveVeh);
            menu.AddItem(savedVehiclesBtn);
            menu.AddItem(deleteSavedVehiclesBtn);

            // Bind submenus to menu items.
            if (cf.IsAllowed(Permission.SVSpawn))
            {
                menu.BindMenuToItem(spawnSavedVehicles, savedVehiclesBtn);
            }
            else
            {
                savedVehiclesBtn.Enabled = false;
                savedVehiclesBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                savedVehiclesBtn.Description = "This option has been disabled by the server owner.";
            }
            menu.BindMenuToItem(deleteSavedVehicles, deleteSavedVehiclesBtn);
            #endregion

            #region Button pressed events
            // Handle button presses.
            menu.OnItemSelect += (sender, item, index) =>
            {
                // Save the current vehicle.
                if (item == saveVeh)
                {
                    cf.SaveVehicle();
                }

                // Open and refresh the "spawn saved vehicle from list" submenu.
                else if (item == savedVehiclesBtn)
                {
                    // Remove all old items.
                    spawnSavedVehicles.MenuItems.Clear();

                    // Get all saved vehicles.
                    SavedVehiclesDict = cf.GetSavedVehicles();

                    // Loop through all saved vehicles and create a button for it, then add that button to the submenu.
                    foreach (KeyValuePair <string, CommonFunctions.VehicleInfo> savedVehicle in SavedVehiclesDict)
                    {
                        //MainMenu.Cf.Log(savedVehicle.ToString());
                        UIMenuItem vehBtn = new UIMenuItem(savedVehicle.Key.Substring(4), "Click to spawn this saved vehicle.");
                        vehBtn.SetRightLabel($"({savedVehicle.Value.name})");
                        spawnSavedVehicles.AddItem(vehBtn);
                        if (!IsModelInCdimage(savedVehicle.Value.model))
                        {
                            vehBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                            vehBtn.Enabled     = false;
                            vehBtn.Description = "This model is not available on this server, if this is an addon vehicle or DLC vehicle, please make sure " +
                                                 "that it's being streamed on this server.";
                        }
                        else
                        {
                            if (!VehicleSpawner.allowedCategories[GetVehicleClassFromName(savedVehicle.Value.model)])
                            {
                                vehBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                                vehBtn.Enabled     = false;
                                vehBtn.Description = "This vehicle is not available on this server because you do not have permissions for this vehicle class.";
                            }
                        }
                    }

                    // Sort the menu items (case IN-sensitive) by name.
                    spawnSavedVehicles.MenuItems.Sort((pair1, pair2) => pair1.Text.ToString().ToLower().CompareTo(pair2.Text.ToString().ToLower()));

                    // Refresh the index of the page.
                    spawnSavedVehicles.RefreshIndex();

                    // Update the scaleform.
                    spawnSavedVehicles.UpdateScaleform();
                }
                // Delete saved vehicle.
                else if (item == deleteSavedVehiclesBtn)
                {
                    deleteSavedVehicles.MenuItems.Clear();

                    // Get the dictionary containing all saved vehicles.
                    SavedVehiclesDict = cf.GetSavedVehicles();

                    // Loop through the list and add all saved vehicles to the menu.
                    foreach (KeyValuePair <string, CommonFunctions.VehicleInfo> savedVehicle in SavedVehiclesDict)
                    {
                        //MainMenu.Cf.Log(savedVehicle.ToString());
                        UIMenuItem vehBtn = new UIMenuItem(savedVehicle.Key.Substring(4), "Are you sure you want to delete this saved vehicle? This action cannot be undone!");
                        vehBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Alert);
                        vehBtn.SetRightLabel($"({savedVehicle.Value.name})");
                        deleteSavedVehicles.AddItem(vehBtn);
                    }

                    // Sort the menu items (case IN-sensitive) by name.
                    deleteSavedVehicles.MenuItems.Sort((pair1, pair2) => pair1.Text.ToString().ToLower().CompareTo(pair2.Text.ToString().ToLower()));
                    deleteSavedVehicles.RefreshIndex();
                    deleteSavedVehicles.UpdateScaleform();
                }
            };
            #endregion

            #region Handle saved vehicles being pressed. (spawning)
            // When a vehicle is selected...
            spawnSavedVehicles.OnItemSelect += (sender2, item2, index2) =>
            {
                CommonFunctions.VehicleInfo vehInfo = SavedVehiclesDict["veh_" + item2.Text];

                // Spawn a vehicle using the hash, and pass on the vehicleInfo dictionary containing all saved vehicle mods.
                if (MainMenu.VehicleSpawnerMenu != null)
                {
                    cf.SpawnVehicle(vehInfo.model, MainMenu.VehicleSpawnerMenu.SpawnInVehicle, MainMenu.VehicleSpawnerMenu.ReplaceVehicle, false, vehicleInfo: vehInfo, saveName: item2.Text);
                }
                else
                {
                    cf.SpawnVehicle(vehInfo.model, true, true, false, vehicleInfo: vehInfo, saveName: item2.Text);
                }
            };

            // Handle vehicle deletions
            deleteSavedVehicles.OnItemSelect += (sender2, item2, index2) =>
            {
                var vehDictName = "veh_" + item2.Text;
                new StorageManager().DeleteSavedStorageItem(vehDictName);
                deleteSavedVehicles.GoBack();
            };
            #endregion

            // Add the submenus to the menu pool.
            MainMenu.Mp.Add(spawnSavedVehicles);
            MainMenu.Mp.Add(deleteSavedVehicles);
        }
Example #8
0
        public StreetRaces()
        {
            Game.FadeScreenIn(500);
            Util.GetClasses();


            ClassList = RaceClasses; //Enum.GetValues(typeof(Raceclass)).Cast<dynamic>().ToList();
            Tick     += OnTick;
            KeyDown  += OnKeyDown;
            KeyUp    += OnKeyUp;

            LoadRaceTriggers();

            _menuPool = new MenuPool();

            //Car Saver Menu
            RaceSetupMenu = new UIMenu("Race Setup", "Change your preferences before the race.");
            _menuPool.Add(RaceSetupMenu);

            AdvancedOptionsMenu = new UIMenu("Adv. Options", "For those who know what they're doing.");
            _menuPool.Add(AdvancedOptionsMenu);



            AdvancedOptions = new UIMenuItem("Advanced Options", "");
            AdvancedOptions.SetLeftBadge(UIMenuItem.BadgeStyle.Michael);
            RaceSetupMenu.AddItem(AdvancedOptions);
            RaceSetupMenu.BindMenuToItem(AdvancedOptionsMenu, AdvancedOptions);


            CarClass = new UIMenuListItem("Vehicle Class", ClassList, 0);
            RaceSetupMenu.AddItem(CarClass);

            SetupCarsNumber = new UIMenuListItem("Nº of Racers", NumberOfRacersList, 0);
            RaceSetupMenu.AddItem(SetupCarsNumber);


            SetupLaps = new UIMenuListItem("Nº of Laps", LapsList, 0);
            RaceSetupMenu.AddItem(SetupLaps);


            MoneyBet = new UIMenuListItem("Bet", MoneyBetList, 0, "Each racer bets this ammount of money. The winner gets it all.");
            RaceSetupMenu.AddItem(MoneyBet);

            RaceSetupMenu.AddItem(UseNitro);
            RaceSetupMenu.AddItem(AllowHelicopter);
            RaceSetupMenu.AddItem(AIGodmode);
            RaceSetupMenu.AddItem(AllowFilling);
            ForceTuneconfig = new UIMenuListItem("Auto Opponent Tuning", TuneconfigListText, 0, "Opponent cars can be randomly tuned for more variety.");


            AdvancedOptionsMenu.AddItem(ForceTuneconfig); //Test
            AdvancedOptionsMenu.AddItem(ImmersiveCheckpoints);
            AdvancedOptionsMenu.AddItem(DebugMode);
            AdvancedOptionsMenu.AddItem(Traffic);
            AdvancedOptionsMenu.AddItem(AICatchup);
            AdvancedOptionsMenu.AddItem(AICurvePathing);
            AdvancedOptionsMenu.AddItem(AIRearEnd);
            AdvancedOptionsMenu.AddItem(AISlamToWall);
            AdvancedOptionsMenu.AddItem(AISpinout);

            StartRace = new UIMenuItem("Start Race", "");
            RaceSetupMenu.AddItem(StartRace);



            foreach (UIMenu menu in _menuPool.ToList())
            {
                menu.RefreshIndex();
                menu.OnItemSelect     += OnItemSelect;
                menu.OnListChange     += OnListChange;
                menu.OnCheckboxChange += OnCheckboxChange;

                /* menu.OnIndexChange += OnItemChange;
                 * menu.OnMenuClose += OnMenuClose;*/
            }
            SetupCarsNumber.Index = Util.GetRandomInt(0, NumberOfRacersList.Count / 2);
            SetupLaps.Index       = Util.GetRandomInt(0, LapsList.Count / 2);
        }
Example #9
0
    public void AddMenuCook(UIMenu menu)
    {
        var newitem = new UIMenuItem("Cook!", "Cook the dish with the appropiate ingredients and ketchup.");

        newitem.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
        newitem.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
        menu.AddItem(newitem);
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == newitem)
            {
                string output = ketchup ? "You have ordered ~b~{0}~w~ ~r~with~w~ ketchup." : "You have ordered ~b~{0}~w~ ~r~without~w~ ketchup.";
                Screen.ShowSubtitle(String.Format(output, dish));
            }
        };

        menu.OnIndexChange += (sender, index) =>
        {
            if (sender.MenuItems[index] == newitem)
            {
                newitem.SetLeftBadge(UIMenuItem.BadgeStyle.None);
            }
        };

        var colorItem = new UIMenuItem("UIMenuItem with Colors", "~b~Look!!~r~I can be colored ~y~too!!~w~", Color.FromArgb(150, 185, 230, 185), Color.FromArgb(170, 174, 219, 242));

        menu.AddItem(colorItem);

        var foods = new List <dynamic>
        {
            "Banana",
            "Apple",
            "Pizza",
            "Quartilicious",
            0xF00D,             // Dynamic!
        };

        var BlankItem = new UIMenuSeparatorItem();

        menu.AddItem(BlankItem);

        var colorListItem = new UIMenuListItem("Colored ListItem.. Really?", foods, 0, "~b~Look!!~r~I can be colored ~y~too!!~w~", Color.FromArgb(150, 185, 230, 185), Color.FromArgb(170, 174, 219, 242));

        menu.AddItem(colorListItem);


        var SliderProgress = new UIMenuSliderProgressItem("Slider Progress Item", 10, 0);

        menu.AddItem(SliderProgress);

        var Progress = new UIMenuProgressItem("Progress Item", "descriptiom", 10, 0, true);

        menu.AddItem(Progress);

        var listPanelItem1 = new UIMenuListItem("Change Color", new List <object> {
            "Example", "example2"
        }, 0);
        var ColorPanel = new UIMenuColorPanel("Color Panel Example", UIMenuColorPanel.ColorPanelType.Hair);

        // you can choose between hair palette or makeup palette
        menu.AddItem(listPanelItem1);
        listPanelItem1.AddPanel(ColorPanel);

        var listPanelItem2 = new UIMenuListItem("Change Percentage", new List <object> {
            "Example", "example2"
        }, 0);
        var PercentagePanel = new UIMenuPercentagePanel("Percentage Panel Example", "0%", "100%");

        // You can change every text in this Panel
        menu.AddItem(listPanelItem2);
        listPanelItem2.AddPanel(PercentagePanel);

        var listPanelItem3 = new UIMenuListItem("Change Grid Position", new List <object> {
            "Example", "example2"
        }, 0);
        var GridPanel = new UIMenuGridPanel("Up", "Left", "Right", "Down", new System.Drawing.PointF(.5f, .5f));

        // you can choose the text in every position and where to place the starting position of the cirlce
        // the other 2 grids panel available are not listed as they work the same way but in only 2 direction (horizontally or vertically)
        // and to use them you must stream the stream folder provided with NativeUI project
        menu.AddItem(listPanelItem3);
        listPanelItem3.AddPanel(GridPanel);

        var listPanelItem4 = new UIMenuListItem("Look at Statistics", new List <object> {
            "Example", "example2"
        }, 0);
        var statistics = new UIMenuStatisticsPanel();

        statistics.AddStatistics("Look at this!");
        statistics.AddStatistics("I'm a statistic too!");
        statistics.AddStatistics("Am i not?!");
        //you can add as menu statistics you want
        statistics.SetPercentage(0, 10f);
        statistics.SetPercentage(1, 50f);
        statistics.SetPercentage(2, 100f);
        //and you can get / set their percentage
        menu.AddItem(listPanelItem4);
        listPanelItem4.AddPanel(statistics);

        // THERE ARE NO EVENTS FOR PANELS.. WHEN YOU CHANGE WHAT IS CHANGABLE THE LISTITEM WILL DO WHATEVER YOU TELL HIM TO DO

        menu.OnListChange += (sender, item, index) =>
        {
            if (item == listPanelItem1)
            {
                Screen.ShowNotification("Selected color " + ((item.Panels[0] as UIMenuColorPanel).CurrentSelection + 1) + "...");
                item.Description = "Selected color " + ((item.Panels[0] as UIMenuColorPanel).CurrentSelection + 1) + "...";
                item.Parent.UpdateDescription();                 // this is neat.. this will update the description of the item without refresh index.. try it by changing color
            }
            else if (item == listPanelItem2)
            {
                Screen.ShowSubtitle("Percentage = " + (item.Panels[0] as UIMenuPercentagePanel).Percentage + "...");
            }
            else if (item == listPanelItem3)
            {
                Screen.ShowSubtitle("GridPosition = " + (item.Panels[0] as UIMenuGridPanel).CirclePosition + "...");
            }
        };
    }
Example #10
0
        private void BuildMainMenu()
        {
            MainMenu = new TabView("Cherry Multiplayer")
            {
                CanLeave      = false,
                MoneySubtitle = "Cherry MP " + CurrentVersion
            };

            _mainMapItem = new TabMapItem();

            #region Welcome Screen
            {
                _welcomePage = new TabWelcomeMessageItem("Welcome to Cherry Multiplayer", "Development branch.");
                MainMenu.Tabs.Add(_welcomePage);
            }
            #endregion

            #region ServerBrowser
            {
                var dConnect = new TabButtonArrayItem("Quick Connect");

                {
                    var ipButton = new TabButton
                    {
                        Text = "IP Address",
                        Size = new Size(500, 40)
                    };
                    ipButton.Activated += (sender, args) =>
                    {
                        MainMenu.TemporarilyHidden = true;
                        var newIp = InputboxThread.GetUserInput(_clientIp ?? "", 30, TickSpinner);
                        _clientIp     = newIp;
                        ipButton.Text = string.IsNullOrWhiteSpace(newIp) ? "IP Address" : newIp;
                        MainMenu.TemporarilyHidden = false;
                    };
                    dConnect.Buttons.Add(ipButton);
                }

                {
                    var ipButton = new TabButton
                    {
                        Text = "Port",
                        Size = new Size(500, 40)
                    };
                    ipButton.Activated += (sender, args) =>
                    {
                        MainMenu.TemporarilyHidden = true;
                        var port = InputboxThread.GetUserInput(Port.ToString(), 30, TickSpinner);

                        if (string.IsNullOrWhiteSpace(port))
                        {
                            port = "4499";
                        }

                        if (!int.TryParse(port, out int newPort))
                        {
                            Util.Util.SafeNotify("Wrong port format!");
                            MainMenu.TemporarilyHidden = false;
                            return;
                        }
                        Port          = newPort;
                        ipButton.Text = Port.ToString();
                        MainMenu.TemporarilyHidden = false;
                    };
                    dConnect.Buttons.Add(ipButton);
                }

                {
                    var ipButton = new TabButton
                    {
                        Text = "Password",
                        Size = new Size(500, 40)
                    };
                    ipButton.Activated += (sender, args) =>
                    {
                        MainMenu.TemporarilyHidden = true;
                        var newIp = InputboxThread.GetUserInput("", 30, TickSpinner);
                        MainMenu.TemporarilyHidden = false;
                        _QCpassword   = newIp;
                        ipButton.Text = string.IsNullOrWhiteSpace(newIp) ? "Password" : "*******";
                    };
                    dConnect.Buttons.Add(ipButton);
                }

                {
                    var ipButton = new TabButton
                    {
                        Text = "Connect",
                        Size = new Size(500, 40)
                    };
                    ipButton.Activated += (sender, args) =>
                    {
                        var isPassworded = false;
                        if (!string.IsNullOrWhiteSpace(_QCpassword))
                        {
                            isPassworded = true;
                        }

                        AddServerToRecent(_clientIp + ":" + Port, _QCpassword);
                        ConnectToServer(_clientIp, Port, isPassworded, _QCpassword);
                        MainMenu.TemporarilyHidden = true;
                    };
                    dConnect.Buttons.Add(ipButton);
                }

                _Verified      = new TabInteractiveListItem("Verified", new List <UIMenuItem>());
                _serverBrowser = new TabInteractiveListItem("Internet", new List <UIMenuItem>());
                _favBrowser    = new TabInteractiveListItem("Favorites", new List <UIMenuItem>());
                _lanBrowser    = new TabInteractiveListItem("Local Network", new List <UIMenuItem>());
                _recentBrowser = new TabInteractiveListItem("Recent", new List <UIMenuItem>());

                _connectTab = new TabSubmenuItem("connect", new List <TabItem>()
                {
                    dConnect, _favBrowser, _Verified, _serverBrowser, _lanBrowser, _recentBrowser
                });

                MainMenu.AddTab(_connectTab);
                _connectTab.DrawInstructionalButtons += (sender, args) =>
                {
                    MainMenu.DrawInstructionalButton(4, Control.Jump, "Refresh");

                    if (Game.IsControlJustPressed(0, Control.Jump))
                    {
                        RebuildServerBrowser();
                    }
                    #region Verified, Iternet, LAN and Recent
                    if (_connectTab.Index == 2 && _connectTab.Items[2].Focused || _connectTab.Index == 3 && _connectTab.Items[3].Focused || _connectTab.Index == 4 && _connectTab.Items[4].Focused || _connectTab.Index == 5 && _connectTab.Items[5].Focused)
                    {
                        MainMenu.DrawInstructionalButton(5, Control.Enter, "Add to Favorites");
                        if (Game.IsControlJustPressed(0, Control.Enter))
                        {
                            var selectedServer = _serverBrowser.Items[_serverBrowser.Index];
                            if (_connectTab.Index == 2 && _connectTab.Items[2].Focused)
                            {
                                selectedServer = _Verified.Items[_Verified.Index];
                            }
                            else if (_connectTab.Index == 4 && _connectTab.Items[4].Focused)
                            {
                                selectedServer = _lanBrowser.Items[_lanBrowser.Index];
                            }
                            else if (_connectTab.Index == 5 && _connectTab.Items[5].Focused)
                            {
                                selectedServer = _recentBrowser.Items[_recentBrowser.Index];
                            }
                            selectedServer.SetRightBadge(UIMenuItem.BadgeStyle.None);
                            if (PlayerSettings.FavoriteServers.Contains(selectedServer.Description))
                            {
                                var favItem = _favBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description);
                                if (favItem != null)
                                {
                                    selectedServer.SetRightBadge(UIMenuItem.BadgeStyle.None);
                                    RemoveFromFavorites(selectedServer.Description);
                                    _favBrowser.Items.Remove(favItem);
                                    _favBrowser.RefreshIndex();
                                }
                            }
                            else
                            {
                                AddToFavorites(selectedServer.Description);
                                selectedServer.SetRightBadge(UIMenuItem.BadgeStyle.Star);
                                var item = new UIMenuItem(selectedServer.Text)
                                {
                                    Description = selectedServer.Description
                                };
                                item.SetRightLabel(selectedServer.RightLabel);
                                item.SetLeftBadge(selectedServer.LeftBadge);
                                item.Activated += (faf, selectedItem) =>
                                {
                                    if (IsOnServer())
                                    {
                                        Client.Disconnect("Switching servers");
                                        NetEntityHandler.ClearAll();

                                        if (Npcs != null)
                                        {
                                            Npcs.ToList().ForEach(pair => pair.Value.Clear());
                                            Npcs.Clear();
                                        }

                                        while (IsOnServer())
                                        {
                                            Script.Yield();
                                        }
                                    }
                                    bool pass = false;
                                    if (selectedServer.LeftBadge == UIMenuItem.BadgeStyle.Lock)
                                    {
                                        pass = true;
                                    }

                                    var splt = selectedServer.Description.Split(':');

                                    if (splt.Length < 2)
                                    {
                                        return;
                                    }
                                    if (!int.TryParse(splt[1], out int port))
                                    {
                                        return;
                                    }

                                    ConnectToServer(splt[0], port, pass);
                                    MainMenu.TemporarilyHidden = true;
                                    _connectTab.RefreshIndex();
                                };
                                _favBrowser.Items.Add(item);
                            }
                        }
                    }
                    #endregion

                    #region Favorites
                    if (_connectTab.Index == 1 && _connectTab.Items[1].Focused)
                    {
                        MainMenu.DrawInstructionalButton(6, Control.NextCamera, "Add Server");

                        #region Add server
                        if (Game.IsControlJustPressed(0, Control.NextCamera))
                        {
                            MainMenu.TemporarilyHidden = true;
                            var serverIp = InputboxThread.GetUserInput("Server IP(:Port)", 40, TickSpinner);

                            if (serverIp.Contains("Server IP(:Port)") || string.IsNullOrWhiteSpace(serverIp))
                            {
                                Util.Util.SafeNotify("Incorrect input!");
                                MainMenu.TemporarilyHidden = false;
                                return;
                            }
                            else if (!serverIp.Contains(":"))
                            {
                                serverIp += ":4499";
                            }
                            MainMenu.TemporarilyHidden = false;

                            if (!PlayerSettings.FavoriteServers.Contains(serverIp))
                            {
                                AddToFavorites(serverIp);
                                var item = new UIMenuItem(serverIp)
                                {
                                    Description = serverIp
                                };
                                _favBrowser.Items.Add(item);
                            }
                            else
                            {
                                Util.Util.SafeNotify("Server already on the list");
                                return;
                            }
                        }
                        #endregion

                        MainMenu.DrawInstructionalButton(5, Control.Enter, "Remove");

                        #region Remove
                        if (Game.IsControlJustPressed(0, Control.Enter))
                        {
                            var selectedServer = _favBrowser.Items[_favBrowser.Index];
                            var favItem        = _favBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description);

                            if (_Verified.Items.FirstOrDefault(i => i.Description == selectedServer.Description) != null)
                            {
                                _Verified.Items.FirstOrDefault(i => i.Description == selectedServer.Description).SetRightBadge(UIMenuItem.BadgeStyle.None);
                            }

                            if (_serverBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description) != null)
                            {
                                _serverBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description).SetRightBadge(UIMenuItem.BadgeStyle.None);
                            }

                            if (_lanBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description) != null)
                            {
                                _lanBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description).SetRightBadge(UIMenuItem.BadgeStyle.None);
                            }

                            if (_recentBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description) != null)
                            {
                                _recentBrowser.Items.FirstOrDefault(i => i.Description == selectedServer.Description).SetRightBadge(UIMenuItem.BadgeStyle.None);
                            }

                            if (favItem != null)
                            {
                                Util.Util.SafeNotify("Server removed from Favorites!");
                                RemoveFromFavorites(selectedServer.Description);
                                _favBrowser.Items.Remove(favItem);
                                _favBrowser.RefreshIndex();
                            }
                        }
                        #endregion
                    }
                    #endregion
                };
                CherryDiscord.CherryDiscord.InMenuDiscordInitialize(CurrentVersion.ToString());
                CherryDiscord.CherryDiscord.InMenuDiscordUpdatePresence();
            }
            #endregion

            #region Settings
            {
                #region General Menu
                var GeneralMenu = new TabInteractiveListItem("General", new List <UIMenuItem>());
                {
                    var nameItem = new UIMenuItem("Display Name");
                    nameItem.SetRightLabel(PlayerSettings.DisplayName);
                    nameItem.Activated += (sender, item) =>
                    {
                        if (IsOnServer())
                        {
                            GTA.UI.Screen.ShowNotification("You cannot change your Display Name while connected to a server.");
                            return;
                        }
                        MainMenu.TemporarilyHidden = true;
                        var newName = InputboxThread.GetUserInput(PlayerSettings.DisplayName ?? "Enter a new Display Name", 32, TickSpinner);
                        if (!string.IsNullOrWhiteSpace(newName))
                        {
                            if (newName.Length > 32)
                            {
                                newName = newName.Substring(0, 32);
                            }

                            newName = newName.Replace(' ', '_');

                            PlayerSettings.DisplayName = newName;
                            SaveSettings();
                            nameItem.SetRightLabel(newName);
                        }
                        MainMenu.TemporarilyHidden = false;
                    };

                    GeneralMenu.Items.Add(nameItem);
                }
                {
                    var debugItem = new UIMenuCheckboxItem("Show Game FPS Counter", PlayerSettings.ShowFPS);
                    debugItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.ShowFPS = @checked;
                        DebugInfo.FPS          = @checked;
                        SaveSettings();
                    };
                    GeneralMenu.Items.Add(debugItem);
                }
                {
                    var debugItem = new UIMenuCheckboxItem("Disable Rockstar Editor", PlayerSettings.DisableRockstarEditor);
                    debugItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.DisableRockstarEditor = @checked;
                        SaveSettings();
                    };
                    GeneralMenu.Items.Add(debugItem);
                }
                {
                    var debugItem = new UIMenuCheckboxItem("Allow Webcam/Microphone Streaming (Requires restart)", PlayerSettings.MediaStream);
                    debugItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.MediaStream = @checked;
                        SaveSettings();
                    };
                    GeneralMenu.Items.Add(debugItem);
                }
                {
                    var nameItem = new UIMenuItem("Update Channel");
                    nameItem.SetRightLabel(PlayerSettings.UpdateChannel);
                    nameItem.Activated += (sender, item) =>
                    {
                        MainMenu.TemporarilyHidden = true;
                        var newName = InputboxThread.GetUserInput(PlayerSettings.UpdateChannel ?? "stable", 40, TickSpinner);
                        if (!string.IsNullOrWhiteSpace(newName))
                        {
                            PlayerSettings.UpdateChannel = newName;
                            SaveSettings();
                            nameItem.SetRightLabel(newName);
                        }
                        MainMenu.TemporarilyHidden = false;
                    };

                    GeneralMenu.Items.Add(nameItem);
                }
                #endregion

                #region Chat
                var ChatboxMenu = new TabInteractiveListItem("Chat", new List <UIMenuItem>());

                {
                    var chatItem = new UIMenuCheckboxItem("Enable Timestamp", PlayerSettings.Timestamp);
                    chatItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.Timestamp = @checked;
                        SaveSettings();
                    };
                    ChatboxMenu.Items.Add(chatItem);
                }
                {
                    var chatItem = new UIMenuCheckboxItem("Use Military Time", PlayerSettings.Militarytime);
                    chatItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.Militarytime = @checked;
                        SaveSettings();
                    };
                    ChatboxMenu.Items.Add(chatItem);
                }
                {
                    var chatItem = new UIMenuCheckboxItem("Scale Chatbox With Safezone", PlayerSettings.ScaleChatWithSafezone);
                    chatItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.ScaleChatWithSafezone = @checked;
                        SaveSettings();
                    };
                    ChatboxMenu.Items.Add(chatItem);
                }

                {
                    var chatItem = new UIMenuItem("Horizontal Chatbox Offset");
                    chatItem.SetRightLabel(PlayerSettings.ChatboxXOffset.ToString());
                    chatItem.Activated += (sender, item) =>
                    {
                        MainMenu.TemporarilyHidden = true;
                        var strInput = InputboxThread.GetUserInput(PlayerSettings.ChatboxXOffset.ToString(),
                                                                   10, TickSpinner);

                        if (!int.TryParse(strInput, out int newSetting))
                        {
                            Util.Util.SafeNotify("Input was not in the correct format.");
                            MainMenu.TemporarilyHidden = false;
                            return;
                        }
                        MainMenu.TemporarilyHidden    = false;
                        PlayerSettings.ChatboxXOffset = newSetting;
                        chatItem.SetRightLabel(PlayerSettings.ChatboxXOffset.ToString());
                        SaveSettings();
                    };
                    ChatboxMenu.Items.Add(chatItem);
                }

                {
                    var chatItem = new UIMenuItem("Vertical Chatbox Offset");
                    chatItem.SetRightLabel(PlayerSettings.ChatboxYOffset.ToString());
                    chatItem.Activated += (sender, item) =>
                    {
                        MainMenu.TemporarilyHidden = true;
                        var strInput = InputboxThread.GetUserInput(PlayerSettings.ChatboxYOffset.ToString(),
                                                                   10, TickSpinner);

                        if (!int.TryParse(strInput, out int newSetting))
                        {
                            Util.Util.SafeNotify("Input was not in the correct format.");
                            MainMenu.TemporarilyHidden = false;
                            return;
                        }
                        MainMenu.TemporarilyHidden    = false;
                        PlayerSettings.ChatboxYOffset = newSetting;
                        chatItem.SetRightLabel(PlayerSettings.ChatboxYOffset.ToString());
                        SaveSettings();
                    };
                    ChatboxMenu.Items.Add(chatItem);
                }

                {
                    var chatItem = new UIMenuCheckboxItem("Use Classic Chatbox", PlayerSettings.UseClassicChat);
                    chatItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.UseClassicChat = @checked;
                        SaveSettings();
                    };
                    ChatboxMenu.Items.Add(chatItem);
                }
                #endregion

                #region Experimental
                var ExpMenu = new TabInteractiveListItem("Experimental", new List <UIMenuItem>());
                {
                    var expItem = new UIMenuCheckboxItem("Disable Chromium Embedded Framework (Requires restart)", PlayerSettings.DisableCEF);
                    expItem.CheckboxEvent += (sender, @checked) =>
                    {
                        PlayerSettings.DisableCEF = @checked;
                        SaveSettings();
                    };
                    ExpMenu.Items.Add(expItem);
                }
                #endregion

                #region Debug Menu
                var DebugMenu = new TabInteractiveListItem("Debug", new List <UIMenuItem>());
                {
                    {
                        var expItem = new UIMenuCheckboxItem("Enable CEF Development Tools (http://localhost:9222) [Restart required]", PlayerSettings.CEFDevtool);
                        expItem.CheckboxEvent += (sender, @checked) =>
                        {
                            PlayerSettings.CEFDevtool = @checked;
                            SaveSettings();
                        };
                        DebugMenu.Items.Add(expItem);
                    }

                    {
                        var expItem = new UIMenuCheckboxItem("Enable Debug mode (Requires an extra tool)", PlayerSettings.DebugMode);
                        expItem.CheckboxEvent += (sender, @checked) =>
                        {
                            PlayerSettings.DebugMode = @checked;
                            SaveSettings();
                        };
                        DebugMenu.Items.Add(expItem);
                    }

                    {
                        var expItem = new UIMenuCheckboxItem("Save Debug to File (Huge performance impact)", SaveDebugToFile);
                        expItem.CheckboxEvent += (sender, @checked) =>
                        {
                            SaveDebugToFile = @checked;
                            SaveSettings();
                        };
                        DebugMenu.Items.Add(expItem);
                    }

                    {
                        var debugItem = new UIMenuCheckboxItem("Remove Game Entities", RemoveGameEntities);
                        debugItem.CheckboxEvent += (sender, @checked) =>
                        {
                            RemoveGameEntities = @checked;
                        };
                        DebugMenu.Items.Add(debugItem);
                    }

                    {
                        var debugItem = new UIMenuCheckboxItem("Show Streamer Debug Data", DebugInfo.StreamerDebug);
                        debugItem.CheckboxEvent += (sender, @checked) =>
                        {
                            DebugInfo.StreamerDebug = @checked;
                        };
                        DebugMenu.Items.Add(debugItem);
                    }

                    {
                        var debugItem = new UIMenuCheckboxItem("Disable Nametag Draw", ToggleNametagDraw);
                        debugItem.CheckboxEvent += (sender, @checked) =>
                        {
                            ToggleNametagDraw = @checked;
                        };
                        DebugMenu.Items.Add(debugItem);
                    }

                    {
                        var debugItem = new UIMenuCheckboxItem("Disable Position Update", TogglePosUpdate);
                        debugItem.CheckboxEvent += (sender, @checked) =>
                        {
                            TogglePosUpdate = @checked;
                        };
                        DebugMenu.Items.Add(debugItem);
                    }
                }
                #endregion

                var welcomeItem = new TabSubmenuItem("settings", new List <TabItem>()
                {
                    GeneralMenu,
                    ChatboxMenu,
                    //DisplayMenu,
                    //GraphicsMenu,
                    ExpMenu,
                    DebugMenu
                });
                MainMenu.AddTab(welcomeItem);
            }
            #endregion

            #region Quit
            {
                var welcomeItem = new TabTextItem("Quit", "Quit Cherry Multiplayer", "Are you sure you want to quit Cherry Multiplayer and return to desktop?")
                {
                    CanBeFocused = false
                };
                welcomeItem.Activated += (sender, args) =>
                {
                    if (Client != null && IsOnServer())
                    {
                        Client.Disconnect("Quit");
                    }
                    CEFManager.Dispose();
                    CEFManager.DisposeCef();
                    Script.Wait(500);
                    //Environment.Exit(0);
                    Process.GetProcessesByName("GTA5")[0].Kill();
                    Process.GetCurrentProcess().Kill();
                };
                MainMenu.Tabs.Add(welcomeItem);
            }
            #endregion

            #region Current Server Tab

            #region Players
            _serverPlayers = new TabItemSimpleList("Players", new Dictionary <string, string>());
            #endregion

            var favTab = new TabTextItem("Favorite", "Add to Favorites", "Add the current server to favorites.")
            {
                CanBeFocused = false
            };
            favTab.Activated += (sender, args) =>
            {
                var serb = _currentServerIp + ":" + _currentServerPort;
                AddToFavorites(_currentServerIp + ":" + _currentServerPort);
                var item = new UIMenuItem(serb)
                {
                    Description = serb
                };
                Util.Util.SafeNotify("Server added to favorites!");
                item.Activated += (faf, selectedItem) =>
                {
                    if (IsOnServer())
                    {
                        Client.Disconnect("Switching servers");

                        NetEntityHandler.ClearAll();

                        if (Npcs != null)
                        {
                            Npcs.ToList().ForEach(pair => pair.Value.Clear());
                            Npcs.Clear();
                        }

                        while (IsOnServer())
                        {
                            Script.Yield();
                        }
                    }

                    var splt = serb.Split(':');

                    if (splt.Length < 2)
                    {
                        return;
                    }
                    if (!int.TryParse(splt[1], out int port))
                    {
                        return;
                    }

                    ConnectToServer(splt[0], port);
                    MainMenu.TemporarilyHidden = true;
                    _connectTab.RefreshIndex();
                    AddServerToRecent(serb, "");
                };
                _favBrowser.Items.Add(item);
            };

            var dcItem = new TabTextItem("Disconnect", "Disconnect", "Disconnect from the current server.")
            {
                CanBeFocused = false
            };
            dcItem.Activated += (sender, args) =>
            {
                if (Client != null)
                {
                    Client.Disconnect("Quit");
                }
            };

            _statsItem = new TabTextItem("Statistics", "Network Statistics", "")
            {
                CanBeFocused = false
            };

            _serverItem = new TabSubmenuItem("server", new List <TabItem>()
            {
                _serverPlayers, favTab, _statsItem, dcItem
            })
            {
                Parent = MainMenu
            };
            #endregion

            MainMenu.RefreshIndex();
        }
Example #11
0
        /// <summary>
        /// Refresh/create the ped customization menu.
        /// </summary>
        private void RefreshCustomizationMenu()
        {
            // Remove any old items.
            pedTextures.MenuItems.Clear();

            #region Loop through all ped drawable variations and all ped props.
            for (var i = 0; i < 17; i++)
            {
                #region Ped Drawable Variations
                //if (i < 12)
                if (i < 12)
                {
                    // Get the drawable information.
                    var currentDrawable = GetPedDrawableVariation(PlayerPedId(), i);
                    var variations      = GetNumberOfPedDrawableVariations(PlayerPedId(), i);
                    var textures        = GetNumberOfPedTextureVariations(PlayerPedId(), i, currentDrawable);
                    // If there are any variations.
                    if (variations > 0)
                    {
                        // Loop through all of them and add them to the list.
                        var textureList = new List <dynamic>();
                        for (var x = 0; x < variations; x++)
                        {
                            textureList.Add("Item #" + x.ToString());
                        }
                        UIMenuListItem listItem = new UIMenuListItem($"{textureNames[i]}", textureList, currentDrawable,
                                                                     $"Use ← & → to select a ~o~{textureNames[i]} Variation~s~, press ~r~enter~s~ to cycle through the available textures.");
                        pedTextures.AddItem(listItem);

                        // Manage list changes.
                        pedTextures.OnListChange += (sender2, item2, index2) =>
                        {
                            if (item2 == listItem)
                            {
                                SetPedComponentVariation(PlayerPedId(), sender2.CurrentSelection, index2, 0, 0);
                            }
                        };

                        // Manage list selections.
                        pedTextures.OnListSelect += (sender2, item2, index2) =>
                        {
                            if (item2 == listItem)
                            {
                                var currentTexture = GetPedTextureVariation(PlayerPedId(), sender2.CurrentSelection);
                                currentTexture = currentTexture == -1 ? 0 : currentTexture;
                                var totalTextures = GetNumberOfPedTextureVariations(PlayerPedId(), sender2.CurrentSelection, index2) - 1;

                                SetPedComponentVariation(PlayerPedId(), sender2.CurrentSelection, index2, (currentTexture < totalTextures ? currentTexture + 1 : 0), 0);
                            }
                        };
                    }
                    else
                    {
                        UIMenuItem placeholder = new UIMenuItem($"{textureNames[i]}");
                        placeholder.SetRightLabel("None");
                        placeholder.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                        placeholder.Enabled = false;
                        pedTextures.AddItem(placeholder);
                    }
                }
                #endregion
                #region Ped Props
                else
                {
                    // Variables setup.
                    var ii = i - 12;// 20;
                    if (ii > 2)
                    {
                        ii += 3;
                    }
                    var currentProp = GetPedPropIndex(PlayerPedId(), ii);
                    var props       = GetNumberOfPedPropDrawableVariations(PlayerPedId(), ii);
                    // If there are any props.
                    if (props > 0)
                    {
                        // Loop through all of them and add them to lists.
                        var propsList = new List <dynamic>();
                        for (var x = 0; x < props; x++)
                        {
                            propsList.Add("Item #" + x.ToString());
                        }

                        // Add an "off" item to the list to allow the prop to be turned off.
                        propsList.Add("Off");

                        // Create and add the list item to the menu.
                        UIMenuListItem listItem = new UIMenuListItem($"{propNames[ii > 2 ? ii - 3 : ii]}", propsList, currentProp,
Example #12
0
        /// <summary>
        /// Creates the menu(s).
        /// </summary>
        private void CreateMenu()
        {
            // Create the menu.
            menu = new UIMenu(GetPlayerName(PlayerId()), "Player Appearance", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            //Create the submenus.
            spawnSavedPedMenu = new UIMenu("Saved Peds", "Spawn a saved ped", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            deleteSavedPedMenu = new UIMenu("Saved Peds", "Delete a saved ped", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            pedTextures = new UIMenu("Ped Customization", "Customize your ped", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            // Add the (submenus) to the menu pool.
            MainMenu.Mp.Add(pedTextures);
            MainMenu.Mp.Add(spawnSavedPedMenu);
            MainMenu.Mp.Add(deleteSavedPedMenu);

            // Create the menu items.
            UIMenuItem pedCustomization = new UIMenuItem("Ped Customization", "Modify your ped's appearance.");

            pedCustomization.SetRightLabel("→→→");
            UIMenuItem savePed = new UIMenuItem("Save Current Ped", "Save your current ped and clothes.");

            savePed.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
            UIMenuItem spawnSavedPed = new UIMenuItem("Spawn Saved Ped", "Spawn one of your saved peds.");

            spawnSavedPed.SetRightLabel("→→→");
            UIMenuItem deleteSavedPed = new UIMenuItem("Delete Saved Ped", "Delete one of your saved peds.");

            deleteSavedPed.SetRightLabel("→→→");
            deleteSavedPed.SetLeftBadge(UIMenuItem.BadgeStyle.Alert);

            // Add items to the mneu.
            menu.AddItem(pedCustomization);
            menu.AddItem(savePed);
            menu.AddItem(spawnSavedPed);
            menu.AddItem(deleteSavedPed);

            // Bind items to the submenus.
            if (cf.IsAllowed(Permission.PACustomize))
            {
                menu.BindMenuToItem(pedTextures, pedCustomization);
            }
            else
            {
                pedCustomization.Enabled = false;
                pedCustomization.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                pedCustomization.Description = "This option has been disabled by the server owner.";
            }


            if (cf.IsAllowed(Permission.PASpawnSaved))
            {
                menu.BindMenuToItem(spawnSavedPedMenu, spawnSavedPed);
            }
            else
            {
                spawnSavedPed.Enabled = false;
                spawnSavedPed.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                spawnSavedPed.Description = "This option has been disabled by the server owner.";
            }

            menu.BindMenuToItem(deleteSavedPedMenu, deleteSavedPed);

            // Handle button presses.
            menu.OnItemSelect += (sender, item, index) =>
            {
                if (item == pedCustomization)
                {
                    RefreshCustomizationMenu();
                }
                else if (item == spawnSavedPed)
                {
                    RefreshSpawnSavedPedMenu();
                }
                else if (item == deleteSavedPed)
                {
                    RefreshDeleteSavedPedMenu();
                }
                else if (item == savePed)
                {
                    cf.SavePed();
                }
            };

            // Loop through all the modelNames and create lists of max 50 ped names each.
            for (int i = 0; i < (modelNames.Count / 50) + 1; i++)
            {
                List <dynamic> pedList = new List <dynamic>();
                for (int ii = 0; ii < 50; ii++)
                {
                    int index = ((i * 50) + ii);
                    if (index >= modelNames.Count)
                    {
                        break;
                    }
                    int max = ((modelNames.Count / 50) != i) ? 50 : modelNames.Count % 50;
                    pedList.Add(modelNames[index] + $" ({(ii + 1).ToString()}/{max.ToString()})");
                }
                UIMenuListItem pedl = new UIMenuListItem("Peds #" + (i + 1).ToString(), pedList, 0);

                menu.AddItem(pedl);
                if (!cf.IsAllowed(Permission.PASpawnNew))
                {
                    pedl.Enabled = false;
                    pedl.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                    pedl.Description = "This option has been disabled by the server owner.";
                }
            }

            // Handle list selections.
            menu.OnListSelect += (sender, item, index) =>
            {
                int    i         = ((sender.CurrentSelection - 4) * 50) + index;
                string modelName = modelNames[i];
                if (cf.IsAllowed(Permission.PASpawnNew))
                {
                    cf.SetPlayerSkin(modelName);
                }
            };
        }
Example #13
0
        /// <summary>
        /// Creates the menu(s).
        /// </summary>
        private void CreateMenu()
        {
            // Create the menu.
            menu = new UIMenu(GetPlayerName(PlayerId()), "Player Appearance", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            //Create the submenus.
            spawnSavedPedMenu = new UIMenu("Saved Peds", "Spawn a saved ped", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            deleteSavedPedMenu = new UIMenu("Saved Peds", "Delete a saved ped", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            pedTextures = new UIMenu("Ped Customization", "Customize your ped", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            // Add the (submenus) to the menu pool.
            MainMenu.Mp.Add(pedTextures);
            MainMenu.Mp.Add(spawnSavedPedMenu);
            MainMenu.Mp.Add(deleteSavedPedMenu);

            // Create the menu items.
            UIMenuItem pedCustomization = new UIMenuItem("Ped Customization", "Modify your ped's appearance.");

            pedCustomization.SetRightLabel("→→→");
            UIMenuItem savePed = new UIMenuItem("Save Current Ped", "Save your current ped and clothes.");

            savePed.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
            UIMenuItem spawnSavedPed = new UIMenuItem("Spawn Saved Ped", "Spawn one of your saved peds.");

            spawnSavedPed.SetRightLabel("→→→");
            UIMenuItem deleteSavedPed = new UIMenuItem("Delete Saved Ped", "Delete one of your saved peds.");

            deleteSavedPed.SetRightLabel("→→→");
            deleteSavedPed.SetLeftBadge(UIMenuItem.BadgeStyle.Alert);
            UIMenuItem     spawnByName = new UIMenuItem("Spawn Ped By Name", "Enter a model name of a custom ped you want to spawn.");
            List <dynamic> walkstyles  = new List <dynamic>()
            {
                "Normal", "Injured", "Tough Guy", "Femme", "Gangster", "Posh", "Sexy", "Business", "Drunk", "Hipster"
            };
            UIMenuListItem walkingStyle = new UIMenuListItem("Walking Style", walkstyles, 0, "Change the walking style of your current ped. " +
                                                             "You need to re-apply this each time you change player model or load a saved ped.");

            // Add items to the mneu.
            menu.AddItem(pedCustomization);
            menu.AddItem(savePed);
            menu.AddItem(spawnSavedPed);
            menu.AddItem(deleteSavedPed);
            menu.AddItem(walkingStyle);



            // Bind items to the submenus.
            if (cf.IsAllowed(Permission.PACustomize))
            {
                menu.BindMenuToItem(pedTextures, pedCustomization);
            }
            else
            {
                pedCustomization.Enabled = false;
                pedCustomization.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                pedCustomization.Description = "This option has been disabled by the server owner.";
            }

            if (cf.IsAllowed(Permission.PASpawnSaved))
            {
                menu.BindMenuToItem(spawnSavedPedMenu, spawnSavedPed);
            }
            else
            {
                spawnSavedPed.Enabled = false;
                spawnSavedPed.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                spawnSavedPed.Description = "This option has been disabled by the server owner.";
            }

            menu.BindMenuToItem(deleteSavedPedMenu, deleteSavedPed);

            UIMenu addonPeds = new UIMenu("Model Spawner", "Spawn Addon Ped", true)
            {
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false,
                ScaleWithSafezone       = false
            };

            UIMenuItem addonPedsBtn = new UIMenuItem("Addon Peds", "Choose a player skin from the addons list available on this server.");

            menu.AddItem(addonPedsBtn);
            MainMenu.Mp.Add(addonPeds);

            if (AddonPeds != null)
            {
                if (AddonPeds.Count > 0)
                {
                    addonPedsBtn.SetRightLabel("→→→");
                    foreach (KeyValuePair <string, uint> ped in AddonPeds)
                    {
                        var button = new UIMenuItem(ped.Key, "Click to use this ped.");
                        addonPeds.AddItem(button);
                        if (!IsModelAPed(ped.Value) || !IsModelInCdimage(ped.Value))
                        {
                            button.Enabled = false;
                            button.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                            button.Description = "This ped is not available on this server. Are you sure the model is valid?";
                        }
                    }
                    addonPeds.OnItemSelect += (sender, item, index) =>
                    {
                        if (item.Enabled)
                        {
                            cf.SetPlayerSkin(AddonPeds.ElementAt(index).Value);
                        }
                        else
                        {
                            Notify.Error("This ped is not available. Please ask the server owner to verify this addon ped.");
                        }
                    };
                    menu.BindMenuToItem(addonPeds, addonPedsBtn);
                }
                else
                {
                    addonPedsBtn.Enabled     = false;
                    addonPedsBtn.Description = "This server does not have any addon peds available.";
                    addonPedsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                }
            }
            else
            {
                addonPedsBtn.Enabled     = false;
                addonPedsBtn.Description = "This server does not have any addon peds available.";
                addonPedsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
            }

            addonPeds.RefreshIndex();
            addonPeds.UpdateScaleform();

            // Add the spawn by name button after the addon peds menu item.
            menu.AddItem(spawnByName);

            // Handle button presses.
            menu.OnItemSelect += (sender, item, index) =>
            {
                if (item == pedCustomization)
                {
                    RefreshCustomizationMenu();
                }
                else if (item == spawnSavedPed)
                {
                    RefreshSpawnSavedPedMenu();
                }
                else if (item == deleteSavedPed)
                {
                    RefreshDeleteSavedPedMenu();
                }
                else if (item == savePed)
                {
                    cf.SavePed();
                }
                else if (item == spawnByName)
                {
                    cf.SpawnPedByName();
                }
            };

            // Loop through all the modelNames and create lists of max 50 ped names each.
            for (int i = 0; i < (modelNames.Count / 50) + 1; i++)
            {
                List <dynamic> pedList = new List <dynamic>();
                for (int ii = 0; ii < 50; ii++)
                {
                    int index = ((i * 50) + ii);
                    if (index >= modelNames.Count)
                    {
                        break;
                    }
                    int max = ((modelNames.Count / 50) != i) ? 50 : modelNames.Count % 50;
                    pedList.Add(modelNames[index] + $" ({(ii + 1).ToString()}/{max.ToString()})");
                }
                UIMenuListItem pedl = new UIMenuListItem("Peds #" + (i + 1).ToString(), pedList, 0);

                menu.AddItem(pedl);
                if (!cf.IsAllowed(Permission.PASpawnNew))
                {
                    pedl.Enabled = false;
                    pedl.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                    pedl.Description = "This option has been disabled by the server owner.";
                }
            }

            // Handle list selections.
            menu.OnListSelect += (sender, item, index) =>
            {
                if (item == walkingStyle)
                {
                    Subtitle.Custom("Ped is: " + IsPedMale(PlayerPedId()));
                    cf.SetWalkingStyle(walkstyles[index].ToString());
                }
                else
                {
                    int    i         = ((sender.CurrentSelection - 7) * 50) + index;
                    string modelName = modelNames[i];
                    if (cf.IsAllowed(Permission.PASpawnNew))
                    {
                        cf.SetPlayerSkin(modelName);
                    }
                }
            };
        }
Example #14
0
        public void UpgradesMenu_ItemSelected(UIMenu menu, UIMenuItem selectedItem, int index)
        {
            if (InsideMethLabIdx == -1)
            {
                return;
            }

            switch (index)
            {
            case 0:
                if (Game.Player.Money < EquipmentUpgradePrice)
                {
                    UI.Notify("You don't have enough money to buy the equipment upgrade.");
                    return;
                }

                if (MethLabs[InsideMethLabIdx].HasFlag(LabFlags.HasEquipmentUpgrade))
                {
                    UI.Notify("This meth lab already has the equipment upgrade.");
                    return;
                }

                MethLabs[InsideMethLabIdx].AddFlag(LabFlags.HasEquipmentUpgrade);
                Save();

                Function.Call(Hash._DISABLE_INTERIOR_PROP, LabInteriorID, "meth_lab_basic");
                Function.Call(Hash._ENABLE_INTERIOR_PROP, LabInteriorID, "meth_lab_upgrade");
                Function.Call(Hash.REFRESH_INTERIOR, LabInteriorID);

                Function.Call(Hash.SET_AMBIENT_ZONE_STATE, "AZ_DLC_Biker_Meth_Warehouse_Normal", false, true);
                Function.Call(Hash.SET_AMBIENT_ZONE_STATE, "AZ_DLC_Biker_Meth_Warehouse_Upgraded", true, true);

                selectedItem.SetLeftBadge(UIMenuItem.BadgeStyle.Tick);
                selectedItem.Enabled = false;

                Game.Player.Money -= EquipmentUpgradePrice;
                Util.NotifyWithPicture("LJT", $"{Util.GetCharacterFromModel(Game.Player.Character.Model.Hash)}, good call getting the equipment upgrade. This will surely boost the lab's performance.", "CHAR_LJT", 1);
                break;

            case 1:
                if (Game.Player.Money < StaffUpgradePrice)
                {
                    UI.Notify("You don't have enough money to buy the staff upgrade.");
                    return;
                }

                if (MethLabs[InsideMethLabIdx].HasFlag(LabFlags.HasStaffUpgrade))
                {
                    UI.Notify("This meth lab already has the staff upgrade.");
                    return;
                }

                MethLabs[InsideMethLabIdx].AddFlag(LabFlags.HasStaffUpgrade);
                Save();

                selectedItem.SetLeftBadge(UIMenuItem.BadgeStyle.Tick);
                selectedItem.Enabled = false;

                Game.Player.Money -= StaffUpgradePrice;
                Util.NotifyWithPicture("LJT", $"{Util.GetCharacterFromModel(Game.Player.Character.Model.Hash)}, good call getting the staff upgrade. This will surely boost the lab's performance.", "CHAR_LJT", 1);
                break;

            case 2:
                if (Game.Player.Money < SecurityUpgradePrice)
                {
                    UI.Notify("You don't have enough money to buy the security upgrade.");
                    return;
                }

                if (MethLabs[InsideMethLabIdx].HasFlag(LabFlags.HasSecurityUpgrade))
                {
                    UI.Notify("This meth lab already has the security upgrade.");
                    return;
                }

                MethLabs[InsideMethLabIdx].AddFlag(LabFlags.HasSecurityUpgrade);
                Save();

                MethLabEntities.Add(Util.CreateSecurityPed());
                Function.Call(Hash._ENABLE_INTERIOR_PROP, LabInteriorID, "meth_lab_security_high");
                Function.Call(Hash.REFRESH_INTERIOR, LabInteriorID);

                selectedItem.SetLeftBadge(UIMenuItem.BadgeStyle.Tick);
                selectedItem.Enabled = false;

                Game.Player.Money -= SecurityUpgradePrice;
                Util.NotifyWithPicture("LJT", $"{Util.GetCharacterFromModel(Game.Player.Character.Model.Hash)}, good call getting the security upgrade. This will surely set the workers with doubts straight.", "CHAR_LJT", 1);
                break;
            }
        }
        private void CreateMenu()
        {
            //VehicleData vd = new VehicleData();
            #region initial setup.


            // Create the menu.
            menu = new UIMenu("BigFam Crew", "Vehicle Spawner", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            // Create the buttons and checkboxes.
            UIMenuItem         spawnByName = new UIMenuItem("Spawn Vehicle By Model Name", "Enter the name of a vehicle to spawn.");
            UIMenuCheckboxItem spawnInVeh  = new UIMenuCheckboxItem("Spawn Inside Vehicle", SpawnInVehicle,
                                                                    "This will teleport you into the vehicle when you spawn it.");
            UIMenuCheckboxItem replacePrev = new UIMenuCheckboxItem("Replace Previous Vehicle", ReplaceVehicle,
                                                                    "This will automatically delete your previously spawned vehicle when you spawn a new vehicle.");

            // Add the items to the menu.
            if (cf.IsAllowed(Permission.VSSpawnByName))
            {
                // menu.AddItem(spawnByName);
            }
            //menu.AddItem(spawnInVeh);
            //menu.AddItem(replacePrev);
            #endregion

            #region addon cars menu
            // Vehicle Addons List
            UIMenu addonCarsMenu = new UIMenu("Addon Vehicles", "Spawn An Addon Vehicle", true)
            {
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false,
                ScaleWithSafezone       = false
            };
            UIMenuItem addonCarsBtn = new UIMenuItem("Addon Vehicles", "A list of addon vehicles available on this server.");
            addonCarsBtn.SetRightLabel("→→→");

            menu.AddItem(addonCarsBtn);

            if (cf.IsAllowed(Permission.VSAddon))
            {
                if (AddonVehicles != null)
                {
                    if (AddonVehicles.Count > 0)
                    {
                        menu.BindMenuToItem(addonCarsMenu, addonCarsBtn);
                        MainMenu.Mp.Add(addonCarsMenu);
                        foreach (KeyValuePair <string, uint> veh in AddonVehicles)
                        {
                            string localizedName = GetLabelText(GetDisplayNameFromVehicleModel(veh.Value));
                            string name          = localizedName != "NULL" ? localizedName : GetDisplayNameFromVehicleModel(veh.Value);
                            name = name != "CARNOTFOUND" ? name : veh.Key;
                            UIMenuItem carBtn = new UIMenuItem(name, $"Click to spawn {name}.");
                            carBtn.SetRightLabel($"({veh.Key.ToString()})");
                            if (!IsModelInCdimage(veh.Value))
                            {
                                carBtn.Enabled     = false;
                                carBtn.Description = "This vehicle is not available. Please ask the server owner to check if the vehicle is being streamed correctly.";
                                carBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                            }
                            addonCarsMenu.AddItem(carBtn);
                        }

                        /*
                         * //AddonVehicles.ToList();
                         * List<UIMenuItem> buttonsList = new List<UIMenuItem> { };
                         * menu.BindMenuToItem(addonCarsMenu, addonCarsBtn);
                         * MainMenu.Mp.Add(addonCarsMenu);
                         * foreach (KeyValuePair<string, uint> veh in AddonVehicles)
                         * {
                         *  string localizedName = GetLabelText(GetDisplayNameFromVehicleModel(veh.Value));
                         *  string name = localizedName != "NULL" ? localizedName : GetDisplayNameFromVehicleModel(veh.Value);
                         *  name = name != "CARNOTFOUND" ? name : veh.Key;
                         *  UIMenuItem carBtn = new UIMenuItem(name, $"Click to spawn {name}.");
                         *  carBtn.SetRightLabel($"({veh.Key.ToString()})");
                         *  if (!IsModelInCdimage(veh.Value))
                         *  {
                         *      carBtn.Enabled = false;
                         *      carBtn.Description = "This vehicle is not available. Please ask the server owner to check if the vehicle is being streamed correctly.";
                         *      carBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                         *  }
                         *
                         *  buttonsList.Add(carBtn);
                         * }
                         *
                         * buttonsList.Sort((prev, next) => String.Compare(prev.Text, next.Text));
                         *
                         * buttonsList.ForEach(carBtn =>
                         * {
                         *  addonCarsMenu.AddItem(carBtn);
                         * });
                         */
                        addonCarsMenu.OnItemSelect += (sender, item, index) =>
                        {
                            cf.SpawnVehicle(AddonVehicles.ElementAt(index).Key, SpawnInVehicle, ReplaceVehicle);
                        };
                        addonCarsMenu.RefreshIndex();
                        addonCarsMenu.UpdateScaleform();
                    }
                    else
                    {
                        addonCarsBtn.Enabled = false;
                        addonCarsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                        addonCarsBtn.Description = "There are no addon vehicles available on this server.";
                    }
                }
                else
                {
                    addonCarsBtn.Enabled = false;
                    addonCarsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                    addonCarsBtn.Description = "The list containing all addon cars could not be loaded, is it configured properly?";
                }
            }
            else
            {
                addonCarsBtn.Enabled = false;
                addonCarsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                addonCarsBtn.Description = "Access to this list has been restricted by the server owner.";
            }
            #endregion

            #region vehicle classes submenus
            // Create the submenus for each category.
            var vl = new Vehicles();

            // Loop through all the vehicle classes.
            for (var vehClass = 0; vehClass < 22; vehClass++)
            {
                // Get the class name.
                string className = cf.GetLocalizedName($"VEH_CLASS_{vehClass.ToString()}");

                // Create a button & a menu for it, add the menu to the menu pool and add & bind the button to the menu.
                UIMenuItem btn = new UIMenuItem(className, $"Spawn a vehicle from the ~o~{className} ~s~class.");
                btn.SetRightLabel("→→→");

                UIMenu vehicleClassMenu = new UIMenu("Vehicle Spawner", className, true)
                {
                    ScaleWithSafezone       = false,
                    MouseControlsEnabled    = false,
                    MouseEdgeEnabled        = false,
                    ControlDisablingEnabled = false
                };

                /*
                 * MainMenu.Mp.Add(vehicleClassMenu);
                 * menu.AddItem(btn);
                 *
                 * if (allowedCategories[vehClass])
                 * {
                 *  menu.BindMenuToItem(vehicleClassMenu, btn);
                 * }
                 * else
                 * {
                 *  btn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                 *  btn.Description = "This category has been disabled by the server owner.";
                 *  btn.Enabled = false;
                 * }
                 */

                // Create a dictionary for the duplicate vehicle names (in this vehicle class).
                var duplicateVehNames = new Dictionary <string, int>();

                #region Add vehicles per class
                // Loop through all the vehicles in the vehicle class.
                foreach (var veh in vl.VehicleClasses[className])
                {
                    // Convert the model name to start with a Capital letter, converting the other characters to lowercase.
                    var properCasedModelName = veh[0].ToString().ToUpper() + veh.ToLower().Substring(1);

                    // Get the localized vehicle name, if it's "NULL" (no label found) then use the "properCasedModelName" created above.
                    var vehName = cf.GetVehDisplayNameFromModel(veh) != "NULL" ? cf.GetVehDisplayNameFromModel(veh) : properCasedModelName;

                    // Loop through all the menu items and check each item's title/text and see if it matches the current vehicle (display) name.
                    var duplicate = false;
                    for (var itemIndex = 0; itemIndex < vehicleClassMenu.MenuItems.Count; itemIndex++)
                    {
                        // If it matches...
                        if (vehicleClassMenu.MenuItems[itemIndex].Text.ToString() == vehName)
                        {
                            // Check if the model was marked as duplicate before.
                            if (duplicateVehNames.Keys.Contains(vehName))
                            {
                                // If so, add 1 to the duplicate counter for this model name.
                                duplicateVehNames[vehName]++;
                            }

                            // If this is the first duplicate, then set it to 2.
                            else
                            {
                                duplicateVehNames[vehName] = 2;
                            }

                            // The model name is a duplicate, so get the modelname and add the duplicate amount for this model name to the end of the vehicle name.
                            vehName += $" ({duplicateVehNames[vehName].ToString()})";

                            // Then create and add a new button for this vehicle.

                            if (cf.DoesModelExist(veh))
                            {
                                var vehBtn = new UIMenuItem(vehName)
                                {
                                    Enabled = true
                                };
                                vehicleClassMenu.AddItem(vehBtn);
                            }
                            else
                            {
                                var vehBtn = new UIMenuItem(vehName, "This vehicle is not available because the model could not be found in your game files. If this is a DLC vehicle, make sure the server is streaming it.")
                                {
                                    Enabled = false
                                };
                                vehicleClassMenu.AddItem(vehBtn);
                                vehBtn.SetRightBadge(UIMenuItem.BadgeStyle.Lock);
                            }

                            // Mark duplicate as true and break from the loop because we already found the duplicate.
                            duplicate = true;
                            break;
                        }
                    }

                    // If it's not a duplicate, add the model name.
                    if (!duplicate)
                    {
                        if (cf.DoesModelExist(veh))
                        {
                            var vehBtn = new UIMenuItem(vehName)
                            {
                                Enabled = true
                            };
                            vehicleClassMenu.AddItem(vehBtn);
                        }
                        else
                        {
                            var vehBtn = new UIMenuItem(vehName, "This vehicle is not available because the model could not be found in your game files. If this is a DLC vehicle, make sure the server is streaming it.")
                            {
                                Enabled = false
                            };
                            vehicleClassMenu.AddItem(vehBtn);
                            vehBtn.SetRightBadge(UIMenuItem.BadgeStyle.Lock);
                        }
                    }
                }
                #endregion

                // Handle button presses
                vehicleClassMenu.OnItemSelect += (sender2, item2, index2) =>
                {
                    cf.SpawnVehicle(vl.VehicleClasses[className][index2], SpawnInVehicle, ReplaceVehicle);
                };
            }
            #endregion

            #region handle events
            // Handle button presses.
            menu.OnItemSelect += (sender, item, index) =>
            {
                if (item == spawnByName)
                {
                    // Passing "custom" as the vehicle name, will ask the user for input.
                    cf.SpawnVehicle("custom", SpawnInVehicle, ReplaceVehicle);
                }
            };

            // Handle checkbox changes.
            menu.OnCheckboxChange += (sender, item, _checked) =>
            {
                if (item == spawnInVeh)
                {
                    SpawnInVehicle = _checked;
                }
                else if (item == replacePrev)
                {
                    ReplaceVehicle = _checked;
                }
            };
            #endregion
        }
Example #16
0
        void SetupMenus()
        {
            // Create main menu
            UIMenuListItem btnToggle = new UIMenuListItem("Toggle Display", new List <dynamic>(Enum.GetNames(typeof(SpeedoMode))), 0);

            btnToggle.OnListChanged += delegate(UIMenuListItem item, int index)
            {
                speedoMode = (SpeedoMode)(((int)index) % Enum.GetNames(typeof(SpeedoMode)).Length);
            };
            UIMenuItem btnClear = new UIMenuItem("Reset Trip Meter");

            btnClear.Activated += delegate { distanceKm = 0; UI.Notify("Trip meter reset"); };
            UIMenuItem btnCore = new UIMenuItem("Core Settings");

            btnCore.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            UIMenuItem btnDisp = new UIMenuItem("Display Settings");

            btnDisp.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            UIMenuItem btnExtras = new UIMenuItem("Extras");

            btnExtras.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            UIMenuItem btnReload = new UIMenuItem("Reload");

            btnReload.Activated += delegate
            {
                ParseSettings(); SetupUIElements();
                UpdateAllMenuButtons();
                UI.Notify("Speedometer reloaded");
            };
            UIMenuItem btnBack = new UIMenuItem("Save & Close");

            btnBack.Activated += delegate { SaveSettings(); mainMenu.Visible = false; };

            mainMenu = new UIMenu(GetTitle(), "By libertylocked");
            foreach (UIMenuItem item in new UIMenuItem[] { btnToggle, btnClear, btnCore, btnDisp, btnExtras, btnReload, btnBack })
            {
                mainMenu.AddItem(item);
            }
            mainMenu.OnMenuClose += delegate { SaveSettings(); };

            // Create core menu
            UIMenuListItem btnUseMph = new UIMenuListItem("Speed Unit", new List <dynamic> {
                "Imperial", "Metric"
            }, 0, "Sets the unit between KPH and MPH");

            btnUseMph.OnListChanged += delegate(UIMenuListItem item, int index)
            {
                useMph = index % 2 == 0; UpdateAllMenuButtons();;
            };
            UIMenuCheckboxItem btnEnableSaving = new UIMenuCheckboxItem("Save Trip Meter", false, "Allows trip meter data to be persistent across game sessions");

            btnEnableSaving.CheckboxEvent += new ItemCheckboxEvent(delegate(UIMenuCheckboxItem item, bool selected)
            {
                enableSaving = selected;
            });
            UIMenuCheckboxItem btnOnfootSpeedo = new UIMenuCheckboxItem("Onfoot Speed", false, "Shows speed when player is on foot");

            btnOnfootSpeedo.CheckboxEvent += new ItemCheckboxEvent(delegate(UIMenuCheckboxItem item, bool selected)
            {
                onfootSpeedo = selected;
            });

            coreMenu = new UIMenu(GetTitle(), "Core Settings");
            foreach (UIMenuItem item in new UIMenuItem[] { btnUseMph, btnEnableSaving, btnOnfootSpeedo })
            {
                coreMenu.AddItem(item);
            }
            mainMenu.BindMenuToItem(coreMenu, btnCore);

            // Create display menu
            UIMenuListItem btnVAlign = new UIMenuListItem("Vertical Alignment", new List <dynamic>(Enum.GetNames(typeof(VerticalAlignment))), 0, "Determines how speedometer display will be aligned vertically");

            btnVAlign.OnListChanged += delegate(UIMenuListItem item, int index)
            {
                vAlign = (VerticalAlignment)(((int)index) % 3); posOffset.Y = 0; SetupUIElements();
            };
            UIMenuListItem btnHAlign = new UIMenuListItem("Horizontal Alignment", new List <dynamic>(Enum.GetNames(typeof(HorizontalAlign))), 0, "Determines how speedometer display will be aligned horizontally");

            btnHAlign.OnListChanged += delegate(UIMenuListItem item, int index)
            {
                hAlign = (HorizontalAlign)(((int)index) % 3); posOffset.X = 0; SetupUIElements();
            };
            UIMenuListItem btnFontStyle = new UIMenuListItem("Font Style", new List <dynamic>(Enum.GetNames(typeof(GTA.Font))), 0, "Sets the font on speedometer display");

            btnFontStyle.OnListChanged += delegate(UIMenuListItem item, int index)
            {
                fontStyle = (int)((GTA.Font[])Enum.GetValues(typeof(GTA.Font)))[index]; SetupUIElements();
            };
            UIMenuItem btnFontSize = new UIMenuItem("Font Size", "Sets the size of text on speedometer");

            btnFontSize.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            UIMenuItem btnPanelSize = new UIMenuItem("Panel Size", "Sets the size of the back rectangle");

            btnPanelSize.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            UIMenuItem btnOffset = new UIMenuItem("Apply Offset", "Applies an offset to speedometer display, to fine tune its position");

            btnOffset.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            UIMenuItem btnBackcolor = new UIMenuItem("Back Color", "Sets the color of the background panel");

            btnBackcolor.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            btnBackcolor.Activated += delegate { isChangingBackcolor = true; UpdateAllMenuButtons(); };
            UIMenuItem btnForecolor = new UIMenuItem("Fore Color", "Sets the color of the text");

            btnForecolor.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            btnForecolor.Activated += delegate { isChangingBackcolor = false; UpdateAllMenuButtons(); };
            UIMenuItem btnTxt = new UIMenuItem("Speed Unit Text", "Changes the text for speed unit");

            btnTxt.Activated += delegate
            {
                string input = Game.GetUserInput(WindowTitle.CELL_EMASH_BOD, useMph ? mphText : kphText, 20);
                if (useMph)
                {
                    mphText = input;
                }
                else
                {
                    kphText = input;
                }
            };
            UIMenuItem btnRstDefault = new UIMenuItem("Restore to Default", "Resets UI to default settings");

            btnRstDefault.Activated += delegate { ResetUIToDefault(); UpdateAllMenuButtons(); };

            dispMenu = new UIMenu(GetTitle(), "Display Settings");
            foreach (UIMenuItem item in new UIMenuItem[] { btnVAlign, btnHAlign, btnFontStyle, btnFontSize, btnPanelSize, btnOffset, btnBackcolor, btnForecolor, btnTxt, btnRstDefault })
            {
                dispMenu.AddItem(item);
            }
            mainMenu.BindMenuToItem(dispMenu, btnDisp);

            // Create font size menu
            UIMenuItem btnAddSize = new UIMenuItem("+ Font Size");

            btnAddSize.Activated += delegate { fontSize += 0.02f; SetupUIElements(); };
            UIMenuItem btnSubSize = new UIMenuItem("- Font Size");

            btnSubSize.Activated += delegate { fontSize -= 0.02f; SetupUIElements(); };
            UIMenu sizeMenu = new UIMenu(GetTitle(), "Font Size");

            sizeMenu.AddItem(btnAddSize);
            sizeMenu.AddItem(btnSubSize);
            dispMenu.BindMenuToItem(sizeMenu, btnFontSize);

            // Create panel size menu
            UIMenuItem btnAddWidth = new UIMenuItem("+ Panel Width");

            btnAddWidth.Activated += delegate { pWidth += 2; SetupUIElements(); };
            UIMenuItem btnSubWidth = new UIMenuItem("- Panel Width");

            btnSubWidth.Activated += delegate { pWidth -= 2; SetupUIElements(); };
            UIMenuItem btnAddHeight = new UIMenuItem("+ Panel Height");

            btnAddHeight.Activated += delegate { pHeight += 2; SetupUIElements(); };
            UIMenuItem btnSubHeight = new UIMenuItem("- Panel Height");

            btnSubHeight.Activated += delegate { pHeight -= 2; SetupUIElements(); };
            UIMenu panelSizeMenu = new UIMenu(GetTitle(), "Panel Size");

            panelSizeMenu.AddItem(btnAddWidth);
            panelSizeMenu.AddItem(btnSubWidth);
            panelSizeMenu.AddItem(btnAddHeight);
            panelSizeMenu.AddItem(btnSubHeight);
            dispMenu.BindMenuToItem(panelSizeMenu, btnPanelSize);

            // Create offset menu
            UIMenuItem btnOffsetUp = new UIMenuItem("Move Up");

            btnOffsetUp.Activated += delegate { posOffset.Y += -2; SetupUIElements(); };
            UIMenuItem btnOffsetDown = new UIMenuItem("Move Down");

            btnOffsetDown.Activated += delegate { posOffset.Y += 2; SetupUIElements(); };
            UIMenuItem btnOffsetLeft = new UIMenuItem("Move Left");

            btnOffsetLeft.Activated += delegate { posOffset.X += -2; SetupUIElements(); };
            UIMenuItem btnOffsetRight = new UIMenuItem("Move Right");

            btnOffsetRight.Activated += delegate { posOffset.X += 2; SetupUIElements(); };
            UIMenuItem btnOffsetClr = new UIMenuItem("Clear Offset");

            btnOffsetClr.Activated += delegate { posOffset.X = 0; posOffset.Y = 0; SetupUIElements(); };
            UIMenu offsetMenu = new UIMenu(GetTitle(), "Apply Offset");

            offsetMenu.AddItem(btnOffsetUp);
            offsetMenu.AddItem(btnOffsetDown);
            offsetMenu.AddItem(btnOffsetLeft);
            offsetMenu.AddItem(btnOffsetRight);
            offsetMenu.AddItem(btnOffsetClr);
            dispMenu.BindMenuToItem(offsetMenu, btnOffset);

            // Create color menu
            UIMenuItem btnAddR = new UIMenuItem("+ R");

            btnAddR.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, 0, 5, 0, 0);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, 0, 5, 0, 0);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            UIMenuItem btnSubR = new UIMenuItem("- R");

            btnSubR.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, 0, -5, 0, 0);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, 0, -5, 0, 0);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            UIMenuItem btnAddG = new UIMenuItem("+ G");

            btnAddG.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, 0, 0, 5, 0);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, 0, 0, 5, 0);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            UIMenuItem btnSubG = new UIMenuItem("- G");

            btnSubG.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, 0, 0, -5, 0);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, 0, 0, -5, 0);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            UIMenuItem btnAddB = new UIMenuItem("+ B");

            btnAddB.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, 0, 0, 0, 5);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, 0, 0, 0, 5);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            UIMenuItem btnSubB = new UIMenuItem("- B");

            btnSubB.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, 0, 0, 0, -5);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, 0, 0, 0, -5);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            UIMenuItem btnAddA = new UIMenuItem("+ Opacity");

            btnAddA.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, 5, 0, 0, 0);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, 5, 0, 0, 0);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            UIMenuItem btnSubA = new UIMenuItem("- Opacity");

            btnSubA.Activated += delegate
            {
                if (isChangingBackcolor)
                {
                    backcolor = Utils.IncrementARGB(backcolor, -5, 0, 0, 0);
                }
                else
                {
                    forecolor = Utils.IncrementARGB(forecolor, -5, 0, 0, 0);
                }
                SetupUIElements(); UpdateAllMenuButtons();
            };
            colorMenu = new UIMenu(GetTitle(), "Set Color");
            foreach (UIMenuItem item in new UIMenuItem[] { btnAddR, btnSubR, btnAddG, btnSubG, btnAddB, btnSubB, btnAddA, btnSubA })
            {
                colorMenu.AddItem(item);
            }
            dispMenu.BindMenuToItem(colorMenu, btnBackcolor);
            dispMenu.BindMenuToItem(colorMenu, btnForecolor);

            // Create extras menu
            UIMenuListItem btnRainbowMode = new UIMenuListItem("Rainbow Mode", new List <dynamic> {
                "Off", "1x", "2x", "4x", "8x", "16x", "32x", "64x"
            }, 0);

            btnRainbowMode.OnListChanged += delegate(UIMenuListItem item, int index)
            {
                rainbowMode = index;
                SetupUIElements();
            };
            UIMenuItem btnAccTimer = new UIMenuItem("0-100kph/62mph Timer");

            btnAccTimer.Activated += delegate { wid_accTimer.Toggle(); };
            UIMenuItem btnMaxSpeed = new UIMenuItem("Top Speed Recorder");

            btnMaxSpeed.Activated += delegate { wid_maxSpeed.Toggle(); };
            UIMenuItem btnShowCredits = new UIMenuItem("Show Credits");

            btnShowCredits.Activated += delegate { ShowCredits(); };

            extrasMenu = new UIMenu(GetTitle(), "Extras");
            foreach (UIMenuItem item in new UIMenuItem[] { btnRainbowMode, btnAccTimer, btnMaxSpeed, btnShowCredits })
            {
                extrasMenu.AddItem(item);
            }
            mainMenu.BindMenuToItem(extrasMenu, btnExtras);

            menuPool = new MenuPool();
            menuPool.Add(mainMenu);
            menuPool.Add(coreMenu);
            menuPool.Add(dispMenu);
            menuPool.Add(extrasMenu);
            menuPool.Add(sizeMenu);
            menuPool.Add(panelSizeMenu);
            menuPool.Add(offsetMenu);
            menuPool.Add(colorMenu);
        }
Example #17
0
        private void AddServerToRecent(UIMenuItem server)
        {
            if (string.IsNullOrWhiteSpace(server.Description))
            {
                return;
            }
            var split = server.Description.Split(':');

            if (split.Length < 2 || string.IsNullOrWhiteSpace(split[0]) || string.IsNullOrWhiteSpace(split[1]) || !int.TryParse(split[1], out int tmpPort))
            {
                return;
            }
            if (!PlayerSettings.RecentServers.Contains(server.Description))
            {
                PlayerSettings.RecentServers.Add(server.Description);
                if (PlayerSettings.RecentServers.Count > 20)
                {
                    PlayerSettings.RecentServers.RemoveAt(0);
                }
                Util.Util.SaveSettings(GTANInstallDir + "\\settings.xml");

                var item = new UIMenuItem(server.Text)
                {
                    Description = server.Description
                };
                item.SetRightLabel(server.RightLabel);
                item.SetLeftBadge(server.LeftBadge);
                item.Activated += (sender, selectedItem) =>
                {
                    if (IsOnServer())
                    {
                        Client.Disconnect("Switching servers");

                        if (Npcs != null)
                        {
                            Npcs.ToList().ForEach(pair => pair.Value.Clear());
                            Npcs.Clear();
                        }

                        while (IsOnServer())
                        {
                            Script.Yield();
                        }
                    }

                    bool pass = false;
                    if (server.LeftBadge == UIMenuItem.BadgeStyle.Lock)
                    {
                        pass = true;
                    }

                    var splt = server.Description.Split(':');
                    if (splt.Length < 2)
                    {
                        return;
                    }
                    if (!int.TryParse(splt[1], out int port))
                    {
                        return;
                    }

                    ConnectToServer(splt[0], port, pass);
                    MainMenu.TemporarilyHidden = true;
                    _connectTab.RefreshIndex();
                };
                _recentBrowser.Items.Add(item);
            }
        }
Example #18
0
        public static void Main()
        {
            // Create a fiber to process our menus
            MenusProcessFiber = new GameFiber(ProcessLoop);

            // Create the MenuPool to easily process our menus
            menuPool = new MenuPool();

            // Create our main menu
            mainMenu = new UIMenu("RAGENative UI", "~b~RAGENATIVEUI SHOWCASE");

            // Add our main menu to the MenuPool
            menuPool.Add(mainMenu);

            // create our items and add them to our main menu
            mainMenu.AddItem(ketchupCheckbox = new UIMenuCheckboxItem("Add ketchup?", false, "Do you wish to add ketchup?"));

            mainMenu.AddItem(dishesListItem = new UIMenuListItem("Food", "",
                                                                 "Banana",
                                                                 "Apple",
                                                                 "Pizza",
                                                                 "Quartilicious",
                                                                 0xF00D));
            mainMenu.AddItem(cookItem = new UIMenuItem("Cook!", "Cook the dish with the appropiate ingredients and ketchup."));

            var menuItem = new UIMenuItem("Go to another menu.");

            mainMenu.AddItem(menuItem);
            cookItem.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            cookItem.SetRightBadge(UIMenuItem.BadgeStyle.Tick);

            carsList = new UIMenuListItem("Cars Models", "",
                                          "Adder",
                                          "Bullet",
                                          "Police",
                                          "Police2",
                                          "Asea",
                                          "FBI",
                                          "FBI2",
                                          "Firetruk",
                                          "Ambulance",
                                          "Rhino");
            mainMenu.AddItem(carsList);

            spawnCar = new UIMenuItem("Spawn Car");
            mainMenu.AddItem(spawnCar);

            coloredItem = new UIMenuItem("Color!");
            mainMenu.AddItem(coloredItem);

            mainMenu.RefreshIndex();

            mainMenu.OnItemSelect     += OnItemSelect;
            mainMenu.OnListChange     += OnListChange;
            mainMenu.OnCheckboxChange += OnCheckboxChange;
            mainMenu.OnIndexChange    += OnItemChange;

            // Create another menu
            newMenu = new UIMenu("RAGENative UI", "~b~RAGENATIVEUI SHOWCASE");
            newMenu.CounterOverride = "Counter Override";
            menuPool.Add(newMenu);       // add it to the menu pool
            for (int i = 0; i < 35; i++) // add items
            {
                newMenu.AddItem(new UIMenuItem("PageFiller " + i.ToString(), "Sample description that takes more than one line. More so, it takes way more than two lines since it's so long. Wow, check out this length!"));
            }
            newMenu.RefreshIndex();
            mainMenu.BindMenuToItem(newMenu, menuItem); // and bind it to an item in our main menu

            // Start our process fiber
            MenusProcessFiber.Start();

            // Continue with our plugin... in this example, hibernate to prevent it from being unloaded
            GameFiber.Hibernate();
        }
Example #19
0
        private void ConfigureMenu()
        {
            MainMenu = new UIMenu("Simple Zombies", "SELECT AN OPTION");
            MenuConrtoller.MenuPool.Add(MainMenu);
            UIMenuCheckboxItem infectionCheckbox = new UIMenuCheckboxItem("Infection Mode", false, "Enable/Disable zombies.");

            infectionCheckbox.CheckboxEvent += delegate(UIMenuCheckboxItem sender, bool @checked)
            {
                ZombieVehicleSpawner.Instance.Spawn = @checked;
                Loot247.Instance.Spawn       = @checked;
                WorldController.Configure    = @checked;
                AnimalSpawner.Instance.Spawn = @checked;
                if (@checked)
                {
                    WorldExtended.ClearAreaOfEverything(Database.PlayerPosition, 10000f);
                    Function.Call(GTA.Native.Hash.REQUEST_IPL, (InputArgument[])new InputArgument[1]
                    {
                        "cs3_07_mpgates"
                    });
                }
            };
            UIMenuCheckboxItem fastZombiesCheckbox = new UIMenuCheckboxItem("Fast Zombies", false, "Enable/Disable running zombies.");

            fastZombiesCheckbox.CheckboxEvent += delegate(UIMenuCheckboxItem sender, bool @checked)
            {
                ZombieCreator.Runners = @checked;
            };
            UIMenuCheckboxItem electricityCheckBox = new UIMenuCheckboxItem("Electricity", true, "Enables/Disable blackout mode.");

            electricityCheckBox.CheckboxEvent += delegate(UIMenuCheckboxItem sender, bool @checked)
            {
                World.SetBlackout(!@checked);
            };
            UIMenuCheckboxItem survivorsCheckBox = new UIMenuCheckboxItem("Survivors", false, "Enable/Disable survivors.");

            survivorsCheckBox.CheckboxEvent += delegate(UIMenuCheckboxItem sender, bool @checked)
            {
                SurvivorController.Instance.Spawn = @checked;
            };
            UIMenuCheckboxItem statsCheckbox = new UIMenuCheckboxItem("Stats", true, "Enable/Disable stats.");

            statsCheckbox.CheckboxEvent += delegate(UIMenuCheckboxItem sender, bool @checked)
            {
                PlayerStats.UseStats = @checked;
            };
            UIMenuItem loadItem = new UIMenuItem("Load", "Load the map, your vehicles and your bodyguards.");

            loadItem.SetLeftBadge(UIMenuItem.BadgeStyle.Heart);
            loadItem.Activated += delegate
            {
                PlayerMap.Instance.Deserialize();
                PlayerVehicles.Instance.Deserialize();
                PlayerGroupManager.Instance.Deserialize();
            };
            UIMenuItem saveCurrentVehicleItem = new UIMenuItem("Save", "Saves the vehicle you are currently in.");

            saveCurrentVehicleItem.SetLeftBadge(UIMenuItem.BadgeStyle.Car);
            saveCurrentVehicleItem.Activated += delegate
            {
                if (Database.PlayerCurrentVehicle == null || (Database.PlayerCurrentVehicle != null && !Database.PlayerCurrentVehicle.Exists()))
                {
                    UI.Notify("You're not in a vehicle.");
                }
                else
                {
                    PlayerVehicles.Instance.SaveVehicle(Database.PlayerCurrentVehicle);
                }
            };
            UIMenuItem saveAllVehiclesItem = new UIMenuItem("Save All", "Saves all marked vehicles, and their positions.");

            saveAllVehiclesItem.SetLeftBadge(UIMenuItem.BadgeStyle.Car);
            saveAllVehiclesItem.Activated += delegate
            {
                PlayerVehicles.Instance.Serialize(true);
            };
            UIMenuItem saveAllGuardsItem = new UIMenuItem("Save All", "Saves the player ped group (guards).");

            saveAllGuardsItem.SetLeftBadge(UIMenuItem.BadgeStyle.Mask);
            saveAllGuardsItem.Activated += delegate
            {
                PlayerGroupManager.Instance.SavePeds();
            };
            MainMenu.AddItem(infectionCheckbox);
            MainMenu.AddItem(fastZombiesCheckbox);
            MainMenu.AddItem(electricityCheckBox);
            MainMenu.AddItem(survivorsCheckBox);
            MainMenu.AddItem(statsCheckbox);
            MainMenu.AddItem(loadItem);
            MainMenu.AddItem(saveCurrentVehicleItem);
            MainMenu.AddItem(saveAllVehiclesItem);
            MainMenu.AddItem(saveAllGuardsItem);
            MainMenu.RefreshIndex();
        }
Example #20
0
        private void CreateMenu()
        {
            // Create the menu.
            menu = new UIMenu(GetPlayerName(PlayerId()), "Weapon Options", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            UIMenuItem         getAllWeapons    = new UIMenuItem("Get All Weapons", "Get all weapons.");
            UIMenuItem         removeAllWeapons = new UIMenuItem("Remove All Weapons", "Removes all weapons in your inventory.");
            UIMenuCheckboxItem unlimitedAmmo    = new UIMenuCheckboxItem("Unlimited Ammo", UnlimitedAmmo, "Unlimited ammonition supply.");
            UIMenuCheckboxItem noReload         = new UIMenuCheckboxItem("No Reload", NoReload, "Never reload.");
            ValidWeapons       vw = new ValidWeapons();


            if (cf.IsAllowed(Permission.WPGetAll))
            {
                menu.AddItem(getAllWeapons);
            }
            if (cf.IsAllowed(Permission.WPRemoveAll))
            {
                menu.AddItem(removeAllWeapons);
            }
            if (cf.IsAllowed(Permission.WPUnlimitedAmmo))
            {
                menu.AddItem(unlimitedAmmo);
            }
            if (cf.IsAllowed(Permission.WPNoReload))
            {
                menu.AddItem(noReload);
            }


            foreach (ValidWeapon weapon in vw.WeaponList)
            {
                if (weapon.Name != null)
                {
                    UIMenu weaponMenu = new UIMenu("Weapon Options", weapon.Name, true)
                    {
                        ScaleWithSafezone       = false,
                        MouseControlsEnabled    = false,
                        MouseEdgeEnabled        = false,
                        ControlDisablingEnabled = false
                    };
                    UIMenuItem weaponItem = new UIMenuItem(weapon.Name, $"Open the options for ~y~{weapon.Name.ToString()}~s~.");
                    weaponItem.SetRightLabel("→→→");
                    weaponItem.SetLeftBadge(UIMenuItem.BadgeStyle.Gun);

                    MainMenu.Mp.Add(weaponMenu);

                    weaponInfo.Add(weaponMenu, weapon);

                    UIMenuItem getOrRemoveWeapon = new UIMenuItem("Equip/Remove Weapon");
                    getOrRemoveWeapon.SetLeftBadge(UIMenuItem.BadgeStyle.Gun);
                    weaponMenu.AddItem(getOrRemoveWeapon);
                    UIMenuItem fillAmmo = new UIMenuItem("Re-fill Ammo", "Get max ammo for this weapon.");
                    fillAmmo.SetLeftBadge(UIMenuItem.BadgeStyle.Ammo);
                    weaponMenu.AddItem(fillAmmo);

                    List <dynamic> tints = new List <dynamic>();
                    if (weapon.Name.Contains(" Mk II"))
                    {
                        foreach (var tint in ValidWeapons.WeaponTintsMkII)
                        {
                            tints.Add(tint.Key);
                        }
                    }
                    else
                    {
                        foreach (var tint in ValidWeapons.WeaponTints)
                        {
                            tints.Add(tint.Key);
                        }
                    }

                    UIMenuListItem weaponTints = new UIMenuListItem("Tints", tints, 0, "Select a tint for your weapon.");
                    weaponMenu.AddItem(weaponTints);

                    weaponMenu.OnListChange += (sender, item, index) =>
                    {
                        if (item == weaponTints)
                        {
                            if (HasPedGotWeapon(PlayerPedId(), weaponInfo[sender].Hash, false))
                            {
                                SetPedWeaponTintIndex(PlayerPedId(), weaponInfo[sender].Hash, index);
                            }
                            else
                            {
                                Notify.Error("You need to get the weapon first!");
                            }
                        }
                    };


                    weaponMenu.OnItemSelect += (sender, item, index) =>
                    {
                        if (item == getOrRemoveWeapon)
                        {
                            var  info = weaponInfo[sender];
                            uint hash = info.Hash;
                            if (HasPedGotWeapon(PlayerPedId(), hash, false))
                            {
                                RemoveWeaponFromPed(PlayerPedId(), hash);
                                Subtitle.Custom("Weapon removed.");
                            }
                            else
                            {
                                var ammo = 255;
                                GetMaxAmmo(PlayerPedId(), hash, ref ammo);
                                GiveWeaponToPed(PlayerPedId(), hash, ammo, false, true);
                                Subtitle.Custom("Weapon added.");
                            }
                        }
                        else if (item == fillAmmo)
                        {
                            if (HasPedGotWeapon(PlayerPedId(), weaponInfo[sender].Hash, false))
                            {
                                var ammo = 900;
                                GetMaxAmmo(PlayerPedId(), weaponInfo[sender].Hash, ref ammo);
                                SetAmmoInClip(PlayerPedId(), weaponInfo[sender].Hash, ammo);
                            }
                            else
                            {
                                Notify.Error("You need to get the weapon first before re-filling ammo!");
                            }
                        }
                    };

                    if (weapon.Components != null)
                    {
                        if (weapon.Components.Count > 0)
                        {
                            foreach (var comp in weapon.Components)
                            {
                                UIMenuItem compItem = new UIMenuItem(comp.Key, "Click to equip or remove this component.");
                                weaponComponents.Add(compItem, comp.Key);
                                weaponMenu.AddItem(compItem);
                                weaponMenu.OnItemSelect += (sender, item, index) =>
                                {
                                    if (item == compItem)
                                    {
                                        var Weapon        = weaponInfo[sender];
                                        var componentHash = Weapon.Components[weaponComponents[item]];
                                        if (HasPedGotWeapon(PlayerPedId(), Weapon.Hash, false))
                                        {
                                            if (HasPedGotWeaponComponent(PlayerPedId(), Weapon.Hash, componentHash))
                                            {
                                                RemoveWeaponComponentFromPed(PlayerPedId(), Weapon.Hash, componentHash);
                                                Subtitle.Custom("Component removed.");
                                            }
                                            else
                                            {
                                                GiveWeaponComponentToPed(PlayerPedId(), Weapon.Hash, componentHash);
                                                Subtitle.Custom("Component equiped.");
                                            }
                                        }
                                        else
                                        {
                                            Notify.Error("You need to get the weapon first before you can modify it.");
                                        }
                                    }
                                };
                            }
                        }
                    }
                    weaponMenu.RefreshIndex();
                    weaponMenu.UpdateScaleform();

                    menu.AddItem(weaponItem);
                    menu.BindMenuToItem(weaponMenu, weaponItem);
                }
            }

            menu.OnItemSelect += (sender, item, index) =>
            {
                Ped ped = new Ped(PlayerPedId());
                if (item == getAllWeapons)
                {
                    foreach (var weapon in ValidWeapons.Weapons)
                    {
                        var ammo = 255;
                        GetMaxAmmo(PlayerPedId(), weapon.Value, ref ammo);
                        ped.Weapons.Give((WeaponHash)weapon.Value, ammo, weapon.Key == "Unarmed", true);
                    }
                    //ped.Weapons.Give(WeaponHash.Unarmed, 0, true, true);
                }
                else if (item == removeAllWeapons)
                {
                    ped.Weapons.RemoveAll();
                }
            };


            menu.OnCheckboxChange += (sender, item, _checked) =>
            {
                if (item == noReload)
                {
                    NoReload = _checked;
                }
                else if (item == unlimitedAmmo)
                {
                    UnlimitedAmmo = _checked;
                }
            };
        }
Example #21
0
        private void CreateMenu()
        {
            VehicleData vd = new VehicleData();

            allowedCategories = new List <bool>()
            {
                cf.IsAllowed(Permission.VSCompacts),
                cf.IsAllowed(Permission.VSSedans),
                cf.IsAllowed(Permission.VSSUVs),
                cf.IsAllowed(Permission.VSCoupes),
                cf.IsAllowed(Permission.VSMuscle),
                cf.IsAllowed(Permission.VSSportsClassic),
                cf.IsAllowed(Permission.VSSports),
                cf.IsAllowed(Permission.VSSuper),
                cf.IsAllowed(Permission.VSMotorcycles),
                cf.IsAllowed(Permission.VSOffRoad),
                cf.IsAllowed(Permission.VSIndustrial),
                cf.IsAllowed(Permission.VSUtility),
                cf.IsAllowed(Permission.VSVans),
                cf.IsAllowed(Permission.VSCycles),
                cf.IsAllowed(Permission.VSBoats),
                cf.IsAllowed(Permission.VSHelicopters),
                cf.IsAllowed(Permission.VSPlanes),
                cf.IsAllowed(Permission.VSService),
                cf.IsAllowed(Permission.VSEmergency),
                cf.IsAllowed(Permission.VSMilitary),
                cf.IsAllowed(Permission.VSCommercial),
                cf.IsAllowed(Permission.VSTrains),
            };

            // Create the menu.
            menu = new UIMenu(GetPlayerName(PlayerId()), "Vehicle Spawner", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            // Create the buttons and checkboxes.
            UIMenuItem         spawnByName = new UIMenuItem("Spawn Vehicle By Model Name", "Enter the name of a vehicle to spawn.");
            UIMenuCheckboxItem spawnInVeh  = new UIMenuCheckboxItem("Spawn Inside Vehicle", SpawnInVehicle,
                                                                    "This will teleport you into the vehicle when you spawn it.");
            UIMenuCheckboxItem replacePrev = new UIMenuCheckboxItem("Replace Previous Vehicle", SpawnInVehicle,
                                                                    "This will automatically delete your previously spawned vehicle when you spawn a new vehicle.");

            // Add the items to the menu.
            if (cf.IsAllowed(Permission.VSSpawnByName))
            {
                menu.AddItem(spawnByName);
            }
            menu.AddItem(spawnInVeh);
            menu.AddItem(replacePrev);

            // Create the submenus for each category.

            var vl = new Vehicles();

            // Loop through all the vehicle classes.
            for (var vehClass = 0; vehClass < 22; vehClass++)
            {
                // Get the class name.
                string className = cf.GetLocalizedName($"VEH_CLASS_{vehClass.ToString()}");

                // Create a button & a menu for it, add the menu to the menu pool and add & bind the button to the menu.
                UIMenuItem btn = new UIMenuItem(className, $"Spawn a vehicle from the ~o~{className} ~s~class.");
                btn.SetRightLabel("→→→");
                UIMenu vehicleClassMenu = new UIMenu("Vehicle Spawner", className, true)
                {
                    ScaleWithSafezone       = false,
                    MouseControlsEnabled    = false,
                    MouseEdgeEnabled        = false,
                    ControlDisablingEnabled = false
                };
                MainMenu.Mp.Add(vehicleClassMenu);
                menu.AddItem(btn);
                if (allowedCategories[vehClass])
                {
                    menu.BindMenuToItem(vehicleClassMenu, btn);
                }
                else
                {
                    btn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                    btn.Description = "This category has been disabled by the server owner.";
                    btn.Enabled     = false;
                }


                // Create a dictionary for the duplicate vehicle names (in this vehicle class).
                var duplicateVehNames = new Dictionary <string, int>();

                // Loop through all the vehicles in the vehicle class.
                foreach (var veh in vl.VehicleClasses[className])
                {
                    // Convert the model name to start with a Capital letter, converting the other characters to lowercase.
                    var properCasedModelName = veh[0].ToString().ToUpper() + veh.ToLower().Substring(1);

                    // Get the localized vehicle name, if it's "NULL" (no label found) then use the "properCasedModelName" created above.
                    var vehName = cf.GetVehDisplayNameFromModel(veh) != "NULL" ? cf.GetVehDisplayNameFromModel(veh) : properCasedModelName;

                    // Loop through all the menu items and check each item's title/text and see if it matches the current vehicle (display) name.
                    var duplicate = false;
                    for (var itemIndex = 0; itemIndex < vehicleClassMenu.MenuItems.Count; itemIndex++)
                    {
                        // If it matches...
                        if (vehicleClassMenu.MenuItems[itemIndex].Text.ToString() == vehName)
                        {
                            // Check if the model was marked as duplicate before.
                            if (duplicateVehNames.Keys.Contains(vehName))
                            {
                                // If so, add 1 to the duplicate counter for this model name.
                                duplicateVehNames[vehName]++;
                            }

                            // If this is the first duplicate, then set it to 2.
                            else
                            {
                                duplicateVehNames[vehName] = 2;
                            }

                            // The model name is a duplicate, so get the modelname and add the duplicate amount for this model name to the end of the vehicle name.
                            vehName += $" ({duplicateVehNames[vehName].ToString()})";

                            // Then create and add a new button for this vehicle.

                            if (cf.DoesModelExist(veh))
                            {
                                var vehBtn = new UIMenuItem(vehName)
                                {
                                    Enabled = true
                                };
                                vehicleClassMenu.AddItem(vehBtn);
                            }
                            else
                            {
                                var vehBtn = new UIMenuItem(vehName, "This vehicle is not available because the model could not be found in your game files. If this is a DLC vehicle, make sure the server is streaming it.")
                                {
                                    Enabled = false
                                };
                                vehicleClassMenu.AddItem(vehBtn);
                                vehBtn.SetRightBadge(UIMenuItem.BadgeStyle.Lock);
                            }

                            // Mark duplicate as true and break from the loop because we already found the duplicate.
                            duplicate = true;
                            break;
                        }
                    }

                    // If it's not a duplicate, add the model name.
                    if (!duplicate)
                    {
                        if (cf.DoesModelExist(veh))
                        {
                            var vehBtn = new UIMenuItem(vehName)
                            {
                                Enabled = true
                            };
                            vehicleClassMenu.AddItem(vehBtn);
                        }
                        else
                        {
                            var vehBtn = new UIMenuItem(vehName, "This vehicle is not available because the model could not be found in your game files. If this is a DLC vehicle, make sure the server is streaming it.")
                            {
                                Enabled = false
                            };
                            vehicleClassMenu.AddItem(vehBtn);
                            vehBtn.SetRightBadge(UIMenuItem.BadgeStyle.Lock);
                        }
                    }
                }

                vehicleClassMenu.OnItemSelect += (sender2, item2, index2) =>
                {
                    cf.SpawnVehicle(vl.VehicleClasses[className][index2], SpawnInVehicle, ReplaceVehicle);
                };
            }


            // Handle button presses.
            menu.OnItemSelect += (sender, item, index) =>
            {
                if (item == spawnByName)
                {
                    // Passing "custom" as the vehicle name, will ask the user for input.
                    cf.SpawnVehicle("custom", SpawnInVehicle, ReplaceVehicle);
                }
            };

            // Handle checkbox changes.
            menu.OnCheckboxChange += (sender, item, _checked) =>
            {
                if (item == spawnInVeh)
                {
                    SpawnInVehicle = _checked;
                }
                else if (item == replacePrev)
                {
                    ReplaceVehicle = _checked;
                }
            };
        }
Example #22
0
        /// <summary>
        /// Creates the menu.
        /// </summary>
        private void CreateMenu()
        {
            string menuTitle = "Saved Vehicles";

            #region Create menus and submenus
            // Create the menu.
            menu = new UIMenu(menuTitle, "Manage Saved Vehicles", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            // Create submenus.
            UIMenu savedVehicles = new UIMenu(menuTitle, "Spawn Saved Vehicle", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            UIMenu deleteSavedVehicles = new UIMenu(menuTitle, "~r~Delete Saved Vehicle", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };
            #endregion

            #region Create, add and bind buttons to the menus.
            // Create menu buttons.
            UIMenuItem saveVeh = new UIMenuItem("Save Current Vehicle", "Save the vehicle you are currently in.");
            saveVeh.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
            UIMenuItem savedVehiclesBtn = new UIMenuItem("Spawn Saved Vehicle", "Select a vehicle from your saved vehicles list.");
            savedVehiclesBtn.SetRightLabel("→→→");
            UIMenuItem deleteSavedVehiclesBtn = new UIMenuItem("~r~Delete Saved Vehicle", "~r~Delete ~s~a saved vehicle.");
            deleteSavedVehiclesBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Alert);
            deleteSavedVehiclesBtn.SetRightLabel("→→→");

            // Add buttons to the menu.
            menu.AddItem(saveVeh);
            menu.AddItem(savedVehiclesBtn);
            menu.AddItem(deleteSavedVehiclesBtn);

            // Bind submenus to menu items.
            if (cf.IsAllowed(Permission.SVSpawn))
            {
                menu.BindMenuToItem(savedVehicles, savedVehiclesBtn);
            }
            else
            {
                savedVehiclesBtn.Enabled = false;
                savedVehiclesBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                savedVehiclesBtn.Description = "This option has been disabled by the server owner.";
            }
            menu.BindMenuToItem(deleteSavedVehicles, deleteSavedVehiclesBtn);
            #endregion

            #region Button pressed events
            // Handle button presses.
            menu.OnItemSelect += (sender, item, index) =>
            {
                // Save the current vehicle.
                if (item == saveVeh)
                {
                    cf.SaveVehicle();
                }

                // Open and refresh the "spawn saved vehicle from list" submenu.
                else if (item == savedVehiclesBtn)
                {
                    // Remove all old items.
                    savedVehicles.MenuItems.Clear();

                    // Get all saved vehicles.
                    SavedVehiclesDict = cf.GetSavedVehiclesDictionary();

                    // Loop through all saved vehicles and create a button for it, then add that button to the submenu.
                    foreach (KeyValuePair <string, Dictionary <string, string> > savedVehicle in SavedVehiclesDict)
                    {
                        UIMenuItem vehBtn = new UIMenuItem(savedVehicle.Key.Substring(4), "Click to spawn this saved vehicle.");
                        vehBtn.SetRightLabel($"({savedVehicle.Value["name"]})");
                        savedVehicles.AddItem(vehBtn);
                    }

                    // Sort the menu items (case IN-sensitive) by name.
                    savedVehicles.MenuItems.Sort((pair1, pair2) => pair1.Text.ToString().ToLower().CompareTo(pair2.Text.ToString().ToLower()));

                    // When a vehicle is selected...
                    savedVehicles.OnItemSelect += (sender2, item2, index2) =>
                    {
                        // Get the vehicle info.
                        var vehInfo = SavedVehiclesDict["veh_" + item2.Text];

                        // Get the model hash.
                        var model = vehInfo["model"];

                        // Spawn a vehicle using the hash, and pass on the vehicleInfo dictionary containing all saved vehicle mods.
                        cf.SpawnVehicle((uint)Int64.Parse(model), MainMenu.VehicleSpawnerMenu.SpawnInVehicle, MainMenu.VehicleSpawnerMenu.ReplaceVehicle, vehicleInfo: vehInfo);
                    };

                    // Refresh the index of the page.
                    savedVehicles.RefreshIndex();
                    // Update the scaleform.
                    savedVehicles.UpdateScaleform();
                }
                // Delete saved vehicle.
                else if (item == deleteSavedVehiclesBtn)
                {
                    deleteSavedVehicles.MenuItems.Clear();

                    // Get the dictionary containing all saved vehicles.
                    SavedVehiclesDict = cf.GetSavedVehiclesDictionary();

                    // Loop through the list and add all saved vehicles to the menu.
                    foreach (KeyValuePair <string, Dictionary <string, string> > savedVehicle in SavedVehiclesDict)
                    {
                        UIMenuItem vehBtn = new UIMenuItem(savedVehicle.Key.Substring(4), "Are you sure you want to delete this saved vehicle? This action cannot be undone!");
                        vehBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Alert);
                        vehBtn.SetRightLabel($"({savedVehicle.Value["name"]})");
                        deleteSavedVehicles.AddItem(vehBtn);
                    }

                    // Sort the menu items (case IN-sensitive) by name.
                    deleteSavedVehicles.MenuItems.Sort((pair1, pair2) => pair1.Text.ToString().ToLower().CompareTo(pair2.Text.ToString().ToLower()));

                    // Handle vehicle deletions
                    deleteSavedVehicles.OnItemSelect += (sender2, item2, index2) =>
                    {
                        var vehDictName = "veh_" + item2.Text;
                        new StorageManager().DeleteSavedDictionary(vehDictName);
                        deleteSavedVehicles.GoBack();
                    };
                }
            };
            #endregion

            // Add the submenus to the menu pool.
            MainMenu.Mp.Add(savedVehicles);
            MainMenu.Mp.Add(deleteSavedVehicles);
        }
Example #23
0
        private void ConfigureMenu()
        {
            this.MainMenu = new UIMenu("Simple Zombies", "SELECT AN OPTION");
            MenuConrtoller.MenuPool.Add(this.MainMenu);
            UIMenuCheckboxItem menuCheckboxItem1 = new UIMenuCheckboxItem("Infection Mode", false, "Enable/Disable zombies.");

            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            menuCheckboxItem1.add_CheckboxEvent(ModController.\u003C\u003Ec.\u003C\u003E9__12_0 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_0 = new ItemCheckboxEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_0))));
            UIMenuCheckboxItem menuCheckboxItem2 = new UIMenuCheckboxItem("Fast Zombies", false, "Enable/Disable running zombies.");

            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            menuCheckboxItem2.add_CheckboxEvent(ModController.\u003C\u003Ec.\u003C\u003E9__12_1 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_1 = new ItemCheckboxEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_1))));
            UIMenuCheckboxItem menuCheckboxItem3 = new UIMenuCheckboxItem("Electricity", true, "Enables/Disable blackout mode.");

            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            menuCheckboxItem3.add_CheckboxEvent(ModController.\u003C\u003Ec.\u003C\u003E9__12_2 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_2 = new ItemCheckboxEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_2))));
            UIMenuCheckboxItem menuCheckboxItem4 = new UIMenuCheckboxItem("Survivors", false, "Enable/Disable survivors.");

            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            menuCheckboxItem4.add_CheckboxEvent(ModController.\u003C\u003Ec.\u003C\u003E9__12_3 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_3 = new ItemCheckboxEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_3))));
            UIMenuCheckboxItem menuCheckboxItem5 = new UIMenuCheckboxItem("Stats", true, "Enable/Disable stats.");

            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            menuCheckboxItem5.add_CheckboxEvent(ModController.\u003C\u003Ec.\u003C\u003E9__12_4 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_4 = new ItemCheckboxEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_4))));
            UIMenuItem uiMenuItem1 = new UIMenuItem("Load", "Load the map, your vehicles and your bodyguards.");

            uiMenuItem1.SetLeftBadge((UIMenuItem.BadgeStyle) 14);
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            uiMenuItem1.add_Activated(ModController.\u003C\u003Ec.\u003C\u003E9__12_5 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_5 = new ItemActivatedEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_5))));
            UIMenuItem uiMenuItem2 = new UIMenuItem("Save", "Saves the vehicle you are currently in.");

            uiMenuItem2.SetLeftBadge((UIMenuItem.BadgeStyle) 12);
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            uiMenuItem2.add_Activated(ModController.\u003C\u003Ec.\u003C\u003E9__12_6 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_6 = new ItemActivatedEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_6))));
            UIMenuItem uiMenuItem3 = new UIMenuItem("Save All", "Saves all marked vehicles, and their positions.");

            uiMenuItem3.SetLeftBadge((UIMenuItem.BadgeStyle) 12);
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            uiMenuItem3.add_Activated(ModController.\u003C\u003Ec.\u003C\u003E9__12_7 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_7 = new ItemActivatedEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_7))));
            UIMenuItem uiMenuItem4 = new UIMenuItem("Save All", "Saves the player ped group (guards).");

            uiMenuItem4.SetLeftBadge((UIMenuItem.BadgeStyle) 16);
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: method pointer
            uiMenuItem4.add_Activated(ModController.\u003C\u003Ec.\u003C\u003E9__12_8 ?? (ModController.\u003C\u003Ec.\u003C\u003E9__12_8 = new ItemActivatedEvent((object)ModController.\u003C\u003Ec.\u003C\u003E9, __methodptr(\u003CConfigureMenu\u003Eb__12_8))));
            this.MainMenu.AddItem((UIMenuItem)menuCheckboxItem1);
            this.MainMenu.AddItem((UIMenuItem)menuCheckboxItem2);
            this.MainMenu.AddItem((UIMenuItem)menuCheckboxItem3);
            this.MainMenu.AddItem((UIMenuItem)menuCheckboxItem4);
            this.MainMenu.AddItem((UIMenuItem)menuCheckboxItem5);
            this.MainMenu.AddItem(uiMenuItem1);
            this.MainMenu.AddItem(uiMenuItem2);
            this.MainMenu.AddItem(uiMenuItem3);
            this.MainMenu.AddItem(uiMenuItem4);
            this.MainMenu.RefreshIndex();
        }
Example #24
0
        /// <summary>
        /// Creates the menu.
        /// </summary>
        private void CreateMenu()
        {
            #region create main weapon options menu and add items
            // Create the menu.
            menu = new UIMenu(GetPlayerName(PlayerId()), "Weapon Options", true)
            {
                ScaleWithSafezone       = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false
            };

            UIMenuItem         getAllWeapons    = new UIMenuItem("Get All Weapons", "Get all weapons.");
            UIMenuItem         removeAllWeapons = new UIMenuItem("Remove All Weapons", "Removes all weapons in your inventory.");
            UIMenuCheckboxItem unlimitedAmmo    = new UIMenuCheckboxItem("Unlimited Ammo", UnlimitedAmmo, "Unlimited ammonition supply.");
            UIMenuCheckboxItem noReload         = new UIMenuCheckboxItem("No Reload", NoReload, "Never reload.");
            UIMenuItem         setAmmo          = new UIMenuItem("Set All Ammo Count", "Set the amount of ammo in all your weapons.");
            UIMenuItem         refillMaxAmmo    = new UIMenuItem("Refill All Ammo", "Give all your weapons max ammo.");
            ValidWeapons       vw          = new ValidWeapons();
            UIMenuItem         spawnByName = new UIMenuItem("Spawn Weapon By Name", "Enter a weapon mode name to spawn.");

            // Add items based on permissions
            if (cf.IsAllowed(Permission.WPGetAll))
            {
                menu.AddItem(getAllWeapons);
            }
            if (cf.IsAllowed(Permission.WPRemoveAll))
            {
                menu.AddItem(removeAllWeapons);
            }
            if (cf.IsAllowed(Permission.WPUnlimitedAmmo))
            {
                menu.AddItem(unlimitedAmmo);
            }
            if (cf.IsAllowed(Permission.WPNoReload))
            {
                menu.AddItem(noReload);
            }
            if (cf.IsAllowed(Permission.WPSetAllAmmo))
            {
                menu.AddItem(setAmmo);
                menu.AddItem(refillMaxAmmo);
            }
            if (cf.IsAllowed(Permission.WPSpawn))
            {
                menu.AddItem(spawnByName);
            }
            #endregion

            #region addonweapons submenu
            UIMenuItem addonWeaponsBtn  = new UIMenuItem("Addon Weapons", "Equip / remove addon weapons available on this server.");
            UIMenu     addonWeaponsMenu = new UIMenu("Addon Weapons", "Equip/Remove Addon Weapons", true)
            {
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false,
                ScaleWithSafezone       = false
            };
            menu.AddItem(addonWeaponsBtn);

            #region manage creating and accessing addon weapons menu
            if (cf.IsAllowed(Permission.WPSpawn) && AddonWeapons != null && AddonWeapons.Count > 0)
            {
                menu.BindMenuToItem(addonWeaponsMenu, addonWeaponsBtn);
                foreach (KeyValuePair <string, uint> weapon in AddonWeapons)
                {
                    string name  = weapon.Key.ToString();
                    uint   model = weapon.Value;
                    var    item  = new UIMenuItem(name, $"Click to add/remove this weapon ({name}) to/from your inventory.");
                    addonWeaponsMenu.AddItem(item);
                    if (!IsWeaponValid(model))
                    {
                        item.Enabled = false;
                        item.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                        item.Description = "This model is not available. Please ask the server owner to verify it's being streamed correctly.";
                    }
                }
                addonWeaponsMenu.OnItemSelect += (sender, item, index) =>
                {
                    var weapon = AddonWeapons.ElementAt(index);
                    if (HasPedGotWeapon(PlayerPedId(), weapon.Value, false))
                    {
                        RemoveWeaponFromPed(PlayerPedId(), weapon.Value);
                    }
                    else
                    {
                        var maxAmmo = 200;
                        GetMaxAmmo(PlayerPedId(), weapon.Value, ref maxAmmo);
                        GiveWeaponToPed(PlayerPedId(), weapon.Value, maxAmmo, false, true);
                    }
                };
                addonWeaponsBtn.SetRightLabel("→→→");
            }
            else
            {
                addonWeaponsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                addonWeaponsBtn.Enabled     = false;
                addonWeaponsBtn.Description = "This option is not available on this server because you don't have permission to use it, or it is not setup correctly.";
            }
            #endregion

            addonWeaponsMenu.RefreshIndex();
            addonWeaponsMenu.UpdateScaleform();
            #endregion

            #region parachute options menu
            #region parachute buttons and submenus
            UIMenuItem parachuteBtn  = new UIMenuItem("Parachute Options", "All parachute related options can be changed here.");
            UIMenu     parachuteMenu = new UIMenu("Parachute Options", "Parachute Options", true)
            {
                MouseEdgeEnabled        = false,
                MouseControlsEnabled    = false,
                ControlDisablingEnabled = false,
                ScaleWithSafezone       = false
            };

            UIMenu primaryChute = new UIMenu("Parachute Options", "Select A Primary Parachute", true)
            {
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false,
                ScaleWithSafezone       = false
            };

            UIMenu secondaryChute = new UIMenu("Parachute Options", "Select A Reserve Parachute", true)
            {
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
                ControlDisablingEnabled = false,
                ScaleWithSafezone       = false
            };

            UIMenuItem chute    = new UIMenuItem("No Style", "Default parachute.");
            UIMenuItem chute0   = new UIMenuItem(GetLabelText("PM_TINT0"), GetLabelText("PD_TINT0"));            // Rainbow Chute
            UIMenuItem chute1   = new UIMenuItem(GetLabelText("PM_TINT1"), GetLabelText("PD_TINT1"));            // Red Chute
            UIMenuItem chute2   = new UIMenuItem(GetLabelText("PM_TINT2"), GetLabelText("PD_TINT2"));            // Seaside Stripes Chute
            UIMenuItem chute3   = new UIMenuItem(GetLabelText("PM_TINT3"), GetLabelText("PD_TINT3"));            // Window Maker Chute
            UIMenuItem chute4   = new UIMenuItem(GetLabelText("PM_TINT4"), GetLabelText("PD_TINT4"));            // Patriot Chute
            UIMenuItem chute5   = new UIMenuItem(GetLabelText("PM_TINT5"), GetLabelText("PD_TINT5"));            // Blue Chute
            UIMenuItem chute6   = new UIMenuItem(GetLabelText("PM_TINT6"), GetLabelText("PD_TINT6"));            // Black Chute
            UIMenuItem chute7   = new UIMenuItem(GetLabelText("PM_TINT7"), GetLabelText("PD_TINT7"));            // Hornet Chute
            UIMenuItem chute8   = new UIMenuItem(GetLabelText("PS_CAN_0"), "Air Force parachute.");              // Air Force Chute
            UIMenuItem chute9   = new UIMenuItem(GetLabelText("PM_TINT0"), "Desert parachute.");                 // Desert Chute
            UIMenuItem chute10  = new UIMenuItem("Shadow Chute", "Shadow parachute.");                           // Shadow Chute
            UIMenuItem chute11  = new UIMenuItem(GetLabelText("UNLOCK_NAME_PSRWD"), "High altitude parachute."); // High Altitude Chute
            UIMenuItem chute12  = new UIMenuItem("Airborne Chute", "Airborne parachute.");                       // Airborne Chute
            UIMenuItem chute13  = new UIMenuItem("Sunrise Chute", "Sunrise parachute.");                         // Sunrise Chute
            UIMenuItem rchute   = new UIMenuItem("No Style", "Default parachute.");
            UIMenuItem rchute0  = new UIMenuItem(GetLabelText("PM_TINT0"), GetLabelText("PD_TINT0"));            // Rainbow Chute
            UIMenuItem rchute1  = new UIMenuItem(GetLabelText("PM_TINT1"), GetLabelText("PD_TINT1"));            // Red Chute
            UIMenuItem rchute2  = new UIMenuItem(GetLabelText("PM_TINT2"), GetLabelText("PD_TINT2"));            // Seaside Stripes Chute
            UIMenuItem rchute3  = new UIMenuItem(GetLabelText("PM_TINT3"), GetLabelText("PD_TINT3"));            // Window Maker Chute
            UIMenuItem rchute4  = new UIMenuItem(GetLabelText("PM_TINT4"), GetLabelText("PD_TINT4"));            // Patriot Chute
            UIMenuItem rchute5  = new UIMenuItem(GetLabelText("PM_TINT5"), GetLabelText("PD_TINT5"));            // Blue Chute
            UIMenuItem rchute6  = new UIMenuItem(GetLabelText("PM_TINT6"), GetLabelText("PD_TINT6"));            // Black Chute
            UIMenuItem rchute7  = new UIMenuItem(GetLabelText("PM_TINT7"), GetLabelText("PD_TINT7"));            // Hornet Chute
            UIMenuItem rchute8  = new UIMenuItem(GetLabelText("PS_CAN_0"), "Air Force parachute.");              // Air Force Chute
            UIMenuItem rchute9  = new UIMenuItem(GetLabelText("PM_TINT0"), "Desert parachute.");                 // Desert Chute
            UIMenuItem rchute10 = new UIMenuItem("Shadow Chute", "Shadow parachute.");                           // Shadow Chute
            UIMenuItem rchute11 = new UIMenuItem(GetLabelText("UNLOCK_NAME_PSRWD"), "High altitude parachute."); // High Altitude Chute
            UIMenuItem rchute12 = new UIMenuItem("Airborne Chute", "Airborne parachute.");                       // Airborne Chute
            UIMenuItem rchute13 = new UIMenuItem("Sunrise Chute", "Sunrise parachute.");                         // Sunrise Chute

            primaryChute.AddItem(chute);
            primaryChute.AddItem(chute0);
            primaryChute.AddItem(chute1);
            primaryChute.AddItem(chute2);
            primaryChute.AddItem(chute3);
            primaryChute.AddItem(chute4);
            primaryChute.AddItem(chute5);
            primaryChute.AddItem(chute6);
            primaryChute.AddItem(chute7);
            primaryChute.AddItem(chute8);
            primaryChute.AddItem(chute9);
            primaryChute.AddItem(chute10);
            primaryChute.AddItem(chute11);
            primaryChute.AddItem(chute12);
            primaryChute.AddItem(chute13);

            secondaryChute.AddItem(rchute);
            secondaryChute.AddItem(rchute0);
            secondaryChute.AddItem(rchute1);
            secondaryChute.AddItem(rchute2);
            secondaryChute.AddItem(rchute3);
            secondaryChute.AddItem(rchute4);
            secondaryChute.AddItem(rchute5);
            secondaryChute.AddItem(rchute6);
            secondaryChute.AddItem(rchute7);
            secondaryChute.AddItem(rchute8);
            secondaryChute.AddItem(rchute9);
            secondaryChute.AddItem(rchute10);
            secondaryChute.AddItem(rchute11);
            secondaryChute.AddItem(rchute12);
            secondaryChute.AddItem(rchute13);
            #endregion

            #region handle events
            primaryChute.OnItemSelect += (sender, item, index) =>
            {
                SetPedParachuteTintIndex(PlayerPedId(), index - 1);
                Subtitle.Custom($"Primary parachute style selected: ~r~{item.Text}~s~.");
            };

            secondaryChute.OnItemSelect += (sender, item, index) =>
            {
                SetPlayerReserveParachuteTintIndex(PlayerId(), index - 1);
                Subtitle.Custom($"Reserve parachute style selected: ~r~{item.Text}~s~.");
            };
            #endregion

            #region create more buttons
            UIMenuItem primaryChuteBtn   = new UIMenuItem("Primary Parachute Style", "Select a primary parachute.");
            UIMenuItem secondaryChuteBtn = new UIMenuItem("Reserve Parachute Style", "Select a reserve parachute.");

            parachuteMenu.AddItem(primaryChuteBtn);
            primaryChuteBtn.SetRightLabel("→→→");
            parachuteMenu.AddItem(secondaryChuteBtn);
            secondaryChuteBtn.SetRightLabel("→→→");

            parachuteMenu.BindMenuToItem(primaryChute, primaryChuteBtn);
            parachuteMenu.BindMenuToItem(secondaryChute, secondaryChuteBtn);

            UIMenuCheckboxItem autoEquipParachute = new UIMenuCheckboxItem("Auto Equip Parachute", AutoEquipChute, "Automatically equip a parachute whenever you enter a plane/helicopter.");
            parachuteMenu.AddItem(autoEquipParachute);

            UIMenuItem togglePrimary   = new UIMenuItem("Get / Remove Primary Parachute", "Equip a primary parachute.");
            UIMenuItem toggleSecondary = new UIMenuItem("Get Reserve Parachute", "Equip a reserve parachute, you need to get a primary parachute first before equipping a reserve parachute.");

            parachuteMenu.AddItem(togglePrimary);
            parachuteMenu.AddItem(toggleSecondary);
            #endregion

            #region handle parachute menu events
            parachuteMenu.OnItemSelect += (sender, item, index) =>
            {
                if (item == togglePrimary)
                {
                    if (HasPedGotWeapon(PlayerPedId(), (uint)WeaponHash.Parachute, false))
                    {
                        RemoveWeaponFromPed(PlayerPedId(), (uint)WeaponHash.Parachute);
                        Notify.Success("Primary parachute ~r~removed~s~.", true);
                    }
                    else
                    {
                        GiveWeaponToPed(PlayerPedId(), (uint)WeaponHash.Parachute, 1, false, false);
                        Notify.Success("Primary parachute ~g~equippped~s~.", true);
                    }
                }
                else if (item == toggleSecondary)
                {
                    SetPlayerHasReserveParachute(PlayerId());
                    Notify.Success("Reserve parachute ~g~equippped~s~.", true);
                }
            };

            parachuteMenu.OnCheckboxChange += (sender, item, _checked) =>
            {
                if (item == autoEquipParachute)
                {
                    AutoEquipChute = _checked;
                }
            };
            #endregion

            #region parachute smoke trail colors
            List <dynamic> smokeColor = new List <dynamic>()
            {
                "White",
                "Yellow",
                "Red",
                "Green",
                "Blue",
                "Dark Gray",
            };

            UIMenuListItem smokeColors = new UIMenuListItem("Smoke Trail Color", smokeColor, 0, "Select a parachute smoke trail color.");
            parachuteMenu.AddItem(smokeColors);
            parachuteMenu.OnListChange += (sender, item, index) =>
            {
                if (item == smokeColors)
                {
                    SetPlayerCanLeaveParachuteSmokeTrail(PlayerId(), false);
                    if (index == 0)
                    {
                        SetPlayerParachuteSmokeTrailColor(PlayerId(), 255, 255, 255);
                    }
                    else if (index == 1)
                    {
                        SetPlayerParachuteSmokeTrailColor(PlayerId(), 255, 255, 0);
                    }
                    else if (index == 2)
                    {
                        SetPlayerParachuteSmokeTrailColor(PlayerId(), 255, 0, 0);
                    }
                    else if (index == 3)
                    {
                        SetPlayerParachuteSmokeTrailColor(PlayerId(), 0, 255, 0);
                    }
                    else if (index == 4)
                    {
                        SetPlayerParachuteSmokeTrailColor(PlayerId(), 0, 0, 255);
                    }
                    else if (index == 5)
                    {
                        SetPlayerParachuteSmokeTrailColor(PlayerId(), 1, 1, 1);
                    }

                    SetPlayerCanLeaveParachuteSmokeTrail(PlayerId(), true);
                }
            };
            #endregion

            #region misc parachute menu setup
            menu.AddItem(parachuteBtn);
            parachuteBtn.SetRightLabel("→→→");
            menu.BindMenuToItem(parachuteMenu, parachuteBtn);

            parachuteMenu.RefreshIndex();
            parachuteMenu.UpdateScaleform();

            primaryChute.RefreshIndex();
            primaryChute.UpdateScaleform();

            secondaryChute.RefreshIndex();
            secondaryChute.UpdateScaleform();

            MainMenu.Mp.Add(addonWeaponsMenu);
            MainMenu.Mp.Add(parachuteMenu);
            MainMenu.Mp.Add(primaryChute);
            MainMenu.Mp.Add(secondaryChute);
            #endregion
            #endregion

            #region Create Weapon Category Submenus
            UIMenuItem spacer = cf.GetSpacerMenuItem("↓ Weapon Categories ↓");
            menu.AddItem(spacer);

            UIMenu handGuns = new UIMenu("Weapons", "Handguns", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            handGuns.SetMenuWidthOffset(50);
            UIMenuItem handGunsBtn = new UIMenuItem("Handguns");

            UIMenu rifles = new UIMenu("Weapons", "Assault Rifles", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            rifles.SetMenuWidthOffset(50);
            UIMenuItem riflesBtn = new UIMenuItem("Assault Rifles");

            UIMenu shotguns = new UIMenu("Weapons", "Shotguns", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            shotguns.SetMenuWidthOffset(50);
            UIMenuItem shotgunsBtn = new UIMenuItem("Shotguns");

            UIMenu smgs = new UIMenu("Weapons", "Sub-/Light Machine Guns", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            smgs.SetMenuWidthOffset(50);
            UIMenuItem smgsBtn = new UIMenuItem("Sub-/Light Machine Guns");

            UIMenu throwables = new UIMenu("Weapons", "Throwables", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            throwables.SetMenuWidthOffset(50);
            UIMenuItem throwablesBtn = new UIMenuItem("Throwables");

            UIMenu melee = new UIMenu("Weapons", "Melee", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            melee.SetMenuWidthOffset(50);
            UIMenuItem meleeBtn = new UIMenuItem("Melee");

            UIMenu heavy = new UIMenu("Weapons", "Heavy Weapons", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            heavy.SetMenuWidthOffset(50);
            UIMenuItem heavyBtn = new UIMenuItem("Heavy Weapons");

            UIMenu snipers = new UIMenu("Weapons", "Sniper Rifles", true)
            {
                ScaleWithSafezone       = false,
                ControlDisablingEnabled = false,
                MouseControlsEnabled    = false,
                MouseEdgeEnabled        = false,
            };
            snipers.SetMenuWidthOffset(50);
            UIMenuItem snipersBtn = new UIMenuItem("Sniper Rifles");

            MainMenu.Mp.Add(handGuns);
            MainMenu.Mp.Add(rifles);
            MainMenu.Mp.Add(shotguns);
            MainMenu.Mp.Add(smgs);
            MainMenu.Mp.Add(throwables);
            MainMenu.Mp.Add(melee);
            MainMenu.Mp.Add(heavy);
            MainMenu.Mp.Add(snipers);
            #endregion

            #region Setup weapon category buttons and submenus.
            handGunsBtn.SetRightLabel("→→→");
            menu.AddItem(handGunsBtn);
            menu.BindMenuToItem(handGuns, handGunsBtn);

            riflesBtn.SetRightLabel("→→→");
            menu.AddItem(riflesBtn);
            menu.BindMenuToItem(rifles, riflesBtn);

            shotgunsBtn.SetRightLabel("→→→");
            menu.AddItem(shotgunsBtn);
            menu.BindMenuToItem(shotguns, shotgunsBtn);

            smgsBtn.SetRightLabel("→→→");
            menu.AddItem(smgsBtn);
            menu.BindMenuToItem(smgs, smgsBtn);

            throwablesBtn.SetRightLabel("→→→");
            menu.AddItem(throwablesBtn);
            menu.BindMenuToItem(throwables, throwablesBtn);

            meleeBtn.SetRightLabel("→→→");
            menu.AddItem(meleeBtn);
            menu.BindMenuToItem(melee, meleeBtn);

            heavyBtn.SetRightLabel("→→→");
            menu.AddItem(heavyBtn);
            menu.BindMenuToItem(heavy, heavyBtn);

            snipersBtn.SetRightLabel("→→→");
            menu.AddItem(snipersBtn);
            menu.BindMenuToItem(snipers, snipersBtn);
            #endregion

            #region Loop through all weapons, create menus for them and add all menu items and handle events.
            foreach (ValidWeapon weapon in vw.WeaponList)
            {
                uint cat = (uint)GetWeapontypeGroup(weapon.Hash);
                if (weapon.Name != null && (cf.IsAllowed(weapon.Perm) || cf.IsAllowed(Permission.WPGetAll)))
                {
                    #region Create menu for this weapon and add buttons
                    UIMenu weaponMenu = new UIMenu("Weapon Options", weapon.Name, true)
                    {
                        ScaleWithSafezone       = false,
                        MouseControlsEnabled    = false,
                        MouseEdgeEnabled        = false,
                        ControlDisablingEnabled = false
                    };
                    UIMenuItem weaponItem = new UIMenuItem(weapon.Name, $"Open the options for ~y~{weapon.Name.ToString()}~s~.");
                    weaponItem.SetRightLabel("→→→");
                    weaponItem.SetLeftBadge(UIMenuItem.BadgeStyle.Gun);

                    MainMenu.Mp.Add(weaponMenu);

                    weaponInfo.Add(weaponMenu, weapon);

                    UIMenuItem getOrRemoveWeapon = new UIMenuItem("Equip/Remove Weapon", "Add or remove this weapon to/form your inventory.");
                    getOrRemoveWeapon.SetLeftBadge(UIMenuItem.BadgeStyle.Gun);
                    weaponMenu.AddItem(getOrRemoveWeapon);
                    if (!cf.IsAllowed(Permission.WPSpawn))
                    {
                        getOrRemoveWeapon.Enabled     = false;
                        getOrRemoveWeapon.Description = "This option has been disabled by the server owner.";
                        getOrRemoveWeapon.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                    }

                    UIMenuItem fillAmmo = new UIMenuItem("Re-fill Ammo", "Get max ammo for this weapon.");
                    fillAmmo.SetLeftBadge(UIMenuItem.BadgeStyle.Ammo);
                    weaponMenu.AddItem(fillAmmo);

                    List <dynamic> tints = new List <dynamic>();
                    if (weapon.Name.Contains(" Mk II"))
                    {
                        foreach (var tint in ValidWeapons.WeaponTintsMkII)
                        {
                            tints.Add(tint.Key);
                        }
                    }
                    else
                    {
                        foreach (var tint in ValidWeapons.WeaponTints)
                        {
                            tints.Add(tint.Key);
                        }
                    }

                    UIMenuListItem weaponTints = new UIMenuListItem("Tints", tints, 0, "Select a tint for your weapon.");
                    weaponMenu.AddItem(weaponTints);
                    #endregion

                    #region Handle weapon specific list changes
                    weaponMenu.OnListChange += (sender, item, index) =>
                    {
                        if (item == weaponTints)
                        {
                            if (HasPedGotWeapon(PlayerPedId(), weaponInfo[sender].Hash, false))
                            {
                                SetPedWeaponTintIndex(PlayerPedId(), weaponInfo[sender].Hash, index);
                            }
                            else
                            {
                                Notify.Error("You need to get the weapon first!");
                            }
                        }
                    };
                    #endregion

                    #region Handle weapon specific button presses
                    weaponMenu.OnItemSelect += (sender, item, index) =>
                    {
                        if (item == getOrRemoveWeapon)
                        {
                            var  info = weaponInfo[sender];
                            uint hash = info.Hash;
                            if (HasPedGotWeapon(PlayerPedId(), hash, false))
                            {
                                RemoveWeaponFromPed(PlayerPedId(), hash);
                                Subtitle.Custom("Weapon removed.");
                            }
                            else
                            {
                                var ammo = 255;
                                GetMaxAmmo(PlayerPedId(), hash, ref ammo);
                                GiveWeaponToPed(PlayerPedId(), hash, ammo, false, true);
                                Subtitle.Custom("Weapon added.");
                            }
                        }
                        else if (item == fillAmmo)
                        {
                            if (HasPedGotWeapon(PlayerPedId(), weaponInfo[sender].Hash, false))
                            {
                                var ammo = 900;
                                GetMaxAmmo(PlayerPedId(), weaponInfo[sender].Hash, ref ammo);
                                SetAmmoInClip(PlayerPedId(), weaponInfo[sender].Hash, ammo);
                            }
                            else
                            {
                                Notify.Error("You need to get the weapon first before re-filling ammo!");
                            }
                        }
                    };
                    #endregion

                    #region load components
                    if (weapon.Components != null)
                    {
                        if (weapon.Components.Count > 0)
                        {
                            foreach (var comp in weapon.Components)
                            {
                                UIMenuItem compItem = new UIMenuItem(comp.Key, "Click to equip or remove this component.");
                                weaponComponents.Add(compItem, comp.Key);
                                weaponMenu.AddItem(compItem);

                                #region Handle component button presses
                                weaponMenu.OnItemSelect += (sender, item, index) =>
                                {
                                    if (item == compItem)
                                    {
                                        var Weapon        = weaponInfo[sender];
                                        var componentHash = Weapon.Components[weaponComponents[item]];
                                        if (HasPedGotWeapon(PlayerPedId(), Weapon.Hash, false))
                                        {
                                            if (HasPedGotWeaponComponent(PlayerPedId(), Weapon.Hash, componentHash))
                                            {
                                                RemoveWeaponComponentFromPed(PlayerPedId(), Weapon.Hash, componentHash);
                                                Subtitle.Custom("Component removed.");
                                            }
                                            else
                                            {
                                                GiveWeaponComponentToPed(PlayerPedId(), Weapon.Hash, componentHash);
                                                Subtitle.Custom("Component equiped.");
                                            }
                                        }
                                        else
                                        {
                                            Notify.Error("You need to get the weapon first before you can modify it.");
                                        }
                                    }
                                };
                                #endregion
                            }
                        }
                    }
                    #endregion

                    // refresh and add to menu.
                    weaponMenu.RefreshIndex();
                    weaponMenu.UpdateScaleform();

                    if (cat == 970310034) // 970310034 rifles
                    {
                        rifles.AddItem(weaponItem);
                        rifles.BindMenuToItem(weaponMenu, weaponItem);
                    }
                    else if (cat == 416676503 || cat == 690389602) // 416676503 hand guns // 690389602 stun gun
                    {
                        handGuns.AddItem(weaponItem);
                        handGuns.BindMenuToItem(weaponMenu, weaponItem);
                    }
                    else if (cat == 860033945) // 860033945 shotguns
                    {
                        shotguns.AddItem(weaponItem);
                        shotguns.BindMenuToItem(weaponMenu, weaponItem);
                    }
                    else if (cat == 3337201093 || cat == 1159398588) // 3337201093 sub machine guns // 1159398588 light machine guns
                    {
                        smgs.AddItem(weaponItem);
                        smgs.BindMenuToItem(weaponMenu, weaponItem);
                    }
                    else if (cat == 1548507267 || cat == 4257178988 || cat == 1595662460) // 1548507267 throwables // 4257178988 fire extinghuiser // jerry can
                    {
                        throwables.AddItem(weaponItem);
                        throwables.BindMenuToItem(weaponMenu, weaponItem);
                    }
                    else if (cat == 3566412244 || cat == 2685387236) // 3566412244 melee weapons // 2685387236 knuckle duster
                    {
                        melee.AddItem(weaponItem);
                        melee.BindMenuToItem(weaponMenu, weaponItem);
                    }
                    else if (cat == 2725924767) // 2725924767 heavy weapons
                    {
                        heavy.AddItem(weaponItem);
                        heavy.BindMenuToItem(weaponMenu, weaponItem);
                    }
                    else if (cat == 3082541095) // 3082541095 sniper rifles
                    {
                        snipers.AddItem(weaponItem);
                        snipers.BindMenuToItem(weaponMenu, weaponItem);
                    }
                }
            }
            #endregion

            #region Disable submenus if no weapons in that category are allowed.
            if (handGuns.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(handGunsBtn);
                handGunsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                handGunsBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                handGunsBtn.Enabled     = false;
            }
            if (rifles.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(riflesBtn);
                riflesBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                riflesBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                riflesBtn.Enabled     = false;
            }
            if (shotguns.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(shotgunsBtn);
                shotgunsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                shotgunsBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                shotgunsBtn.Enabled     = false;
            }
            if (smgs.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(smgsBtn);
                smgsBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                smgsBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                smgsBtn.Enabled     = false;
            }
            if (throwables.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(throwablesBtn);
                throwablesBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                throwablesBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                throwablesBtn.Enabled     = false;
            }
            if (melee.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(meleeBtn);
                meleeBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                meleeBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                meleeBtn.Enabled     = false;
            }
            if (heavy.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(heavyBtn);
                heavyBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                heavyBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                heavyBtn.Enabled     = false;
            }
            if (snipers.MenuItems.Count == 0)
            {
                menu.ReleaseMenuFromItem(snipersBtn);
                snipersBtn.SetLeftBadge(UIMenuItem.BadgeStyle.Lock);
                snipersBtn.Description = "The server owner removed the permissions for all weapons in this category.";
                snipersBtn.Enabled     = false;
            }
            #endregion

            #region Handle button presses
            menu.OnItemSelect += (sender, item, index) =>
            {
                Ped ped = new Ped(PlayerPedId());
                if (item == getAllWeapons)
                {
                    foreach (var weapon in ValidWeapons.Weapons)
                    {
                        var ammo = 255;
                        GetMaxAmmo(PlayerPedId(), weapon.Value, ref ammo);
                        ped.Weapons.Give((WeaponHash)weapon.Value, ammo, weapon.Key == "Unarmed", true);
                    }
                    ped.Weapons.Give(WeaponHash.Unarmed, 0, true, true);
                }
                else if (item == removeAllWeapons)
                {
                    ped.Weapons.RemoveAll();
                }
                else if (item == setAmmo)
                {
                    cf.SetAllWeaponsAmmo();
                }
                else if (item == refillMaxAmmo)
                {
                    foreach (var wp in ValidWeapons.Weapons)
                    {
                        if (ped.Weapons.HasWeapon((WeaponHash)wp.Value))
                        {
                            int maxammo = 200;
                            GetMaxAmmo(ped.Handle, wp.Value, ref maxammo);
                            SetPedAmmo(ped.Handle, wp.Value, maxammo);
                        }
                    }
                }
                else if (item == spawnByName)
                {
                    cf.SpawnCustomWeapon();
                }
            };
            #endregion

            #region Handle checkbox changes
            menu.OnCheckboxChange += (sender, item, _checked) =>
            {
                if (item == noReload)
                {
                    NoReload = _checked;
                    Subtitle.Custom($"No reload is now {(_checked ? "enabled" : "disabled")}.");
                }
                else if (item == unlimitedAmmo)
                {
                    UnlimitedAmmo = _checked;
                    Subtitle.Custom($"Unlimited ammo is now {(_checked ? "enabled" : "disabled")}.");
                }
            };
            #endregion
        }
Example #25
0
        public Main()
        {
            // Initialize managers
            AmmoTypeManager.Init();
            MaterialManager.Init();
            ConversionManager.Init();
            BenchManager.Init();

            // NativeUI
            Point          noBannerOffset = new Point(0, -107);
            UIResRectangle emptyBanner    = new UIResRectangle(Point.Empty, Size.Empty, Color.Empty);

            // Main menu
            BenchMain = new UIMenu(string.Empty, "SELECT AN OPTION", noBannerOffset);
            BenchMain.SetBannerType(emptyBanner);

            // Generic list menu for displaying ammo types/bench materials, subtitle changes with BenchMain item selection
            BenchList = new UIMenu(string.Empty, "LIST MENU TITLE", noBannerOffset);
            BenchList.SetBannerType(emptyBanner);

            // Action menu, subtitle changes with BenchList item selection
            BenchAction = new UIMenu(string.Empty, "ACTION MENU TITLE", noBannerOffset);
            BenchAction.SetBannerType(emptyBanner);

            MaterialHeader = new UIMenuColoredItem("~b~MATERIAL", Color.Transparent, Color.Transparent);
            MaterialHeader.SetRightLabel("~b~BENCH");
            MaterialHeader.Enabled = false;

            // Amount button
            AmountItem = new UIMenuItem("Amount");
            AmountItem.SetRightLabel("Select...");

            // Confirm button
            ConfirmItem = new UIMenuItem("Confirm");
            ConfirmItem.SetLeftBadge(UIMenuItem.BadgeStyle.Tick);

            // Separators
            MaterialSeparator         = new UIMenuColoredItem("TITLE", Color.Black, Color.Black);
            MaterialSeparator.Enabled = false;

            ActionSeparator         = new UIMenuColoredItem("~b~ACTION", Color.Black, Color.Black);
            ActionSeparator.Enabled = false;

            // Menu relations
            BenchMain.BindMenuToItem(BenchList, new UIMenuItem("Craft Ammo"));
            BenchMain.BindMenuToItem(BenchList, new UIMenuItem("Dismantle Ammo"));
            BenchMain.BindMenuToItem(BenchList, new UIMenuItem("Bench Materials"));

            // Add menus to the menupool
            MenuPool.Add(BenchMain);
            MenuPool.Add(BenchList);
            MenuPool.Add(BenchAction);

            // Menu events
            BenchMain.OnItemSelect += BenchMain_OnItemSelect;
            BenchList.OnItemSelect += BenchList_OnItemSelect;
            AmountItem.Activated   += AmountItem_Activated;
            ConfirmItem.Activated  += ConfirmItem_Activated;

            // Events
            Tick    += Main_Tick;
            Aborted += Main_Aborted;
        }