Skip to content

Commit

Permalink
RMG: fix flicker UI logic of NetplaySessionBrowserWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Feb 9, 2025
1 parent 1ec02c5 commit c046984
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,6 @@ void NetplaySessionBrowserDialog::on_webSocket_textMessageReceived(QString messa

// we're done refreshing the sessions
this->sessionBrowserWidget->RefreshDone();
// enable refresh button when refreshing is done
QPushButton* refreshButton = this->buttonBox->button(QDialogButtonBox::RestoreDefaults);
refreshButton->setEnabled(true);
// re-validate join button after refresh
this->validateJoinButton();
}
else
{
Expand Down Expand Up @@ -332,6 +327,13 @@ void NetplaySessionBrowserDialog::on_sessionBrowserWidget_OnSessionChanged(bool
this->validateJoinButton();
}

void NetplaySessionBrowserDialog::on_sessionBrowserWidget_OnRefreshDone(void)
{
QPushButton* refreshButton = this->buttonBox->button(QDialogButtonBox::RestoreDefaults);
refreshButton->setEnabled(true);
this->validateJoinButton();
}

void NetplaySessionBrowserDialog::on_nickNameLineEdit_textChanged()
{
this->validateJoinButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class NetplaySessionBrowserDialog : public QDialog, private Ui::NetplaySessionBr

void on_serverComboBox_currentIndexChanged(int index);
void on_sessionBrowserWidget_OnSessionChanged(bool valid);

void on_sessionBrowserWidget_OnRefreshDone(void);

void on_nickNameLineEdit_textChanged(void);

void on_buttonBox_clicked(QAbstractButton* button);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,24 @@ void NetplaySessionBrowserWidget::RefreshDone(void)
{
if (this->tableWidget->rowCount() == 0)
{
this->setCurrentWidget(this->emptyWidget);
return;
this->currentViewWidget = this->emptyWidget;
}
else
{
this->currentViewWidget = this->tableWidget;
}

// prevent flicker by forcing the loading screen
// to be shown at least 300ms
qint64 elapsedTime = this->refreshTimer.elapsed();
if (elapsedTime < 300)
{
this->startTimer(300 - elapsedTime);
this->showViewWidgetTimerId = this->startTimer(300 - elapsedTime);
return;
}

this->setCurrentWidget(this->tableWidget);
this->setCurrentWidget(this->currentViewWidget);
emit this->OnRefreshDone();
}

bool NetplaySessionBrowserWidget::IsCurrentSessionValid()
Expand Down Expand Up @@ -167,8 +171,14 @@ bool NetplaySessionBrowserWidget::GetCurrentSession(NetplaySessionData& data)

void NetplaySessionBrowserWidget::timerEvent(QTimerEvent *event)
{
this->killTimer(event->timerId());
this->setCurrentWidget(this->tableWidget);
if (event->timerId() == this->showViewWidgetTimerId)
{
this->killTimer(this->showViewWidgetTimerId);
this->showViewWidgetTimerId = -1;

this->setCurrentWidget(this->currentViewWidget);
emit this->OnRefreshDone();
}
}

void NetplaySessionBrowserWidget::on_tableWidget_currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class NetplaySessionBrowserWidget : public QStackedWidget
QTableWidget* tableWidget = nullptr;
QWidget* currentViewWidget = nullptr;

int showViewWidgetTimerId = -1;
QElapsedTimer refreshTimer;

protected:
Expand All @@ -70,6 +71,7 @@ class NetplaySessionBrowserWidget : public QStackedWidget
void on_tableWidget_currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);

signals:
void OnRefreshDone(void);
void OnSessionChanged(bool valid);

};
Expand Down

0 comments on commit c046984

Please sign in to comment.