Skip to content

Commit 64a9e2c

Browse files
Add dividing line for tilesets in Tileset Editor
1 parent 883087d commit 64a9e2c

10 files changed

+60
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
1313
- Add a `Close Project` option
1414
- Add charts to the `Wild Pokémon` tab that show species and level distributions.
1515
- Add options for customizing the map grid under `View -> Grid Settings`.
16+
- Add an option to display a dividing line between tilesets in the Tileset Editor.
1617
- An alert will be displayed when attempting to open a seemingly invalid project.
1718
- Add support for defining project values with `enum` where `#define` was expected.
1819
- Add button to enable editing map groups including renaming groups and rearranging the maps within them.

forms/tileseteditor.ui

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@
647647
</property>
648648
<addaction name="actionLayer_Grid"/>
649649
<addaction name="actionMetatile_Grid"/>
650+
<addaction name="actionShow_Tileset_Divider"/>
650651
<addaction name="separator"/>
651652
<addaction name="actionShow_Counts"/>
652653
<addaction name="actionShow_Unused"/>
@@ -799,6 +800,14 @@
799800
<string>Ctrl+G</string>
800801
</property>
801802
</action>
803+
<action name="actionShow_Tileset_Divider">
804+
<property name="checkable">
805+
<bool>true</bool>
806+
</property>
807+
<property name="text">
808+
<string>Show Tileset Divider</string>
809+
</property>
810+
</action>
802811
</widget>
803812
<customwidgets>
804813
<customwidget>

include/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PorymapConfig: public KeyValueConfigBase
6868
this->showGrid = false;
6969
this->showTilesetEditorMetatileGrid = false;
7070
this->showTilesetEditorLayerGrid = true;
71+
this->showTilesetEditorDivider = false;
7172
this->monitorFiles = true;
7273
this->tilesetCheckerboardFill = true;
7374
this->theme = "default";
@@ -119,6 +120,7 @@ class PorymapConfig: public KeyValueConfigBase
119120
bool showGrid;
120121
bool showTilesetEditorMetatileGrid;
121122
bool showTilesetEditorLayerGrid;
123+
bool showTilesetEditorDivider;
122124
bool monitorFiles;
123125
bool tilesetCheckerboardFill;
124126
QString theme;

include/ui/tileseteditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private slots:
8888
void on_actionShow_UnusedTiles_toggled(bool checked);
8989
void on_actionMetatile_Grid_triggered(bool checked);
9090
void on_actionLayer_Grid_triggered(bool checked);
91+
void on_actionShow_Tileset_Divider_triggered(bool checked);
9192

9293
void on_actionUndo_triggered();
9394

include/ui/tileseteditormetatileselector.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class TilesetEditorMetatileSelector: public SelectablePixmapItem {
2323
QVector<uint16_t> usedMetatiles;
2424
bool selectorShowUnused = false;
2525
bool selectorShowCounts = false;
26-
bool showGrid;
26+
bool showGrid = false;
27+
bool showDivider = false;
2728

2829
protected:
2930
void mousePressEvent(QGraphicsSceneMouseEvent*);
@@ -44,6 +45,7 @@ class TilesetEditorMetatileSelector: public SelectablePixmapItem {
4445
int numRows(int numMetatiles);
4546
int numRows();
4647
void drawGrid();
48+
void drawDivider();
4749
void drawFilters();
4850
void drawUnused();
4951
void drawCounts();

include/ui/tileseteditortileselector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TilesetEditorTileSelector: public SelectablePixmapItem {
3333

3434
QVector<uint16_t> usedTiles;
3535
bool showUnused = false;
36+
bool showDivider = false;
3637

3738
protected:
3839
void mousePressEvent(QGraphicsSceneMouseEvent*);

src/config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
368368
this->showTilesetEditorMetatileGrid = getConfigBool(key, value);
369369
} else if (key == "show_tileset_editor_layer_grid") {
370370
this->showTilesetEditorLayerGrid = getConfigBool(key, value);
371+
} else if (key == "show_tileset_editor_divider") {
372+
this->showTilesetEditorDivider = getConfigBool(key, value);
371373
} else if (key == "monitor_files") {
372374
this->monitorFiles = getConfigBool(key, value);
373375
} else if (key == "tileset_checkerboard_fill") {
@@ -452,6 +454,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
452454
map.insert("show_grid", this->showGrid ? "1" : "0");
453455
map.insert("show_tileset_editor_metatile_grid", this->showTilesetEditorMetatileGrid ? "1" : "0");
454456
map.insert("show_tileset_editor_layer_grid", this->showTilesetEditorLayerGrid ? "1" : "0");
457+
map.insert("show_tileset_editor_divider", this->showTilesetEditorDivider ? "1" : "0");
455458
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
456459
map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0");
457460
map.insert("theme", this->theme);

src/ui/tileseteditor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void TilesetEditor::initUi() {
9999
this->paletteId = ui->spinBox_paletteSelector->value();
100100
this->ui->spinBox_paletteSelector->setMinimum(0);
101101
this->ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1);
102+
this->ui->actionShow_Tileset_Divider->setChecked(porymapConfig.showTilesetEditorDivider);
102103

103104
this->setAttributesUi();
104105
this->setMetatileLabelValidator();
@@ -191,6 +192,7 @@ void TilesetEditor::initMetatileSelector()
191192
bool showGrid = porymapConfig.showTilesetEditorMetatileGrid;
192193
this->ui->actionMetatile_Grid->setChecked(showGrid);
193194
this->metatileSelector->showGrid = showGrid;
195+
this->metatileSelector->showDivider = this->ui->actionShow_Tileset_Divider->isChecked();
194196

195197
this->metatilesScene = new QGraphicsScene;
196198
this->metatilesScene->addItem(this->metatileSelector);
@@ -232,6 +234,8 @@ void TilesetEditor::initTileSelector()
232234
connect(this->tileSelector, &TilesetEditorTileSelector::selectedTilesChanged,
233235
this, &TilesetEditor::onSelectedTilesChanged);
234236

237+
this->tileSelector->showDivider = this->ui->actionShow_Tileset_Divider->isChecked();
238+
235239
this->tilesScene = new QGraphicsScene;
236240
this->tilesScene->addItem(this->tileSelector);
237241
this->tileSelector->select(0);
@@ -1048,6 +1052,16 @@ void TilesetEditor::on_actionLayer_Grid_triggered(bool checked) {
10481052
porymapConfig.showTilesetEditorLayerGrid = checked;
10491053
}
10501054

1055+
void TilesetEditor::on_actionShow_Tileset_Divider_triggered(bool checked) {
1056+
this->metatileSelector->showDivider = checked;
1057+
this->metatileSelector->draw();
1058+
1059+
this->tileSelector->showDivider = checked;
1060+
this->tileSelector->draw();
1061+
1062+
porymapConfig.showTilesetEditorDivider = checked;
1063+
}
1064+
10511065
void TilesetEditor::countMetatileUsage() {
10521066
// do not double count
10531067
metatileSelector->usedMetatiles.fill(0);

src/ui/tileseteditormetatileselector.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ QImage TilesetEditorMetatileSelector::buildImage(int metatileIdStart, int numMet
7070
void TilesetEditorMetatileSelector::draw() {
7171
this->setPixmap(QPixmap::fromImage(this->buildAllMetatilesImage()));
7272
this->drawGrid();
73+
this->drawDivider();
7374
this->drawSelection();
7475
this->drawFilters();
7576
}
@@ -186,6 +187,20 @@ void TilesetEditorMetatileSelector::drawGrid() {
186187
this->setPixmap(pixmap);
187188
}
188189

190+
void TilesetEditorMetatileSelector::drawDivider() {
191+
if (!this->showDivider)
192+
return;
193+
194+
const int y = this->numRows(this->primaryTileset->numMetatiles()) * 32;
195+
196+
QPixmap pixmap = this->pixmap();
197+
QPainter painter(&pixmap);
198+
painter.setPen(Qt::white);
199+
painter.drawLine(0, y, this->numMetatilesWide * 32, y);
200+
painter.end();
201+
this->setPixmap(pixmap);
202+
}
203+
189204
void TilesetEditorMetatileSelector::drawFilters() {
190205
if (selectorShowUnused) {
191206
drawUnused();

src/ui/tileseteditortileselector.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ void TilesetEditorTileSelector::draw() {
4646
painter.drawImage(origin, tileImage);
4747
}
4848

49+
if (this->showDivider) {
50+
int row = this->primaryTileset->tiles.length() / this->numTilesWide;
51+
if (this->primaryTileset->tiles.length() % this->numTilesWide != 0) {
52+
// Round up height for incomplete last row
53+
row++;
54+
}
55+
const int y = row * 16;
56+
painter.setPen(Qt::white);
57+
painter.drawLine(0, y, this->numTilesWide * 16, y);
58+
}
59+
4960
painter.end();
5061
this->setPixmap(QPixmap::fromImage(image));
5162

0 commit comments

Comments
 (0)