Fix multiplayer dropdowns and proxy model
* Filters in the lobby properly remove rooms * Multiplayer menu items for Show Room and Leave Room work as intended
This commit is contained in:
parent
601fd81d5c
commit
a85511cd7d
9 changed files with 107 additions and 171 deletions
|
@ -32,6 +32,7 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
|||
model = new QStandardItemModel(ui->room_list);
|
||||
proxy = new LobbyFilterProxyModel(this, game_list);
|
||||
proxy->setSourceModel(model);
|
||||
proxy->setDynamicSortFilter(true);
|
||||
proxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
proxy->setSortLocaleAware(true);
|
||||
ui->room_list->setModel(proxy);
|
||||
|
@ -45,7 +46,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
|||
ui->room_list->setSortingEnabled(true);
|
||||
ui->room_list->setEditTriggers(QHeaderView::NoEditTriggers);
|
||||
ui->room_list->setExpandsOnDoubleClick(false);
|
||||
// ui->room_list->setUniformRowHeights(true);
|
||||
ui->room_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
ui->nickname->setValidator(Validation::nickname);
|
||||
|
@ -54,7 +54,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
|||
// UI Buttons
|
||||
MultiplayerState* p = reinterpret_cast<MultiplayerState*>(parent);
|
||||
connect(ui->refresh_list, &QPushButton::pressed, this, &Lobby::RefreshLobby);
|
||||
connect(ui->chat, &QPushButton::pressed, p, &MultiplayerState::OnOpenNetworkRoom);
|
||||
connect(ui->games_owned, &QCheckBox::stateChanged, proxy,
|
||||
&LobbyFilterProxyModel::SetFilterOwned);
|
||||
connect(ui->hide_full, &QCheckBox::stateChanged, proxy, &LobbyFilterProxyModel::SetFilterFull);
|
||||
|
@ -68,28 +67,11 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
|||
// TODO(jroweboy): change this slot to OnConnected?
|
||||
connect(this, &Lobby::Connected, p, &MultiplayerState::OnOpenNetworkRoom);
|
||||
|
||||
// setup the callbacks for network updates
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
member->BindOnStateChanged(
|
||||
[this](const Network::RoomMember::State& state) { emit StateChanged(state); });
|
||||
connect(this, &Lobby::StateChanged, this, &Lobby::OnStateChanged);
|
||||
} else {
|
||||
// TODO (jroweboy) network was not initialized?
|
||||
}
|
||||
|
||||
// manually start a refresh when the window is opening
|
||||
// TODO(jroweboy): if this refresh is slow for people with bad internet, then don't do it as
|
||||
// part of the constructor, but offload the refresh until after the window shown. perhaps emit a
|
||||
// refreshroomlist signal from places that open the lobby
|
||||
RefreshLobby();
|
||||
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
if (member->IsConnected()) {
|
||||
ui->chat->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ui->chat->setDisabled(true);
|
||||
}
|
||||
|
||||
const QString Lobby::PasswordPrompt() {
|
||||
|
@ -148,16 +130,6 @@ void Lobby::OnJoinRoom(const QModelIndex& index) {
|
|||
Settings::Apply();
|
||||
}
|
||||
|
||||
void Lobby::OnStateChanged(const Network::RoomMember::State& state) {
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
if (member->IsConnected()) {
|
||||
ui->chat->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ui->chat->setDisabled(true);
|
||||
}
|
||||
|
||||
void Lobby::ResetModel() {
|
||||
model->clear();
|
||||
model->insertColumns(0, Column::TOTAL);
|
||||
|
@ -218,7 +190,7 @@ void Lobby::OnRefreshLobby() {
|
|||
first_item->appendRow(new LobbyItemExpandedMemberList(members));
|
||||
}
|
||||
}
|
||||
ui->room_list->setModel(model);
|
||||
proxy->setSourceModel(model);
|
||||
|
||||
// Reenable the refresh button and resize the columns
|
||||
ui->refresh_list->setEnabled(true);
|
||||
|
@ -311,12 +283,12 @@ void LobbyFilterProxyModel::sort(int column, Qt::SortOrder order) {
|
|||
|
||||
void LobbyFilterProxyModel::SetFilterOwned(bool filter) {
|
||||
filter_owned = filter;
|
||||
invalidateFilter();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void LobbyFilterProxyModel::SetFilterFull(bool filter) {
|
||||
filter_full = filter;
|
||||
invalidateFilter();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void Lobby::OnConnection() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue