-
Notifications
You must be signed in to change notification settings - Fork 68
Add reconnect button to disconnection notice. #1102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
ec00075
8d8512e
65f564a
51e41c3
d4438e2
81cae16
0198674
fca3ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ AOApplication::AOApplication(QObject *parent) | |
: QObject(parent) | ||
{ | ||
net_manager = new NetworkManager(this); | ||
debug_func = new debug_functions(this); | ||
|
||
discord = new AttorneyOnline::Discord(); | ||
|
||
asset_lookup_cache.reserve(2048); | ||
|
@@ -142,10 +144,11 @@ void AOApplication::server_disconnected() | |
{ | ||
if (w_courtroom->isVisible()) | ||
{ | ||
call_notice(tr("Disconnected from server.")); | ||
construct_lobby(); | ||
destruct_courtroom(); | ||
// call_notice(tr("Disconnected from server.")); | ||
|
||
debug_func->call_notice_reconnect(tr("Disconnected from server, reconnect?")); | ||
} | ||
construct_lobby(); | ||
destruct_courtroom(); | ||
} | ||
Options::getInstance().setServerSubTheme(QString()); | ||
} | ||
|
@@ -158,14 +161,17 @@ void AOApplication::loading_cancelled() | |
void AOApplication::call_settings_menu() | ||
{ | ||
AOOptionsDialog *l_dialog = new AOOptionsDialog(this); | ||
// force disconnect as a test | ||
server_disconnected(); | ||
|
||
if (is_courtroom_constructed()) | ||
{ | ||
connect(l_dialog, &AOOptionsDialog::reloadThemeRequest, w_courtroom, &Courtroom::on_reload_theme_clicked); | ||
} | ||
|
||
if (is_lobby_constructed()) | ||
{} | ||
l_dialog->exec(); | ||
// if (is_lobby_constructed()) | ||
// {} | ||
// l_dialog->exec(); | ||
Comment on lines
+176
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remove these, this snippet is for the execution of the lobby settings when the settings button is pressed. |
||
|
||
if (is_courtroom_constructed()) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ class NetworkManager; | |
class Lobby; | ||
class Courtroom; | ||
class Options; | ||
class debug_functions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs removed |
||
|
||
class VPath : QString | ||
{ | ||
|
@@ -57,6 +58,7 @@ class AOApplication : public QObject | |
~AOApplication(); | ||
|
||
NetworkManager *net_manager; | ||
debug_functions *debug_func; | ||
Lobby *w_lobby = nullptr; | ||
Courtroom *w_courtroom = nullptr; | ||
AttorneyOnline::Discord *discord; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#include "debug_functions.h" | ||
#include "aoapplication.h" | ||
#include "networkmanager.h" | ||
|
||
#include <QCoreApplication> | ||
#include <QDialogButtonBox> | ||
|
@@ -9,6 +11,12 @@ | |
|
||
#include <functional> | ||
|
||
debug_functions::debug_functions(AOApplication *parent) | ||
: QObject(parent) | ||
{ | ||
ao_app = parent; | ||
} | ||
|
||
void call_error(QString p_message) | ||
{ | ||
QMessageBox *msgBox = new QMessageBox; | ||
|
@@ -58,3 +66,48 @@ void call_notice(QString p_message) | |
|
||
msgBox->exec(); | ||
} | ||
|
||
void debug_functions::call_notice_reconnect(QString p_message) | ||
{ | ||
auto *msgBox = new QMessageBox; | ||
|
||
|
||
msgBox->setAttribute(Qt::WA_DeleteOnClose); | ||
msgBox->setText(p_message); | ||
msgBox->setWindowTitle(QCoreApplication::translate("debug_functions", "Notice")); | ||
|
||
msgBox->setStandardButtons(QMessageBox::Ok); | ||
msgBox->setDefaultButton(QMessageBox::Ok); | ||
msgBox->defaultButton()->setEnabled(false); | ||
|
||
QPushButton *reconnectButton = msgBox->addButton(QObject::tr("Reconnect"), QMessageBox::ActionRole); | ||
|
||
QTimer intervalTimer; | ||
intervalTimer.setInterval(1000); | ||
|
||
int counter = 3; | ||
|
||
const auto updateCounter = [msgBox, &counter] { | ||
if (counter <= 0) | ||
{ | ||
return; | ||
} | ||
msgBox->defaultButton()->setText(QString("%1 (%2)").arg(QDialogButtonBox::tr("OK")).arg(counter)); | ||
counter--; | ||
}; | ||
|
||
QObject::connect(&intervalTimer, &QTimer::timeout, msgBox, updateCounter); | ||
intervalTimer.start(); | ||
updateCounter(); | ||
|
||
QTimer::singleShot(3000, msgBox, [msgBox, &intervalTimer] { | ||
msgBox->defaultButton()->setEnabled(true); | ||
msgBox->defaultButton()->setText(QDialogButtonBox::tr("OK")); | ||
intervalTimer.stop(); | ||
}); | ||
|
||
msgBox->exec(); | ||
|
||
if (msgBox->clickedButton() == reconnectButton) | ||
{ | ||
ao_app->net_manager->reconnect_to_last_server(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
#pragma once | ||
|
||
#include "aoapplication.h" | ||
|
||
#include <QString> | ||
|
||
void call_error(QString message); | ||
void call_notice(QString message); | ||
|
||
class debug_functions : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit debug_functions(AOApplication *parent); | ||
AOApplication *ao_app; | ||
|
||
void call_notice_reconnect(QString message); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug_func
is too vague as a variable name.debug_functions
is meaningless as a class name nor does it follow at all any kind of somewhat established naming convention.