Godot Version
4.2.2
Question
Hello. I have a multi list ItemList which I am trying to dynamically select the items that were selected in the last session. I have saved the state of the items in a json. This works fine and the loading of the json.
I’m having difficulty with the code that selects the items. It ends up just highlighting the last item in the json in the iteration.
This the method that selects the items in the list
public static void LoadSelectionState()
{
var SaveFilePath = OpsDashboard.workItemTypeSaveFilePath;
string globalPath = ProjectSettings.GlobalizePath(SaveFilePath);
int workItemTypeListCount = OpsDashboard._workItemTypeList.ItemCount;
OpsDashboard._workItemTypeList.SelectMode = ItemList.SelectModeEnum.Multi;
if (!File.Exists(globalPath))
return;
var json = File.ReadAllText(globalPath);
var selectedItems = JsonSerializer.Deserialize<List<string>>(json);
if (selectedItems == null)
return;
for (int i = 0; i < workItemTypeListCount; i++)
{
if (selectedItems.Contains(OpsDashboard._workItemTypeList.GetItemText(i)))
{
OpsDashboard._workItemTypeList.Select(i);
}
}
}
Any help would be appreciated.
Thanks.