Populate scripts comboboxes with scripts found in map.json

This commit is contained in:
BigBahss 2020-12-01 16:32:08 -05:00
parent e97b50a249
commit 62f73bee04
5 changed files with 86 additions and 29 deletions

View file

@ -15,6 +15,9 @@
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>9</number>
</property>
<item> <item>
<widget class="QGroupBox" name="groupBox_Themes"> <widget class="QGroupBox" name="groupBox_Themes">
<property name="sizePolicy"> <property name="sizePolicy">
@ -63,17 +66,17 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>482</width> <width>482</width>
<height>398</height> <height>392</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum> <enum>QLayout::SetMinimumSize</enum>
</property> </property>
<item row="5" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<widget class="QLabel" name="label_TextEditorGotoLineHelp"> <widget class="QLabel" name="label_TextEditorGotoLineHelp">
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The command that will be executed when clicking the &lt;span style=&quot; font-weight:600;&quot;&gt;Open Map Scripts&lt;/span&gt; button&lt;span style=&quot; font-weight:600;&quot;&gt;. %F&lt;/span&gt; will be substituted with the scripts file path and &lt;span style=&quot; font-weight:600;&quot;&gt;%L&lt;/span&gt; will be substituted with the line number of the event that is currently selected. &lt;span style=&quot; font-weight:600;&quot;&gt;%F &lt;/span&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;must&lt;/span&gt; be specified if &lt;span style=&quot; font-weight:600;&quot;&gt;%L&lt;/span&gt; is specified. If &lt;span style=&quot; font-weight:600;&quot;&gt;%F&lt;/span&gt; is &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; specified then the scripts file path will be appended to the end of the command.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the command that will be executed when clicking the &lt;span style=&quot; font-weight:600;&quot;&gt;Open Map Scripts&lt;/span&gt; button&lt;span style=&quot; font-weight:600;&quot;&gt;. %F&lt;/span&gt; will be substituted with the scripts file path and &lt;span style=&quot; font-weight:600;&quot;&gt;%L&lt;/span&gt; will be substituted with the line number of the script for the currently selected event. &lt;span style=&quot; font-weight:600;&quot;&gt;%F &lt;/span&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;must&lt;/span&gt; be specified if &lt;span style=&quot; font-weight:600;&quot;&gt;%L&lt;/span&gt; is specified. If &lt;span style=&quot; font-weight:600;&quot;&gt;%F&lt;/span&gt; is &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; specified then the scripts file path will be appended to the end of the command.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
@ -83,13 +86,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="5" column="0">
<widget class="QLineEdit" name="lineEdit_TextEditorGotoLine"> <widget class="QLabel" name="label_TextEditorGotoLine">
<property name="text">
<string>Goto Line Command</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_TextEditorOpenFolder">
<property name="toolTip"> <property name="toolTip">
<string>The shell command for your preferred text editor to open a file to a specific line number (possibly an absolute path if the program doesn't exist in your PATH).</string> <string>The shell command for your preferred text editor (possibly an absolute path if the program doesn't exist in your PATH).</string>
</property> </property>
<property name="placeholderText"> <property name="placeholderText">
<string>e.g. code --goto %F:%L</string> <string>e.g. code %D</string>
</property> </property>
<property name="clearButtonEnabled"> <property name="clearButtonEnabled">
<bool>true</bool> <bool>true</bool>
@ -99,7 +109,7 @@
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_TextEditorOpenFolderHelp"> <widget class="QLabel" name="label_TextEditorOpenFolderHelp">
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The command that will be executed when clicking &lt;span style=&quot; font-weight:600;&quot;&gt;Open Project in Text Editor&lt;/span&gt; in the &lt;span style=&quot; font-weight:600;&quot;&gt;Tools&lt;/span&gt; menu. &lt;span style=&quot; font-weight:600;&quot;&gt;%D&lt;/span&gt; will be substituted with the current project's root directory. If &lt;span style=&quot; font-weight:600;&quot;&gt;%D&lt;/span&gt; is &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; specified then the project directory will be appended to the end of the command.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the command that will be executed when clicking &lt;span style=&quot; font-weight:600;&quot;&gt;Open Project in Text Editor&lt;/span&gt; in the &lt;span style=&quot; font-weight:600;&quot;&gt;Tools&lt;/span&gt; menu. &lt;span style=&quot; font-weight:600;&quot;&gt;%D&lt;/span&gt; will be substituted with the current project's root directory. If &lt;span style=&quot; font-weight:600;&quot;&gt;%D&lt;/span&gt; is &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; specified then the project directory will be appended to the end of the command.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
@ -116,22 +126,47 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="5" column="1">
<widget class="QLineEdit" name="lineEdit_TextEditorOpenFolder"> <widget class="QLineEdit" name="lineEdit_TextEditorGotoLine">
<property name="toolTip"> <property name="toolTip">
<string>The shell command for your preferred text editor (possibly an absolute path if the program doesn't exist in your PATH).</string> <string>The shell command for your preferred text editor to open a file to a specific line number (possibly an absolute path if the program doesn't exist in your PATH).</string>
</property> </property>
<property name="placeholderText"> <property name="placeholderText">
<string>e.g. code %D</string> <string>e.g. code --goto %F:%L</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_TextEditorGotoLine"> <spacer name="verticalSpacer_2">
<property name="text"> <property name="orientation">
<string>Goto Line Command</string> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>15</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>

View file

@ -31,10 +31,10 @@ public:
Event(const Event&); Event(const Event&);
Event(QJsonObject, QString); Event(QJsonObject, QString);
public: public:
int x() { int x() const {
return getInt("x"); return getInt("x");
} }
int y() { int y() const {
return getInt("y"); return getInt("y");
} }
int elevation() { int elevation() {
@ -46,16 +46,16 @@ public:
void setY(int y) { void setY(int y) {
put("y", y); put("y", y);
} }
QString get(QString key) { QString get(const QString &key) const {
return values.value(key); return values.value(key);
} }
int getInt(QString key) { int getInt(const QString &key) const {
return values.value(key).toInt(nullptr, 0); return values.value(key).toInt(nullptr, 0);
} }
uint16_t getU16(QString key) { uint16_t getU16(const QString &key) const {
return values.value(key).toUShort(nullptr, 0); return values.value(key).toUShort(nullptr, 0);
} }
int16_t getS16(QString key) { int16_t getS16(const QString &key) const {
return values.value(key).toShort(nullptr, 0); return values.value(key).toShort(nullptr, 0);
} }
void put(QString key, int value) { void put(QString key, int value) {

View file

@ -83,7 +83,8 @@ 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 _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(); QList<Event*> getAllEvents() const;
QStringList eventScriptLabels(const QString &event_group_type = QString()) const;
void removeEvent(Event*); void removeEvent(Event*);
void addEvent(Event*); void addEvent(Event*);
QPixmap renderConnection(MapConnection, MapLayout *); QPixmap renderConnection(MapConnection, MapLayout *);

View file

@ -450,12 +450,32 @@ void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t colli
} }
} }
QList<Event *> Map::getAllEvents() { QList<Event *> Map::getAllEvents() const {
QList<Event*> all; QList<Event *> all_events;
for (QList<Event*> list : events.values()) { for (const auto &event_list : events) {
all += list; all_events << event_list;
} }
return all; return all_events;
}
QStringList Map::eventScriptLabels(const QString &event_group_type) const {
QStringList scriptLabels;
if (event_group_type.isEmpty()) {
for (const auto *event : getAllEvents())
scriptLabels << event->get("script_label");
} else {
for (const auto *event : events.value(event_group_type))
scriptLabels << event->get("script_label");
}
scriptLabels.removeDuplicates();
scriptLabels.removeAll(QString());
if (scriptLabels.contains("0x0"))
scriptLabels.move(scriptLabels.indexOf("0x0"), scriptLabels.count() - 1);
if (scriptLabels.contains("NULL"))
scriptLabels.move(scriptLabels.indexOf("NULL"), scriptLabels.count() - 1);
return scriptLabels;
} }
void Map::removeEvent(Event *event) { void Map::removeEvent(Event *event) {

View file

@ -1789,6 +1789,7 @@ void MainWindow::updateSelectedObjects() {
"normal movement behavior actions."); "normal movement behavior actions.");
combo->setMinimumContentsLength(4); combo->setMinimumContentsLength(4);
} else if (key == "script_label") { } else if (key == "script_label") {
combo->addItems(editor->map->eventScriptLabels());
combo->setToolTip("The script which is executed with this event."); combo->setToolTip("The script which is executed with this event.");
} else if (key == "trainer_type") { } else if (key == "trainer_type") {
combo->addItems(*editor->project->trainerTypes); combo->addItems(*editor->project->trainerTypes);