Server browser: keep the list stable between GUI passes (fixes 'Getting control 1's position' error)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+15
-6
@@ -44,6 +44,8 @@ namespace MSCO
|
|||||||
|
|
||||||
bool stylesReady;
|
bool stylesReady;
|
||||||
Texture2D texBackground, texSidebar, texAccent, texOnline, texPending, texMuted, texRow;
|
Texture2D texBackground, texSidebar, texAccent, texOnline, texPending, texMuted, texRow;
|
||||||
|
List<ServerListEntry> shownAll, shownServers; // Stand des letzten Layout-Durchgangs
|
||||||
|
string layoutError;
|
||||||
GUIStyle windowBox, sidebarBox, rowBox, accentBox, pillStyle, pillMutedStyle, chipOnStyle, chipOffStyle;
|
GUIStyle windowBox, sidebarBox, rowBox, accentBox, pillStyle, pillMutedStyle, chipOnStyle, chipOffStyle;
|
||||||
GUIStyle logoStyle, taglineStyle, navStyle, navActiveStyle, titleStyle, textStyle, captionStyle,
|
GUIStyle logoStyle, taglineStyle, navStyle, navActiveStyle, titleStyle, textStyle, captionStyle,
|
||||||
fieldStyle, primaryStyle, secondaryStyle, statusStyle, tabStyle, headerCellStyle,
|
fieldStyle, primaryStyle, secondaryStyle, statusStyle, tabStyle, headerCellStyle,
|
||||||
@@ -151,7 +153,11 @@ namespace MSCO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Server, die auf die direkte Abfrage nicht antworten (z.B. gerade geschlossen), gar nicht zeigen
|
// Server, die auf die direkte Abfrage nicht antworten (z.B. gerade geschlossen), gar nicht zeigen
|
||||||
List<ServerListEntry> all = browser.Servers.FindAll(s => !s.Offline);
|
// Unity-GUI läuft in mehreren Durchgängen (Layout, Klick, Zeichnen). Die Liste nur im Layout-Durchgang
|
||||||
|
// übernehmen - ändert sie sich dazwischen (Aktualisierung im Hintergrund), bricht das Layout sonst ab
|
||||||
|
if (shownAll == null || Event.current.type == EventType.Layout)
|
||||||
|
shownAll = browser.Servers.FindAll(s => !s.Offline);
|
||||||
|
List<ServerListEntry> all = shownAll;
|
||||||
|
|
||||||
// Server-Profil (Klick auf einen Server)
|
// Server-Profil (Klick auf einen Server)
|
||||||
if (selectedServer != null)
|
if (selectedServer != null)
|
||||||
@@ -186,10 +192,13 @@ namespace MSCO
|
|||||||
GUILayout.Space(6);
|
GUILayout.Space(6);
|
||||||
|
|
||||||
string search = (searchInput ?? "").Trim().ToLower();
|
string search = (searchInput ?? "").Trim().ToLower();
|
||||||
List<ServerListEntry> servers = all.FindAll(s =>
|
if (shownServers == null || Event.current.type == EventType.Layout)
|
||||||
(s.RequireSteam ? showSteam : showNonSteam) &&
|
shownServers = all.FindAll(s =>
|
||||||
(!hideFull || s.Players < s.MaxPlayers) &&
|
(s.RequireSteam ? showSteam : showNonSteam) &&
|
||||||
(search.Length == 0 || (s.Name ?? "").ToLower().Contains(search) || (s.Owner ?? "").ToLower().Contains(search)));
|
(!hideFull || s.Players < s.MaxPlayers) &&
|
||||||
|
(search.Length == 0 || (s.Name ?? "").ToLower().Contains(search) || (s.Owner ?? "").ToLower().Contains(search)));
|
||||||
|
List<ServerListEntry> servers = shownServers;
|
||||||
|
string shownError = Event.current.type == EventType.Layout ? (layoutError = browser.Error) : layoutError;
|
||||||
|
|
||||||
// Tabellenkopf
|
// Tabellenkopf
|
||||||
Rect header = GUILayoutUtility.GetRect(10, 26, GUILayout.ExpandWidth(true));
|
Rect header = GUILayoutUtility.GetRect(10, 26, GUILayout.ExpandWidth(true));
|
||||||
@@ -200,7 +209,7 @@ namespace MSCO
|
|||||||
GUI.Label(new Rect(header.x + header.width * 0.76f, header.y, 50, header.height), "PING", headerCellStyle);
|
GUI.Label(new Rect(header.x + header.width * 0.76f, header.y, 50, header.height), "PING", headerCellStyle);
|
||||||
|
|
||||||
serverScroll = GUILayout.BeginScrollView(serverScroll, GUILayout.Height(140));
|
serverScroll = GUILayout.BeginScrollView(serverScroll, GUILayout.Height(140));
|
||||||
if (browser.Error != null) GUILayout.Label(browser.Error, textStyle);
|
if (shownError != null) GUILayout.Label(shownError, textStyle);
|
||||||
if (servers.Count == 0)
|
if (servers.Count == 0)
|
||||||
GUILayout.Label(browser.Loading ? "Loading servers..." : all.Count > 0 ? "No servers match your filters." : "No servers online right now.", textStyle);
|
GUILayout.Label(browser.Loading ? "Loading servers..." : all.Count > 0 ? "No servers match your filters." : "No servers online right now.", textStyle);
|
||||||
foreach (ServerListEntry s in servers)
|
foreach (ServerListEntry s in servers)
|
||||||
|
|||||||
Reference in New Issue
Block a user