/// <summary> /// Filters the log file based on <see cref="shipLoc"/> and the sector range listed in <see cref="textRange.Text"/>.</summary> /// Range calculation is simplified into a box shape for speed; min and max sector values are calculated for all three axis and the Map Log coordinates are kept if they fit in this box. private bool filterLog() { // Temporary storage for the new contents of the log file MapList tempLog = new MapList (); int range = MapPoint.intParse (txtRange.Text); // calculate sector ranges (+1 to make the range inclusive) int xmin = (int)shipLoc [0] - (range + 1); int xmax = (int)shipLoc [0] + (range + 1); int ymin = (int)shipLoc [1] - (range + 1); int ymax = (int)shipLoc [1] + (range + 1); int zmin = (int)shipLoc [2] - (range + 1); int zmax = (int)shipLoc [2] + (range + 1); // search for Map Log entries that are within the specified range foreach (MapPoint point in lstMasterLog) { if (point.sx > xmin && point.sx < xmax && point.sy > ymin && point.sy < ymax && point.sz > zmin && point.sz < zmax) { tempLog.Add (point); } } // sort the new list, if desired if (chkSort.Active && sortNeeded) { tempLog.Sort (sorter); sortNeeded = false; } // convert the new list into a string before opening the file for write (minimize the time the file is open) string tempLogText = tempLog.ToString(); // Replace the Map Log with the filtered resaults try { // delete the contents of the file before re-writing it. It's the easy way to ensure the file is overwritten and not appended to. deleteFile(btnMapLog.Label); using (System.IO.StreamWriter newLog = new System.IO.StreamWriter(OpenFile(btnMapLog.Label,true))) { newLog.Write(tempLog.ToString()); newLog.Close(); // remember what was written textMapLogFile = tempLogText; // remember when the file was last written lastLogged = getLastWriteTimeUTC(btnMapLog.Label); } } catch (System.ArgumentNullException) { // OpenFile should have already given an error message since OpenFile() returns null on error } return true; }
public static void RebuildLists(GameObject GO, InventoryScreenExtender.TabController TabController) { QudUX_InventoryScreenState SavedInventoryState = GO.RequirePart <QudUX_InventoryScreenState>(); //TabController.RecalculateWeights(GO); Inventory pInventory = GO.GetPart("Inventory") as Inventory; CategoryMap.Clear(); SelectionList.Clear(); ItemsSkippedByFilter = 0; int listHeightMinusOne = InventoryListHeight - 1; bool bIsFiltered = (FilterString != ""); if (!Categories.CleanContains("Category")) { Categories.Add("Category"); } List <GameObject> Objs = pInventory.GetObjectsDirect(); for (int x = 0; x < Objs.Count; x++) { GameObject Obj = Objs[x]; if (!Obj.HasTag("HiddenInInventory")) { string iCategory = Obj.GetInventoryCategory(); if (bIsFiltered && !Obj.GetCachedDisplayNameStripped().Contains(FilterString, CompareOptions.IgnoreCase)) { ItemsSkippedByFilter++; continue; } else if (!bIsFiltered) { if (TabController != null && !TabController.CurrentTabIncludes(iCategory)) { //if we're not filtering by string, include only the categories associated with the current tab continue; } } Obj.Seen(); if (!CategoryList.ContainsKey(iCategory)) { bool bExpandState = SavedInventoryState.GetExpandState(iCategory); CategoryList.Add(iCategory, new QudUX_InventoryCategory(iCategory, bExpandState)); Categories.Add(iCategory); } if (!CategoryMap.ContainsKey(iCategory)) { CategoryMap.Add(iCategory, new List <GameObject>()); } CategoryMap[iCategory].Add(Obj); } } foreach (List <GameObject> MapList in CategoryMap.Values) { MapList.Sort(displayNameSorter); } while (CategorySort >= Categories.Count) { CategorySort--; } if (CategorySort == -1) { SortList = pInventory.GetObjects(); SortList.Sort(displayNameSorter); } else if (Categories[CategorySort] == "Category") { SortList = pInventory.GetObjects(); SortList.Sort(categorySorter); } else { if (CategoryMap.ContainsKey(Categories[CategorySort])) { SortList = CategoryMap[Categories[CategorySort]]; } SortList.Sort(displayNameSorter); } int nEntries = 0; bMore = false; if (CategorySort != -1 && Categories[CategorySort] == "Category") { CategorySelectionList.Clear(); int nObject = 0; char c = 'a'; List <string> CatNames = new List <string>(); foreach (string N in CategoryList.Keys) { CatNames.Add(N); } CatNames.Sort(); for (int n = 0; n < CatNames.Count; n++) { string sCat = CatNames[n]; QudUX_InventoryCategory Cat = CategoryList[sCat]; if (forceCategorySelect != null && Cat == forceCategorySelect) { if (nObject < StartObject) { StartObject = nObject; } nSelected = nObject - StartObject; forceCategorySelect = null; } if (nObject >= StartObject && nObject <= listHeightMinusOne + StartObject) { CategorySelectionList.Add(c, new QudUX_CategorySelectionListEntry(Cat)); c++; nEntries++; } if (Cat.Expanded && CategoryMap.ContainsKey(Cat.Name)) { foreach (GameObject Obj in CategoryMap[Cat.Name]) { nObject++; nEntries++; if (nObject >= StartObject && nObject <= listHeightMinusOne + StartObject) { CategorySelectionList.Add(c, new QudUX_CategorySelectionListEntry(Obj)); c++; } else if (nObject > listHeightMinusOne + StartObject) { bMore = true; break; } } } if (CategoryList.ContainsKey(sCat)) { CategoryList[sCat].Weight = 0; CategoryList[sCat].Items = 0; } if (CategoryMap.ContainsKey(Cat.Name)) { foreach (GameObject Obj in CategoryMap[Cat.Name]) { if (Obj.pPhysics != null) { CategoryList[sCat].Weight += Obj.pPhysics.Weight; } CategoryList[sCat].Items++; } } if (nObject > listHeightMinusOne + StartObject) { bMore = true; break; } nObject++; } } else { if (pInventory != null) { int nObject = 0; char c = 'a'; foreach (GameObject Obj in SortList) { if (nObject >= StartObject && nObject <= listHeightMinusOne + StartObject) { SelectionList.Add(c, Obj); c++; } nObject++; if (nObject > listHeightMinusOne + StartObject) { bMore = true; break; } } } } List <string> RemovedCategories = new List <string>(); foreach (string sCat in CategoryList.Keys) { if (!CategoryMap.ContainsKey(sCat)) { RemovedCategories.Add(sCat); } else if (CategoryMap[sCat].Count == 0) { RemovedCategories.Add(sCat); } } foreach (string sRemovedCat in RemovedCategories) { if (CategoryList.ContainsKey(sRemovedCat)) { CategoryList.Remove(sRemovedCat); } if (CategoryMap.ContainsKey(sRemovedCat)) { CategoryMap.Remove(sRemovedCat); } } }