From 0d52596ac2e773e585d8fb4a17723a8230ec9ec5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 24 Jul 2012 06:58:47 +0200 Subject: [PATCH] CHANGED: #1471 The procedure list window is now fully implemented ( can add/remove/edit procedures ). --- code/nel/include/nel/gui/interface_parser.h | 21 ++++-- code/nel/include/nel/gui/parser.h | 6 +- code/nel/include/nel/gui/proc.h | 35 ++++++++++ code/nel/src/gui/interface_parser.cpp | 31 +++++++++ .../src/plugins/gui_editor/proc_editor.cpp | 21 +++++- .../src/plugins/gui_editor/proc_editor.h | 3 + .../src/plugins/gui_editor/proc_list.cpp | 69 ++++++++++++++++++- .../src/plugins/gui_editor/proc_list.h | 3 + 8 files changed, 179 insertions(+), 10 deletions(-) diff --git a/code/nel/include/nel/gui/interface_parser.h b/code/nel/include/nel/gui/interface_parser.h index be333044c..f2c16ebe4 100644 --- a/code/nel/include/nel/gui/interface_parser.h +++ b/code/nel/include/nel/gui/interface_parser.h @@ -233,6 +233,15 @@ namespace NLGUI void removeAll(); // @} + protected: + /// Procedure list + typedef TProcedureMap::iterator ItProcedureMap; + typedef TProcedureMap::const_iterator CstItProcedureMap; + TProcedureMap _ProcedureMap; + + public: + + // get info on procedure. return 0 if procedure not found uint getProcedureNumActions( const std::string &procName ) const; @@ -245,6 +254,8 @@ namespace NLGUI CProcedure* getProc( const std::string &name ); + const TProcedureMap& getProcMap() const{ return _ProcedureMap; } + protected: /** @@ -288,12 +299,6 @@ namespace NLGUI }; - /// Procedure list - typedef std::map TProcedureMap; - typedef TProcedureMap::iterator ItProcedureMap; - typedef TProcedureMap::const_iterator CstItProcedureMap; - TProcedureMap _ProcedureMap; - // mgt of sheet selections (inventory, buy, sell..) CCtrlSheetSelection _CtrlSheetSelection; @@ -331,6 +336,10 @@ namespace NLGUI void reloadAllLuaFileScripts(); void setSetupOptionsCallback( ISetupOptionCallbackClass *cb ){ setupCallback = cb; } + + bool hasProc( const std::string &name ) const; + bool addProc( const std::string &name ); + bool removeProc( const std::string &name ); }; } diff --git a/code/nel/include/nel/gui/parser.h b/code/nel/include/nel/gui/parser.h index e9736ec2a..06fdc4c62 100644 --- a/code/nel/include/nel/gui/parser.h +++ b/code/nel/include/nel/gui/parser.h @@ -21,13 +21,13 @@ #include #include #include "nel/misc/types_nl.h" +#include "nel/gui/proc.h" namespace NLGUI { class CInterfaceElement; class CInterfaceGroup; class CInterfaceAnim; - class CProcedure; class CCtrlSheetSelection; class CInterfaceLink; @@ -52,6 +52,7 @@ namespace NLGUI virtual const std::string& getDefine(const std::string &id) const = 0; virtual CInterfaceAnim* getAnim( const std::string &name ) const = 0; virtual CProcedure* getProc( const std::string &name ) = 0; + virtual const TProcedureMap& getProcMap() const = 0; virtual bool parseInterface( const std::vector< std::string > &xmlFileNames, bool reload, bool isFilename = true, bool checkInData = false ) = 0; virtual void initLUA() = 0; virtual void uninitLUA() = 0; @@ -67,6 +68,9 @@ namespace NLGUI virtual bool addLink( CInterfaceLink *link, const std::string &id ) = 0; virtual bool removeLink( const std::string &id ) = 0; virtual void removeAll() = 0; + virtual bool hasProc( const std::string &name ) const = 0; + virtual bool addProc( const std::string &name ) = 0; + virtual bool removeProc( const std::string &name ) = 0; }; } diff --git a/code/nel/include/nel/gui/proc.h b/code/nel/include/nel/gui/proc.h index ea3c382ed..20b4a8977 100644 --- a/code/nel/include/nel/gui/proc.h +++ b/code/nel/include/nel/gui/proc.h @@ -21,6 +21,7 @@ #include "nel/misc/types_nl.h" #include #include +#include namespace NLGUI { @@ -65,12 +66,46 @@ namespace NLGUI }; + class CActionNameIs + { + public: + CActionNameIs( const std::string &n ) + { + name = n; + } + + bool operator()( const CProcAction &action ) + { + if( action.Action == name ) + return true; + else + return false; + } + + private: + std::string name; + }; + + class CProcedure { public: // List of the actions std::vector< CProcAction > Actions; + + bool hasAction( const std::string &name ) const + { + std::vector< CProcAction >::const_iterator itr + = std::find_if( Actions.begin(), Actions.end(), CActionNameIs( name ) ); + if( itr != Actions.end() ) + return true; + else + return false; + } + }; + + typedef std::map< std::string, CProcedure > TProcedureMap; } #endif diff --git a/code/nel/src/gui/interface_parser.cpp b/code/nel/src/gui/interface_parser.cpp index 12b04244d..8bb20e5aa 100644 --- a/code/nel/src/gui/interface_parser.cpp +++ b/code/nel/src/gui/interface_parser.cpp @@ -2777,5 +2777,36 @@ namespace NLGUI } } } + + bool CInterfaceParser::hasProc( const std::string &name ) const + { + TProcedureMap::const_iterator itr + = _ProcedureMap.find( name ); + if( itr != _ProcedureMap.end() ) + return true; + else + return false; + } + + bool CInterfaceParser::addProc( const std::string &name ) + { + if( hasProc( name ) ) + return false; + + _ProcedureMap[ name ] = CProcedure(); + + return true; + } + + bool CInterfaceParser::removeProc( const std::string &name ) + { + TProcedureMap::iterator itr = + _ProcedureMap.find( name ); + if( itr == _ProcedureMap.end() ) + return false; + + _ProcedureMap.erase( itr ); + return true; + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.cpp index c9c728603..02941d6c8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.cpp @@ -17,7 +17,8 @@ #include "proc_editor.h" #include "action_editor.h" - +#include "nel/gui/interface_group.h" +#include "nel/gui/widget_manager.h" namespace GUIEditor { @@ -28,7 +29,6 @@ namespace GUIEditor connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); connect( editButton, SIGNAL( clicked( bool ) ), actionEditor, SLOT( show() ) ); - } ProcEditor::~ProcEditor() @@ -36,4 +36,21 @@ namespace GUIEditor delete actionEditor; actionEditor = NULL; } + + void ProcEditor::setCurrentProc( const QString &name ) + { + actionList->clear(); + + currentProc = name; + IParser *parser = CWidgetManager::getInstance()->getParser(); + CProcedure *proc = parser->getProc( name.toStdString() ); + + std::vector< CProcAction >::const_iterator itr; + for( itr = proc->Actions.begin(); itr != proc->Actions.end(); ++itr ) + { + actionList->addItem( itr->Action.c_str() ); + } + + setWindowTitle( QString( "Procedure Editor - %1" ).arg( currentProc ) ); + } } \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.h index b7ee0bff2..f82590f81 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_editor.h @@ -31,8 +31,11 @@ namespace GUIEditor ProcEditor( QWidget *parent = NULL ); ~ProcEditor(); + void setCurrentProc( const QString &name ); + private: ActionEditor *actionEditor; + QString currentProc; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.cpp index ed39ef31e..d1822c999 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.cpp @@ -17,6 +17,10 @@ #include "proc_list.h" #include "proc_editor.h" +#include +#include +#include "nel/gui/interface_group.h" +#include "nel/gui/widget_manager.h" namespace GUIEditor { @@ -29,6 +33,8 @@ namespace GUIEditor connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOkButtonClicked() ) ); connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditButtonClicked() ) ); + connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddButtonClicked() ) ); + connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveButtonClicked() ) ); } ProcList::~ProcList() @@ -38,7 +44,7 @@ namespace GUIEditor void ProcList::onGUILoaded() { - + setupProcList(); } void ProcList::onOkButtonClicked() @@ -48,7 +54,68 @@ namespace GUIEditor void ProcList::onEditButtonClicked() { + IParser *parser = CWidgetManager::getInstance()->getParser(); + QListWidgetItem *item = procList->item( procList->currentRow() ); + if( item == NULL ) + return; + + CProcedure *proc = parser->getProc( item->text().toStdString() ); + if( proc == NULL ) + return; + + procEditor->setCurrentProc( item->text() ); procEditor->show(); } + + void ProcList::onAddButtonClicked() + { + bool ok; + QString newProc = + QInputDialog::getText( this, + tr( "Adding a new procedure" ), + tr( "Please specify the name of the new procedure" ), + QLineEdit::Normal, + QString(), + &ok ); + if( ok ) + { + IParser *parser = CWidgetManager::getInstance()->getParser(); + if( !parser->addProc( newProc.toStdString() ) ) + { + QMessageBox::critical( this, + tr( "Cannot add new procedure" ), + tr( "There was an error adding the new procedure" ) ); + } + procList->addItem( newProc ); + procList->sortItems(); + } + } + + void ProcList::onRemoveButtonClicked() + { + IParser *parser = CWidgetManager::getInstance()->getParser(); + QListWidgetItem *item = procList->item( procList->currentRow() ); + if( item == NULL ) + return; + + if( !parser->removeProc( item->text().toStdString() ) ) + return; + item = procList->takeItem( procList->currentRow() ); + delete item; + } + + void ProcList::setupProcList() + { + procList->clear(); + + const TProcedureMap& procMap = + CWidgetManager::getInstance()->getParser()->getProcMap(); + + TProcedureMap::const_iterator itr; + for( itr = procMap.begin(); itr != procMap.end(); ++itr ) + { + procList->addItem( itr->first.c_str() ); + } + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.h index e26b03e06..a5a83b2eb 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/proc_list.h @@ -37,8 +37,11 @@ namespace GUIEditor private Q_SLOTS: void onOkButtonClicked(); void onEditButtonClicked(); + void onAddButtonClicked(); + void onRemoveButtonClicked(); private: + void setupProcList(); ProcEditor *procEditor; }; }