From 11d9de671d627b0a326496cfde405d2da9907a84 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Sat, 31 Dec 2011 12:24:23 +0300 Subject: [PATCH] Added #1193 Added scheme bank dialog in particles editor. --- .../src/plugins/object_viewer/attrib_form.ui | 2 +- .../plugins/object_viewer/attrib_widget.cpp | 11 +- .../plugins/object_viewer/particle_editor.cpp | 1 + .../object_viewer/scheme_bank_dialog.cpp | 149 ++++++++++++++++-- .../object_viewer/scheme_bank_dialog.h | 57 +++++-- .../plugins/object_viewer/scheme_bank_form.ui | 36 +++-- .../plugins/object_viewer/scheme_manager.cpp | 26 +-- 7 files changed, 217 insertions(+), 65 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_form.ui index 77c4b895f..404444fc0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_form.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_form.ui @@ -91,7 +91,7 @@ - false + true diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_widget.cpp index 648e0e1a5..e00d07cec 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/attrib_widget.cpp @@ -186,12 +186,11 @@ void CAttribWidget::changeUseScheme(int index) void CAttribWidget::openSchemeBankDialog() { - CSchemeBankDialog *dialog = new CSchemeBankDialog(this); - dialog->setModal(true); - dialog->show(); - dialog->exec(); - delete dialog; - //updateUi(); + CSchemeBankDialog dialog(this); + dialog.setModal(true); + dialog.show(); + dialog.exec(); + updateUi(); } void CAttribWidget::inputValueUpdate(void) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/particle_editor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/particle_editor.cpp index 768576755..12ea96c8a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/particle_editor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/particle_editor.cpp @@ -73,6 +73,7 @@ void CParticleEditor::release() { stop(); closeWorkspace(); + delete _SchemeManager; } void CParticleEditor::setActiveNode(CWorkspaceNode *node) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.cpp index 66deb2a17..bca0f4879 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.cpp @@ -1,24 +1,33 @@ -// NeL - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// 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 +// NeL - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// 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 . // Project includes #include "stdpch.h" #include "scheme_bank_dialog.h" +#include "scheme_manager.h" #include "modules.h" +// NeL includes +#include + +// Qt includes +#include +#include +#include + namespace NLQT { @@ -27,6 +36,16 @@ CSchemeBankDialog::CSchemeBankDialog(CAttribWidget *attribWidget, QWidget *paren { _ui.setupUi(this); _attribWidget = attribWidget; + + connect(_ui.createButton, SIGNAL(clicked()), this, SLOT(createScheme())); + connect(_ui.currentButton, SIGNAL(clicked()), this, SLOT(setCurrentScheme())); + connect(_ui.removeButton, SIGNAL(clicked()), this, SLOT(removeScheme())); + connect(_ui.loadButton, SIGNAL(clicked()), this, SLOT(loadBank())); + connect(_ui.saveButton, SIGNAL(clicked()), this, SLOT(saveBank())); + connect(_ui.listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableButtons())); + connect(_ui.listWidget, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(changeNameScheme(QListWidgetItem *))); + + buildList(); } CSchemeBankDialog::~CSchemeBankDialog() @@ -35,27 +54,125 @@ CSchemeBankDialog::~CSchemeBankDialog() void CSchemeBankDialog::createScheme() { + bool ok; + QString text = QInputDialog::getText(this, tr("Insert new scheme"), + tr("Set name:"), QLineEdit::Normal, + "new scheme", &ok); + if (ok && !text.isEmpty()) + { + NL3D::CPSAttribMakerBase *attribMakerBase = _attribWidget->getCurrentSchemePtr()->clone(); + Modules::psEdit().getSchemeManager()->insertScheme(text.toStdString(), attribMakerBase); + + CSchemeItem *item = new CSchemeItem(text, _ui.listWidget); + item->setUserData(attribMakerBase); + item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled); + } } void CSchemeBankDialog::setCurrentScheme() { - //SchemeManager.insertScheme(cn.getName(), getCurrentSchemePtr()->clone()); + CSchemeItem *item = dynamic_cast(_ui.listWidget->currentItem()); + + NL3D::CPSAttribMakerBase *attrib = item->getUserData(); + nlassert(attrib); + + _attribWidget->setCurrentSchemePtr(attrib->clone()); + _attribWidget->updateUi(); } void CSchemeBankDialog::removeScheme() { + CSchemeItem *item = dynamic_cast(_ui.listWidget->currentItem()); + + NL3D::CPSAttribMakerBase *attrib = item->getUserData(); + nlassert(attrib); + Modules::psEdit().getSchemeManager()->remove(attrib); + _ui.listWidget->removeItemWidget(item); + delete item; + + if (_ui.listWidget->count() == 0) + { + _ui.currentButton->setEnabled(false); + _ui.removeButton->setEnabled(false); + } } void CSchemeBankDialog::saveBank() { + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save scheme bank file"), ".", + tr("Scheme bank files (*.scb)")); + + if (!fileName.isEmpty()) + { + try + { + NLMISC::COFile iF; + iF.open(fileName.toStdString()); + NLQT::CSchemeManager *schemeManager = Modules::psEdit().getSchemeManager(); + iF.serial(*schemeManager); + } + catch (std::exception &e) + { + QMessageBox::critical(this, "Scheme manager", tr("Error saving scheme bank : %1").arg(e.what())); + return; + } + } } void CSchemeBankDialog::loadBank() { + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open scheme bank file"), ".", + tr("Scheme bank files (*.scb)")); + + if (!fileName.isEmpty()) + { + NLQT::CSchemeManager sm; + try + { + NLMISC::CIFile iF; + iF.open(fileName.toStdString()); + iF.serial(sm); + Modules::psEdit().getSchemeManager()->swap(sm); + } + catch (std::exception &e) + { + QMessageBox::critical(this, "Scheme manager", tr("Error loading scheme bank : %1").arg(e.what())); + return; + } + buildList(); + } } -void CSchemeBankDialog::buildList() +void CSchemeBankDialog::changeNameScheme(QListWidgetItem *item) { + CSchemeItem *schemeItem = dynamic_cast(item); + + NL3D::CPSAttribMakerBase *attrib = schemeItem->getUserData(); + nlassert(attrib); + + Modules::psEdit().getSchemeManager()->rename(attrib, item->text().toStdString()); +} + +void CSchemeBankDialog::enableButtons() +{ + _ui.currentButton->setEnabled(true); + _ui.removeButton->setEnabled(true); +} + +void CSchemeBankDialog::buildList() +{ + _ui.listWidget->clear(); + typedef std::vector TSchemeVect; + static TSchemeVect schemes; + Modules::psEdit().getSchemeManager()->getSchemes(_attribWidget->getCurrentSchemePtr()->getType(), schemes); + for (TSchemeVect::const_iterator it = schemes.begin(); it != schemes.end(); ++it) + { + CSchemeItem *item = new CSchemeItem(it->first.c_str(), _ui.listWidget); + item->setUserData(it->second); + item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled); + } } } /* namespace NLQT */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.h index a02406468..8f9f300b8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_dialog.h @@ -1,17 +1,17 @@ -// NeL - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// 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 +// NeL - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// 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 SCHEME_BANK_DIALOG_H @@ -27,12 +27,37 @@ #include "nel/3d/particle_system.h" // Project includes +#include "attrib_widget.h" #include "ps_wrapper.h" namespace NLQT { class CAttribWidget; +/** +@class CSchemeItem +@brief Contain pointer to NL3D::CPSAttribMakerBase. +*/ +class CSchemeItem: public QListWidgetItem +{ +public: + CSchemeItem(const QString &text, QListWidget *parent = 0, int type = UserType ): + QListWidgetItem(text, parent, type), _attrib(NULL) {} + + void setUserData(NL3D::CPSAttribMakerBase *attrib) + { + _attrib = attrib; + } + NL3D::CPSAttribMakerBase *getUserData() const + { + return _attrib; + } + +private: + + NL3D::CPSAttribMakerBase *_attrib; +}; /* class CSchemeItem */ + class CSchemeBankDialog: public QDialog { Q_OBJECT @@ -47,9 +72,11 @@ private Q_SLOTS: void removeScheme(); void saveBank(); void loadBank(); + void enableButtons(); + void changeNameScheme(QListWidgetItem *item); private: - void buildList(); + void buildList(); CAttribWidget *_attribWidget; Ui::CSchemeBankDialog _ui; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_form.ui index e7dd281f8..f8fa10865 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_form.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_bank_form.ui @@ -14,31 +14,27 @@ Sceme bank - + - Create + Put current - - - Rename - - - - + + false + Remove - + Qt::Vertical @@ -51,24 +47,33 @@ - + + + true + Load bank - + + + true + Save bank - + + + false + 0 @@ -105,7 +110,10 @@ - + + + false + Set current diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.cpp index 62e847a73..c00422af5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.cpp @@ -18,7 +18,7 @@ #include "scheme_manager.h" #include "nel/3d/ps_attrib_maker.h" -namespace NLQT +namespace NLQT { CSchemeManager::~CSchemeManager() @@ -34,7 +34,7 @@ void CSchemeManager::insertScheme(const std::string &name, NL3D::CPSAttribMakerB { nlassert(scheme); TSchemeInfo si(std::string(name), scheme); - _SchemeMap.insert(TSchemeMap::value_type(std::string(scheme->getType()), si)); + _SchemeMap.insert(TSchemeMap::value_type(std::string(scheme->getType()), si)); } void CSchemeManager::getSchemes(const std::string &type, std::vector &dest) @@ -49,30 +49,30 @@ void CSchemeManager::getSchemes(const std::string &type, std::vectorsecond.first); // name f.serialPolyPtr(smIt->second.second); // scheme - } + } } else { _SchemeMap.clear(); - + std::string name; NL3D::CPSAttribMakerBase *scheme = NULL; sint32 size; f.serial(size); for (sint32 k = 0; k < size; ++k) - { + { f.serial(name); f.serialPolyPtr(scheme); insertScheme(name, scheme); @@ -80,12 +80,12 @@ void CSchemeManager::serial(NLMISC::IStream &f) throw(NLMISC::EStream) } } -void CSchemeManager::swap(CSchemeManager &other) +void CSchemeManager::swap(CSchemeManager &other) { this->_SchemeMap.swap(other._SchemeMap); } -void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am) +void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am) { TSchemeMap::iterator smIt; for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt) @@ -101,7 +101,7 @@ void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am) } // rename a scheme, given a pointer on it -void CSchemeManager::rename(NL3D::CPSAttribMakerBase *am, const std::string &newName) +void CSchemeManager::rename(NL3D::CPSAttribMakerBase *am, const std::string &newName) { TSchemeMap::iterator smIt; for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt) @@ -110,7 +110,7 @@ void CSchemeManager::rename(NL3D::CPSAttribMakerBase *am, const std::string &ne } if (smIt != _SchemeMap.end()) { - smIt->second.first = newName; + smIt->second.first = newName; } }