various changes around projects
-we can now pin projects, that is then save to the noggitproj file -book marks are now saved to noggitproj file instead of a standalone file
This commit is contained in:
@@ -1073,17 +1073,19 @@ void MapView::setupFileMenu()
|
||||
ADD_ACTION ( file_menu
|
||||
, "Add bookmark"
|
||||
, Qt::Key_F5
|
||||
, [this]
|
||||
{
|
||||
std::ofstream f ("bookmarks.txt", std::ios_base::app);
|
||||
f << _world->getMapID() << " "
|
||||
<< _camera.position.x << " "
|
||||
<< _camera.position.y << " "
|
||||
<< _camera.position.z << " "
|
||||
<< _camera.yaw()._ << " "
|
||||
<< _camera.pitch()._ << " "
|
||||
<< _world->getAreaID (_camera.position) << std::endl;
|
||||
}
|
||||
, [this]
|
||||
{
|
||||
|
||||
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));
|
||||
|
||||
_project->CreateBookmark(bookmark);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
ADD_ACTION ( file_menu
|
||||
@@ -2526,6 +2528,7 @@ MapView::MapView( math::degrees camera_yaw0
|
||||
, math::degrees camera_pitch0
|
||||
, glm::vec3 camera_pos
|
||||
, Noggit::Ui::Windows::NoggitWindow* NoggitWindow
|
||||
, std::shared_ptr<Noggit::Project::NoggitProject> Project
|
||||
, std::unique_ptr<World> world
|
||||
, uid_fix_mode uid_fix
|
||||
, bool from_bookmark
|
||||
@@ -2547,7 +2550,8 @@ MapView::MapView( math::degrees camera_yaw0
|
||||
, _status_culling (new QLabel (this))
|
||||
, _texBrush{new OpenGL::texture{}}
|
||||
, _transform_gizmo(Noggit::Ui::Tools::ViewportGizmo::GizmoContext::MAP_VIEW)
|
||||
, _tablet_manager(Noggit::TabletManager::instance())
|
||||
, _tablet_manager(Noggit::TabletManager::instance()),
|
||||
_project(Project)
|
||||
{
|
||||
setWindowTitle ("Noggit Studio - " STRPRODUCTVER);
|
||||
setFocusPolicy (Qt::StrongFocus);
|
||||
|
||||
@@ -188,7 +188,7 @@ private:
|
||||
// Vars for the ground editing toggle mode store the status of some
|
||||
// view settings when the ground editing mode is switched on to
|
||||
// restore them if switch back again
|
||||
|
||||
std::shared_ptr<Noggit::Project::NoggitProject> _project;
|
||||
bool alloff = true;
|
||||
bool alloff_models = false;
|
||||
bool alloff_doodads = false;
|
||||
@@ -235,6 +235,7 @@ public:
|
||||
, math::degrees av0
|
||||
, glm::vec3 camera_pos
|
||||
, Noggit::Ui::Windows::NoggitWindow*
|
||||
, std::shared_ptr<Noggit::Project::NoggitProject> Project
|
||||
, std::unique_ptr<World>
|
||||
, uid_fix_mode uid_fix = uid_fix_mode::none
|
||||
, bool from_bookmark = false
|
||||
|
||||
0
src/noggit/project/ApplicationProject.cpp
Normal file
0
src/noggit/project/ApplicationProject.cpp
Normal file
@@ -22,6 +22,10 @@
|
||||
#include <QString>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "ApplicationProjectReader.h"
|
||||
#include "ApplicationProjectWriter.h"
|
||||
|
||||
namespace Noggit::Project
|
||||
{
|
||||
@@ -38,86 +42,101 @@ namespace Noggit::Project
|
||||
SL
|
||||
};
|
||||
|
||||
struct Client
|
||||
struct ClientVersionFactory
|
||||
{
|
||||
std::string ClientPath;
|
||||
std::string ClientVersion;
|
||||
static ProjectVersion MapToEnumVersion(std::string const& projectVersion)
|
||||
{
|
||||
if (projectVersion == "Wrath Of The Lich King")
|
||||
return ProjectVersion::WOTLK;
|
||||
if (projectVersion == "Shadowlands")
|
||||
return ProjectVersion::SL;
|
||||
}
|
||||
|
||||
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 Project
|
||||
struct NoggitProjectBookmarkMap
|
||||
{
|
||||
std::string ProjectName;
|
||||
Client Client;
|
||||
int MapID;
|
||||
std::string Name;
|
||||
glm::vec3 Position;
|
||||
float CameraYaw;
|
||||
float CameraPitch;
|
||||
};
|
||||
|
||||
struct NoggitProjectPinnedMap
|
||||
{
|
||||
int MapId;
|
||||
std::string MapName;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class ApplicationProjectReader
|
||||
{
|
||||
public:
|
||||
ApplicationProjectReader() = default;
|
||||
|
||||
std::optional<NoggitProject> ReadProject(std::filesystem::path const& projectPath)
|
||||
NoggitProject()
|
||||
{
|
||||
for (const auto& entry : std::filesystem::directory_iterator(projectPath))
|
||||
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)
|
||||
{
|
||||
if(entry.path().extension() == std::string(".noggitproj"))
|
||||
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)
|
||||
{
|
||||
QFile inputFile(QString::fromStdString(entry.path().generic_string()));
|
||||
inputFile.open(QIODevice::ReadOnly);
|
||||
return pinnedMap.MapId == mapId;
|
||||
}),
|
||||
PinnedMaps.end());
|
||||
|
||||
auto document = QJsonDocument().fromJson(inputFile.readAll());
|
||||
auto root = document.object();
|
||||
|
||||
auto project = NoggitProject();
|
||||
if (root.contains("Project") && root["Project"].isObject())
|
||||
{
|
||||
auto projectConfiguration = root["Project"].toObject();
|
||||
if (projectConfiguration.contains("ProjectName"))
|
||||
project.ProjectName = projectConfiguration["ProjectName"].toString().toStdString();
|
||||
|
||||
if (projectConfiguration.contains("Client") && projectConfiguration["Client"].isObject())
|
||||
{
|
||||
auto projectClientConfiguration = projectConfiguration["Client"].toObject();
|
||||
|
||||
if (projectClientConfiguration.contains("ClientPath"))
|
||||
{
|
||||
project.ClientPath = projectClientConfiguration["ClientPath"].toString().toStdString();
|
||||
}
|
||||
|
||||
if (projectClientConfiguration.contains("ClientVersion"))
|
||||
{
|
||||
auto clientVersion = projectClientConfiguration["ClientVersion"].toString().toStdString();
|
||||
|
||||
auto clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
|
||||
if (clientVersion == std::string("Shadowlands"))
|
||||
{
|
||||
clientVersionEnum = Noggit::Project::ProjectVersion::SL;
|
||||
}
|
||||
|
||||
if (clientVersion == std::string("Wrath Of The Lich King"))
|
||||
{
|
||||
clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
|
||||
}
|
||||
|
||||
project.ProjectVersion = clientVersionEnum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
_projectWriter->SaveProject(this, std::filesystem::path(ProjectPath));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -142,33 +161,13 @@ namespace Noggit::Project
|
||||
std::filesystem::create_directory(workspaceDirectory);
|
||||
std::filesystem::create_directory(projectPath / std::string("export"));
|
||||
|
||||
auto project = Project();
|
||||
auto project = NoggitProject();
|
||||
project.ProjectName = projectName;
|
||||
project.Client = Client();
|
||||
project.Client.ClientVersion = clientVersion;
|
||||
project.Client.ClientPath = clientPath.generic_string();
|
||||
project.ProjectVersion = ClientVersionFactory::MapToEnumVersion(clientVersion);
|
||||
project.ClientPath = clientPath.generic_string();
|
||||
|
||||
auto projectConfigurationFilePath = (projectPath / (projectName + std::string(".noggitproj")));
|
||||
auto projectConfigurationFile = QFile(QString::fromStdString(projectConfigurationFilePath.generic_string()));
|
||||
projectConfigurationFile.open(QIODevice::WriteOnly);
|
||||
|
||||
auto document = QJsonDocument();
|
||||
auto root = QJsonObject();
|
||||
auto projectConfiguration = QJsonObject();
|
||||
|
||||
auto clientConfiguration = QJsonObject();
|
||||
|
||||
clientConfiguration.insert("ClientPath", project.Client.ClientPath.c_str());
|
||||
clientConfiguration.insert("ClientVersion", project.Client.ClientVersion.c_str());
|
||||
|
||||
projectConfiguration.insert("ProjectName", project.ProjectName.c_str());
|
||||
projectConfiguration.insert("Client", clientConfiguration);
|
||||
|
||||
root.insert("Project", projectConfiguration);
|
||||
document.setObject(root);
|
||||
|
||||
projectConfigurationFile.write(document.toJson(QJsonDocument::Indented));
|
||||
projectConfigurationFile.close();
|
||||
auto projectWriter = ApplicationProjectWriter();
|
||||
projectWriter.SaveProject(&project,projectPath);
|
||||
|
||||
auto listOfDbcPaths = std::vector<std::string>
|
||||
{
|
||||
@@ -185,7 +184,7 @@ namespace Noggit::Project
|
||||
"DBFilesClient/LiquidType.dbc",
|
||||
};
|
||||
|
||||
if (project.Client.ClientVersion == "Wrath Of The Lich King")
|
||||
if (project.ProjectVersion == ProjectVersion::WOTLK)
|
||||
{
|
||||
auto clientData = BlizzardArchive::ClientData(clientPath.generic_string(), BlizzardArchive::ClientVersion::WOTLK,
|
||||
BlizzardArchive::Locale::AUTO, workspaceDirectory.generic_string());
|
||||
@@ -226,7 +225,7 @@ namespace Noggit::Project
|
||||
//"DBFilesClient/LiquidType.db2",
|
||||
};
|
||||
|
||||
if (project.Client.ClientVersion == "Shadowlands")
|
||||
if (project.ProjectVersion == ProjectVersion::SL)
|
||||
{
|
||||
auto clientData = BlizzardArchive::ClientData(clientPath.generic_string(), BlizzardArchive::ClientVersion::SL,
|
||||
BlizzardArchive::Locale::enUS, std::string(""));
|
||||
@@ -289,4 +288,4 @@ namespace Noggit::Project
|
||||
return std::make_shared<NoggitProject>(project.value());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
104
src/noggit/project/ApplicationProjectReader.cpp
Normal file
104
src/noggit/project/ApplicationProjectReader.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <noggit/project/ApplicationProjectReader.h>
|
||||
#include <noggit/project/ApplicationProject.h>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QFile>
|
||||
#include <filesystem>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QString>
|
||||
#include <chrono>
|
||||
#include <QJsonArray>
|
||||
|
||||
namespace Noggit::Project
|
||||
{
|
||||
std::optional<NoggitProject> ApplicationProjectReader::ReadProject(std::filesystem::path const& projectPath)
|
||||
{
|
||||
for (const auto& entry : std::filesystem::directory_iterator(projectPath))
|
||||
{
|
||||
if (entry.path().extension() == std::string(".noggitproj"))
|
||||
{
|
||||
QFile inputFile(QString::fromStdString(entry.path().generic_string()));
|
||||
inputFile.open(QIODevice::ReadOnly);
|
||||
|
||||
auto document = QJsonDocument().fromJson(inputFile.readAll());
|
||||
auto root = document.object();
|
||||
|
||||
auto project = NoggitProject();
|
||||
project.ProjectPath = projectPath.generic_string();
|
||||
if (root.contains("Project") && root["Project"].isObject())
|
||||
{
|
||||
auto projectConfiguration = root["Project"].toObject();
|
||||
if (projectConfiguration.contains("ProjectName"))
|
||||
project.ProjectName = projectConfiguration["ProjectName"].toString().toStdString();
|
||||
|
||||
if (projectConfiguration.contains("Bookmarks") && projectConfiguration["Bookmarks"].isArray())
|
||||
{
|
||||
auto projectBookmarks = projectConfiguration["Bookmarks"].toArray();
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
project.Bookmarks.push_back(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
if (projectConfiguration.contains("PinnedMaps") && projectConfiguration["PinnedMaps"].isArray())
|
||||
{
|
||||
auto projectPinnedMaps = projectConfiguration["PinnedMaps"].toArray();
|
||||
|
||||
for(auto const &jsonPinnedMap : projectPinnedMaps)
|
||||
{
|
||||
auto pinnedMap = NoggitProjectPinnedMap();
|
||||
pinnedMap.MapId = jsonPinnedMap.toObject().value("MapId").toInt();
|
||||
pinnedMap.MapName = jsonPinnedMap.toObject().value("MapName").toString().toStdString();
|
||||
project.PinnedMaps.push_back(pinnedMap);
|
||||
}
|
||||
}
|
||||
|
||||
if (projectConfiguration.contains("Client") && projectConfiguration["Client"].isObject())
|
||||
{
|
||||
auto projectClientConfiguration = projectConfiguration["Client"].toObject();
|
||||
|
||||
if (projectClientConfiguration.contains("ClientPath"))
|
||||
{
|
||||
project.ClientPath = projectClientConfiguration["ClientPath"].toString().toStdString();
|
||||
}
|
||||
|
||||
if (projectClientConfiguration.contains("ClientVersion"))
|
||||
{
|
||||
auto clientVersion = projectClientConfiguration["ClientVersion"].toString().toStdString();
|
||||
|
||||
auto clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
|
||||
if (clientVersion == std::string("Shadowlands"))
|
||||
{
|
||||
clientVersionEnum = Noggit::Project::ProjectVersion::SL;
|
||||
}
|
||||
|
||||
if (clientVersion == std::string("Wrath Of The Lich King"))
|
||||
{
|
||||
clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
|
||||
}
|
||||
|
||||
project.ProjectVersion = clientVersionEnum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
19
src/noggit/project/ApplicationProjectReader.h
Normal file
19
src/noggit/project/ApplicationProjectReader.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef NOGGIT_APPLICATION_PROJECT_READER_HPP
|
||||
#define NOGGIT_APPLICATION_PROJECT_READER_HPP
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace Noggit::Project
|
||||
{
|
||||
class NoggitProject;
|
||||
|
||||
class ApplicationProjectReader
|
||||
{
|
||||
public:
|
||||
ApplicationProjectReader() = default;
|
||||
|
||||
std::optional<NoggitProject> ReadProject(std::filesystem::path const& projectPath);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //NOGGIT_APPLICATION_PROJECT_READER_HPP
|
||||
65
src/noggit/project/ApplicationProjectWriter.cpp
Normal file
65
src/noggit/project/ApplicationProjectWriter.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <noggit/project/ApplicationProjectWriter.h>
|
||||
#include <noggit/project/ApplicationProject.h>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QFile>
|
||||
#include <filesystem>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QString>
|
||||
#include <chrono>
|
||||
#include <QJsonArray>
|
||||
|
||||
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);
|
||||
|
||||
auto document = QJsonDocument();
|
||||
auto root = QJsonObject();
|
||||
auto projectConfiguration = QJsonObject();
|
||||
auto clientConfiguration = QJsonObject();
|
||||
|
||||
clientConfiguration.insert("ClientPath", project->ClientPath.c_str());
|
||||
clientConfiguration.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 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 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);
|
||||
}
|
||||
|
||||
projectConfiguration.insert("PinnedMaps", pinnedMaps);
|
||||
projectConfiguration.insert("Bookmarks", bookmarks);
|
||||
projectConfiguration.insert("ProjectName", project->ProjectName.c_str());
|
||||
projectConfiguration.insert("Client", clientConfiguration);
|
||||
|
||||
root.insert("Project", projectConfiguration);
|
||||
document.setObject(root);
|
||||
|
||||
projectConfigurationFile.write(document.toJson(QJsonDocument::Indented));
|
||||
projectConfigurationFile.close();
|
||||
}
|
||||
}
|
||||
19
src/noggit/project/ApplicationProjectWriter.h
Normal file
19
src/noggit/project/ApplicationProjectWriter.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef NOGGIT_APPLICATION_PROJECT_WRITER_HPP
|
||||
#define NOGGIT_APPLICATION_PROJECT_WRITER_HPP
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace Noggit::Project
|
||||
{
|
||||
class NoggitProject;
|
||||
|
||||
class ApplicationProjectWriter
|
||||
{
|
||||
public:
|
||||
ApplicationProjectWriter() = default;
|
||||
|
||||
void SaveProject(NoggitProject* project, std::filesystem::path const& projectPath);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //NOGGIT_APPLICATION_PROJECT_WRITER_HPP
|
||||
@@ -66,7 +66,6 @@ namespace Noggit::Ui::Windows
|
||||
}
|
||||
|
||||
setCentralWidget (_null_widget);
|
||||
createBookmarkList();
|
||||
|
||||
_about = new about(this);
|
||||
_settings = new settings(this);
|
||||
@@ -178,7 +177,7 @@ namespace Noggit::Ui::Windows
|
||||
)
|
||||
{
|
||||
_map_creation_wizard->destroyFakeWorld();
|
||||
_map_view = (new MapView (camera_yaw, camera_pitch, pos, this, std::move (_world), uid_fix, from_bookmark));
|
||||
_map_view = (new MapView (camera_yaw, camera_pitch, pos, this,_project, std::move (_world), uid_fix, from_bookmark));
|
||||
connect(_map_view, &MapView::uid_fix_failed, [this]() { prompt_uid_fix_failure(); });
|
||||
connect(_settings, &settings::saved, [this]() { if (_map_view) _map_view->onSettingsSave(); });
|
||||
|
||||
@@ -238,31 +237,31 @@ namespace Noggit::Ui::Windows
|
||||
_buildMapListComponent->BuildMapList(this);
|
||||
|
||||
qulonglong bookmark_index (0);
|
||||
for (auto entry : mBookmarks)
|
||||
for (auto entry : _project->Bookmarks)
|
||||
{
|
||||
auto item (new QListWidgetItem (entry.name.c_str(), bookmarks_table));
|
||||
auto item (new QListWidgetItem (entry.Name.c_str(), bookmarks_table));
|
||||
item->setData (Qt::UserRole, QVariant (bookmark_index++));
|
||||
}
|
||||
|
||||
QObject::connect ( bookmarks_table, &QListWidget::itemDoubleClicked
|
||||
, [this] (QListWidgetItem* item)
|
||||
{
|
||||
auto& entry (mBookmarks.at (item->data (Qt::UserRole).toInt()));
|
||||
|
||||
auto& entry (_project->Bookmarks.at (item->data (Qt::UserRole).toInt()));
|
||||
|
||||
_world.reset();
|
||||
|
||||
for (DBCFile::Iterator it = gMapDB.begin(); it != gMapDB.end(); ++it)
|
||||
{
|
||||
if (it->getInt(MapDB::MapID) == entry.mapID)
|
||||
if (it->getInt(MapDB::MapID) == entry.MapID)
|
||||
{
|
||||
_world = std::make_unique<World> (it->getString(MapDB::InternalName),
|
||||
entry.mapID, Noggit::NoggitRenderContext::MAP_VIEW);
|
||||
check_uid_then_enter_map ( entry.pos
|
||||
, math::degrees (entry.camera_pitch)
|
||||
, math::degrees (entry.camera_yaw)
|
||||
entry.MapID, Noggit::NoggitRenderContext::MAP_VIEW);
|
||||
check_uid_then_enter_map ( entry.Position
|
||||
, math::degrees (entry.CameraPitch)
|
||||
, math::degrees (entry.CameraYaw)
|
||||
, true
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -309,37 +308,6 @@ namespace Noggit::Ui::Windows
|
||||
_minimap->adjustSize();
|
||||
}
|
||||
|
||||
void NoggitWindow::createBookmarkList()
|
||||
{
|
||||
mBookmarks.clear();
|
||||
|
||||
std::ifstream f("bookmarks.txt");
|
||||
if (!f.is_open())
|
||||
{
|
||||
LogDebug << "No bookmarks file." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string basename;
|
||||
std::size_t areaID;
|
||||
BookmarkEntry b;
|
||||
int mapID = -1;
|
||||
while (f >> mapID >> b.pos.x >> b.pos.y >> b.pos.z >> b.camera_yaw >> b.camera_pitch >> areaID)
|
||||
{
|
||||
if (mapID == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::stringstream temp;
|
||||
temp << MapDB::getMapName(mapID) << ": " << AreaDB::getAreaName(areaID);
|
||||
b.name = temp.str();
|
||||
b.mapID = mapID;
|
||||
mBookmarks.push_back(b);
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
|
||||
void NoggitWindow::closeEvent (QCloseEvent* event)
|
||||
{
|
||||
if (map_loaded)
|
||||
@@ -353,6 +321,18 @@ namespace Noggit::Ui::Windows
|
||||
}
|
||||
}
|
||||
|
||||
void NoggitWindow::HandleEventMapListContextMenuPinMap(int mapId, std::string MapName)
|
||||
{
|
||||
_project->PinMap(mapId, MapName);
|
||||
_buildMapListComponent->BuildMapList(this);
|
||||
}
|
||||
|
||||
void NoggitWindow::HandleEventMapListContextMenuUnpinMap(int mapId)
|
||||
{
|
||||
_project->UnpinMap(mapId);
|
||||
_buildMapListComponent->BuildMapList(this);
|
||||
}
|
||||
|
||||
void NoggitWindow::prompt_exit(QCloseEvent* event)
|
||||
{
|
||||
emit exit_prompt_opened();
|
||||
|
||||
@@ -23,7 +23,6 @@ namespace Noggit::Ui
|
||||
class minimap_widget;
|
||||
class settings;
|
||||
class about;
|
||||
|
||||
}
|
||||
|
||||
namespace Noggit::Ui::Windows
|
||||
@@ -48,10 +47,16 @@ namespace Noggit::Ui::Windows
|
||||
void exit_prompt_opened();
|
||||
void map_selected(int map_id);
|
||||
|
||||
|
||||
private:
|
||||
std::unique_ptr<Component::BuildMapListComponent> _buildMapListComponent;
|
||||
std::shared_ptr<Application::NoggitApplicationConfiguration> _applicationConfiguration;
|
||||
std::shared_ptr<Project::NoggitProject> _project;
|
||||
std::shared_ptr<Application::NoggitApplicationConfiguration> _applicationConfiguration;
|
||||
std::shared_ptr<Project::NoggitProject> _project;
|
||||
|
||||
|
||||
void HandleEventMapListContextMenuPinMap(int mapId, std::string MapName);
|
||||
void HandleEventMapListContextMenuUnpinMap(int mapId);
|
||||
|
||||
|
||||
void loadMap (int mapID);
|
||||
|
||||
@@ -68,19 +73,6 @@ namespace Noggit::Ui::Windows
|
||||
, bool from_bookmark = false
|
||||
);
|
||||
|
||||
void createBookmarkList();
|
||||
|
||||
struct BookmarkEntry
|
||||
{
|
||||
int mapID;
|
||||
std::string name;
|
||||
glm::vec3 pos;
|
||||
float camera_yaw;
|
||||
float camera_pitch;
|
||||
};
|
||||
|
||||
std::vector<BookmarkEntry> mBookmarks;
|
||||
|
||||
minimap_widget* _minimap;
|
||||
settings* _settings;
|
||||
about* _about;
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include <noggit/ui/windows/noggitWindow/components/BuildMapListComponent.hpp>
|
||||
#include <noggit/ui/windows/noggitWindow/widgets/MapListItem.hpp>
|
||||
#include <noggit/ui/windows/noggitWindow/NoggitWindow.hpp>
|
||||
#include <QMenuBar>
|
||||
#include <QAction>
|
||||
#include <QObject>
|
||||
|
||||
using namespace Noggit::Ui::Component;
|
||||
|
||||
@@ -38,8 +41,16 @@ void BuildMapListComponent::BuildMapList(Noggit::Ui::Windows::NoggitWindow* pare
|
||||
if (mapListData.MapTypeId < 0 || mapListData.MapTypeId > 5 || !World::IsEditableWorld(record))
|
||||
continue;
|
||||
|
||||
if (mapListData.Pinned)
|
||||
auto projectPinnedMaps = parent->_project->PinnedMaps;
|
||||
|
||||
auto pinnedMapFound = std::find_if(std::begin(projectPinnedMaps), std::end(projectPinnedMaps), [&](Project::NoggitProjectPinnedMap pinnedMap)
|
||||
{
|
||||
return pinnedMap.MapId == mapListData.MapId;
|
||||
});
|
||||
|
||||
if (pinnedMapFound != std::end(projectPinnedMaps))
|
||||
{
|
||||
mapListData.Pinned = true;
|
||||
pinnedMaps.push_back(mapListData);
|
||||
}
|
||||
else
|
||||
@@ -54,13 +65,53 @@ void BuildMapListComponent::BuildMapList(Noggit::Ui::Windows::NoggitWindow* pare
|
||||
{
|
||||
auto mapListItem = new Widget::MapListItem(map, parent->_continents_table);
|
||||
auto item = new QListWidgetItem(parent->_continents_table);
|
||||
|
||||
if (map.Pinned)
|
||||
{
|
||||
QObject::connect(mapListItem, &QListWidget::customContextMenuRequested,
|
||||
[=](const QPoint& pos)
|
||||
{
|
||||
QMenu contextMenu(mapListItem->tr("Context menu"), mapListItem);
|
||||
|
||||
QAction action1("Unpin Map", mapListItem);
|
||||
auto icon = QIcon();
|
||||
icon.addPixmap(FontAwesomeIcon(FontAwesome::star).pixmap(QSize(16, 16)));
|
||||
action1.setIcon(icon);
|
||||
|
||||
QObject::connect(&action1, &QAction::triggered, [=]()
|
||||
{
|
||||
parent->HandleEventMapListContextMenuUnpinMap(map.MapId);
|
||||
});
|
||||
|
||||
contextMenu.addAction(&action1);
|
||||
contextMenu.exec(mapListItem->mapToGlobal(pos));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
QObject::connect(mapListItem, &QListWidget::customContextMenuRequested,
|
||||
[=](const QPoint& pos)
|
||||
{
|
||||
QMenu contextMenu(mapListItem->tr("Context menu"), mapListItem);
|
||||
QAction action1("Pin Map", mapListItem);
|
||||
auto icon = QIcon();
|
||||
icon.addPixmap(FontAwesomeIcon(FontAwesome::star).pixmap(QSize(16, 16)));
|
||||
action1.setIcon(icon);
|
||||
|
||||
QObject::connect(&action1, &QAction::triggered, [=]()
|
||||
{
|
||||
parent->HandleEventMapListContextMenuPinMap(map.MapId, map.MapName.toStdString());
|
||||
});
|
||||
|
||||
contextMenu.addAction(&action1);
|
||||
contextMenu.exec(mapListItem->mapToGlobal(pos));
|
||||
});
|
||||
}
|
||||
|
||||
item->setSizeHint(mapListItem->minimumSizeHint());
|
||||
item->setData(Qt::UserRole, QVariant(map.MapId));
|
||||
parent->_continents_table->setItemWidget(item, mapListItem);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
parent->_project->ClientDatabase->UnloadTable(table);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef NOGGIT_COMPONENT_BUILD_MAP_LIST_HPP
|
||||
#define NOGGIT_COMPONENT_BUILD_MAP_LIST_HPP
|
||||
|
||||
#include <noggit/ui/tools/NodeEditor/Nodes/Data/Image/ImageMaskRandomPointsNode.hpp>
|
||||
|
||||
namespace Noggit::Ui::Windows
|
||||
{
|
||||
class NoggitWindow;
|
||||
@@ -13,6 +15,10 @@ namespace Noggit::Ui::Component
|
||||
friend class Noggit::Ui::Windows::NoggitWindow;
|
||||
public:
|
||||
void BuildMapList(Noggit::Ui::Windows::NoggitWindow* parent);
|
||||
|
||||
private:
|
||||
void BuildPinMapContextMenu(const QPoint& pos);
|
||||
void BuildUnPinMapContextMenu(const QPoint& pos);
|
||||
};
|
||||
}
|
||||
#endif //NOGGIT_COMPONENT_BUILD_MAP_LIST_HPP
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <QListWidget>
|
||||
#include <noggit/ui/windows/noggitWindow/widgets/MapListItem.hpp>
|
||||
#include <noggit/ui/FontAwesome.hpp>
|
||||
|
||||
@@ -95,6 +96,8 @@ namespace Noggit::Ui::Widget
|
||||
layout.addWidget(map_pinned_label);
|
||||
}
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
layout.addWidget(project_version_icon);
|
||||
layout.addWidget(project_name_label);
|
||||
layout.addWidget(project_directory_label);
|
||||
|
||||
Reference in New Issue
Block a user