Merge pull request #54 from huderlem/tilesets

Allow changing map tilesets
This commit is contained in:
yenatch 2018-07-08 19:05:53 -04:00 committed by GitHub
commit 8d2958c952
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 373 additions and 119 deletions

View file

@ -306,7 +306,7 @@ void Editor::onBorderMetatilesChanged() {
} }
void Editor::setConnectionsVisibility(bool visible) { void Editor::setConnectionsVisibility(bool visible) {
for (QGraphicsPixmapItem* item : map->connection_items) { for (QGraphicsPixmapItem* item : connection_items) {
item->setVisible(visible); item->setVisible(visible);
item->setActive(visible); item->setActive(visible);
} }
@ -348,8 +348,13 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
} }
void Editor::displayMap() { void Editor::displayMap() {
scene = new QGraphicsScene; if (!scene)
scene = new QGraphicsScene;
if (map_item && scene) {
scene->removeItem(map_item);
delete map_item;
}
map_item = new MapPixmapItem(map); map_item = new MapPixmapItem(map);
connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)), connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*))); this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
@ -357,6 +362,10 @@ void Editor::displayMap() {
map_item->draw(true); map_item->draw(true);
scene->addItem(map_item); scene->addItem(map_item);
if (collision_item && scene) {
scene->removeItem(collision_item);
delete collision_item;
}
collision_item = new CollisionPixmapItem(map); collision_item = new CollisionPixmapItem(map);
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)), connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*))); this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
@ -364,19 +373,6 @@ void Editor::displayMap() {
collision_item->draw(true); collision_item->draw(true);
scene->addItem(collision_item); scene->addItem(collision_item);
events_group = new EventGroup;
scene->addItem(events_group);
if (map_item) {
map_item->setVisible(false);
}
if (collision_item) {
collision_item->setVisible(false);
}
if (events_group) {
events_group->setVisible(false);
}
int tw = 16; int tw = 16;
int th = 16; int th = 16;
scene->setSceneRect( scene->setSceneRect(
@ -394,9 +390,24 @@ void Editor::displayMap() {
displayMapConnections(); displayMapConnections();
displayMapBorder(); displayMapBorder();
displayMapGrid(); displayMapGrid();
if (map_item) {
map_item->setVisible(false);
}
if (collision_item) {
collision_item->setVisible(false);
}
if (events_group) {
events_group->setVisible(false);
}
} }
void Editor::displayMetatiles() { void Editor::displayMetatiles() {
if (metatiles_item && metatiles_item->scene()) {
metatiles_item->scene()->removeItem(metatiles_item);
delete metatiles_item;
}
scene_metatiles = new QGraphicsScene; scene_metatiles = new QGraphicsScene;
metatiles_item = new MetatilesPixmapItem(map); metatiles_item = new MetatilesPixmapItem(map);
metatiles_item->draw(); metatiles_item->draw();
@ -404,6 +415,11 @@ void Editor::displayMetatiles() {
} }
void Editor::displayBorderMetatiles() { void Editor::displayBorderMetatiles() {
if (selected_border_metatiles_item && selected_border_metatiles_item->scene()) {
selected_border_metatiles_item->scene()->removeItem(selected_border_metatiles_item);
delete selected_border_metatiles_item;
}
scene_selected_border_metatiles = new QGraphicsScene; scene_selected_border_metatiles = new QGraphicsScene;
selected_border_metatiles_item = new BorderMetatilesPixmapItem(map); selected_border_metatiles_item = new BorderMetatilesPixmapItem(map);
selected_border_metatiles_item->draw(); selected_border_metatiles_item->draw();
@ -413,6 +429,11 @@ void Editor::displayBorderMetatiles() {
} }
void Editor::displayCollisionMetatiles() { void Editor::displayCollisionMetatiles() {
if (collision_metatiles_item && collision_metatiles_item->scene()) {
collision_metatiles_item->scene()->removeItem(collision_metatiles_item);
delete collision_metatiles_item;
}
scene_collision_metatiles = new QGraphicsScene; scene_collision_metatiles = new QGraphicsScene;
collision_metatiles_item = new CollisionMetatilesPixmapItem(map); collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
collision_metatiles_item->draw(); collision_metatiles_item->draw();
@ -420,6 +441,11 @@ void Editor::displayCollisionMetatiles() {
} }
void Editor::displayElevationMetatiles() { void Editor::displayElevationMetatiles() {
if (elevation_metatiles_item && elevation_metatiles_item->scene()) {
elevation_metatiles_item->scene()->removeItem(elevation_metatiles_item);
delete elevation_metatiles_item;
}
scene_elevation_metatiles = new QGraphicsScene; scene_elevation_metatiles = new QGraphicsScene;
elevation_metatiles_item = new ElevationMetatilesPixmapItem(map); elevation_metatiles_item = new ElevationMetatilesPixmapItem(map);
elevation_metatiles_item->draw(); elevation_metatiles_item->draw();
@ -427,10 +453,22 @@ void Editor::displayElevationMetatiles() {
} }
void Editor::displayMapEvents() { void Editor::displayMapEvents() {
for (QGraphicsItem *child : events_group->childItems()) { if (events_group) {
events_group->removeFromGroup(child); for (QGraphicsItem *child : events_group->childItems()) {
events_group->removeFromGroup(child);
delete child;
}
if (events_group->scene()) {
events_group->scene()->removeItem(events_group);
}
delete events_group;
} }
events_group = new EventGroup;
scene->addItem(events_group);
QList<Event *> events = map->getAllEvents(); QList<Event *> events = map->getAllEvents();
project->loadEventPixmaps(events); project->loadEventPixmaps(events);
for (Event *event : events) { for (Event *event : events) {
@ -450,12 +488,18 @@ DraggablePixmapItem *Editor::addMapEvent(Event *event) {
} }
void Editor::displayMapConnections() { void Editor::displayMapConnections() {
for (QGraphicsPixmapItem* item : map->connection_items) { for (QGraphicsPixmapItem* item : connection_items) {
if (item->scene()) {
item->scene()->removeItem(item);
}
delete item; delete item;
} }
map->connection_items.clear(); connection_items.clear();
for (ConnectionPixmapItem* item : connection_edit_items) { for (ConnectionPixmapItem* item : connection_edit_items) {
if (item->scene()) {
item->scene()->removeItem(item);
}
delete item; delete item;
} }
selected_connection_item = NULL; selected_connection_item = NULL;
@ -497,7 +541,7 @@ void Editor::createConnectionItem(Connection* connection, bool hide) {
item->setX(x); item->setX(x);
item->setY(y); item->setY(y);
scene->addItem(item); scene->addItem(item);
map->connection_items.append(item); connection_items.append(item);
item->setVisible(!hide); item->setVisible(!hide);
ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight()); ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight());
@ -512,6 +556,14 @@ void Editor::createConnectionItem(Connection* connection, bool hide) {
} }
void Editor::displayMapBorder() { void Editor::displayMapBorder() {
for (QGraphicsPixmapItem* item : borderItems) {
if (item->scene()) {
item->scene()->removeItem(item);
}
delete item;
}
borderItems.clear();
QPixmap pixmap = map->renderBorder(); QPixmap pixmap = map->renderBorder();
for (int y = -6; y < map->getHeight() + 6; y += 2) for (int y = -6; y < map->getHeight() + 6; y += 2)
for (int x = -6; x < map->getWidth() + 6; x += 2) { for (int x = -6; x < map->getWidth() + 6; x += 2) {
@ -525,18 +577,29 @@ void Editor::displayMapBorder() {
} }
void Editor::displayMapGrid() { void Editor::displayMapGrid() {
for (QGraphicsLineItem* item : gridLines) {
if (item && item->scene()) {
item->scene()->removeItem(item);
}
delete item;
}
gridLines.clear();
ui->checkBox_ToggleGrid->disconnect();
int pixelWidth = map->getWidth() * 16; int pixelWidth = map->getWidth() * 16;
int pixelHeight = map->getHeight() * 16; int pixelHeight = map->getHeight() * 16;
for (int i = 0; i <= map->getWidth(); i++) { for (int i = 0; i <= map->getWidth(); i++) {
int x = i * 16; int x = i * 16;
QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight); QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
line->setVisible(ui->checkBox_ToggleGrid->isChecked()); line->setVisible(ui->checkBox_ToggleGrid->isChecked());
gridLines.append(line);
connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);}); connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
} }
for (int j = 0; j <= map->getHeight(); j++) { for (int j = 0; j <= map->getHeight(); j++) {
int y = j * 16; int y = j * 16;
QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y); QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
line->setVisible(ui->checkBox_ToggleGrid->isChecked()); line->setVisible(ui->checkBox_ToggleGrid->isChecked());
gridLines.append(line);
connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);}); connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
} }
} }
@ -679,8 +742,11 @@ void Editor::removeCurrentConnection() {
connection_edit_items.removeOne(selected_connection_item); connection_edit_items.removeOne(selected_connection_item);
removeMirroredConnection(selected_connection_item->connection); removeMirroredConnection(selected_connection_item->connection);
scene->removeItem(selected_connection_item); if (selected_connection_item && selected_connection_item->scene()) {
delete selected_connection_item; selected_connection_item->scene()->removeItem(selected_connection_item);
delete selected_connection_item;
}
selected_connection_item = NULL; selected_connection_item = NULL;
setConnectionEditControlsEnabled(false); setConnectionEditControlsEnabled(false);
ui->spinBox_ConnectionOffset->setValue(0); ui->spinBox_ConnectionOffset->setValue(0);
@ -737,6 +803,20 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
ui->label_NumConnections->setText(QString::number(map->connections.length())); ui->label_NumConnections->setText(QString::number(map->connections.length()));
} }
void Editor::updatePrimaryTileset(QString tilesetLabel)
{
map->layout->tileset_primary_label = tilesetLabel;
map->layout->tileset_primary = project->getTileset(tilesetLabel);
emit tilesetChanged(map->name);
}
void Editor::updateSecondaryTileset(QString tilesetLabel)
{
map->layout->tileset_secondary_label = tilesetLabel;
map->layout->tileset_secondary = project->getTileset(tilesetLabel);
emit tilesetChanged(map->name);
}
void MetatilesPixmapItem::paintTileChanged(Map *map) { void MetatilesPixmapItem::paintTileChanged(Map *map) {
draw(); draw();
} }

View file

@ -59,6 +59,8 @@ public:
void updateDiveMap(QString mapName); void updateDiveMap(QString mapName);
void updateEmergeMap(QString mapName); void updateEmergeMap(QString mapName);
void setSelectedConnectionFromMap(QString mapName); void setSelectedConnectionFromMap(QString mapName);
void updatePrimaryTileset(QString tilesetLabel);
void updateSecondaryTileset(QString tilesetLabel);
DraggablePixmapItem *addMapEvent(Event *event); DraggablePixmapItem *addMapEvent(Event *event);
void selectMapEvent(DraggablePixmapItem *object); void selectMapEvent(DraggablePixmapItem *object);
@ -74,10 +76,12 @@ public:
QGraphicsPixmapItem *current_view = NULL; QGraphicsPixmapItem *current_view = NULL;
MapPixmapItem *map_item = NULL; MapPixmapItem *map_item = NULL;
ConnectionPixmapItem* selected_connection_item = NULL; ConnectionPixmapItem* selected_connection_item = NULL;
QList<QGraphicsPixmapItem*> connection_items;
QList<ConnectionPixmapItem*> connection_edit_items; QList<ConnectionPixmapItem*> connection_edit_items;
CollisionPixmapItem *collision_item = NULL; CollisionPixmapItem *collision_item = NULL;
QGraphicsItemGroup *events_group = NULL; QGraphicsItemGroup *events_group = NULL;
QList<QGraphicsPixmapItem*> borderItems; QList<QGraphicsPixmapItem*> borderItems;
QList<QGraphicsLineItem*> gridLines;
QGraphicsScene *scene_metatiles = NULL; QGraphicsScene *scene_metatiles = NULL;
QGraphicsScene *scene_selected_border_metatiles = NULL; QGraphicsScene *scene_selected_border_metatiles = NULL;
@ -133,6 +137,7 @@ signals:
void objectsChanged(); void objectsChanged();
void selectedObjectsChanged(); void selectedObjectsChanged();
void loadMapRequested(QString, QString); void loadMapRequested(QString, QString);
void tilesetChanged(QString);
}; };

View file

@ -34,6 +34,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects())); connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects())); connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString))); connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
on_toolButton_Paint_clicked(); on_toolButton_Paint_clicked();
@ -206,6 +207,8 @@ void MainWindow::displayMapProperties() {
ui->comboBox_Weather->clear(); ui->comboBox_Weather->clear();
ui->comboBox_Type->clear(); ui->comboBox_Type->clear();
ui->comboBox_BattleScene->clear(); ui->comboBox_BattleScene->clear();
ui->comboBox_PrimaryTileset->clear();
ui->comboBox_SecondaryTileset->clear();
ui->checkBox_ShowLocation->setChecked(false); ui->checkBox_ShowLocation->setChecked(false);
if (!editor || !editor->map || !editor->project) { if (!editor || !editor->map || !editor->project) {
ui->frame_3->setEnabled(false); ui->frame_3->setEnabled(false);
@ -222,6 +225,12 @@ void MainWindow::displayMapProperties() {
ui->comboBox_Location->addItems(project->getLocations()); ui->comboBox_Location->addItems(project->getLocations());
ui->comboBox_Location->setCurrentText(map->location); ui->comboBox_Location->setCurrentText(map->location);
QMap<QString, QStringList> tilesets = project->getTilesets();
ui->comboBox_PrimaryTileset->addItems(tilesets.value("primary"));
ui->comboBox_PrimaryTileset->setCurrentText(map->layout->tileset_primary_label);
ui->comboBox_SecondaryTileset->addItems(tilesets.value("secondary"));
ui->comboBox_SecondaryTileset->setCurrentText(map->layout->tileset_secondary_label);
ui->comboBox_Visibility->addItems(project->getVisibilities()); ui->comboBox_Visibility->addItems(project->getVisibilities());
ui->comboBox_Visibility->setCurrentText(map->visibility); ui->comboBox_Visibility->setCurrentText(map->visibility);
@ -412,6 +421,11 @@ void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
setMap(newMapName); setMap(newMapName);
} }
void MainWindow::onTilesetChanged(QString mapName)
{
setMap(mapName);
}
void MainWindow::on_mapList_activated(const QModelIndex &index) void MainWindow::on_mapList_activated(const QModelIndex &index)
{ {
QVariant data = index.data(Qt::UserRole); QVariant data = index.data(Qt::UserRole);
@ -814,3 +828,13 @@ void MainWindow::on_comboBox_EmergeMap_currentTextChanged(const QString &mapName
{ {
editor->updateEmergeMap(mapName); editor->updateEmergeMap(mapName);
} }
void MainWindow::on_comboBox_PrimaryTileset_activated(const QString &tilesetLabel)
{
editor->updatePrimaryTileset(tilesetLabel);
}
void MainWindow::on_comboBox_SecondaryTileset_activated(const QString &tilesetLabel)
{
editor->updateSecondaryTileset(tilesetLabel);
}

View file

@ -71,6 +71,7 @@ private slots:
void onOpenMapListContextMenu(const QPoint &point); void onOpenMapListContextMenu(const QPoint &point);
void onAddNewMapToGroupClick(QAction* triggeredAction); void onAddNewMapToGroupClick(QAction* triggeredAction);
void onTilesetChanged(QString);
void on_action_Export_Map_Image_triggered(); void on_action_Export_Map_Image_triggered();
@ -88,6 +89,10 @@ private slots:
void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName); void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName);
void on_comboBox_PrimaryTileset_activated(const QString &arg1);
void on_comboBox_SecondaryTileset_activated(const QString &arg1);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QStandardItemModel *mapListModel; QStandardItemModel *mapListModel;

View file

@ -290,7 +290,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>475</width> <width>436</width>
<height>621</height> <height>621</height>
</rect> </rect>
</property> </property>
@ -451,9 +451,146 @@
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QFrame" name="frame_Tilesets">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_PrimaryTileset">
<property name="text">
<string>Primary Tileset</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_PrimaryTileset">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_SecondaryTileset">
<property name="text">
<string>Secondary Tileset</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_SecondaryTileset">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QFrame" name="frame_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Border</string>
</property>
</widget>
</item>
<item>
<widget class="QGraphicsView" name="graphicsView_BorderMetatile">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>48</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QScrollArea" name="scrollArea_2"> <widget class="QScrollArea" name="scrollArea_2">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -470,6 +607,9 @@
<property name="widgetResizable"> <property name="widgetResizable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2"> <widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@ -479,7 +619,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>358</width> <width>358</width>
<height>612</height> <height>497</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -488,7 +628,7 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QGridLayout" name="gridLayout_5" rowstretch="0,0" columnstretch="0"> <layout class="QGridLayout" name="gridLayout_5">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetDefaultConstraint</enum>
</property> </property>
@ -504,97 +644,26 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="horizontalSpacing"> <item row="1" column="1">
<number>0</number> <spacer name="verticalSpacer_5">
</property> <property name="orientation">
<property name="verticalSpacing"> <enum>Qt::Vertical</enum>
<number>8</number>
</property>
<item row="0" column="0">
<widget class="QFrame" name="frame_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="frameShape"> <property name="sizeHint" stdset="0">
<enum>QFrame::NoFrame</enum> <size>
<width>20</width>
<height>40</height>
</size>
</property> </property>
<property name="frameShadow"> </spacer>
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label_16">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Border</string>
</property>
</widget>
</item>
<item>
<widget class="QGraphicsView" name="graphicsView_BorderMetatile">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>48</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item> </item>
<item row="1" column="0"> <item row="0" column="1">
<widget class="QGraphicsView" name="graphicsView_Metatiles"> <widget class="QGraphicsView" name="graphicsView_Metatiles">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -610,6 +679,32 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_15">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

1
map.h
View file

@ -193,7 +193,6 @@ public:
QMap<QString, QList<Event*>> events; QMap<QString, QList<Event*>> events;
QList<Connection*> connections; QList<Connection*> connections;
QList<QGraphicsPixmapItem*> connection_items;
QPixmap renderConnection(Connection); QPixmap renderConnection(Connection);
QPixmap renderBorder(); QPixmap renderBorder();

View file

@ -64,7 +64,6 @@ void Project::loadMapConnections(Map *map) {
} }
map->connections.clear(); map->connections.clear();
map->connection_items.clear();
if (!map->connections_label.isNull()) { if (!map->connections_label.isNull()) {
QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name); QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name);
QString text = readTextFile(path); QString text = readTextFile(path);
@ -354,7 +353,7 @@ void Project::readMapLayout(Map* map) {
map->layout = mapLayouts[map->layout_label]; map->layout = mapLayouts[map->layout_label];
} }
getTilesets(map); loadMapTilesets(map);
loadBlockdata(map); loadBlockdata(map);
loadMapBorder(map); loadMapBorder(map);
} }
@ -494,7 +493,7 @@ void Project::saveMapConstantsHeader() {
saveTextFile(root + "/include/constants/maps.h", text); saveTextFile(root + "/include/constants/maps.h", text);
} }
void Project::getTilesets(Map* map) { void Project::loadMapTilesets(Map* map) {
if (map->layout->has_unsaved_changes) { if (map->layout->has_unsaved_changes) {
return; return;
} }
@ -955,7 +954,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
mapNamesToMapConstants->insert(map->name, map->constantName); mapNamesToMapConstants->insert(map->name, map->constantName);
setNewMapHeader(map, mapLayoutsTable.size() + 1); setNewMapHeader(map, mapLayoutsTable.size() + 1);
setNewMapLayout(map); setNewMapLayout(map);
getTilesets(map); loadMapTilesets(map);
setNewMapBlockdata(map); setNewMapBlockdata(map);
setNewMapBorder(map); setNewMapBorder(map);
setNewMapEvents(map); setNewMapEvents(map);
@ -1001,6 +1000,47 @@ QStringList Project::getVisibilities() {
return names; return names;
} }
QMap<QString, QStringList> Project::getTilesets() {
QMap<QString, QStringList> allTilesets;
QStringList primaryTilesets;
QStringList secondaryTilesets;
allTilesets.insert("primary", primaryTilesets);
allTilesets.insert("secondary", secondaryTilesets);
QString headers_text = readTextFile(root + "/data/tilesets/headers.inc");
QList<QStringList>* commands = parseAsm(headers_text);
int i = 0;
while (i < commands->length()) {
if (commands->at(i).length() != 2)
continue;
if (commands->at(i).at(0) == ".label") {
QString tilesetLabel = commands->at(i).at(1);
// Advance to command specifying whether or not it is a secondary tileset
i += 2;
if (commands->at(i).at(0) != ".byte") {
qDebug() << "Unexpected command found for secondary tileset flag. Expected '.byte', but found: " << commands->at(i).at(0);
continue;
}
QString secondaryTilesetValue = commands->at(i).at(1);
if (secondaryTilesetValue != "TRUE" && secondaryTilesetValue != "FALSE" && secondaryTilesetValue != "0" && secondaryTilesetValue != "1") {
qDebug() << "Unexpected secondary tileset flag found. Expected \"TRUE\", \"FALSE\", \"0\", or \"1\", but found: " << secondaryTilesetValue;
continue;
}
bool isSecondaryTileset = (secondaryTilesetValue == "TRUE" || secondaryTilesetValue == "1");
if (isSecondaryTileset)
allTilesets["secondary"].append(tilesetLabel);
else
allTilesets["primary"].append(tilesetLabel);
}
i++;
}
return allTilesets;
}
QStringList Project::getWeathers() { QStringList Project::getWeathers() {
// TODO // TODO
QStringList names; QStringList names;

View file

@ -57,7 +57,7 @@ public:
QStringList* readLayoutValues(QString layoutName); QStringList* readLayoutValues(QString layoutName);
void readMapLayout(Map*); void readMapLayout(Map*);
void readMapsWithConnections(); void readMapsWithConnections();
void getTilesets(Map*); void loadMapTilesets(Map*);
void loadTilesetAssets(Tileset*); void loadTilesetAssets(Tileset*);
void saveBlockdata(Map*); void saveBlockdata(Map*);
@ -74,6 +74,7 @@ public:
QStringList getSongNames(); QStringList getSongNames();
QStringList getLocations(); QStringList getLocations();
QStringList getVisibilities(); QStringList getVisibilities();
QMap<QString, QStringList> getTilesets();
QStringList getWeathers(); QStringList getWeathers();
QStringList getMapTypes(); QStringList getMapTypes();
QStringList getBattleScenes(); QStringList getBattleScenes();

View file

@ -2,6 +2,7 @@
#include <QPainter> #include <QPainter>
#include <QImage> #include <QImage>
#include <QDebug>
Tileset::Tileset() Tileset::Tileset()
{ {
@ -43,9 +44,13 @@ QImage Metatile::getMetatileImage(int tile, Tileset *primaryTileset, Tileset *se
} }
// Colorize the metatile tiles with its palette. // Colorize the metatile tiles with its palette.
QList<QRgb> palette = palettes.value(tile_.palette); if (tile_.palette < palettes.length()) {
for (int j = 0; j < palette.length(); j++) { QList<QRgb> palette = palettes.value(tile_.palette);
tile_image.setColor(j, palette.value(j)); for (int j = 0; j < palette.length(); j++) {
tile_image.setColor(j, palette.value(j));
}
} else {
qDebug() << "Tile is referring to invalid palette number: " << tile_.palette;
} }
// The top layer of the metatile has its last color displayed at transparent. // The top layer of the metatile has its last color displayed at transparent.
@ -105,7 +110,7 @@ QList<QList<QRgb>> Metatile::getBlockPalettes(Tileset *primaryTileset, Tileset *
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
palettes.append(primaryTileset->palettes->at(i)); palettes.append(primaryTileset->palettes->at(i));
} }
for (int i = 6; i < secondaryTileset->palettes->length(); i++) { for (int i = 6; i < 12; i++) {
palettes.append(secondaryTileset->palettes->at(i)); palettes.append(secondaryTileset->palettes->at(i));
} }
return palettes; return palettes;