Add new map to group that was selected (UI functionality only)
This commit is contained in:
parent
794b814c47
commit
3fcad085c3
5 changed files with 80 additions and 24 deletions
|
@ -289,11 +289,12 @@ void MainWindow::populateMapList() {
|
||||||
QIcon folderIcon;
|
QIcon folderIcon;
|
||||||
folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
||||||
|
|
||||||
QIcon mapIcon;
|
mapIcon = new QIcon;
|
||||||
mapIcon.addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
mapIcon->addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
||||||
mapIcon.addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On);
|
mapIcon->addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On);
|
||||||
|
|
||||||
mapListModel = new QStandardItemModel;
|
mapListModel = new QStandardItemModel;
|
||||||
|
mapGroupsModel = new QList<QStandardItem*>;
|
||||||
|
|
||||||
QStandardItem *entry = new QStandardItem;
|
QStandardItem *entry = new QStandardItem;
|
||||||
entry->setText(project->getProjectTitle());
|
entry->setText(project->getProjectTitle());
|
||||||
|
@ -316,16 +317,13 @@ void MainWindow::populateMapList() {
|
||||||
group->setEditable(false);
|
group->setEditable(false);
|
||||||
group->setData(group_name, Qt::UserRole);
|
group->setData(group_name, Qt::UserRole);
|
||||||
group->setData("map_group", MapListUserRoles::TypeRole);
|
group->setData("map_group", MapListUserRoles::TypeRole);
|
||||||
|
group->setData(i, MapListUserRoles::GroupRole);
|
||||||
maps->appendRow(group);
|
maps->appendRow(group);
|
||||||
|
mapGroupsModel->append(group);
|
||||||
QStringList *names = project->groupedMapNames->value(i);
|
QStringList *names = project->groupedMapNames->value(i);
|
||||||
for (int j = 0; j < names->length(); j++) {
|
for (int j = 0; j < names->length(); j++) {
|
||||||
QString map_name = names->value(j);
|
QString map_name = names->value(j);
|
||||||
QStandardItem *map = new QStandardItem;
|
QStandardItem *map = createMapItem(map_name, i, j);
|
||||||
map->setText(QString("[%1.%2] ").arg(i).arg(j, 2, 10, QLatin1Char('0')) + map_name);
|
|
||||||
map->setIcon(mapIcon);
|
|
||||||
map->setEditable(false);
|
|
||||||
map->setData(map_name, Qt::UserRole);
|
|
||||||
map->setData("map_name", MapListUserRoles::TypeRole);
|
|
||||||
group->appendRow(map);
|
group->appendRow(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,6 +339,16 @@ void MainWindow::populateMapList() {
|
||||||
ui->mapList->repaint();
|
ui->mapList->repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStandardItem* MainWindow::createMapItem(QString mapName, int groupNum, int inGroupNum) {
|
||||||
|
QStandardItem *map = new QStandardItem;
|
||||||
|
map->setText(QString("[%1.%2] ").arg(groupNum).arg(inGroupNum, 2, 10, QLatin1Char('0')) + mapName);
|
||||||
|
map->setIcon(*mapIcon);
|
||||||
|
map->setEditable(false);
|
||||||
|
map->setData(mapName, Qt::UserRole);
|
||||||
|
map->setData("map_name", MapListUserRoles::TypeRole);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->mapList->indexAt(point);
|
QModelIndex index = ui->mapList->indexAt(point);
|
||||||
|
@ -357,18 +365,26 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
||||||
// Build custom context menu depending on which type of item was selected (map group, map name, etc.)
|
// Build custom context menu depending on which type of item was selected (map group, map name, etc.)
|
||||||
if (itemType == "map_group") {
|
if (itemType == "map_group") {
|
||||||
QString groupName = selectedItem->data(Qt::UserRole).toString();
|
QString groupName = selectedItem->data(Qt::UserRole).toString();
|
||||||
|
int groupNum = selectedItem->data(MapListUserRoles::GroupRole).toInt();
|
||||||
QMenu* menu = new QMenu();
|
QMenu* menu = new QMenu();
|
||||||
QActionGroup* actions = new QActionGroup(menu);
|
QActionGroup* actions = new QActionGroup(menu);
|
||||||
actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupName);
|
actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupNum);
|
||||||
connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(addNewMapToGroup(QAction*)));
|
connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(onAddNewMapToGroupClick(QAction*)));
|
||||||
menu->exec(QCursor::pos());
|
menu->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addNewMapToGroup(QAction* triggeredAction)
|
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
|
||||||
{
|
{
|
||||||
QString groupName = triggeredAction->data().toString();
|
int groupNum = triggeredAction->data().toInt();
|
||||||
qDebug() << "Adding new map " << groupName;
|
QStandardItem* groupItem = mapGroupsModel->at(groupNum);
|
||||||
|
|
||||||
|
QString newMapName = editor->project->getNewMapName();
|
||||||
|
editor->project->addNewMapToGroup(newMapName, groupNum);
|
||||||
|
|
||||||
|
int numMapsInGroup = groupItem->rowCount();
|
||||||
|
QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);
|
||||||
|
groupItem->appendRow(newMapItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||||
|
|
|
@ -67,18 +67,21 @@ private slots:
|
||||||
void on_toolButton_Dropper_clicked();
|
void on_toolButton_Dropper_clicked();
|
||||||
|
|
||||||
void onOpenMapListContextMenu(const QPoint &point);
|
void onOpenMapListContextMenu(const QPoint &point);
|
||||||
void addNewMapToGroup(QAction* triggeredAction);
|
void onAddNewMapToGroupClick(QAction* triggeredAction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QStandardItemModel *mapListModel;
|
QStandardItemModel *mapListModel;
|
||||||
|
QList<QStandardItem*> *mapGroupsModel;
|
||||||
Editor *editor = NULL;
|
Editor *editor = NULL;
|
||||||
|
QIcon* mapIcon;
|
||||||
void setMap(QString);
|
void setMap(QString);
|
||||||
void populateMapList();
|
void populateMapList();
|
||||||
QString getExistingDirectory(QString);
|
QString getExistingDirectory(QString);
|
||||||
void openProject(QString dir);
|
void openProject(QString dir);
|
||||||
QString getDefaultMap();
|
QString getDefaultMap();
|
||||||
void setRecentMap(QString map_name);
|
void setRecentMap(QString map_name);
|
||||||
|
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
||||||
|
|
||||||
void markAllEdited(QAbstractItemModel *model);
|
void markAllEdited(QAbstractItemModel *model);
|
||||||
void markEdited(QModelIndex index);
|
void markEdited(QModelIndex index);
|
||||||
|
@ -89,6 +92,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MapListUserRoles {
|
enum MapListUserRoles {
|
||||||
|
GroupRole = Qt::UserRole + 1, // Used to hold the map group number.
|
||||||
TypeRole = Qt::UserRole + 10, // Used to differentiate between the different layers of the map list tree view.
|
TypeRole = Qt::UserRole + 10, // Used to differentiate between the different layers of the map list tree view.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
10
map.h
10
map.h
|
@ -76,6 +76,7 @@ public:
|
||||||
public:
|
public:
|
||||||
QString name;
|
QString name;
|
||||||
QString constantName;
|
QString constantName;
|
||||||
|
QString group_num;
|
||||||
QString attributes_label;
|
QString attributes_label;
|
||||||
QString events_label;
|
QString events_label;
|
||||||
QString scripts_label;
|
QString scripts_label;
|
||||||
|
@ -190,4 +191,13 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MapGroup : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QString name;
|
||||||
|
int group_num;
|
||||||
|
QList<Map*> maps;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // MAP_H
|
#endif // MAP_H
|
||||||
|
|
36
project.cpp
36
project.cpp
|
@ -8,15 +8,19 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QStandardItem>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
Project::Project()
|
Project::Project()
|
||||||
{
|
{
|
||||||
groupNames = new QStringList;
|
groupNames = new QStringList;
|
||||||
|
map_groups = new QMap<QString, int>;
|
||||||
groupedMapNames = new QList<QStringList*>;
|
groupedMapNames = new QList<QStringList*>;
|
||||||
mapNames = new QStringList;
|
mapNames = new QStringList;
|
||||||
map_cache = new QMap<QString, Map*>;
|
map_cache = new QMap<QString, Map*>;
|
||||||
|
mapConstantsToMapNames = new QMap<QString, QString>;
|
||||||
|
mapNamesToMapConstants = new QMap<QString, QString>;
|
||||||
tileset_cache = new QMap<QString, Tileset*>;
|
tileset_cache = new QMap<QString, Tileset*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +71,8 @@ void Project::loadMapConnections(Map *map) {
|
||||||
connection->direction = command.value(1);
|
connection->direction = command.value(1);
|
||||||
connection->offset = command.value(2);
|
connection->offset = command.value(2);
|
||||||
QString mapConstant = command.value(3);
|
QString mapConstant = command.value(3);
|
||||||
if (mapConstantsToMapNames.contains(mapConstant)) {
|
if (mapConstantsToMapNames->contains(mapConstant)) {
|
||||||
connection->map_name = mapConstantsToMapNames[mapConstant];
|
connection->map_name = mapConstantsToMapNames->value(mapConstant);
|
||||||
map->connections.append(connection);
|
map->connections.append(connection);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << QString("Failed to find connected map for map constant '%1'").arg(mapConstant);
|
qDebug() << QString("Failed to find connected map for map constant '%1'").arg(mapConstant);
|
||||||
|
@ -521,11 +525,12 @@ void Project::readMapGroups() {
|
||||||
QStringList *list = groupedMaps->value(group);
|
QStringList *list = groupedMaps->value(group);
|
||||||
list->append(mapName);
|
list->append(mapName);
|
||||||
maps->append(mapName);
|
maps->append(mapName);
|
||||||
|
map_groups->insert(mapName, group);
|
||||||
|
|
||||||
// Build the mapping and reverse mapping between map constants and map names.
|
// Build the mapping and reverse mapping between map constants and map names.
|
||||||
QString mapConstant = Map::mapConstantFromName(mapName);
|
QString mapConstant = Map::mapConstantFromName(mapName);
|
||||||
mapConstantsToMapNames.insert(mapConstant, mapName);
|
mapConstantsToMapNames->insert(mapConstant, mapName);
|
||||||
mapNamesToMapConstants.insert(mapName, mapConstant);
|
mapNamesToMapConstants->insert(mapName, mapConstant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -536,6 +541,23 @@ void Project::readMapGroups() {
|
||||||
mapNames = maps;
|
mapNames = maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
|
mapNames->append(mapName);
|
||||||
|
map_groups->insert(mapName, groupNum);
|
||||||
|
groupedMapNames->value(groupNum)->append(mapName);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Project::getNewMapName() {
|
||||||
|
// Ensure default name doesn't already exist.
|
||||||
|
int i = 0;
|
||||||
|
QString newMapName;
|
||||||
|
do {
|
||||||
|
newMapName = QString("NewMap%1").arg(++i);
|
||||||
|
} while (mapNames->contains(newMapName));
|
||||||
|
|
||||||
|
return newMapName;
|
||||||
|
}
|
||||||
|
|
||||||
QList<QStringList>* Project::parse(QString text) {
|
QList<QStringList>* Project::parse(QString text) {
|
||||||
Asm *parser = new Asm;
|
Asm *parser = new Asm;
|
||||||
return parser->parse(text);
|
return parser->parse(text);
|
||||||
|
@ -739,7 +761,7 @@ void Project::saveMapEvents(Map *map) {
|
||||||
text += QString(", %1").arg(warp->get("y"));
|
text += QString(", %1").arg(warp->get("y"));
|
||||||
text += QString(", %1").arg(warp->get("elevation"));
|
text += QString(", %1").arg(warp->get("elevation"));
|
||||||
text += QString(", %1").arg(warp->get("destination_warp"));
|
text += QString(", %1").arg(warp->get("destination_warp"));
|
||||||
text += QString(", %1").arg(mapNamesToMapConstants[warp->get("destination_map_name")]);
|
text += QString(", %1").arg(mapNamesToMapConstants->value(warp->get("destination_map_name")));
|
||||||
text += "\n";
|
text += "\n";
|
||||||
}
|
}
|
||||||
text += "\n";
|
text += "\n";
|
||||||
|
@ -882,8 +904,8 @@ void Project::readMapEvents(Map *map) {
|
||||||
|
|
||||||
// Ensure the warp destination map constant is valid before adding it to the warps.
|
// Ensure the warp destination map constant is valid before adding it to the warps.
|
||||||
QString mapConstant = command.value(i++);
|
QString mapConstant = command.value(i++);
|
||||||
if (mapConstantsToMapNames.contains(mapConstant)) {
|
if (mapConstantsToMapNames->contains(mapConstant)) {
|
||||||
warp->put("destination_map_name", mapConstantsToMapNames[mapConstant]);
|
warp->put("destination_map_name", mapConstantsToMapNames->value(mapConstant));
|
||||||
warp->put("event_type", "warp");
|
warp->put("event_type", "warp");
|
||||||
map->events["warp"].append(warp);
|
map->events["warp"].append(warp);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QStandardItem>
|
||||||
|
|
||||||
class Project
|
class Project
|
||||||
{
|
{
|
||||||
|
@ -13,10 +14,11 @@ public:
|
||||||
Project();
|
Project();
|
||||||
QString root;
|
QString root;
|
||||||
QStringList *groupNames = NULL;
|
QStringList *groupNames = NULL;
|
||||||
|
QMap<QString, int> *map_groups;
|
||||||
QList<QStringList*> *groupedMapNames = NULL;
|
QList<QStringList*> *groupedMapNames = NULL;
|
||||||
QStringList *mapNames = NULL;
|
QStringList *mapNames = NULL;
|
||||||
QMap<QString, QString> mapConstantsToMapNames;
|
QMap<QString, QString> *mapConstantsToMapNames;
|
||||||
QMap<QString, QString> mapNamesToMapConstants;
|
QMap<QString, QString> *mapNamesToMapConstants;
|
||||||
|
|
||||||
QMap<QString, Map*> *map_cache;
|
QMap<QString, Map*> *map_cache;
|
||||||
Map* loadMap(QString);
|
Map* loadMap(QString);
|
||||||
|
@ -33,6 +35,8 @@ public:
|
||||||
void saveTextFile(QString path, QString text);
|
void saveTextFile(QString path, QString text);
|
||||||
|
|
||||||
void readMapGroups();
|
void readMapGroups();
|
||||||
|
void addNewMapToGroup(QString mapName, int groupNum);
|
||||||
|
QString getNewMapName();
|
||||||
QString getProjectTitle();
|
QString getProjectTitle();
|
||||||
|
|
||||||
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
|
||||||
|
|
Loading…
Reference in a new issue