ShaderEditorWidget will now load/save it's content.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent c9cd9cdd3c
commit cc86cdd3ef

@ -142,7 +142,6 @@ namespace MaterialEditor
void MaterialEditorWindow::onShadersClicked() void MaterialEditorWindow::onShadersClicked()
{ {
shaderWidget->load();
shaderWidget->show(); shaderWidget->show();
} }

@ -133,6 +133,12 @@ namespace MaterialEditor
shaderCB->removeItem( i ); shaderCB->removeItem( i );
} }
void MaterialWidget::setNel3DIface( CNel3DInterface *iface )
{
nl3dIface = iface;
shaderEditorWidget->setNel3DInterface( iface );
}
void MaterialWidget::getCurrentPass( QString &pass ) void MaterialWidget::getCurrentPass( QString &pass )
{ {
pass = passCB->currentText(); pass = passCB->currentText();
@ -161,11 +167,8 @@ namespace MaterialEditor
void MaterialWidget::onShaderEditClicked() void MaterialWidget::onShaderEditClicked()
{ {
shaderEditorWidget->show(); shaderEditorWidget->load( shaderCB->currentText() );
} int result = shaderEditorWidget->exec();
void MaterialWidget::onShaderEditOKClicked()
{
} }
void MaterialWidget::onPassCBChanged( const QString &text ) void MaterialWidget::onPassCBChanged( const QString &text )

@ -45,7 +45,7 @@ namespace MaterialEditor
void onShaderAdded( const QString &name ); void onShaderAdded( const QString &name );
void onShaderRemoved( const QString &name ); void onShaderRemoved( const QString &name );
void setNel3DIface( CNel3DInterface *iface ){ nl3dIface = iface; } void setNel3DIface( CNel3DInterface *iface );
void getCurrentPass( QString &pass ); void getCurrentPass( QString &pass );
@ -62,7 +62,6 @@ namespace MaterialEditor
private Q_SLOTS: private Q_SLOTS:
void onPassEditClicked(); void onPassEditClicked();
void onShaderEditClicked(); void onShaderEditClicked();
void onShaderEditOKClicked();
void onPassCBChanged( const QString &text ); void onPassCBChanged( const QString &text );
}; };

@ -16,6 +16,7 @@
#include "shader_editor.h" #include "shader_editor.h"
#include "nel3d_interface.h"
namespace MaterialEditor namespace MaterialEditor
{ {
@ -23,6 +24,7 @@ namespace MaterialEditor
QDialog( parent ) QDialog( parent )
{ {
setupUi( this ); setupUi( this );
nl3dIface = NULL;
setupConnections(); setupConnections();
} }
@ -30,46 +32,11 @@ namespace MaterialEditor
{ {
} }
void ShaderEditorWidget::getName( QString &name )
{
name = nameEdit->text();
}
void ShaderEditorWidget::getDescription( QString &desc ) void ShaderEditorWidget::getDescription( QString &desc )
{ {
desc = descriptionEdit->toPlainText(); desc = descriptionEdit->toPlainText();
} }
void ShaderEditorWidget::getVertexShader( QString &vs )
{
vs = vsEdit->toPlainText();
}
void ShaderEditorWidget::getFragmentShader( QString &fs )
{
fs = fsEdit->toPlainText();
}
void ShaderEditorWidget::setName( const QString &name )
{
nameEdit->setText( name );
}
void ShaderEditorWidget::setDescription( const QString &desc )
{
descriptionEdit->setPlainText( desc );
}
void ShaderEditorWidget::setVertexShader( const QString &vs )
{
vsEdit->setPlainText( vs );
}
void ShaderEditorWidget::setFragmentShader( const QString &fs )
{
fsEdit->setPlainText( fs );
}
void ShaderEditorWidget::setupConnections() void ShaderEditorWidget::setupConnections()
{ {
connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) ) ; connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) ) ;
@ -78,6 +45,16 @@ namespace MaterialEditor
void ShaderEditorWidget::onOKClicked() void ShaderEditorWidget::onOKClicked()
{ {
SShaderInfo info;
info.name = nameEdit->text().toUtf8().data();
info.description = descriptionEdit->toPlainText().toUtf8().data();
info.vp = vsEdit->toPlainText().toUtf8().data();
info.fp = fsEdit->toPlainText().toUtf8().data();
bool ok = nl3dIface->updateShaderInfo( info );
if( ok )
nl3dIface->saveShader( info.name );
accept(); accept();
} }
@ -95,6 +72,18 @@ namespace MaterialEditor
fsEdit->setPlainText( empty ); fsEdit->setPlainText( empty );
setResult( QDialog::Rejected ); setResult( QDialog::Rejected );
} }
void ShaderEditorWidget::load( const QString &name )
{
SShaderInfo info;
nl3dIface->getShaderInfo( name.toUtf8().data(), info );
nameEdit->setText( info.name.c_str() );
descriptionEdit->setPlainText( info.description.c_str() );
vsEdit->setPlainText( info.vp.c_str() );
fsEdit->setPlainText( info.fp.c_str() );
}
} }

@ -22,6 +22,8 @@
namespace MaterialEditor namespace MaterialEditor
{ {
class CNel3DInterface;
class ShaderEditorWidget : public QDialog, public Ui::ShaderEditorWidget class ShaderEditorWidget : public QDialog, public Ui::ShaderEditorWidget
{ {
Q_OBJECT Q_OBJECT
@ -29,17 +31,12 @@ namespace MaterialEditor
ShaderEditorWidget( QDialog *parent = NULL ); ShaderEditorWidget( QDialog *parent = NULL );
~ShaderEditorWidget(); ~ShaderEditorWidget();
void getName( QString &name );
void getDescription( QString &desc ); void getDescription( QString &desc );
void getVertexShader( QString &vs );
void getFragmentShader( QString &fs );
void setName( const QString &name ); void setNel3DInterface( CNel3DInterface *iface ){ nl3dIface = iface; }
void setDescription( const QString &desc );
void setVertexShader( const QString &vs );
void setFragmentShader( const QString &fs );
void reset(); void reset();
void load( const QString &name );
private Q_SLOTS: private Q_SLOTS:
void onOKClicked(); void onOKClicked();
@ -47,6 +44,7 @@ namespace MaterialEditor
private: private:
void setupConnections(); void setupConnections();
CNel3DInterface *nl3dIface;
}; };
} }

@ -39,6 +39,12 @@ namespace MaterialEditor
shaderEditorWidget = NULL; shaderEditorWidget = NULL;
} }
void ShaderWidget::setNel3DInterface( CNel3DInterface *iface )
{
nl3dIface = iface;
shaderEditorWidget->setNel3DInterface( iface );
}
void ShaderWidget::load() void ShaderWidget::load()
{ {
std::vector< std::string > v; std::vector< std::string > v;
@ -185,54 +191,15 @@ namespace MaterialEditor
QString name = shaderList->item( i )->text(); QString name = shaderList->item( i )->text();
shaderEditorWidget->reset(); shaderEditorWidget->reset();
shaderEditorWidget->load( name );
SShaderInfo info;
std::string n = name.toUtf8().data();
bool ok = nl3dIface->getShaderInfo( n, info );
if( !ok )
{
QMessageBox::critical(
this,
tr( "Error retrieving shader data" ),
tr( "There was an error while trying to retrieve shader data!" )
);
return;
}
shaderEditorWidget->setName( info.name.c_str() );
shaderEditorWidget->setDescription( info.description.c_str() );
shaderEditorWidget->setVertexShader( info.vp.c_str() );
shaderEditorWidget->setFragmentShader( info.fp.c_str() );
int res = shaderEditorWidget->exec(); int res = shaderEditorWidget->exec();
if( res == QDialog::Rejected ) if( res == QDialog::Rejected )
return; return;
// save QString descr;
QString s; shaderEditorWidget->getDescription( descr );
description->setPlainText( descr );
shaderEditorWidget->getDescription( s );
info.description = s.toUtf8().data();
shaderEditorWidget->getVertexShader( s );
info.vp = s.toUtf8().data();
shaderEditorWidget->getFragmentShader( s );
info.fp = s.toUtf8().data();
ok = nl3dIface->updateShaderInfo( info );
if( !ok )
{
QMessageBox::critical(
this,
tr( "Error saving shader data" ),
tr( "There was an error while trying to save shader data!" )
);
}
nl3dIface->saveShader( info.name );
description->setPlainText( info.description.c_str() );
} }
void ShaderWidget::onRowChanged( int i ) void ShaderWidget::onRowChanged( int i )

@ -33,7 +33,7 @@ namespace MaterialEditor
ShaderWidget( QWidget *parent = NULL ); ShaderWidget( QWidget *parent = NULL );
~ShaderWidget(); ~ShaderWidget();
void setNel3DInterface( CNel3DInterface *iface ){ nl3dIface = iface; } void setNel3DInterface( CNel3DInterface *iface );
void load(); void load();
Q_SIGNALS: Q_SIGNALS:

Loading…
Cancel
Save