Merge remote-tracking branch 'origin/master' into scripting

This commit is contained in:
Marcus Huderle 2020-05-08 11:35:58 -05:00
commit e0afb24002
7 changed files with 65 additions and 28 deletions

View file

@ -677,7 +677,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QStackedWidget" name="stackedWidget_MapEvents"> <widget class="AdjustingStackedWidget" name="stackedWidget_MapEvents">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -3036,6 +3036,11 @@
<extends>QComboBox</extends> <extends>QComboBox</extends>
<header>noscrollcombobox.h</header> <header>noscrollcombobox.h</header>
</customwidget> </customwidget>
<customwidget>
<class>AdjustingStackedWidget</class>
<extends>QStackedWidget</extends>
<header>adjustingstackedwidget.h</header>
</customwidget>
<customwidget> <customwidget>
<class>GraphicsView</class> <class>GraphicsView</class>
<extends>QGraphicsView</extends> <extends>QGraphicsView</extends>

View file

@ -37,7 +37,7 @@ public:
QList<QStringList> groupedMapNames; QList<QStringList> groupedMapNames;
QStringList *mapNames = nullptr; QStringList *mapNames = nullptr;
QMap<QString, QVariant> miscConstants; QMap<QString, QVariant> miscConstants;
QList<HealLocation> flyableMaps; QList<HealLocation> healLocations;
QMap<QString, QString>* mapConstantsToMapNames; QMap<QString, QString>* mapConstantsToMapNames;
QMap<QString, QString>* mapNamesToMapConstants; QMap<QString, QString>* mapNamesToMapConstants;
QList<QString> mapLayoutsTable; QList<QString> mapLayoutsTable;

View file

@ -0,0 +1,25 @@
#ifndef ADJUSTINGSTACKEDWIDGET_H
#define ADJUSTINGSTACKEDWIDGET_H
#include <QStackedWidget>
class AdjustingStackedWidget : public QStackedWidget
{
Q_OBJECT
public:
AdjustingStackedWidget(QWidget *parent = nullptr) : QStackedWidget(parent) {}
// override this to allow the stacked widget's current page to dictate size
virtual void setCurrentIndex(int index) {
QStackedWidget::setCurrentIndex(index);
for (int i = 0; i < this->count(); ++i) {
this->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
}
this->widget(index)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
};
#endif // ADJUSTINGSTACKEDWIDGET_H

View file

@ -122,6 +122,7 @@ HEADERS += include/core/block.h \
include/ui/noscrollcombobox.h \ include/ui/noscrollcombobox.h \
include/ui/noscrollspinbox.h \ include/ui/noscrollspinbox.h \
include/ui/montabwidget.h \ include/ui/montabwidget.h \
include/ui/adjustingstackedwidget.h \
include/ui/paletteeditor.h \ include/ui/paletteeditor.h \
include/ui/selectablepixmapitem.h \ include/ui/selectablepixmapitem.h \
include/ui/tileseteditor.h \ include/ui/tileseteditor.h \

View file

@ -1067,10 +1067,14 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
} else { } else {
// Left-clicking while in paint mode will add a new event of the // Left-clicking while in paint mode will add a new event of the
// type of the first currently selected events. // type of the first currently selected events.
DraggablePixmapItem * newEvent = addNewEvent(this->selected_events->first()->event->get("event_type")); // Disallow adding heal locations, deleting them is not possible yet
if (newEvent) { QString eventType = this->selected_events->first()->event->get("event_type");
newEvent->move(x, y); if (eventType != "event_heal_location") {
selectMapEvent(newEvent, false); DraggablePixmapItem * newEvent = addNewEvent(eventType);
if (newEvent) {
newEvent->move(x, y);
selectMapEvent(newEvent, false);
}
} }
} }
} else if (map_edit_mode == "select") { } else if (map_edit_mode == "select") {
@ -1868,8 +1872,8 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
event->put("map_name", map->name); event->put("map_name", map->name);
if (event_type == "event_heal_location") { if (event_type == "event_heal_location") {
HealLocation hl = HealLocation::fromEvent(event); HealLocation hl = HealLocation::fromEvent(event);
project->flyableMaps.append(hl); project->healLocations.append(hl);
event->put("index", project->flyableMaps.length()); event->put("index", project->healLocations.length());
} }
map->addEvent(event); map->addEvent(event);
project->loadEventPixmaps(map->getAllEvents()); project->loadEventPixmaps(map->getAllEvents());

View file

@ -10,6 +10,7 @@
#include "currentselectedmetatilespixmapitem.h" #include "currentselectedmetatilespixmapitem.h"
#include "customattributestable.h" #include "customattributestable.h"
#include "scripting.h" #include "scripting.h"
#include "adjustingstackedwidget.h"
#include <QFileDialog> #include <QFileDialog>
#include <QDirIterator> #include <QDirIterator>

View file

@ -341,7 +341,7 @@ bool Project::loadMapData(Map* map) {
} }
map->events["heal_event_group"].clear(); map->events["heal_event_group"].clear();
for (auto it = flyableMaps.begin(); it != flyableMaps.end(); it++) { for (auto it = healLocations.begin(); it != healLocations.end(); it++) {
HealLocation loc = *it; HealLocation loc = *it;
@ -917,33 +917,34 @@ void Project::saveHealLocationStruct(Map *map) {
QString constants_text = QString("#ifndef GUARD_CONSTANTS_HEAL_LOCATIONS_H\n"); QString constants_text = QString("#ifndef GUARD_CONSTANTS_HEAL_LOCATIONS_H\n");
constants_text += QString("#define GUARD_CONSTANTS_HEAL_LOCATIONS_H\n\n"); constants_text += QString("#define GUARD_CONSTANTS_HEAL_LOCATIONS_H\n\n");
QMap<QString, int> flyableMapsDupes; QMap<QString, int> healLocationsDupes;
QSet<QString> flyableMapsUnique; QSet<QString> healLocationsUnique;
// set flyableMapsDupes and flyableMapsUnique // set healLocationsDupes and healLocationsUnique
for (auto it = flyableMaps.begin(); it != flyableMaps.end(); it++) { for (auto it = healLocations.begin(); it != healLocations.end(); it++) {
HealLocation loc = *it; HealLocation loc = *it;
QString xname = loc.idName; QString xname = loc.idName;
if (flyableMapsUnique.contains(xname)) { if (healLocationsUnique.contains(xname)) {
flyableMapsDupes[xname] = 1; healLocationsDupes[xname] = 1;
} }
flyableMapsUnique.insert(xname); healLocationsUnique.insert(xname);
} }
// set new location in flyableMapsList // set new location in healLocations list
if (map->events["heal_event_group"].length() > 0) { if (map->events["heal_event_group"].length() > 0) {
for (Event *healEvent : map->events["heal_event_group"]) { for (Event *healEvent : map->events["heal_event_group"]) {
HealLocation hl = HealLocation::fromEvent(healEvent); HealLocation hl = HealLocation::fromEvent(healEvent);
flyableMaps[hl.index - 1] = hl; healLocations[hl.index - 1] = hl;
} }
} }
int i = 1; int i = 1;
for (auto map_in : flyableMaps) { for (auto map_in : healLocations) {
// add numbered suffix for duplicate constants // add numbered suffix for duplicate constants
if (flyableMapsDupes.keys().contains(map_in.idName)) { if (healLocationsDupes.keys().contains(map_in.idName)) {
map_in.idName += QString("_%1").arg(flyableMapsDupes[map_in.idName]); QString duplicateName = map_in.idName;
flyableMapsDupes[map_in.idName]++; map_in.idName += QString("_%1").arg(healLocationsDupes[duplicateName]);
healLocationsDupes[duplicateName]++;
} }
// Save first array (heal location coords), only data array in RSE // Save first array (heal location coords), only data array in RSE
@ -973,7 +974,7 @@ void Project::saveHealLocationStruct(Map *map) {
data_text += QString("};\n\n%1%2u16 sWhiteoutRespawnHealCenterMapIdxs[][2] =\n{\n") data_text += QString("};\n\n%1%2u16 sWhiteoutRespawnHealCenterMapIdxs[][2] =\n{\n")
.arg(dataQualifiers.value("heal_locations").isStatic ? "static " : "") .arg(dataQualifiers.value("heal_locations").isStatic ? "static " : "")
.arg(dataQualifiers.value("heal_locations").isConst ? "const " : ""); .arg(dataQualifiers.value("heal_locations").isConst ? "const " : "");
for (auto map_in : flyableMaps) { for (auto map_in : healLocations) {
data_text += QString(" [%1%2 - 1] = {MAP_GROUP(%3), MAP_NUM(%3)},\n") data_text += QString(" [%1%2 - 1] = {MAP_GROUP(%3), MAP_NUM(%3)},\n")
.arg(constantPrefix) .arg(constantPrefix)
.arg(map_in.idName) .arg(map_in.idName)
@ -984,7 +985,7 @@ void Project::saveHealLocationStruct(Map *map) {
data_text += QString("};\n\n%1%2u8 sWhiteoutRespawnHealerNpcIds[] =\n{\n") data_text += QString("};\n\n%1%2u8 sWhiteoutRespawnHealerNpcIds[] =\n{\n")
.arg(dataQualifiers.value("heal_locations").isStatic ? "static " : "") .arg(dataQualifiers.value("heal_locations").isStatic ? "static " : "")
.arg(dataQualifiers.value("heal_locations").isConst ? "const " : ""); .arg(dataQualifiers.value("heal_locations").isConst ? "const " : "");
for (auto map_in : flyableMaps) { for (auto map_in : healLocations) {
data_text += QString(" [%1%2 - 1] = %3,\n") data_text += QString(" [%1%2 - 1] = %3,\n")
.arg(constantPrefix) .arg(constantPrefix)
.arg(map_in.idName) .arg(map_in.idName)
@ -2120,7 +2121,7 @@ bool Project::readRegionMapSections() {
bool Project::readHealLocations() { bool Project::readHealLocations() {
dataQualifiers.clear(); dataQualifiers.clear();
flyableMaps.clear(); healLocations.clear();
QString filename = "src/data/heal_locations.h"; QString filename = "src/data/heal_locations.h";
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
QString text = parser.readTextFile(root + "/" + filename); QString text = parser.readTextFile(root + "/" + filename);
@ -2147,7 +2148,7 @@ bool Project::readHealLocations() {
unsigned x = spawn.captured("x").toUShort(); unsigned x = spawn.captured("x").toUShort();
unsigned y = spawn.captured("y").toUShort(); unsigned y = spawn.captured("y").toUShort();
unsigned npc = respawnNPC.captured("npc").toUShort(); unsigned npc = respawnNPC.captured("npc").toUShort();
flyableMaps.append(HealLocation(idName, mapName, i, x, y, respawnMapName, npc)); healLocations.append(HealLocation(idName, mapName, i, x, y, respawnMapName, npc));
} }
} else { } else {
dataQualifiers.insert("heal_locations", getDataQualifiers(text, "sHealLocations")); dataQualifiers.insert("heal_locations", getDataQualifiers(text, "sHealLocations"));
@ -2160,7 +2161,7 @@ bool Project::readHealLocations() {
QString mapName = match.captured("map"); QString mapName = match.captured("map");
unsigned x = match.captured("x").toUShort(); unsigned x = match.captured("x").toUShort();
unsigned y = match.captured("y").toUShort(); unsigned y = match.captured("y").toUShort();
flyableMaps.append(HealLocation(idName, mapName, i, x, y)); healLocations.append(HealLocation(idName, mapName, i, x, y));
} }
} }
return true; return true;
@ -2497,7 +2498,7 @@ void Project::saveMapHealEvents(Map *map) {
if (map->events["heal_event_group"].length() > 0) { if (map->events["heal_event_group"].length() > 0) {
for (Event *healEvent : map->events["heal_event_group"]) { for (Event *healEvent : map->events["heal_event_group"]) {
HealLocation hl = HealLocation::fromEvent(healEvent); HealLocation hl = HealLocation::fromEvent(healEvent);
flyableMaps[hl.index - 1] = hl; healLocations[hl.index - 1] = hl;
} }
} }
saveHealLocationStruct(map); saveHealLocationStruct(map);