Texture selection dialog

--HG--
branch : feature-material-editor
hg/feature/material-editor
kaetemi 9 years ago
parent e6385a1b34
commit 67a5497883

@ -53,11 +53,13 @@ public:
/// Undo init /// Undo init
static void release(); static void release();
static std::string assetRoot(); static std::string getAssetRoot();
static void getDatabaseTextureSearchPaths(std::vector<std::string> &paths);
private: private:
static void cleanup(); static void cleanup();
static void searchDirectories(const char *var); static void searchDirectories(const char *var);
static void getSearchPaths(std::vector<std::string> &paths, const char *var);
static CProjectConfig s_Instance; static CProjectConfig s_Instance;

@ -208,12 +208,12 @@ void CProjectConfig::searchDirectories(const char *var)
{ {
CConfigFile *cfg = s_ConfigFiles[i]; CConfigFile *cfg = s_ConfigFiles[i];
const TPathString &dir = s_ConfigPaths[i]; const TPathString &dir = s_ConfigPaths[i];
CConfigFile::CVar *paths = cfg->getVarPtr(var); CConfigFile::CVar *pathvar = cfg->getVarPtr(var);
if (paths) 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; if (!CPath::isAbsolutePath(path)) path = dir + path;
path = CPath::standardizePath(path); path = CPath::standardizePath(path);
if (s_SearchPaths.find(path) == s_SearchPaths.end()) if (s_SearchPaths.find(path) == s_SearchPaths.end())
@ -233,11 +233,41 @@ void CProjectConfig::release()
cleanup(); cleanup();
} }
std::string CProjectConfig::assetRoot() std::string CProjectConfig::getAssetRoot()
{ {
return CFile::getPath(s_AssetConfigPath); return CFile::getPath(s_AssetConfigPath);
} }
void CProjectConfig::getSearchPaths(std::vector<std::string> &paths, const char *var)
{
std::set<std::string> 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<std::string> &paths)
{
getSearchPaths(paths, "DatabaseTextureSearchPaths");
}
/* /*
std::string CProjectConfig::databaseRoot() std::string CProjectConfig::databaseRoot()
{ {

@ -3,5 +3,6 @@
<file>icons/cross-circle.png</file> <file>icons/cross-circle.png</file>
<file>icons/exclamation.png</file> <file>icons/exclamation.png</file>
<file>icons/information-white.png</file> <file>icons/information-white.png</file>
<file>icons/folder-open-image.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

@ -43,7 +43,7 @@
#include "../shared_widgets/error_list.h" #include "../shared_widgets/error_list.h"
#include "graphics_viewport.h" #include "graphics_viewport.h"
#include "graphics_config.h" #include "graphics_config.h"
#include "texture_browser.h" #include "texture_select_dialog.h"
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
@ -92,24 +92,29 @@ CMainWindow::CMainWindow(QWidget *parent, Qt::WindowFlags flags)
connect(m_GraphicsConfig, SIGNAL(applyGraphicsConfig()), this, SLOT(applyGraphicsConfig())); connect(m_GraphicsConfig, SIGNAL(applyGraphicsConfig()), this, SLOT(applyGraphicsConfig()));
m_Configuration.setAndCallback("SoundEnabled", CConfigCallback(this, &CMainWindow::cfcbSoundEnabled)); m_Configuration.setAndCallback("SoundEnabled", CConfigCallback(this, &CMainWindow::cfcbSoundEnabled));
NLMISC::CConfigFile::CVar *lastFiles = m_Configuration.getConfigFile().getVarPtr("LastFiles"); NLMISC::CConfigFile::CVar *recentFiles = m_Configuration.getConfigFile().getVarPtr("RecentFiles");
if (lastFiles) 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; break;
} }
} }
} }
/*
QDockWidget *dock = new QDockWidget(this); QDockWidget *dock = new QDockWidget(this);
dock->setFloating(true); dock->setFloating(true);
CTextureBrowser *browser = new CTextureBrowser(dock); CTextureBrowser *browser = new CTextureBrowser(dock);
dock->setWidget(browser); dock->setWidget(browser);
dock->resize(800, 800); dock->resize(800, 800);
*/
CTextureSelectDialog *textureSelect = new CTextureSelectDialog(this);
textureSelect->exec();
} }
CMainWindow::~CMainWindow() CMainWindow::~CMainWindow()
@ -131,7 +136,7 @@ void CMainWindow::initProjectConfig(const std::string &asset)
NLPIPELINE::CProjectConfig::DatabaseTextureSearchPaths, NLPIPELINE::CProjectConfig::DatabaseTextureSearchPaths,
true); true);
std::string databaseRoot = NLPIPELINE::CProjectConfig::assetRoot(); std::string databaseRoot = NLPIPELINE::CProjectConfig::getAssetRoot();
m_AssetTreeView->setRootIndex(m_AssetTreeModel->index(QString::fromUtf8(databaseRoot.c_str()))); m_AssetTreeView->setRootIndex(m_AssetTreeModel->index(QString::fromUtf8(databaseRoot.c_str())));
} }

@ -81,7 +81,7 @@ CTextureBrowser::CTextureBrowser(QWidget *parent) : QListWidget(parent)
setGridSize(QSize(144, 160)); setGridSize(QSize(144, 160));
setDirectory("W:/database/stuff/fyros/agents/_textures/actors/"); // setDirectory("W:/database/stuff/fyros/agents/_textures/actors/");
} }
CTextureBrowser::~CTextureBrowser() CTextureBrowser::~CTextureBrowser()
@ -90,6 +90,15 @@ CTextureBrowser::~CTextureBrowser()
delete m_Thread; delete m_Thread;
} }
std::string CTextureBrowser::getSelectedTextureFile() const
{
std::string res;
QList<QListWidgetItem *> items = selectedItems();
if (items.size() > 0)
res = items[0]->text().toUtf8().data();
return res;
}
void CTextureBrowser::setDirectory(const QString &dir) void CTextureBrowser::setDirectory(const QString &dir)
{ {
if (dir == m_CurrentDirectory) if (dir == m_CurrentDirectory)
@ -106,7 +115,9 @@ void CTextureBrowser::setDirectory(const QString &dir)
NLMISC::CFile::createDirectoryTree(cacheDir); NLMISC::CFile::createDirectoryTree(cacheDir);
std::vector<std::string> files; std::vector<std::string> files;
NLMISC::CPath::getPathContent(dir.toUtf8().data(), false, false, true, 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) for (size_t i = 0; i < files.size(); ++i)
{ {
std::string &file = files[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)); std::string ext = NLMISC::toLower(NLMISC::CFile::getExtension(file));
if (ext == "dds" || ext == "tga" || ext == "png" || ext == "jpg" || ext == "jpeg") 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()); item->setSizeHint(gridSize());
addItem(item); addItem(item);
m_Thread->immediate([this, file, cacheDir, item]() -> void { m_Thread->immediate([this, file, cacheDir, item]() -> void {

@ -45,8 +45,8 @@ public:
CTextureBrowser(QWidget *parent = NULL); CTextureBrowser(QWidget *parent = NULL);
virtual ~CTextureBrowser(); virtual ~CTextureBrowser();
std::string getSelectedTextureFile() const;
private:
void setDirectory(const QString &dir); void setDirectory(const QString &dir);
// STD INVOKE -> // STD INVOKE ->

@ -0,0 +1,113 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2016 Winch Gate Property Limited
// Author: Jan Boon <jan.boon@kaetemi.be>
//
// 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 <http://www.gnu.org/licenses/>.
#include <nel/misc/types_nl.h>
#include "texture_select_dialog.h"
// STL includes
#include <functional>
// Qt includes
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QPixmap>
#include <QListWidget>
#include <QFileInfo>
#include <QSplitter>
#include <QPushButton>
#include <QDir>
// NeL includes
// #include <nel/misc/debug.h>
#include <nel/misc/common.h>
#include <nel/misc/bitmap.h>
#include <nel/misc/file.h>
#include <nel/misc/sha1.h>
#include <nel/pipeline/project_config.h>
// 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<int> 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<std::string> 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 */

@ -0,0 +1,60 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2016 Winch Gate Property Limited
// Author: Jan Boon <jan.boon@kaetemi.be>
//
// 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 <http://www.gnu.org/licenses/>.
#ifndef NL_TEXTURE_SELECT_DIALOG_H
#define NL_TEXTURE_SELECT_DIALOG_H
#include <nel/misc/types_nl.h>
// STL includes
// Qt includes
#include <QDialog>
// NeL includes
// ...
// Project includes
#include "texture_browser.h"
/**
* CTextureSelectDialog
* \brief CTextureSelectDialog
* \date 2016-02-18 14:06GMT
* \author Jan Boon <jan.boon@kaetemi.be>
*/
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 */
Loading…
Cancel
Save