Added #1193 Added scheme bank dialog in particles editor.

This commit is contained in:
dnk-88 2011-12-31 12:24:23 +03:00
parent cbe8f88266
commit 3e32c1b037
7 changed files with 217 additions and 65 deletions

View file

@ -91,7 +91,7 @@
<item> <item>
<widget class="QPushButton" name="bankButton"> <widget class="QPushButton" name="bankButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">

View file

@ -186,12 +186,11 @@ void CAttribWidget::changeUseScheme(int index)
void CAttribWidget::openSchemeBankDialog() void CAttribWidget::openSchemeBankDialog()
{ {
CSchemeBankDialog *dialog = new CSchemeBankDialog(this); CSchemeBankDialog dialog(this);
dialog->setModal(true); dialog.setModal(true);
dialog->show(); dialog.show();
dialog->exec(); dialog.exec();
delete dialog; updateUi();
//updateUi();
} }
void CAttribWidget::inputValueUpdate(void) void CAttribWidget::inputValueUpdate(void)

View file

@ -73,6 +73,7 @@ void CParticleEditor::release()
{ {
stop(); stop();
closeWorkspace(); closeWorkspace();
delete _SchemeManager;
} }
void CParticleEditor::setActiveNode(CWorkspaceNode *node) void CParticleEditor::setActiveNode(CWorkspaceNode *node)

View file

@ -1,24 +1,33 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/> // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2010 Winch Gate Property Limited
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// Project includes // Project includes
#include "stdpch.h" #include "stdpch.h"
#include "scheme_bank_dialog.h" #include "scheme_bank_dialog.h"
#include "scheme_manager.h"
#include "modules.h" #include "modules.h"
// NeL includes
#include <nel/misc/file.h>
// Qt includes
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
namespace NLQT namespace NLQT
{ {
@ -27,6 +36,16 @@ CSchemeBankDialog::CSchemeBankDialog(CAttribWidget *attribWidget, QWidget *paren
{ {
_ui.setupUi(this); _ui.setupUi(this);
_attribWidget = attribWidget; _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() CSchemeBankDialog::~CSchemeBankDialog()
@ -35,27 +54,125 @@ CSchemeBankDialog::~CSchemeBankDialog()
void CSchemeBankDialog::createScheme() 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() void CSchemeBankDialog::setCurrentScheme()
{ {
//SchemeManager.insertScheme(cn.getName(), getCurrentSchemePtr()->clone()); CSchemeItem *item = dynamic_cast<CSchemeItem *>(_ui.listWidget->currentItem());
NL3D::CPSAttribMakerBase *attrib = item->getUserData();
nlassert(attrib);
_attribWidget->setCurrentSchemePtr(attrib->clone());
_attribWidget->updateUi();
} }
void CSchemeBankDialog::removeScheme() void CSchemeBankDialog::removeScheme()
{ {
CSchemeItem *item = dynamic_cast<CSchemeItem *>(_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() 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() 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<CSchemeItem *>(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<NLQT::CSchemeManager::TSchemeInfo> 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 */ } /* namespace NLQT */

View file

@ -1,17 +1,17 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/> // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2010 Winch Gate Property Limited
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SCHEME_BANK_DIALOG_H #ifndef SCHEME_BANK_DIALOG_H
@ -27,12 +27,37 @@
#include "nel/3d/particle_system.h" #include "nel/3d/particle_system.h"
// Project includes // Project includes
#include "attrib_widget.h"
#include "ps_wrapper.h" #include "ps_wrapper.h"
namespace NLQT namespace NLQT
{ {
class CAttribWidget; 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 class CSchemeBankDialog: public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -47,9 +72,11 @@ private Q_SLOTS:
void removeScheme(); void removeScheme();
void saveBank(); void saveBank();
void loadBank(); void loadBank();
void enableButtons();
void changeNameScheme(QListWidgetItem *item);
private: private:
void buildList(); void buildList();
CAttribWidget *_attribWidget; CAttribWidget *_attribWidget;
Ui::CSchemeBankDialog _ui; Ui::CSchemeBankDialog _ui;

View file

@ -14,31 +14,27 @@
<string>Sceme bank</string> <string>Sceme bank</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="8"> <item row="0" column="0" rowspan="7">
<widget class="QListWidget" name="listWidget"/> <widget class="QListWidget" name="listWidget"/>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QPushButton" name="createButton"> <widget class="QPushButton" name="createButton">
<property name="text"> <property name="text">
<string>Create</string> <string>Put current</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QPushButton" name="renameButton">
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="removeButton"> <widget class="QPushButton" name="removeButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Remove</string> <string>Remove</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="4" column="1">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -51,24 +47,33 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="1"> <item row="5" column="1">
<widget class="QPushButton" name="loadButton"> <widget class="QPushButton" name="loadButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text"> <property name="text">
<string>Load bank</string> <string>Load bank</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="6" column="1">
<widget class="QPushButton" name="saveButton"> <widget class="QPushButton" name="saveButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text"> <property name="text">
<string>Save bank</string> <string>Save bank</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0" colspan="2"> <item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -105,7 +110,10 @@
</layout> </layout>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="setCurrentButton"> <widget class="QPushButton" name="currentButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Set current</string> <string>Set current</string>
</property> </property>

View file

@ -18,7 +18,7 @@
#include "scheme_manager.h" #include "scheme_manager.h"
#include "nel/3d/ps_attrib_maker.h" #include "nel/3d/ps_attrib_maker.h"
namespace NLQT namespace NLQT
{ {
CSchemeManager::~CSchemeManager() CSchemeManager::~CSchemeManager()
@ -34,7 +34,7 @@ void CSchemeManager::insertScheme(const std::string &name, NL3D::CPSAttribMakerB
{ {
nlassert(scheme); nlassert(scheme);
TSchemeInfo si(std::string(name), 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<TSchemeInfo> &dest) void CSchemeManager::getSchemes(const std::string &type, std::vector<TSchemeInfo> &dest)
@ -49,30 +49,30 @@ void CSchemeManager::getSchemes(const std::string &type, std::vector<TSchemeInfo
void CSchemeManager::serial(NLMISC::IStream &f) throw(NLMISC::EStream) void CSchemeManager::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
{ {
f.serialCheck((uint32) '_GNM'); f.serialCheck((uint32) '_GNM');
f.serialCheck((uint32) 'MHCS'); f.serialCheck((uint32) 'MHCS');
f.serialVersion(1); f.serialVersion(1);
if (!f.isReading()) if (!f.isReading())
{ {
sint32 size = (sint32)_SchemeMap.size(); sint32 size = (sint32)_SchemeMap.size();
f.serial(size); f.serial(size);
for (TSchemeMap::iterator smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt) for (TSchemeMap::iterator smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt)
{ {
f.serial(smIt->second.first); // name f.serial(smIt->second.first); // name
f.serialPolyPtr(smIt->second.second); // scheme f.serialPolyPtr(smIt->second.second); // scheme
} }
} }
else else
{ {
_SchemeMap.clear(); _SchemeMap.clear();
std::string name; std::string name;
NL3D::CPSAttribMakerBase *scheme = NULL; NL3D::CPSAttribMakerBase *scheme = NULL;
sint32 size; sint32 size;
f.serial(size); f.serial(size);
for (sint32 k = 0; k < size; ++k) for (sint32 k = 0; k < size; ++k)
{ {
f.serial(name); f.serial(name);
f.serialPolyPtr(scheme); f.serialPolyPtr(scheme);
insertScheme(name, 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); this->_SchemeMap.swap(other._SchemeMap);
} }
void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am) void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am)
{ {
TSchemeMap::iterator smIt; TSchemeMap::iterator smIt;
for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++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 // 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; TSchemeMap::iterator smIt;
for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++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()) if (smIt != _SchemeMap.end())
{ {
smIt->second.first = newName; smIt->second.first = newName;
} }
} }