mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-19 21:56:13 +00:00
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)
|
||||
|
|
|
@ -17,8 +17,17 @@
|
|||
// 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::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 */
|
|
@ -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,6 +72,8 @@ private Q_SLOTS:
|
|||
void removeScheme();
|
||||
void saveBank();
|
||||
void loadBank();
|
||||
void enableButtons();
|
||||
void changeNameScheme(QListWidgetItem *item);
|
||||
|
||||
private:
|
||||
void buildList();
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue