Support map JSON data
This commit is contained in:
parent
d2508b1f1d
commit
94686e6f0a
12 changed files with 625 additions and 890 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
class EventType
|
class EventType
|
||||||
{
|
{
|
||||||
|
@ -64,13 +65,13 @@ public:
|
||||||
static Event* createNewHiddenItemEvent();
|
static Event* createNewHiddenItemEvent();
|
||||||
static Event* createNewSecretBaseEvent();
|
static Event* createNewSecretBaseEvent();
|
||||||
|
|
||||||
QString buildObjectEventMacro(int);
|
QJsonObject buildObjectEventJSON();
|
||||||
QString buildWarpEventMacro(QMap<QString, QString>*);
|
QJsonObject buildWarpEventJSON(QMap<QString, QString>*);
|
||||||
QString buildTriggerEventMacro();
|
QJsonObject buildTriggerEventJSON();
|
||||||
QString buildWeatherTriggerEventMacro();
|
QJsonObject buildWeatherTriggerEventJSON();
|
||||||
QString buildSignEventMacro();
|
QJsonObject buildSignEventJSON();
|
||||||
QString buildHiddenItemEventMacro();
|
QJsonObject buildHiddenItemEventJSON();
|
||||||
QString buildSecretBaseEventMacro();
|
QJsonObject buildSecretBaseEventJSON();
|
||||||
void setPixmapFromSpritesheet(QImage, int, int);
|
void setPixmapFromSpritesheet(QImage, int, int);
|
||||||
int getPixelX();
|
int getPixelX();
|
||||||
int getPixelY();
|
int getPixelY();
|
||||||
|
|
|
@ -24,18 +24,13 @@ public:
|
||||||
QString name;
|
QString name;
|
||||||
QString constantName;
|
QString constantName;
|
||||||
QString group_num;
|
QString group_num;
|
||||||
QString layout_label;
|
|
||||||
QString events_label;
|
|
||||||
QString scripts_label;
|
|
||||||
QString connections_label;
|
|
||||||
QString song;
|
QString song;
|
||||||
QString layout_id;
|
QString layoutId;
|
||||||
QString location;
|
QString location;
|
||||||
QString requiresFlash;
|
QString requiresFlash;
|
||||||
QString isFlyable;
|
QString isFlyable;
|
||||||
QString weather;
|
QString weather;
|
||||||
QString type;
|
QString type;
|
||||||
QString unknown;
|
|
||||||
QString show_location;
|
QString show_location;
|
||||||
QString allowRunning;
|
QString allowRunning;
|
||||||
QString allowBiking;
|
QString allowBiking;
|
||||||
|
|
|
@ -10,14 +10,12 @@
|
||||||
class MapLayout {
|
class MapLayout {
|
||||||
public:
|
public:
|
||||||
MapLayout() {}
|
MapLayout() {}
|
||||||
int index;
|
static QString layoutConstantFromName(QString mapName);
|
||||||
|
QString id;
|
||||||
QString name;
|
QString name;
|
||||||
QString label;
|
|
||||||
QString width;
|
QString width;
|
||||||
QString height;
|
QString height;
|
||||||
QString border_label;
|
|
||||||
QString border_path;
|
QString border_path;
|
||||||
QString blockdata_label;
|
|
||||||
QString blockdata_path;
|
QString blockdata_path;
|
||||||
QString tileset_primary_label;
|
QString tileset_primary_label;
|
||||||
QString tileset_secondary_label;
|
QString tileset_secondary_label;
|
||||||
|
@ -31,11 +29,6 @@ public:
|
||||||
Blockdata *cached_collision = nullptr;
|
Blockdata *cached_collision = nullptr;
|
||||||
Blockdata *cached_border = nullptr;
|
Blockdata *cached_border = nullptr;
|
||||||
bool has_unsaved_changes = false;
|
bool has_unsaved_changes = false;
|
||||||
public:
|
|
||||||
static QString getNameFromLabel(QString label) {
|
|
||||||
// ASSUMPTION: strip off "_Layout" from layout label. Directories in 'data/layouts/' must be well-formed.
|
|
||||||
return label.replace(label.lastIndexOf("_Layout"), label.length(), "");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPLAYOUT_H
|
#endif // MAPLAYOUT_H
|
||||||
|
|
|
@ -226,6 +226,7 @@ private:
|
||||||
enum MapListUserRoles {
|
enum MapListUserRoles {
|
||||||
GroupRole = Qt::UserRole + 1, // Used to hold the map group number.
|
GroupRole = Qt::UserRole + 1, // Used to hold the map group number.
|
||||||
TypeRole, // Used to differentiate between the different layers of the map list tree view.
|
TypeRole, // Used to differentiate between the different layers of the map list tree view.
|
||||||
|
TypeRole2, // Used for various extra data needed.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
QMap<QString, QString>* mapNamesToMapConstants;
|
QMap<QString, QString>* mapNamesToMapConstants;
|
||||||
QList<QString> mapLayoutsTable;
|
QList<QString> mapLayoutsTable;
|
||||||
QList<QString> mapLayoutsTableMaster;
|
QList<QString> mapLayoutsTableMaster;
|
||||||
|
QString layoutsLabel;
|
||||||
QMap<QString, MapLayout*> mapLayouts;
|
QMap<QString, MapLayout*> mapLayouts;
|
||||||
QMap<QString, MapLayout*> mapLayoutsMaster;
|
QMap<QString, MapLayout*> mapLayoutsMaster;
|
||||||
QStringList *regionMapSections = nullptr;
|
QStringList *regionMapSections = nullptr;
|
||||||
|
@ -39,7 +40,6 @@ public:
|
||||||
QStringList *coordEventWeatherNames = nullptr;
|
QStringList *coordEventWeatherNames = nullptr;
|
||||||
QStringList *secretBaseIds = nullptr;
|
QStringList *secretBaseIds = nullptr;
|
||||||
QStringList *bgEventFacingDirections = nullptr;
|
QStringList *bgEventFacingDirections = nullptr;
|
||||||
QStringList mapsWithConnections;
|
|
||||||
QMap<QString, int> metatileBehaviorMap;
|
QMap<QString, int> metatileBehaviorMap;
|
||||||
QMap<int, QString> metatileBehaviorMapInverse;
|
QMap<int, QString> metatileBehaviorMapInverse;
|
||||||
|
|
||||||
|
@ -70,25 +70,22 @@ public:
|
||||||
|
|
||||||
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
||||||
QStringList* getLabelValues(QList<QStringList>*, QString);
|
QStringList* getLabelValues(QList<QStringList>*, QString);
|
||||||
bool readMapHeader(Map*);
|
bool loadMapData(Map*);
|
||||||
void readMapLayoutsTable();
|
void readMapLayouts();
|
||||||
void readAllMapLayouts();
|
void loadMapLayout(Map*);
|
||||||
QStringList* readLayoutValues(QString layoutName);
|
|
||||||
void readMapLayout(Map*);
|
|
||||||
void readMapsWithConnections();
|
|
||||||
void loadMapTilesets(Map*);
|
void loadMapTilesets(Map*);
|
||||||
void loadTilesetAssets(Tileset*);
|
void loadTilesetAssets(Tileset*);
|
||||||
void loadTilesetTiles(Tileset*, QImage);
|
void loadTilesetTiles(Tileset*, QImage);
|
||||||
void loadTilesetMetatiles(Tileset*);
|
void loadTilesetMetatiles(Tileset*);
|
||||||
|
|
||||||
void saveBlockdata(Map*);
|
void saveLayoutBlockdata(Map*);
|
||||||
void saveMapBorder(Map*);
|
void saveLayoutBorder(Map*);
|
||||||
void writeBlockdata(QString, Blockdata*);
|
void writeBlockdata(QString, Blockdata*);
|
||||||
void saveAllMaps();
|
void saveAllMaps();
|
||||||
void saveMap(Map*);
|
void saveMap(Map*);
|
||||||
void saveAllDataStructures();
|
void saveAllDataStructures();
|
||||||
void saveAllMapLayouts();
|
void saveMapLayouts();
|
||||||
void saveMapGroupsTable();
|
void saveMapGroups();
|
||||||
void saveMapConstantsHeader();
|
void saveMapConstantsHeader();
|
||||||
void saveHealLocationStruct(Map*);
|
void saveHealLocationStruct(Map*);
|
||||||
void saveTilesets(Tileset*, Tileset*);
|
void saveTilesets(Tileset*, Tileset*);
|
||||||
|
@ -116,12 +113,9 @@ public:
|
||||||
QString fixPalettePath(QString path);
|
QString fixPalettePath(QString path);
|
||||||
QString fixGraphicPath(QString path);
|
QString fixGraphicPath(QString path);
|
||||||
|
|
||||||
void readMapEvents(Map *map);
|
|
||||||
void loadMapConnections(Map *map);
|
|
||||||
|
|
||||||
void loadMapBorder(Map *map);
|
void loadMapBorder(Map *map);
|
||||||
|
|
||||||
void saveMapEvents(Map *map);
|
void saveMapHealEvents(Map *map);
|
||||||
|
|
||||||
QStringList readCArray(QString text, QString label);
|
QStringList readCArray(QString text, QString label);
|
||||||
QString readCIncbin(QString text, QString label);
|
QString readCIncbin(QString text, QString label);
|
||||||
|
@ -134,17 +128,10 @@ public:
|
||||||
static int getNumPalettesPrimary();
|
static int getNumPalettesPrimary();
|
||||||
static int getNumPalettesTotal();
|
static int getNumPalettesTotal();
|
||||||
private:
|
private:
|
||||||
QString getMapLayoutsTableFilepath();
|
|
||||||
QString getMapLayoutFilepath(QString);
|
|
||||||
void saveMapHeader(Map*);
|
|
||||||
void saveMapConnections(Map*);
|
|
||||||
void saveTilesetMetatileAttributes(Tileset*);
|
void saveTilesetMetatileAttributes(Tileset*);
|
||||||
void saveTilesetMetatiles(Tileset*);
|
void saveTilesetMetatiles(Tileset*);
|
||||||
void saveTilesetTilesImage(Tileset*);
|
void saveTilesetTilesImage(Tileset*);
|
||||||
void saveTilesetPalettes(Tileset*, bool);
|
void saveTilesetPalettes(Tileset*, bool);
|
||||||
void updateMapsWithConnections(Map*);
|
|
||||||
void saveMapsWithConnections();
|
|
||||||
void saveMapLayoutsTable();
|
|
||||||
void updateMapLayout(Map*);
|
void updateMapLayout(Map*);
|
||||||
void readCDefinesSorted(QString, QStringList, QStringList*);
|
void readCDefinesSorted(QString, QStringList, QStringList*);
|
||||||
void readCDefinesSorted(QString, QStringList, QStringList*, QString, int);
|
void readCDefinesSorted(QString, QStringList, QStringList*, QString, int);
|
||||||
|
|
|
@ -19,8 +19,8 @@ public:
|
||||||
~NewMapPopup();
|
~NewMapPopup();
|
||||||
Map *map;
|
Map *map;
|
||||||
int group;
|
int group;
|
||||||
bool changeLayout;
|
bool existingLayout;
|
||||||
QString layoutName;
|
QString layoutId;
|
||||||
void init(int, int, QString, QString);
|
void init(int, int, QString, QString);
|
||||||
void useLayout(QString);
|
void useLayout(QString);
|
||||||
|
|
||||||
|
|
|
@ -139,100 +139,98 @@ int Event::getPixelY()
|
||||||
return (this->y() * 16) - qMax(0, this->spriteHeight - 16);
|
return (this->y() * 16) - qMax(0, this->spriteHeight - 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Event::buildObjectEventMacro(int item_index)
|
QJsonObject Event::buildObjectEventJSON()
|
||||||
{
|
{
|
||||||
int radius_x = this->getInt("radius_x");
|
QJsonObject eventObj;
|
||||||
int radius_y = this->getInt("radius_y");
|
eventObj["graphics_id"] = this->get("sprite");
|
||||||
uint16_t x = this->getU16("x");
|
eventObj["x"] = this->getU16("x");
|
||||||
uint16_t y = this->getU16("y");
|
eventObj["y"] = this->getU16("y");
|
||||||
|
eventObj["elevation"] = this->getInt("elevation");
|
||||||
|
eventObj["movement_type"] = this->get("movement_type");
|
||||||
|
eventObj["movement_range_x"] = this->getInt("radius_x");
|
||||||
|
eventObj["movement_range_y"] = this->getInt("radius_y");
|
||||||
|
eventObj["trainer_type"] = this->get("trainer_type");
|
||||||
|
eventObj["trainer_sight_or_berry_tree_id"] = this->get("sight_radius_tree_id");
|
||||||
|
eventObj["script"] = this->get("script_label");
|
||||||
|
eventObj["flag"] = this->get("event_flag");
|
||||||
|
|
||||||
QString text = "";
|
return eventObj;
|
||||||
text += QString("\tobject_event %1").arg(item_index + 1);
|
|
||||||
text += QString(", %1").arg(this->get("sprite"));
|
|
||||||
text += QString(", %1").arg(this->get("replacement"));
|
|
||||||
text += QString(", %1").arg(x);
|
|
||||||
text += QString(", %1").arg(y);
|
|
||||||
text += QString(", %1").arg(this->get("elevation"));
|
|
||||||
text += QString(", %1").arg(this->get("movement_type"));
|
|
||||||
text += QString(", %1").arg(radius_x);
|
|
||||||
text += QString(", %1").arg(radius_y);
|
|
||||||
text += QString(", %1").arg(this->get("trainer_type"));
|
|
||||||
text += QString(", %1").arg(this->get("sight_radius_tree_id"));
|
|
||||||
text += QString(", %1").arg(this->get("script_label"));
|
|
||||||
text += QString(", %1").arg(this->get("event_flag"));
|
|
||||||
text += "\n";
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Event::buildWarpEventMacro(QMap<QString, QString> *mapNamesToMapConstants)
|
QJsonObject Event::buildWarpEventJSON(QMap<QString, QString> *mapNamesToMapConstants)
|
||||||
{
|
{
|
||||||
QString text = "";
|
QJsonObject warpObj;
|
||||||
text += QString("\twarp_def %1").arg(this->get("x"));
|
warpObj["x"] = this->getU16("x");
|
||||||
text += QString(", %1").arg(this->get("y"));
|
warpObj["y"] = this->getU16("y");
|
||||||
text += QString(", %1").arg(this->get("elevation"));
|
warpObj["elevation"] = this->getInt("elevation");
|
||||||
text += QString(", %1").arg(this->get("destination_warp"));
|
warpObj["dest_map"] = mapNamesToMapConstants->value(this->get("destination_map_name"));
|
||||||
text += QString(", %1").arg(mapNamesToMapConstants->value(this->get("destination_map_name")));
|
warpObj["dest_warp_id"] = this->getInt("destination_warp");
|
||||||
text += "\n";
|
|
||||||
return text;
|
return warpObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Event::buildTriggerEventMacro()
|
QJsonObject Event::buildTriggerEventJSON()
|
||||||
{
|
{
|
||||||
QString text = "";
|
QJsonObject triggerObj;
|
||||||
text += QString("\tcoord_event %1").arg(this->get("x"));
|
triggerObj["type"] = "trigger";
|
||||||
text += QString(", %1").arg(this->get("y"));
|
triggerObj["x"] = this->getU16("x");
|
||||||
text += QString(", %1").arg(this->get("elevation"));
|
triggerObj["y"] = this->getU16("y");
|
||||||
text += QString(", %1").arg(this->get("script_var"));
|
triggerObj["elevation"] = this->getInt("elevation");
|
||||||
text += QString(", %1").arg(this->get("script_var_value"));
|
triggerObj["var"] = this->get("script_var");
|
||||||
text += QString(", %1").arg(this->get("script_label"));
|
triggerObj["var_value"] = this->get("script_var_value");
|
||||||
text += "\n";
|
triggerObj["script"] = this->get("script_label");
|
||||||
return text;
|
|
||||||
|
return triggerObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Event::buildWeatherTriggerEventMacro()
|
QJsonObject Event::buildWeatherTriggerEventJSON()
|
||||||
{
|
{
|
||||||
QString text = "";
|
QJsonObject weatherObj;
|
||||||
text += QString("\tcoord_weather_event %1").arg(this->get("x"));
|
weatherObj["type"] = "weather";
|
||||||
text += QString(", %1").arg(this->get("y"));
|
weatherObj["x"] = this->getU16("x");
|
||||||
text += QString(", %1").arg(this->get("elevation"));
|
weatherObj["y"] = this->getU16("y");
|
||||||
text += QString(", %1").arg(this->get("weather"));
|
weatherObj["elevation"] = this->getInt("elevation");
|
||||||
text += "\n";
|
weatherObj["weather"] = this->get("weather");
|
||||||
return text;
|
|
||||||
|
return weatherObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Event::buildSignEventMacro()
|
QJsonObject Event::buildSignEventJSON()
|
||||||
{
|
{
|
||||||
QString text = "";
|
QJsonObject signObj;
|
||||||
text += QString("\tbg_event %1").arg(this->get("x"));
|
signObj["type"] = "sign";
|
||||||
text += QString(", %1").arg(this->get("y"));
|
signObj["x"] = this->getU16("x");
|
||||||
text += QString(", %1").arg(this->get("elevation"));
|
signObj["y"] = this->getU16("y");
|
||||||
text += QString(", %1").arg(this->get("player_facing_direction"));
|
signObj["elevation"] = this->getInt("elevation");
|
||||||
text += QString(", %1").arg(this->get("script_label"));
|
signObj["player_facing_dir"] = this->get("player_facing_direction");
|
||||||
text += "\n";
|
signObj["script"] = this->get("script_label");
|
||||||
return text;
|
|
||||||
|
return signObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Event::buildHiddenItemEventMacro()
|
QJsonObject Event::buildHiddenItemEventJSON()
|
||||||
{
|
{
|
||||||
QString text = "";
|
QJsonObject hiddenItemObj;
|
||||||
text += QString("\tbg_hidden_item_event %1").arg(this->get("x"));
|
hiddenItemObj["type"] = "hidden_item";
|
||||||
text += QString(", %1").arg(this->get("y"));
|
hiddenItemObj["x"] = this->getU16("x");
|
||||||
text += QString(", %1").arg(this->get("elevation"));
|
hiddenItemObj["y"] = this->getU16("y");
|
||||||
text += QString(", %1").arg(this->get("item"));
|
hiddenItemObj["elevation"] = this->getInt("elevation");
|
||||||
text += QString(", %1").arg(this->get("flag"));
|
hiddenItemObj["item"] = this->get("item");
|
||||||
text += "\n";
|
hiddenItemObj["flag"] = this->get("flag");
|
||||||
return text;
|
|
||||||
|
return hiddenItemObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Event::buildSecretBaseEventMacro()
|
QJsonObject Event::buildSecretBaseEventJSON()
|
||||||
{
|
{
|
||||||
QString text = "";
|
QJsonObject secretBaseObj;
|
||||||
text += QString("\tbg_secret_base_event %1").arg(this->get("x"));
|
secretBaseObj["type"] = "secret_base";
|
||||||
text += QString(", %1").arg(this->get("y"));
|
secretBaseObj["x"] = this->getU16("x");
|
||||||
text += QString(", %1").arg(this->get("elevation"));
|
secretBaseObj["y"] = this->getU16("y");
|
||||||
text += QString(", %1").arg(this->get("secret_base_id"));
|
secretBaseObj["elevation"] = this->getInt("elevation");
|
||||||
text += "\n";
|
secretBaseObj["secret_base_id"] = this->get("secret_base_id");
|
||||||
return text;
|
|
||||||
|
return secretBaseObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight)
|
void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight)
|
||||||
|
|
|
@ -1,2 +1,16 @@
|
||||||
#include "maplayout.h"
|
#include "maplayout.h"
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
QString MapLayout::layoutConstantFromName(QString mapName) {
|
||||||
|
// Transform map names of the form 'GraniteCave_B1F` into layout constants like 'LAYOUT_GRANITE_CAVE_B1F'.
|
||||||
|
QString nameWithUnderscores = mapName.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2");
|
||||||
|
QString withMapAndUppercase = "LAYOUT_" + nameWithUnderscores.toUpper();
|
||||||
|
QString constantName = withMapAndUppercase.replace(QRegularExpression("_+"), "_");
|
||||||
|
|
||||||
|
// Handle special cases.
|
||||||
|
// SSTidal should be SS_TIDAL, rather than SSTIDAL
|
||||||
|
constantName = constantName.replace("SSTIDAL", "SS_TIDAL");
|
||||||
|
|
||||||
|
return constantName;
|
||||||
|
}
|
||||||
|
|
|
@ -1225,6 +1225,8 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
|
||||||
Event *event = Event::createNewEvent(event_type, map->name);
|
Event *event = Event::createNewEvent(event_type, map->name);
|
||||||
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);
|
||||||
|
project->flyableMaps.append(hl);
|
||||||
event->put("index", project->flyableMaps.length());
|
event->put("index", project->flyableMaps.length());
|
||||||
}
|
}
|
||||||
map->addEvent(event);
|
map->addEvent(event);
|
||||||
|
|
|
@ -580,8 +580,7 @@ void MainWindow::on_checkBox_AllowEscapeRope_clicked(bool checked)
|
||||||
|
|
||||||
void MainWindow::loadDataStructures() {
|
void MainWindow::loadDataStructures() {
|
||||||
Project *project = editor->project;
|
Project *project = editor->project;
|
||||||
project->readMapLayoutsTable();
|
project->readMapLayouts();
|
||||||
project->readAllMapLayouts();
|
|
||||||
project->readRegionMapSections();
|
project->readRegionMapSections();
|
||||||
project->readItemNames();
|
project->readItemNames();
|
||||||
project->readFlagNames();
|
project->readFlagNames();
|
||||||
|
@ -593,7 +592,6 @@ void MainWindow::loadDataStructures() {
|
||||||
project->readCoordEventWeatherNames();
|
project->readCoordEventWeatherNames();
|
||||||
project->readSecretBaseIds();
|
project->readSecretBaseIds();
|
||||||
project->readBgEventFacingDirections();
|
project->readBgEventFacingDirections();
|
||||||
project->readMapsWithConnections();
|
|
||||||
project->readMetatileBehaviors();
|
project->readMetatileBehaviors();
|
||||||
project->readTilesetProperties();
|
project->readTilesetProperties();
|
||||||
}
|
}
|
||||||
|
@ -674,17 +672,21 @@ void MainWindow::sortMapList() {
|
||||||
}
|
}
|
||||||
case MapSortOrder::Layout:
|
case MapSortOrder::Layout:
|
||||||
{
|
{
|
||||||
|
QMap<QString, int> layoutIndices;
|
||||||
for (int i = 0; i < project->mapLayoutsTable.length(); i++) {
|
for (int i = 0; i < project->mapLayoutsTable.length(); i++) {
|
||||||
QString layoutName = project->mapLayoutsTable.value(i);
|
QString layoutId = project->mapLayoutsTable.value(i);
|
||||||
QStandardItem *layout = new QStandardItem;
|
MapLayout *layout = project->mapLayouts.value(layoutId);
|
||||||
layout->setText(layoutName);
|
QStandardItem *layoutItem = new QStandardItem;
|
||||||
layout->setIcon(folderIcon);
|
layoutItem->setText(layout->name);
|
||||||
layout->setEditable(false);
|
layoutItem->setIcon(folderIcon);
|
||||||
layout->setData(layoutName, Qt::UserRole);
|
layoutItem->setEditable(false);
|
||||||
layout->setData("map_layout", MapListUserRoles::TypeRole);
|
layoutItem->setData(layout->name, Qt::UserRole);
|
||||||
layout->setData(i, MapListUserRoles::GroupRole);
|
layoutItem->setData("map_layout", MapListUserRoles::TypeRole);
|
||||||
root->appendRow(layout);
|
layoutItem->setData(layout->id, MapListUserRoles::TypeRole2);
|
||||||
mapGroupItemsList->append(layout);
|
layoutItem->setData(i, MapListUserRoles::GroupRole);
|
||||||
|
root->appendRow(layoutItem);
|
||||||
|
mapGroupItemsList->append(layoutItem);
|
||||||
|
layoutIndices[layoutId] = i;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < project->groupNames->length(); i++) {
|
for (int i = 0; i < project->groupNames->length(); i++) {
|
||||||
QStringList names = project->groupedMapNames.value(i);
|
QStringList names = project->groupedMapNames.value(i);
|
||||||
|
@ -692,7 +694,7 @@ void MainWindow::sortMapList() {
|
||||||
QString map_name = names.value(j);
|
QString map_name = names.value(j);
|
||||||
QStandardItem *map = createMapItem(map_name, i, j);
|
QStandardItem *map = createMapItem(map_name, i, j);
|
||||||
QString layoutId = project->readMapLayoutId(map_name);
|
QString layoutId = project->readMapLayoutId(map_name);
|
||||||
QStandardItem *layoutItem = mapGroupItemsList->at(layoutId.toInt() - 1);
|
QStandardItem *layoutItem = mapGroupItemsList->at(layoutIndices.value(layoutId));
|
||||||
layoutItem->setIcon(mapFolderIcon);
|
layoutItem->setIcon(mapFolderIcon);
|
||||||
layoutItem->appendRow(map);
|
layoutItem->appendRow(map);
|
||||||
mapListIndexes.insert(map_name, map->index());
|
mapListIndexes.insert(map_name, map->index());
|
||||||
|
@ -746,10 +748,10 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
||||||
connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(onAddNewMapToAreaClick(QAction*)));
|
connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(onAddNewMapToAreaClick(QAction*)));
|
||||||
menu->exec(QCursor::pos());
|
menu->exec(QCursor::pos());
|
||||||
} else if (itemType == "map_layout") {
|
} else if (itemType == "map_layout") {
|
||||||
QString layoutName = selectedItem->data(Qt::UserRole).toString();
|
QString layoutId = selectedItem->data(MapListUserRoles::TypeRole2).toString();
|
||||||
QMenu* menu = new QMenu(this);
|
QMenu* menu = new QMenu(this);
|
||||||
QActionGroup* actions = new QActionGroup(menu);
|
QActionGroup* actions = new QActionGroup(menu);
|
||||||
actions->addAction(menu->addAction("Add New Map with Layout"))->setData(layoutName);
|
actions->addAction(menu->addAction("Add New Map with Layout"))->setData(layoutId);
|
||||||
connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(onAddNewMapToLayoutClick(QAction*)));
|
connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(onAddNewMapToLayoutClick(QAction*)));
|
||||||
menu->exec(QCursor::pos());
|
menu->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
@ -769,17 +771,17 @@ void MainWindow::onAddNewMapToAreaClick(QAction* triggeredAction)
|
||||||
|
|
||||||
void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction)
|
void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction)
|
||||||
{
|
{
|
||||||
QString layoutName = triggeredAction->data().toString();
|
QString layoutId = triggeredAction->data().toString();
|
||||||
openNewMapPopupWindow(MapSortOrder::Layout, layoutName);
|
openNewMapPopupWindow(MapSortOrder::Layout, layoutId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onNewMapCreated() {
|
void MainWindow::onNewMapCreated() {
|
||||||
QString newMapName = this->newmapprompt->map->name;
|
QString newMapName = this->newmapprompt->map->name;
|
||||||
int newMapGroup = this->newmapprompt->group;
|
int newMapGroup = this->newmapprompt->group;
|
||||||
Map *newMap_ = this->newmapprompt->map;
|
Map *newMap_ = this->newmapprompt->map;
|
||||||
bool updateLayout = this->newmapprompt->changeLayout;
|
bool existingLayout = this->newmapprompt->existingLayout;
|
||||||
|
|
||||||
Map *newMap = editor->project->addNewMapToGroup(newMapName, newMapGroup, newMap_, updateLayout);
|
Map *newMap = editor->project->addNewMapToGroup(newMapName, newMapGroup, newMap_, existingLayout);
|
||||||
|
|
||||||
logInfo(QString("Created a new map named %1.").arg(newMapName));
|
logInfo(QString("Created a new map named %1.").arg(newMapName));
|
||||||
|
|
||||||
|
|
1175
src/project.cpp
1175
src/project.cpp
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,7 @@ NewMapPopup::NewMapPopup(QWidget *parent, Project *project) :
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->project = project;
|
this->project = project;
|
||||||
this->changeLayout = false;
|
this->existingLayout = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewMapPopup::~NewMapPopup()
|
NewMapPopup::~NewMapPopup()
|
||||||
|
@ -24,7 +24,7 @@ NewMapPopup::~NewMapPopup()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewMapPopup::init(int type, int group, QString sec, QString layout) {
|
void NewMapPopup::init(int type, int group, QString sec, QString layoutId) {
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case MapSortOrder::Group:
|
case MapSortOrder::Group:
|
||||||
|
@ -34,15 +34,15 @@ void NewMapPopup::init(int type, int group, QString sec, QString layout) {
|
||||||
setDefaultValues(group, sec);
|
setDefaultValues(group, sec);
|
||||||
break;
|
break;
|
||||||
case MapSortOrder::Layout:
|
case MapSortOrder::Layout:
|
||||||
useLayout(layout);
|
useLayout(layoutId);
|
||||||
setDefaultValues(group, QString());
|
setDefaultValues(group, QString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewMapPopup::useLayout(QString mapName) {
|
void NewMapPopup::useLayout(QString layoutId) {
|
||||||
this->changeLayout = true;
|
this->existingLayout = true;
|
||||||
this->layoutName = mapName;
|
this->layoutId = layoutId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
|
void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
|
||||||
|
@ -55,11 +55,11 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
|
||||||
ui->comboBox_NewMap_Group->addItems(*project->groupNames);
|
ui->comboBox_NewMap_Group->addItems(*project->groupNames);
|
||||||
ui->comboBox_NewMap_Group->setCurrentText("gMapGroup" + QString::number(groupNum));
|
ui->comboBox_NewMap_Group->setCurrentText("gMapGroup" + QString::number(groupNum));
|
||||||
|
|
||||||
if (changeLayout) {
|
if (existingLayout) {
|
||||||
ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutName)->width.toInt(nullptr, 0));
|
ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutId)->width.toInt(nullptr, 0));
|
||||||
ui->spinBox_NewMap_Height->setValue(project->mapLayouts.value(layoutName)->height.toInt(nullptr, 0));
|
ui->spinBox_NewMap_Height->setValue(project->mapLayouts.value(layoutId)->height.toInt(nullptr, 0));
|
||||||
ui->comboBox_NewMap_Primary_Tileset->setCurrentText(project->mapLayouts.value(layoutName)->tileset_primary_label);
|
ui->comboBox_NewMap_Primary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_primary_label);
|
||||||
ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(project->mapLayouts.value(layoutName)->tileset_secondary_label);
|
ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_secondary_label);
|
||||||
ui->spinBox_NewMap_Width->setDisabled(true);
|
ui->spinBox_NewMap_Width->setDisabled(true);
|
||||||
ui->spinBox_NewMap_Height->setDisabled(true);
|
ui->spinBox_NewMap_Height->setDisabled(true);
|
||||||
ui->comboBox_NewMap_Primary_Tileset->setDisabled(true);
|
ui->comboBox_NewMap_Primary_Tileset->setDisabled(true);
|
||||||
|
@ -110,38 +110,35 @@ void NewMapPopup::on_lineEdit_NewMap_Name_textChanged(const QString &text) {
|
||||||
|
|
||||||
void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
||||||
Map *newMap = new Map;
|
Map *newMap = new Map;
|
||||||
MapLayout *layout = new MapLayout;
|
MapLayout *layout;
|
||||||
|
|
||||||
// If map name is not unique, use default value. Also use only valid characters.
|
// If map name is not unique, use default value. Also use only valid characters.
|
||||||
QString newMapName = this->ui->lineEdit_NewMap_Name->text().remove(QRegularExpression("[^a-zA-Z0-9_]+"));
|
QString newMapName = this->ui->lineEdit_NewMap_Name->text().remove(QRegularExpression("[^a-zA-Z0-9_]+"));
|
||||||
if (project->mapNames->contains(newMapName) || newMapName.isEmpty()) {
|
if (project->mapNames->contains(newMapName) || newMapName.isEmpty()) {
|
||||||
newMapName = project->getNewMapName();
|
newMapName = project->getNewMapName();
|
||||||
}
|
}
|
||||||
newMap->name = newMapName;
|
|
||||||
|
|
||||||
|
newMap->name = newMapName;
|
||||||
newMap->type = this->ui->comboBox_NewMap_Type->currentText();
|
newMap->type = this->ui->comboBox_NewMap_Type->currentText();
|
||||||
newMap->location = this->ui->comboBox_NewMap_Location->currentText();
|
newMap->location = this->ui->comboBox_NewMap_Location->currentText();
|
||||||
|
newMap->song = "MUS_DAN02";
|
||||||
|
newMap->requiresFlash = "0";
|
||||||
|
newMap->weather = "WEATHER_SUNNY";
|
||||||
|
newMap->show_location = "1";
|
||||||
|
newMap->battle_scene = "MAP_BATTLE_SCENE_NORMAL";
|
||||||
|
|
||||||
layout->width = QString::number(this->ui->spinBox_NewMap_Width->value());
|
if (this->existingLayout) {
|
||||||
layout->height = QString::number(this->ui->spinBox_NewMap_Height->value());
|
layout = this->project->mapLayouts.value(this->layoutId);
|
||||||
layout->tileset_primary_label = this->ui->comboBox_NewMap_Primary_Tileset->currentText();
|
|
||||||
layout->tileset_secondary_label = this->ui->comboBox_NewMap_Secondary_Tileset->currentText();
|
|
||||||
layout->border_label = QString("%1_MapBorder").arg(newMap->name);
|
|
||||||
layout->blockdata_label = QString("%1_MapBlockdata").arg(newMap->name);
|
|
||||||
|
|
||||||
if (changeLayout) {
|
|
||||||
layout->label = layoutName;
|
|
||||||
layout->name = MapLayout::getNameFromLabel(layout->label);
|
|
||||||
QString block_path = QString("%1/data/layout/%2/map.bin").arg(project->root).arg(MapLayout::getNameFromLabel(layoutName));
|
|
||||||
QString border_path = QString("%1/data/layout/%2/border.bin").arg(project->root).arg(MapLayout::getNameFromLabel(layoutName));
|
|
||||||
layout->blockdata = project->readBlockdata(block_path);
|
|
||||||
layout->border = project->readBlockdata(border_path);
|
|
||||||
newMap->needsLayoutDir = false;
|
|
||||||
} else {
|
} else {
|
||||||
layout->border_path = QString("data/layouts/%1/border.bin").arg(newMap->name);
|
layout = new MapLayout;
|
||||||
layout->blockdata_path = QString("data/layouts/%1/map.bin").arg(newMap->name);
|
layout->id = MapLayout::layoutConstantFromName(newMapName);
|
||||||
layout->label = QString("%1_Layout").arg(newMap->name);
|
layout->name = QString("%1_Layout").arg(newMap->name);
|
||||||
layout->name = MapLayout::getNameFromLabel(layout->label);
|
layout->width = QString::number(this->ui->spinBox_NewMap_Width->value());
|
||||||
|
layout->height = QString::number(this->ui->spinBox_NewMap_Height->value());
|
||||||
|
layout->tileset_primary_label = this->ui->comboBox_NewMap_Primary_Tileset->currentText();
|
||||||
|
layout->tileset_secondary_label = this->ui->comboBox_NewMap_Secondary_Tileset->currentText();
|
||||||
|
layout->border_path = QString("data/layouts/%1/border.bin").arg(newMapName);
|
||||||
|
layout->blockdata_path = QString("data/layouts/%1/map.bin").arg(newMapName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->ui->checkBox_NewMap_Flyable->isChecked()) {
|
if (this->ui->checkBox_NewMap_Flyable->isChecked()) {
|
||||||
|
@ -155,14 +152,10 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = this->ui->comboBox_NewMap_Group->currentText().remove("gMapGroup").toInt();
|
group = this->ui->comboBox_NewMap_Group->currentText().remove("gMapGroup").toInt();
|
||||||
|
|
||||||
newMap->layout = layout;
|
newMap->layout = layout;
|
||||||
newMap->layout_label = layout->label;
|
newMap->layoutId = layout->id;
|
||||||
newMap->group_num = QString::number(group);
|
newMap->group_num = QString::number(group);
|
||||||
|
|
||||||
map = newMap;
|
map = newMap;
|
||||||
|
|
||||||
emit applied();
|
emit applied();
|
||||||
|
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue