Skip to content

Commit

Permalink
Start reworking the loading demo system
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-Beirao committed May 23, 2024
1 parent 1e4839f commit 3f5b003
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 142 deletions.
21 changes: 17 additions & 4 deletions src/demodialog.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
#include "demodialog.h"
#include "mainwindow.h"

demodialog::demodialog(QStringList iwad_list, QWidget *parent)
: QDialog(parent)
demodialog::demodialog(QString missing_iwad, QStringList missing_files, QWidget *parent) : QDialog(parent)
{
QGridLayout *mainLayout = new QGridLayout;

QLabel *description = new QLabel("No footer found on the demo.\nPlease select the correct files.\n");
QLabel *description;
if (missing_iwad.isEmpty() && missing_files.isEmpty())
{
description = new QLabel("No footer found on the demo.\n");
}
else
{
description = new QLabel("");
if (!missing_iwad.isEmpty()) description->setText("Demo IWAD not found.\n");
if (!missing_files.isEmpty()) description->setText(description->text() + "Demo PWADs/DEHs not found.\n");
}
mainLayout->addWidget(description, 0, 0, 1, 3);

QLabel *iwad_label = new QLabel("IWAD:");
mainLayout->addWidget(iwad_label, 1, 0);

iwad_comboBox = new QComboBox();
iwad_comboBox->addItems(iwad_list);
QFileInfoList IWADs = findIwads();
for (int i = 0; i < IWADs.count(); i++)
{
iwad_comboBox->addItem(IWADs[i].baseName().toLower());
}
mainLayout->addWidget(iwad_comboBox, 1, 1, 1, 2);

QLabel *files_label = new QLabel("Files:");
Expand Down
17 changes: 9 additions & 8 deletions src/demodialog.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#ifndef DEMODIALOG_H
#define DEMODIALOG_H

#include "funcs.h"
#include <QComboBox>
#include <QDialog>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QHeaderView>
#include <QLabel>
#include <QComboBox>
#include <QPair>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QSettings>
#include <QPair>
#include <QVBoxLayout>
#include <qtablewidget.h>
#include <QHeaderView>

class demodialog : public QDialog
{
Q_OBJECT

public:
explicit demodialog(QStringList iwad_list, QWidget *parent = nullptr);
int get_iwad_index();
QStringList get_files_list();
explicit demodialog(QString missing_iwad, QStringList missing_files, QWidget *parent = nullptr);
int get_iwad_index();
QStringList get_files_list();

private:
QComboBox *iwad_comboBox;
Expand Down
87 changes: 87 additions & 0 deletions src/funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ QString getFileName(QString filePath)

QString getFilePath(QString fileName)
{
fileName = fileName.toLower();

// Find file in dsda folder
QString dsda_folder;
#ifdef _WIN32
Expand Down Expand Up @@ -86,4 +88,89 @@ QString getFilePath(QString fileName)
return "";
}

QString removeExtension(QString fileName)
{
int dot_pos = fileName.lastIndexOf('.');
if (dot_pos == -1) return fileName;

return fileName.left(dot_pos);
}

QString getExtension(QString fileName)
{
int dot_pos = fileName.lastIndexOf('.');
if (dot_pos == -1) return "";

return fileName.mid(dot_pos + 1);
}

QFileInfoList findIwads_possibleFiles()
{
QFileInfoList possible_files;
QString doomwaddirstr = QString(qgetenv("DOOMWADDIR"));

// Find the IWADs in the correct folder depending on the OS
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
if (!QDir(dotfolder).exists()) QDir().mkdir(dotfolder);

// Copies dsda-doom.wad to the dotfolder
#if defined(Q_OS_MAC)
QProcess::startDetached("cp", {launcherFolderPath + "/../Resources/" + gameName + ".wad", dotfolder});
#endif

QDir directory(dotfolder);

doomwaddirstr = doomwaddirstr.split(":")[0];

#elif defined(Q_OS_WIN)
QDir directory(execPath);

doomwaddirstr = doomwaddirstr.split(";")[0];
#endif

possible_files = directory.entryInfoList(QStringList() << "*.WAD", QDir::Files);

QDir doomwaddir(doomwaddirstr);
possible_files += doomwaddir.entryInfoList(QStringList() << "*.WAD", QDir::Files);

int size = settings->beginReadArray("iwadfolders");
for (int i = 0; i < size; i++)
{
settings->setArrayIndex(i);
QString folder = settings->value("folder").toString();
if (!folder.isEmpty())
{
possible_files += QDir(folder).entryInfoList(QStringList() << "*.WAD", QDir::Files);
}
}
settings->endArray();

return possible_files;
}

QFileInfoList findIwads()
{
QFileInfoList ret;
QFileInfoList possible_files = findIwads_possibleFiles();

// This makes sure that a logical order to display the IWADs is followed
// I think doing this is better than having random orders like: Doom 2 -> TNT -> Doom
QStringList IWADS = exmxIWADS + mapxxIWADS;

for (int i = 0; i < IWADS.size(); i++)
{
for (QFileInfo &fileInfo : possible_files)
{
QString file_name = fileInfo.baseName().toLower();
if (IWADS[i] == file_name)
{
ret.append(fileInfo);
break;
}
}
}

return ret;
}

QStringList parseStringIntoArguments(QString line) { return QProcess::splitCommand(line); }
3 changes: 3 additions & 0 deletions src/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ void openIWADsFolder();
QString getFileName(QString filePath);
QString getFilePath(QString fileName);
QStringList parseStringIntoArguments(QString line);
QString removeExtension(QString fileName);
QString getExtension(QString fileName);
QFileInfoList findIwads();

#endif // FUNCS_H
98 changes: 44 additions & 54 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
QShortcut *shortcut3 = new QShortcut(QKeySequence(Qt::Key_W | Qt::CTRL), this, SLOT(close()));
shortcut3->setAutoRepeat(false);

findIwads();
QFileInfoList IWADs = findIwads();
for (int i = 0; i < IWADs.count(); i++)
{
ui->iwad_comboBox->addItem(IWADs[i].baseName().toLower());
ui->iwad_comboBox->setItemData(ui->iwad_comboBox->count() - 1, IWADs[i].absoluteFilePath(), Qt::ToolTipRole);
}

// If no IWAD found, show a tool tip
if (ui->iwad_comboBox->count() == 0) ui->tooltip_textBrowser->show();
else ui->tooltip_textBrowser->hide();

loadSelected();

Expand Down Expand Up @@ -258,73 +267,59 @@ void MainWindow::dropLmp(QString filePath)
QTextStream stream(&file);
QString buffer;

bool found_footer = false;
bool openDemoDialog = true;
QString missing_iwad = "";
QStringList missing_files;

while (stream.readLineInto(&buffer))
{
if (buffer.mid(0, 5) == "-iwad")
if (buffer.left(5) == "-iwad")
{
found_footer = true;
openDemoDialog = false;
ui->wads_listWidget->clear();

QStringList argList;
QString tmp;
for (qsizetype i = 0; i < buffer.size(); i++)
{
if (buffer[i] != ' ' && buffer[i] != '\"')
{
tmp += buffer[i];
}
else if (!tmp.isEmpty())
{
argList.push_back(tmp);
tmp.clear();
}
}
if (!tmp.isEmpty())
{
argList.push_back(tmp);
tmp.clear();
}
QStringList args = QProcess::splitCommand(buffer);

for (int i = 0; i < argList.count() - 1; i++)
for (int i = 0; i < args.count() - 1; i++)
{
if (argList[i] == "-iwad")
if (args[i] == "-iwad")
{
int iwad_dot_pos = argList[i + 1].lastIndexOf('.');
iwad_dot_pos = iwad_dot_pos == -1 ? argList[i + 1].size() : iwad_dot_pos;

int iwad_index = ui->iwad_comboBox->findText(argList[i + 1].left(iwad_dot_pos));
int iwad_index = ui->iwad_comboBox->findText(removeExtension(args[i + 1]).toLower());
if (iwad_index != -1)
{
ui->iwad_comboBox->setCurrentIndex(iwad_index);
}
else
{
missing_iwad = args[i + 1];
openDemoDialog = true;
}
}
else if (argList[i] == "-file" || argList[i] == "-deh")
else if (args[i] == "-file" || args[i] == "-deh")
{
QStringList files;
for (int ii = i + 1; ii < argList.count(); ii++)
for (i = i + 1; i < args.count(); i++)
{
if (argList[ii].size() < 2 || argList[ii][0] == '-')
qDebug() << 1 << args[i];
if (args[i].size() < 2 || args[i][0] == '-')
{
break;
}

QString tmp = argList[ii].toLower();

// Some old Woof demos don't have the .wad extension on the footer
int file_dot_pos = tmp.lastIndexOf('.');
if (file_dot_pos == -1) tmp += ".wad";

files.append(tmp);
}

for (int i = 0; i < files.count(); i++)
{
QString filePath = getFilePath(files[i]);
if (filePath.isEmpty()) continue;
int file_dot_pos = args[i].lastIndexOf('.');
if (file_dot_pos == -1) args[i] += ".wad";

ui->wads_listWidget->addItem(getFileName(filePath));
ui->wads_listWidget->item(ui->wads_listWidget->count() - 1)->setToolTip(filePath);
QString filePath = getFilePath(args[i]);
if (filePath.isEmpty())
{
missing_files.append(args[i]);
openDemoDialog = true;
}
else
{
ui->wads_listWidget->addItem(getFileName(filePath));
ui->wads_listWidget->item(ui->wads_listWidget->count() - 1)->setToolTip(filePath);
}
}
}
}
Expand All @@ -333,14 +328,9 @@ void MainWindow::dropLmp(QString filePath)

file.close();

if (!found_footer)
if (openDemoDialog)
{
QStringList iwad_list;
for (int i = 0; i < ui->iwad_comboBox->count(); i++)
{
iwad_list.push_back(ui->iwad_comboBox->itemText(i));
}
demodialog *demoDialogNew = new demodialog(iwad_list, this);
demodialog *demoDialogNew = new demodialog(missing_iwad, missing_files, this);
demoDialogNew->open();

demoDialog = demoDialogNew;
Expand Down
2 changes: 0 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public slots:
void setResolutionsList(QListWidget *list);
void dropFile(QString fileName);
void dropLmp(QString filePath);
void findIwads();
void changeExeName(QString newName);
void setToggles(QString t1, QString a1, QString t2, QString a2, QString t3, QString a3, QString t4, QString a4);
void whenAnimationFinishNext();
Expand Down Expand Up @@ -169,7 +168,6 @@ private slots:
void on_hud_pushButton_clicked();
void on_config_pushButton_clicked();
void on_playback_lineEdit_textChanged(const QString &arg1);
QFileInfoList findIwads_possibleFiles();
void loadSelected();
void saveSelected();
void setStyles();
Expand Down
Loading

0 comments on commit 3f5b003

Please sign in to comment.