LemonUIbyLemon / LemonUI

LemonUI for .NET (FiveM, RageMP, RagePluginHook and ScriptHookVDotNet 3)
MIT License
177 stars 40 forks source link

Submenu not displaying? #156

Closed amir16yp closed 7 months ago

amir16yp commented 7 months ago

I'm using the the latest 2.0 release from github. for some reason everything works okay except for a submenu i created on the scripthoovdotnet 3.0 on sp code and video attached. I don't know what's causing this, what should I log, or am i missing something? Video: https://youtu.be/VaJ6l0L23zc Code:

using System;
using LemonUI;
using GTA;
using System.Windows.Forms;
using LemonUI.Menus;
using System.Collections.Generic;

namespace ChaosNGINE
{

    public class MainScript : Script
    {

        private ObjectPool pool = new ObjectPool();
        private NativeMenu nativeMenu = new NativeMenu("ChaosNGINE menu", "ChaosNGINE", "an Engine for Chaos");
        private NativeCheckboxItem godmodeItem = new NativeCheckboxItem("Player Godmode");
        private NativeListItem<int> wantedLevelItem = new NativeListItem<int>("Player Wanted Level (-1 for natural)", -1, 0, 1, 2, 3, 4, 5);
        private NativeCheckboxItem npcAggroToggle = new NativeCheckboxItem("NPC Aggro");
        private NativeMenu NPCgunCheckboxMenu = new NativeMenu("NPC Aggro Gun List", "NPC Aggro Gun List", "NPC Aggro guns list");
        private Random random = new Random();
        private Dictionary<Ped, bool> hasWeaponDictionary = new Dictionary<Ped, bool>();
        private GtaVLogger logger = new GtaVLogger();
        public MainScript()
        {
            Tick += onTick;
            KeyDown += onKey;
            nativeMenu.Add(godmodeItem);
            nativeMenu.Add(wantedLevelItem);
            nativeMenu.Add(npcAggroToggle);
            foreach (WeaponHash weaponHash in Enum.GetValues(typeof(WeaponHash)))
            {
                NativeCheckboxItem weaponItem = new NativeCheckboxItem(weaponHash.ToString());
                //logger.Log(weaponHash.ToString());
                NPCgunCheckboxMenu.Add(weaponItem);
            }
            NativeSubmenuItem npcAgroSubMenu = nativeMenu.AddSubMenu(NPCgunCheckboxMenu);
            pool.Add(nativeMenu);
        }

        private WeaponHash GetRandomWeapon()
        {
            List<WeaponHash> weapons = new List<WeaponHash>();
            foreach (NativeCheckboxItem item in NPCgunCheckboxMenu.Items)
            {
                if (item.Checked)
                {
                    weapons.Add((WeaponHash)Enum.Parse(typeof(WeaponHash), item.Title));
                }
            }
            if (weapons.Count == 0)
            {
                return WeaponHash.Pistol;
            }
            return weapons[random.Next(weapons.Count)];

        }

        private void onTick(object sender, EventArgs e)
        {
            pool.Process();
            Game.Player.IsInvincible = godmodeItem.Checked;
            if (wantedLevelItem.SelectedItem != -1)
            {
                Game.Player.WantedLevel = wantedLevelItem.SelectedItem;
            }
            if (npcAggroToggle.Checked)
            {
                foreach (Ped predator in World.GetNearbyPeds(Game.Player.Character, 100f))
                {
                    foreach (Ped target in World.GetNearbyPeds(predator, 100f))
                    {
                        if (!target.IsPlayer && !predator.IsPlayer && predator.IsAlive && target.IsAlive && target != predator && predator.IsHuman && target.IsHuman)
                        {
                            if (!hasWeaponDictionary.ContainsKey(predator))
                            {
                                WeaponHash randomWeapon = GetRandomWeapon();
                                predator.Weapons.Give(randomWeapon, 500, true, true);
                                predator.Weapons.Select(randomWeapon);
                                hasWeaponDictionary[predator] = true;
                            }

                            if (!hasWeaponDictionary.ContainsKey(target))
                            {
                                WeaponHash randomWeapon = GetRandomWeapon();
                                target.Weapons.Give(randomWeapon, 500, true, true);
                                target.Weapons.Select(randomWeapon);
                                hasWeaponDictionary[target] = true;
                            }

                            predator.Task.FightAgainst(target);
                            target.Task.FightAgainst(predator);
                        }

                    }
                }
            }
        }

        private void onKey(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                nativeMenu.Visible = !nativeMenu.Visible;
            }
        }
    }
}
justalemon commented 7 months ago

All of the menus need to be in the pool.

NPCgunCheckboxMenu is not in the pool.

amir16yp commented 7 months ago

All of the menus need to be in the pool.

NPCgunCheckboxMenu is not in the pool.

Oh right. this fixed it. I read the docs at the wiki and this wasn't obvious when i read it. is possible to update it to include this fact?

justalemon commented 7 months ago

From the quick start page:

Just remember that all of the Menus need to be added into an Object Pool, including submenus!