-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create p2ce addons, other misc #6
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
31bc192
feat: change logo for p2ce variant
craftablescience e9d519e
feat: open new mods in file explorer after creation
craftablescience 92bec5c
feat: add basic p2ce addon creator
craftablescience b442a3d
chore: bump version
craftablescience 1a8722b
fix: add safe mode game launch config, remove -game from hammer
craftablescience 8dde0dc
fix: remove kv3 header from generated p2ce addon metadata
craftablescience File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#include "NewP2CEAddonDialog.h" | ||
|
||
#include <filesystem> | ||
#include <utility> | ||
|
||
#include <QCheckBox> | ||
#include <QComboBox> | ||
#include <QDesktopServices> | ||
#include <QDialogButtonBox> | ||
#include <QDir> | ||
#include <QFile> | ||
#include <QFormLayout> | ||
#include <QLabel> | ||
#include <QLineEdit> | ||
#include <QMessageBox> | ||
#include <QStandardPaths> | ||
#include <QPlainTextEdit> | ||
|
||
NewP2CEAddonDialog::NewP2CEAddonDialog(QString gameRoot_, QWidget* parent) | ||
: QDialog(parent) | ||
, gameRoot(std::move(gameRoot_)) { | ||
// Window setup | ||
this->setModal(true); | ||
this->setWindowTitle(tr("New Addon")); | ||
this->setMinimumWidth(350); | ||
|
||
// Create UI elements | ||
auto* layout = new QFormLayout{this}; | ||
|
||
this->addonID = new QLineEdit{this}; | ||
this->addonID->setPlaceholderText(tr("For example: p2ce, revolution, portal2")); | ||
layout->addRow(tr("Addon ID"), this->addonID); | ||
|
||
this->addonName = new QLineEdit{this}; | ||
this->addonName->setPlaceholderText(tr("My Cool Addon")); | ||
layout->addRow(tr("Addon Name"), this->addonName); | ||
|
||
this->addonDesc = new QPlainTextEdit{this}; | ||
this->addonDesc->setPlaceholderText(tr("A description of the addon.")); | ||
layout->addRow(tr("Addon Description"), this->addonDesc); | ||
|
||
this->addonType = new QComboBox{this}; | ||
this->addonType->addItem("Campaign"); | ||
this->addonType->addItem("Map"); | ||
this->addonType->addItem("Asset Pack"); | ||
this->addonType->addItem("Other"); | ||
layout->addRow(tr("Addon Type"), this->addonType); | ||
|
||
this->addShortcutOnDesktop = new QCheckBox{this}; | ||
this->addShortcutOnDesktop->setCheckState(Qt::Unchecked); | ||
layout->addRow(tr("Create Desktop Shortcut"), this->addShortcutOnDesktop); | ||
|
||
auto* buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this}; | ||
layout->addWidget(buttonBox); | ||
|
||
// Connect ok/cancel buttons to download stuff | ||
QObject::connect(buttonBox, &QDialogButtonBox::accepted, this, [this] { | ||
// Validate mod ID | ||
if (this->addonID->text().trimmed().isEmpty()) { | ||
QMessageBox::critical(this, tr("Incorrect Input"), tr("Addon ID must not be empty.")); | ||
return; | ||
} | ||
|
||
const auto addonInstallDir = this->getAddonInstallDir(); | ||
|
||
// Validate install location | ||
if (std::filesystem::exists(addonInstallDir.toLocal8Bit().constData())) { | ||
QMessageBox::critical(this, tr("Incorrect Input"), tr("A folder with the name of the addon ID already exists at this install location.")); | ||
return; | ||
} | ||
|
||
// Create directory structure | ||
QDir dir{this->getAddonInstallDir()}; | ||
dir.mkpath("maps"); | ||
dir.mkpath("materials"); | ||
dir.mkpath("models"); | ||
dir.mkpath("particles"); | ||
dir.mkpath("resource"); | ||
dir.mkpath("scenes"); | ||
dir.mkpath("scripts"); | ||
dir.mkpath("sound"); | ||
|
||
// Create addon.kv3 | ||
QFile addonKV3{this->getAddonInstallDir() + QDir::separator() + "addon.kv3"}; | ||
addonKV3.open(QIODevice::WriteOnly | QIODevice::Text); | ||
|
||
static constexpr auto p2ceAddonKV3ContentsBase = R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} --> | ||
{ | ||
mod = "%1" | ||
description = "%2" | ||
type = "%3" | ||
id = 0 | ||
thumbnail = "" | ||
authors = [ ] | ||
dependencies = [ ] | ||
tags = [ ] | ||
ignore = [ ] | ||
metadata = | ||
{ | ||
} | ||
assets = | ||
{ | ||
logo = "" | ||
cover = "" | ||
} | ||
})"; | ||
{ | ||
QTextStream out{&addonKV3}; | ||
out << QString{p2ceAddonKV3ContentsBase}.arg(this->addonName->text(), this->addonDesc->toPlainText(), this->addonType->currentText()).toLocal8Bit(); | ||
} | ||
addonKV3.close(); | ||
|
||
// Create desktop shortcut | ||
if (this->addShortcutOnDesktop->isChecked()) { | ||
const auto shortcutPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + QDir::separator() + this->addonID->text().trimmed(); | ||
#ifdef _WIN32 | ||
QFile::link(addonInstallDir, shortcutPath + ".lnk"); | ||
#else | ||
QFile::link(addonInstallDir, shortcutPath); | ||
#endif | ||
} | ||
QDesktopServices::openUrl({QString("file:///") + addonInstallDir}); | ||
|
||
this->accept(); | ||
}); | ||
QObject::connect(buttonBox, &QDialogButtonBox::rejected, this, &NewP2CEAddonDialog::reject); | ||
} | ||
|
||
QString NewP2CEAddonDialog::getAddonInstallDir() const { | ||
return this->gameRoot + QDir::separator() + "addons" + QDir::separator() + this->addonID->text().trimmed(); | ||
} | ||
|
||
void NewP2CEAddonDialog::open(QString gameRoot, QWidget* parent) { | ||
auto* dialog = new NewP2CEAddonDialog{std::move(gameRoot), parent}; | ||
dialog->exec(); | ||
dialog->deleteLater(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <QDialog> | ||
|
||
class QCheckBox; | ||
class QComboBox; | ||
class QLineEdit; | ||
class QPlainTextEdit; | ||
|
||
class NewP2CEAddonDialog : public QDialog { | ||
Q_OBJECT; | ||
|
||
public: | ||
NewP2CEAddonDialog(QString gameRoot_, QWidget* parent = nullptr); | ||
|
||
[[nodiscard]] QString getAddonInstallDir() const; | ||
|
||
static void open(QString gameRoot, QWidget* parent = nullptr); | ||
|
||
private: | ||
QString gameRoot; | ||
|
||
QLineEdit* addonID; | ||
QLineEdit* addonName; | ||
QPlainTextEdit* addonDesc; | ||
QComboBox* addonType; | ||
QCheckBox* addShortcutOnDesktop; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you exclude this line? It is optional