From 3d50bf4b7d652c02410f19e73087194ddea3a15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 5 Mar 2026 22:36:15 +0100 Subject: [PATCH] Add categories to the server list --- Core/Config.cpp | 2 +- Core/Config.h | 1 + UI/AdhocServerScreen.cpp | 59 ++++++++++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 4949a9b469..e66c0aed3a 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1043,7 +1043,7 @@ static const ConfigSetting networkSettings[] = { ConfigSetting("AllowSavestateWhileConnected", SETTING(g_Config, bAllowSavestateWhileConnected), false, CfgFlag::DONT_SAVE), ConfigSetting("AllowSpeedControlWhileConnected", SETTING(g_Config, bAllowSpeedControlWhileConnected), false, CfgFlag::PER_GAME), ConfigSetting("DontDownloadInfraJson", SETTING(g_Config, bDontDownloadInfraJson), false, CfgFlag::DONT_SAVE), - + ConfigSetting("proAdhocServerList", SETTING(g_Config, vCustomAdhocServerList), &std::vector(), CfgFlag::DEFAULT), // Customizable server list. ConfigSetting("EnableNetworkChat", SETTING(g_Config, bEnableNetworkChat), false, CfgFlag::PER_GAME), ConfigSetting("ChatButtonPosition", SETTING(g_Config, iChatButtonPosition), (int)ScreenEdgePosition::BOTTOM_LEFT, CfgFlag::PER_GAME), ConfigSetting("ChatScreenPosition", SETTING(g_Config, iChatScreenPosition), (int)ScreenEdgePosition::BOTTOM_LEFT, CfgFlag::PER_GAME), diff --git a/Core/Config.h b/Core/Config.h index 2dc7ccb7e3..4cd0342b64 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -560,6 +560,7 @@ public: bool bInfrastructureAutoDNS; bool bAllowSavestateWhileConnected; // Developer option, ini-only. No normal users need this, it's always wrong to save/load state when online. bool bAllowSpeedControlWhileConnected; // Useful in some games but not recommended. + std::vector vCustomAdhocServerList; bool bEnableWlan; std::map mHostToAlias; // Local DNS database stored in ini file diff --git a/UI/AdhocServerScreen.cpp b/UI/AdhocServerScreen.cpp index ec9de72a42..5a19269d29 100644 --- a/UI/AdhocServerScreen.cpp +++ b/UI/AdhocServerScreen.cpp @@ -40,27 +40,52 @@ void AdhocServerScreen::CreatePopupContents(UI::ViewGroup *parent) { PopupTextInputChoice *textInputChoice = parent->Add(new PopupTextInputChoice(GetRequesterToken(), &editValue_, n->T("Hostname"), "", 256, screenManager())); parent->Add(new Spacer(5.0f)); + // editValue_ has the currently selected server. On closing the dialog, we copy that to settings. + // Start with the downloaded list. std::vector entries = listItems; + std::vector localEntries; + std::vector customEntries; // Add localhost and local IPs, since those are common ones to connect to. { AdhocServerListEntry localhostEntry; localhostEntry.name = "localhost"; localhostEntry.host = "localhost"; - entries.push_back(localhostEntry); + localEntries.push_back(localhostEntry); std::vector listIP; net::GetLocalIP4List(listIP); - for (const auto &item : listIP) { - if (startsWith(item, "127.") || startsWith(item, "169.254.") || startsWith(item, "0.")) { + for (const auto &ipAddress : listIP) { + if (startsWith(ipAddress, "127.") || startsWith(ipAddress, "169.254.") || startsWith(ipAddress, "0.")) { continue; } AdhocServerListEntry entry; - entry.name = item; - entry.host = item; - entries.push_back(entry); + entry.name = ipAddress; + entry.host = ipAddress; + localEntries.push_back(entry); + } + } + + { + for (const auto &host : g_Config.vCustomAdhocServerList) { + // If the host is already in the public list, skip it. We don't want duplicates. + bool found = false; + for (const auto &entry : entries) { + if (entry.host == host) { + found = true; + break; + } + } + if (found) { + continue; + } + + AdhocServerListEntry entry; + entry.name = host; + entry.host = host; + customEntries.push_back(entry); } } @@ -68,10 +93,9 @@ void AdhocServerScreen::CreatePopupContents(UI::ViewGroup *parent) { LinearLayout *innerView = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); innerView->SetSpacing(5.0f); - // TODO: Fancier UI. - for (const auto &entry : entries) { + auto AddButtonFromEntry = [this](UI::ViewGroup *parent, const AdhocServerListEntry &entry) { // Filter out IP prefixed with "127." and "169.254." also "0." since they can be redundant or unusable - auto button = innerView->Add(new Button(entry.host, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); + auto button = parent->Add(new Button(entry.host, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); button->OnClick.Add([this](UI::EventParams &e) { std::string value = e.v->Tag(); if (!value.empty()) { @@ -81,6 +105,23 @@ void AdhocServerScreen::CreatePopupContents(UI::ViewGroup *parent) { } }); button->SetTag(entry.host); + }; + + if (!customEntries.empty()) { + CollapsibleSection *customSection = innerView->Add(new CollapsibleSection(n->T("Custom server list"), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); + for (const auto &entry : customEntries) { + AddButtonFromEntry(customSection, entry); + } + } + + CollapsibleSection *publicSection = innerView->Add(new CollapsibleSection(n->T("Public server list"), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); + for (const auto &entry : entries) { + AddButtonFromEntry(publicSection, entry); + } + + CollapsibleSection *localSection = innerView->Add(new CollapsibleSection(n->T("Local addresses"), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); + for (const auto &entry : localEntries) { + AddButtonFromEntry(localSection, entry); } scrollView->Add(innerView);