mirror of
https://github.com/huderlem/porymap.git
synced 2026-07-01 03:59:54 -05:00
Make Map members private
This commit is contained in:
parent
18308fa9de
commit
b7d78b0263
|
|
@ -37,58 +37,74 @@ public:
|
|||
~Map();
|
||||
|
||||
public:
|
||||
QString name;
|
||||
QString constantName;
|
||||
|
||||
QString song;
|
||||
QString layoutId;
|
||||
QString location;
|
||||
bool requiresFlash;
|
||||
QString weather;
|
||||
QString type;
|
||||
bool show_location;
|
||||
bool allowRunning;
|
||||
bool allowBiking;
|
||||
bool allowEscaping;
|
||||
int floorNumber = 0;
|
||||
QString battle_scene;
|
||||
|
||||
QString sharedEventsMap = "";
|
||||
QString sharedScriptsMap = "";
|
||||
|
||||
QStringList scriptsFileLabels;
|
||||
QMap<QString, QJsonValue> customHeaders;
|
||||
|
||||
Layout *layout = nullptr;
|
||||
void setLayout(Layout *layout);
|
||||
|
||||
bool isPersistedToFile = true;
|
||||
bool hasUnsavedDataChanges = false;
|
||||
|
||||
bool needsLayoutDir = true;
|
||||
bool needsHealLocation = false;
|
||||
bool scriptsLoaded = false;
|
||||
|
||||
QMap<Event::Group, QList<Event *>> events;
|
||||
QList<Event *> ownedEvents; // for memory management
|
||||
|
||||
QList<int> metatileLayerOrder;
|
||||
QList<float> metatileLayerOpacity;
|
||||
|
||||
void setName(QString mapName);
|
||||
QString name() const { return m_name; }
|
||||
QString constantName() const { return m_constantName; }
|
||||
|
||||
static QString mapConstantFromName(QString mapName, bool includePrefix = true);
|
||||
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
int getBorderWidth();
|
||||
int getBorderHeight();
|
||||
void setLayout(Layout *layout);
|
||||
Layout* layout() const { return m_layout; }
|
||||
|
||||
QList<Event *> getAllEvents() const;
|
||||
void setLayoutId(const QString &layoutId) { m_layoutId = layoutId; }
|
||||
QString layoutId() const { return m_layoutId; }
|
||||
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
int getBorderWidth() const;
|
||||
int getBorderHeight() const;
|
||||
|
||||
// TODO: Combine these into a separate MapHeader class?
|
||||
void setSong(const QString &song);
|
||||
void setLocation(const QString &location);
|
||||
void setRequiresFlash(bool requiresFlash);
|
||||
void setWeather(const QString &weather);
|
||||
void setType(const QString &type);
|
||||
void setShowsLocation(bool showsLocation);
|
||||
void setAllowsRunning(bool allowsRunning);
|
||||
void setAllowsBiking(bool allowsBiking);
|
||||
void setAllowsEscaping(bool allowsEscaping);
|
||||
void setFloorNumber(int floorNumber);
|
||||
void setBattleScene(const QString &battleScene);
|
||||
|
||||
QString song() const { return m_song; }
|
||||
QString location() const { return m_location; }
|
||||
bool requiresFlash() const { return m_requiresFlash; }
|
||||
QString weather() const { return m_weather; }
|
||||
QString type() const { return m_type; }
|
||||
bool showsLocation() const { return m_showsLocation; }
|
||||
bool allowsRunning() const { return m_allowsRunning; }
|
||||
bool allowsBiking() const { return m_allowsBiking; }
|
||||
bool allowsEscaping() const { return m_allowsEscaping; }
|
||||
int floorNumber() const { return m_floorNumber; }
|
||||
QString battleScene() const { return m_battleScene; }
|
||||
|
||||
void setSharedEventsMap(const QString &sharedEventsMap) { m_sharedEventsMap = sharedEventsMap; }
|
||||
void setSharedScriptsMap(const QString &sharedScriptsMap) { m_sharedScriptsMap = sharedScriptsMap; }
|
||||
|
||||
QString sharedEventsMap() const { return m_sharedEventsMap; }
|
||||
QString sharedScriptsMap() const { return m_sharedScriptsMap; }
|
||||
|
||||
void setNeedsLayoutDir(bool needsLayoutDir) { m_needsLayoutDir = needsLayoutDir; }
|
||||
void setNeedsHealLocation(bool needsHealLocation) { m_needsHealLocation = needsHealLocation; }
|
||||
void setIsPersistedToFile(bool persistedToFile) { m_isPersistedToFile = persistedToFile; }
|
||||
void setHasUnsavedDataChanges(bool unsavedDataChanges) { m_hasUnsavedDataChanges = unsavedDataChanges; }
|
||||
|
||||
bool needsLayoutDir() const { return m_needsLayoutDir; }
|
||||
bool needsHealLocation() const { return m_needsHealLocation; }
|
||||
bool isPersistedToFile() const { return m_isPersistedToFile; }
|
||||
bool hasUnsavedDataChanges() const { return m_hasUnsavedDataChanges; }
|
||||
|
||||
void resetEvents();
|
||||
QList<Event *> getEvents(Event::Group group = Event::Group::None) const;
|
||||
Event* getEvent(Event::Group group, int index) const;
|
||||
int getNumEvents(Event::Group group = Event::Group::None) const;
|
||||
QStringList getScriptLabels(Event::Group group = Event::Group::None);
|
||||
QString getScriptsFilePath() const;
|
||||
void openScript(QString label);
|
||||
void removeEvent(Event *);
|
||||
void addEvent(Event *);
|
||||
int getIndexOfEvent(Event *) const;
|
||||
|
||||
void deleteConnections();
|
||||
QList<MapConnection*> getConnections() const;
|
||||
|
|
@ -98,18 +114,60 @@ public:
|
|||
QRect getConnectionRect(const QString &direction, Layout *fromLayout = nullptr);
|
||||
QPixmap renderConnection(const QString &direction, Layout *fromLayout = nullptr);
|
||||
|
||||
QUndoStack editHistory;
|
||||
QUndoStack* editHistory() const { return m_editHistory; }
|
||||
void commit(QUndoCommand*);
|
||||
void modify();
|
||||
void clean();
|
||||
void setClean();
|
||||
bool hasUnsavedChanges() const;
|
||||
void pruneEditHistory();
|
||||
|
||||
void setCustomAttributes(const QMap<QString, QJsonValue> &attributes) { m_customAttributes = attributes; }
|
||||
QMap<QString, QJsonValue> customAttributes() const { return m_customAttributes; }
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_constantName;
|
||||
QString m_layoutId; // TODO: Why do we do half this->layout()->id and half this->layoutId. Should these ever be different?
|
||||
|
||||
QString m_song;
|
||||
QString m_location;
|
||||
bool m_requiresFlash;
|
||||
QString m_weather;
|
||||
QString m_type;
|
||||
bool m_showsLocation;
|
||||
bool m_allowsRunning;
|
||||
bool m_allowsBiking;
|
||||
bool m_allowsEscaping;
|
||||
int m_floorNumber = 0;
|
||||
QString m_battleScene;
|
||||
|
||||
QString m_sharedEventsMap = "";
|
||||
QString m_sharedScriptsMap = "";
|
||||
|
||||
QStringList m_scriptsFileLabels;
|
||||
QMap<QString, QJsonValue> m_customAttributes;
|
||||
|
||||
Layout *m_layout = nullptr;
|
||||
|
||||
bool m_isPersistedToFile = true;
|
||||
bool m_hasUnsavedDataChanges = false;
|
||||
bool m_needsLayoutDir = true;
|
||||
bool m_needsHealLocation = false;
|
||||
bool m_scriptsLoaded = false;
|
||||
|
||||
QMap<Event::Group, QList<Event *>> m_events;
|
||||
QList<Event *> m_ownedEvents; // for memory management
|
||||
|
||||
QList<int> m_metatileLayerOrder;
|
||||
QList<float> m_metatileLayerOpacity;
|
||||
|
||||
void trackConnection(MapConnection*);
|
||||
|
||||
// MapConnections in 'ownedConnections' but not 'connections' persist in the edit history.
|
||||
QList<MapConnection*> connections;
|
||||
QSet<MapConnection*> ownedConnections;
|
||||
QList<MapConnection*> m_connections;
|
||||
QSet<MapConnection*> m_ownedConnections;
|
||||
|
||||
QUndoStack *m_editHistory = nullptr;
|
||||
|
||||
signals:
|
||||
void modified();
|
||||
|
|
|
|||
|
|
@ -84,10 +84,10 @@ public:
|
|||
Layout *copy();
|
||||
void copyFrom(Layout *other);
|
||||
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
int getBorderWidth();
|
||||
int getBorderHeight();
|
||||
int getWidth() const { return width; }
|
||||
int getHeight() const { return height; }
|
||||
int getBorderWidth() const { return border_width; }
|
||||
int getBorderHeight() const { return border_height; }
|
||||
|
||||
bool isWithinBounds(int x, int y);
|
||||
bool isWithinBorderBounds(int x, int y);
|
||||
|
|
|
|||
|
|
@ -247,8 +247,6 @@ private:
|
|||
|
||||
void setNewLayoutBlockdata(Layout *layout);
|
||||
void setNewLayoutBorder(Layout *layout);
|
||||
void setNewMapEvents(Map *map);
|
||||
void setNewMapConnections(Map *map);
|
||||
|
||||
void saveHealLocationsData(Map *map);
|
||||
void saveHealLocationsConstants();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ void Event::setPixmapItem(DraggablePixmapItem *item) {
|
|||
}
|
||||
|
||||
int Event::getEventIndex() {
|
||||
return this->map->events.value(this->getEventGroup()).indexOf(this);
|
||||
return this->map->getIndexOfEvent(this);
|
||||
}
|
||||
|
||||
void Event::setDefaultValues(Project *) {
|
||||
|
|
@ -424,7 +424,7 @@ bool CloneObjectEvent::loadFromJson(QJsonObject json, Project *project) {
|
|||
void CloneObjectEvent::setDefaultValues(Project *project) {
|
||||
this->setGfx(project->gfxDefines.keys().value(0, "0"));
|
||||
this->setTargetID(1);
|
||||
if (this->getMap()) this->setTargetMap(this->getMap()->name);
|
||||
if (this->getMap()) this->setTargetMap(this->getMap()->name());
|
||||
}
|
||||
|
||||
const QSet<QString> expectedCloneObjectFields = {
|
||||
|
|
@ -445,7 +445,7 @@ void CloneObjectEvent::loadPixmap(Project *project) {
|
|||
// Try to get the targeted object to clone
|
||||
int eventIndex = this->targetID - 1;
|
||||
Map *clonedMap = project->getMap(this->targetMap);
|
||||
Event *clonedEvent = clonedMap ? clonedMap->events[Event::Group::Object].value(eventIndex, nullptr) : nullptr;
|
||||
Event *clonedEvent = clonedMap ? clonedMap->getEvent(Event::Group::Object, eventIndex) : nullptr;
|
||||
|
||||
if (clonedEvent && clonedEvent->getEventType() == Event::Type::Object) {
|
||||
// Get graphics data from cloned object
|
||||
|
|
@ -534,7 +534,7 @@ bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
|
|||
}
|
||||
|
||||
void WarpEvent::setDefaultValues(Project *) {
|
||||
if (this->getMap()) this->setDestinationMap(this->getMap()->name);
|
||||
if (this->getMap()) this->setDestinationMap(this->getMap()->name());
|
||||
this->setDestinationWarpID("0");
|
||||
this->setElevation(0);
|
||||
}
|
||||
|
|
@ -952,13 +952,13 @@ void HealLocationEvent::setDefaultValues(Project *) {
|
|||
if (!this->getMap())
|
||||
return;
|
||||
bool respawnEnabled = projectConfig.healLocationRespawnDataEnabled;
|
||||
const QString mapConstant = Map::mapConstantFromName(this->getMap()->name, false);
|
||||
const QString mapConstant = Map::mapConstantFromName(this->getMap()->name(), false);
|
||||
const QString prefix = projectConfig.getIdentifier(respawnEnabled ? ProjectIdentifier::define_spawn_prefix
|
||||
: ProjectIdentifier::define_heal_locations_prefix);
|
||||
this->setLocationName(mapConstant);
|
||||
this->setIdName(prefix + mapConstant);
|
||||
if (respawnEnabled) {
|
||||
this->setRespawnMap(this->getMap()->name);
|
||||
this->setRespawnMap(this->getMap()->name());
|
||||
this->setRespawnNPC(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
191
src/core/map.cpp
191
src/core/map.cpp
|
|
@ -13,25 +13,27 @@
|
|||
|
||||
Map::Map(QObject *parent) : QObject(parent)
|
||||
{
|
||||
editHistory.setClean();
|
||||
m_editHistory = new QUndoStack(this);
|
||||
resetEvents();
|
||||
}
|
||||
|
||||
Map::~Map() {
|
||||
qDeleteAll(ownedEvents);
|
||||
ownedEvents.clear();
|
||||
qDeleteAll(m_ownedEvents);
|
||||
m_ownedEvents.clear();
|
||||
deleteConnections();
|
||||
}
|
||||
|
||||
void Map::setName(QString mapName) {
|
||||
name = mapName;
|
||||
constantName = mapConstantFromName(mapName);
|
||||
scriptsLoaded = false;
|
||||
m_name = mapName;
|
||||
m_constantName = mapConstantFromName(mapName);
|
||||
m_scriptsLoaded = false;
|
||||
}
|
||||
|
||||
// Note: Map does not take ownership of layout
|
||||
void Map::setLayout(Layout *layout) {
|
||||
this->layout = layout;
|
||||
m_layout = layout;
|
||||
if (layout) {
|
||||
this->layoutId = layout->id;
|
||||
m_layoutId = layout->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,20 +53,20 @@ QString Map::mapConstantFromName(QString mapName, bool includePrefix) {
|
|||
return constantName;
|
||||
}
|
||||
|
||||
int Map::getWidth() {
|
||||
return layout->getWidth();
|
||||
int Map::getWidth() const {
|
||||
return m_layout->getWidth();
|
||||
}
|
||||
|
||||
int Map::getHeight() {
|
||||
return layout->getHeight();
|
||||
int Map::getHeight() const {
|
||||
return m_layout->getHeight();
|
||||
}
|
||||
|
||||
int Map::getBorderWidth() {
|
||||
return layout->getBorderWidth();
|
||||
int Map::getBorderWidth() const {
|
||||
return m_layout->getBorderWidth();
|
||||
}
|
||||
|
||||
int Map::getBorderHeight() {
|
||||
return layout->getBorderHeight();
|
||||
int Map::getBorderHeight() const {
|
||||
return m_layout->getBorderHeight();
|
||||
}
|
||||
|
||||
// Get the portion of the map that can be rendered when rendered as a map connection.
|
||||
|
|
@ -106,7 +108,7 @@ QPixmap Map::renderConnection(const QString &direction, Layout * fromLayout) {
|
|||
if (MapConnection::isDiving(direction))
|
||||
fromLayout = nullptr;
|
||||
|
||||
QPixmap connectionPixmap = this->layout->render(true, fromLayout, bounds);
|
||||
QPixmap connectionPixmap = m_layout->render(true, fromLayout, bounds);
|
||||
return connectionPixmap.copy(bounds.x() * 16, bounds.y() * 16, bounds.width() * 16, bounds.height() * 16);
|
||||
}
|
||||
|
||||
|
|
@ -114,18 +116,10 @@ void Map::openScript(QString label) {
|
|||
emit openScriptRequested(label);
|
||||
}
|
||||
|
||||
QList<Event *> Map::getAllEvents() const {
|
||||
QList<Event *> all_events;
|
||||
for (const auto &event_list : events) {
|
||||
all_events << event_list;
|
||||
}
|
||||
return all_events;
|
||||
}
|
||||
|
||||
QStringList Map::getScriptLabels(Event::Group group) {
|
||||
if (!this->scriptsLoaded) {
|
||||
this->scriptsFileLabels = ParseUtil::getGlobalScriptLabels(this->getScriptsFilePath());
|
||||
this->scriptsLoaded = true;
|
||||
if (!m_scriptsLoaded) {
|
||||
m_scriptsFileLabels = ParseUtil::getGlobalScriptLabels(getScriptsFilePath());
|
||||
m_scriptsLoaded = true;
|
||||
}
|
||||
|
||||
QStringList scriptLabels;
|
||||
|
|
@ -133,20 +127,20 @@ QStringList Map::getScriptLabels(Event::Group group) {
|
|||
// Get script labels currently in-use by the map's events
|
||||
if (group == Event::Group::None) {
|
||||
ScriptTracker scriptTracker;
|
||||
for (Event *event : this->getAllEvents()) {
|
||||
for (const auto &event : getEvents()) {
|
||||
event->accept(&scriptTracker);
|
||||
}
|
||||
scriptLabels = scriptTracker.getScripts();
|
||||
} else {
|
||||
ScriptTracker scriptTracker;
|
||||
for (Event *event : events.value(group)) {
|
||||
for (const auto &event : m_events.value(group)) {
|
||||
event->accept(&scriptTracker);
|
||||
}
|
||||
scriptLabels = scriptTracker.getScripts();
|
||||
}
|
||||
|
||||
// Add scripts from map's scripts file, and empty names.
|
||||
scriptLabels.append(this->scriptsFileLabels);
|
||||
scriptLabels.append(m_scriptsFileLabels);
|
||||
scriptLabels.sort(Qt::CaseInsensitive);
|
||||
scriptLabels.prepend("0x0");
|
||||
scriptLabels.prepend("NULL");
|
||||
|
|
@ -162,7 +156,7 @@ QString Map::getScriptsFilePath() const {
|
|||
auto path = QDir::cleanPath(QString("%1/%2/%3/scripts")
|
||||
.arg(projectConfig.projectDir)
|
||||
.arg(projectConfig.getFilePath(ProjectFilePath::data_map_folders))
|
||||
.arg(this->name));
|
||||
.arg(m_name));
|
||||
auto extension = Project::getScriptFileExtension(usePoryscript);
|
||||
if (usePoryscript && !QFile::exists(path + extension))
|
||||
extension = Project::getScriptFileExtension(false);
|
||||
|
|
@ -170,37 +164,77 @@ QString Map::getScriptsFilePath() const {
|
|||
return path;
|
||||
}
|
||||
|
||||
void Map::resetEvents() {
|
||||
m_events[Event::Group::Object].clear();
|
||||
m_events[Event::Group::Warp].clear();
|
||||
m_events[Event::Group::Coord].clear();
|
||||
m_events[Event::Group::Bg].clear();
|
||||
m_events[Event::Group::Heal].clear();
|
||||
}
|
||||
|
||||
QList<Event *> Map::getEvents(Event::Group group) const {
|
||||
if (group == Event::Group::None) {
|
||||
// Get all events
|
||||
QList<Event *> all_events;
|
||||
for (const auto &event_list : m_events) {
|
||||
all_events << event_list;
|
||||
}
|
||||
return all_events;
|
||||
}
|
||||
return m_events[group];
|
||||
}
|
||||
|
||||
Event* Map::getEvent(Event::Group group, int index) const {
|
||||
return m_events[group].value(index, nullptr);
|
||||
}
|
||||
|
||||
int Map::getNumEvents(Event::Group group) const {
|
||||
if (group == Event::Group::None) {
|
||||
// Total number of events
|
||||
int numEvents = 0;
|
||||
for (auto i = m_events.constBegin(); i != m_events.constEnd(); i++) {
|
||||
numEvents += i.value().length();
|
||||
}
|
||||
return numEvents;
|
||||
}
|
||||
return m_events[group].length();
|
||||
}
|
||||
|
||||
void Map::removeEvent(Event *event) {
|
||||
for (Event::Group key : events.keys()) {
|
||||
events[key].removeAll(event);
|
||||
for (auto i = m_events.begin(); i != m_events.end(); i++) {
|
||||
i.value().removeAll(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::addEvent(Event *event) {
|
||||
event->setMap(this);
|
||||
events[event->getEventGroup()].append(event);
|
||||
if (!ownedEvents.contains(event)) ownedEvents.append(event);
|
||||
m_events[event->getEventGroup()].append(event);
|
||||
if (!m_ownedEvents.contains(event)) m_ownedEvents.append(event);
|
||||
}
|
||||
|
||||
int Map::getIndexOfEvent(Event *event) const {
|
||||
return m_events.value(event->getEventGroup()).indexOf(event);
|
||||
}
|
||||
|
||||
void Map::deleteConnections() {
|
||||
qDeleteAll(this->ownedConnections);
|
||||
this->ownedConnections.clear();
|
||||
this->connections.clear();
|
||||
qDeleteAll(m_ownedConnections);
|
||||
m_ownedConnections.clear();
|
||||
m_connections.clear();
|
||||
}
|
||||
|
||||
QList<MapConnection*> Map::getConnections() const {
|
||||
return this->connections;
|
||||
return m_connections;
|
||||
}
|
||||
|
||||
void Map::addConnection(MapConnection *connection) {
|
||||
if (!connection || this->connections.contains(connection))
|
||||
if (!connection || m_connections.contains(connection))
|
||||
return;
|
||||
|
||||
// Maps should only have one Dive/Emerge connection at a time.
|
||||
// (Users can technically have more by editing their data manually, but we will only display one at a time)
|
||||
// Any additional connections being added (this can happen via mirroring) are tracked for deleting but otherwise ignored.
|
||||
if (MapConnection::isDiving(connection->direction())) {
|
||||
for (auto i : this->connections) {
|
||||
for (const auto &i : m_connections) {
|
||||
if (i->direction() == connection->direction()) {
|
||||
trackConnection(connection);
|
||||
return;
|
||||
|
|
@ -218,8 +252,8 @@ void Map::loadConnection(MapConnection *connection) {
|
|||
if (!connection)
|
||||
return;
|
||||
|
||||
if (!this->connections.contains(connection))
|
||||
this->connections.append(connection);
|
||||
if (!m_connections.contains(connection))
|
||||
m_connections.append(connection);
|
||||
|
||||
trackConnection(connection);
|
||||
}
|
||||
|
|
@ -227,12 +261,12 @@ void Map::loadConnection(MapConnection *connection) {
|
|||
void Map::trackConnection(MapConnection *connection) {
|
||||
connection->setParentMap(this, false);
|
||||
|
||||
if (!this->ownedConnections.contains(connection)) {
|
||||
this->ownedConnections.insert(connection);
|
||||
if (!m_ownedConnections.contains(connection)) {
|
||||
m_ownedConnections.insert(connection);
|
||||
connect(connection, &MapConnection::parentMapChanged, [=](Map *, Map *after) {
|
||||
if (after != this && after != nullptr) {
|
||||
// MapConnection's parent has been reassigned, it's no longer our responsibility
|
||||
this->ownedConnections.remove(connection);
|
||||
m_ownedConnections.remove(connection);
|
||||
QObject::disconnect(connection, &MapConnection::parentMapChanged, this, nullptr);
|
||||
}
|
||||
});
|
||||
|
|
@ -241,23 +275,29 @@ void Map::trackConnection(MapConnection *connection) {
|
|||
|
||||
// We retain ownership of this MapConnection until it's assigned to a new parent map.
|
||||
void Map::removeConnection(MapConnection *connection) {
|
||||
if (!this->connections.removeOne(connection))
|
||||
if (!m_connections.removeOne(connection))
|
||||
return;
|
||||
connection->setParentMap(nullptr, false);
|
||||
modify();
|
||||
emit connectionRemoved(connection);
|
||||
}
|
||||
|
||||
void Map::commit(QUndoCommand *cmd) {
|
||||
m_editHistory->push(cmd);
|
||||
}
|
||||
|
||||
void Map::modify() {
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void Map::clean() {
|
||||
this->hasUnsavedDataChanges = false;
|
||||
void Map::setClean() {
|
||||
m_editHistory->setClean();
|
||||
m_hasUnsavedDataChanges = false;
|
||||
m_isPersistedToFile = true;
|
||||
}
|
||||
|
||||
bool Map::hasUnsavedChanges() const {
|
||||
return !editHistory.isClean() || this->layout->hasUnsavedChanges() || hasUnsavedDataChanges || !isPersistedToFile;
|
||||
return !m_editHistory->isClean() || m_layout->hasUnsavedChanges() || m_hasUnsavedDataChanges || !m_isPersistedToFile;
|
||||
}
|
||||
|
||||
void Map::pruneEditHistory() {
|
||||
|
|
@ -271,12 +311,57 @@ void Map::pruneEditHistory() {
|
|||
ID_MapConnectionAdd,
|
||||
ID_MapConnectionRemove
|
||||
};
|
||||
for (int i = 0; i < this->editHistory.count(); i++) {
|
||||
for (int i = 0; i < m_editHistory->count(); i++) {
|
||||
// Qt really doesn't expect editing commands in the stack to be valid (fair).
|
||||
// A better future design might be to have separate edit histories per map tab,
|
||||
// and dumping the entire Connections tab history with QUndoStack::clear.
|
||||
auto command = const_cast<QUndoCommand*>(this->editHistory.command(i));
|
||||
auto command = const_cast<QUndoCommand*>(m_editHistory->command(i));
|
||||
if (mapConnectionIds.contains(command->id()))
|
||||
command->setObsolete(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setSong(const QString &song) {
|
||||
m_song = song;
|
||||
}
|
||||
|
||||
void Map::setLocation(const QString &location) {
|
||||
m_location = location;
|
||||
}
|
||||
|
||||
void Map::setRequiresFlash(bool requiresFlash) {
|
||||
m_requiresFlash = requiresFlash;
|
||||
}
|
||||
|
||||
void Map::setWeather(const QString &weather) {
|
||||
m_weather = weather;
|
||||
}
|
||||
|
||||
void Map::setType(const QString &type) {
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
void Map::setShowsLocation(bool showsLocation) {
|
||||
m_showsLocation = showsLocation;
|
||||
}
|
||||
|
||||
void Map::setAllowsRunning(bool allowsRunning) {
|
||||
m_allowsRunning = allowsRunning;
|
||||
}
|
||||
|
||||
void Map::setAllowsBiking(bool allowsBiking) {
|
||||
m_allowsBiking = allowsBiking;
|
||||
}
|
||||
|
||||
void Map::setAllowsEscaping(bool allowsEscaping) {
|
||||
m_allowsEscaping = allowsEscaping;
|
||||
}
|
||||
|
||||
void Map::setFloorNumber(int floorNumber) {
|
||||
m_floorNumber = floorNumber;
|
||||
}
|
||||
|
||||
void Map::setBattleScene(const QString &battleScene) {
|
||||
m_battleScene = battleScene;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ QPixmap MapConnection::getPixmap() {
|
|||
if (!map)
|
||||
return QPixmap();
|
||||
|
||||
return map->renderConnection(m_direction, m_parentMap ? m_parentMap->layout : nullptr);
|
||||
return map->renderConnection(m_direction, m_parentMap ? m_parentMap->layout() : nullptr);
|
||||
}
|
||||
|
||||
void MapConnection::setParentMap(Map* map, bool mirror) {
|
||||
|
|
@ -75,7 +75,7 @@ void MapConnection::setParentMap(Map* map, bool mirror) {
|
|||
if (mirror) {
|
||||
auto connection = findMirror();
|
||||
if (connection)
|
||||
connection->setTargetMapName(map ? map->name : QString(), false);
|
||||
connection->setTargetMapName(map ? map->name() : QString(), false);
|
||||
}
|
||||
|
||||
if (m_parentMap)
|
||||
|
|
@ -91,7 +91,7 @@ void MapConnection::setParentMap(Map* map, bool mirror) {
|
|||
}
|
||||
|
||||
QString MapConnection::parentMapName() const {
|
||||
return m_parentMap ? m_parentMap->name : QString();
|
||||
return m_parentMap ? m_parentMap->name() : QString();
|
||||
}
|
||||
|
||||
void MapConnection::setTargetMapName(const QString &targetMapName, bool mirror) {
|
||||
|
|
|
|||
|
|
@ -45,22 +45,6 @@ QString Layout::layoutConstantFromName(QString mapName) {
|
|||
return constantName;
|
||||
}
|
||||
|
||||
int Layout::getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
int Layout::getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
int Layout::getBorderWidth() {
|
||||
return border_width;
|
||||
}
|
||||
|
||||
int Layout::getBorderHeight() {
|
||||
return border_height;
|
||||
}
|
||||
|
||||
bool Layout::isWithinBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getWidth() && y >= 0 && y < this->getHeight());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ void Editor::setEditorView() {
|
|||
map_item->setEditsEnabled(false);
|
||||
case EditMode::Events:
|
||||
if (this->map) {
|
||||
this->editGroup.setActiveStack(&this->map->editHistory);
|
||||
this->editGroup.setActiveStack(this->map->editHistory());
|
||||
}
|
||||
break;
|
||||
case EditMode::Header:
|
||||
|
|
@ -240,23 +240,23 @@ void Editor::displayWildMonTables() {
|
|||
clearWildMonTables();
|
||||
|
||||
// Don't try to read encounter data if it doesn't exist on disk for this map.
|
||||
if (!project->wildMonData.contains(map->constantName)) {
|
||||
if (!project->wildMonData.contains(map->constantName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
|
||||
for (auto groupPair : project->wildMonData[map->constantName])
|
||||
for (auto groupPair : project->wildMonData[map->constantName()])
|
||||
labelCombo->addItem(groupPair.first);
|
||||
|
||||
labelCombo->setCurrentText(labelCombo->itemText(0));
|
||||
|
||||
QStackedWidget *stack = ui->stackedWidget_WildMons;
|
||||
int labelIndex = 0;
|
||||
for (auto labelPair : project->wildMonData[map->constantName]) {
|
||||
for (auto labelPair : project->wildMonData[map->constantName()]) {
|
||||
|
||||
QString label = labelPair.first;
|
||||
|
||||
WildPokemonHeader header = project->wildMonData[map->constantName][label];
|
||||
WildPokemonHeader header = project->wildMonData[map->constantName()][label];
|
||||
|
||||
MonTabWidget *tabWidget = new MonTabWidget(this);
|
||||
stack->insertWidget(labelIndex++, tabWidget);
|
||||
|
|
@ -267,7 +267,7 @@ void Editor::displayWildMonTables() {
|
|||
|
||||
tabWidget->clearTableAt(tabIndex);
|
||||
|
||||
if (project->wildMonData.contains(map->constantName) && header.wildMons[fieldName].active) {
|
||||
if (project->wildMonData.contains(map->constantName()) && header.wildMons[fieldName].active) {
|
||||
tabWidget->populateTab(tabIndex, header.wildMons[fieldName]);
|
||||
} else {
|
||||
tabWidget->setTabActive(tabIndex, false);
|
||||
|
|
@ -312,7 +312,7 @@ void Editor::addNewWildMonGroup(QWidget *window) {
|
|||
}
|
||||
});
|
||||
// Give a default value to the label.
|
||||
lineEdit->setText(QString("g%1%2").arg(map->name).arg(stack->count()));
|
||||
lineEdit->setText(QString("g%1%2").arg(map->name()).arg(stack->count()));
|
||||
|
||||
// Fields [x] copy from existing
|
||||
QLabel *fieldsLabel = new QLabel("Fields:");
|
||||
|
|
@ -415,9 +415,9 @@ void Editor::deleteWildMonGroup() {
|
|||
msgBox.exec();
|
||||
|
||||
if (msgBox.clickedButton() == deleteButton) {
|
||||
auto it = project->wildMonData.find(map->constantName);
|
||||
auto it = project->wildMonData.find(map->constantName());
|
||||
if (it == project->wildMonData.end()) {
|
||||
logError(QString("Failed to find data for map %1. Unable to delete").arg(map->constantName));
|
||||
logError(QString("Failed to find data for map %1. Unable to delete").arg(map->constantName()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -698,7 +698,7 @@ void Editor::saveEncounterTabData() {
|
|||
|
||||
if (!stack->count()) return;
|
||||
|
||||
tsl::ordered_map<QString, WildPokemonHeader> &encounterMap = project->wildMonData[map->constantName];
|
||||
tsl::ordered_map<QString, WildPokemonHeader> &encounterMap = project->wildMonData[map->constantName()];
|
||||
|
||||
for (int groupIndex = 0; groupIndex < stack->count(); groupIndex++) {
|
||||
MonTabWidget *tabWidget = static_cast<MonTabWidget *>(stack->widget(groupIndex));
|
||||
|
|
@ -863,13 +863,13 @@ void Editor::addConnection(MapConnection *connection) {
|
|||
// It's possible this is a Dive/Emerge connection, but that's ok (no selection will occur).
|
||||
connection_to_select = connection;
|
||||
|
||||
this->map->editHistory.push(new MapConnectionAdd(this->map, connection));
|
||||
this->map->commit(new MapConnectionAdd(this->map, connection));
|
||||
}
|
||||
|
||||
void Editor::removeConnection(MapConnection *connection) {
|
||||
if (!connection)
|
||||
return;
|
||||
this->map->editHistory.push(new MapConnectionRemove(this->map, connection));
|
||||
this->map->commit(new MapConnectionRemove(this->map, connection));
|
||||
}
|
||||
|
||||
void Editor::removeConnectionPixmap(MapConnection *connection) {
|
||||
|
|
@ -986,7 +986,7 @@ void Editor::setDivingMapName(QString mapName, QString direction) {
|
|||
if (mapName.isEmpty()) {
|
||||
removeConnection(connection);
|
||||
} else {
|
||||
map->editHistory.push(new MapConnectionChangeMap(connection, mapName));
|
||||
map->commit(new MapConnectionChangeMap(connection, mapName));
|
||||
}
|
||||
} else if (!mapName.isEmpty()) {
|
||||
// Create new connection
|
||||
|
|
@ -1268,10 +1268,10 @@ bool Editor::setMap(QString map_name) {
|
|||
|
||||
this->map = loadedMap;
|
||||
|
||||
setLayout(map->layout->id);
|
||||
setLayout(map->layout()->id);
|
||||
|
||||
editGroup.addStack(&map->editHistory);
|
||||
editGroup.setActiveStack(&map->editHistory);
|
||||
editGroup.addStack(map->editHistory());
|
||||
editGroup.setActiveStack(map->editHistory());
|
||||
|
||||
selected_events->clear();
|
||||
if (!displayMap()) {
|
||||
|
|
@ -1469,7 +1469,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
|
|||
}
|
||||
selection_origin = QPoint(pos.x(), pos.y());
|
||||
|
||||
map->editHistory.push(new EventShift(selectedEvents, xDelta, yDelta, actionId));
|
||||
map->commit(new EventShift(selectedEvents, xDelta, yDelta, actionId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1784,8 +1784,7 @@ void Editor::displayMapEvents() {
|
|||
events_group = new QGraphicsItemGroup;
|
||||
scene->addItem(events_group);
|
||||
|
||||
QList<Event *> events = map->getAllEvents();
|
||||
for (Event *event : events) {
|
||||
for (const auto &event : map->getEvents()) {
|
||||
project->setEventPixmap(event);
|
||||
addMapEvent(event);
|
||||
}
|
||||
|
|
@ -2032,14 +2031,14 @@ void Editor::updateBorderVisibility() {
|
|||
// When connecting a map to itself we don't bother to re-render the map connections in real-time,
|
||||
// i.e. if the user paints a new metatile on the map this isn't immediately reflected in the connection.
|
||||
// We're rendering them now, so we take the opportunity to do a full re-render for self-connections.
|
||||
bool fullRender = (this->map && item->connection && this->map->name == item->connection->targetMapName());
|
||||
bool fullRender = (this->map && item->connection && this->map->name() == item->connection->targetMapName());
|
||||
item->render(fullRender);
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::updateCustomMapHeaderValues(QTableWidget *table)
|
||||
{
|
||||
map->customHeaders = CustomAttributesTable::getAttributes(table);
|
||||
map->setCustomAttributes(CustomAttributesTable::getAttributes(table));
|
||||
map->modify();
|
||||
}
|
||||
|
||||
|
|
@ -2080,13 +2079,13 @@ void Editor::redrawObject(DraggablePixmapItem *item) {
|
|||
void Editor::updateWarpEventWarning(Event *event) {
|
||||
if (porymapConfig.warpBehaviorWarningDisabled)
|
||||
return;
|
||||
if (!project || !map || !map->layout || !event || event->getEventType() != Event::Type::Warp)
|
||||
if (!project || !map || !map->layout() || !event || event->getEventType() != Event::Type::Warp)
|
||||
return;
|
||||
Block block;
|
||||
Metatile * metatile = nullptr;
|
||||
WarpEvent * warpEvent = static_cast<WarpEvent*>(event);
|
||||
if (map->layout->getBlock(warpEvent->getX(), warpEvent->getY(), &block)) {
|
||||
metatile = Tileset::getMetatile(block.metatileId(), map->layout->tileset_primary, map->layout->tileset_secondary);
|
||||
if (map->layout()->getBlock(warpEvent->getX(), warpEvent->getY(), &block)) {
|
||||
metatile = Tileset::getMetatile(block.metatileId(), map->layout()->tileset_primary, map->layout()->tileset_secondary);
|
||||
}
|
||||
// metatile may be null if the warp is in the map border. Display the warning in this case
|
||||
bool validWarpBehavior = metatile && projectConfig.warpBehaviors.contains(metatile->behavior());
|
||||
|
|
@ -2144,10 +2143,7 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
|
|||
void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup) {
|
||||
int event_offs = Event::getIndexOffset(eventGroup);
|
||||
index = index - event_offs;
|
||||
Event *event = nullptr;
|
||||
if (index < this->map->events.value(eventGroup).length()) {
|
||||
event = this->map->events.value(eventGroup).at(index);
|
||||
}
|
||||
Event *event = this->map->getEvent(eventGroup, index);
|
||||
DraggablePixmapItem *selectedEvent = nullptr;
|
||||
for (QGraphicsItem *child : this->events_group->childItems()) {
|
||||
DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
|
||||
|
|
@ -2189,7 +2185,7 @@ void Editor::duplicateSelectedEvents() {
|
|||
duplicate->setY(duplicate->getY() + 1);
|
||||
selectedEvents.append(duplicate);
|
||||
}
|
||||
map->editHistory.push(new EventDuplicate(this, map, selectedEvents));
|
||||
map->commit(new EventDuplicate(this, map, selectedEvents));
|
||||
}
|
||||
|
||||
DraggablePixmapItem *Editor::addNewEvent(Event::Type type) {
|
||||
|
|
@ -2209,7 +2205,7 @@ DraggablePixmapItem *Editor::addNewEvent(Event::Type type) {
|
|||
((HealLocationEvent *)event)->setIndex(project->healLocations.length());
|
||||
}
|
||||
|
||||
map->editHistory.push(new EventCreate(this, map, event));
|
||||
map->commit(new EventCreate(this, map, event));
|
||||
return event->getPixmapItem();
|
||||
}
|
||||
|
||||
|
|
@ -2217,7 +2213,7 @@ DraggablePixmapItem *Editor::addNewEvent(Event::Type type) {
|
|||
bool Editor::eventLimitReached(Event::Type event_type) {
|
||||
if (project && map) {
|
||||
if (Event::typeToGroup(event_type) == Event::Group::Object)
|
||||
return map->events.value(Event::Group::Object).length() >= project->getMaxObjectEvents();
|
||||
return map->getNumEvents(Event::Group::Object) >= project->getMaxObjectEvents();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -2246,14 +2242,12 @@ void Editor::deleteSelectedEvents() {
|
|||
// If deleting multiple events, just let editor work out next selected.
|
||||
if (numDeleted == 1) {
|
||||
Event::Group event_group = selectedEvents[0]->getEventGroup();
|
||||
int index = this->map->events.value(event_group).indexOf(selectedEvents[0]);
|
||||
if (index != this->map->events.value(event_group).size() - 1)
|
||||
int index = this->map->getIndexOfEvent(selectedEvents[0]);
|
||||
if (index != this->map->getNumEvents(event_group) - 1)
|
||||
index++;
|
||||
else
|
||||
index--;
|
||||
Event *event = nullptr;
|
||||
if (index >= 0)
|
||||
event = this->map->events.value(event_group).at(index);
|
||||
Event *event = this->map->getEvent(event_group, index);
|
||||
for (QGraphicsItem *child : this->events_group->childItems()) {
|
||||
DraggablePixmapItem *event_item = static_cast<DraggablePixmapItem *>(child);
|
||||
if (event_item->event == event) {
|
||||
|
|
@ -2262,7 +2256,7 @@ void Editor::deleteSelectedEvents() {
|
|||
}
|
||||
}
|
||||
}
|
||||
this->map->editHistory.push(new EventDelete(this, this->map, selectedEvents, nextSelectedEvent ? nextSelectedEvent->event : nullptr));
|
||||
this->map->commit(new EventDelete(this, this->map, selectedEvents, nextSelectedEvent ? nextSelectedEvent->event : nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ void MainWindow::updateWindowTitle() {
|
|||
if (editor->map) {
|
||||
setWindowTitle(QString("%1%2 - %3")
|
||||
.arg(editor->map->hasUnsavedChanges() ? "* " : "")
|
||||
.arg(editor->map->name)
|
||||
.arg(editor->map->name())
|
||||
.arg(projectName)
|
||||
);
|
||||
} else {
|
||||
|
|
@ -471,7 +471,7 @@ void MainWindow::markMapEdited() {
|
|||
void MainWindow::markSpecificMapEdited(Map* map) {
|
||||
if (!map)
|
||||
return;
|
||||
map->hasUnsavedDataChanges = true;
|
||||
map->setHasUnsavedDataChanges(true);
|
||||
|
||||
if (editor && editor->map == map)
|
||||
updateWindowTitle();
|
||||
|
|
@ -827,7 +827,7 @@ void MainWindow::unsetMap() {
|
|||
// setMap, but with a visible error message in case of failure.
|
||||
// Use when the user is specifically requesting a map to open.
|
||||
bool MainWindow::userSetMap(QString map_name) {
|
||||
if (editor->map && editor->map->name == map_name)
|
||||
if (editor->map && editor->map->name() == map_name)
|
||||
return true; // Already set
|
||||
|
||||
if (map_name == DYNAMIC_MAP_NAME) {
|
||||
|
|
@ -988,20 +988,19 @@ void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_
|
|||
|
||||
// Select the target event.
|
||||
int index = event_id - Event::getIndexOffset(event_group);
|
||||
QList<Event*> events = editor->map->events[event_group];
|
||||
if (index < events.length() && index >= 0) {
|
||||
Event *event = events.at(index);
|
||||
Event* event = editor->map->getEvent(event_group, index);
|
||||
if (event) {
|
||||
for (DraggablePixmapItem *item : editor->getObjects()) {
|
||||
if (item->event == event) {
|
||||
editor->selected_events->clear();
|
||||
editor->selected_events->append(item);
|
||||
editor->updateSelectedEvents();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Can still warp to this map, but can't select the specified event
|
||||
logWarn(QString("%1 %2 doesn't exist on map '%3'").arg(Event::eventGroupToString(event_group)).arg(event_id).arg(map_name));
|
||||
}
|
||||
// Can still warp to this map, but can't select the specified event
|
||||
logWarn(QString("%1 %2 doesn't exist on map '%3'").arg(Event::eventGroupToString(event_group)).arg(event_id).arg(map_name));
|
||||
}
|
||||
|
||||
void MainWindow::displayMapProperties() {
|
||||
|
|
@ -1033,35 +1032,37 @@ void MainWindow::displayMapProperties() {
|
|||
ui->frame_3->setEnabled(true);
|
||||
Map *map = editor->map;
|
||||
|
||||
ui->comboBox_PrimaryTileset->setCurrentText(map->layout->tileset_primary_label);
|
||||
ui->comboBox_SecondaryTileset->setCurrentText(map->layout->tileset_secondary_label);
|
||||
ui->comboBox_PrimaryTileset->setCurrentText(map->layout()->tileset_primary_label);
|
||||
ui->comboBox_SecondaryTileset->setCurrentText(map->layout()->tileset_secondary_label);
|
||||
|
||||
ui->comboBox_Song->setCurrentText(map->song);
|
||||
ui->comboBox_Location->setCurrentText(map->location);
|
||||
ui->checkBox_Visibility->setChecked(map->requiresFlash);
|
||||
ui->comboBox_Weather->setCurrentText(map->weather);
|
||||
ui->comboBox_Type->setCurrentText(map->type);
|
||||
ui->comboBox_BattleScene->setCurrentText(map->battle_scene);
|
||||
ui->checkBox_ShowLocation->setChecked(map->show_location);
|
||||
ui->checkBox_AllowRunning->setChecked(map->allowRunning);
|
||||
ui->checkBox_AllowBiking->setChecked(map->allowBiking);
|
||||
ui->checkBox_AllowEscaping->setChecked(map->allowEscaping);
|
||||
ui->spinBox_FloorNumber->setValue(map->floorNumber);
|
||||
ui->comboBox_Song->setCurrentText(map->song());
|
||||
ui->comboBox_Location->setCurrentText(map->location());
|
||||
ui->checkBox_Visibility->setChecked(map->requiresFlash());
|
||||
ui->comboBox_Weather->setCurrentText(map->weather());
|
||||
ui->comboBox_Type->setCurrentText(map->type());
|
||||
ui->comboBox_BattleScene->setCurrentText(map->battleScene());
|
||||
ui->checkBox_ShowLocation->setChecked(map->showsLocation());
|
||||
ui->checkBox_AllowRunning->setChecked(map->allowsRunning());
|
||||
ui->checkBox_AllowBiking->setChecked(map->allowsBiking());
|
||||
ui->checkBox_AllowEscaping->setChecked(map->allowsEscaping());
|
||||
ui->spinBox_FloorNumber->setValue(map->floorNumber());
|
||||
|
||||
// Custom fields table.
|
||||
/* // TODO: Re-enable
|
||||
ui->tableWidget_CustomHeaderFields->blockSignals(true);
|
||||
ui->tableWidget_CustomHeaderFields->setRowCount(0);
|
||||
for (auto it = map->customHeaders.begin(); it != map->customHeaders.end(); it++)
|
||||
CustomAttributesTable::addAttribute(ui->tableWidget_CustomHeaderFields, it.key(), it.value());
|
||||
ui->tableWidget_CustomHeaderFields->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
ui->tableWidget_CustomHeaderFields->blockSignals(false);
|
||||
*/
|
||||
}
|
||||
|
||||
void MainWindow::on_comboBox_LayoutSelector_currentTextChanged(const QString &text) {
|
||||
if (editor && editor->project && editor->map) {
|
||||
if (editor->project->mapLayouts.contains(text)) {
|
||||
editor->map->setLayout(editor->project->loadLayout(text));
|
||||
setMap(editor->map->name);
|
||||
setMap(editor->map->name());
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1070,7 +1071,7 @@ void MainWindow::on_comboBox_LayoutSelector_currentTextChanged(const QString &te
|
|||
void MainWindow::on_comboBox_Song_currentTextChanged(const QString &song)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->song = song;
|
||||
editor->map->setSong(song);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1078,7 +1079,7 @@ void MainWindow::on_comboBox_Song_currentTextChanged(const QString &song)
|
|||
void MainWindow::on_comboBox_Location_currentTextChanged(const QString &location)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->location = location;
|
||||
editor->map->setLocation(location);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1086,7 +1087,7 @@ void MainWindow::on_comboBox_Location_currentTextChanged(const QString &location
|
|||
void MainWindow::on_comboBox_Weather_currentTextChanged(const QString &weather)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->weather = weather;
|
||||
editor->map->setWeather(weather);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1094,7 +1095,7 @@ void MainWindow::on_comboBox_Weather_currentTextChanged(const QString &weather)
|
|||
void MainWindow::on_comboBox_Type_currentTextChanged(const QString &type)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->type = type;
|
||||
editor->map->setType(type);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1102,7 +1103,7 @@ void MainWindow::on_comboBox_Type_currentTextChanged(const QString &type)
|
|||
void MainWindow::on_comboBox_BattleScene_currentTextChanged(const QString &battle_scene)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->battle_scene = battle_scene;
|
||||
editor->map->setBattleScene(battle_scene);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1110,7 +1111,7 @@ void MainWindow::on_comboBox_BattleScene_currentTextChanged(const QString &battl
|
|||
void MainWindow::on_checkBox_Visibility_stateChanged(int selected)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->requiresFlash = (selected == Qt::Checked);
|
||||
editor->map->setRequiresFlash(selected == Qt::Checked);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1118,7 +1119,7 @@ void MainWindow::on_checkBox_Visibility_stateChanged(int selected)
|
|||
void MainWindow::on_checkBox_ShowLocation_stateChanged(int selected)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->show_location = (selected == Qt::Checked);
|
||||
editor->map->setShowsLocation(selected == Qt::Checked);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1126,7 +1127,7 @@ void MainWindow::on_checkBox_ShowLocation_stateChanged(int selected)
|
|||
void MainWindow::on_checkBox_AllowRunning_stateChanged(int selected)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->allowRunning = (selected == Qt::Checked);
|
||||
editor->map->setAllowsRunning(selected == Qt::Checked);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1134,7 +1135,7 @@ void MainWindow::on_checkBox_AllowRunning_stateChanged(int selected)
|
|||
void MainWindow::on_checkBox_AllowBiking_stateChanged(int selected)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->allowBiking = (selected == Qt::Checked);
|
||||
editor->map->setAllowsBiking(selected == Qt::Checked);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1142,7 +1143,7 @@ void MainWindow::on_checkBox_AllowBiking_stateChanged(int selected)
|
|||
void MainWindow::on_checkBox_AllowEscaping_stateChanged(int selected)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->allowEscaping = (selected == Qt::Checked);
|
||||
editor->map->setAllowsEscaping(selected == Qt::Checked);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1150,7 +1151,7 @@ void MainWindow::on_checkBox_AllowEscaping_stateChanged(int selected)
|
|||
void MainWindow::on_spinBox_FloorNumber_valueChanged(int offset)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
editor->map->floorNumber = offset;
|
||||
editor->map->setFloorNumber(offset);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
|
@ -1251,7 +1252,7 @@ void MainWindow::refreshLocationsComboBox() {
|
|||
ui->comboBox_Location->clear();
|
||||
ui->comboBox_Location->addItems(locations);
|
||||
if (this->editor->map)
|
||||
ui->comboBox_Location->setCurrentText(this->editor->map->location);
|
||||
ui->comboBox_Location->setCurrentText(this->editor->map->location());
|
||||
}
|
||||
|
||||
void MainWindow::clearProjectUI() {
|
||||
|
|
@ -1309,7 +1310,7 @@ void MainWindow::scrollMapList(MapTree *list, QString itemName) {
|
|||
|
||||
void MainWindow::scrollMapListToCurrentMap(MapTree *list) {
|
||||
if (this->editor->map) {
|
||||
scrollMapList(list, this->editor->map->name);
|
||||
scrollMapList(list, this->editor->map->name());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1591,7 +1592,7 @@ void MainWindow::mapListAddArea() {
|
|||
}
|
||||
|
||||
void MainWindow::onNewMapCreated() {
|
||||
QString newMapName = this->newMapPrompt->map->name;
|
||||
QString newMapName = this->newMapPrompt->map->name();
|
||||
int newMapGroup = this->newMapPrompt->group;
|
||||
Map *newMap = this->newMapPrompt->map;
|
||||
bool existingLayout = this->newMapPrompt->existingLayout;
|
||||
|
|
@ -1607,8 +1608,8 @@ void MainWindow::onNewMapCreated() {
|
|||
|
||||
// Add new Map / Layout to the mapList models
|
||||
this->mapGroupModel->insertMapItem(newMapName, editor->project->groupNames[newMapGroup]);
|
||||
this->mapAreaModel->insertMapItem(newMapName, newMap->location, newMapGroup);
|
||||
this->layoutTreeModel->insertMapItem(newMapName, newMap->layout->id);
|
||||
this->mapAreaModel->insertMapItem(newMapName, newMap->location(), newMapGroup);
|
||||
this->layoutTreeModel->insertMapItem(newMapName, newMap->layout()->id);
|
||||
|
||||
// Refresh any combo box that displays map names and persists between maps
|
||||
// (other combo boxes like for warp destinations are repopulated when the map changes).
|
||||
|
|
@ -1622,16 +1623,16 @@ void MainWindow::onNewMapCreated() {
|
|||
|
||||
// Refresh layout combo box (if a new one was created)
|
||||
if (!existingLayout) {
|
||||
int layoutIndex = this->editor->project->mapLayoutsTable.indexOf(newMap->layout->id);
|
||||
int layoutIndex = this->editor->project->mapLayoutsTable.indexOf(newMap->layout()->id);
|
||||
if (layoutIndex >= 0) {
|
||||
const QSignalBlocker b_Layouts(ui->comboBox_LayoutSelector);
|
||||
ui->comboBox_LayoutSelector->insertItem(layoutIndex, newMap->layout->id);
|
||||
ui->comboBox_LayoutSelector->insertItem(layoutIndex, newMap->layout()->id);
|
||||
}
|
||||
}
|
||||
|
||||
setMap(newMapName);
|
||||
|
||||
if (newMap->needsHealLocation) {
|
||||
if (newMap->needsHealLocation()) {
|
||||
addNewEvent(Event::Type::HealLocation);
|
||||
editor->project->saveHealLocations(newMap);
|
||||
editor->save();
|
||||
|
|
@ -1862,9 +1863,9 @@ void MainWindow::openMapListItem(const QModelIndex &index) {
|
|||
|
||||
void MainWindow::updateMapList() {
|
||||
if (this->editor->map) {
|
||||
this->mapGroupModel->setMap(this->editor->map->name);
|
||||
this->mapGroupModel->setMap(this->editor->map->name());
|
||||
this->groupListProxyModel->layoutChanged();
|
||||
this->mapAreaModel->setMap(this->editor->map->name);
|
||||
this->mapAreaModel->setMap(this->editor->map->name());
|
||||
this->areaListProxyModel->layoutChanged();
|
||||
} else {
|
||||
this->mapGroupModel->setMap(QString());
|
||||
|
|
@ -2107,7 +2108,7 @@ void MainWindow::paste() {
|
|||
}
|
||||
|
||||
if (!newEvents.empty()) {
|
||||
editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents));
|
||||
editor->map->commit(new EventPaste(this->editor, editor->map, newEvents));
|
||||
updateObjects();
|
||||
}
|
||||
|
||||
|
|
@ -2329,7 +2330,7 @@ void MainWindow::addNewEvent(Event::Type type) {
|
|||
|
||||
void MainWindow::tryAddEventTab(QWidget * tab) {
|
||||
auto group = getEventGroupFromTabWidget(tab);
|
||||
if (editor->map->events.value(group).length())
|
||||
if (editor->map->getNumEvents(group))
|
||||
ui->tabWidget_EventType->addTab(tab, QString("%1s").arg(Event::eventGroupToString(group)));
|
||||
}
|
||||
|
||||
|
|
@ -2363,7 +2364,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
else {
|
||||
QList<Event *> all_events;
|
||||
if (editor->map) {
|
||||
all_events = editor->map->getAllEvents();
|
||||
all_events = editor->map->getEvents();
|
||||
}
|
||||
if (all_events.length()) {
|
||||
DraggablePixmapItem *selectedEvent = all_events.first()->getPixmapItem();
|
||||
|
|
@ -2397,7 +2398,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
QSignalBlocker b(this->ui->spinner_ObjectID);
|
||||
this->ui->spinner_ObjectID->setMinimum(event_offs);
|
||||
this->ui->spinner_ObjectID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
|
||||
this->ui->spinner_ObjectID->setMaximum(current->getMap()->getNumEvents(eventGroup) + event_offs - 1);
|
||||
this->ui->spinner_ObjectID->setValue(current->getEventIndex() + event_offs);
|
||||
break;
|
||||
}
|
||||
|
|
@ -2408,7 +2409,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
QSignalBlocker b(this->ui->spinner_WarpID);
|
||||
this->ui->spinner_WarpID->setMinimum(event_offs);
|
||||
this->ui->spinner_WarpID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
|
||||
this->ui->spinner_WarpID->setMaximum(current->getMap()->getNumEvents(eventGroup) + event_offs - 1);
|
||||
this->ui->spinner_WarpID->setValue(current->getEventIndex() + event_offs);
|
||||
break;
|
||||
}
|
||||
|
|
@ -2419,7 +2420,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
QSignalBlocker b(this->ui->spinner_TriggerID);
|
||||
this->ui->spinner_TriggerID->setMinimum(event_offs);
|
||||
this->ui->spinner_TriggerID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
|
||||
this->ui->spinner_TriggerID->setMaximum(current->getMap()->getNumEvents(eventGroup) + event_offs - 1);
|
||||
this->ui->spinner_TriggerID->setValue(current->getEventIndex() + event_offs);
|
||||
break;
|
||||
}
|
||||
|
|
@ -2430,7 +2431,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
QSignalBlocker b(this->ui->spinner_BgID);
|
||||
this->ui->spinner_BgID->setMinimum(event_offs);
|
||||
this->ui->spinner_BgID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
|
||||
this->ui->spinner_BgID->setMaximum(current->getMap()->getNumEvents(eventGroup) + event_offs - 1);
|
||||
this->ui->spinner_BgID->setValue(current->getEventIndex() + event_offs);
|
||||
break;
|
||||
}
|
||||
|
|
@ -2441,7 +2442,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
QSignalBlocker b(this->ui->spinner_HealID);
|
||||
this->ui->spinner_HealID->setMinimum(event_offs);
|
||||
this->ui->spinner_HealID->setMaximum(current->getMap()->events.value(eventGroup).length() + event_offs - 1);
|
||||
this->ui->spinner_HealID->setMaximum(current->getMap()->getNumEvents(eventGroup) + event_offs - 1);
|
||||
this->ui->spinner_HealID->setValue(current->getEventIndex() + event_offs);
|
||||
break;
|
||||
}
|
||||
|
|
@ -2534,8 +2535,8 @@ void MainWindow::eventTabChanged(int index) {
|
|||
}
|
||||
|
||||
if (!isProgrammaticEventTabChange) {
|
||||
if (!selectedEvent && editor->map->events.value(group).count()) {
|
||||
Event *event = editor->map->events.value(group).at(0);
|
||||
if (!selectedEvent && editor->map->getNumEvents(group)) {
|
||||
Event *event = editor->map->getEvent(group, 0);
|
||||
for (QGraphicsItem *child : editor->events_group->childItems()) {
|
||||
DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
|
||||
if (item->event == event) {
|
||||
|
|
@ -3222,7 +3223,7 @@ void MainWindow::reloadScriptEngine() {
|
|||
// Lying to the scripts here, simulating a project reload
|
||||
Scripting::cb_ProjectOpened(projectConfig.projectDir);
|
||||
if (editor && editor->map)
|
||||
Scripting::cb_MapOpened(editor->map->name); // TODO: API should have equivalent for layout
|
||||
Scripting::cb_MapOpened(editor->map->name()); // TODO: API should have equivalent for layout
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_AddCustomHeaderField_clicked()
|
||||
|
|
|
|||
177
src/project.cpp
177
src/project.cpp
|
|
@ -195,11 +195,11 @@ QSet<QString> Project::getTopLevelMapFields() {
|
|||
}
|
||||
|
||||
bool Project::loadMapData(Map* map) {
|
||||
if (!map->isPersistedToFile) {
|
||||
if (!map->isPersistedToFile()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QString mapFilepath = QString("%1/%3%2/map.json").arg(root).arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_map_folders));
|
||||
QString mapFilepath = QString("%1/%3%2/map.json").arg(root).arg(map->name()).arg(projectConfig.getFilePath(ProjectFilePath::data_map_folders));
|
||||
QJsonDocument mapDoc;
|
||||
if (!parser.tryParseJsonFile(&mapDoc, mapFilepath)) {
|
||||
logError(QString("Failed to read map data from %1").arg(mapFilepath));
|
||||
|
|
@ -208,28 +208,28 @@ bool Project::loadMapData(Map* map) {
|
|||
|
||||
QJsonObject mapObj = mapDoc.object();
|
||||
|
||||
map->song = ParseUtil::jsonToQString(mapObj["music"]);
|
||||
map->layoutId = ParseUtil::jsonToQString(mapObj["layout"]);
|
||||
map->location = ParseUtil::jsonToQString(mapObj["region_map_section"]);
|
||||
map->requiresFlash = ParseUtil::jsonToBool(mapObj["requires_flash"]);
|
||||
map->weather = ParseUtil::jsonToQString(mapObj["weather"]);
|
||||
map->type = ParseUtil::jsonToQString(mapObj["map_type"]);
|
||||
map->show_location = ParseUtil::jsonToBool(mapObj["show_map_name"]);
|
||||
map->battle_scene = ParseUtil::jsonToQString(mapObj["battle_scene"]);
|
||||
map->setSong(ParseUtil::jsonToQString(mapObj["music"]));
|
||||
map->setLayoutId(ParseUtil::jsonToQString(mapObj["layout"]));
|
||||
map->setLocation(ParseUtil::jsonToQString(mapObj["region_map_section"]));
|
||||
map->setRequiresFlash(ParseUtil::jsonToBool(mapObj["requires_flash"]));
|
||||
map->setWeather(ParseUtil::jsonToQString(mapObj["weather"]));
|
||||
map->setType(ParseUtil::jsonToQString(mapObj["map_type"]));
|
||||
map->setShowsLocation(ParseUtil::jsonToBool(mapObj["show_map_name"]));
|
||||
map->setBattleScene(ParseUtil::jsonToQString(mapObj["battle_scene"]));
|
||||
|
||||
if (projectConfig.mapAllowFlagsEnabled) {
|
||||
map->allowBiking = ParseUtil::jsonToBool(mapObj["allow_cycling"]);
|
||||
map->allowEscaping = ParseUtil::jsonToBool(mapObj["allow_escaping"]);
|
||||
map->allowRunning = ParseUtil::jsonToBool(mapObj["allow_running"]);
|
||||
map->setAllowsBiking(ParseUtil::jsonToBool(mapObj["allow_cycling"]));
|
||||
map->setAllowsEscaping(ParseUtil::jsonToBool(mapObj["allow_escaping"]));
|
||||
map->setAllowsRunning(ParseUtil::jsonToBool(mapObj["allow_running"]));
|
||||
}
|
||||
if (projectConfig.floorNumberEnabled) {
|
||||
map->floorNumber = ParseUtil::jsonToInt(mapObj["floor_number"]);
|
||||
map->setFloorNumber(ParseUtil::jsonToInt(mapObj["floor_number"]));
|
||||
}
|
||||
map->sharedEventsMap = ParseUtil::jsonToQString(mapObj["shared_events_map"]);
|
||||
map->sharedScriptsMap = ParseUtil::jsonToQString(mapObj["shared_scripts_map"]);
|
||||
map->setSharedEventsMap(ParseUtil::jsonToQString(mapObj["shared_events_map"]));
|
||||
map->setSharedScriptsMap(ParseUtil::jsonToQString(mapObj["shared_scripts_map"]));
|
||||
|
||||
// Events
|
||||
map->events[Event::Group::Object].clear();
|
||||
map->resetEvents();
|
||||
QJsonArray objectEventsArr = mapObj["object_events"].toArray();
|
||||
for (int i = 0; i < objectEventsArr.size(); i++) {
|
||||
QJsonObject event = objectEventsArr[i].toObject();
|
||||
|
|
@ -248,11 +248,10 @@ bool Project::loadMapData(Map* map) {
|
|||
delete clone;
|
||||
}
|
||||
} else {
|
||||
logError(QString("Map %1 object_event %2 has invalid type '%3'. Must be 'object' or 'clone'.").arg(map->name).arg(i).arg(type));
|
||||
logError(QString("Map %1 object_event %2 has invalid type '%3'. Must be 'object' or 'clone'.").arg(map->name()).arg(i).arg(type));
|
||||
}
|
||||
}
|
||||
|
||||
map->events[Event::Group::Warp].clear();
|
||||
QJsonArray warpEventsArr = mapObj["warp_events"].toArray();
|
||||
for (int i = 0; i < warpEventsArr.size(); i++) {
|
||||
QJsonObject event = warpEventsArr[i].toObject();
|
||||
|
|
@ -265,7 +264,6 @@ bool Project::loadMapData(Map* map) {
|
|||
}
|
||||
}
|
||||
|
||||
map->events[Event::Group::Coord].clear();
|
||||
QJsonArray coordEventsArr = mapObj["coord_events"].toArray();
|
||||
for (int i = 0; i < coordEventsArr.size(); i++) {
|
||||
QJsonObject event = coordEventsArr[i].toObject();
|
||||
|
|
@ -279,11 +277,10 @@ bool Project::loadMapData(Map* map) {
|
|||
coord->loadFromJson(event, this);
|
||||
map->addEvent(coord);
|
||||
} else {
|
||||
logError(QString("Map %1 coord_event %2 has invalid type '%3'. Must be 'trigger' or 'weather'.").arg(map->name).arg(i).arg(type));
|
||||
logError(QString("Map %1 coord_event %2 has invalid type '%3'. Must be 'trigger' or 'weather'.").arg(map->name()).arg(i).arg(type));
|
||||
}
|
||||
}
|
||||
|
||||
map->events[Event::Group::Bg].clear();
|
||||
QJsonArray bgEventsArr = mapObj["bg_events"].toArray();
|
||||
for (int i = 0; i < bgEventsArr.size(); i++) {
|
||||
QJsonObject event = bgEventsArr[i].toObject();
|
||||
|
|
@ -301,12 +298,12 @@ bool Project::loadMapData(Map* map) {
|
|||
bg->loadFromJson(event, this);
|
||||
map->addEvent(bg);
|
||||
} else {
|
||||
logError(QString("Map %1 bg_event %2 has invalid type '%3'. Must be 'sign', 'hidden_item', or 'secret_base'.").arg(map->name).arg(i).arg(type));
|
||||
logError(QString("Map %1 bg_event %2 has invalid type '%3'. Must be 'sign', 'hidden_item', or 'secret_base'.").arg(map->name()).arg(i).arg(type));
|
||||
}
|
||||
}
|
||||
|
||||
map->events[Event::Group::Heal].clear();
|
||||
|
||||
|
||||
/* TODO: Re-enable
|
||||
const QString mapPrefix = projectConfig.getIdentifier(ProjectIdentifier::define_map_prefix);
|
||||
for (auto it = healLocations.begin(); it != healLocations.end(); it++) {
|
||||
HealLocation loc = *it;
|
||||
|
|
@ -328,6 +325,7 @@ bool Project::loadMapData(Map* map) {
|
|||
map->ownedEvents.append(heal);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
map->deleteConnections();
|
||||
QJsonArray connectionsArr = mapObj["connections"].toArray();
|
||||
|
|
@ -347,19 +345,21 @@ bool Project::loadMapData(Map* map) {
|
|||
}
|
||||
|
||||
// Check for custom fields
|
||||
/* // TODO: Re-enable
|
||||
QSet<QString> baseFields = this->getTopLevelMapFields();
|
||||
for (QString key : mapObj.keys()) {
|
||||
if (!baseFields.contains(key)) {
|
||||
map->customHeaders.insert(key, mapObj[key]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Project::readMapLayoutId(QString map_name) {
|
||||
if (mapCache.contains(map_name)) {
|
||||
return mapCache.value(map_name)->layoutId;
|
||||
return mapCache.value(map_name)->layoutId();
|
||||
}
|
||||
|
||||
QString mapFilepath = QString("%1/%3%2/map.json").arg(root).arg(map_name).arg(projectConfig.getFilePath(ProjectFilePath::data_map_folders));
|
||||
|
|
@ -375,7 +375,7 @@ QString Project::readMapLayoutId(QString map_name) {
|
|||
|
||||
QString Project::readMapLocation(QString map_name) {
|
||||
if (mapCache.contains(map_name)) {
|
||||
return mapCache.value(map_name)->location;
|
||||
return mapCache.value(map_name)->location();
|
||||
}
|
||||
|
||||
QString mapFilepath = QString("%1/%3%2/map.json").arg(root).arg(map_name).arg(projectConfig.getFilePath(ProjectFilePath::data_map_folders));
|
||||
|
|
@ -473,21 +473,21 @@ Layout *Project::loadLayout(QString layoutId) {
|
|||
}
|
||||
|
||||
bool Project::loadMapLayout(Map* map) {
|
||||
if (!map->isPersistedToFile) {
|
||||
if (!map->isPersistedToFile()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mapLayouts.contains(map->layoutId)) {
|
||||
map->layout = mapLayouts[map->layoutId];
|
||||
if (mapLayouts.contains(map->layoutId())) {
|
||||
map->setLayout(mapLayouts[map->layoutId()]);
|
||||
} else {
|
||||
logError(QString("Error: Map '%1' has an unknown layout '%2'").arg(map->name).arg(map->layoutId));
|
||||
logError(QString("Error: Map '%1' has an unknown layout '%2'").arg(map->name()).arg(map->layoutId()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (map->hasUnsavedChanges()) {
|
||||
return true;
|
||||
} else {
|
||||
return loadLayout(map->layout);
|
||||
return loadLayout(map->layout());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -848,12 +848,14 @@ void Project::saveHealLocations(Map *map) {
|
|||
// Saves heal location maps/coords/respawn data in root + /src/data/heal_locations.h
|
||||
void Project::saveHealLocationsData(Map *map) {
|
||||
// Update heal locations from map
|
||||
/* TODO: Re-enable
|
||||
if (map->events[Event::Group::Heal].length() > 0) {
|
||||
for (Event *healEvent : map->events[Event::Group::Heal]) {
|
||||
HealLocation hl = HealLocation::fromEvent(healEvent);
|
||||
this->healLocations[hl.index - 1] = hl;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Find any duplicate constant names
|
||||
QMap<QString, int> healLocationsDupes;
|
||||
|
|
@ -1262,14 +1264,14 @@ void Project::saveAllMaps() {
|
|||
void Project::saveMap(Map *map) {
|
||||
// Create/Modify a few collateral files for brand new maps.
|
||||
QString basePath = projectConfig.getFilePath(ProjectFilePath::data_map_folders);
|
||||
QString mapDataDir = root + "/" + basePath + map->name;
|
||||
if (!map->isPersistedToFile) {
|
||||
QString mapDataDir = root + "/" + basePath + map->name();
|
||||
if (!map->isPersistedToFile()) {
|
||||
if (!QDir::root().mkdir(mapDataDir)) {
|
||||
logError(QString("Error: failed to create directory for new map: '%1'").arg(mapDataDir));
|
||||
}
|
||||
|
||||
// Create file data/maps/<map_name>/scripts.inc
|
||||
QString text = this->getScriptDefaultString(projectConfig.usePoryScript, map->name);
|
||||
QString text = this->getScriptDefaultString(projectConfig.usePoryScript, map->name());
|
||||
saveTextFile(mapDataDir + "/scripts" + this->getScriptFileExtension(projectConfig.usePoryScript), text);
|
||||
|
||||
if (projectConfig.createMapTextFileEnabled) {
|
||||
|
|
@ -1278,14 +1280,14 @@ void Project::saveMap(Map *map) {
|
|||
}
|
||||
|
||||
// Simply append to data/event_scripts.s.
|
||||
text = QString("\n\t.include \"%1%2/scripts.inc\"\n").arg(basePath, map->name);
|
||||
text = QString("\n\t.include \"%1%2/scripts.inc\"\n").arg(basePath, map->name());
|
||||
if (projectConfig.createMapTextFileEnabled) {
|
||||
text += QString("\t.include \"%1%2/text.inc\"\n").arg(basePath, map->name);
|
||||
text += QString("\t.include \"%1%2/text.inc\"\n").arg(basePath, map->name());
|
||||
}
|
||||
appendTextFile(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_event_scripts), text);
|
||||
|
||||
if (map->needsLayoutDir) {
|
||||
QString newLayoutDir = QString(root + "/%1%2").arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders), map->name);
|
||||
if (map->needsLayoutDir()) {
|
||||
QString newLayoutDir = QString(root + "/%1%2").arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders), map->name());
|
||||
if (!QDir::root().mkdir(newLayoutDir)) {
|
||||
logError(QString("Error: failed to create directory for new layout: '%1'").arg(newLayoutDir));
|
||||
}
|
||||
|
|
@ -1302,24 +1304,24 @@ void Project::saveMap(Map *map) {
|
|||
|
||||
OrderedJson::object mapObj;
|
||||
// Header values.
|
||||
mapObj["id"] = map->constantName;
|
||||
mapObj["name"] = map->name;
|
||||
mapObj["layout"] = map->layout->id;
|
||||
mapObj["music"] = map->song;
|
||||
mapObj["region_map_section"] = map->location;
|
||||
mapObj["requires_flash"] = map->requiresFlash;
|
||||
mapObj["weather"] = map->weather;
|
||||
mapObj["map_type"] = map->type;
|
||||
mapObj["id"] = map->constantName();
|
||||
mapObj["name"] = map->name();
|
||||
mapObj["layout"] = map->layout()->id;
|
||||
mapObj["music"] = map->song();
|
||||
mapObj["region_map_section"] = map->location();
|
||||
mapObj["requires_flash"] = map->requiresFlash();
|
||||
mapObj["weather"] = map->weather();
|
||||
mapObj["map_type"] = map->type();
|
||||
if (projectConfig.mapAllowFlagsEnabled) {
|
||||
mapObj["allow_cycling"] = map->allowBiking;
|
||||
mapObj["allow_escaping"] = map->allowEscaping;
|
||||
mapObj["allow_running"] = map->allowRunning;
|
||||
mapObj["allow_cycling"] = map->allowsBiking();
|
||||
mapObj["allow_escaping"] = map->allowsEscaping();
|
||||
mapObj["allow_running"] = map->allowsRunning();
|
||||
}
|
||||
mapObj["show_map_name"] = map->show_location;
|
||||
mapObj["show_map_name"] = map->showsLocation();
|
||||
if (projectConfig.floorNumberEnabled) {
|
||||
mapObj["floor_number"] = map->floorNumber;
|
||||
mapObj["floor_number"] = map->floorNumber();
|
||||
}
|
||||
mapObj["battle_scene"] = map->battle_scene;
|
||||
mapObj["battle_scene"] = map->battleScene();
|
||||
|
||||
// Connections
|
||||
auto connections = map->getConnections();
|
||||
|
|
@ -1341,67 +1343,59 @@ void Project::saveMap(Map *map) {
|
|||
mapObj["connections"] = QJsonValue::Null;
|
||||
}
|
||||
|
||||
if (map->sharedEventsMap.isEmpty()) {
|
||||
if (map->sharedEventsMap().isEmpty()) {
|
||||
// Object events
|
||||
OrderedJson::array objectEventsArr;
|
||||
for (int i = 0; i < map->events[Event::Group::Object].length(); i++) {
|
||||
Event *event = map->events[Event::Group::Object].value(i);
|
||||
OrderedJson::object jsonObj = event->buildEventJson(this);
|
||||
objectEventsArr.push_back(jsonObj);
|
||||
for (const auto &event : map->getEvents(Event::Group::Object)){
|
||||
objectEventsArr.push_back(event->buildEventJson(this));
|
||||
}
|
||||
mapObj["object_events"] = objectEventsArr;
|
||||
|
||||
|
||||
// Warp events
|
||||
OrderedJson::array warpEventsArr;
|
||||
for (int i = 0; i < map->events[Event::Group::Warp].length(); i++) {
|
||||
Event *event = map->events[Event::Group::Warp].value(i);
|
||||
OrderedJson::object warpObj = event->buildEventJson(this);
|
||||
warpEventsArr.append(warpObj);
|
||||
for (const auto &event : map->getEvents(Event::Group::Warp)) {
|
||||
warpEventsArr.push_back(event->buildEventJson(this));
|
||||
}
|
||||
mapObj["warp_events"] = warpEventsArr;
|
||||
|
||||
// Coord events
|
||||
OrderedJson::array coordEventsArr;
|
||||
for (int i = 0; i < map->events[Event::Group::Coord].length(); i++) {
|
||||
Event *event = map->events[Event::Group::Coord].value(i);
|
||||
OrderedJson::object triggerObj = event->buildEventJson(this);
|
||||
coordEventsArr.append(triggerObj);
|
||||
for (const auto &event : map->getEvents(Event::Group::Coord)) {
|
||||
coordEventsArr.push_back(event->buildEventJson(this));
|
||||
}
|
||||
mapObj["coord_events"] = coordEventsArr;
|
||||
|
||||
// Bg Events
|
||||
OrderedJson::array bgEventsArr;
|
||||
for (int i = 0; i < map->events[Event::Group::Bg].length(); i++) {
|
||||
Event *event = map->events[Event::Group::Bg].value(i);
|
||||
OrderedJson::object bgObj = event->buildEventJson(this);
|
||||
bgEventsArr.append(bgObj);
|
||||
for (const auto &event : map->getEvents(Event::Group::Bg)) {
|
||||
bgEventsArr.push_back(event->buildEventJson(this));
|
||||
}
|
||||
mapObj["bg_events"] = bgEventsArr;
|
||||
} else {
|
||||
mapObj["shared_events_map"] = map->sharedEventsMap;
|
||||
mapObj["shared_events_map"] = map->sharedEventsMap();
|
||||
}
|
||||
|
||||
if (!map->sharedScriptsMap.isEmpty()) {
|
||||
mapObj["shared_scripts_map"] = map->sharedScriptsMap;
|
||||
if (!map->sharedScriptsMap().isEmpty()) {
|
||||
mapObj["shared_scripts_map"] = map->sharedScriptsMap();
|
||||
}
|
||||
|
||||
// Custom header fields.
|
||||
/* // TODO: Re-enable
|
||||
for (QString key : map->customHeaders.keys()) {
|
||||
mapObj[key] = OrderedJson::fromQJsonValue(map->customHeaders[key]);
|
||||
}
|
||||
*/
|
||||
|
||||
OrderedJson mapJson(mapObj);
|
||||
OrderedJsonDoc jsonDoc(&mapJson);
|
||||
jsonDoc.dump(&mapFile);
|
||||
mapFile.close();
|
||||
|
||||
saveLayout(map->layout);
|
||||
saveLayout(map->layout());
|
||||
saveHealLocations(map);
|
||||
|
||||
map->isPersistedToFile = true;
|
||||
map->hasUnsavedDataChanges = false;
|
||||
map->editHistory.setClean();
|
||||
map->setClean();
|
||||
}
|
||||
|
||||
void Project::saveLayout(Layout *layout) {
|
||||
|
|
@ -1910,25 +1904,24 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool
|
|||
this->mapGroups.insert(mapName, groupNum);
|
||||
this->groupedMapNames[groupNum].append(mapName);
|
||||
|
||||
newMap->isPersistedToFile = false;
|
||||
newMap->setIsPersistedToFile(false);
|
||||
newMap->setName(mapName);
|
||||
|
||||
this->mapConstantsToMapNames.insert(newMap->constantName, newMap->name);
|
||||
this->mapNamesToMapConstants.insert(newMap->name, newMap->constantName);
|
||||
this->mapConstantsToMapNames.insert(newMap->constantName(), newMap->name());
|
||||
this->mapNamesToMapConstants.insert(newMap->name(), newMap->constantName());
|
||||
if (!existingLayout) {
|
||||
this->mapLayouts.insert(newMap->layoutId, newMap->layout);
|
||||
this->mapLayoutsTable.append(newMap->layoutId);
|
||||
this->layoutIdsToNames.insert(newMap->layout->id, newMap->layout->name);
|
||||
this->mapLayouts.insert(newMap->layoutId(), newMap->layout());
|
||||
this->mapLayoutsTable.append(newMap->layoutId());
|
||||
this->layoutIdsToNames.insert(newMap->layout()->id, newMap->layout()->name);
|
||||
if (!importedMap) {
|
||||
setNewLayoutBlockdata(newMap->layout);
|
||||
setNewLayoutBlockdata(newMap->layout());
|
||||
}
|
||||
if (newMap->layout->border.isEmpty()) {
|
||||
setNewLayoutBorder(newMap->layout);
|
||||
if (newMap->layout()->border.isEmpty()) {
|
||||
setNewLayoutBorder(newMap->layout());
|
||||
}
|
||||
}
|
||||
|
||||
loadLayoutTilesets(newMap->layout);
|
||||
setNewMapEvents(newMap);
|
||||
loadLayoutTilesets(newMap->layout());
|
||||
|
||||
return newMap;
|
||||
}
|
||||
|
|
@ -2854,14 +2847,6 @@ bool Project::readSpeciesIconPaths() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Project::setNewMapEvents(Map *map) {
|
||||
map->events[Event::Group::Object].clear();
|
||||
map->events[Event::Group::Warp].clear();
|
||||
map->events[Event::Group::Heal].clear();
|
||||
map->events[Event::Group::Coord].clear();
|
||||
map->events[Event::Group::Bg].clear();
|
||||
}
|
||||
|
||||
int Project::getNumTilesPrimary()
|
||||
{
|
||||
return Project::num_tiles_primary;
|
||||
|
|
|
|||
|
|
@ -811,10 +811,12 @@ QJSValue MainWindow::getTilePixels(int tileId) {
|
|||
// Editing map header
|
||||
//=====================
|
||||
|
||||
// TODO: Replace UI setting here with calls to appropriate set functions. Update UI with signals from Map
|
||||
|
||||
QString MainWindow::getSong() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return QString();
|
||||
return this->editor->map->song;
|
||||
return this->editor->map->song();
|
||||
}
|
||||
|
||||
void MainWindow::setSong(QString song) {
|
||||
|
|
@ -830,7 +832,7 @@ void MainWindow::setSong(QString song) {
|
|||
QString MainWindow::getLocation() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return QString();
|
||||
return this->editor->map->location;
|
||||
return this->editor->map->location();
|
||||
}
|
||||
|
||||
void MainWindow::setLocation(QString location) {
|
||||
|
|
@ -846,7 +848,7 @@ void MainWindow::setLocation(QString location) {
|
|||
bool MainWindow::getRequiresFlash() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return false;
|
||||
return this->editor->map->requiresFlash;
|
||||
return this->editor->map->requiresFlash();
|
||||
}
|
||||
|
||||
void MainWindow::setRequiresFlash(bool require) {
|
||||
|
|
@ -858,7 +860,7 @@ void MainWindow::setRequiresFlash(bool require) {
|
|||
QString MainWindow::getWeather() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return QString();
|
||||
return this->editor->map->weather;
|
||||
return this->editor->map->weather();
|
||||
}
|
||||
|
||||
void MainWindow::setWeather(QString weather) {
|
||||
|
|
@ -874,7 +876,7 @@ void MainWindow::setWeather(QString weather) {
|
|||
QString MainWindow::getType() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return QString();
|
||||
return this->editor->map->type;
|
||||
return this->editor->map->type();
|
||||
}
|
||||
|
||||
void MainWindow::setType(QString type) {
|
||||
|
|
@ -890,7 +892,7 @@ void MainWindow::setType(QString type) {
|
|||
QString MainWindow::getBattleScene() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return QString();
|
||||
return this->editor->map->battle_scene;
|
||||
return this->editor->map->battleScene();
|
||||
}
|
||||
|
||||
void MainWindow::setBattleScene(QString battleScene) {
|
||||
|
|
@ -906,7 +908,7 @@ void MainWindow::setBattleScene(QString battleScene) {
|
|||
bool MainWindow::getShowLocationName() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return false;
|
||||
return this->editor->map->show_location;
|
||||
return this->editor->map->showsLocation();
|
||||
}
|
||||
|
||||
void MainWindow::setShowLocationName(bool show) {
|
||||
|
|
@ -918,7 +920,7 @@ void MainWindow::setShowLocationName(bool show) {
|
|||
bool MainWindow::getAllowRunning() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return false;
|
||||
return this->editor->map->allowRunning;
|
||||
return this->editor->map->allowsRunning();
|
||||
}
|
||||
|
||||
void MainWindow::setAllowRunning(bool allow) {
|
||||
|
|
@ -930,7 +932,7 @@ void MainWindow::setAllowRunning(bool allow) {
|
|||
bool MainWindow::getAllowBiking() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return false;
|
||||
return this->editor->map->allowBiking;
|
||||
return this->editor->map->allowsBiking();
|
||||
}
|
||||
|
||||
void MainWindow::setAllowBiking(bool allow) {
|
||||
|
|
@ -942,7 +944,7 @@ void MainWindow::setAllowBiking(bool allow) {
|
|||
bool MainWindow::getAllowEscaping() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return false;
|
||||
return this->editor->map->allowEscaping;
|
||||
return this->editor->map->allowsEscaping();
|
||||
}
|
||||
|
||||
void MainWindow::setAllowEscaping(bool allow) {
|
||||
|
|
@ -954,7 +956,7 @@ void MainWindow::setAllowEscaping(bool allow) {
|
|||
int MainWindow::getFloorNumber() {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return 0;
|
||||
return this->editor->map->floorNumber;
|
||||
return this->editor->map->floorNumber();
|
||||
}
|
||||
|
||||
void MainWindow::setFloorNumber(int floorNumber) {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
|
|||
|
||||
// This is convoluted because of how our edit history works; this would otherwise just be 'this->connection->setOffset(newOffset);'
|
||||
if (this->connection->parentMap() && newOffset != this->connection->offset())
|
||||
this->connection->parentMap()->editHistory.push(new MapConnectionMove(this->connection, newOffset, this->actionId));
|
||||
this->connection->parentMap()->commit(new MapConnectionMove(this->connection, newOffset, this->actionId));
|
||||
|
||||
return QPointF(x, y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,24 +79,24 @@ void ConnectionsListItem::mousePressEvent(QMouseEvent *) {
|
|||
void ConnectionsListItem::on_comboBox_Direction_currentTextChanged(QString direction) {
|
||||
this->setSelected(true);
|
||||
if (this->map)
|
||||
this->map->editHistory.push(new MapConnectionChangeDirection(this->connection, direction));
|
||||
this->map->commit(new MapConnectionChangeDirection(this->connection, direction));
|
||||
}
|
||||
|
||||
void ConnectionsListItem::on_comboBox_Map_currentTextChanged(QString mapName) {
|
||||
this->setSelected(true);
|
||||
if (this->map && ui->comboBox_Map->findText(mapName) >= 0)
|
||||
this->map->editHistory.push(new MapConnectionChangeMap(this->connection, mapName));
|
||||
this->map->commit(new MapConnectionChangeMap(this->connection, mapName));
|
||||
}
|
||||
|
||||
void ConnectionsListItem::on_spinBox_Offset_valueChanged(int offset) {
|
||||
this->setSelected(true);
|
||||
if (this->map)
|
||||
this->map->editHistory.push(new MapConnectionMove(this->connection, offset, this->actionId));
|
||||
this->map->commit(new MapConnectionMove(this->connection, offset, this->actionId));
|
||||
}
|
||||
|
||||
void ConnectionsListItem::on_button_Delete_clicked() {
|
||||
if (this->map)
|
||||
this->map->editHistory.push(new MapConnectionRemove(this->map, this->connection));
|
||||
this->map->commit(new MapConnectionRemove(this->map, this->connection));
|
||||
}
|
||||
|
||||
void ConnectionsListItem::on_button_OpenMap_clicked() {
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
|||
} else {
|
||||
selectedEvents.append(this->event);
|
||||
}
|
||||
editor->map->editHistory.push(new EventMove(selectedEvents, moveDistance.x(), moveDistance.y(), currentActionId));
|
||||
editor->map->commit(new EventMove(selectedEvents, moveDistance.x(), moveDistance.y(), currentActionId));
|
||||
this->releaseSelectionQueued = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ void EventFrame::connectSignals(MainWindow *) {
|
|||
connect(this->spinner_x, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
|
||||
int delta = value - event->getX();
|
||||
if (delta) {
|
||||
this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << this->event, delta, 0, this->spinner_x->getActionId()));
|
||||
this->event->getMap()->commit(new EventMove(QList<Event *>() << this->event, delta, 0, this->spinner_x->getActionId()));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ void EventFrame::connectSignals(MainWindow *) {
|
|||
connect(this->spinner_y, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
|
||||
int delta = value - event->getY();
|
||||
if (delta) {
|
||||
this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << this->event, 0, delta, this->spinner_y->getActionId()));
|
||||
this->event->getMap()->commit(new EventMove(QList<Event *>() << this->event, 0, delta, this->spinner_y->getActionId()));
|
||||
}
|
||||
});
|
||||
connect(this->event->getPixmapItem(), &DraggablePixmapItem::yChanged, this->spinner_y, &NoScrollSpinBox::setValue);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_, ImageExpor
|
|||
|
||||
if (this->map) {
|
||||
this->ui->comboBox_MapSelection->addItems(editor->project->mapNames);
|
||||
this->ui->comboBox_MapSelection->setCurrentText(map->name);
|
||||
this->ui->comboBox_MapSelection->setCurrentText(map->name());
|
||||
this->ui->comboBox_MapSelection->setEnabled(false);// TODO: allow selecting map from drop-down
|
||||
}
|
||||
|
||||
|
|
@ -85,18 +85,19 @@ void MapImageExporter::saveImage() {
|
|||
if (this->preview.isNull())
|
||||
return;
|
||||
|
||||
QString title = getTitle(this->mode);
|
||||
const QString title = getTitle(this->mode);
|
||||
const QString itemName = this->map ? this->map->name() : this->layout->name;
|
||||
QString defaultFilename;
|
||||
switch (this->mode)
|
||||
{
|
||||
case ImageExporterMode::Normal:
|
||||
defaultFilename = this->map? this->map->name : this->layout->name;
|
||||
defaultFilename = itemName;
|
||||
break;
|
||||
case ImageExporterMode::Stitch:
|
||||
defaultFilename = QString("Stitch_From_%1").arg(this->map? this->map->name : this->layout->name);
|
||||
defaultFilename = QString("Stitch_From_%1").arg(itemName);
|
||||
break;
|
||||
case ImageExporterMode::Timelapse:
|
||||
defaultFilename = QString("Timelapse_%1").arg(this->map? this->map->name : this->layout->name);
|
||||
defaultFilename = QString("Timelapse_%1").arg(itemName);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +122,7 @@ void MapImageExporter::saveImage() {
|
|||
timelapseImg.setDefaultTransparentColor(QColor(0, 0, 0));
|
||||
|
||||
// lambda to avoid redundancy
|
||||
auto generateTimelapseFromHistory = [this, &timelapseImg](QString progressText, QUndoStack &historyStack){
|
||||
auto generateTimelapseFromHistory = [this, &timelapseImg](QString progressText, QUndoStack *historyStack){
|
||||
QProgressDialog progress(progressText, "Cancel", 0, 1, this);
|
||||
progress.setAutoClose(true);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
|
|
@ -137,9 +138,9 @@ void MapImageExporter::saveImage() {
|
|||
}
|
||||
// Rewind to the specified start of the map edit history.
|
||||
int i = 0;
|
||||
while (historyStack.canUndo()) {
|
||||
while (historyStack->canUndo()) {
|
||||
progress.setValue(i);
|
||||
historyStack.undo();
|
||||
historyStack->undo();
|
||||
int width = this->layout->getWidth() * 16;
|
||||
int height = this->layout->getHeight() * 16;
|
||||
if (this->settings.showBorder) {
|
||||
|
|
@ -161,16 +162,16 @@ void MapImageExporter::saveImage() {
|
|||
while (i > 0) {
|
||||
if (progress.wasCanceled()) {
|
||||
progress.close();
|
||||
while (i > 0 && historyStack.canRedo()) {
|
||||
while (i > 0 && historyStack->canRedo()) {
|
||||
i--;
|
||||
historyStack.redo();
|
||||
historyStack->redo();
|
||||
}
|
||||
return;
|
||||
}
|
||||
while (historyStack.canRedo() &&
|
||||
!historyItemAppliesToFrame(historyStack.command(historyStack.index()))) {
|
||||
while (historyStack->canRedo() &&
|
||||
!historyItemAppliesToFrame(historyStack->command(historyStack->index()))) {
|
||||
i--;
|
||||
historyStack.redo();
|
||||
historyStack->redo();
|
||||
}
|
||||
progress.setValue(progress.maximum() - i);
|
||||
QPixmap pixmap = this->getFormattedMapPixmap(this->map);
|
||||
|
|
@ -186,11 +187,11 @@ void MapImageExporter::saveImage() {
|
|||
for (int j = 0; j < this->settings.timelapseSkipAmount; j++) {
|
||||
if (i > 0) {
|
||||
i--;
|
||||
historyStack.redo();
|
||||
while (historyStack.canRedo() &&
|
||||
!historyItemAppliesToFrame(historyStack.command(historyStack.index()))) {
|
||||
historyStack->redo();
|
||||
while (historyStack->canRedo() &&
|
||||
!historyItemAppliesToFrame(historyStack->command(historyStack->index()))) {
|
||||
i--;
|
||||
historyStack.redo();
|
||||
historyStack->redo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -202,10 +203,10 @@ void MapImageExporter::saveImage() {
|
|||
};
|
||||
|
||||
if (this->layout)
|
||||
generateTimelapseFromHistory("Building layout timelapse...", this->layout->editHistory);
|
||||
generateTimelapseFromHistory("Building layout timelapse...", &this->layout->editHistory);
|
||||
|
||||
if (this->map)
|
||||
generateTimelapseFromHistory("Building map timelapse...", this->map->editHistory);
|
||||
generateTimelapseFromHistory("Building map timelapse...", this->map->editHistory());
|
||||
|
||||
timelapseImg.save(filepath);
|
||||
break;
|
||||
|
|
@ -279,9 +280,9 @@ QPixmap MapImageExporter::getStitchedImage(QProgressDialog *progress, bool inclu
|
|||
progress->setValue(visited.size());
|
||||
|
||||
StitchedMap cur = unvisited.takeFirst();
|
||||
if (visited.contains(cur.map->name))
|
||||
if (visited.contains(cur.map->name()))
|
||||
continue;
|
||||
visited.insert(cur.map->name);
|
||||
visited.insert(cur.map->name());
|
||||
stitchedMaps.append(cur);
|
||||
|
||||
for (MapConnection *connection : cur.map->getConnections()) {
|
||||
|
|
@ -420,22 +421,11 @@ void MapImageExporter::scalePreview() {
|
|||
}
|
||||
}
|
||||
|
||||
// THIS
|
||||
QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
|
||||
QPixmap pixmap;
|
||||
Layout *layout = this->map ? this->map->layout() : this->layout;
|
||||
layout->render(true);
|
||||
|
||||
Layout *layout;
|
||||
|
||||
// draw background layer / base image
|
||||
if (!this->map) {
|
||||
layout = this->layout;
|
||||
layout->render(true);
|
||||
pixmap = layout->pixmap;
|
||||
} else {
|
||||
layout = map->layout;
|
||||
map->layout->render(true);
|
||||
pixmap = map->layout->pixmap;
|
||||
}
|
||||
QPixmap pixmap = layout->pixmap;
|
||||
|
||||
if (this->settings.showCollision) {
|
||||
QPainter collisionPainter(&pixmap);
|
||||
|
|
@ -494,7 +484,7 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
|
|||
if (!ignoreBorder && this->settings.showBorder) {
|
||||
pixelOffset = this->mode == ImageExporterMode::Normal ? BORDER_DISTANCE * 16 : STITCH_MODE_BORDER_DISTANCE * 16;
|
||||
}
|
||||
const QList<Event *> events = map->getAllEvents();
|
||||
const QList<Event *> events = map->getEvents();
|
||||
for (const auto &event : events) {
|
||||
Event::Group group = event->getEventGroup();
|
||||
if ((this->settings.showObjects && group == Event::Group::Object)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ NewMapConnectionDialog::NewMapConnectionDialog(QWidget *parent, Map* map, const
|
|||
QString defaultMapName;
|
||||
if (mapNames.isEmpty()) {
|
||||
defaultMapName = QString();
|
||||
} else if (mapNames.first() == map->name && mapNames.length() > 1) {
|
||||
} else if (mapNames.first() == map->name() && mapNames.length() > 1) {
|
||||
// Prefer not to connect the map to itself
|
||||
defaultMapName = mapNames.at(1);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -129,11 +129,11 @@ void NewMapPopup::init(Layout *mapLayout) {
|
|||
useLayoutSettings(mapLayout);
|
||||
|
||||
this->map = new Map();
|
||||
this->map->layout = new Layout();
|
||||
this->map->layout->blockdata = mapLayout->blockdata;
|
||||
this->map->setLayout(new Layout());
|
||||
this->map->layout()->blockdata = mapLayout->blockdata;
|
||||
|
||||
if (!mapLayout->border.isEmpty()) {
|
||||
this->map->layout->border = mapLayout->border;
|
||||
this->map->layout()->border = mapLayout->border;
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
|
@ -299,22 +299,22 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
|||
newMapName = project->getNewMapName();
|
||||
}
|
||||
|
||||
newMap->name = newMapName;
|
||||
newMap->type = this->ui->comboBox_NewMap_Type->currentText();
|
||||
newMap->location = this->ui->comboBox_NewMap_Location->currentText();
|
||||
newMap->song = this->ui->comboBox_NewMap_Song->currentText();
|
||||
newMap->requiresFlash = false;
|
||||
newMap->weather = this->project->weatherNames.value(0, "0");
|
||||
newMap->show_location = this->ui->checkBox_NewMap_Show_Location->isChecked();
|
||||
newMap->battle_scene = this->project->mapBattleScenes.value(0, "0");
|
||||
newMap->setName(newMapName);
|
||||
newMap->setType(this->ui->comboBox_NewMap_Type->currentText());
|
||||
newMap->setLocation(this->ui->comboBox_NewMap_Location->currentText());
|
||||
newMap->setSong(this->ui->comboBox_NewMap_Song->currentText());
|
||||
newMap->setRequiresFlash(false);
|
||||
newMap->setWeather(this->project->weatherNames.value(0, "0"));
|
||||
newMap->setShowsLocation(this->ui->checkBox_NewMap_Show_Location->isChecked());
|
||||
newMap->setBattleScene(this->project->mapBattleScenes.value(0, "0"));
|
||||
|
||||
if (this->existingLayout) {
|
||||
layout = this->project->mapLayouts.value(this->layoutId);
|
||||
newMap->needsLayoutDir = false;
|
||||
newMap->setNeedsLayoutDir(false);
|
||||
} else {
|
||||
layout = new Layout;
|
||||
layout->id = Layout::layoutConstantFromName(newMapName);
|
||||
layout->name = QString("%1_Layout").arg(newMap->name);
|
||||
layout->name = QString("%1_Layout").arg(newMap->name());
|
||||
layout->width = this->ui->spinBox_NewMap_Width->value();
|
||||
layout->height = this->ui->spinBox_NewMap_Height->value();
|
||||
if (projectConfig.useCustomBorderSize) {
|
||||
|
|
@ -332,26 +332,25 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
|||
}
|
||||
|
||||
if (this->importedMap) {
|
||||
layout->blockdata = map->layout->blockdata;
|
||||
if (!map->layout->border.isEmpty())
|
||||
layout->border = map->layout->border;
|
||||
layout->blockdata = map->layout()->blockdata;
|
||||
if (!map->layout()->border.isEmpty())
|
||||
layout->border = map->layout()->border;
|
||||
}
|
||||
|
||||
if (this->ui->checkBox_NewMap_Flyable->isChecked()) {
|
||||
newMap->needsHealLocation = true;
|
||||
newMap->setNeedsHealLocation(true);
|
||||
}
|
||||
|
||||
if (projectConfig.mapAllowFlagsEnabled) {
|
||||
newMap->allowRunning = this->ui->checkBox_NewMap_Allow_Running->isChecked();
|
||||
newMap->allowBiking = this->ui->checkBox_NewMap_Allow_Biking->isChecked();
|
||||
newMap->allowEscaping = this->ui->checkBox_NewMap_Allow_Escape_Rope->isChecked();
|
||||
newMap->setAllowsRunning(this->ui->checkBox_NewMap_Allow_Running->isChecked());
|
||||
newMap->setAllowsBiking(this->ui->checkBox_NewMap_Allow_Biking->isChecked());
|
||||
newMap->setAllowsEscaping(this->ui->checkBox_NewMap_Allow_Escape_Rope->isChecked());
|
||||
}
|
||||
if (projectConfig.floorNumberEnabled) {
|
||||
newMap->floorNumber = this->ui->spinBox_NewMap_Floor_Number->value();
|
||||
newMap->setFloorNumber(this->ui->spinBox_NewMap_Floor_Number->value());
|
||||
}
|
||||
|
||||
newMap->layout = layout;
|
||||
newMap->layoutId = layout->id;
|
||||
newMap->setLayout(layout);
|
||||
if (this->existingLayout) {
|
||||
project->loadMapLayout(newMap);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user