Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
cmake_minimum_required(VERSION 3.26 FATAL_ERROR)

if (NOT WIN32)
message(FATAL_ERROR "This program has been specified to compile on Microsoft Windows OS only.")
Expand Down
26 changes: 7 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,15 @@
)

# Copying Resource folder with subfolders, configs and files
file(
COPY "${PROJECT_RESOURCE_FOLDER}"
DESTINATION ${PROJECT_DESTINATION_RESOURCES_FOLDER}/..
)

# Managing additional source files
# Declare json files
set(
ADDITIONAL_RESOURCES
"${PROJECT_RESOURCE_FOLDER}/TechTree.json"
"${PROJECT_RESOURCE_FOLDER}/Settings.json"
# https://discourse.cmake.org/t/copying-files-with-destination-folder-depending-on-build-config/10686
add_custom_target(SyncResourceDir
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
"${PROJECT_RESOURCE_FOLDER}"
"${PROJECT_DESTINATION_RESOURCES_FOLDER}"
COMMENT "Synchronize resources directories"
)

# Copy json files if file updates
foreach(CURRENT_FILE ${ADDITIONAL_RESOURCES})
configure_file(
${CURRENT_FILE}
${PROJECT_DESTINATION_RESOURCES_FOLDER}
COPYONLY
)
endforeach()
add_dependencies(${MAIN_TARGET_NAME} SyncResourceDir)

# Qt libs linking aka copying dependecies to the standalone release version of the project
# Find the qt libs deploy program
Expand Down
5 changes: 5 additions & 0 deletions src/Core/ProgramConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ void ProgramConstants::InitializeTranslations()
Languages.insert(i, {file.completeBaseName().toLower(), Windows::Locale::LanguageName(file.completeBaseName().toLower())});
}
}

void ProgramConstants::InitializeProfiles()
{

}
30 changes: 21 additions & 9 deletions src/Core/ProgramConstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,28 @@ class ProgramConstants
// Colors
const QString LINK_COLOR = "#baff0c";

// Folders
// General strings
const QString STYLES_FILENAME = "Styles.css";
const QString TECH_TREE_FILENAME = "TechTree.json";
const QString G_FOLDER_NAME = "Generals";
const QString GZH_FOLDER_NAME = "GeneralsZH";
const QString ICONS_FOLDER_NAME = "Icons";

// General editor folders
const QString QT_ICONS_FOLDER = ":/icons";
const QString RESOURCE_FOLDER = "Resources";
const QString BINARIES_FOLDER = RESOURCE_FOLDER + "\\Binaries";
const QString TRANSLATIONS_FOLDER = RESOURCE_FOLDER + "/Translations";
const QString ICONS_FOLDER = RESOURCE_FOLDER + "/Icons";
const QString THEME_FOLDER = RESOURCE_FOLDER + "/Theme";
const QString QT_ICONS_FOLDER = ":/icons";

// Resource files
const QString TECH_TREE_FILE = RESOURCE_FOLDER + "/TechTree.json";

// Profile folders
const QString PROFILES_FOLDER = RESOURCE_FOLDER + "/Profiles";
const QString G_PROFILE_FOLDER = PROFILES_FOLDER + "/" + G_FOLDER_NAME;
const QString GZH_PROFILE_FOLDER = PROFILES_FOLDER + "/" + GZH_FOLDER_NAME;
const QString MAIN_STYLES_FILE = PROFILES_FOLDER + "/" + STYLES_FILENAME;

// Profile unrelated resource files
const QString SETTINGS_FILE = RESOURCE_FOLDER + "/Settings.json";
const QString STYLES_SHEET_FILE = THEME_FOLDER + "/Styles.css";
const QString GLOBAL_STYLES_FILE = RESOURCE_FOLDER + STYLES_FILENAME;

// Build-in files
const QString MISSING_ICON_FILE = QT_ICONS_FOLDER + "/NoImageSmall.webp";
Expand Down Expand Up @@ -101,7 +111,7 @@ class ProgramConstants
const QString NON_ASCII_HOTKEY_ERROR_DESCRIPTION = QObject::tr("You have assign as hotkey a non-ASCII character \"%1\".\nMake sure that you are using ASCII only symbols.");
const QString FORBIDDEN_HOTKEY_ERROR_DESCRIPTION = QObject::tr("You have assign as hotkey a forbidden character \"%1\".\nMake sure that you are using only allowed symbols.");

// Other string constants
// CSF string constants
const QString HOTKEY_CSF_CATEGORY = "CONTROLBAR";
const QString OBJECT_CSF_CATEGORY = "OBJECT";
const QString BIG_ARCHIVE_CSF_PATH = "Data\\English\\generals.csf";
Expand Down Expand Up @@ -159,4 +169,6 @@ class ProgramConstants
void InitializeFileSettings();
/// @brief Parse `*.qm` files in the `Resources\Translations` folder.
void InitializeTranslations();
/// @brief Parse folders in `Resources\Profiles` folder.
void InitializeProfiles();
};
3 changes: 0 additions & 3 deletions src/GUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,3 @@

# Link the libwebp target to the GUI target
target_link_libraries(${TARGET_NAME} PRIVATE ${LIB_WEBP_TARGET_NAME})

# Copy Styles.css with updates
configure_file("${PROJECT_RESOURCE_FOLDER}/Theme/Styles.css" "${PROJECT_DESTINATION_RESOURCES_FOLDER}/Theme/Styles.css")
7 changes: 4 additions & 3 deletions src/GUI/ImageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "../../libs/libwebp/src/webp/decode.h"
#include "../Core/Logger.hpp"
#include "WindowManager.hpp"
#include "ImageManager.hpp"

QImage ImageManager::DecodeWebpIcon(const QString& iconName)
Expand All @@ -12,8 +13,8 @@ QImage ImageManager::DecodeWebpIcon(const QString& iconName)
const auto it = ImagesCache.constFind(iconName);
if (it != ImagesCache.constEnd()) return it.value();

// Find
const QFileInfo targetIconFile = FindIconFile(PROGRAM_CONSTANTS->ICONS_FOLDER, iconName);
// Search for specific image
const QFileInfo targetIconFile = FindIconFile(WINDOW_MANAGER->ProfileFolder + "/" + PROGRAM_CONSTANTS->ICONS_FOLDER_NAME, iconName);

if (targetIconFile.exists())
{
Expand Down Expand Up @@ -74,7 +75,7 @@ QImage ImageManager::DecodeWebpIconPath(const QString& iconPath)
{
if (!iconPath.isEmpty())
{
LOGMSG("No icon file [" + iconFile.fileName() + "] was found");
LOGMSG("Icon file [" + iconFile.fileName() + "] was not found");
}
return DecodeMissingWebpIcon();
}
Expand Down
54 changes: 54 additions & 0 deletions src/GUI/SelectProfileWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <QDir>
#include "../Extensions/StringExt.hpp"
#include "../Core/Logger.hpp"
#include "../Core/ProgramConstants.hpp"
#include "SelectProfileWindow.hpp"

using namespace StringExt;

SelectProfileWindow::SelectProfileWindow(QWidget* parent) : QWidget(parent)
{
ltMain = new QHBoxLayout();
ltGameProfiles = new QVBoxLayout();
ltCustomProfiles = new QVBoxLayout();
btnGenerals = new QPushButton(tr(PROGRAM_CONSTANTS->G_FOLDER_NAME.toStdString().c_str()));
btnGeneralsZH = new QPushButton(tr(PROGRAM_CONSTANTS->GZH_FOLDER_NAME.toStdString().c_str()));

btnGenerals->setObjectName(nameof(btnGenerals));
connect(btnGenerals, &QPushButton::clicked, this, &SelectProfileWindow::BtnGenerals_Clicked);
btnGeneralsZH->setObjectName(nameof(btnGeneralsZH));
connect(btnGeneralsZH, &QPushButton::clicked, this, &SelectProfileWindow::BtnGeneralsZH_Clicked);
ltGameProfiles->addWidget(btnGenerals);
ltGameProfiles->addWidget(btnGeneralsZH);

QDir profilesDir(PROGRAM_CONSTANTS->PROFILES_FOLDER);
auto list = profilesDir.entryList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot, QDir::SortFlag::Name);
list.removeOne(PROGRAM_CONSTANTS->G_FOLDER_NAME);
list.removeOne(PROGRAM_CONSTANTS->GZH_FOLDER_NAME);
for (const auto& elem : list)
{
LOGMSG("Add custom profile " + elem);
QPushButton* btnCustomProfile = new QPushButton();
btnCustomProfile->setObjectName(nameof(btnCustomProfile));
btnCustomProfile->setProperty("profileName", "btn"q + elem);
btnCustomProfile->setText(elem);
connect(btnCustomProfile, &QPushButton::clicked, this, &SelectProfileWindow::BtnCustomProfile_Clicked);
ltCustomProfiles->addWidget(btnCustomProfile);
}

ltMain->addLayout(ltGameProfiles);
ltMain->addLayout(ltCustomProfiles);

setLayout(ltMain);
}

void SelectProfileWindow::BtnGenerals_Clicked() { emit gProfileSelected(); }
void SelectProfileWindow::BtnGeneralsZH_Clicked() { emit gzhProfileSelected(); }
void SelectProfileWindow::BtnCustomProfile_Clicked()
{
auto btn = qobject_cast<QPushButton*>(sender());
if (btn == nullptr)
return;

emit customProfileSelected(btn->text());
}
26 changes: 26 additions & 0 deletions src/GUI/SelectProfileWindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include "../Core/ProgramConstants.hpp"

class SelectProfileWindow : public QWidget
{
Q_OBJECT
private: // Data
QHBoxLayout* ltMain = nullptr;
QVBoxLayout* ltGameProfiles = nullptr;
QVBoxLayout* ltCustomProfiles = nullptr;
QPushButton* btnGenerals = nullptr;
QPushButton* btnGeneralsZH = nullptr;
public: // Methods
SelectProfileWindow(QWidget* parent = nullptr);
signals:
void gProfileSelected();
void gzhProfileSelected();
void customProfileSelected(QString data);
private slots:
void BtnGenerals_Clicked();
void BtnGeneralsZH_Clicked();
void BtnCustomProfile_Clicked();
};
74 changes: 38 additions & 36 deletions src/GUI/SetUpWindowsWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,98 +20,91 @@ SetUpWindowsWrapper::SetUpWindowsWrapper(QWidget* parent) : QStackedWidget(paren
~Qt::WindowMinimizeButtonHint);

AddWidgets();
setCurrentWidget(pGreetingWidget);
setCurrentWidget(pSelectProfileWindow);
AttachConnections();
}

void SetUpWindowsWrapper::AttachConnections()
{
connect(pSettingsWindow, &SettingsWindow::languageChanged,
this, &SetUpWindowsWrapper::SettingsWindow_LanguageChanged);

connect(pGreetingWidget, &GreetingWindow::btnLoadFromFileClicked,
this, &SetUpWindowsWrapper::BtnLoadFromFile_Clicked);

connect(pGreetingWidget, &GreetingWindow::btnLoadFromGameClicked,
this, &SetUpWindowsWrapper::BtnLoadFromGame_Clicked);

connect(pGreetingWidget, &GreetingWindow::btnSettingsClicked,
this, &SetUpWindowsWrapper::BtnSettings_Clicked);
connect(pSelectProfileWindow, &SelectProfileWindow::gProfileSelected,
this, &SetUpWindowsWrapper::SelectProfileWindow_GProfileSelected);
connect(pSelectProfileWindow, &SelectProfileWindow::gzhProfileSelected,
this, &SetUpWindowsWrapper::SelectProfileWindow_GZHProfileSelected);
connect(pSelectProfileWindow, &SelectProfileWindow::customProfileSelected,
this, &SetUpWindowsWrapper::SelectProfileWindow_CustomProfileSelected);

connect(pLoadFromTheFileWindow, &LoadFromTheFileWindow::btnBackClicked,
this, &SetUpWindowsWrapper::BtnBack_Clicked);

connect(pLoadFromTheFileWindow, &LoadFromTheFileWindow::btnStartClicked,
this, &SetUpWindowsWrapper::LoadFromTheFileWindow_AcceptConfiguration);

connect(pLoadFromTheGameWindow, &LoadFromTheGameWindow::btnBackClicked,
this, &SetUpWindowsWrapper::BtnBack_Clicked);

connect(pLoadFromTheGameWindow, &LoadFromTheGameWindow::btnStartClicked,
this, &SetUpWindowsWrapper::LoadFromTheGameWindow_AcceptConfiguration);

connect(pSettingsWindow, &SettingsWindow::languageChanged,
this, &SetUpWindowsWrapper::SettingsWindow_LanguageChanged);
connect(pSettingsWindow, &SettingsWindow::btnBackClicked,
this, &SetUpWindowsWrapper::BtnBack_Clicked);
}

void SetUpWindowsWrapper::DetachConnections()
{
disconnect(pSettingsWindow, &SettingsWindow::languageChanged,
this, &SetUpWindowsWrapper::SettingsWindow_LanguageChanged);

disconnect(pGreetingWidget, &GreetingWindow::btnLoadFromFileClicked,
this, &SetUpWindowsWrapper::BtnLoadFromFile_Clicked);

disconnect(pGreetingWidget, &GreetingWindow::btnLoadFromGameClicked,
this, &SetUpWindowsWrapper::BtnLoadFromGame_Clicked);
disconnect(pSelectProfileWindow, &SelectProfileWindow::gProfileSelected,
this, &SetUpWindowsWrapper::SelectProfileWindow_GProfileSelected);
disconnect(pSelectProfileWindow, &SelectProfileWindow::gzhProfileSelected,
this, &SetUpWindowsWrapper::SelectProfileWindow_GZHProfileSelected);
disconnect(pSelectProfileWindow, &SelectProfileWindow::customProfileSelected,
this, &SetUpWindowsWrapper::SelectProfileWindow_CustomProfileSelected);

disconnect(pGreetingWidget, &GreetingWindow::btnSettingsClicked,
this, &SetUpWindowsWrapper::BtnBack_Clicked);

disconnect(pLoadFromTheFileWindow, &LoadFromTheFileWindow::btnBackClicked,
this, &SetUpWindowsWrapper::BtnBack_Clicked);

disconnect(pLoadFromTheFileWindow, &LoadFromTheFileWindow::btnStartClicked,
this, &SetUpWindowsWrapper::LoadFromTheFileWindow_AcceptConfiguration);

disconnect(pLoadFromTheGameWindow, &LoadFromTheGameWindow::btnBackClicked,
this, &SetUpWindowsWrapper::BtnBack_Clicked);

disconnect(pLoadFromTheGameWindow, &LoadFromTheGameWindow::btnStartClicked,
this, &SetUpWindowsWrapper::LoadFromTheGameWindow_AcceptConfiguration);

disconnect(pSettingsWindow, &SettingsWindow::languageChanged,
this, &SetUpWindowsWrapper::SettingsWindow_LanguageChanged);
disconnect(pSettingsWindow, &SettingsWindow::btnBackClicked,
this, &SetUpWindowsWrapper::BtnBack_Clicked);
}

void SetUpWindowsWrapper::AddWidgets()
{
pGreetingWidget = new GreetingWindow();
pSelectProfileWindow = new SelectProfileWindow();
pLoadFromTheGameWindow = new LoadFromTheGameWindow();
pLoadFromTheFileWindow = new LoadFromTheFileWindow();
pSettingsWindow = new SettingsWindow();

pGreetingWidget->setFixedSize(size());
pSelectProfileWindow->setFixedSize(size());
pLoadFromTheGameWindow->setFixedSize(size());
pLoadFromTheFileWindow->setFixedSize(size());
pSettingsWindow->setFixedSize(size());

addWidget(pGreetingWidget);
addWidget(pSelectProfileWindow);
addWidget(pLoadFromTheGameWindow);
addWidget(pLoadFromTheFileWindow);
addWidget(pSettingsWindow);
}

void SetUpWindowsWrapper::SettingsWindow_LanguageChanged()
void SetUpWindowsWrapper::DeleteWidgets()
{
WINDOW_MANAGER->SetTranslator();

DetachConnections();
pGreetingWidget->deleteLater();
pSelectProfileWindow->deleteLater();
pLoadFromTheGameWindow->deleteLater();
pLoadFromTheFileWindow->deleteLater();
pSettingsWindow->deleteLater();
}

void SetUpWindowsWrapper::SettingsWindow_LanguageChanged()
{
WINDOW_MANAGER->SetTranslator();
DetachConnections();
DeleteWidgets();
AddWidgets();
AttachConnections();
setCurrentWidget(pSettingsWindow);
Expand All @@ -120,7 +113,16 @@ void SetUpWindowsWrapper::SettingsWindow_LanguageChanged()
void SetUpWindowsWrapper::BtnLoadFromFile_Clicked() { setCurrentWidget(pLoadFromTheFileWindow); }
void SetUpWindowsWrapper::BtnLoadFromGame_Clicked() { setCurrentWidget(pLoadFromTheGameWindow); }
void SetUpWindowsWrapper::BtnSettings_Clicked() { setCurrentWidget(pSettingsWindow); }
void SetUpWindowsWrapper::BtnBack_Clicked() { WINDOW_MANAGER->SetCSFFilePath(""); setCurrentWidget(pGreetingWidget); }
void SetUpWindowsWrapper::BtnBack_Clicked()
{
setCurrentWidget(pSelectProfileWindow);
WINDOW_MANAGER->SetCSFFilePath("");
WINDOW_MANAGER->ApplyDefaultProfileStyleSheet();
}

void SetUpWindowsWrapper::SelectProfileWindow_GProfileSelected() { WINDOW_MANAGER->StartUpWindow_GProfileSelected(); BtnLoadFromFile_Clicked(); }
void SetUpWindowsWrapper::SelectProfileWindow_GZHProfileSelected() { WINDOW_MANAGER->StartUpWindow_GZHProfileSelected(); BtnLoadFromFile_Clicked(); }
void SetUpWindowsWrapper::SelectProfileWindow_CustomProfileSelected(const QString& folder) { WINDOW_MANAGER->StartUpWindow_CustomProfileSelected(folder); BtnLoadFromFile_Clicked(); }

void SetUpWindowsWrapper::LoadFromTheGameWindow_AcceptConfiguration()
{
Expand Down
Loading
Loading