Skip to content

Commit 8671a74

Browse files
Testing new window rendering
1 parent de1ddec commit 8671a74

10 files changed

Lines changed: 146 additions & 391 deletions

File tree

src/Core/ProgramConstants.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class ProgramConstants
3737

3838
// General strings
3939
const QString STYLES_FILENAME = "Styles.css";
40+
const QString G_FOLDER_NAME = "Generals";
41+
const QString GZH_FOLDER_NAME = "GeneralsZH";
4042

4143
// General editor folders
4244
const QString QT_ICONS_FOLDER = ":/icons";
@@ -46,8 +48,8 @@ class ProgramConstants
4648

4749
// Profile folders. TODO: Make profile related
4850
const QString PROFILES_FOLDER = RESOURCE_FOLDER + "/Profiles";
49-
const QString G_PROFILE_FOLDER = PROFILES_FOLDER + "/Generals";
50-
const QString GZH_PROFILE_FOLDER = PROFILES_FOLDER + "/GeneralsZH";
51+
const QString G_PROFILE_FOLDER = PROFILES_FOLDER + G_FOLDER_NAME;
52+
const QString GZH_PROFILE_FOLDER = PROFILES_FOLDER + GZH_FOLDER_NAME;
5153
const QString ICONS_FOLDER = GZH_PROFILE_FOLDER + "/Icons";
5254
const QString THEME_FOLDER = GZH_PROFILE_FOLDER + "/Theme";
5355
const QString MAIN_STYLES_FILE = PROFILES_FOLDER + STYLES_FILENAME;

src/GUI/SelectProfileWindow.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <QVBoxLayout>
2+
#include <QPushButton>
3+
#include <QDir>
4+
#include "../Extensions/StringExt.hpp"
5+
#include "../Core/Logger.hpp"
6+
#include "../Core/ProgramConstants.hpp"
7+
#include "SelectProfileWindow.hpp"
8+
9+
using namespace StringExt;
10+
11+
SelectProfileWindow::SelectProfileWindow(QWidget* parent) : QWidget(parent)
12+
{
13+
QHBoxLayout* ltMain = new QHBoxLayout();
14+
QVBoxLayout* ltCustomProfiles = new QVBoxLayout();
15+
QPushButton* btnGenerals = new QPushButton(tr(PROGRAM_CONSTANTS->G_FOLDER_NAME.toStdString().c_str()));
16+
QPushButton* btnGeneralsZH = new QPushButton(tr(PROGRAM_CONSTANTS->GZH_FOLDER_NAME.toStdString().c_str()));
17+
18+
btnGenerals->setObjectName(nameof(btnGenerals));
19+
btnGeneralsZH->setObjectName(nameof(btnGeneralsZH));
20+
21+
QDir profilesDir(PROGRAM_CONSTANTS->PROFILES_FOLDER);
22+
auto list = profilesDir.entryList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot, QDir::SortFlag::Name);
23+
list.removeOne(PROGRAM_CONSTANTS->G_FOLDER_NAME);
24+
list.removeOne(PROGRAM_CONSTANTS->GZH_FOLDER_NAME);
25+
for (const auto& elem : list)
26+
{
27+
LOGMSG("Add custom profile " + elem);
28+
QPushButton* btnCustomProfile = new QPushButton();
29+
btnCustomProfile->setObjectName("btn"q + elem);
30+
btnCustomProfile->setText(elem);
31+
ltCustomProfiles->addWidget(btnCustomProfile);
32+
}
33+
34+
ltMain->addWidget(btnGenerals);
35+
ltMain->addWidget(btnGeneralsZH);
36+
ltMain->addLayout(ltCustomProfiles);
37+
38+
setLayout(ltMain);
39+
}

src/GUI/SelectProfileWindow.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include <QWidget>
3+
#include "../Core/ProgramConstants.hpp"
4+
5+
class SelectProfileWindow : public QWidget
6+
{
7+
Q_OBJECT
8+
public: // Methods
9+
SelectProfileWindow(QWidget* parent = nullptr);
10+
};

src/GUI/SetUpWindowsWrapper.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SetUpWindowsWrapper::SetUpWindowsWrapper(QWidget* parent) : QStackedWidget(paren
2020
~Qt::WindowMinimizeButtonHint);
2121

2222
AddWidgets();
23-
setCurrentWidget(pGreetingWidget);
23+
setCurrentWidget(pSelectProfileWindow);
2424
AttachConnections();
2525
}
2626

@@ -29,18 +29,18 @@ void SetUpWindowsWrapper::AttachConnections()
2929
connect(pSettingsWindow, &SettingsWindow::languageChanged,
3030
this, &SetUpWindowsWrapper::SettingsWindow_LanguageChanged);
3131

32-
connect(pGreetingWidget, &GreetingWindow::btnLoadFromFileClicked,
33-
this, &SetUpWindowsWrapper::BtnLoadFromFile_Clicked);
34-
35-
connect(pGreetingWidget, &GreetingWindow::btnLoadFromGameClicked,
36-
this, &SetUpWindowsWrapper::BtnLoadFromGame_Clicked);
32+
// connect(pGreetingWidget, &GreetingWindow::btnLoadFromFileClicked,
33+
// this, &SetUpWindowsWrapper::BtnLoadFromFile_Clicked);
34+
35+
// connect(pGreetingWidget, &GreetingWindow::btnLoadFromGameClicked,
36+
// this, &SetUpWindowsWrapper::BtnLoadFromGame_Clicked);
3737

38-
connect(pGreetingWidget, &GreetingWindow::btnSettingsClicked,
39-
this, &SetUpWindowsWrapper::BtnSettings_Clicked);
38+
// connect(pGreetingWidget, &GreetingWindow::btnSettingsClicked,
39+
// this, &SetUpWindowsWrapper::BtnSettings_Clicked);
4040

4141
connect(pLoadFromTheFileWindow, &LoadFromTheFileWindow::btnBackClicked,
4242
this, &SetUpWindowsWrapper::BtnBack_Clicked);
43-
43+
4444
connect(pLoadFromTheFileWindow, &LoadFromTheFileWindow::btnStartClicked,
4545
this, &SetUpWindowsWrapper::LoadFromTheFileWindow_AcceptConfiguration);
4646

@@ -59,15 +59,15 @@ void SetUpWindowsWrapper::DetachConnections()
5959
disconnect(pSettingsWindow, &SettingsWindow::languageChanged,
6060
this, &SetUpWindowsWrapper::SettingsWindow_LanguageChanged);
6161

62-
disconnect(pGreetingWidget, &GreetingWindow::btnLoadFromFileClicked,
63-
this, &SetUpWindowsWrapper::BtnLoadFromFile_Clicked);
64-
65-
disconnect(pGreetingWidget, &GreetingWindow::btnLoadFromGameClicked,
66-
this, &SetUpWindowsWrapper::BtnLoadFromGame_Clicked);
62+
// disconnect(pGreetingWidget, &GreetingWindow::btnLoadFromFileClicked,
63+
// this, &SetUpWindowsWrapper::BtnLoadFromFile_Clicked);
64+
65+
// disconnect(pGreetingWidget, &GreetingWindow::btnLoadFromGameClicked,
66+
// this, &SetUpWindowsWrapper::BtnLoadFromGame_Clicked);
67+
68+
// disconnect(pGreetingWidget, &GreetingWindow::btnSettingsClicked,
69+
// this, &SetUpWindowsWrapper::BtnBack_Clicked);
6770

68-
disconnect(pGreetingWidget, &GreetingWindow::btnSettingsClicked,
69-
this, &SetUpWindowsWrapper::BtnBack_Clicked);
70-
7171
disconnect(pLoadFromTheFileWindow, &LoadFromTheFileWindow::btnBackClicked,
7272
this, &SetUpWindowsWrapper::BtnBack_Clicked);
7373

@@ -86,17 +86,20 @@ void SetUpWindowsWrapper::DetachConnections()
8686

8787
void SetUpWindowsWrapper::AddWidgets()
8888
{
89-
pGreetingWidget = new GreetingWindow();
89+
pSelectProfileWindow = new SelectProfileWindow();
90+
// pGreetingWidget = new GreetingWindow();
9091
pLoadFromTheGameWindow = new LoadFromTheGameWindow();
9192
pLoadFromTheFileWindow = new LoadFromTheFileWindow();
9293
pSettingsWindow = new SettingsWindow();
9394

94-
pGreetingWidget->setFixedSize(size());
95+
pSelectProfileWindow->setFixedSize(size());
96+
// pGreetingWidget->setFixedSize(size());
9597
pLoadFromTheGameWindow->setFixedSize(size());
9698
pLoadFromTheFileWindow->setFixedSize(size());
9799
pSettingsWindow->setFixedSize(size());
98100

99-
addWidget(pGreetingWidget);
101+
addWidget(pSelectProfileWindow);
102+
// addWidget(pGreetingWidget);
100103
addWidget(pLoadFromTheGameWindow);
101104
addWidget(pLoadFromTheFileWindow);
102105
addWidget(pSettingsWindow);
@@ -107,7 +110,7 @@ void SetUpWindowsWrapper::SettingsWindow_LanguageChanged()
107110
WINDOW_MANAGER->SetTranslator();
108111

109112
DetachConnections();
110-
pGreetingWidget->deleteLater();
113+
// pGreetingWidget->deleteLater();
111114
pLoadFromTheGameWindow->deleteLater();
112115
pLoadFromTheFileWindow->deleteLater();
113116
pSettingsWindow->deleteLater();
@@ -120,7 +123,7 @@ void SetUpWindowsWrapper::SettingsWindow_LanguageChanged()
120123
void SetUpWindowsWrapper::BtnLoadFromFile_Clicked() { setCurrentWidget(pLoadFromTheFileWindow); }
121124
void SetUpWindowsWrapper::BtnLoadFromGame_Clicked() { setCurrentWidget(pLoadFromTheGameWindow); }
122125
void SetUpWindowsWrapper::BtnSettings_Clicked() { setCurrentWidget(pSettingsWindow); }
123-
void SetUpWindowsWrapper::BtnBack_Clicked() { WINDOW_MANAGER->SetCSFFilePath(""); setCurrentWidget(pGreetingWidget); }
126+
void SetUpWindowsWrapper::BtnBack_Clicked() { WINDOW_MANAGER->SetCSFFilePath(""); setCurrentWidget(pSelectProfileWindow); }
124127

125128
void SetUpWindowsWrapper::LoadFromTheGameWindow_AcceptConfiguration()
126129
{

src/GUI/SetUpWindowsWrapper.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
#include "GreetingWindow.hpp"
44
#include "LoadFromTheGameWindow.hpp"
55
#include "LoadFromTheFileWindow.hpp"
6+
#include "SelectProfileWindow.hpp"
67
#include "SettingsWindow.hpp"
78

89
class SetUpWindowsWrapper final : public QStackedWidget
910
{
1011
Q_OBJECT
1112
private: // Data
13+
SelectProfileWindow* pSelectProfileWindow = nullptr;
1214
GreetingWindow* pGreetingWidget = nullptr;
1315
LoadFromTheGameWindow* pLoadFromTheGameWindow = nullptr;
1416
LoadFromTheFileWindow* pLoadFromTheFileWindow = nullptr;

src/GUI/WindowManager.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,34 @@ WindowManager::WindowManager()
2020

2121
qApp->setWindowIcon(QIcon(QPixmap::fromImage(ImageManager::DecodeEditorWebpIcon())));
2222

23+
// Apply general style
2324
LOGMSG("Loading \"" + PROGRAM_CONSTANTS->MAIN_STYLES_FILE + "\"...");
24-
QFile css(PROGRAM_CONSTANTS->MAIN_STYLES_FILE);
25-
if (css.open(QIODevice::ReadOnly))
25+
QFile cssGLobal(PROGRAM_CONSTANTS->MAIN_STYLES_FILE);
26+
if (cssGLobal.open(QIODevice::ReadOnly))
2627
{
27-
qApp->setStyleSheet(css.readAll());
28-
css.close();
28+
qApp->setStyleSheet(cssGLobal.readAll());
29+
cssGLobal.close();
2930
LOGMSG("Main styles sheet has been loaded");
3031
}
3132
else
3233
{
3334
LOGMSG("Unable to read the main style file");
3435
}
3536

37+
// Apply ZH style as default
38+
LOGMSG("Loading \"" + PROGRAM_CONSTANTS->GZH_PROFILE_FOLDER + "/" + PROGRAM_CONSTANTS->STYLES_FILENAME + "\"...");
39+
QFile cssGZH(PROGRAM_CONSTANTS->GZH_PROFILE_FOLDER + "/" + PROGRAM_CONSTANTS->STYLES_FILENAME);
40+
if (cssGZH.open(QIODevice::ReadOnly))
41+
{
42+
qApp->setStyleSheet(cssGZH.readAll());
43+
cssGZH.close();
44+
LOGMSG("GeneralsZH styles sheet has been loaded");
45+
}
46+
else
47+
{
48+
LOGMSG("Unable to read the GeneralsZH style file");
49+
}
50+
3651
LOGMSG("Loading launch window...");
3752
pStartUpWindow = new SetUpWindowsWrapper();
3853
pStartUpWindow->setWindowTitle(strWindowName);
@@ -122,7 +137,10 @@ void WindowManager::SetTranslator()
122137
pAppTranslator = new QTranslator();
123138
pAppTranslator->load(lngShortName, PROGRAM_CONSTANTS->TRANSLATIONS_FOLDER);
124139
qApp->installTranslator(pAppTranslator);
125-
FACTIONS_MANAGER->UpdateFactionNames();
140+
if (FACTIONS_MANAGER != nullptr)
141+
{
142+
FACTIONS_MANAGER->UpdateFactionNames();
143+
}
126144
}
127145

128146
void WindowManager::Show() { pStartUpWindow->show(); }

src/Main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QApplication>
88
#include <QMessageBox>
99
#include <QDebug>
10+
#include <QDir>
1011

1112
// Project headers
1213
#include "GUI/WindowManager.hpp"
@@ -83,12 +84,12 @@ int main(int argc, const char** argv)
8384
if (PROGRAM_CONSTANTS->pSettingsFile->IsDiscordRPCEnabled())
8485
DISCORD_MANAGER->Initialize();
8586

86-
// Initialize TechTree.json parsing
87-
FACTIONS_MANAGER = make_unique<FactionManager>();
88-
8987
// Define logger as the singleton class, that could be used anywhere in the project
9088
WINDOW_MANAGER = make_unique<WindowManager>();
9189

90+
// Initialize TechTree.json parsing
91+
// FACTIONS_MANAGER = make_unique<FactionManager>();
92+
9293
try
9394
{
9495
WINDOW_MANAGER->Show();

src/Resources/Profiles/GeneralsZH/Theme/Styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ QPushButton#btnOk
130130
}
131131

132132
/* Start widgets and SettingsWindow style settings */
133-
LoadFromTheFileWindow, SetUpWindowsWrapper, LoadFromTheGameWindow, SettingsWindow, QWidget#pSettingsWindow
133+
LoadFromTheFileWindow, SetUpWindowsWrapper, LoadFromTheGameWindow, SettingsWindow, SelectProfileWindow, QWidget#pSettingsWindow
134134
{
135135
border-image: url(Resources/Profiles/GeneralsZH/Theme/StartMenuBackground.webp) 0 0 0 0 stretch stretch;
136136
background-color: black;

0 commit comments

Comments
 (0)