Skip to content

Commit

Permalink
Merge branch 'import-bms'
Browse files Browse the repository at this point in the history
  • Loading branch information
excln committed Jul 20, 2017
2 parents 40b99cf + 5281911 commit a2d0399
Show file tree
Hide file tree
Showing 23 changed files with 3,166 additions and 281 deletions.
89 changes: 57 additions & 32 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "ExternalViewerTools.h"
#include "EditConfig.h"
#include "MasterOutDialog.h"
#include "bmson/Bmson.h"
#include "bms/Bms.h"
#include "bms/BmsImportDialog.h"


const char* MainWindow::SettingsGroup = "MainWindow";
Expand Down Expand Up @@ -509,23 +512,16 @@ void MainWindow::FileOpen()
if (!EnsureClosingFile())
return;
QString filters = tr("bmson files (*.bmson)"
";;" "old bms files (*.bms *.bme *.bml *.pms)"
";;" "legacy bms files (*.bms *.bme *.bml *.pms)"
";;" "all files (*.*)");
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), QString(), filters, 0);
if (fileName.isEmpty())
return;
try{
Document *newEditor = new Document(this);
newEditor->LoadFile(fileName);
ReplaceDocument(newEditor);
}catch(QString message){
QMessageBox *msgbox = new QMessageBox(
QMessageBox::Warning,
tr("Error"),
message,
QMessageBox::Ok,
this);
msgbox->show();
QString ext = QFileInfo(fileName).suffix().toLower();
if (BmsIO::IsBmsFileExtension(ext)){
OpenBms(fileName);
}else{
OpenBmson(fileName);
}
}

Expand All @@ -535,18 +531,11 @@ void MainWindow::FileOpen(QString path)
return;
if (!EnsureClosingFile())
return;
try{
Document *newEditor = new Document(this);
newEditor->LoadFile(path);
ReplaceDocument(newEditor);
}catch(QString message){
QMessageBox *msgbox = new QMessageBox(
QMessageBox::Warning,
tr("Error"),
message,
QMessageBox::Ok,
this);
msgbox->show();
QString ext = QFileInfo(path).suffix().toLower();
if (BmsIO::IsBmsFileExtension(ext)){
OpenBms(path);
}else{
OpenBmson(path);
}
}

Expand Down Expand Up @@ -1032,11 +1021,12 @@ bool MainWindow::EnsureClosingFile()
}
}

bool MainWindow::IsBmsFileExtension(const QString &ext)
bool MainWindow::IsSourceFileExtension(const QString &ext)
{
if (ext == "bmson"){
if (BmsonIO::IsBmsonFileExtension(ext))
return true;
if (BmsIO::IsBmsFileExtension(ext))
return true;
}
return false;
}

Expand Down Expand Up @@ -1099,7 +1089,9 @@ void MainWindow::dropEvent(QDropEvent *event)
for (auto url : mimeData->urls()){
filePaths.append(url.toLocalFile());
}
OpenFiles(filePaths);
QTimer::singleShot(10, [=](){
OpenFiles(filePaths);
});
event->setDropAction(Qt::CopyAction);
event->accept();
}
Expand All @@ -1108,10 +1100,12 @@ void MainWindow::dropEvent(QDropEvent *event)
void MainWindow::OpenFiles(QStringList filePaths)
{
QString ext = QFileInfo(filePaths[0]).suffix().toLower();
if (IsBmsFileExtension(ext)){
QMetaObject::invokeMethod(this, "FileOpen", Qt::QueuedConnection, Q_ARG(QString, filePaths[0]));
if (IsSourceFileExtension(ext)){
//QMetaObject::invokeMethod(this, "FileOpen", Qt::QueuedConnection, Q_ARG(QString, filePaths[0]));
FileOpen(filePaths[0]);
}else if (IsSoundFileExtension(ext)){
QMetaObject::invokeMethod(this, "ChannelsNew", Qt::QueuedConnection, Q_ARG(QList<QString>, filePaths));
//QMetaObject::invokeMethod(this, "ChannelsNew", Qt::QueuedConnection, Q_ARG(QList<QString>, filePaths));
ChannelsNew(filePaths);
}else{
QMessageBox *msgbox = new QMessageBox(
QMessageBox::Warning,
Expand All @@ -1123,6 +1117,37 @@ void MainWindow::OpenFiles(QStringList filePaths)
}
}

void MainWindow::OpenBmson(QString path)
{
try{
Document *newEditor = new Document(this);
newEditor->LoadFile(path);
ReplaceDocument(newEditor);
}catch(QString message){
QMessageBox *msgbox = new QMessageBox(
QMessageBox::Warning,
tr("Error"),
message,
QMessageBox::Ok,
this);
msgbox->show();
}
}

void MainWindow::OpenBms(QString path)
{
Bms::BmsReader *reader = BmsIO::LoadBms(path);
BmsImportDialog *dialog = new BmsImportDialog(this, *reader);
dialog->exec();
if (dialog->result() == QDialog::Accepted && dialog->IsSucceeded()){
auto newEditor = new Document(this);
newEditor->LoadBms(reader->GetBms());
ReplaceDocument(newEditor);
}
delete dialog;
delete reader;
}

bool MainWindow::WarningFileTraversals(QStringList filePaths)
{
QString paths;
Expand Down
4 changes: 3 additions & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class MainWindow : public QMainWindow
void ReplaceDocument(Document *newDocument);
bool Save();
bool EnsureClosingFile();
static bool IsBmsFileExtension(const QString &ext);
static bool IsSourceFileExtension(const QString &ext);
static bool IsSoundFileExtension(const QString &ext);

private slots:
Expand Down Expand Up @@ -258,6 +258,8 @@ public slots:
void UnsetSelectedObjectsView(QWidget *view);

void OpenFiles(QStringList filePaths);
void OpenBmson(QString path);
void OpenBms(QString path);

bool WarningFileTraversals(QStringList filePaths);
};
Expand Down
94 changes: 94 additions & 0 deletions src/PrefBms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "PrefBms.h"
#include "bms/Bms.h"

PrefBmsPage::PrefBmsPage(QWidget *parent)
: QWidget(parent)
{
auto layout = new QVBoxLayout();
{
auto grid = new QGridLayout();
grid->addWidget(new QLabel(tr("Default")), 0, 1, Qt::AlignCenter);
grid->addWidget(new QLabel(tr("Ask")), 0, 2, Qt::AlignCenter);
grid->setColumnStretch(1, 1);
grid->addWidget(new QLabel(tr("Text Encoding:")), 1, 0, Qt::AlignRight);
grid->addWidget(defaultTextEncoding = new QComboBox(), 1, 1);
grid->addWidget(askTextEncoding = new QCheckBox(), 1, 2, Qt::AlignCenter);
grid->addWidget(new QLabel(tr("#RANDOM Command:")), 2, 0, Qt::AlignRight);
grid->addWidget(useRandomValues = new QCheckBox(tr("Generate random values")), 2, 1);
grid->addWidget(askRandomValues = new QCheckBox(), 2, 2, Qt::AlignCenter);
grid->addWidget(new QLabel(tr("Game Mode:")), 3, 0, Qt::AlignRight);
{
auto gameModeLayout = new QVBoxLayout();
gameModeLayout->setMargin(0);
gameModeLayout->addWidget(trustPlayerCommand = new QCheckBox(tr("Trust #PLAYER command")));
gameModeLayout->addWidget(ignoreExtension = new QCheckBox(tr("Ignore file extension")));
gameModeLayout->addWidget(preferExModes = new QCheckBox(tr("Prefer 7/14/9key to 5/10/5key.")));
grid->addLayout(gameModeLayout, 3, 1);
}
grid->addWidget(askGameMode = new QCheckBox(), 3, 2, Qt::AlignCenter);
layout->addLayout(grid);
}
{
auto miscGroup = new QGroupBox(tr("Miscellaneous"));
auto miscLayout = new QFormLayout();
{
miscLayout->addRow(skipBetweenRandomAndIf = new QCheckBox(tr("Skip commands between #RANDOM and #IF")));
}
miscGroup->setLayout(miscLayout);
layout->addWidget(miscGroup);
}
{
auto bmsonGroup = new QGroupBox(tr("Conversion to Bmson"));
auto bmsonLayout = new QFormLayout();
{
bmsonLayout->addRow(tr("Minimum resolution"), minResolution = new QLineEdit());
bmsonLayout->addRow(tr("Maximum resolution"), maxResolution = new QLineEdit());
}
bmsonGroup->setLayout(bmsonLayout);
layout->addWidget(bmsonGroup);
}
setLayout(layout);

for (auto codec : Bms::BmsReaderConfig::AvailableCodecs){
defaultTextEncoding->addItem(codec.isEmpty() ? QString(tr("(default)")) : codec);
}
}

void PrefBmsPage::load()
{
Bms::BmsReaderConfig config;
config.Load();
askTextEncoding->setChecked(config.askTextEncoding);
askRandomValues->setChecked(config.askRandomValues);
askGameMode->setChecked(config.askGameMode);
if (config.defaultTextEncoding.isEmpty()){
defaultTextEncoding->setCurrentIndex(0);
}else{
defaultTextEncoding->setCurrentText(config.defaultTextEncoding);
}
useRandomValues->setChecked(config.useRandomValues);
trustPlayerCommand->setChecked(config.trustPlayerCommand);
ignoreExtension->setChecked(config.ignoreExtension);
preferExModes->setChecked(config.preferExModes);
minResolution->setText(QString::number(config.minimumResolution));
maxResolution->setText(QString::number(config.maximumResolution));
skipBetweenRandomAndIf->setChecked(config.skipBetweenRandomAndIf);
}

void PrefBmsPage::store()
{
Bms::BmsReaderConfig config;
config.askTextEncoding = askTextEncoding->isChecked();
config.askRandomValues = askRandomValues->isChecked();
config.askGameMode = askGameMode->isChecked();
config.defaultTextEncoding = defaultTextEncoding->currentIndex() > 0 ? defaultTextEncoding->currentText() : "";
config.useRandomValues = useRandomValues->isChecked();
config.trustPlayerCommand = trustPlayerCommand->isChecked();
config.ignoreExtension = ignoreExtension->isChecked();
config.preferExModes = preferExModes->isChecked();
config.minimumResolution = std::max(1, std::min(1000000, minResolution->text().toInt()));
config.maximumResolution = std::max(config.minimumResolution, std::min(1000000, maxResolution->text().toInt()));
config.skipBetweenRandomAndIf = skipBetweenRandomAndIf->isChecked();
config.Save();
}

35 changes: 35 additions & 0 deletions src/PrefBms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef PREFBMS_H
#define PREFBMS_H

#include <QtCore>
#include <QtWidgets>

class Preferences;

class PrefBmsPage : public QWidget
{
Q_OBJECT

private:
QCheckBox *askTextEncoding;
QCheckBox *askRandomValues;
QCheckBox *askGameMode;

QComboBox *defaultTextEncoding;
QCheckBox *useRandomValues;
QCheckBox *trustPlayerCommand;
QCheckBox *ignoreExtension;
QCheckBox *preferExModes;

QLineEdit *minResolution;
QLineEdit *maxResolution;
QCheckBox *skipBetweenRandomAndIf;

public:
PrefBmsPage(QWidget *parent);

void load();
void store();
};

#endif // PREFBMS_H
11 changes: 11 additions & 0 deletions src/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "MainWindow.h"
#include "PrefEdit.h"
#include "PrefPreview.h"
#include "PrefBms.h"


Preferences::Preferences(MainWindow *mainWindow)
Expand Down Expand Up @@ -49,6 +50,14 @@ Preferences::Preferences(MainWindow *mainWindow)
previewItem->setText(tr("Preview"));
previewItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);

// BMS
bmsPage = new PrefBmsPage(this);
pages->addWidget(bmsPage);
auto bmsItem = new QListWidgetItem(list);
bmsItem->setIcon(QIcon(":/images/config/general.png"));
bmsItem->setText(tr("BMS Import"));
bmsItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);

list->setCurrentRow(0);

auto bodyLayout = new QHBoxLayout();
Expand All @@ -73,6 +82,7 @@ void Preferences::showEvent(QShowEvent *event)
generalPage->load();
editPage->load();
previewPage->load();
bmsPage->load();
QDialog::showEvent(event);
}

Expand All @@ -81,6 +91,7 @@ void Preferences::hideEvent(QHideEvent *event)
generalPage->store();
editPage->store();
previewPage->store();
bmsPage->store();
QDialog::hideEvent(event);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MainWindow;

class PrefEditPage;
class PrefPreviewPage;

class PrefBmsPage;

class PrefGeneralPage : public QWidget
{
Expand Down Expand Up @@ -56,6 +56,7 @@ class Preferences : public QDialog
PrefGeneralPage *generalPage;
PrefEditPage *editPage;
PrefPreviewPage *previewPage;
PrefBmsPage *bmsPage;

virtual void showEvent(QShowEvent *event);
virtual void hideEvent(QHideEvent *event);
Expand Down
Loading

0 comments on commit a2d0399

Please sign in to comment.