Add labels from scripts file to Script dropdowns
This commit is contained in:
parent
6a8d3a8197
commit
ced402a4c6
6 changed files with 49 additions and 36 deletions
|
@ -53,6 +53,7 @@ public:
|
|||
QString battle_scene;
|
||||
QString sharedEventsMap = "";
|
||||
QString sharedScriptsMap = "";
|
||||
QStringList scriptsFileLabels;
|
||||
QMap<QString, QJsonValue> customHeaders;
|
||||
MapLayout *layout;
|
||||
bool isPersistedToFile = true;
|
||||
|
@ -70,6 +71,7 @@ public:
|
|||
QList<MapConnection*> connections;
|
||||
QList<int> metatileLayerOrder;
|
||||
QList<float> metatileLayerOpacity;
|
||||
|
||||
void setName(QString mapName);
|
||||
static QString mapConstantFromName(QString mapName, bool includePrefix = true);
|
||||
int getWidth();
|
||||
|
@ -92,7 +94,7 @@ public:
|
|||
void _floodFillCollisionElevation(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;
|
||||
QStringList eventScriptLabels(Event::Group group = Event::Group::None) const;
|
||||
QStringList getScriptLabels(Event::Group group = Event::Group::None) const;
|
||||
void removeEvent(Event *);
|
||||
void addEvent(Event *);
|
||||
QPixmap renderConnection(MapConnection, MapLayout *);
|
||||
|
@ -105,6 +107,7 @@ public:
|
|||
bool isWithinBounds(int x, int y);
|
||||
bool isWithinBorderBounds(int x, int y);
|
||||
void openScript(QString label);
|
||||
QString getScriptsFilePath() const;
|
||||
|
||||
MapPixmapItem *mapItem = nullptr;
|
||||
void setMapItem(MapPixmapItem *item) { mapItem = item; }
|
||||
|
|
|
@ -204,9 +204,8 @@ public:
|
|||
QString fixPalettePath(QString path);
|
||||
QString fixGraphicPath(QString path);
|
||||
|
||||
QString getScriptFileExtension(bool usePoryScript) const;
|
||||
static QString getScriptFileExtension(bool usePoryScript);
|
||||
QString getScriptDefaultString(bool usePoryScript, QString mapName) const;
|
||||
QString getMapScriptsFilePath(const QString &mapName) const;
|
||||
QStringList getEventScriptsFilePaths() const;
|
||||
QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels);
|
||||
QStringList getGlobalScriptLabels();
|
||||
|
|
|
@ -27,6 +27,7 @@ Map::~Map() {
|
|||
void Map::setName(QString mapName) {
|
||||
name = mapName;
|
||||
constantName = mapConstantFromName(mapName);
|
||||
scriptsFileLabels = ParseUtil::getGlobalScriptLabels(this->getScriptsFilePath());
|
||||
}
|
||||
|
||||
QString Map::mapConstantFromName(QString mapName, bool includePrefix) {
|
||||
|
@ -462,9 +463,10 @@ QList<Event *> Map::getAllEvents() const {
|
|||
return all_events;
|
||||
}
|
||||
|
||||
QStringList Map::eventScriptLabels(Event::Group group) const {
|
||||
QStringList Map::getScriptLabels(Event::Group group) const {
|
||||
QStringList scriptLabels;
|
||||
|
||||
// Get script labels currently in-use by the map's events
|
||||
if (group == Event::Group::None) {
|
||||
ScriptTracker scriptTracker;
|
||||
for (Event *event : this->getAllEvents()) {
|
||||
|
@ -479,14 +481,30 @@ QStringList Map::eventScriptLabels(Event::Group group) const {
|
|||
scriptLabels = scriptTracker.getScripts();
|
||||
}
|
||||
|
||||
scriptLabels.removeAll("");
|
||||
// Add scripts from map's scripts file, and empty names.
|
||||
scriptLabels.append(scriptsFileLabels);
|
||||
scriptLabels.prepend("0x0");
|
||||
scriptLabels.prepend("NULL");
|
||||
|
||||
scriptLabels.removeAll("");
|
||||
scriptLabels.removeDuplicates();
|
||||
|
||||
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) {
|
||||
for (Event::Group key : events.keys()) {
|
||||
events[key].removeAll(event);
|
||||
|
|
|
@ -2167,13 +2167,12 @@ bool Editor::eventLimitReached(Event::Type event_type) {
|
|||
}
|
||||
|
||||
void Editor::openMapScripts() const {
|
||||
const QString scriptPath = project->getMapScriptsFilePath(map->name);
|
||||
openInTextEditor(scriptPath);
|
||||
openInTextEditor(map->getScriptsFilePath());
|
||||
}
|
||||
|
||||
void Editor::openScript(const QString &scriptLabel) const {
|
||||
// Find the location of scriptLabel.
|
||||
QStringList scriptPaths(project->getMapScriptsFilePath(map->name));
|
||||
QStringList scriptPaths(map->getScriptsFilePath());
|
||||
scriptPaths << project->getEventScriptsFilePaths();
|
||||
int lineNum = 0;
|
||||
QString scriptPath = scriptPaths.first();
|
||||
|
|
|
@ -2403,7 +2403,7 @@ QString Project::fixGraphicPath(QString path) {
|
|||
return path;
|
||||
}
|
||||
|
||||
QString Project::getScriptFileExtension(bool usePoryScript) const {
|
||||
QString Project::getScriptFileExtension(bool usePoryScript) {
|
||||
if(usePoryScript) {
|
||||
return ".pory";
|
||||
} else {
|
||||
|
@ -2418,16 +2418,6 @@ QString Project::getScriptDefaultString(bool usePoryScript, QString mapName) con
|
|||
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 filePaths(QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_event_scripts)));
|
||||
const QString scriptsDir = QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_scripts_folders));
|
||||
|
|
|
@ -367,14 +367,16 @@ void ObjectFrame::populate(Project *project) {
|
|||
this->combo_flag->addItems(project->flagNames);
|
||||
this->combo_trainer_type->addItems(project->trainerTypes);
|
||||
|
||||
QStringList scriptLabels = this->object->getMap()->eventScriptLabels() + project->getGlobalScriptLabels();
|
||||
scriptLabels.removeDuplicates();
|
||||
|
||||
// The script dropdown is populated with scripts used by the map's events and from its scripts file.
|
||||
QStringList scriptLabels;
|
||||
if (this->object->getMap()) {
|
||||
const auto localScriptLabels = this->object->getMap()->eventScriptLabels();
|
||||
this->combo_script->addItems(localScriptLabels);
|
||||
scriptLabels.append(this->object->getMap()->getScriptLabels());
|
||||
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->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
this->scriptCompleter->setFilterMode(Qt::MatchContains);
|
||||
|
@ -635,15 +637,16 @@ void TriggerFrame::populate(Project *project) {
|
|||
// var combo
|
||||
this->combo_var->addItems(project->varNames);
|
||||
|
||||
// script
|
||||
QStringList scriptLabels = this->trigger->getMap()->eventScriptLabels() + project->getGlobalScriptLabels();
|
||||
scriptLabels.removeDuplicates();
|
||||
|
||||
// The script dropdown is populated with scripts used by the map's events and from its scripts file.
|
||||
QStringList scriptLabels;
|
||||
if (this->trigger->getMap()) {
|
||||
const auto localScriptLabels = this->trigger->getMap()->eventScriptLabels();
|
||||
this->combo_script->addItems(localScriptLabels);
|
||||
scriptLabels.append(this->trigger->getMap()->getScriptLabels());
|
||||
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->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
this->scriptCompleter->setFilterMode(Qt::MatchContains);
|
||||
|
@ -769,15 +772,16 @@ void SignFrame::populate(Project *project) {
|
|||
// facing dir
|
||||
this->combo_facing_dir->addItems(project->bgEventFacingDirections);
|
||||
|
||||
// script
|
||||
QStringList scriptLabels = this->sign->getMap()->eventScriptLabels() + project->getGlobalScriptLabels();
|
||||
scriptLabels.removeDuplicates();
|
||||
|
||||
// The script dropdown is populated with scripts used by the map's events and from its scripts file.
|
||||
QStringList scriptLabels;
|
||||
if (this->sign->getMap()) {
|
||||
const auto localScriptLabels = this->sign->getMap()->eventScriptLabels();
|
||||
this->combo_script->addItems(localScriptLabels);
|
||||
scriptLabels.append(this->sign->getMap()->getScriptLabels());
|
||||
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->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
this->scriptCompleter->setFilterMode(Qt::MatchContains);
|
||||
|
|
Loading…
Reference in a new issue