mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 21:40:11 +00:00
Merge branch 'newgame'
This commit is contained in:
commit
554c44892a
@ -43,7 +43,8 @@ opencs_units_noqt (model/tools
|
|||||||
|
|
||||||
|
|
||||||
opencs_units (view/doc
|
opencs_units (view/doc
|
||||||
viewmanager view operations operation subview startup filedialog
|
viewmanager view operations operation subview startup filedialog newgame filewidget
|
||||||
|
adjusterwidget
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,27 +4,35 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QLocalServer>
|
#include <QLocalServer>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "model/doc/document.hpp"
|
#include "model/doc/document.hpp"
|
||||||
#include "model/world/data.hpp"
|
#include "model/world/data.hpp"
|
||||||
|
|
||||||
|
|
||||||
CS::Editor::Editor() : mViewManager (mDocumentManager)
|
CS::Editor::Editor() : mViewManager (mDocumentManager)
|
||||||
{
|
{
|
||||||
mIpcServerName = "org.openmw.OpenCS";
|
mIpcServerName = "org.openmw.OpenCS";
|
||||||
|
|
||||||
connect (&mViewManager, SIGNAL (newDocumentRequest ()), this, SLOT (createDocument ()));
|
setupDataFiles();
|
||||||
|
|
||||||
|
mNewGame.setLocalData (mLocal);
|
||||||
|
|
||||||
|
connect (&mViewManager, SIGNAL (newGameRequest ()), this, SLOT (createGame ()));
|
||||||
|
connect (&mViewManager, SIGNAL (newAddonRequest ()), this, SLOT (createAddon ()));
|
||||||
connect (&mViewManager, SIGNAL (loadDocumentRequest ()), this, SLOT (loadDocument ()));
|
connect (&mViewManager, SIGNAL (loadDocumentRequest ()), this, SLOT (loadDocument ()));
|
||||||
connect (&mViewManager, SIGNAL (editSettingsRequest()), this, SLOT (showSettings ()));
|
connect (&mViewManager, SIGNAL (editSettingsRequest()), this, SLOT (showSettings ()));
|
||||||
|
|
||||||
connect (&mStartup, SIGNAL (createGame()), this, SLOT (createDocument ())); /// \todo split
|
connect (&mStartup, SIGNAL (createGame()), this, SLOT (createGame ()));
|
||||||
connect (&mStartup, SIGNAL (createAddon()), this, SLOT (createDocument ()));
|
connect (&mStartup, SIGNAL (createAddon()), this, SLOT (createAddon ()));
|
||||||
connect (&mStartup, SIGNAL (loadDocument()), this, SLOT (loadDocument ()));
|
connect (&mStartup, SIGNAL (loadDocument()), this, SLOT (loadDocument ()));
|
||||||
connect (&mStartup, SIGNAL (editConfig()), this, SLOT (showSettings ()));
|
connect (&mStartup, SIGNAL (editConfig()), this, SLOT (showSettings ()));
|
||||||
|
|
||||||
connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles()));
|
connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles()));
|
||||||
connect (&mFileDialog, SIGNAL(createNewFile()), this, SLOT(createNewFile()));
|
connect (&mFileDialog, SIGNAL(createNewFile()), this, SLOT(createNewFile()));
|
||||||
|
|
||||||
setupDataFiles();
|
connect (&mNewGame, SIGNAL (createRequest (const boost::filesystem::path&)),
|
||||||
|
this, SLOT (createNewGame (const boost::filesystem::path&)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::setupDataFiles()
|
void CS::Editor::setupDataFiles()
|
||||||
@ -42,26 +50,39 @@ void CS::Editor::setupDataFiles()
|
|||||||
|
|
||||||
mCfgMgr.readConfiguration(variables, desc);
|
mCfgMgr.readConfiguration(variables, desc);
|
||||||
|
|
||||||
Files::PathContainer mDataDirs, mDataLocal;
|
Files::PathContainer dataDirs, dataLocal;
|
||||||
if (!variables["data"].empty()) {
|
if (!variables["data"].empty()) {
|
||||||
mDataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
|
dataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string local = variables["data-local"].as<std::string>();
|
std::string local = variables["data-local"].as<std::string>();
|
||||||
if (!local.empty()) {
|
if (!local.empty()) {
|
||||||
mDataLocal.push_back(Files::PathContainer::value_type(local));
|
dataLocal.push_back(Files::PathContainer::value_type(local));
|
||||||
}
|
}
|
||||||
|
|
||||||
mCfgMgr.processPaths(mDataDirs);
|
mCfgMgr.processPaths (dataDirs);
|
||||||
mCfgMgr.processPaths(mDataLocal);
|
mCfgMgr.processPaths (dataLocal, true);
|
||||||
|
|
||||||
|
if (!dataLocal.empty())
|
||||||
|
mLocal = dataLocal[0];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox messageBox;
|
||||||
|
messageBox.setWindowTitle (tr ("No local data path available"));
|
||||||
|
messageBox.setIcon (QMessageBox::Critical);
|
||||||
|
messageBox.setStandardButtons (QMessageBox::Ok);
|
||||||
|
messageBox.setText(tr("<br><b>OpenCS is unable to access the local data directory. This may indicate a faulty configuration or a broken install.</b>"));
|
||||||
|
messageBox.exec();
|
||||||
|
|
||||||
|
QApplication::exit (1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the charset for reading the esm/esp files
|
// Set the charset for reading the esm/esp files
|
||||||
QString encoding = QString::fromStdString(variables["encoding"].as<std::string>());
|
QString encoding = QString::fromStdString(variables["encoding"].as<std::string>());
|
||||||
mFileDialog.setEncoding(encoding);
|
mFileDialog.setEncoding(encoding);
|
||||||
|
|
||||||
Files::PathContainer dataDirs;
|
dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end());
|
||||||
dataDirs.insert(dataDirs.end(), mDataDirs.begin(), mDataDirs.end());
|
|
||||||
dataDirs.insert(dataDirs.end(), mDataLocal.begin(), mDataLocal.end());
|
|
||||||
|
|
||||||
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
||||||
{
|
{
|
||||||
@ -72,10 +93,20 @@ void CS::Editor::setupDataFiles()
|
|||||||
//load the settings into the userSettings instance.
|
//load the settings into the userSettings instance.
|
||||||
const QString settingFileName = "opencs.cfg";
|
const QString settingFileName = "opencs.cfg";
|
||||||
CSMSettings::UserSettings::instance().loadSettings(settingFileName);
|
CSMSettings::UserSettings::instance().loadSettings(settingFileName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::createDocument()
|
void CS::Editor::createGame()
|
||||||
|
{
|
||||||
|
mStartup.hide();
|
||||||
|
|
||||||
|
if (mNewGame.isHidden())
|
||||||
|
mNewGame.show();
|
||||||
|
|
||||||
|
mNewGame.raise();
|
||||||
|
mNewGame.activateWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CS::Editor::createAddon()
|
||||||
{
|
{
|
||||||
mStartup.hide();
|
mStartup.hide();
|
||||||
|
|
||||||
@ -98,7 +129,9 @@ void CS::Editor::openFiles()
|
|||||||
files.push_back(path.toStdString());
|
files.push_back(path.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMDoc::Document *document = mDocumentManager.addDocument(files, false);
|
/// \todo Get the save path from the file dialogue
|
||||||
|
|
||||||
|
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), false);
|
||||||
|
|
||||||
mViewManager.addView (document);
|
mViewManager.addView (document);
|
||||||
mFileDialog.hide();
|
mFileDialog.hide();
|
||||||
@ -115,12 +148,27 @@ void CS::Editor::createNewFile()
|
|||||||
|
|
||||||
files.push_back(mFileDialog.fileName().toStdString());
|
files.push_back(mFileDialog.fileName().toStdString());
|
||||||
|
|
||||||
CSMDoc::Document *document = mDocumentManager.addDocument (files, true);
|
/// \todo Get the save path from the file dialogue.
|
||||||
|
|
||||||
|
CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), true);
|
||||||
|
|
||||||
mViewManager.addView (document);
|
mViewManager.addView (document);
|
||||||
mFileDialog.hide();
|
mFileDialog.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CS::Editor::createNewGame (const boost::filesystem::path& file)
|
||||||
|
{
|
||||||
|
std::vector<boost::filesystem::path> files;
|
||||||
|
|
||||||
|
files.push_back (file);
|
||||||
|
|
||||||
|
CSMDoc::Document *document = mDocumentManager.addDocument (files, file, true);
|
||||||
|
|
||||||
|
mViewManager.addView (document);
|
||||||
|
|
||||||
|
mNewGame.hide();
|
||||||
|
}
|
||||||
|
|
||||||
void CS::Editor::showStartup()
|
void CS::Editor::showStartup()
|
||||||
{
|
{
|
||||||
if(mStartup.isHidden())
|
if(mStartup.isHidden())
|
||||||
@ -161,6 +209,9 @@ void CS::Editor::connectToIPCServer()
|
|||||||
|
|
||||||
int CS::Editor::run()
|
int CS::Editor::run()
|
||||||
{
|
{
|
||||||
|
if (mLocal.empty())
|
||||||
|
return 1;
|
||||||
|
|
||||||
mStartup.show();
|
mStartup.show();
|
||||||
|
|
||||||
QApplication::setQuitOnLastWindowClosed (true);
|
QApplication::setQuitOnLastWindowClosed (true);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "view/doc/viewmanager.hpp"
|
#include "view/doc/viewmanager.hpp"
|
||||||
#include "view/doc/startup.hpp"
|
#include "view/doc/startup.hpp"
|
||||||
#include "view/doc/filedialog.hpp"
|
#include "view/doc/filedialog.hpp"
|
||||||
|
#include "view/doc/newgame.hpp"
|
||||||
|
|
||||||
#include "view/settings/usersettingsdialog.hpp"
|
#include "view/settings/usersettingsdialog.hpp"
|
||||||
|
|
||||||
@ -29,10 +30,13 @@ namespace CS
|
|||||||
CSMDoc::DocumentManager mDocumentManager;
|
CSMDoc::DocumentManager mDocumentManager;
|
||||||
CSVDoc::ViewManager mViewManager;
|
CSVDoc::ViewManager mViewManager;
|
||||||
CSVDoc::StartupDialogue mStartup;
|
CSVDoc::StartupDialogue mStartup;
|
||||||
|
CSVDoc::NewGameDialogue mNewGame;
|
||||||
CSVSettings::UserSettingsDialog mSettings;
|
CSVSettings::UserSettingsDialog mSettings;
|
||||||
FileDialog mFileDialog;
|
FileDialog mFileDialog;
|
||||||
|
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
|
boost::filesystem::path mLocal;
|
||||||
|
|
||||||
void setupDataFiles();
|
void setupDataFiles();
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
@ -51,11 +55,13 @@ namespace CS
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void createDocument();
|
void createGame();
|
||||||
|
void createAddon();
|
||||||
|
|
||||||
void loadDocument();
|
void loadDocument();
|
||||||
void openFiles();
|
void openFiles();
|
||||||
void createNewFile();
|
void createNewFile();
|
||||||
|
void createNewGame (const boost::filesystem::path& file);
|
||||||
|
|
||||||
void showStartup();
|
void showStartup();
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(!editor.makeIPCServer())
|
if(!editor.makeIPCServer())
|
||||||
{
|
{
|
||||||
editor.connectToIPCServer();
|
editor.connectToIPCServer();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return editor.run();
|
return editor.run();
|
||||||
|
@ -2139,18 +2139,13 @@ void CSMDoc::Document::createBase()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files, bool new_)
|
CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
|
||||||
: mTools (mData)
|
const boost::filesystem::path& savePath, bool new_)
|
||||||
|
: mSavePath (savePath), mTools (mData)
|
||||||
{
|
{
|
||||||
if (files.empty())
|
if (files.empty())
|
||||||
throw std::runtime_error ("Empty content file sequence");
|
throw std::runtime_error ("Empty content file sequence");
|
||||||
|
|
||||||
/// \todo adjust last file name:
|
|
||||||
/// \li make sure it is located in the data-local directory (adjust path if necessary)
|
|
||||||
/// \li make sure the extension matches the new scheme (change it if necesarry)
|
|
||||||
|
|
||||||
mName = files.back().filename().string();
|
|
||||||
|
|
||||||
if (new_ && files.size()==1)
|
if (new_ && files.size()==1)
|
||||||
createBase();
|
createBase();
|
||||||
else
|
else
|
||||||
@ -2201,9 +2196,9 @@ int CSMDoc::Document::getState() const
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& CSMDoc::Document::getName() const
|
const boost::filesystem::path& CSMDoc::Document::getSavePath() const
|
||||||
{
|
{
|
||||||
return mName;
|
return mSavePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::Document::save()
|
void CSMDoc::Document::save()
|
||||||
|
@ -31,7 +31,7 @@ namespace CSMDoc
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string mName; ///< \todo replace name with ESX list
|
boost::filesystem::path mSavePath;
|
||||||
CSMWorld::Data mData;
|
CSMWorld::Data mData;
|
||||||
CSMTools::Tools mTools;
|
CSMTools::Tools mTools;
|
||||||
|
|
||||||
@ -64,15 +64,16 @@ namespace CSMDoc
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Document (const std::vector<boost::filesystem::path>& files, bool new_);
|
Document (const std::vector<boost::filesystem::path>& files,
|
||||||
|
const boost::filesystem::path& savePath, bool new_);
|
||||||
|
|
||||||
~Document();
|
~Document();
|
||||||
|
|
||||||
QUndoStack& getUndoStack();
|
QUndoStack& getUndoStack();
|
||||||
|
|
||||||
int getState() const;
|
int getState() const;
|
||||||
|
|
||||||
const std::string& getName() const;
|
const boost::filesystem::path& getSavePath() const;
|
||||||
///< \todo replace with ESX list
|
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ CSMDoc::DocumentManager::~DocumentManager()
|
|||||||
delete *iter;
|
delete *iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files,
|
CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
|
||||||
bool new_)
|
bool new_)
|
||||||
{
|
{
|
||||||
Document *document = new Document (files, new_);
|
Document *document = new Document (files, savePath, new_);
|
||||||
|
|
||||||
mDocuments.push_back (document);
|
mDocuments.push_back (document);
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ namespace CSMDoc
|
|||||||
|
|
||||||
~DocumentManager();
|
~DocumentManager();
|
||||||
|
|
||||||
Document *addDocument (const std::vector<boost::filesystem::path>& files, bool new_);
|
Document *addDocument (const std::vector<boost::filesystem::path>& files,
|
||||||
|
const boost::filesystem::path& savePath, bool new_);
|
||||||
///< The ownership of the returned document is not transferred to the caller.
|
///< The ownership of the returned document is not transferred to the caller.
|
||||||
///
|
///
|
||||||
/// \param new_ Do not load the last content file in \a files and instead create in an
|
/// \param new_ Do not load the last content file in \a files and instead create in an
|
||||||
|
90
apps/opencs/view/doc/adjusterwidget.cpp
Normal file
90
apps/opencs/view/doc/adjusterwidget.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
#include "adjusterwidget.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QStyle>
|
||||||
|
|
||||||
|
CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent)
|
||||||
|
: QWidget (parent), mValid (false)
|
||||||
|
{
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout (this);
|
||||||
|
|
||||||
|
mIcon = new QLabel (this);
|
||||||
|
|
||||||
|
layout->addWidget (mIcon, 0);
|
||||||
|
|
||||||
|
mMessage = new QLabel (this);
|
||||||
|
mMessage->setWordWrap (true);
|
||||||
|
mMessage->setSizePolicy (QSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum));
|
||||||
|
|
||||||
|
layout->addWidget (mMessage, 1);
|
||||||
|
|
||||||
|
setName ("", false);
|
||||||
|
|
||||||
|
setLayout (layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::AdjusterWidget::setLocalData (const boost::filesystem::path& localData)
|
||||||
|
{
|
||||||
|
mLocalData = localData;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::filesystem::path CSVDoc::AdjusterWidget::getPath() const
|
||||||
|
{
|
||||||
|
if (!mValid)
|
||||||
|
throw std::logic_error ("invalid content file path");
|
||||||
|
|
||||||
|
return mResultPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon)
|
||||||
|
{
|
||||||
|
QString message;
|
||||||
|
|
||||||
|
if (name.isEmpty())
|
||||||
|
{
|
||||||
|
mValid = false;
|
||||||
|
message = "No name.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boost::filesystem::path path (name.toUtf8().data());
|
||||||
|
|
||||||
|
path.replace_extension (addon ? ".omwaddon" : ".omwgame");
|
||||||
|
|
||||||
|
if (path.parent_path().string()==mLocalData.string())
|
||||||
|
{
|
||||||
|
// path already points to the local data directory
|
||||||
|
message = QString::fromUtf8 (("Will be saved as: " + path.native()).c_str());
|
||||||
|
mResultPath = path;
|
||||||
|
mValid = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// path points somewhere else or is a leaf name.
|
||||||
|
path = mLocalData / path.filename();
|
||||||
|
|
||||||
|
message = QString::fromUtf8 (("Will be saved as: " + path.native()).c_str());
|
||||||
|
mResultPath = path;
|
||||||
|
mValid = true;
|
||||||
|
|
||||||
|
if (boost::filesystem::exists (path))
|
||||||
|
{
|
||||||
|
/// \todo add an user setting to make this an error.
|
||||||
|
message += "<p>But a file with the same name already exists. If you continue, it will be overwritten.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mMessage->setText (message);
|
||||||
|
mIcon->setPixmap (style()->standardIcon (
|
||||||
|
mValid ? QStyle::SP_MessageBoxInformation : QStyle::SP_MessageBoxWarning).
|
||||||
|
pixmap (QSize (16, 16)));
|
||||||
|
|
||||||
|
emit stateChanged (mValid);
|
||||||
|
}
|
41
apps/opencs/view/doc/adjusterwidget.hpp
Normal file
41
apps/opencs/view/doc/adjusterwidget.hpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#ifndef CSV_DOC_ADJUSTERWIDGET_H
|
||||||
|
#define CSV_DOC_ADJUSTERWIDGET_H
|
||||||
|
|
||||||
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
|
||||||
|
namespace CSVDoc
|
||||||
|
{
|
||||||
|
class AdjusterWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
boost::filesystem::path mLocalData;
|
||||||
|
QLabel *mMessage;
|
||||||
|
QLabel *mIcon;
|
||||||
|
bool mValid;
|
||||||
|
boost::filesystem::path mResultPath;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
AdjusterWidget (QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setLocalData (const boost::filesystem::path& localData);
|
||||||
|
|
||||||
|
boost::filesystem::path getPath() const;
|
||||||
|
///< This function must not be called if there is no valid path.
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void setName (const QString& name, bool addon);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void stateChanged (bool valid);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
53
apps/opencs/view/doc/filewidget.cpp
Normal file
53
apps/opencs/view/doc/filewidget.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
#include "filewidget.hpp"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QRegExpValidator>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
QString CSVDoc::FileWidget::getExtension() const
|
||||||
|
{
|
||||||
|
return mAddon ? ".omwaddon" : ".omwgame";
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVDoc::FileWidget::FileWidget (QWidget *parent) : QWidget (parent), mAddon (false)
|
||||||
|
{
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout (this);
|
||||||
|
|
||||||
|
mInput = new QLineEdit (this);
|
||||||
|
mInput->setValidator (new QRegExpValidator(QRegExp("^[a-zA-Z0-9\\s]*$")));
|
||||||
|
|
||||||
|
layout->addWidget (mInput, 1);
|
||||||
|
|
||||||
|
mType = new QLabel (this);
|
||||||
|
|
||||||
|
layout ->addWidget (mType);
|
||||||
|
|
||||||
|
connect (mInput, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&)));
|
||||||
|
|
||||||
|
setLayout (layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::FileWidget::setType (bool addon)
|
||||||
|
{
|
||||||
|
mAddon = addon;
|
||||||
|
|
||||||
|
mType->setText (getExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CSVDoc::FileWidget::getName() const
|
||||||
|
{
|
||||||
|
QString text = mInput->text();
|
||||||
|
|
||||||
|
if (text.isEmpty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return text + getExtension();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::FileWidget::textChanged (const QString& text)
|
||||||
|
{
|
||||||
|
emit nameChanged (getName(), mAddon);
|
||||||
|
}
|
40
apps/opencs/view/doc/filewidget.hpp
Normal file
40
apps/opencs/view/doc/filewidget.hpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef CSV_DOC_FILEWIDGET_H
|
||||||
|
#define CSV_DOC_FILEWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
class QString;
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
|
namespace CSVDoc
|
||||||
|
{
|
||||||
|
class FileWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
bool mAddon;
|
||||||
|
QLineEdit *mInput;
|
||||||
|
QLabel *mType;
|
||||||
|
|
||||||
|
QString getExtension() const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FileWidget (QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setType (bool addon);
|
||||||
|
|
||||||
|
QString getName() const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void textChanged (const QString& text);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void nameChanged (const QString& file, bool addon);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
68
apps/opencs/view/doc/newgame.cpp
Normal file
68
apps/opencs/view/doc/newgame.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
#include "newgame.hpp"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include "filewidget.hpp"
|
||||||
|
#include "adjusterwidget.hpp"
|
||||||
|
|
||||||
|
CSVDoc::NewGameDialogue::NewGameDialogue()
|
||||||
|
{
|
||||||
|
setWindowTitle ("Create New Game");
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout (this);
|
||||||
|
|
||||||
|
mFileWidget = new FileWidget (this);
|
||||||
|
mFileWidget->setType (false);
|
||||||
|
|
||||||
|
layout->addWidget (mFileWidget, 1);
|
||||||
|
|
||||||
|
mAdjusterWidget = new AdjusterWidget (this);
|
||||||
|
|
||||||
|
layout->addWidget (mAdjusterWidget, 1);
|
||||||
|
|
||||||
|
QDialogButtonBox *buttons = new QDialogButtonBox (this);
|
||||||
|
|
||||||
|
mCreate = new QPushButton ("Create", this);
|
||||||
|
mCreate->setDefault (true);
|
||||||
|
mCreate->setEnabled (false);
|
||||||
|
|
||||||
|
buttons->addButton (mCreate, QDialogButtonBox::AcceptRole);
|
||||||
|
|
||||||
|
QPushButton *cancel = new QPushButton ("Cancel", this);
|
||||||
|
|
||||||
|
buttons->addButton (cancel, QDialogButtonBox::RejectRole);
|
||||||
|
|
||||||
|
layout->addWidget (buttons);
|
||||||
|
|
||||||
|
setLayout (layout);
|
||||||
|
|
||||||
|
connect (mAdjusterWidget, SIGNAL (stateChanged (bool)), this, SLOT (stateChanged (bool)));
|
||||||
|
connect (mCreate, SIGNAL (clicked()), this, SLOT (create()));
|
||||||
|
connect (cancel, SIGNAL (clicked()), this, SLOT (reject()));
|
||||||
|
connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)),
|
||||||
|
mAdjusterWidget, SLOT (setName (const QString&, bool)));
|
||||||
|
|
||||||
|
QRect scr = QApplication::desktop()->screenGeometry();
|
||||||
|
QRect rect = geometry();
|
||||||
|
move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::NewGameDialogue::setLocalData (const boost::filesystem::path& localData)
|
||||||
|
{
|
||||||
|
mAdjusterWidget->setLocalData (localData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::NewGameDialogue::stateChanged (bool valid)
|
||||||
|
{
|
||||||
|
mCreate->setEnabled (valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::NewGameDialogue::create()
|
||||||
|
{
|
||||||
|
emit createRequest (mAdjusterWidget->getPath());
|
||||||
|
}
|
44
apps/opencs/view/doc/newgame.hpp
Normal file
44
apps/opencs/view/doc/newgame.hpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef CSV_DOC_NEWGAME_H
|
||||||
|
#define CSV_DOC_NEWGAME_H
|
||||||
|
|
||||||
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE (boost::filesystem::path)
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
|
||||||
|
namespace CSVDoc
|
||||||
|
{
|
||||||
|
class FileWidget;
|
||||||
|
class AdjusterWidget;
|
||||||
|
|
||||||
|
class NewGameDialogue : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QPushButton *mCreate;
|
||||||
|
FileWidget *mFileWidget;
|
||||||
|
AdjusterWidget *mAdjusterWidget;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
NewGameDialogue();
|
||||||
|
|
||||||
|
void setLocalData (const boost::filesystem::path& localData);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void createRequest (const boost::filesystem::path& file);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void stateChanged (bool valid);
|
||||||
|
|
||||||
|
void create();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -27,9 +27,13 @@ void CSVDoc::View::setupFileMenu()
|
|||||||
{
|
{
|
||||||
QMenu *file = menuBar()->addMenu (tr ("&File"));
|
QMenu *file = menuBar()->addMenu (tr ("&File"));
|
||||||
|
|
||||||
QAction *new_ = new QAction (tr ("New"), this);
|
QAction *newGame = new QAction (tr ("New Game"), this);
|
||||||
connect (new_, SIGNAL (triggered()), this, SIGNAL (newDocumentRequest()));
|
connect (newGame, SIGNAL (triggered()), this, SIGNAL (newGameRequest()));
|
||||||
file->addAction (new_);
|
file->addAction (newGame);
|
||||||
|
|
||||||
|
QAction *newAddon = new QAction (tr ("New Addon"), this);
|
||||||
|
connect (newAddon, SIGNAL (triggered()), this, SIGNAL (newAddonRequest()));
|
||||||
|
file->addAction (newAddon);
|
||||||
|
|
||||||
QAction *open = new QAction (tr ("&Open"), this);
|
QAction *open = new QAction (tr ("&Open"), this);
|
||||||
connect (open, SIGNAL (triggered()), this, SIGNAL (loadDocumentRequest()));
|
connect (open, SIGNAL (triggered()), this, SIGNAL (loadDocumentRequest()));
|
||||||
@ -180,7 +184,7 @@ void CSVDoc::View::updateTitle()
|
|||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
|
|
||||||
stream << mDocument->getName();
|
stream << mDocument->getSavePath().filename().string();
|
||||||
|
|
||||||
if (mDocument->getState() & CSMDoc::State_Modified)
|
if (mDocument->getState() & CSMDoc::State_Modified)
|
||||||
stream << " *";
|
stream << " *";
|
||||||
|
@ -106,7 +106,9 @@ namespace CSVDoc
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void newDocumentRequest();
|
void newGameRequest();
|
||||||
|
|
||||||
|
void newAddonRequest();
|
||||||
|
|
||||||
void loadDocumentRequest();
|
void loadDocumentRequest();
|
||||||
|
|
||||||
|
@ -107,12 +107,12 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
|||||||
|
|
||||||
View *view = new View (*this, document, countViews (document)+1);
|
View *view = new View (*this, document, countViews (document)+1);
|
||||||
|
|
||||||
|
|
||||||
mViews.push_back (view);
|
mViews.push_back (view);
|
||||||
|
|
||||||
view->show();
|
view->show();
|
||||||
|
|
||||||
connect (view, SIGNAL (newDocumentRequest ()), this, SIGNAL (newDocumentRequest()));
|
connect (view, SIGNAL (newGameRequest ()), this, SIGNAL (newGameRequest()));
|
||||||
|
connect (view, SIGNAL (newAddonRequest ()), this, SIGNAL (newAddonRequest()));
|
||||||
connect (view, SIGNAL (loadDocumentRequest ()), this, SIGNAL (loadDocumentRequest()));
|
connect (view, SIGNAL (loadDocumentRequest ()), this, SIGNAL (loadDocumentRequest()));
|
||||||
connect (view, SIGNAL (editSettingsRequest()), this, SIGNAL (editSettingsRequest()));
|
connect (view, SIGNAL (editSettingsRequest()), this, SIGNAL (editSettingsRequest()));
|
||||||
|
|
||||||
|
@ -55,7 +55,9 @@ namespace CSVDoc
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void newDocumentRequest();
|
void newGameRequest();
|
||||||
|
|
||||||
|
void newAddonRequest();
|
||||||
|
|
||||||
void loadDocumentRequest();
|
void loadDocumentRequest();
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigurationManager::processPaths(Files::PathContainer& dataDirs)
|
void ConfigurationManager::processPaths(Files::PathContainer& dataDirs, bool create)
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
|
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
|
||||||
@ -94,6 +94,18 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs)
|
|||||||
|
|
||||||
if (!boost::filesystem::is_directory(*it))
|
if (!boost::filesystem::is_directory(*it))
|
||||||
{
|
{
|
||||||
|
if (create)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::filesystem::create_directories (*it);
|
||||||
|
}
|
||||||
|
catch (...) {}
|
||||||
|
|
||||||
|
if (boost::filesystem::is_directory(*it))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
(*it).clear();
|
(*it).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ struct ConfigurationManager
|
|||||||
|
|
||||||
void readConfiguration(boost::program_options::variables_map& variables,
|
void readConfiguration(boost::program_options::variables_map& variables,
|
||||||
boost::program_options::options_description& description);
|
boost::program_options::options_description& description);
|
||||||
void processPaths(Files::PathContainer& dataDirs);
|
|
||||||
|
void processPaths(Files::PathContainer& dataDirs, bool create = false);
|
||||||
|
///< \param create Try creating the directory, if it does not exist.
|
||||||
|
|
||||||
/**< Fixed paths */
|
/**< Fixed paths */
|
||||||
const boost::filesystem::path& getGlobalPath() const;
|
const boost::filesystem::path& getGlobalPath() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user