mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-04-20 19:44:30 -04:00
Edit game_list.cpp
This commit is contained in:
@@ -407,7 +407,7 @@ void GameList::OnFilterCloseClicked() {
|
||||
main_window->filterBarSetChecked(false);
|
||||
}
|
||||
|
||||
GameList::GameList(FileSys::VirtualFilesystem vfs_, FileSys::ManualContentProvider* provider_,
|
||||
GameList::GameList(std::shared_ptr<FileSys::VfsFilesystem> vfs_, FileSys::ManualContentProvider* provider_,
|
||||
PlayTime::PlayTimeManager& play_time_manager_, Core::System& system_,
|
||||
GMainWindow* parent)
|
||||
: QWidget{parent}, vfs{std::move(vfs_)}, provider{provider_},
|
||||
@@ -505,6 +505,11 @@ GameList::GameList(FileSys::VirtualFilesystem vfs_, FileSys::ManualContentProvid
|
||||
|
||||
// Set initial view mode
|
||||
SetViewMode(UISettings::values.game_list_grid_view.GetValue());
|
||||
|
||||
// Set up the timer for automatic refresh
|
||||
online_status_timer = new QTimer(this);
|
||||
connect(online_status_timer, &QTimer::timeout, this, &GameList::UpdateOnlineStatus);
|
||||
online_status_timer->start(5000); // Refresh every 5 seconds
|
||||
}
|
||||
|
||||
void GameList::UnloadController() {
|
||||
@@ -551,6 +556,52 @@ void GameList::AddEntry(const QList<QStandardItem*>& entry_items, GameListDir* p
|
||||
parent->appendRow(entry_items);
|
||||
}
|
||||
|
||||
// THIS IS THE NEW REFRESH FUNCTION
|
||||
void GameList::UpdateOnlineStatus() {
|
||||
auto session = main_window->GetMultiplayerState()->GetSession();
|
||||
if (!session || !item_model) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This part is the same as in the worker: fetch and count.
|
||||
std::map<u64, std::pair<int, int>> online_stats; // Game ID -> {player_count, server_count}
|
||||
AnnounceMultiplayerRoom::RoomList room_list = session->GetRoomList();
|
||||
for (const auto& room : room_list) {
|
||||
u64 game_id = room.information.preferred_game.id;
|
||||
if (game_id != 0) {
|
||||
online_stats[game_id].first += room.members.size();
|
||||
online_stats[game_id].second++;
|
||||
}
|
||||
}
|
||||
|
||||
// Now, iterate through the existing list and update the "Online" column.
|
||||
for (int i = 0; i < item_model->rowCount(); ++i) {
|
||||
QStandardItem* folder = item_model->item(i, 0);
|
||||
if (!folder) continue;
|
||||
|
||||
for (int j = 0; j < folder->rowCount(); ++j) {
|
||||
QStandardItem* game_item = folder->child(j, COLUMN_NAME);
|
||||
if (!game_item) continue;
|
||||
|
||||
u64 program_id = game_item->data(GameListItemPath::ProgramIdRole).toULongLong();
|
||||
QString online_text = QStringLiteral("N/A");
|
||||
|
||||
auto it_stats = online_stats.find(program_id);
|
||||
if (it_stats != online_stats.end()) {
|
||||
const auto& stats = it_stats->second;
|
||||
online_text = QStringLiteral("Players: %1 | Servers: %2").arg(stats.first).arg(stats.second);
|
||||
}
|
||||
|
||||
// This is the efficient update. We find the item for the "Online" column and just change its text.
|
||||
QStandardItem* online_item = folder->child(j, COLUMN_ONLINE);
|
||||
if (online_item) {
|
||||
online_item->setData(online_text, Qt::DisplayRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GameList::ValidateEntry(const QModelIndex& item) {
|
||||
const auto selected = item.sibling(item.row(), 0);
|
||||
|
||||
@@ -955,6 +1006,7 @@ void GameList::RetranslateUI() {
|
||||
item_model->setHeaderData(COLUMN_FILE_TYPE, Qt::Horizontal, tr("File type"));
|
||||
item_model->setHeaderData(COLUMN_SIZE, Qt::Horizontal, tr("Size"));
|
||||
item_model->setHeaderData(COLUMN_PLAY_TIME, Qt::Horizontal, tr("Play time"));
|
||||
item_model->setHeaderData(COLUMN_ONLINE, Qt::Horizontal, tr("Online"));
|
||||
}
|
||||
|
||||
void GameListSearchField::changeEvent(QEvent* event) {
|
||||
@@ -992,7 +1044,7 @@ void GameList::PopulateAsync(QVector<UISettings::GameDir>& game_dirs) {
|
||||
search_field->clear();
|
||||
|
||||
current_worker = std::make_unique<GameListWorker>(vfs, provider, game_dirs, compatibility_list,
|
||||
play_time_manager, system);
|
||||
play_time_manager, system, main_window->GetMultiplayerState()->GetSession());
|
||||
|
||||
// Get events from the worker as data becomes available
|
||||
connect(current_worker.get(), &GameListWorker::DataAvailable, this, &GameList::WorkerEvent,
|
||||
|
||||
Reference in New Issue
Block a user