Assistance Needed for a refresh of dynamic list item...
-
As the title says, I have a dynamic list item on my sub menu, I actually have 2 of them. I have a car model type setup I am working on so you select the type of vehicle you want aka muscle, and the second list populates with all the hashes of that type. The issue I have is if I select muscle, the list loads, but then if I change it to sport, the list remains the same with all the muscle cars listed. So my second dynamic list is not updating when I have changed the first one of model.
-
@xhiyikfkox It might help if you explained whether this is your own menu system, or an existing library.
-
Not sure what you mean by that... I can say this though. I have been using NativeUI to make a modmenu, same one you helped me with before, but after getting the muscle car setup working I wanted to make a dynamic list setup. So the way it will work is dynaic list vehicleTypes gets all known vehicleclass's from the vehicleclass list, then fills it into the dynamic list ot vehicleTypes. When you select a type from that list I have dynamic list vehicleTypeHashes go and get all the vehicles of that type, ex vehicleTypes select muscle cehicleTyeHashes gets all the muscle car hashes. However if you then change the vehicleTypes to sports car, the vehicleTypeHashes dose not update with the new list. In otherwords its not refreshing.
-
@xhiyikfkox It didn't say you were using NativeUI, so it wasn't clear if that's what you were using. I know we've discussed your code before, but for anyone who hasn't they would have no idea if that's what you were using.
There are a lot of mods out there with menus that don't use it... that's why I mentioned it.
As for the problem, now I know it's NativeUI, unless he has changed the code and released the updated version, you can't do what you want. I had to get the source code and make my own changes to make it do that, because the List<dynamic> isn't a property you can set, unless it's in the UIMenuListItem constructor.
-
is there a way to remove it from the menu? if so I could just remove it and repost it to the menu after the change has been made.
-
@xhiyikfkox I can't remember to be honest... It's possible. I use my own menu system now so I don't know for sure.
I know a while back I was speaking to someone who needed the same thing and they did submit a pull request on GitHub to add the List<> access feature. I don't know if the available version has that code in it though.
I suppose the problem with that is the item that is getting refreshed would always have to be the bottom item in the menu, as that's where it would get added back.
-
List<dynamic> listOfVehicleTypes = new List<dynamic>();
VehicleClass[] allVehicleTypes = (VehicleClass[])Enum.GetValues(typeof(VehicleClass));
for(int i = 0; i < allVehicleTypes.Length; i++)
{
listOfVehicleTypes.Add(allVehicleTypes[i]);
}
UIMenuListItem types = new UIMenuListItem("Vehicle Types: ", listOfVehicleTypes, 0);
submenu.AddItem(types);List<dynamic> listOfVehicleHashesType = new List<dynamic>(); VehicleHash[] allVehicleHashes = (VehicleHash[])Enum.GetValues(typeof(VehicleHash)); int x = 0; submenu.OnListChange += (sender, listItem, newIndex) => { if (listItem == types) { listOfVehicleHashesType = new List<dynamic>(); VehicleClass getter = allVehicleTypes[newIndex]; for (int i = 0; i < allVehicleHashes.Length; i++) { if (Function.Call<int>(Hash.GET_VEHICLE_CLASS_FROM_NAME, (int)allVehicleHashes[i]) == (int)getter) { listOfVehicleHashesType.Add(allVehicleHashes[i]); } if (listOfVehicleHashesType.Count == 0) UI.Notify("Nothing in the list"); else UI.Notify("List Count: " + listOfVehicleHashesType.Count); } vehicleTypes = new UIMenuListItem("Vehicle: ", listOfVehicleHashesType, 0); if(x == 0) { submenu.AddItem(vehicleTypes); x++; } } };
was trying to think how to describe the code but figured posting would be better. As you can see I only call the hashes and post to menu once you change the list on the first dynamic list. I have my second list, the hashes declared in the main class so its not having to be created over and over in this area. but I only add the second list after the first change, then each time after it just says the second list is new to over write it but it does not refresh in game is the issue.
-
@xhiyikfkox You can't create a List<dynamic> pass it into the contructor of a UIMenuListItem and then change that original List<dynamic> and have it change on the menu.
You would have to set the List<> property of that UIMenuListItem with a new List<dynamic> or update it by accessing it through the UIMenuListItem. And that's the thing you can't do, unless he has released the updated code.
-
Think of it like this. In this code, if Y is changed after being assigned to Foo, myX inside Foo doesn't get updated.
int Y = 10; Foo myFoo = new Foo(Y); Y = Y + 1; public class Foo { int myX; Public Foo(int x) { myX = x; } }
-
Asked my Dad if he could check the code a moment and told him what I was trying to do... Like a min later this is his change:
vehicleTypes = new UIMenuListItem("Vehicle: ", listOfVehicleHashesType, 0);
if(x == 1)
{
submenu.RemoveItemAt(submenu.MenuItems.Count() - 1 );
}
submenu.AddItem(vehicleTypes);
x = 1;and all works now just as I was wanting it to.
-
@xhiyikfkox Which as I said earlier, is fine if you know where the item is on the list, and it's at the end because List.AddItem adds it back onto the end.
And if the menu currently has the last item selected, you could very well generate an index out of range error because you have reduced the number of items by one and possibly removed the item that was currently indexed.
Brute force isn't always the solution, no matter how quickly that solution can be found.
-
Not sure if its brute forcing it but I can say it works thus far. Even setup my code to gen the second button as the first vehicleclass type in the type array by default and only change when you change the type. Also just got the vehicle spawn mechanic wired into it too
thus far all is working.