mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Fix launcher crashing when your selected server is the very bottom entry in the list, you refresh the list, and the very last server disappears from it
This commit is contained in:
parent
5adf0890fc
commit
a98f668e5d
@ -55,14 +55,13 @@ namespace Launcher.Gui.Widgets {
|
||||
}
|
||||
|
||||
void SortEntries(TableEntryComparer comparer, bool noRedraw) {
|
||||
string selHash = SelectedIndex >= 0 ? usedEntries[SelectedIndex].Hash : "";
|
||||
Array.Sort(usedEntries, 0, Count, comparer);
|
||||
Array.Sort(entries, 0, entries.Length, comparer);
|
||||
lastIndex = -10;
|
||||
if (noRedraw) return;
|
||||
|
||||
comparer.Invert = !comparer.Invert;
|
||||
SetSelected(selHash);
|
||||
SetSelected(SelectedHash);
|
||||
NeedRedraw();
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ namespace Launcher.Gui.Widgets {
|
||||
public TableNeedsRedrawHandler NeedRedraw;
|
||||
public Action<string> SelectedChanged;
|
||||
public int SelectedIndex = -1;
|
||||
public string SelectedHash = "";
|
||||
public int CurrentIndex, Count;
|
||||
|
||||
internal TableEntry[] entries, usedEntries;
|
||||
@ -56,7 +57,6 @@ namespace Launcher.Gui.Widgets {
|
||||
/// <summary> Filters the table such that only rows with server names
|
||||
/// that contain the input (case insensitive) are shown. </summary>
|
||||
public void FilterEntries(string filter) {
|
||||
string selHash = SelectedIndex >= 0 ? usedEntries[SelectedIndex].Hash : "";
|
||||
Count = 0;
|
||||
int index = 0;
|
||||
|
||||
@ -67,7 +67,7 @@ namespace Launcher.Gui.Widgets {
|
||||
usedEntries[index++] = entry;
|
||||
}
|
||||
}
|
||||
SetSelected(selHash);
|
||||
SetSelected(SelectedHash);
|
||||
}
|
||||
|
||||
internal void GetScrollbarCoords(out int y, out int height) {
|
||||
@ -85,11 +85,15 @@ namespace Launcher.Gui.Widgets {
|
||||
if (index >= Count) index = Count - 1;
|
||||
if (index < 0) index = 0;
|
||||
|
||||
SelectedHash = "";
|
||||
SelectedIndex = index;
|
||||
lastIndex = index;
|
||||
ClampIndex();
|
||||
if (Count > 0)
|
||||
|
||||
if (Count > 0) {
|
||||
SelectedChanged(usedEntries[index].Hash);
|
||||
SelectedHash = usedEntries[index].Hash;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSelected(string hash) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user