Update MapView.cpp, NoggitApplication.cpp, and 21 more files... | start project system rework

This commit is contained in:
Skarn
2022-03-11 00:35:09 +03:00
parent f2074bc4ba
commit edf9497ed1
22 changed files with 837 additions and 655 deletions

View File

@@ -1104,13 +1104,13 @@ void MapView::setupFileMenu()
{
auto bookmark = Noggit::Project::NoggitProjectBookmarkMap();
bookmark.Position = _camera.position;
bookmark.CameraPitch = _camera.pitch()._;
bookmark.CameraYaw = _camera.yaw()._;
bookmark.MapID = _world->getMapID();
bookmark.Name = gAreaDB.getAreaName(_world->getAreaID(_camera.position));
bookmark.position = _camera.position;
bookmark.camera_pitch = _camera.pitch()._;
bookmark.camera_yaw = _camera.yaw()._;
bookmark.map_id = _world->getMapID();
bookmark.name = gAreaDB.getAreaName(_world->getAreaID(_camera.position));
_project->CreateBookmark(bookmark);
_project->createBookmark(bookmark);
}
);

View File

@@ -112,7 +112,7 @@ namespace Noggit::Application
}
std::shared_ptr<Noggit::Application::NoggitApplicationConfiguration> NoggitApplication::GetConfiguration()
std::shared_ptr<Noggit::Application::NoggitApplicationConfiguration> NoggitApplication::getConfiguration()
{
return _applicationConfiguration;
}

View File

@@ -10,7 +10,7 @@
#include <noggit/application/Configuration/NoggitApplicationConfiguration.hpp>
#include <noggit/application/Configuration/NoggitApplicationConfigurationReader.hpp>
#include <noggit/application/Configuration/NoggitApplicationConfigurationWriter.hpp>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.h>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.hpp>
#include <memory>
#include <string>
#include <vector>
@@ -49,7 +49,7 @@ namespace Noggit::Application {
void clientData(std::shared_ptr<BlizzardArchive::ClientData> data) { _client_data = data; }
void Initalize(int argc, char* argv[]);
std::shared_ptr<Noggit::Application::NoggitApplicationConfiguration> GetConfiguration();
std::shared_ptr<Noggit::Application::NoggitApplicationConfiguration> getConfiguration();
static void TerminationHandler();
private:
NoggitApplication() = default;

View File

@@ -1,5 +1,6 @@
//Folder to contain all of the project related files
#pragma once
#include <map>
#include <memory>
#include <blizzard-archive-library/include/CASCArchive.hpp>
@@ -30,179 +31,183 @@
namespace Noggit::Project
{
enum class ProjectVersion
enum class ProjectVersion
{
VANILLA,
BC,
WOTLK,
CATA,
PANDARIA,
WOD,
LEGION,
BFA,
SL
};
struct ClientVersionFactory
{
static ProjectVersion mapToEnumVersion(std::string const& projectVersion)
{
VANILLA,
BC,
WOTLK,
CATA,
PANDARIA,
WOD,
LEGION,
BFA,
SL
};
if (projectVersion == "Wrath Of The Lich King")
return ProjectVersion::WOTLK;
if (projectVersion == "Shadowlands")
return ProjectVersion::SL;
struct ClientVersionFactory
assert(false);
}
static std::string MapToStringVersion(ProjectVersion const& projectVersion)
{
static ProjectVersion MapToEnumVersion(std::string const& projectVersion)
{
if (projectVersion == "Wrath Of The Lich King")
return ProjectVersion::WOTLK;
if (projectVersion == "Shadowlands")
return ProjectVersion::SL;
if (projectVersion == ProjectVersion::WOTLK)
return std::string("Wrath Of The Lich King");
if (projectVersion == ProjectVersion::SL)
return std::string("Shadowlands");
assert(false);
}
assert(false);
}
};
static std::string MapToStringVersion(ProjectVersion const& projectVersion)
{
if(projectVersion == ProjectVersion::WOTLK)
return std::string("Wrath Of The Lich King");
if(projectVersion == ProjectVersion::SL)
return std::string("Shadowlands");
struct NoggitProjectBookmarkMap
{
int map_id;
std::string name;
glm::vec3 position;
float camera_yaw;
float camera_pitch;
};
assert(false);
}
};
struct NoggitProjectPinnedMap
{
int MapId;
std::string MapName;
};
struct NoggitProjectBookmarkMap
class NoggitProject
{
std::shared_ptr<ApplicationProjectWriter> _projectWriter;
public:
std::string ProjectPath;
std::string ProjectName;
std::string ClientPath;
ProjectVersion projectVersion;
std::vector<NoggitProjectPinnedMap> PinnedMaps;
std::vector<NoggitProjectBookmarkMap> Bookmarks;
std::shared_ptr<BlizzardDatabaseLib::BlizzardDatabase> ClientDatabase;
std::shared_ptr<BlizzardArchive::ClientData> ClientData;
NoggitProject()
{
int MapID;
std::string Name;
glm::vec3 Position;
float CameraYaw;
float CameraPitch;
};
PinnedMaps = std::vector<NoggitProjectPinnedMap>();
Bookmarks = std::vector<NoggitProjectBookmarkMap>();
_projectWriter = std::make_shared<ApplicationProjectWriter>();
}
struct NoggitProjectPinnedMap
void createBookmark(const NoggitProjectBookmarkMap& bookmark)
{
int MapId;
std::string MapName;
};
Bookmarks.push_back(bookmark);
class NoggitProject
_projectWriter->saveProject(this, std::filesystem::path(ProjectPath));
}
void deleteBookmark()
{
std::shared_ptr<ApplicationProjectWriter> _projectWriter;
public:
std::string ProjectPath;
std::string ProjectName;
std::string ClientPath;
ProjectVersion projectVersion;
std::vector<NoggitProjectPinnedMap> PinnedMaps;
std::vector<NoggitProjectBookmarkMap> Bookmarks;
std::shared_ptr<BlizzardDatabaseLib::BlizzardDatabase> ClientDatabase;
std::shared_ptr<BlizzardArchive::ClientData> ClientData;
NoggitProject()
{
PinnedMaps = std::vector<NoggitProjectPinnedMap>();
Bookmarks = std::vector<NoggitProjectBookmarkMap>();
_projectWriter = std::make_shared<ApplicationProjectWriter>();
}
}
void CreateBookmark(NoggitProjectBookmarkMap bookmark)
{
Bookmarks.push_back(bookmark);
_projectWriter->SaveProject(this, std::filesystem::path(ProjectPath));
}
void DeleteBookmark()
{
}
void PinMap(int mapId, std::string MapName)
{
auto pinnedMap = NoggitProjectPinnedMap();
pinnedMap.MapName = MapName;
pinnedMap.MapId = mapId;
auto pinnedMapFound = std::find_if(std::begin(PinnedMaps), std::end(PinnedMaps), [&](Project::NoggitProjectPinnedMap pinnedMap)
{
return pinnedMap.MapId == mapId;
});
if (pinnedMapFound != std::end(PinnedMaps))
return;
PinnedMaps.push_back(pinnedMap);
_projectWriter->SaveProject(this, std::filesystem::path(ProjectPath));
}
void UnpinMap(int mapId)
{
PinnedMaps.erase(std::remove_if(PinnedMaps.begin(),PinnedMaps.end(),
[=](NoggitProjectPinnedMap pinnedMap)
{
return pinnedMap.MapId == mapId;
}),
PinnedMaps.end());
_projectWriter->SaveProject(this, std::filesystem::path(ProjectPath));
}
};
class ApplicationProject
void pinMap(int map_id, const std::string& map_name)
{
std::shared_ptr<NoggitProject> _activeProject;
std::shared_ptr<Application::NoggitApplicationConfiguration> _configuration;
public:
ApplicationProject(std::shared_ptr<Application::NoggitApplicationConfiguration> configuration)
{
_activeProject = nullptr;
_configuration = configuration;
}
auto pinnedMap = NoggitProjectPinnedMap();
pinnedMap.MapName = map_name;
pinnedMap.MapId = map_id;
void CreateProject(std::filesystem::path const& projectPath, std::filesystem::path const& clientPath,
std::string const& clientVersion, std::string const& projectName)
{
std::filesystem::create_directory(projectPath);
auto pinnedMapFound = std::find_if(std::begin(PinnedMaps), std::end(PinnedMaps),
[&](Project::NoggitProjectPinnedMap pinnedMap)
{
return pinnedMap.MapId == map_id;
});
auto project = NoggitProject();
project.ProjectName = projectName;
project.projectVersion = ClientVersionFactory::MapToEnumVersion(clientVersion);
project.ClientPath = clientPath.generic_string();
if (pinnedMapFound != std::end(PinnedMaps))
return;
auto projectWriter = ApplicationProjectWriter();
projectWriter.SaveProject(&project, projectPath);
PinnedMaps.push_back(pinnedMap);
}
_projectWriter->saveProject(this, std::filesystem::path(ProjectPath));
}
std::shared_ptr<NoggitProject> LoadProject(std::filesystem::path const& projectPath)
{
auto projectReader = ApplicationProjectReader();
auto project = projectReader.ReadProject(projectPath);
void unpinMap(int mapId)
{
PinnedMaps.erase(std::remove_if(PinnedMaps.begin(), PinnedMaps.end(),
[=](NoggitProjectPinnedMap pinnedMap)
{
return pinnedMap.MapId == mapId;
}),
PinnedMaps.end());
assert (project.has_value());
_projectWriter->saveProject(this, std::filesystem::path(ProjectPath));
}
};
std::string dbdFileDirectory = _configuration->ApplicationDatabaseDefinitionsPath;
class ApplicationProject
{
std::shared_ptr<NoggitProject> _activeProject;
std::shared_ptr<Application::NoggitApplicationConfiguration> _configuration;
public:
ApplicationProject(std::shared_ptr<Application::NoggitApplicationConfiguration> configuration)
{
_activeProject = nullptr;
_configuration = configuration;
}
auto clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
auto clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
auto clientArchiveLocale = BlizzardArchive::Locale::AUTO;
if (project->projectVersion == ProjectVersion::SL)
{
clientArchiveVersion = BlizzardArchive::ClientVersion::SL;
clientBuild = BlizzardDatabaseLib::Structures::Build("9.1.0.39584");
clientArchiveLocale = BlizzardArchive::Locale::enUS;
}
void createProject(std::filesystem::path const& project_path, std::filesystem::path const& client_path,
std::string const& client_version, std::string const& project_name)
{
if (!std::filesystem::exists(project_path))
std::filesystem::create_directory(project_path);
if (project->projectVersion == ProjectVersion::WOTLK)
{
clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
clientArchiveLocale = BlizzardArchive::Locale::AUTO;
}
auto project = NoggitProject();
project.ProjectName = project_name;
project.projectVersion = ClientVersionFactory::mapToEnumVersion(client_version);
project.ClientPath = client_path.generic_string();
project.ProjectPath = project_path.generic_string();
project->ClientDatabase = std::make_shared<BlizzardDatabaseLib::BlizzardDatabase>(dbdFileDirectory, clientBuild);
project->ClientData = std::make_shared<BlizzardArchive::ClientData>(
project->ClientPath, clientArchiveVersion, clientArchiveLocale, projectPath.generic_string());
auto project_writer = ApplicationProjectWriter();
project_writer.saveProject(&project, project_path);
return std::make_shared<NoggitProject>(project.value());
}
};
}
std::shared_ptr<NoggitProject> loadProject(std::filesystem::path const& projectPath)
{
auto projectReader = ApplicationProjectReader();
auto project = projectReader.ReadProject(projectPath);
assert (project.has_value());
std::string dbdFileDirectory = _configuration->ApplicationDatabaseDefinitionsPath;
auto clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
auto clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
auto clientArchiveLocale = BlizzardArchive::Locale::AUTO;
if (project->projectVersion == ProjectVersion::SL)
{
clientArchiveVersion = BlizzardArchive::ClientVersion::SL;
clientBuild = BlizzardDatabaseLib::Structures::Build("9.1.0.39584");
clientArchiveLocale = BlizzardArchive::Locale::enUS;
}
if (project->projectVersion == ProjectVersion::WOTLK)
{
clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
clientArchiveLocale = BlizzardArchive::Locale::AUTO;
}
project->ClientDatabase = std::make_shared<BlizzardDatabaseLib::BlizzardDatabase>(dbdFileDirectory, clientBuild);
project->ClientData = std::make_shared<BlizzardArchive::ClientData>(
project->ClientPath, clientArchiveVersion, clientArchiveLocale, projectPath.generic_string());
return std::make_shared<NoggitProject>(project.value());
}
};
}

View File

@@ -38,16 +38,16 @@ namespace Noggit::Project
for (auto const& jsonBookmark : projectBookmarks)
{
auto bookmark = NoggitProjectBookmarkMap();
bookmark.MapID = jsonBookmark.toObject().value("MapId").toInt();
bookmark.Name = jsonBookmark.toObject().value("BookmarkName").toString().toStdString();
bookmark.CameraPitch = jsonBookmark.toObject().value("CameraPitch").toDouble();
bookmark.CameraYaw = jsonBookmark.toObject().value("CameraYaw").toDouble();
bookmark.map_id = jsonBookmark.toObject().value("MapId").toInt();
bookmark.name = jsonBookmark.toObject().value("BookmarkName").toString().toStdString();
bookmark.camera_pitch = jsonBookmark.toObject().value("CameraPitch").toDouble();
bookmark.camera_yaw = jsonBookmark.toObject().value("CameraYaw").toDouble();
auto bookmarkPosition = jsonBookmark.toObject().value("Position");
auto bookmarkPositionX = bookmarkPosition.toObject().value("X").toDouble();
auto bookmarkPositionY = bookmarkPosition.toObject().value("Y").toDouble();
auto bookmarkPositionZ = bookmarkPosition.toObject().value("Z").toDouble();
bookmark.Position = glm::vec3(bookmarkPositionX, bookmarkPositionY, bookmarkPositionZ);
bookmark.position = glm::vec3(bookmarkPositionX, bookmarkPositionY, bookmarkPositionZ);
project.Bookmarks.push_back(bookmark);
}

View File

@@ -11,55 +11,56 @@
namespace Noggit::Project
{
void ApplicationProjectWriter::SaveProject(NoggitProject* project, std::filesystem::path const& projectPath)
{
auto projectConfigurationFilePath = (projectPath / (project->ProjectName + std::string(".noggitproj")));
auto projectConfigurationFile = QFile(QString::fromStdString(projectConfigurationFilePath.generic_string()));
projectConfigurationFile.open(QIODevice::WriteOnly);
void ApplicationProjectWriter::saveProject(NoggitProject* project, std::filesystem::path const& project_path)
{
auto project_configuration_file_path = (project_path / (project->ProjectName + std::string(".noggitproj")));
auto project_configuration_file = QFile(QString::fromStdString(project_configuration_file_path.generic_string()));
project_configuration_file.open(QIODevice::WriteOnly);
auto document = QJsonDocument();
auto root = QJsonObject();
auto projectConfiguration = QJsonObject();
auto clientConfiguration = QJsonObject();
auto document = QJsonDocument();
auto root = QJsonObject();
auto project_configuration = QJsonObject();
auto client_configuration = QJsonObject();
clientConfiguration.insert("ClientPath", project->ClientPath.c_str());
clientConfiguration.insert("ClientVersion", ClientVersionFactory::MapToStringVersion(project->projectVersion).c_str());
client_configuration.insert("ClientPath", project->ClientPath.c_str());
client_configuration.insert("ClientVersion",
ClientVersionFactory::MapToStringVersion(project->projectVersion).c_str());
auto pinnedMaps = QJsonArray();
for(auto const &pinnedMap : project->PinnedMaps)
{
auto jsonPinnedMap = QJsonObject();
jsonPinnedMap.insert("MapName", pinnedMap.MapName.c_str());
jsonPinnedMap.insert("MapId", pinnedMap.MapId);
pinnedMaps.push_back(jsonPinnedMap);
}
auto pinned_maps = QJsonArray();
for (auto const& pinnedMap: project->PinnedMaps)
{
auto json_pinned_map = QJsonObject();
json_pinned_map.insert("MapName", pinnedMap.MapName.c_str());
json_pinned_map.insert("MapId", pinnedMap.MapId);
pinned_maps.push_back(json_pinned_map);
}
auto bookmarks = QJsonArray();
for (auto const& bookmark : project->Bookmarks)
{
auto jsonPosition = QJsonObject();
jsonPosition.insert("X", bookmark.Position.x);
jsonPosition.insert("Y", bookmark.Position.y);
jsonPosition.insert("Z", bookmark.Position.z);
auto bookmarks = QJsonArray();
for (auto const& bookmark: project->Bookmarks)
{
auto json_position = QJsonObject();
json_position.insert("X", bookmark.position.x);
json_position.insert("Y", bookmark.position.y);
json_position.insert("Z", bookmark.position.z);
auto jsonBookmark = QJsonObject();
jsonBookmark.insert("BookmarkName", bookmark.Name.c_str());
jsonBookmark.insert("MapId", bookmark.MapID);
jsonBookmark.insert("CameraPitch", bookmark.CameraPitch);
jsonBookmark.insert("CameraYaw", bookmark.CameraYaw);
jsonBookmark.insert("Position", jsonPosition);
bookmarks.push_back(jsonBookmark);
}
auto json_bookmark = QJsonObject();
json_bookmark.insert("BookmarkName", bookmark.name.c_str());
json_bookmark.insert("MapId", bookmark.map_id);
json_bookmark.insert("CameraPitch", bookmark.camera_pitch);
json_bookmark.insert("CameraYaw", bookmark.camera_yaw);
json_bookmark.insert("Position", json_position);
bookmarks.push_back(json_bookmark);
}
projectConfiguration.insert("PinnedMaps", pinnedMaps);
projectConfiguration.insert("Bookmarks", bookmarks);
projectConfiguration.insert("ProjectName", project->ProjectName.c_str());
projectConfiguration.insert("Client", clientConfiguration);
project_configuration.insert("PinnedMaps", pinned_maps);
project_configuration.insert("Bookmarks", bookmarks);
project_configuration.insert("ProjectName", project->ProjectName.c_str());
project_configuration.insert("Client", client_configuration);
root.insert("Project", projectConfiguration);
document.setObject(root);
root.insert("Project", project_configuration);
document.setObject(root);
projectConfigurationFile.write(document.toJson(QJsonDocument::Indented));
projectConfigurationFile.close();
}
project_configuration_file.write(document.toJson(QJsonDocument::Indented));
project_configuration_file.close();
}
}

View File

@@ -12,7 +12,7 @@ namespace Noggit::Project
public:
ApplicationProjectWriter() = default;
void SaveProject(NoggitProject* project, std::filesystem::path const& projectPath);
void saveProject(NoggitProject* project, std::filesystem::path const& project_path);
};
}

View File

@@ -245,8 +245,8 @@ namespace Noggit::Ui::Windows
auto item = new QListWidgetItem(bookmarks_table);
auto mapBookmarkData = Widget::MapListBookmarkData();
mapBookmarkData.MapName = QString::fromStdString(entry.Name);
mapBookmarkData.Position = entry.Position;
mapBookmarkData.MapName = QString::fromStdString(entry.name);
mapBookmarkData.Position = entry.position;
auto mapBookmarkItem = new Widget::MapListBookmarkItem(mapBookmarkData, bookmarks_table);
@@ -265,13 +265,13 @@ namespace Noggit::Ui::Windows
for (DBCFile::Iterator it = gMapDB.begin(); it != gMapDB.end(); ++it)
{
if (it->getInt(MapDB::MapID) == entry.MapID)
if (it->getInt(MapDB::MapID) == entry.map_id)
{
_world = std::make_unique<World> (it->getString(MapDB::InternalName),
entry.MapID, Noggit::NoggitRenderContext::MAP_VIEW);
check_uid_then_enter_map ( entry.Position
, math::degrees (entry.CameraPitch)
, math::degrees (entry.CameraYaw)
entry.map_id, Noggit::NoggitRenderContext::MAP_VIEW);
check_uid_then_enter_map ( entry.position
, math::degrees (entry.camera_pitch)
, math::degrees (entry.camera_yaw)
, true
);
return;
@@ -335,13 +335,13 @@ namespace Noggit::Ui::Windows
void NoggitWindow::HandleEventMapListContextMenuPinMap(int mapId, std::string MapName)
{
_project->PinMap(mapId, MapName);
_project->pinMap(mapId, MapName);
_buildMapListComponent->BuildMapList(this);
}
void NoggitWindow::HandleEventMapListContextMenuUnpinMap(int mapId)
{
_project->UnpinMap(mapId);
_project->unpinMap(mapId);
_buildMapListComponent->BuildMapList(this);
}

View File

@@ -3,68 +3,78 @@
#include <QFileDialog>
#include <QSettings>
NoggitProjectCreationDialog::NoggitProjectCreationDialog(ProjectInformation& projectInformation, QWidget *parent) :
QDialog(parent)
, ui(new ::Ui::NoggitProjectCreationDialog)
, _projectInformation(projectInformation)
NoggitProjectCreationDialog::NoggitProjectCreationDialog(ProjectInformation& project_information, QWidget* parent) :
QDialog(parent), ui(new ::Ui::NoggitProjectCreationDialog), _projectInformation(project_information)
{
setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
ui->setupUi(this);
ui->setupUi(this);
QIcon icon = QIcon(":/icon-wrath");
ui->expansion_icon->setPixmap(icon.pixmap(QSize(32, 32)));
ui->expansion_icon->setObjectName("icon");
ui->expansion_icon->setStyleSheet("QLabel#icon { padding: 0px }");
ui->projectPathField_browse->setObjectName("icon");
QIcon icon = QIcon(":/icon-wrath");
ui->expansion_icon->setPixmap(icon.pixmap(QSize(32, 32)));
ui->expansion_icon->setObjectName("icon");
ui->expansion_icon->setStyleSheet("QLabel#icon { padding: 0px }");
ui->clientPathField_browse->setObjectName("icon");
QObject::connect(ui->project_expansion, QOverload<int>::of(&QComboBox::currentIndexChanged)
, [&](int index)
{
auto versionSelected = ui->project_expansion->currentText().toStdString();
QObject::connect(ui->project_expansion, QOverload<int>::of(&QComboBox::currentIndexChanged), [&](int index)
{
auto version_selected = ui->project_expansion->currentText().toStdString();
QIcon icon;
if (versionSelected == "Wrath Of The Lich King")
icon = QIcon(":/icon-wrath");
if (versionSelected == "Shadowlands")
icon = QIcon(":/icon-shadow");
QIcon icon;
if (version_selected == "Wrath Of The Lich King")
icon = QIcon(":/icon-wrath");
if (version_selected == "Shadowlands");
ui->expansion_icon->setPixmap(icon.pixmap(QSize(32, 32)));
}
);
ui->expansion_icon->setPixmap(icon.pixmap(QSize(32, 32)));
}
);
QObject::connect(ui->projectPathField_browse, &QPushButton::clicked
, [this]
{
QSettings settings;
auto defaultPath = settings.value("project/game_path").toString();
ui->projectPathField->setText(defaultPath);
QString folderName = QFileDialog::getExistingDirectory(this, "Select Client Directory", defaultPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
ui->projectPathField->setText(folderName);
}
);
QObject::connect(ui->button_ok, &QPushButton::clicked
, [&]
{
projectInformation.ProjectName = ui->projectName->text().toStdString();
projectInformation.GameClientPath = ui->projectPathField->text().toStdString();
projectInformation.GameClientVersion = ui->project_expansion->currentText().toStdString();
close();
}
);
QObject::connect(ui->button_cancel, &QPushButton::clicked
, [&]
{
close();
}
);
QObject::connect(ui->clientPathField_browse, &QPushButton::clicked, [this]
{
// TODO: implement automatic client path detection
QSettings settings;
auto default_path = settings.value("project/game_path").toString();
ui->clientPathField->setText(default_path);
QString folder_name = QFileDialog::getExistingDirectory(this
, "Select Client Directory"
, default_path
, QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks);
ui->clientPathField->setText(folder_name);
}
);
QObject::connect(ui->projectPathField_browse, &QPushButton::clicked, [this]
{
QString folder_name = QFileDialog::getExistingDirectory(this
, "Select Client Directory"
, "/"
, QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks);
ui->projectPathField->setText(folder_name);
}
);
QObject::connect(ui->button_ok, &QPushButton::clicked, [&]
{
project_information.ProjectName = ui->projectName->text().toStdString();
project_information.GameClientPath = ui->clientPathField->text().toStdString();
project_information.GameClientVersion = ui->project_expansion->currentText().toStdString();
project_information.ProjectPath = ui->projectPathField->text().toStdString();
close();
}
);
QObject::connect(ui->button_cancel, &QPushButton::clicked, [&]
{
close();
}
);
}
NoggitProjectCreationDialog::~NoggitProjectCreationDialog()
{
delete ui;
delete ui;
}

View File

@@ -11,6 +11,7 @@ class NoggitProjectCreationDialog;
struct ProjectInformation
{
std::string ProjectName;
std::string ProjectPath;
std::string GameClientPath;
std::string GameClientVersion;
};
@@ -20,7 +21,7 @@ class NoggitProjectCreationDialog : public QDialog
Q_OBJECT
public:
NoggitProjectCreationDialog(ProjectInformation& projectInformation, QWidget *parent = nullptr);
NoggitProjectCreationDialog(ProjectInformation& project_information, QWidget *parent = nullptr);
~NoggitProjectCreationDialog();
private:

View File

@@ -1,187 +1,282 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NoggitProjectCreationDialog</class>
<widget class="QDialog" name="NoggitProjectCreationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string>Noggit Project Creation</string>
</property>
<property name="windowIcon">
<iconset>
<normalon>:/icon</normalon>
</iconset>
</property>
<class>NoggitProjectCreationDialog</class>
<widget class="QDialog" name="NoggitProjectCreationDialog">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>238</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Noggit Project Creation</string>
</property>
<property name="windowIcon">
<iconset>
<normalon>:/icon</normalon>
</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>New Project Settings</string>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>150</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<property name="title">
<string>New Project Settings</string>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<layout class="QVBoxLayout" name="verticalLayout_21">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_24">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="labelx">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Project Name</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="projectName">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_25">
<item>
<widget class="QLabel" name="label_26">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Game Client Path</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="projectPathField"/>
</item>
<item>
<widget class="QPushButton" name="projectPathField_browse">
<property name="minimumSize">
<size>
<width>32</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_36">
<item>
<widget class="QLabel" name="label_27">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Project Expansion</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="project_expansion">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Wrath Of The Lich King</string>
</property>
</item>
<item>
<property name="text">
<string>Shadowlands</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="expansion_icon">
<property name="minimumSize">
<size>
<width>32</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Project Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Project Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Game Client Path</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Project Expansion</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<item>
<layout class="QVBoxLayout" name="verticalLayout_21">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_24">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLineEdit" name="projectName">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="projectPathField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_25">
<item>
<widget class="QLineEdit" name="clientPathField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_36">
<item>
<widget class="QComboBox" name="project_expansion">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Wrath Of The Lich King</string>
</property>
</item>
<item>
<property name="text">
<string>Shadowlands</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="projectPathField_browse">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>28</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>28</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clientPathField_browse">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>28</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>28</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="expansion_icon">
<property name="minimumSize">
<size>
<width>32</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QPushButton" name="button_cancel">
<property name="geometry">
<rect>
<x>310</x>
<y>160</y>
<width>70</width>
<height>30</height>
</rect>
</property>
<property name="text">
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="button_cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton" name="button_ok">
<property name="geometry">
<rect>
<x>240</x>
<y>160</y>
<width>60</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Ok</string>
</property>
</widget>
</widget>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_ok">
<property name="text">
<string>Okay</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,5 +1,5 @@
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.h>
#include <noggit/ui/windows/projectSelection/components/ExistingProjectEnumerationComponent.hpp>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.hpp>
#include <noggit/ui/windows/projectSelection/components/RecentProjectsComponent.hpp>
#include <noggit/ui/windows/projectSelection/components/CreateProjectComponent.hpp>
#include <noggit/ui/windows/projectSelection/components/LoadProjectComponent.hpp>
#include <noggit/project/CurrentProject.hpp>
@@ -9,95 +9,94 @@
#include "ui_NoggitProjectSelectionWindow.h"
namespace Noggit::Ui::Windows
using namespace Noggit::Ui::Windows;
NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::NoggitApplication* noggit_app,
QWidget* parent)
: QMainWindow(parent)
, _ui(new ::Ui::NoggitProjectSelectionWindow)
,_noggit_application(noggit_app)
{
NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::NoggitApplication* noggitApplication, QWidget* parent)
: QMainWindow(parent)
, ui(new ::Ui::NoggitProjectSelectionWindow),
_noggitApplication(noggitApplication)
{
setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint);
setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint);
ui->setupUi(this);
_ui->setupUi(this);
ui->label->setObjectName("title");
ui->label->setStyleSheet("QLabel#title { font-size: 18px; padding: 0px; }");
_ui->label->setObjectName("title");
_ui->label->setStyleSheet("QLabel#title { font-size: 18px; padding: 0px; }");
ui->label_2->setObjectName("title");
ui->label_2->setStyleSheet("QLabel#title { font-size: 18px; padding: 0px; }");
_ui->label_2->setObjectName("title");
_ui->label_2->setStyleSheet("QLabel#title { font-size: 18px; padding: 0px; }");
_settings = new Noggit::Ui::settings(this);
_settings = new Noggit::Ui::settings(this);
_existingProjectEnumerationComponent = std::make_unique<Component::ExistingProjectEnumerationComponent>();
_createProjectComponent = std::make_unique<Component::CreateProjectComponent>();
_loadProjectComponent = std::make_unique<Component::LoadProjectComponent>();
_create_project_component = std::make_unique<Component::CreateProjectComponent>();
_load_project_component = std::make_unique<Component::LoadProjectComponent>();
_existingProjectEnumerationComponent->BuildExistingProjectList(this);
Component::RecentProjectsComponent::buildRecentProjectsList(this);
QObject::connect(ui->button_create_new_project, &QPushButton::clicked
, [=,this]
{
auto projectReference = ProjectInformation();
auto projectCreationDialog = NoggitProjectCreationDialog(projectReference,this);
projectCreationDialog.exec();
QObject::connect(_ui->button_create_new_project, &QPushButton::clicked, [=, this]
{
auto project_reference = ProjectInformation();
auto project_creation_dialog = NoggitProjectCreationDialog(project_reference, this);
project_creation_dialog.exec();
project_creation_dialog.setFixedSize(project_creation_dialog.size());
_createProjectComponent->CreateProject(this,projectReference);
_existingProjectEnumerationComponent->BuildExistingProjectList(this);
}
);
_create_project_component->createProject(this, project_reference);
Component::RecentProjectsComponent::buildRecentProjectsList(this);
}
);
QObject::connect(ui->button_open_existing_project, &QPushButton::clicked
, [=]
{
return;
}
);
QObject::connect(_ui->button_open_existing_project, &QPushButton::clicked, [=]
{
return;
}
);
QObject::connect(ui->listView, &QListView::doubleClicked
, [=]
{
auto selectedProject = _loadProjectComponent->LoadProject(this);
QObject::connect(_ui->listView, &QListView::doubleClicked, [=]
{
auto selected_project = _load_project_component->loadProject(this);
Noggit::Project::CurrentProject::initialize(selectedProject.get());
Noggit::Project::CurrentProject::initialize(selected_project.get());
projectSelectionPage = std::make_unique<Noggit::Ui::Windows::NoggitWindow>(_noggitApplication->GetConfiguration(), selectedProject);
projectSelectionPage->showMaximized();
_project_selection_page = std::make_unique<Noggit::Ui::Windows::NoggitWindow>(
_noggit_application->getConfiguration(),
selected_project);
_project_selection_page->showMaximized();
close();
}
);
}
void NoggitProjectSelectionWindow::HandleContextMenuProjectListItemDelete(std::string projectPath)
{
QMessageBox prompt;
prompt.setWindowIcon(QIcon(":/icon"));
prompt.setWindowTitle("Delete Project");
prompt.setIcon(QMessageBox::Warning);
prompt.setWindowFlags(Qt::WindowStaysOnTopHint);
prompt.setText("Deleting project will remove all saved data.");
prompt.addButton("Accept", QMessageBox::AcceptRole);
prompt.setDefaultButton(prompt.addButton("Cancel", QMessageBox::RejectRole));
prompt.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
prompt.exec();
switch (prompt.buttonRole(prompt.clickedButton()))
{
case QMessageBox::AcceptRole:
std::filesystem::remove_all(projectPath);
break;
case QMessageBox::DestructiveRole:
break;
default:
break;
}
_existingProjectEnumerationComponent->BuildExistingProjectList(this);
}
NoggitProjectSelectionWindow::~NoggitProjectSelectionWindow()
{
delete ui;
}
close();
}
);
}
void NoggitProjectSelectionWindow::handleContextMenuProjectListItemDelete(std::string const& project_path)
{
QMessageBox prompt;
prompt.setWindowIcon(QIcon(":/icon"));
prompt.setWindowTitle("Delete Project");
prompt.setIcon(QMessageBox::Warning);
prompt.setWindowFlags(Qt::WindowStaysOnTopHint);
prompt.setText("Deleting project will remove all saved data.");
prompt.addButton("Accept", QMessageBox::AcceptRole);
prompt.setDefaultButton(prompt.addButton("Cancel", QMessageBox::RejectRole));
prompt.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
prompt.exec();
switch (prompt.buttonRole(prompt.clickedButton()))
{
case QMessageBox::AcceptRole:
std::filesystem::remove_all(project_path);
break;
case QMessageBox::DestructiveRole:
default:
break;
}
Component::RecentProjectsComponent::buildRecentProjectsList(this);
}
NoggitProjectSelectionWindow::~NoggitProjectSelectionWindow()
{
delete _ui;
}

View File

@@ -2,7 +2,6 @@
#define NOGGITREDPROJECTPAGE_H
#include <QMainWindow>
#include <noggit/ui/windows/settingsPanel/SettingsPanel.h>
#include <QMenuBar>
#include <QAction>
#include <qgraphicseffect.h>
@@ -10,6 +9,8 @@
#include <noggit/application/NoggitApplication.hpp>
#include <noggit/ui/windows/noggitWindow/NoggitWindow.hpp>
#include <noggit/ui/windows/projectCreation/NoggitProjectCreationDialog.h>
#include <noggit/ui/windows/settingsPanel/SettingsPanel.h>
#include <ui_NoggitProjectSelectionWindow.h>
QT_BEGIN_NAMESPACE
namespace Ui { class NoggitProjectSelectionWindow; }
@@ -17,7 +18,7 @@ QT_END_NAMESPACE
namespace Noggit::Ui::Component
{
class ExistingProjectEnumerationComponent;
class RecentProjectsComponent;
class CreateProjectComponent;
class LoadProjectComponent;
}
@@ -32,25 +33,23 @@ namespace Noggit::Ui::Windows
class NoggitProjectSelectionWindow : public QMainWindow
{
Q_OBJECT
friend Component::ExistingProjectEnumerationComponent;
friend Component::RecentProjectsComponent;
friend Component::CreateProjectComponent;
friend Component::LoadProjectComponent;
public:
NoggitProjectSelectionWindow(Noggit::Application::NoggitApplication* noggitApplication, QWidget* parent = nullptr);
NoggitProjectSelectionWindow(Noggit::Application::NoggitApplication* noggit_app, QWidget* parent = nullptr);
~NoggitProjectSelectionWindow();
private:
::Ui::NoggitProjectSelectionWindow* ui;
Noggit::Application::NoggitApplication* _noggitApplication;
::Ui::NoggitProjectSelectionWindow* _ui;
Noggit::Application::NoggitApplication* _noggit_application;
Noggit::Ui::settings* _settings;
std::unique_ptr<Noggit::Ui::Windows::NoggitWindow> projectSelectionPage;
std::unique_ptr<Noggit::Ui::Windows::NoggitWindow> _project_selection_page;
std::unique_ptr<Component::CreateProjectComponent> _create_project_component;
std::unique_ptr<Component::LoadProjectComponent> _load_project_component;
std::unique_ptr<Component::ExistingProjectEnumerationComponent> _existingProjectEnumerationComponent;
std::unique_ptr<Component::CreateProjectComponent> _createProjectComponent;
std::unique_ptr<Component::LoadProjectComponent> _loadProjectComponent;
void HandleContextMenuProjectListItemDelete(std::string projectPath);
void handleContextMenuProjectListItemDelete(std::string const& project_path);
};
}
#endif // NOGGITREDPROJECTPAGE_H

View File

@@ -16,12 +16,12 @@
<property name="windowTitle">
<string>Noggit Red Project Selection</string>
</property>
<property name="windowIcon">
<iconset>
<normalon>:/icon</normalon>
</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<property name="windowIcon">
<iconset>
<normalon>:/icon</normalon>
</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
@@ -70,7 +70,7 @@
</font>
</property>
<property name="text">
<string>Projects</string>
<string>Recent Projects</string>
</property>
</widget>
</item>
@@ -208,10 +208,10 @@
</item>
<item row="2" column="0">
<widget class="QPushButton" name="button_open_existing_project">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>

View File

@@ -0,0 +1,54 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include "CreateProjectComponent.hpp"
#include <QList>
using namespace Noggit::Ui::Component;
void CreateProjectComponent::createProject(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent
, ProjectInformation& project_information)
{
auto application_configuration = parent->_noggit_application->getConfiguration();
auto application_project_service = Noggit::Project::ApplicationProject(application_configuration);
if (!std::filesystem::exists(project_information.ProjectPath)
|| std::filesystem::is_empty(project_information.ProjectPath))
{
application_project_service.createProject(project_information.ProjectPath,
project_information.GameClientPath,
project_information.GameClientVersion,
project_information.ProjectName);
QSettings settings;
settings.sync();
QList<QString> recent_projects;
std::size_t size = settings.beginReadArray("recent_projects");
for (int i = 0; i < size; ++i)
{
settings.setArrayIndex(i);
recent_projects.append(settings.value("project_path").toString());
}
settings.endArray();
settings.beginWriteArray("recent_projects");
settings.setArrayIndex(0);
settings.setValue("project_path", QString(project_information.ProjectPath.c_str()));
for (int i = 0; i < size; ++i)
{
settings.setArrayIndex(i + 1);
settings.setValue("project_path", recent_projects[i]);
}
settings.endArray();
settings.sync();
}
else
{
QMessageBox::critical(parent, "Error", "Selected directory is not empty.");
}
}

View File

@@ -1,8 +1,12 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#ifndef NOGGIT_COMPONENT_CREATE_PROJECT_HPP
#define NOGGIT_COMPONENT_CREATE_PROJECT_HPP
#include <noggit/project/ApplicationProject.h>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.h>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.hpp>
#include <QMessageBox>
namespace Noggit::Ui::Component
{
@@ -10,17 +14,8 @@ namespace Noggit::Ui::Component
{
friend Windows::NoggitProjectSelectionWindow;
public:
void CreateProject(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent, ProjectInformation& projectInformation)
{
auto applicationConfiguration = parent->_noggitApplication->GetConfiguration();
auto applicationProjectsFolderPath = std::filesystem::path(applicationConfiguration->ApplicationProjectPath);
auto applicationProjectService = Noggit::Project::ApplicationProject(applicationConfiguration);
auto projectPath = std::filesystem::path(applicationProjectsFolderPath / projectInformation.ProjectName);
if (!std::filesystem::exists(projectPath))
{
applicationProjectService.CreateProject(projectPath, projectInformation.GameClientPath, projectInformation.GameClientVersion, projectInformation.ProjectName);
}
}
static void createProject(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent
, ProjectInformation& project_information);
};
}

View File

@@ -1,66 +0,0 @@
#ifndef NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP
#define NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP
#include <noggit/project/ApplicationProject.h>
#include <noggit/ui/windows/projectSelection/widgets/ProjectListItem.hpp>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.h>
#include "ui_NoggitProjectSelectionWindow.h"
namespace Noggit::Ui::Component
{
class ExistingProjectEnumerationComponent
{
friend Windows::NoggitProjectSelectionWindow;
public:
void BuildExistingProjectList(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent)
{
parent->ui->listView->clear();
auto applicationConfiguration = parent->_noggitApplication->GetConfiguration();
for (const auto& dirEntry : std::filesystem::directory_iterator(applicationConfiguration->ApplicationProjectPath))
{
auto item = new QListWidgetItem(parent->ui->listView);
auto projectReader = Noggit::Project::ApplicationProjectReader();
auto project = projectReader.ReadProject(dirEntry);
if(!project.has_value())
continue;
auto projectData = Noggit::Ui::Widget::ProjectListItemData();
projectData.ProjectVersion = project->projectVersion;
projectData.ProjectDirectory = QString::fromStdString(dirEntry.path().generic_string());
projectData.ProjectName = QString::fromStdString(project->ProjectName);
projectData.ProjectLastEdited = QDateTime::currentDateTime().date().toString();
auto projectListItem = new Noggit::Ui::Widget::ProjectListItem(projectData, parent->ui->listView);
item->setData(Qt::UserRole, QVariant(projectData.ProjectName));
item->setSizeHint(projectListItem->minimumSizeHint());
QObject::connect(projectListItem, &QListWidget::customContextMenuRequested,
[=](const QPoint& pos)
{
QMenu contextMenu(projectListItem->tr("Context menu"), projectListItem);
QAction action1("Delete Project", projectListItem);
auto icon = QIcon();
icon.addPixmap(FontAwesomeIcon(FontAwesome::trash).pixmap(QSize(16, 16)));
action1.setIcon(icon);
QObject::connect(&action1, &QAction::triggered, [=]()
{
parent->HandleContextMenuProjectListItemDelete(projectData.ProjectDirectory.toStdString());
});
contextMenu.addAction(&action1);
contextMenu.exec(projectListItem->mapToGlobal(pos));
});
parent->ui->listView->setItemWidget(item, projectListItem);
}
}
};
}
#endif //NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP

View File

@@ -2,30 +2,30 @@
#define NOGGIT_COMPONENT_LOAD_PROJECT_HPP
#include <noggit/project/ApplicationProject.h>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.h>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.hpp>
namespace Noggit::Ui::Component
{
class LoadProjectComponent
{
friend Windows::NoggitProjectSelectionWindow;
public:
std::shared_ptr<Project::NoggitProject> LoadProject(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent)
{
QModelIndex index = parent->ui->listView->currentIndex();
auto applicationConfiguration = parent->_noggitApplication->GetConfiguration();
auto applicationProjectsFolderPath = std::filesystem::path(applicationConfiguration->ApplicationProjectPath);
auto projectName = index.data(Qt::UserRole).toString().toStdString();
auto applicationProjectService = Noggit::Project::ApplicationProject(applicationConfiguration);
auto projectPath = std::filesystem::path(applicationProjectsFolderPath / projectName);
auto project = applicationProjectService.LoadProject(projectPath);
class LoadProjectComponent
{
friend Windows::NoggitProjectSelectionWindow;
//This to not be static, but its hard to remove
Noggit::Application::NoggitApplication::instance()->clientData(project->ClientData);
public:
std::shared_ptr<Project::NoggitProject> loadProject(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent)
{
QModelIndex index = parent->_ui->listView->currentIndex();
auto application_configuration = parent->_noggit_application->getConfiguration();
auto application_projects_folder_path = std::filesystem::path(application_configuration->ApplicationProjectPath);
auto project_path = index.data(Qt::UserRole).toString().toStdString();
auto application_project_service = Noggit::Project::ApplicationProject(application_configuration);
auto project = application_project_service.loadProject(project_path);
return project;
}
};
//This to not be static, but its hard to remove
Noggit::Application::NoggitApplication::instance()->clientData(project->ClientData);
return project;
}
};
}
#endif //NOGGIT_COMPONENT_LOAD_PROJECT_HPP

View File

@@ -0,0 +1,67 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include "RecentProjectsComponent.hpp"
using namespace Noggit::Ui::Component;
void RecentProjectsComponent::buildRecentProjectsList(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent)
{
parent->_ui->listView->clear();
auto application_configuration = parent->_noggit_application->getConfiguration();
QSettings settings;
int size = settings.beginReadArray("recent_projects");
for (int i = 0; i < size; ++i)
{
settings.setArrayIndex(i);
std::filesystem::path project_path = settings.value("project_path").toString().toStdString().c_str();
auto item = new QListWidgetItem(parent->_ui->listView);
auto project_reader = Noggit::Project::ApplicationProjectReader();
auto project = project_reader.ReadProject(project_path);
if (!project.has_value())
continue;
auto project_data = Noggit::Ui::Widget::ProjectListItemData();
project_data.ProjectVersion = project->projectVersion;
project_data.ProjectDirectory = QString::fromStdString(project_path.generic_string());
project_data.ProjectName = QString::fromStdString(project->ProjectName);
project_data.ProjectLastEdited = QDateTime::currentDateTime().date().toString();
auto project_list_item = new Noggit::Ui::Widget::ProjectListItem(project_data, parent->_ui->listView);
item->setData(Qt::UserRole, QVariant(QString(project_path.c_str())));
item->setSizeHint(project_list_item->minimumSizeHint());
QObject::connect(project_list_item, &QListWidget::customContextMenuRequested,
[=](const QPoint& pos)
{
QMenu context_menu(project_list_item->tr("Context menu"), project_list_item);
QAction action_1("Delete Project", project_list_item);
auto icon = QIcon();
icon.addPixmap(FontAwesomeIcon(FontAwesome::trash).pixmap(QSize(16, 16)));
action_1.setIcon(icon);
QObject::connect(&action_1, &QAction::triggered, [=]()
{
parent->handleContextMenuProjectListItemDelete(project_data.ProjectDirectory.toStdString());
});
context_menu.addAction(&action_1);
context_menu.exec(project_list_item->mapToGlobal(pos));
});
parent->_ui->listView->setItemWidget(item, project_list_item);
}
settings.endArray();
}

View File

@@ -0,0 +1,22 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#ifndef NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP
#define NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP
#include <noggit/project/ApplicationProject.h>
#include <noggit/ui/windows/projectSelection/widgets/ProjectListItem.hpp>
#include <noggit/ui/windows/projectSelection/NoggitProjectSelectionWindow.hpp>
#include "ui_NoggitProjectSelectionWindow.h"
namespace Noggit::Ui::Component
{
class RecentProjectsComponent
{
friend Windows::NoggitProjectSelectionWindow;
public:
static void buildRecentProjectsList(Noggit::Ui::Windows::NoggitProjectSelectionWindow* parent);
};
}
#endif //NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP

View File

@@ -68,17 +68,17 @@ namespace Noggit
}
);
connect(ui->projectPathField, &QLineEdit::textChanged, [&](QString value)
connect(ui->clientPathField, &QLineEdit::textChanged, [&](QString value)
{
_settings->setValue("project/path", value);
}
);
connect(ui->projectPathField_browse, &QPushButton::clicked, [=]
connect(ui->clientPathField_browse, &QPushButton::clicked, [=]
{
auto result(QFileDialog::getExistingDirectory(
nullptr, "Project Path", ui->projectPathField->text()));
nullptr, "Project Path", ui->clientPathField->text()));
if (!result.isNull())
{
@@ -87,7 +87,7 @@ namespace Noggit
result += "/";
}
ui->projectPathField->setText(result);
ui->clientPathField->setText(result);
}
}
);
@@ -206,7 +206,7 @@ namespace Noggit
void settings::discard_changes()
{
ui->gamePathField->setText(_settings->value("project/game_path").toString());
ui->projectPathField->setText(_settings->value("project/path").toString());
ui->clientPathField->setText(_settings->value("project/path").toString());
ui->importPathField->setText(_settings->value("project/import_file", "import.txt").toString());
ui->wmvLogPathField->setText(_settings->value("project/wmv_log_file").toString());
ui->viewDistanceField->setValue(_settings->value("view_distance", 1000.f).toFloat());
@@ -270,7 +270,7 @@ namespace Noggit
void settings::save_changes()
{
_settings->setValue("project/game_path", ui->gamePathField->text());
_settings->setValue("project/path", ui->projectPathField->text());
_settings->setValue("project/path", ui->clientPathField->text());
_settings->setValue("project/import_file", ui->importPathField->text());
_settings->setValue("project/wmv_log_file", ui->wmvLogPathField->text());
_settings->setValue("farZ", ui->farZField->value());

View File

@@ -160,10 +160,10 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="projectPathField"/>
<widget class="QLineEdit" name="clientPathField"/>
</item>
<item>
<widget class="QPushButton" name="projectPathField_browse">
<widget class="QPushButton" name="clientPathField_browse">
<property name="text">
<string>Browse</string>
</property>