Add labels from scripts file to Script dropdowns

This commit is contained in:
GriffinR 2023-12-29 21:54:37 -05:00
parent 6a8d3a8197
commit ced402a4c6
6 changed files with 49 additions and 36 deletions

View file

@ -53,6 +53,7 @@ public:
QString battle_scene; QString battle_scene;
QString sharedEventsMap = ""; QString sharedEventsMap = "";
QString sharedScriptsMap = ""; QString sharedScriptsMap = "";
QStringList scriptsFileLabels;
QMap<QString, QJsonValue> customHeaders; QMap<QString, QJsonValue> customHeaders;
MapLayout *layout; MapLayout *layout;
bool isPersistedToFile = true; bool isPersistedToFile = true;
@ -70,6 +71,7 @@ public:
QList<MapConnection*> connections; QList<MapConnection*> connections;
QList<int> metatileLayerOrder; QList<int> metatileLayerOrder;
QList<float> metatileLayerOpacity; QList<float> metatileLayerOpacity;
void setName(QString mapName); void setName(QString mapName);
static QString mapConstantFromName(QString mapName, bool includePrefix = true); static QString mapConstantFromName(QString mapName, bool includePrefix = true);
int getWidth(); int getWidth();
@ -92,7 +94,7 @@ public:
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
QList<Event *> getAllEvents() const; QList<Event *> getAllEvents() const;
QStringList eventScriptLabels(Event::Group group = Event::Group::None) const; QStringList getScriptLabels(Event::Group group = Event::Group::None) const;
void removeEvent(Event *); void removeEvent(Event *);
void addEvent(Event *); void addEvent(Event *);
QPixmap renderConnection(MapConnection, MapLayout *); QPixmap renderConnection(MapConnection, MapLayout *);
@ -105,6 +107,7 @@ public:
bool isWithinBounds(int x, int y); bool isWithinBounds(int x, int y);
bool isWithinBorderBounds(int x, int y); bool isWithinBorderBounds(int x, int y);
void openScript(QString label); void openScript(QString label);
QString getScriptsFilePath() const;
MapPixmapItem *mapItem = nullptr; MapPixmapItem *mapItem = nullptr;
void setMapItem(MapPixmapItem *item) { mapItem = item; } void setMapItem(MapPixmapItem *item) { mapItem = item; }

View file

@ -204,9 +204,8 @@ public:
QString fixPalettePath(QString path); QString fixPalettePath(QString path);
QString fixGraphicPath(QString path); QString fixGraphicPath(QString path);
QString getScriptFileExtension(bool usePoryScript) const; static QString getScriptFileExtension(bool usePoryScript);
QString getScriptDefaultString(bool usePoryScript, QString mapName) const; QString getScriptDefaultString(bool usePoryScript, QString mapName) const;
QString getMapScriptsFilePath(const QString &mapName) const;
QStringList getEventScriptsFilePaths() const; QStringList getEventScriptsFilePaths() const;
QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels); QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels);
QStringList getGlobalScriptLabels(); QStringList getGlobalScriptLabels();

View file

@ -27,6 +27,7 @@ Map::~Map() {
void Map::setName(QString mapName) { void Map::setName(QString mapName) {
name = mapName; name = mapName;
constantName = mapConstantFromName(mapName); constantName = mapConstantFromName(mapName);
scriptsFileLabels = ParseUtil::getGlobalScriptLabels(this->getScriptsFilePath());
} }
QString Map::mapConstantFromName(QString mapName, bool includePrefix) { QString Map::mapConstantFromName(QString mapName, bool includePrefix) {
@ -462,9 +463,10 @@ QList<Event *> Map::getAllEvents() const {
return all_events; return all_events;
} }
QStringList Map::eventScriptLabels(Event::Group group) const { QStringList Map::getScriptLabels(Event::Group group) const {
QStringList scriptLabels; QStringList scriptLabels;
// Get script labels currently in-use by the map's events
if (group == Event::Group::None) { if (group == Event::Group::None) {
ScriptTracker scriptTracker; ScriptTracker scriptTracker;
for (Event *event : this->getAllEvents()) { for (Event *event : this->getAllEvents()) {
@ -479,14 +481,30 @@ QStringList Map::eventScriptLabels(Event::Group group) const {
scriptLabels = scriptTracker.getScripts(); scriptLabels = scriptTracker.getScripts();
} }
scriptLabels.removeAll(""); // Add scripts from map's scripts file, and empty names.
scriptLabels.append(scriptsFileLabels);
scriptLabels.prepend("0x0"); scriptLabels.prepend("0x0");
scriptLabels.prepend("NULL"); scriptLabels.prepend("NULL");
scriptLabels.removeAll("");
scriptLabels.removeDuplicates(); scriptLabels.removeDuplicates();
return scriptLabels; return scriptLabels;
} }
QString Map::getScriptsFilePath() const {
const bool usePoryscript = projectConfig.getUsePoryScript();
auto path = QDir::cleanPath(QString("%1/%2/%3/scripts")
.arg(projectConfig.getProjectDir())
.arg(projectConfig.getFilePath(ProjectFilePath::data_map_folders))
.arg(this->name));
auto extension = Project::getScriptFileExtension(usePoryscript);
if (usePoryscript && !QFile::exists(path + extension))
extension = Project::getScriptFileExtension(false);
path += extension;
return path;
}
void Map::removeEvent(Event *event) { void Map::removeEvent(Event *event) {
for (Event::Group key : events.keys()) { for (Event::Group key : events.keys()) {
events[key].removeAll(event); events[key].removeAll(event);

View file

@ -2167,13 +2167,12 @@ bool Editor::eventLimitReached(Event::Type event_type) {
} }
void Editor::openMapScripts() const { void Editor::openMapScripts() const {
const QString scriptPath = project->getMapScriptsFilePath(map->name); openInTextEditor(map->getScriptsFilePath());
openInTextEditor(scriptPath);
} }
void Editor::openScript(const QString &scriptLabel) const { void Editor::openScript(const QString &scriptLabel) const {
// Find the location of scriptLabel. // Find the location of scriptLabel.
QStringList scriptPaths(project->getMapScriptsFilePath(map->name)); QStringList scriptPaths(map->getScriptsFilePath());
scriptPaths << project->getEventScriptsFilePaths(); scriptPaths << project->getEventScriptsFilePaths();
int lineNum = 0; int lineNum = 0;
QString scriptPath = scriptPaths.first(); QString scriptPath = scriptPaths.first();

View file

@ -2403,7 +2403,7 @@ QString Project::fixGraphicPath(QString path) {
return path; return path;
} }
QString Project::getScriptFileExtension(bool usePoryScript) const { QString Project::getScriptFileExtension(bool usePoryScript) {
if(usePoryScript) { if(usePoryScript) {
return ".pory"; return ".pory";
} else { } else {
@ -2418,16 +2418,6 @@ QString Project::getScriptDefaultString(bool usePoryScript, QString mapName) con
return QString("%1_MapScripts::\n\t.byte 0\n").arg(mapName); return QString("%1_MapScripts::\n\t.byte 0\n").arg(mapName);
} }
QString Project::getMapScriptsFilePath(const QString &mapName) const {
const bool usePoryscript = projectConfig.getUsePoryScript();
auto path = QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_map_folders) + "/" + mapName + "/scripts");
auto extension = getScriptFileExtension(usePoryscript);
if (usePoryscript && !QFile::exists(path + extension))
extension = getScriptFileExtension(false);
path += extension;
return path;
}
QStringList Project::getEventScriptsFilePaths() const { QStringList Project::getEventScriptsFilePaths() const {
QStringList filePaths(QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_event_scripts))); QStringList filePaths(QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_event_scripts)));
const QString scriptsDir = QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_scripts_folders)); const QString scriptsDir = QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_scripts_folders));

View file

@ -367,14 +367,16 @@ void ObjectFrame::populate(Project *project) {
this->combo_flag->addItems(project->flagNames); this->combo_flag->addItems(project->flagNames);
this->combo_trainer_type->addItems(project->trainerTypes); this->combo_trainer_type->addItems(project->trainerTypes);
QStringList scriptLabels = this->object->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); // The script dropdown is populated with scripts used by the map's events and from its scripts file.
scriptLabels.removeDuplicates(); QStringList scriptLabels;
if (this->object->getMap()) { if (this->object->getMap()) {
const auto localScriptLabels = this->object->getMap()->eventScriptLabels(); scriptLabels.append(this->object->getMap()->getScriptLabels());
this->combo_script->addItems(localScriptLabels); this->combo_script->addItems(scriptLabels);
} }
// The dropdown's autocomplete has all script labels across the full project.
scriptLabels.append(project->getGlobalScriptLabels());
scriptLabels.removeDuplicates();
this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
this->scriptCompleter->setFilterMode(Qt::MatchContains); this->scriptCompleter->setFilterMode(Qt::MatchContains);
@ -635,15 +637,16 @@ void TriggerFrame::populate(Project *project) {
// var combo // var combo
this->combo_var->addItems(project->varNames); this->combo_var->addItems(project->varNames);
// script // The script dropdown is populated with scripts used by the map's events and from its scripts file.
QStringList scriptLabels = this->trigger->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); QStringList scriptLabels;
scriptLabels.removeDuplicates();
if (this->trigger->getMap()) { if (this->trigger->getMap()) {
const auto localScriptLabels = this->trigger->getMap()->eventScriptLabels(); scriptLabels.append(this->trigger->getMap()->getScriptLabels());
this->combo_script->addItems(localScriptLabels); this->combo_script->addItems(scriptLabels);
} }
// The dropdown's autocomplete has all script labels across the full project.
scriptLabels.append(project->getGlobalScriptLabels());
scriptLabels.removeDuplicates();
this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
this->scriptCompleter->setFilterMode(Qt::MatchContains); this->scriptCompleter->setFilterMode(Qt::MatchContains);
@ -769,15 +772,16 @@ void SignFrame::populate(Project *project) {
// facing dir // facing dir
this->combo_facing_dir->addItems(project->bgEventFacingDirections); this->combo_facing_dir->addItems(project->bgEventFacingDirections);
// script // The script dropdown is populated with scripts used by the map's events and from its scripts file.
QStringList scriptLabels = this->sign->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); QStringList scriptLabels;
scriptLabels.removeDuplicates();
if (this->sign->getMap()) { if (this->sign->getMap()) {
const auto localScriptLabels = this->sign->getMap()->eventScriptLabels(); scriptLabels.append(this->sign->getMap()->getScriptLabels());
this->combo_script->addItems(localScriptLabels); this->combo_script->addItems(scriptLabels);
} }
// The dropdown's autocomplete has all script labels across the full project.
scriptLabels.append(project->getGlobalScriptLabels());
scriptLabels.removeDuplicates();
this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
this->scriptCompleter->setFilterMode(Qt::MatchContains); this->scriptCompleter->setFilterMode(Qt::MatchContains);