Added #1193 Added scheme bank dialog in particles editor.
This commit is contained in:
parent
3524ec9d64
commit
afdafa1a8a
7 changed files with 217 additions and 65 deletions
|
@ -91,7 +91,7 @@
|
|||
<item>
|
||||
<widget class="QPushButton" name="bankButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -73,6 +73,7 @@ void CParticleEditor::release()
|
|||
{
|
||||
stop();
|
||||
closeWorkspace();
|
||||
delete _SchemeManager;
|
||||
}
|
||||
|
||||
void CParticleEditor::setActiveNode(CWorkspaceNode *node)
|
||||
|
|
|
@ -1,24 +1,33 @@
|
|||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// 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 <http://dev.ryzom.com/projects/nel/>
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Project includes
|
||||
#include "stdpch.h"
|
||||
#include "scheme_bank_dialog.h"
|
||||
#include "scheme_manager.h"
|
||||
#include "modules.h"
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/file.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
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<CSchemeItem *>(_ui.listWidget->currentItem());
|
||||
|
||||
NL3D::CPSAttribMakerBase *attrib = item->getUserData();
|
||||
nlassert(attrib);
|
||||
|
||||
_attribWidget->setCurrentSchemePtr(attrib->clone());
|
||||
_attribWidget->updateUi();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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<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 */
|
|
@ -1,17 +1,17 @@
|
|||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// 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 <http://dev.ryzom.com/projects/nel/>
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#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;
|
||||
|
|
|
@ -14,31 +14,27 @@
|
|||
<string>Sceme bank</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" rowspan="8">
|
||||
<item row="0" column="0" rowspan="7">
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="createButton">
|
||||
<property name="text">
|
||||
<string>Create</string>
|
||||
<string>Put current</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="4" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
@ -51,24 +47,33 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<item row="5" column="1">
|
||||
<widget class="QPushButton" name="loadButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load bank</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="saveButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save bank</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<item row="7" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -105,7 +110,10 @@
|
|||
</layout>
|
||||
</item>
|
||||
<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">
|
||||
<string>Set current</string>
|
||||
</property>
|
||||
|
|
|
@ -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<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)
|
||||
{
|
||||
|
||||
|
||||
f.serialCheck((uint32) '_GNM');
|
||||
f.serialCheck((uint32) 'MHCS');
|
||||
f.serialVersion(1);
|
||||
if (!f.isReading())
|
||||
{
|
||||
sint32 size = (sint32)_SchemeMap.size();
|
||||
f.serial(size);
|
||||
{
|
||||
sint32 size = (sint32)_SchemeMap.size();
|
||||
f.serial(size);
|
||||
for (TSchemeMap::iterator smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt)
|
||||
{
|
||||
f.serial(smIt->second.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue