diff --git a/code/nel/include/nel/pipeline/project_config.h b/code/nel/include/nel/pipeline/project_config.h index b28cbb97e..a54aed134 100644 --- a/code/nel/include/nel/pipeline/project_config.h +++ b/code/nel/include/nel/pipeline/project_config.h @@ -53,11 +53,13 @@ public: /// Undo init static void release(); - static std::string assetRoot(); + static std::string getAssetRoot(); + static void getDatabaseTextureSearchPaths(std::vector &paths); private: static void cleanup(); static void searchDirectories(const char *var); + static void getSearchPaths(std::vector &paths, const char *var); static CProjectConfig s_Instance; diff --git a/code/nel/src/pipeline/project_config.cpp b/code/nel/src/pipeline/project_config.cpp index ba8cf201e..930e7491e 100644 --- a/code/nel/src/pipeline/project_config.cpp +++ b/code/nel/src/pipeline/project_config.cpp @@ -208,12 +208,12 @@ void CProjectConfig::searchDirectories(const char *var) { CConfigFile *cfg = s_ConfigFiles[i]; const TPathString &dir = s_ConfigPaths[i]; - CConfigFile::CVar *paths = cfg->getVarPtr(var); - if (paths) + CConfigFile::CVar *pathvar = cfg->getVarPtr(var); + if (pathvar) { - for (uint i = 0; i < paths->size(); i++) + for (uint j = 0; j < pathvar->size(); j++) { - TPathString path = paths->asString(i); + TPathString path = pathvar->asString(j); if (!CPath::isAbsolutePath(path)) path = dir + path; path = CPath::standardizePath(path); if (s_SearchPaths.find(path) == s_SearchPaths.end()) @@ -233,11 +233,41 @@ void CProjectConfig::release() cleanup(); } -std::string CProjectConfig::assetRoot() +std::string CProjectConfig::getAssetRoot() { return CFile::getPath(s_AssetConfigPath); } +void CProjectConfig::getSearchPaths(std::vector &paths, const char *var) +{ + std::set deduplicate; + for (uint i = 0; i < s_ConfigFiles.size(); ++i) + { + CConfigFile *cfg = s_ConfigFiles[i]; + const TPathString &dir = s_ConfigPaths[i]; + CConfigFile::CVar *pathvar = cfg->getVarPtr(var); + if (pathvar) + { + for (uint j = 0; j < pathvar->size(); j++) + { + TPathString path = pathvar->asString(j); + if (!CPath::isAbsolutePath(path)) path = dir + path; + path = CPath::standardizePath(path); + if (deduplicate.find(path) == deduplicate.end()) + { + paths.push_back(path); + deduplicate.insert(path); + } + } + } + } +} + +void CProjectConfig::getDatabaseTextureSearchPaths(std::vector &paths) +{ + getSearchPaths(paths, "DatabaseTextureSearchPaths"); +} + /* std::string CProjectConfig::databaseRoot() { diff --git a/code/nel/tools/3d/mesh_editor/icons.qrc b/code/nel/tools/3d/mesh_editor/icons.qrc index 31a9f782d..04117b75f 100644 --- a/code/nel/tools/3d/mesh_editor/icons.qrc +++ b/code/nel/tools/3d/mesh_editor/icons.qrc @@ -3,5 +3,6 @@ icons/cross-circle.png icons/exclamation.png icons/information-white.png + icons/folder-open-image.png diff --git a/code/nel/tools/3d/mesh_editor/icons/folder-open-image.png b/code/nel/tools/3d/mesh_editor/icons/folder-open-image.png new file mode 100644 index 000000000..6b21e1abb Binary files /dev/null and b/code/nel/tools/3d/mesh_editor/icons/folder-open-image.png differ diff --git a/code/nel/tools/3d/mesh_editor/main_window.cpp b/code/nel/tools/3d/mesh_editor/main_window.cpp index 6ba48292f..10d1993f0 100644 --- a/code/nel/tools/3d/mesh_editor/main_window.cpp +++ b/code/nel/tools/3d/mesh_editor/main_window.cpp @@ -43,7 +43,7 @@ #include "../shared_widgets/error_list.h" #include "graphics_viewport.h" #include "graphics_config.h" -#include "texture_browser.h" +#include "texture_select_dialog.h" using namespace std; using namespace NLMISC; @@ -92,24 +92,29 @@ CMainWindow::CMainWindow(QWidget *parent, Qt::WindowFlags flags) connect(m_GraphicsConfig, SIGNAL(applyGraphicsConfig()), this, SLOT(applyGraphicsConfig())); m_Configuration.setAndCallback("SoundEnabled", CConfigCallback(this, &CMainWindow::cfcbSoundEnabled)); - NLMISC::CConfigFile::CVar *lastFiles = m_Configuration.getConfigFile().getVarPtr("LastFiles"); - if (lastFiles) + NLMISC::CConfigFile::CVar *recentFiles = m_Configuration.getConfigFile().getVarPtr("RecentFiles"); + if (recentFiles) { - for (uint i = 0; i < lastFiles->size(); ++i) + for (uint i = 0; i < recentFiles->size(); ++i) { - if (NLMISC::CFile::isExists(lastFiles->asString())) + if (NLMISC::CFile::isExists(recentFiles->asString())) { - initProjectConfig(lastFiles->asString()); + initProjectConfig(recentFiles->asString()); break; } } } + /* QDockWidget *dock = new QDockWidget(this); dock->setFloating(true); CTextureBrowser *browser = new CTextureBrowser(dock); dock->setWidget(browser); dock->resize(800, 800); + */ + + CTextureSelectDialog *textureSelect = new CTextureSelectDialog(this); + textureSelect->exec(); } CMainWindow::~CMainWindow() @@ -131,7 +136,7 @@ void CMainWindow::initProjectConfig(const std::string &asset) NLPIPELINE::CProjectConfig::DatabaseTextureSearchPaths, true); - std::string databaseRoot = NLPIPELINE::CProjectConfig::assetRoot(); + std::string databaseRoot = NLPIPELINE::CProjectConfig::getAssetRoot(); m_AssetTreeView->setRootIndex(m_AssetTreeModel->index(QString::fromUtf8(databaseRoot.c_str()))); } diff --git a/code/nel/tools/3d/mesh_editor/texture_browser.cpp b/code/nel/tools/3d/mesh_editor/texture_browser.cpp index 2d58c84fc..6c0fbeecb 100644 --- a/code/nel/tools/3d/mesh_editor/texture_browser.cpp +++ b/code/nel/tools/3d/mesh_editor/texture_browser.cpp @@ -81,7 +81,7 @@ CTextureBrowser::CTextureBrowser(QWidget *parent) : QListWidget(parent) setGridSize(QSize(144, 160)); - setDirectory("W:/database/stuff/fyros/agents/_textures/actors/"); + // setDirectory("W:/database/stuff/fyros/agents/_textures/actors/"); } CTextureBrowser::~CTextureBrowser() @@ -90,6 +90,15 @@ CTextureBrowser::~CTextureBrowser() delete m_Thread; } +std::string CTextureBrowser::getSelectedTextureFile() const +{ + std::string res; + QList items = selectedItems(); + if (items.size() > 0) + res = items[0]->text().toUtf8().data(); + return res; +} + void CTextureBrowser::setDirectory(const QString &dir) { if (dir == m_CurrentDirectory) @@ -106,7 +115,9 @@ void CTextureBrowser::setDirectory(const QString &dir) NLMISC::CFile::createDirectoryTree(cacheDir); std::vector files; NLMISC::CPath::getPathContent(dir.toUtf8().data(), false, false, true, files); - QPixmap dummy = QPixmap::fromImage(QImage(128, 128, QImage::Format_ARGB32)); + QImage dummyimg = QImage(128, 128, QImage::Format_ARGB32); + dummyimg.fill(0); + QIcon dummy = QIcon(QPixmap::fromImage(dummyimg)); for (size_t i = 0; i < files.size(); ++i) { std::string &file = files[i]; @@ -114,7 +125,7 @@ void CTextureBrowser::setDirectory(const QString &dir) std::string ext = NLMISC::toLower(NLMISC::CFile::getExtension(file)); if (ext == "dds" || ext == "tga" || ext == "png" || ext == "jpg" || ext == "jpeg") { - QListWidgetItem *item = new QListWidgetItem(QIcon(dummy), fileName); + QListWidgetItem *item = new QListWidgetItem(dummy, fileName); item->setSizeHint(gridSize()); addItem(item); m_Thread->immediate([this, file, cacheDir, item]() -> void { diff --git a/code/nel/tools/3d/mesh_editor/texture_browser.h b/code/nel/tools/3d/mesh_editor/texture_browser.h index f36144394..230cd1411 100644 --- a/code/nel/tools/3d/mesh_editor/texture_browser.h +++ b/code/nel/tools/3d/mesh_editor/texture_browser.h @@ -45,8 +45,8 @@ public: CTextureBrowser(QWidget *parent = NULL); virtual ~CTextureBrowser(); + std::string getSelectedTextureFile() const; -private: void setDirectory(const QString &dir); // STD INVOKE -> diff --git a/code/nel/tools/3d/mesh_editor/texture_select_dialog.cpp b/code/nel/tools/3d/mesh_editor/texture_select_dialog.cpp new file mode 100644 index 000000000..2baed207d --- /dev/null +++ b/code/nel/tools/3d/mesh_editor/texture_select_dialog.cpp @@ -0,0 +1,113 @@ +// NeL - MMORPG Framework +// Copyright (C) 2016 Winch Gate Property Limited +// Author: Jan Boon +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include +#include "texture_select_dialog.h" + +// STL includes +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// NeL includes +// #include +#include +#include +#include +#include +#include + +// Project includes +#include "texture_browser.h" + +CTextureSelectDialog::CTextureSelectDialog(QWidget *parent) : QDialog(parent) +{ + resize(640, 400); + setWindowTitle(tr("Select Texture")); + + m_TextureBrowser = new CTextureBrowser(this); + + QVBoxLayout *outer = new QVBoxLayout(this); + setLayout(outer); + + QSplitter *splitter = new QSplitter(Qt::Horizontal, this); + outer->addWidget(splitter); + + QListWidget *folderList = new QListWidget(this); + splitter->addWidget(folderList); + splitter->addWidget(m_TextureBrowser); + + QList sizes; + sizes << 160 << 480; + splitter->setSizes(sizes); + + QHBoxLayout *buttons = new QHBoxLayout(this); + outer->addLayout(buttons); + buttons->addStretch(); + + QPushButton *select = new QPushButton("Select", this); + buttons->addWidget(select); + + QPushButton *cancel = new QPushButton("Cancel", this); + buttons->addWidget(cancel); + + connect(select, &QPushButton::clicked, this, &QDialog::accept); + connect(cancel, &QPushButton::clicked, this, &QDialog::reject); + + std::vector paths; + NLPIPELINE::CProjectConfig::getDatabaseTextureSearchPaths(paths); + QString assetRoot = QString::fromUtf8(NLPIPELINE::CProjectConfig::getAssetRoot().c_str()); + + QIcon folder(":/icons/folder-open-image.png"); + for (uint i = 0; i < paths.size(); ++i) + { + QString path = QString::fromUtf8(paths[i].c_str()); + if (path.startsWith(assetRoot)) + path = path.mid(assetRoot.size()); + folderList->addItem(new QListWidgetItem(folder, path)); + } + + auto textChanged = [this, assetRoot](const QString &text) -> void { + if (text.isEmpty()) return; + else if (QDir::isRelativePath(text)) m_TextureBrowser->setDirectory(assetRoot + text); + else m_TextureBrowser->setDirectory(text); + }; + + if (folderList->count()) + { + folderList->item(0)->setSelected(true); + textChanged(folderList->item(0)->text()); + } + + connect(folderList, &QListWidget::currentTextChanged, this, textChanged); +} + +CTextureSelectDialog::~CTextureSelectDialog() +{ + +} + +/* end of file */ diff --git a/code/nel/tools/3d/mesh_editor/texture_select_dialog.h b/code/nel/tools/3d/mesh_editor/texture_select_dialog.h new file mode 100644 index 000000000..5e07ae388 --- /dev/null +++ b/code/nel/tools/3d/mesh_editor/texture_select_dialog.h @@ -0,0 +1,60 @@ +// NeL - MMORPG Framework +// Copyright (C) 2016 Winch Gate Property Limited +// Author: Jan Boon +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef NL_TEXTURE_SELECT_DIALOG_H +#define NL_TEXTURE_SELECT_DIALOG_H +#include + +// STL includes + +// Qt includes +#include + +// NeL includes +// ... + +// Project includes +#include "texture_browser.h" + +/** + * CTextureSelectDialog + * \brief CTextureSelectDialog + * \date 2016-02-18 14:06GMT + * \author Jan Boon + */ +class CTextureSelectDialog : public QDialog +{ + Q_OBJECT + +public: + CTextureSelectDialog(QWidget *parent = NULL); + virtual ~CTextureSelectDialog(); + + inline std::string getSelectedTextureFile() const { return m_TextureBrowser->getSelectedTextureFile(); } + +private: + CTextureBrowser *m_TextureBrowser; + +private: + CTextureSelectDialog(const CTextureSelectDialog &); + CTextureSelectDialog &operator=(const CTextureSelectDialog &); + +}; /* class CTextureSelectDialog */ + +#endif /* #ifndef NL_TEXTURE_SELECT_DIALOG_H */ + +/* end of file */