forked from mirror/openmw-tes3mp
Add autocomplete to the "Start default character at" field
This commit is contained in:
parent
d42791e260
commit
fb27f34a32
8 changed files with 136 additions and 0 deletions
|
@ -8,6 +8,7 @@ set(LAUNCHER
|
||||||
settingspage.cpp
|
settingspage.cpp
|
||||||
advancedpage.cpp
|
advancedpage.cpp
|
||||||
|
|
||||||
|
utils/cellnameloader.cpp
|
||||||
utils/profilescombobox.cpp
|
utils/profilescombobox.cpp
|
||||||
utils/textinputdialog.cpp
|
utils/textinputdialog.cpp
|
||||||
utils/lineedit.cpp
|
utils/lineedit.cpp
|
||||||
|
@ -24,6 +25,7 @@ set(LAUNCHER_HEADER
|
||||||
settingspage.hpp
|
settingspage.hpp
|
||||||
advancedpage.hpp
|
advancedpage.hpp
|
||||||
|
|
||||||
|
utils/cellnameloader.hpp
|
||||||
utils/profilescombobox.hpp
|
utils/profilescombobox.hpp
|
||||||
utils/textinputdialog.hpp
|
utils/textinputdialog.hpp
|
||||||
utils/lineedit.hpp
|
utils/lineedit.hpp
|
||||||
|
@ -39,6 +41,7 @@ set(LAUNCHER_HEADER_MOC
|
||||||
settingspage.hpp
|
settingspage.hpp
|
||||||
advancedpage.hpp
|
advancedpage.hpp
|
||||||
|
|
||||||
|
utils/cellnameloader.hpp
|
||||||
utils/textinputdialog.hpp
|
utils/textinputdialog.hpp
|
||||||
utils/profilescombobox.hpp
|
utils/profilescombobox.hpp
|
||||||
utils/lineedit.hpp
|
utils/lineedit.hpp
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
#include "advancedpage.hpp"
|
#include "advancedpage.hpp"
|
||||||
|
|
||||||
#include <components/config/gamesettings.hpp>
|
#include <components/config/gamesettings.hpp>
|
||||||
|
#include <components/config/launchersettings.hpp>
|
||||||
|
#include <apps/launcher/utils/cellnameloader.hpp>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QCompleter>
|
||||||
|
#include <components/contentselector/view/contentselector.hpp>
|
||||||
|
#include <components/contentselector/model/esmfile.hpp>
|
||||||
|
|
||||||
Launcher::AdvancedPage::AdvancedPage(Files::ConfigurationManager &cfg,
|
Launcher::AdvancedPage::AdvancedPage(Files::ConfigurationManager &cfg,
|
||||||
Config::GameSettings &gameSettings,
|
Config::GameSettings &gameSettings,
|
||||||
|
@ -17,6 +22,19 @@ Launcher::AdvancedPage::AdvancedPage(Files::ConfigurationManager &cfg,
|
||||||
loadSettings();
|
loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Launcher::AdvancedPage::loadCellsForAutocomplete(QStringList filePaths) {
|
||||||
|
CellNameLoader cellNameLoader;
|
||||||
|
QStringList cellNamesList = QStringList::fromSet(cellNameLoader.getCellNames(filePaths));
|
||||||
|
std::sort(cellNamesList.begin(), cellNamesList.end());
|
||||||
|
|
||||||
|
// Set up an auto-completer for the "Start default character at" field
|
||||||
|
auto *completer = new QCompleter(cellNamesList);
|
||||||
|
completer->setCompletionMode(QCompleter::PopupCompletion);
|
||||||
|
completer->setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||||
|
startDefaultCharacterAtField->setCompleter(completer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Launcher::AdvancedPage::on_skipMenuCheckBox_stateChanged(int state) {
|
void Launcher::AdvancedPage::on_skipMenuCheckBox_stateChanged(int state) {
|
||||||
startDefaultCharacterAtLabel->setEnabled(state == Qt::Checked);
|
startDefaultCharacterAtLabel->setEnabled(state == Qt::Checked);
|
||||||
startDefaultCharacterAtField->setEnabled(state == Qt::Checked);
|
startDefaultCharacterAtField->setEnabled(state == Qt::Checked);
|
||||||
|
|
|
@ -23,6 +23,12 @@ namespace Launcher
|
||||||
bool loadSettings();
|
bool loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the cells associated with the given content files for use in autocomplete
|
||||||
|
* @param filePaths the file paths of the content files to be examined
|
||||||
|
*/
|
||||||
|
void loadCellsForAutocomplete(QStringList filePaths);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_skipMenuCheckBox_stateChanged(int state);
|
void on_skipMenuCheckBox_stateChanged(int state);
|
||||||
void on_runScriptAfterStartupBrowseButton_clicked();
|
void on_runScriptAfterStartupBrowseButton_clicked();
|
||||||
|
|
|
@ -142,6 +142,17 @@ void Launcher::DataFilesPage::saveSettings(const QString &profile)
|
||||||
mGameSettings.setContentList(fileNames);
|
mGameSettings.setContentList(fileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList Launcher::DataFilesPage::selectedFilePaths()
|
||||||
|
{
|
||||||
|
//retrieve the files selected for the profile
|
||||||
|
ContentSelectorModel::ContentFileList items = mSelector->selectedFiles();
|
||||||
|
QStringList filePaths;
|
||||||
|
foreach(const ContentSelectorModel::EsmFile *item, items) {
|
||||||
|
filePaths.append(item->filePath());
|
||||||
|
}
|
||||||
|
return filePaths;
|
||||||
|
}
|
||||||
|
|
||||||
void Launcher::DataFilesPage::removeProfile(const QString &profile)
|
void Launcher::DataFilesPage::removeProfile(const QString &profile)
|
||||||
{
|
{
|
||||||
mLauncherSettings.removeContentList(profile);
|
mLauncherSettings.removeContentList(profile);
|
||||||
|
|
|
@ -41,6 +41,12 @@ namespace Launcher
|
||||||
void saveSettings(const QString &profile = "");
|
void saveSettings(const QString &profile = "");
|
||||||
bool loadSettings();
|
bool loadSettings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the file paths of all selected content files
|
||||||
|
* @return the file paths of all selected content files
|
||||||
|
*/
|
||||||
|
QStringList selectedFilePaths();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signalProfileChanged (int index);
|
void signalProfileChanged (int index);
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,9 @@ void Launcher::MainDialog::createPages()
|
||||||
mPlayPage->setProfilesModel(mDataFilesPage->profilesModel());
|
mPlayPage->setProfilesModel(mDataFilesPage->profilesModel());
|
||||||
mPlayPage->setProfilesIndex(mDataFilesPage->profilesIndex());
|
mPlayPage->setProfilesIndex(mDataFilesPage->profilesIndex());
|
||||||
|
|
||||||
|
// Load cells for the "Start default character at" field
|
||||||
|
mAdvancedPage->loadCellsForAutocomplete(mDataFilesPage->selectedFilePaths());
|
||||||
|
|
||||||
// Add the pages to the stacked widget
|
// Add the pages to the stacked widget
|
||||||
pagesWidget->addWidget(mPlayPage);
|
pagesWidget->addWidget(mPlayPage);
|
||||||
pagesWidget->addWidget(mDataFilesPage);
|
pagesWidget->addWidget(mDataFilesPage);
|
||||||
|
|
48
apps/launcher/utils/cellnameloader.cpp
Normal file
48
apps/launcher/utils/cellnameloader.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include "cellnameloader.hpp"
|
||||||
|
|
||||||
|
#include <components/esm/loadcell.hpp>
|
||||||
|
#include <components/contentselector/view/contentselector.hpp>
|
||||||
|
|
||||||
|
QSet<QString> CellNameLoader::getCellNames(QStringList &contentPaths)
|
||||||
|
{
|
||||||
|
QSet<QString> cellNames;
|
||||||
|
ESM::ESMReader esmReader;
|
||||||
|
|
||||||
|
// Loop through all content files
|
||||||
|
for (auto &contentPath : contentPaths) {
|
||||||
|
esmReader.open(contentPath.toStdString());
|
||||||
|
|
||||||
|
// Loop through all records
|
||||||
|
while(esmReader.hasMoreRecs())
|
||||||
|
{
|
||||||
|
ESM::NAME recordName = esmReader.getRecName();
|
||||||
|
esmReader.getRecHeader();
|
||||||
|
|
||||||
|
if (isCellRecord(recordName)) {
|
||||||
|
QString cellName = getCellName(esmReader);
|
||||||
|
if (!cellName.isEmpty()) {
|
||||||
|
cellNames.insert(cellName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop loading content for this record and continue to the next
|
||||||
|
esmReader.skipRecord();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cellNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CellNameLoader::isCellRecord(ESM::NAME &recordName)
|
||||||
|
{
|
||||||
|
return recordName.intval == ESM::REC_CELL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CellNameLoader::getCellName(ESM::ESMReader &esmReader)
|
||||||
|
{
|
||||||
|
ESM::Cell cell;
|
||||||
|
bool isDeleted = false;
|
||||||
|
cell.loadNameAndData(esmReader, isDeleted);
|
||||||
|
|
||||||
|
return QString::fromStdString(cell.mName);
|
||||||
|
}
|
41
apps/launcher/utils/cellnameloader.hpp
Normal file
41
apps/launcher/utils/cellnameloader.hpp
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#ifndef OPENMW_CELLNAMELOADER_H
|
||||||
|
#define OPENMW_CELLNAMELOADER_H
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QSet>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include <components/esm/esmreader.hpp>
|
||||||
|
|
||||||
|
namespace ESM {class ESMReader; struct Cell;}
|
||||||
|
namespace ContentSelectorView {class ContentSelector;}
|
||||||
|
|
||||||
|
class CellNameLoader {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the names of all cells contained within the given content files
|
||||||
|
* @param contentPaths the file paths of each content file to be examined
|
||||||
|
* @return the names of all cells
|
||||||
|
*/
|
||||||
|
QSet<QString> getCellNames(QStringList &contentPaths);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Returns whether or not the given record is of type "Cell"
|
||||||
|
* @param name The name associated with the record
|
||||||
|
* @return whether or not the given record is of type "Cell"
|
||||||
|
*/
|
||||||
|
bool isCellRecord(ESM::NAME &name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the cell
|
||||||
|
* @param esmReader the reader currently pointed to a loaded cell
|
||||||
|
* @return the name of the cell
|
||||||
|
*/
|
||||||
|
QString getCellName(ESM::ESMReader &esmReader);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //OPENMW_CELLNAMELOADER_H
|
Loading…
Reference in a new issue