save and load palettes
This commit is contained in:
@@ -603,7 +603,7 @@ void MapView::setupTexturePainterUi()
|
||||
/* Texture Browser */
|
||||
|
||||
// Dock
|
||||
_texture_browser_dock = new QDockWidget("Texture palette", this);
|
||||
_texture_browser_dock = new QDockWidget("Texture Browser", this);
|
||||
_texture_browser_dock->setFeatures(QDockWidget::DockWidgetMovable
|
||||
| QDockWidget::DockWidgetFloatable
|
||||
| QDockWidget::DockWidgetClosable);
|
||||
@@ -662,7 +662,7 @@ void MapView::setupTexturePainterUi()
|
||||
|
||||
|
||||
/* Texture Palette Small */
|
||||
_texture_palette_small = new Noggit::Ui::texture_palette_small(this);
|
||||
_texture_palette_small = new Noggit::Ui::texture_palette_small(_project, _world->getMapID(), this);
|
||||
|
||||
// Dock
|
||||
_texture_palette_dock = new QDockWidget("Texture Palette", this);
|
||||
@@ -855,7 +855,7 @@ void MapView::setupObjectEditorUi()
|
||||
_area_selection = new QRubberBand(QRubberBand::Rectangle, this);
|
||||
|
||||
/* Object Palette */
|
||||
_object_palette = new Noggit::Ui::ObjectPalette(this, this);
|
||||
_object_palette = new Noggit::Ui::ObjectPalette(this, _project, this);
|
||||
_object_palette->hide();
|
||||
|
||||
// Dock
|
||||
@@ -2046,9 +2046,9 @@ void MapView::setupViewMenu()
|
||||
|
||||
ADD_TOGGLE (view_menu, "Detail infos", Qt::Key_F8, _show_detail_info_window);
|
||||
|
||||
ADD_TOGGLE (view_menu, "Texture palette", Qt::Key_X, _show_texture_palette_window);
|
||||
ADD_TOGGLE (view_menu, "Texture Browser", Qt::Key_X, _show_texture_palette_window);
|
||||
|
||||
ADD_TOGGLE_NS(view_menu, "Small texture palette", _show_texture_palette_small_window);
|
||||
ADD_TOGGLE_NS(view_menu, "Texture palette", _show_texture_palette_small_window);
|
||||
|
||||
addHotkey( Qt::Key_H
|
||||
, MOD_none
|
||||
@@ -4460,7 +4460,7 @@ void MapView::draw_map()
|
||||
case editing_mode::ground:
|
||||
radius = terrainTool->brushRadius();
|
||||
inner_radius = terrainTool->innerRadius();
|
||||
if((terrainTool->_edit_type != eTerrainType_Vertex || terrainTool->_edit_type != eTerrainType_Script) && terrainTool->getImageMaskSelector()->isEnabled())
|
||||
if(terrainTool->_edit_type != eTerrainType_Vertex || terrainTool->_edit_type != eTerrainType_Script && terrainTool->getImageMaskSelector()->isEnabled())
|
||||
_cursorType = CursorType::STAMP;
|
||||
break;
|
||||
case editing_mode::flatten_blur:
|
||||
|
||||
@@ -84,6 +84,18 @@ namespace Noggit::Project
|
||||
std::string MapName;
|
||||
};
|
||||
|
||||
struct NoggitProjectObjectPalette
|
||||
{
|
||||
int MapId;
|
||||
std::vector<std::string> Filepaths;
|
||||
};
|
||||
|
||||
struct NoggitProjectTexturePalette
|
||||
{
|
||||
int MapId;
|
||||
std::vector<std::string> Filepaths;
|
||||
};
|
||||
|
||||
class NoggitProject
|
||||
{
|
||||
std::shared_ptr<ApplicationProjectWriter> _projectWriter;
|
||||
@@ -96,11 +108,15 @@ namespace Noggit::Project
|
||||
std::vector<NoggitProjectBookmarkMap> Bookmarks;
|
||||
std::shared_ptr<BlizzardDatabaseLib::BlizzardDatabase> ClientDatabase;
|
||||
std::shared_ptr<BlizzardArchive::ClientData> ClientData;
|
||||
std::vector<NoggitProjectObjectPalette> ObjectPalettes;
|
||||
std::vector<NoggitProjectTexturePalette> TexturePalettes;
|
||||
|
||||
NoggitProject()
|
||||
{
|
||||
PinnedMaps = std::vector<NoggitProjectPinnedMap>();
|
||||
Bookmarks = std::vector<NoggitProjectBookmarkMap>();
|
||||
ObjectPalettes = std::vector<NoggitProjectObjectPalette>();
|
||||
TexturePalettes = std::vector<NoggitProjectTexturePalette>();
|
||||
_projectWriter = std::make_shared<ApplicationProjectWriter>();
|
||||
}
|
||||
|
||||
@@ -147,6 +163,35 @@ namespace Noggit::Project
|
||||
|
||||
_projectWriter->saveProject(this, std::filesystem::path(ProjectPath));
|
||||
}
|
||||
|
||||
void saveTexturePalette(const NoggitProjectTexturePalette& new_texture_palette)
|
||||
{
|
||||
TexturePalettes.erase(std::remove_if(TexturePalettes.begin(), TexturePalettes.end(),
|
||||
[=](NoggitProjectTexturePalette texture_palette)
|
||||
{
|
||||
return texture_palette.MapId == new_texture_palette.MapId;
|
||||
}),
|
||||
TexturePalettes.end());
|
||||
|
||||
TexturePalettes.push_back(new_texture_palette);
|
||||
|
||||
_projectWriter->saveProject(this, std::filesystem::path(ProjectPath));
|
||||
}
|
||||
|
||||
void saveObjectPalette(const NoggitProjectObjectPalette& new_object_palette)
|
||||
{
|
||||
ObjectPalettes.erase(std::remove_if(ObjectPalettes.begin(), ObjectPalettes.end(),
|
||||
[=](NoggitProjectObjectPalette obj_palette)
|
||||
{
|
||||
return obj_palette.MapId == new_object_palette.MapId;
|
||||
}),
|
||||
ObjectPalettes.end());
|
||||
|
||||
ObjectPalettes.push_back(new_object_palette);
|
||||
|
||||
_projectWriter->saveProject(this, std::filesystem::path(ProjectPath));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class ApplicationProject
|
||||
|
||||
@@ -57,6 +57,44 @@ namespace Noggit::Project
|
||||
}
|
||||
}
|
||||
|
||||
if (project_configuration.contains("TexturePalettes") && project_configuration["TexturePalettes"].isArray())
|
||||
{
|
||||
auto project_texture_palettes = project_configuration["ObjectPalettes"].toArray();
|
||||
|
||||
for (auto const& json_texture_palette : project_texture_palettes)
|
||||
{
|
||||
auto texture_palette = NoggitProjectObjectPalette();
|
||||
texture_palette.MapId = json_texture_palette.toObject().value("MapId").toInt();
|
||||
auto json_filepaths = json_texture_palette.toObject().value("Filepaths").toArray();
|
||||
|
||||
for (auto const& json_filepath : json_filepaths)
|
||||
{
|
||||
std::string filepath = json_filepath.toString().toStdString();
|
||||
texture_palette.Filepaths.push_back(filepath);
|
||||
}
|
||||
project.ObjectPalettes.push_back(texture_palette);
|
||||
}
|
||||
}
|
||||
|
||||
if (project_configuration.contains("ObjectPalettes") && project_configuration["ObjectPalettes"].isArray())
|
||||
{
|
||||
auto project_object_palettes = project_configuration["ObjectPalettes"].toArray();
|
||||
|
||||
for (auto const& json_object_palette : project_object_palettes)
|
||||
{
|
||||
auto object_palette = NoggitProjectObjectPalette();
|
||||
object_palette.MapId = json_object_palette.toObject().value("MapId").toInt();
|
||||
auto json_filepaths = json_object_palette.toObject().value("Filepaths").toArray();
|
||||
|
||||
for (auto const& json_filepath : json_filepaths)
|
||||
{
|
||||
std::string filepath = json_filepath.toString().toStdString();
|
||||
object_palette.Filepaths.push_back(filepath);
|
||||
}
|
||||
project.ObjectPalettes.push_back(object_palette);
|
||||
}
|
||||
}
|
||||
|
||||
if (project_configuration.contains("PinnedMaps") && project_configuration["PinnedMaps"].isArray())
|
||||
{
|
||||
auto project_pinned_maps = project_configuration["PinnedMaps"].toArray();
|
||||
|
||||
@@ -52,10 +52,42 @@ namespace Noggit::Project
|
||||
bookmarks.push_back(json_bookmark);
|
||||
}
|
||||
|
||||
auto texture_palettes = QJsonArray();
|
||||
for (auto const& texturePalette : project->TexturePalettes)
|
||||
{
|
||||
auto json_texture_palette = QJsonObject();
|
||||
|
||||
auto json_filepaths = QJsonArray();
|
||||
for (auto& filepath : texturePalette.Filepaths)
|
||||
json_filepaths.push_back(filepath.c_str());
|
||||
json_texture_palette.insert("Filepaths", json_filepaths);
|
||||
|
||||
json_texture_palette.insert("MapId", texturePalette.MapId);
|
||||
|
||||
texture_palettes.push_back(json_texture_palette);
|
||||
}
|
||||
|
||||
auto object_palettes = QJsonArray();
|
||||
for (auto const& objectPalette : project->ObjectPalettes)
|
||||
{
|
||||
auto json_object_palette = QJsonObject();
|
||||
|
||||
auto json_filepaths = QJsonArray();
|
||||
for (auto& filepath : objectPalette.Filepaths)
|
||||
json_filepaths.push_back(filepath.c_str());
|
||||
json_object_palette.insert("Filepaths", json_filepaths);
|
||||
|
||||
json_object_palette.insert("MapId", objectPalette.MapId);
|
||||
|
||||
object_palettes.push_back(json_object_palette);
|
||||
}
|
||||
|
||||
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);
|
||||
project_configuration.insert("TexturePalettes", texture_palettes);
|
||||
project_configuration.insert("ObjectPalettes", object_palettes);
|
||||
|
||||
root.insert("Project", project_configuration);
|
||||
document.setObject(root);
|
||||
|
||||
@@ -75,8 +75,8 @@ namespace Noggit
|
||||
|
||||
}
|
||||
|
||||
ObjectPalette::ObjectPalette(MapView* map_view, QWidget* parent)
|
||||
: widget(parent), layout(new ::QGridLayout(this)), _map_view(map_view)
|
||||
ObjectPalette::ObjectPalette(MapView* map_view, std::shared_ptr<Noggit::Project::NoggitProject> Project, QWidget* parent)
|
||||
: widget(parent), layout(new ::QGridLayout(this)), _map_view(map_view), _project(Project)
|
||||
{
|
||||
setWindowTitle("Object Palette");
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
@@ -122,7 +122,33 @@ namespace Noggit
|
||||
|
||||
layout->addLayout(button_layout, 0, 1);
|
||||
|
||||
LoadSavedPalette();
|
||||
}
|
||||
|
||||
|
||||
void ObjectPalette::LoadSavedPalette()
|
||||
{
|
||||
auto& saved_palette = _project->ObjectPalettes;
|
||||
for (auto& palette : saved_palette)
|
||||
{
|
||||
if (palette.MapId == _map_view->getWorld()->getMapID())
|
||||
{
|
||||
for (auto& filename : palette.Filepaths)
|
||||
addObjectByFilename(filename.c_str(), false);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectPalette::SavePalette()
|
||||
{
|
||||
auto palette_obj = Noggit::Project::NoggitProjectObjectPalette();
|
||||
palette_obj.MapId = _map_view->getWorld()->getMapID();
|
||||
for (auto& path : _object_paths)
|
||||
palette_obj.Filepaths.push_back(path);
|
||||
|
||||
_project->saveObjectPalette(palette_obj);
|
||||
}
|
||||
|
||||
void ObjectPalette::addObjectFromAssetBrowser()
|
||||
@@ -182,7 +208,7 @@ namespace Noggit
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void ObjectPalette::addObjectByFilename(QString const& filename)
|
||||
void ObjectPalette::addObjectByFilename(QString const& filename, bool save_palette)
|
||||
{
|
||||
if (filename.isEmpty())
|
||||
return;
|
||||
@@ -203,6 +229,9 @@ namespace Noggit
|
||||
|
||||
_object_list->addItem(list_item);
|
||||
|
||||
// auto saving whenever an object is added, could change it to manually save
|
||||
if (save_palette)
|
||||
SavePalette();
|
||||
}
|
||||
|
||||
void ObjectPalette::dropEvent(QDropEvent* event)
|
||||
|
||||
@@ -45,11 +45,15 @@ namespace Noggit
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ObjectPalette(MapView* map_view, QWidget* parent);
|
||||
ObjectPalette(MapView* map_view, std::shared_ptr<Noggit::Project::NoggitProject> Project, QWidget* parent);
|
||||
|
||||
~ObjectPalette();
|
||||
|
||||
void addObjectFromAssetBrowser();
|
||||
void addObjectByFilename(QString const& filename);
|
||||
void addObjectByFilename(QString const& filename, bool save_palette = true);
|
||||
void LoadSavedPalette();
|
||||
|
||||
void SavePalette();
|
||||
|
||||
void removeObject(QString filename);
|
||||
|
||||
@@ -71,6 +75,7 @@ namespace Noggit
|
||||
std::unordered_set<std::string> _object_paths;
|
||||
MapView* _map_view;
|
||||
Noggit::Ui::Tools::PreviewRenderer* _preview_renderer;
|
||||
std::shared_ptr<Noggit::Project::NoggitProject> _project;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <noggit/ui/FontAwesome.hpp>
|
||||
#include <noggit/ui/TexturingGUI.h>
|
||||
#include <noggit/ui/CurrentTexture.h>
|
||||
#include <noggit/project/ApplicationProject.h>
|
||||
|
||||
#include <QtWidgets/QGridLayout>
|
||||
#include <QtWidgets/QPushButton>
|
||||
@@ -73,10 +74,11 @@ namespace Noggit
|
||||
|
||||
}
|
||||
|
||||
texture_palette_small::texture_palette_small (QWidget* parent)
|
||||
texture_palette_small::texture_palette_small (std::shared_ptr<Noggit::Project::NoggitProject> Project, int mapId, QWidget* parent)
|
||||
: widget(parent)
|
||||
, layout(new ::QGridLayout(this)
|
||||
)
|
||||
, layout(new ::QGridLayout(this))
|
||||
, _project(Project)
|
||||
, _map_id(mapId)
|
||||
{
|
||||
setWindowTitle("Quick Access Texture Palette");
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
@@ -113,7 +115,31 @@ namespace Noggit
|
||||
|
||||
layout->addLayout(button_layout, 0, 1);
|
||||
|
||||
LoadSavedPalette();
|
||||
}
|
||||
|
||||
void texture_palette_small::LoadSavedPalette()
|
||||
{
|
||||
auto& saved_palette = _project->TexturePalettes;
|
||||
for (auto& palette : saved_palette)
|
||||
{
|
||||
if (palette.MapId == _map_id)
|
||||
{
|
||||
for (auto& filename : palette.Filepaths)
|
||||
addTextureByFilename(filename.c_str(), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void texture_palette_small::SavePalette()
|
||||
{
|
||||
auto palette_text = Noggit::Project::NoggitProjectTexturePalette();
|
||||
palette_text.MapId =_map_id;
|
||||
for (auto& path : _texture_paths)
|
||||
palette_text.Filepaths.push_back("tileset/" + path);
|
||||
|
||||
_project->saveTexturePalette(palette_text);
|
||||
}
|
||||
|
||||
void texture_palette_small::addTexture()
|
||||
@@ -129,10 +155,11 @@ namespace Noggit
|
||||
|
||||
}
|
||||
|
||||
void texture_palette_small::addTextureByFilename(const std::string& filename)
|
||||
void texture_palette_small::addTextureByFilename(const std::string& filename, bool save_palette)
|
||||
{
|
||||
|
||||
QString display_name = QString(filename.c_str()).remove("tileset/");
|
||||
display_name.remove("tileset\\");
|
||||
|
||||
for (auto path : _texture_paths)
|
||||
if (path == display_name.toStdString())
|
||||
@@ -147,6 +174,9 @@ namespace Noggit
|
||||
|
||||
_texture_list->addItem(list_item);
|
||||
|
||||
// auto saving whenever an object is added, could change it to manually save
|
||||
if (save_palette)
|
||||
SavePalette();
|
||||
}
|
||||
|
||||
void texture_palette_small::removeTexture(QString filename)
|
||||
|
||||
@@ -42,13 +42,16 @@ namespace Noggit
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
texture_palette_small (QWidget* parent);
|
||||
texture_palette_small (std::shared_ptr<Noggit::Project::NoggitProject> Project, int mapId, QWidget* parent);
|
||||
|
||||
void addTexture();
|
||||
void addTextureByFilename(const std::string& filename);
|
||||
void addTextureByFilename(const std::string& filename, bool save_palette = true);
|
||||
|
||||
void removeTexture(QString filename);
|
||||
|
||||
void LoadSavedPalette();
|
||||
void SavePalette();
|
||||
|
||||
void removeSelectedTexture();
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
@@ -67,6 +70,8 @@ namespace Noggit
|
||||
QPushButton* _remove_button;
|
||||
std::unordered_set<std::string> _texture_paths;
|
||||
|
||||
std::shared_ptr<Noggit::Project::NoggitProject> _project;
|
||||
int _map_id;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user