mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-26 14:56:39 +00:00 
			
		
		
		
	Improve start script creation (Fixes #3024)
Improved start script creation by updating input to be a drop target and adding auto-completion.
This commit is contained in:
		
							parent
							
								
									07a4c0bf73
								
							
						
					
					
						commit
						b93b97575e
					
				
					 3 changed files with 186 additions and 23 deletions
				
			
		|  | @ -1,20 +1,130 @@ | ||||||
| #include "startscriptcreator.hpp" | #include "startscriptcreator.hpp" | ||||||
| 
 | 
 | ||||||
| CSVWorld::StartScriptCreator::StartScriptCreator(CSMWorld::Data &data, QUndoStack &undoStack, const CSMWorld::UniversalId &id, bool relaxedIdRules): | #include <QLabel> | ||||||
|     GenericCreator (data, undoStack, id, true) | 
 | ||||||
| {} | #include "../../model/doc/document.hpp" | ||||||
|  | 
 | ||||||
|  | #include "../../model/world/columns.hpp" | ||||||
|  | #include "../../model/world/commands.hpp" | ||||||
|  | #include "../../model/world/data.hpp" | ||||||
|  | #include "../../model/world/idcompletionmanager.hpp" | ||||||
|  | #include "../../model/world/idtable.hpp" | ||||||
|  | 
 | ||||||
|  | #include "../widget/droplineedit.hpp" | ||||||
|  | 
 | ||||||
|  | std::string CSVWorld::StartScriptCreator::getId() const | ||||||
|  | { | ||||||
|  |     return mScript->text().toUtf8().constData(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | CSMWorld::IdTable& CSVWorld::StartScriptCreator::getStartScriptsTable() const | ||||||
|  | { | ||||||
|  |     return dynamic_cast<CSMWorld::IdTable&> ( | ||||||
|  |         *getData().getTableModel(getCollectionId()) | ||||||
|  |     ); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void CSVWorld::StartScriptCreator::configureCreateCommand(CSMWorld::CreateCommand& command) const | ||||||
|  | { | ||||||
|  |     CSMWorld::IdTable& table = getStartScriptsTable(); | ||||||
|  |     int column = table.findColumnIndex(CSMWorld::Columns::ColumnId_Id); | ||||||
|  | 
 | ||||||
|  |     // Set script ID to be added to start scripts table.
 | ||||||
|  |     command.addValue(column, mScript->text()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | CSVWorld::StartScriptCreator::StartScriptCreator( | ||||||
|  |     CSMWorld::Data &data, | ||||||
|  |     QUndoStack &undoStack, | ||||||
|  |     const CSMWorld::UniversalId &id, | ||||||
|  |     CSMWorld::IdCompletionManager& completionManager | ||||||
|  | ) : GenericCreator(data, undoStack, id, true) | ||||||
|  | { | ||||||
|  |     setManualEditing(false); | ||||||
|  | 
 | ||||||
|  |     // Add script ID input label.
 | ||||||
|  |     QLabel *label = new QLabel("Script ID", this); | ||||||
|  |     insertBeforeButtons(label, false); | ||||||
|  | 
 | ||||||
|  |     // Add script ID input with auto-completion.
 | ||||||
|  |     CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Script; | ||||||
|  |     mScript = new CSVWidget::DropLineEdit(displayType, this); | ||||||
|  |     mScript->setCompleter(completionManager.getCompleter(displayType).get()); | ||||||
|  |     insertBeforeButtons(mScript, true); | ||||||
|  | 
 | ||||||
|  |     connect(mScript, SIGNAL (textChanged(const QString&)), this, SLOT (scriptChanged())); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void CSVWorld::StartScriptCreator::cloneMode( | ||||||
|  |     const std::string& originId, | ||||||
|  |     const CSMWorld::UniversalId::Type type) | ||||||
|  | { | ||||||
|  |     CSVWorld::GenericCreator::cloneMode(originId, type); | ||||||
|  | 
 | ||||||
|  |     // Look up cloned record in start scripts table and set script ID text.
 | ||||||
|  |     CSMWorld::IdTable& table = getStartScriptsTable(); | ||||||
|  |     int column = table.findColumnIndex(CSMWorld::Columns::ColumnId_Id); | ||||||
|  |     mScript->setText(table.data(table.getModelIndex(originId, column)).toString()); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| std::string CSVWorld::StartScriptCreator::getErrors() const | std::string CSVWorld::StartScriptCreator::getErrors() const | ||||||
| { | { | ||||||
|     std::string errors; |     std::string scriptId = getId(); | ||||||
| 
 | 
 | ||||||
|     errors = getIdValidatorResult(); |     // Check user input for any errors.
 | ||||||
|     if (errors.length() > 0) |     std::string errors; | ||||||
|         return errors; |     if (scriptId.empty()) | ||||||
|     else if (getData().getScripts().searchId(getId()) == -1) |     { | ||||||
|         errors = "Script ID not found"; |         if (!errors.empty()) | ||||||
|     else if (getData().getStartScripts().searchId(getId()) > -1 ) |         { | ||||||
|         errors = "Script with this ID already registered as Start Script"; |             errors += "<br>"; | ||||||
|  |         } | ||||||
|  |         errors += "No Script ID entered"; | ||||||
|  |     } | ||||||
|  |     else if (getData().getScripts().searchId(scriptId) == -1) | ||||||
|  |     { | ||||||
|  |         if (!errors.empty()) | ||||||
|  |         { | ||||||
|  |             errors += "<br>"; | ||||||
|  |         } | ||||||
|  |         errors += "Script ID not found"; | ||||||
|  |     } | ||||||
|  |     else if (getData().getStartScripts().searchId(scriptId) > -1) | ||||||
|  |     { | ||||||
|  |         if (!errors.empty()) | ||||||
|  |         { | ||||||
|  |             errors += "<br>"; | ||||||
|  |         } | ||||||
|  |         errors += "Script with this ID already registered as Start Script"; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return errors; |     return errors; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void CSVWorld::StartScriptCreator::focus() | ||||||
|  | { | ||||||
|  |     mScript->setFocus(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void CSVWorld::StartScriptCreator::reset() | ||||||
|  | { | ||||||
|  |     CSVWorld::GenericCreator::reset(); | ||||||
|  |     mScript->setText(""); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void CSVWorld::StartScriptCreator::scriptChanged() | ||||||
|  | { | ||||||
|  |     update(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | CSVWorld::Creator *CSVWorld::StartScriptCreatorFactory::makeCreator( | ||||||
|  |     CSMDoc::Document& document, | ||||||
|  |     const CSMWorld::UniversalId& id) const | ||||||
|  | { | ||||||
|  |     return new StartScriptCreator( | ||||||
|  |         document.getData(), | ||||||
|  |         document.getUndoStack(), | ||||||
|  |         id, | ||||||
|  |         document.getIdCompletionManager() | ||||||
|  |     ); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -3,23 +3,77 @@ | ||||||
| 
 | 
 | ||||||
| #include "genericcreator.hpp" | #include "genericcreator.hpp" | ||||||
| 
 | 
 | ||||||
| namespace CSVWorld { | namespace CSMWorld | ||||||
|  | { | ||||||
|  |     class IdCompletionManager; | ||||||
|  |     class IdTable; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
|  | namespace CSVWidget | ||||||
|  | { | ||||||
|  |     class DropLineEdit; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | namespace CSVWorld | ||||||
|  | { | ||||||
|  |     /// \brief Record creator for start scripts.
 | ||||||
|     class StartScriptCreator : public GenericCreator |     class StartScriptCreator : public GenericCreator | ||||||
|     { |     { | ||||||
|         Q_OBJECT |         Q_OBJECT | ||||||
| 
 | 
 | ||||||
|         public: |         CSVWidget::DropLineEdit *mScript; | ||||||
|             StartScriptCreator(CSMWorld::Data& data, QUndoStack& undoStack, |  | ||||||
|                                const CSMWorld::UniversalId& id, bool relaxedIdRules = false); |  | ||||||
| 
 | 
 | ||||||
|  |         private: | ||||||
|  | 
 | ||||||
|  |             /// \return script ID entered by user.
 | ||||||
|  |             virtual std::string getId() const; | ||||||
|  | 
 | ||||||
|  |             /// \return reference to table containing start scripts.
 | ||||||
|  |             CSMWorld::IdTable& getStartScriptsTable() const; | ||||||
|  | 
 | ||||||
|  |             /// \brief Add user input to command for creating start script.
 | ||||||
|  |             /// \param command Creation command to configure.
 | ||||||
|  |             virtual void configureCreateCommand(CSMWorld::CreateCommand& command) const; | ||||||
|  | 
 | ||||||
|  |         public: | ||||||
|  | 
 | ||||||
|  |             StartScriptCreator( | ||||||
|  |                 CSMWorld::Data& data, | ||||||
|  |                 QUndoStack& undoStack, | ||||||
|  |                 const CSMWorld::UniversalId& id, | ||||||
|  |                 CSMWorld::IdCompletionManager& completionManager); | ||||||
|  | 
 | ||||||
|  |             /// \brief Set script ID input widget to ID of record to be cloned.
 | ||||||
|  |             /// \param originId Script ID to be cloned.
 | ||||||
|  |             /// \param type Type of record to be cloned.
 | ||||||
|  |             virtual void cloneMode( | ||||||
|  |                 const std::string& originId, | ||||||
|  |                 const CSMWorld::UniversalId::Type type); | ||||||
|  | 
 | ||||||
|  |             /// \return Formatted error descriptions for current user input.
 | ||||||
|             virtual std::string getErrors() const; |             virtual std::string getErrors() const; | ||||||
|             ///< Return formatted error descriptions for the current state of the creator. if an empty
 | 
 | ||||||
|             /// string is returned, there is no error.
 |             /// \brief Set focus to script ID input widget.
 | ||||||
|  |             virtual void focus(); | ||||||
|  | 
 | ||||||
|  |             /// \brief Clear script ID input widget.
 | ||||||
|  |             virtual void reset(); | ||||||
|  | 
 | ||||||
|  |         private slots: | ||||||
|  | 
 | ||||||
|  |             /// \brief Check user input for any errors.
 | ||||||
|  |             void scriptChanged(); | ||||||
|      }; |      }; | ||||||
| 
 | 
 | ||||||
|  |      /// \brief Creator factory for start script record creator.
 | ||||||
|  |      class StartScriptCreatorFactory : public CreatorFactoryBase | ||||||
|  |      { | ||||||
|  |         public: | ||||||
|  | 
 | ||||||
|  |             virtual Creator *makeCreator( | ||||||
|  |                 CSMDoc::Document& document, | ||||||
|  |                 const CSMWorld::UniversalId& id) const; | ||||||
|  |      }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| #endif // STARTSCRIPTCREATOR_HPP
 | #endif // STARTSCRIPTCREATOR_HPP
 | ||||||
|  |  | ||||||
|  | @ -52,7 +52,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) | ||||||
|             new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<GenericCreator> >); |             new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<GenericCreator> >); | ||||||
| 
 | 
 | ||||||
|     manager.add (CSMWorld::UniversalId::Type_StartScripts, |     manager.add (CSMWorld::UniversalId::Type_StartScripts, | ||||||
|         new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<StartScriptCreator> >); |         new CSVDoc::SubViewFactoryWithCreator<TableSubView, StartScriptCreatorFactory>); | ||||||
| 
 | 
 | ||||||
|     manager.add (CSMWorld::UniversalId::Type_Cells, |     manager.add (CSMWorld::UniversalId::Type_Cells, | ||||||
|         new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<CellCreator> >); |         new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<CellCreator> >); | ||||||
|  | @ -136,8 +136,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) | ||||||
|             CreatorFactory<GenericCreator> > (false)); |             CreatorFactory<GenericCreator> > (false)); | ||||||
| 
 | 
 | ||||||
|     manager.add (CSMWorld::UniversalId::Type_StartScript, |     manager.add (CSMWorld::UniversalId::Type_StartScript, | ||||||
|         new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, |         new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, StartScriptCreatorFactory>(false)); | ||||||
|         CreatorFactory<StartScriptCreator> > (false)); |  | ||||||
| 
 | 
 | ||||||
|     manager.add (CSMWorld::UniversalId::Type_Skill, |     manager.add (CSMWorld::UniversalId::Type_Skill, | ||||||
|         new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, NullCreatorFactory > (false)); |         new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, NullCreatorFactory > (false)); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue