Skip to content

Commit 0952c81

Browse files
Implement debug console disabling
1 parent 9625dd0 commit 0952c81

File tree

12 files changed

+204
-71
lines changed

12 files changed

+204
-71
lines changed

src/GUI/LoadFromTheGameWindow.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,11 @@ LoadFromTheGameWindow::LoadFromTheGameWindow(QWidget* parent) : QWidget(parent)
5151
ltChoiseGame->addWidget(rdxGenerals);
5252
ltChoiseGame->addWidget(rdxZeroHour);
5353

54-
// configure save option
55-
QCheckBox* chkSaveToGame = new QCheckBox();
56-
chkSaveToGame->setText(tr("Save hotkeys dirrectly to the game."));
57-
chkSaveToGame->setObjectName(nameof(chkSaveToGame));
58-
5954
// configure dialog view
6055
QVBoxLayout* ltMainBlock = new QVBoxLayout();
6156
ltMainBlock->setAlignment(Qt::Alignment::enum_type::AlignCenter);
6257
ltMainBlock->addStretch(5);
6358
ltMainBlock->addLayout(ltChoiseGame);
64-
ltMainBlock->addStretch(2);
65-
ltMainBlock->addWidget(chkSaveToGame);
6659
ltMainBlock->addStretch(5);
6760
ltMainBlock->addLayout(ltOkAndCancel);
6861
ltMainBlock->addStretch(1);

src/GUI/SettingsWindow.cpp

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
1-
#include <QPushButton>
2-
#include <QVBoxLayout>
1+
#include <windows.h> // Allows disable console
32

43
#include "../Logger.hpp"
54
#include "../NameOfExt.hpp"
6-
#include "../Settings.hpp"
75
#include "SettingsWindow.hpp"
86

97
SettingsWindow::SettingsWindow(QWidget* parent) : QWidget(parent)
108
{
11-
QVBoxLayout* ltMain = new QVBoxLayout(this);
12-
QHBoxLayout* ltButtons = new QHBoxLayout(this);
13-
QPushButton* btnBack = new QPushButton(this);
14-
QPushButton* btnSave = new QPushButton(this);
15-
QPushButton* btnResetAll = new QPushButton(this);
9+
ltMain = new QVBoxLayout(this);
10+
ltButtons = new QHBoxLayout();
11+
ltSettings = new QVBoxLayout();
12+
btnBack = new QPushButton(this);
13+
btnSave = new QPushButton(this);
14+
btnResetAll = new QPushButton(this);
15+
chkEnableDebugConsole = new QCheckBox(this);
16+
chkEnableDiscordRPC = new QCheckBox(this);
17+
chkForceSystemLanguage = new QCheckBox(this);
18+
19+
chkEnableDebugConsole->setText(tr("Enable debug console"));
20+
chkEnableDebugConsole->setObjectName(nameof(chkEnableDebugConsole));
21+
if (settings.IsConsoleEnabled())
22+
chkEnableDebugConsole->setCheckState(Qt::CheckState::Checked);
23+
else
24+
chkEnableDebugConsole->setCheckState(Qt::CheckState::Unchecked);
25+
26+
chkEnableDiscordRPC->setText(tr("Enable Discord RPC (WIP)"));
27+
chkEnableDiscordRPC->setObjectName(nameof(chkEnableDiscordRPC));
28+
if (settings.IsDiscordRPCEnabled())
29+
chkEnableDiscordRPC->setCheckState(Qt::CheckState::Checked);
30+
else
31+
chkEnableDiscordRPC->setCheckState(Qt::CheckState::Unchecked);
32+
33+
// TODO: Make it work later.
34+
chkForceSystemLanguage->setVisible(false);
35+
36+
ltSettings->addWidget(chkEnableDebugConsole);
37+
ltSettings->addWidget(chkEnableDiscordRPC);
1638

1739
btnSave->setText(tr("SAVE"));
1840
btnSave->setObjectName(nameof(btnSave));
@@ -30,12 +52,50 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QWidget(parent)
3052
ltButtons->addWidget(btnResetAll);
3153
ltButtons->addWidget(btnBack);
3254

33-
ltMain->addLayout(ltButtons);
3455
ltMain->setAlignment(Qt::AlignCenter);
35-
ltMain->setSpacing(20);
56+
ltMain->addLayout(ltSettings);
57+
ltMain->addLayout(ltButtons);
58+
ltMain->setSpacing(10);
3659
ltMain->setContentsMargins(160, 120, 160, 120);
3760
setLayout(ltMain);
3861
}
3962

40-
void SettingsWindow::BtnSave_Clicked() {}
41-
void SettingsWindow::BtnResetAll_Clicked() {}
63+
void SettingsWindow::BtnSave_Clicked()
64+
{
65+
settings.SetConsoleStatus(chkEnableDebugConsole->checkState());
66+
ConsoleWindowStateUpdate(chkEnableDebugConsole->checkState());
67+
68+
settings.SetDiscordRPCStatus(chkEnableDiscordRPC->checkState());
69+
DiscordRPCStateUpdate(chkEnableDiscordRPC->checkState());
70+
71+
settings.Save();
72+
}
73+
74+
void SettingsWindow::BtnResetAll_Clicked()
75+
{
76+
settings.SetToDefault();
77+
78+
if (settings.IsConsoleEnabled())
79+
chkEnableDebugConsole->setCheckState(Qt::CheckState::Checked);
80+
else
81+
chkEnableDebugConsole->setCheckState(Qt::CheckState::Unchecked);
82+
83+
chkEnableDebugConsole->update();
84+
}
85+
86+
void SettingsWindow::ConsoleWindowStateUpdate(const Qt::CheckState& state)
87+
{
88+
switch (state)
89+
{
90+
case Qt::CheckState::Checked:
91+
ShowWindow(GetConsoleWindow(), SW_SHOW);
92+
break;
93+
case Qt::CheckState::Unchecked:
94+
ShowWindow(GetConsoleWindow(), SW_HIDE);
95+
break;
96+
}
97+
}
98+
99+
void SettingsWindow::DiscordRPCStateUpdate(const Qt::CheckState& state)
100+
{
101+
}

src/GUI/SettingsWindow.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
#pragma once
22
#include <QWidget>
3+
#include <QPushButton>
4+
#include <QCheckBox>
5+
#include <QVBoxLayout>
6+
#include "../Settings.hpp"
37

48
class SettingsWindow final : public QWidget
59
{
610
Q_OBJECT
711
private: // Data
12+
Settings settings;
13+
14+
QVBoxLayout* ltMain = nullptr;
15+
QHBoxLayout* ltButtons = nullptr;
16+
QVBoxLayout* ltSettings = nullptr;
17+
QPushButton* btnBack = nullptr;
18+
QPushButton* btnSave = nullptr;
19+
QPushButton* btnResetAll = nullptr;
20+
QCheckBox* chkEnableDebugConsole = nullptr;
21+
QCheckBox* chkEnableDiscordRPC = nullptr;
22+
QCheckBox* chkForceSystemLanguage = nullptr;
823
public:
924
private: // Methods
25+
/// @brief Enable/disable debug console.
26+
void ConsoleWindowStateUpdate(const Qt::CheckState& state);
27+
/// @brief Enable/disable Discord RPC integration.
28+
/// @todo Implement later.
29+
void DiscordRPCStateUpdate(const Qt::CheckState& state);
1030
private slots:
1131
void BtnSave_Clicked();
1232
void BtnResetAll_Clicked();

src/GUI/Theme/Styles.css

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ QPushButton
7777
border-radius: 3px;
7878
}
7979

80+
QPushButton:hover
81+
{
82+
background-color: #3543e7;
83+
color: #baff0c;
84+
}
85+
8086
GreetingWindow QPushButton#btnSettings
8187
{
8288
border-color: transparent;
@@ -85,18 +91,7 @@ GreetingWindow QPushButton#btnSettings
8591

8692
GreetingWindow QPushButton { font-size: 18pt; }
8793

88-
GreetingWindow QLabel, LoadFromTheFileWindow QLabel, LoadFromTheGameWindow QLabel,
89-
GreetingWindow QRadioButton, LoadFromTheFileWindow QRadioButton, LoadFromTheGameWindow QRadioButton,
90-
GreetingWindow QCheckBox, LoadFromTheFileWindow QCheckBox, LoadFromTheGameWindow QCheckBox
91-
{
92-
color: white;
93-
}
94-
95-
GreetingWindow QPushButton:hover, LoadFromTheFileWindow QPushButton:hover, LoadFromTheGameWindow QPushButton:hover
96-
{
97-
background-color: #3543e7;
98-
color: #baff0c;
99-
}
94+
QLabel, QRadioButton, QCheckBox { color: white; }
10095

10196
QPushButton#btnReview
10297
{

src/GUI/Translations/ru.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,8 @@
340340
<translation>НАЗАД</translation>
341341
</message>
342342
<message>
343-
<location filename="../LoadFromTheGameWindow.cpp" line="56"/>
344343
<source>Save hotkeys dirrectly to the game.</source>
345-
<translation>Сохранять горячие клавиши в игре.</translation>
344+
<translation type="vanished">Сохранять горячие клавиши в игре.</translation>
346345
</message>
347346
</context>
348347
<context>
@@ -425,19 +424,29 @@ Make sure that you are load correct file.</source>
425424
<translation type="obsolete">Назад</translation>
426425
</message>
427426
<message>
428-
<location filename="../SettingsWindow.cpp" line="17"/>
427+
<location filename="../SettingsWindow.cpp" line="19"/>
428+
<source>Enable debug console</source>
429+
<translation>Включить отладочную консоль</translation>
430+
</message>
431+
<message>
432+
<location filename="../SettingsWindow.cpp" line="26"/>
433+
<source>Enable Discord RPC (WIP)</source>
434+
<translation>Включить Discord RPC (WIP)</translation>
435+
</message>
436+
<message>
437+
<location filename="../SettingsWindow.cpp" line="39"/>
429438
<source>SAVE</source>
430-
<translation type="unfinished"></translation>
439+
<translation>СОХРАНИТЬ</translation>
431440
</message>
432441
<message>
433-
<location filename="../SettingsWindow.cpp" line="21"/>
442+
<location filename="../SettingsWindow.cpp" line="43"/>
434443
<source>RESET ALL</source>
435-
<translation type="unfinished"></translation>
444+
<translation>СБРОСИТЬ ВСЁ</translation>
436445
</message>
437446
<message>
438-
<location filename="../SettingsWindow.cpp" line="25"/>
447+
<location filename="../SettingsWindow.cpp" line="47"/>
439448
<source>BACK</source>
440-
<translation type="unfinished">НАЗАД</translation>
449+
<translation>НАЗАД</translation>
441450
</message>
442451
</context>
443452
</TS>

src/Logger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ using namespace std;
1313
#pragma region ctor and dtor
1414
Logger::Logger()
1515
{
16+
ShowWindow(GetConsoleWindow(), SW_HIDE);
1617
LogFile.open(GetLogFileName());
1718

1819
// Due to Logger is a singleton, we must create check if folder Logs exists.

src/Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ int main(int argc, const char** argv)
6868
PROGRAM_CONSTANTS->InitializeFileSettings();
6969

7070
// Hides console
71-
if (!PROGRAM_CONSTANTS->IsConsoleEnabled())
72-
ShowWindow(GetConsoleWindow(), SW_HIDE);
71+
if (PROGRAM_CONSTANTS->IsConsoleEnabled())
72+
ShowWindow(GetConsoleWindow(), SW_SHOW);
7373

7474
// Define logger as the singleton class, that could be used anywhere in the project
7575
WINDOW_MANAGER = make_unique<WindowManager>();

src/Parsers/JSONFile.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,11 @@ using namespace std;
3535
#pragma endregion
3636

3737
#pragma region Getters
38-
const QJsonObject& JSONFile::GetMainObject() const
39-
{
40-
return JsonMainObject;
41-
}
42-
43-
QJsonValue JSONFile::Query(const QString& strQuery) const
44-
{
45-
return Query(JsonMainObject, strQuery);
46-
}
47-
48-
QJsonValue JSONFile::Query(const char* strQuery) const
49-
{
50-
return Query(JsonMainObject, QString{strQuery});
51-
}
52-
53-
QJsonValue JSONFile::Query(const std::string& strQuery) const
54-
{
55-
return Query(JsonMainObject, QString::fromStdString(strQuery));
56-
}
38+
const QJsonObject& JSONFile::GetMainObject() const { return JsonMainObject; }
39+
40+
QJsonValue JSONFile::Query(const QString& strQuery) const { return Query(JsonMainObject, strQuery); }
41+
QJsonValue JSONFile::Query(const char* strQuery) const { return Query(JsonMainObject, QString{strQuery}); }
42+
QJsonValue JSONFile::Query(const std::string& strQuery) const { return Query(JsonMainObject, QString::fromStdString(strQuery)); }
5743

5844
QJsonValue JSONFile::Query(const QJsonObject& jsonObject, const QString& strQuery)
5945
{

src/Settings.cpp

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
#include <QFile>
12
#include <QJsonValue>
23
#include <QJsonArray>
34
#include <QJsonDocument>
45

5-
#include "Parsers/JSONFile.hpp"
66
#include "ProgramConstants.hpp"
77
#include "Settings.hpp"
88

9+
#include "Logger.hpp"
10+
911
Settings::Settings()
1012
{
1113
SetToDefault();
12-
ParseSettings();
14+
Parse();
1315
}
1416

1517
Settings::~Settings()
@@ -22,7 +24,7 @@ void Settings::SetToDefault()
2224
enabledConsole = false;
2325
}
2426

25-
void Settings::ParseSettings()
27+
void Settings::Parse()
2628
{
2729
JSONFile json(PROGRAM_CONSTANTS->SETTINGS_FILE);
2830

@@ -32,5 +34,54 @@ void Settings::ParseSettings()
3234
allowedKeys.insert(PROGRAM_CONSTANTS->KEYBOARD_KEYS.value(ch.toString()[0]));
3335
}
3436

35-
const bool Settings::IsConsoleEnabled() { return enabledConsole; }
36-
const QSet<Qt::Key> Settings::GetAllowedKeys() { return allowedKeys; }
37+
void Settings::Save()
38+
{
39+
JSONFile json(PROGRAM_CONSTANTS->SETTINGS_FILE);
40+
QJsonObject jsMainObj = json.GetMainObject();
41+
jsMainObj["DebugConsole"] = enabledConsole;
42+
jsMainObj["DiscordRPC"] = enabledDiscordRPC;
43+
44+
QJsonDocument jsDoc;
45+
jsDoc.setObject(jsMainObj);
46+
47+
LOGMSG("Saving changes to the \"" + PROGRAM_CONSTANTS->SETTINGS_FILE + "\"..." );
48+
QFile settingsJson(PROGRAM_CONSTANTS->SETTINGS_FILE);
49+
settingsJson.remove();
50+
settingsJson.open(QIODevice::WriteOnly | QIODevice::Text);
51+
settingsJson.write(jsDoc.toJson());
52+
settingsJson.close();
53+
LOGMSG("Setting changes has been saved.");
54+
}
55+
56+
const bool Settings::IsConsoleEnabled() const { return enabledConsole; }
57+
const QSet<Qt::Key> Settings::GetAllowedKeys() const { return allowedKeys; }
58+
const bool Settings::IsDiscordRPCEnabled() const { return enabledDiscordRPC; }
59+
60+
void Settings::SetAllowedKeys(const QSet<Qt::Key>& keys) { allowedKeys = keys; }
61+
void Settings::SetConsoleStatus(bool state) { enabledConsole = state; }
62+
void Settings::SetConsoleStatus(const Qt::CheckState& state)
63+
{
64+
switch (state)
65+
{
66+
case (Qt::CheckState::Checked):
67+
enabledConsole = true;
68+
break;
69+
case (Qt::CheckState::Unchecked):
70+
enabledConsole = false;
71+
break;
72+
}
73+
}
74+
75+
void Settings::SetDiscordRPCStatus(bool state) { enabledDiscordRPC = state; }
76+
void Settings::SetDiscordRPCStatus(const Qt::CheckState& state)
77+
{
78+
switch (state)
79+
{
80+
case (Qt::CheckState::Checked):
81+
enabledDiscordRPC = true;
82+
break;
83+
case (Qt::CheckState::Unchecked):
84+
enabledDiscordRPC = false;
85+
break;
86+
}
87+
}

0 commit comments

Comments
 (0)