public void RefreshTreeView() { // First get the selected category so we can select it again after the refresh var selectedCategory = GetSelectedAchievementCategory(); tvwAchievementCategories.Nodes.Clear(); var categories = dataManager.GetAll(true); foreach (var category in categories) { if (category.Parent == null) { tvwAchievementCategories.Nodes.Add(new AchievementCategoryTreeNode(category)); } else { var node = FindAchievementCategoryNode(tvwAchievementCategories.Nodes, category.Parent); if (node != null) { node.Nodes.Add(new AchievementCategoryTreeNode(category)); } } } if (selectedCategory != null) { var node = FindAchievementCategoryNode(tvwAchievementCategories.Nodes, selectedCategory); if (node != null) { tvwAchievementCategories.SelectedNode = node; } } }
public void ExportCategories() { var sb = new StringBuilder(); sb.AppendLine($"-- [[ Exported at {DateTime.Now:yyyy-MM-dd HH-mm-ss} ]] --"); sb.AppendLine($"-- [[ This code is automatically generated as an export from ]] --"); sb.AppendLine($"-- [[ an SQLite database and is not meant for manual edit. ]] --"); sb.AppendLine(""); sb.AppendLine("-- [[ Namespaces ]] --"); sb.AppendLine("local _, addon = ...;"); sb.AppendLine("local objects = addon.Objects;"); sb.AppendLine("local achievementCategory = objects.AchievementCategory;"); sb.AppendLine("local data = addon.Data;"); sb.AppendLine("data.ExportedCategories = {};"); sb.AppendLine("local exportedCategories = data.ExportedCategories;"); sb.AppendLine(""); sb.AppendLine("local function InsertAndReturn(table, value)"); sb.AppendLineTabbed(1, "tinsert(table, value);"); sb.AppendLineTabbed(1, "return value;"); sb.AppendLine("end"); sb.AppendLine(""); sb.AppendLine("function exportedCategories.Load(categories, achievements)"); sb.AppendLineTabbed(1, "for i, _ in next, categories do"); sb.AppendLineTabbed(2, "categories[i] = nil;"); sb.AppendLineTabbed(1, "end"); sb.AppendLine(""); sb.AppendLineTabbed(1, "local tmpCategories = {};"); var categories = achCatDatMan.GetAll(); foreach (var category in categories) { if (!category.Active) { continue; } //var mapIDs = achCatDatMan.GetMapIDs(category); var appendString = $"tmpCategories[{category.ID}] = InsertAndReturn(categories, achievementCategory:New("; // New appendString += category.Function.Call.Replace("%value%", category.FunctionValue); // Category name appendString += $"{(category.Legacy ? $" .. \" (\" .. {funDatMan.GetLegacyFunction().Call} .. \")\"" : "")}"; // Legacy if applicable //appendString += ", "; //appendString += $"{(mapIDs.Any() ? $"{{{string.Join(", ", mapIDs)}}}" : "nil")}"; // MapIDs //appendString += ", "; //appendString += $"{(category.IgnoreParentMapIDs ? "true" : "nil")}"; // IgnoreParentMapIDs appendString += ", "; appendString += $"{(category.CanMerge ? "true" : "nil")}"; // CanMergeChildren appendString = TrimNils(appendString); // Remove unneccesary nils appendString += $")); -- {category.Name}"; sb.AppendLineTabbed(1, appendString); if (category.Parent != null) { sb.AppendLineTabbed(1, $"tmpCategories[{category.Parent.ID}]:AddCategory(tmpCategories[{category.ID}]);"); } if (category.Function.Description == "Current Zone") { sb.AppendLineTabbed(1, $"tmpCategories[{category.ID}].AlwaysVisible = true;"); sb.AppendLineTabbed(1, $"tmpCategories[{category.ID}].HasFlexibleData = true;"); sb.AppendLineTabbed(1, $"local currentZoneCategory = tmpCategories[{category.ID}];"); } if (category.Function.Description == "Coming in ") { sb.AppendLineTabbed(1, $"local nextPatchCategory = tmpCategories[{category.ID}];"); } var achievements = achDatMan.GetWithCategory(category); foreach (var achievement in achievements) { sb.AppendLineTabbed(1, $"tmpCategories[{category.ID}]:AddAchievement(achievements[{achievement.ID}]) -- {achievement.Name}"); } } sb.AppendLine(""); sb.AppendLineTabbed(1, "return currentZoneCategory, nextPatchCategory;"); sb.AppendLine("end"); using var file = new StreamWriter(@"../../../../../Krowi_AchievementFilter/Data/ExportedCategories.lua"); file.WriteLine(sb.ToString()); }