Skip to content

Commit 9fa8cb4

Browse files
Adjustment Discord RPC integration
1 parent 46289d2 commit 9fa8cb4

5 files changed

Lines changed: 61 additions & 31 deletions

File tree

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
11
#include "Logger.hpp"
2-
#include "DiscordRPCManager.hpp"
2+
#include "DiscordManager.hpp"
33

4-
DiscordRPCManager::DiscordRPCManager()
4+
DiscordManager::DiscordManager()
55
{
66
}
77

8-
DiscordRPCManager::~DiscordRPCManager()
8+
DiscordManager::~DiscordManager()
99
{
1010
Discord_Shutdown();
1111
}
1212

13-
void DiscordRPCManager::Initialize()
13+
void DiscordManager::Initialize()
1414
{
15+
LOGMSG("Initializing Discord RPC...");
1516
DiscordEventHandlers handlers;
1617
memset(&handlers, 0, sizeof(handlers));
1718
handlers.ready = &HandleDiscordReady;
1819
handlers.disconnected = &HandleDiscordDisconnected;
1920
handlers.errored = &HandleDiscordError;
20-
Discord_Initialize(APPLICATION_ID, NULL, 1, NULL);
21+
Discord_Initialize(AppID, NULL, 1, NULL);
2122
UpdateDiscordPresence();
23+
LOGMSG("Discord RPC is running");
2224
}
2325

24-
void DiscordRPCManager::HandleDiscordReady(const DiscordUser* connectedUser)
26+
void DiscordManager::Dispose()
27+
{
28+
Discord_Shutdown();
29+
}
30+
31+
void DiscordManager::HandleDiscordReady(const DiscordUser* connectedUser)
2532
{
2633
LOGMSG("Discord: connected to user" + connectedUser->username + "#" + connectedUser->discriminator + " - " + connectedUser->userId);
2734
}
2835

29-
void DiscordRPCManager::HandleDiscordDisconnected(int errcode, const char* message)
36+
void DiscordManager::HandleDiscordDisconnected(int errcode, const char* message)
3037
{
3138
LOGMSG("Discord: disconnected (" + errcode + ":" + message);
3239
}
3340

34-
void DiscordRPCManager::HandleDiscordError(int errcode, const char* message)
41+
void DiscordManager::HandleDiscordError(int errcode, const char* message)
3542
{
3643
LOGMSG("Discord: error (" + errcode + ":" + message);
3744
}
3845

39-
void DiscordRPCManager::UpdateDiscordPresence()
46+
void DiscordManager::UpdateDiscordPresence()
4047
{
4148
if (SendPresence)
4249
{
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
#include <QString>
44
#include "../libs/discord-rpc/include/discord_rpc.h"
55

6-
class DiscordRPCManager final
6+
#define DISCORD_MANAGER DiscordManager::Instance
7+
8+
class DiscordManager final
79
{
810
private: // Data
911
QString state = "Editing hotkeys";
1012
QString details = "";
11-
public:
12-
const char* APPLICATION_ID = "830497958034145300";
13+
public:
14+
inline static std::unique_ptr<DiscordManager> Instance = std::make_unique<DiscordManager>();
15+
const char* AppID = "830497958034145300";
1316
const int SendPresence = 1;
1417

15-
public: // Methods
16-
DiscordRPCManager();
17-
~DiscordRPCManager();
18-
void Initialize();
18+
private: // Methods
1919
static void HandleDiscordReady(const DiscordUser* connectedUser);
2020
static void HandleDiscordDisconnected(int errcode, const char* message);
2121
static void HandleDiscordError(int errcode, const char* message);
22+
public:
23+
DiscordManager();
24+
~DiscordManager();
25+
void Initialize();
26+
void Dispose();
2227
void UpdateDiscordPresence();
2328
};

src/GUI/SettingsWindow.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../Extensions/BoolExt.hpp"
77
#include "../Windows/Locale.hpp"
88
#include "../ProgramConstants.hpp"
9+
#include "../DiscordManager.hpp"
910
#include "../SteamManager.hpp"
1011
#include "../Logger.hpp"
1112

@@ -38,7 +39,7 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QWidget(parent)
3839
? Qt::CheckState::Checked
3940
: Qt::CheckState::Unchecked);
4041

41-
chkEnableDiscordRPC->setText(tr("Enable Discord RPC (WIP)"));
42+
chkEnableDiscordRPC->setText(tr("Enable Discord RPC"));
4243
chkEnableDiscordRPC->setObjectName(nameof(chkEnableDiscordRPC));
4344
chkEnableDiscordRPC->setCheckState(PROGRAM_CONSTANTS->pSettingsFile->IsDiscordRPCEnabled()
4445
? Qt::CheckState::Checked
@@ -63,7 +64,7 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QWidget(parent)
6364
cmbLanguage->addItem(PROGRAM_CONSTANTS->Languages.value(i).second);
6465

6566
cmbLanguage->setObjectName(nameof(cmbLanguage));
66-
// cmbLanguage->setFixedHeight(25); // TODO: remove this 25 px and think how to handle it in css
67+
cmbLanguage->setFixedHeight(23); // TODO: remove this 25 px and think how to handle it in css
6768
cmbLanguage->setCurrentIndex(static_cast<int>(PROGRAM_CONSTANTS->pSettingsFile->GetLanguage()));
6869
cmbLanguage->setCurrentText(PROGRAM_CONSTANTS->Languages.value(PROGRAM_CONSTANTS->pSettingsFile->GetLanguage()).second);
6970

@@ -197,6 +198,14 @@ void SettingsWindow::ConsoleWindowStateUpdate(const Qt::CheckState& state)
197198

198199
void SettingsWindow::DiscordRPCStateUpdate(const Qt::CheckState& state)
199200
{
201+
if (ToBool(state))
202+
{
203+
DISCORD_MANAGER->Initialize();
204+
}
205+
else
206+
{
207+
DISCORD_MANAGER->Dispose();
208+
}
200209
}
201210

202211
void SettingsWindow::SteamAPIStateUpdate(const Qt::CheckState& state)

src/GUI/Translations/ru.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -393,22 +393,21 @@
393393
<context>
394394
<name>SettingsWindow</name>
395395
<message>
396-
<location filename="../SettingsWindow.cpp" line="35"/>
396+
<location filename="../SettingsWindow.cpp" line="36"/>
397397
<source>Enable debug console</source>
398398
<translation>Включить отладочную консоль</translation>
399399
</message>
400400
<message>
401-
<location filename="../SettingsWindow.cpp" line="41"/>
402401
<source>Enable Discord RPC (WIP)</source>
403-
<translation>Включить Discord RPC (WIP)</translation>
402+
<translation type="vanished">Включить Discord RPC (WIP)</translation>
404403
</message>
405404
<message>
406-
<location filename="../SettingsWindow.cpp" line="47"/>
405+
<location filename="../SettingsWindow.cpp" line="48"/>
407406
<source>Enable Steam Integration</source>
408407
<translation>Включить интеграцию со Steam</translation>
409408
</message>
410409
<message>
411-
<location filename="../SettingsWindow.cpp" line="53"/>
410+
<location filename="../SettingsWindow.cpp" line="54"/>
412411
<source>Force editor to use system language on start up</source>
413412
<translation>Использовать язык системы при запуске</translation>
414413
</message>
@@ -417,42 +416,47 @@
417416
<translation type="vanished">Включить строку состояния</translation>
418417
</message>
419418
<message>
420-
<location filename="../SettingsWindow.cpp" line="59"/>
419+
<location filename="../SettingsWindow.cpp" line="42"/>
420+
<source>Enable Discord RPC</source>
421+
<translation>Включить Discord RPC</translation>
422+
</message>
423+
<message>
424+
<location filename="../SettingsWindow.cpp" line="60"/>
421425
<source>Language:</source>
422426
<translation>Язык:</translation>
423427
</message>
424428
<message>
425-
<location filename="../SettingsWindow.cpp" line="80"/>
429+
<location filename="../SettingsWindow.cpp" line="81"/>
426430
<source>SAVE</source>
427431
<translation>СОХРАНИТЬ</translation>
428432
</message>
429433
<message>
430-
<location filename="../SettingsWindow.cpp" line="84"/>
434+
<location filename="../SettingsWindow.cpp" line="85"/>
431435
<source>RESET ALL</source>
432436
<translation>СБРОСИТЬ ВСЁ</translation>
433437
</message>
434438
<message>
435-
<location filename="../SettingsWindow.cpp" line="88"/>
439+
<location filename="../SettingsWindow.cpp" line="89"/>
436440
<source>BACK</source>
437441
<translation>НАЗАД</translation>
438442
</message>
439443
<message>
440-
<location filename="../SettingsWindow.cpp" line="135"/>
444+
<location filename="../SettingsWindow.cpp" line="136"/>
441445
<source>Setting Apply Confirmation</source>
442446
<translation>Подтверждение применения настроек</translation>
443447
</message>
444448
<message>
445-
<location filename="../SettingsWindow.cpp" line="136"/>
449+
<location filename="../SettingsWindow.cpp" line="137"/>
446450
<source>You have selected settings that require a complete restart of the editor. Do you want to apply new settings and restart editor?</source>
447451
<translation>Вы выбрали настройки, которые требуют полного перезапуска редактора. Вы желаете применить новые настройки и перезапустить редактор?</translation>
448452
</message>
449453
<message>
450-
<location filename="../SettingsWindow.cpp" line="138"/>
454+
<location filename="../SettingsWindow.cpp" line="139"/>
451455
<source>YES</source>
452456
<translation>ДА</translation>
453457
</message>
454458
<message>
455-
<location filename="../SettingsWindow.cpp" line="139"/>
459+
<location filename="../SettingsWindow.cpp" line="140"/>
456460
<source>CANCEL</source>
457461
<translation>ОТМЕНА</translation>
458462
</message>

src/Main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "GUI/WindowManager.hpp"
1313
#include "ProgramConstants.hpp"
1414
#include "FactionsManager.hpp"
15+
#include "DiscordManager.hpp"
1516
#include "SteamManager.hpp"
1617
#include "Logger.hpp"
1718

@@ -73,6 +74,10 @@ int main(int argc, const char** argv)
7374
// Enable Steam integration and create steam_appid.txt, if it doesn't exist
7475
if (PROGRAM_CONSTANTS->pSettingsFile->IsSteamIntegrationEnabled())
7576
STEAM_MANAGER->Initialize();
77+
78+
// Enable Discord RPC
79+
if (PROGRAM_CONSTANTS->pSettingsFile->IsDiscordRPCEnabled())
80+
DISCORD_MANAGER->Initialize();
7681

7782
// Initialize TechTree.json parsing
7883
FACTIONS_MANAGER = make_unique<FactionManager>();

0 commit comments

Comments
 (0)