Add categories to the server list

This commit is contained in:
Henrik Rydgård committed 2026-03-06 13:25:07 +01:00
1 parent 6009f305f8
commit 3d50bf4b7d
3 files changed
+52 -10

No files matched your search

+1 -1
View File
@@ -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<std::string_view>(), 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),
+1
View File
@@ -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<std::string> vCustomAdhocServerList;
bool bEnableWlan;
std::map<std::string, std::string> mHostToAlias; // Local DNS database stored in ini file
+50 -9
View File
@@ -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<AdhocServerListEntry> entries = listItems;
std::vector<AdhocServerListEntry> localEntries;
std::vector<AdhocServerListEntry> 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<std::string> 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);