Skip to content

Commit

Permalink
Add dividing line for tilesets in Tileset Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Dec 18, 2024
1 parent 883087d commit 64a9e2c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Add a `Close Project` option
- Add charts to the `Wild Pokémon` tab that show species and level distributions.
- Add options for customizing the map grid under `View -> Grid Settings`.
- Add an option to display a dividing line between tilesets in the Tileset Editor.
- An alert will be displayed when attempting to open a seemingly invalid project.
- Add support for defining project values with `enum` where `#define` was expected.
- Add button to enable editing map groups including renaming groups and rearranging the maps within them.
Expand Down
9 changes: 9 additions & 0 deletions forms/tileseteditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@
</property>
<addaction name="actionLayer_Grid"/>
<addaction name="actionMetatile_Grid"/>
<addaction name="actionShow_Tileset_Divider"/>
<addaction name="separator"/>
<addaction name="actionShow_Counts"/>
<addaction name="actionShow_Unused"/>
Expand Down Expand Up @@ -799,6 +800,14 @@
<string>Ctrl+G</string>
</property>
</action>
<action name="actionShow_Tileset_Divider">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Tileset Divider</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
2 changes: 2 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PorymapConfig: public KeyValueConfigBase
this->showGrid = false;
this->showTilesetEditorMetatileGrid = false;
this->showTilesetEditorLayerGrid = true;
this->showTilesetEditorDivider = false;
this->monitorFiles = true;
this->tilesetCheckerboardFill = true;
this->theme = "default";
Expand Down Expand Up @@ -119,6 +120,7 @@ class PorymapConfig: public KeyValueConfigBase
bool showGrid;
bool showTilesetEditorMetatileGrid;
bool showTilesetEditorLayerGrid;
bool showTilesetEditorDivider;
bool monitorFiles;
bool tilesetCheckerboardFill;
QString theme;
Expand Down
1 change: 1 addition & 0 deletions include/ui/tileseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private slots:
void on_actionShow_UnusedTiles_toggled(bool checked);
void on_actionMetatile_Grid_triggered(bool checked);
void on_actionLayer_Grid_triggered(bool checked);
void on_actionShow_Tileset_Divider_triggered(bool checked);

void on_actionUndo_triggered();

Expand Down
4 changes: 3 additions & 1 deletion include/ui/tileseteditormetatileselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class TilesetEditorMetatileSelector: public SelectablePixmapItem {
QVector<uint16_t> usedMetatiles;
bool selectorShowUnused = false;
bool selectorShowCounts = false;
bool showGrid;
bool showGrid = false;
bool showDivider = false;

protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
Expand All @@ -44,6 +45,7 @@ class TilesetEditorMetatileSelector: public SelectablePixmapItem {
int numRows(int numMetatiles);
int numRows();
void drawGrid();
void drawDivider();
void drawFilters();
void drawUnused();
void drawCounts();
Expand Down
1 change: 1 addition & 0 deletions include/ui/tileseteditortileselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TilesetEditorTileSelector: public SelectablePixmapItem {

QVector<uint16_t> usedTiles;
bool showUnused = false;
bool showDivider = false;

protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
Expand Down
3 changes: 3 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->showTilesetEditorMetatileGrid = getConfigBool(key, value);
} else if (key == "show_tileset_editor_layer_grid") {
this->showTilesetEditorLayerGrid = getConfigBool(key, value);
} else if (key == "show_tileset_editor_divider") {
this->showTilesetEditorDivider = getConfigBool(key, value);
} else if (key == "monitor_files") {
this->monitorFiles = getConfigBool(key, value);
} else if (key == "tileset_checkerboard_fill") {
Expand Down Expand Up @@ -452,6 +454,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("show_grid", this->showGrid ? "1" : "0");
map.insert("show_tileset_editor_metatile_grid", this->showTilesetEditorMetatileGrid ? "1" : "0");
map.insert("show_tileset_editor_layer_grid", this->showTilesetEditorLayerGrid ? "1" : "0");
map.insert("show_tileset_editor_divider", this->showTilesetEditorDivider ? "1" : "0");
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0");
map.insert("theme", this->theme);
Expand Down
14 changes: 14 additions & 0 deletions src/ui/tileseteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void TilesetEditor::initUi() {
this->paletteId = ui->spinBox_paletteSelector->value();
this->ui->spinBox_paletteSelector->setMinimum(0);
this->ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1);
this->ui->actionShow_Tileset_Divider->setChecked(porymapConfig.showTilesetEditorDivider);

this->setAttributesUi();
this->setMetatileLabelValidator();
Expand Down Expand Up @@ -191,6 +192,7 @@ void TilesetEditor::initMetatileSelector()
bool showGrid = porymapConfig.showTilesetEditorMetatileGrid;
this->ui->actionMetatile_Grid->setChecked(showGrid);
this->metatileSelector->showGrid = showGrid;
this->metatileSelector->showDivider = this->ui->actionShow_Tileset_Divider->isChecked();

this->metatilesScene = new QGraphicsScene;
this->metatilesScene->addItem(this->metatileSelector);
Expand Down Expand Up @@ -232,6 +234,8 @@ void TilesetEditor::initTileSelector()
connect(this->tileSelector, &TilesetEditorTileSelector::selectedTilesChanged,
this, &TilesetEditor::onSelectedTilesChanged);

this->tileSelector->showDivider = this->ui->actionShow_Tileset_Divider->isChecked();

this->tilesScene = new QGraphicsScene;
this->tilesScene->addItem(this->tileSelector);
this->tileSelector->select(0);
Expand Down Expand Up @@ -1048,6 +1052,16 @@ void TilesetEditor::on_actionLayer_Grid_triggered(bool checked) {
porymapConfig.showTilesetEditorLayerGrid = checked;
}

void TilesetEditor::on_actionShow_Tileset_Divider_triggered(bool checked) {
this->metatileSelector->showDivider = checked;
this->metatileSelector->draw();

this->tileSelector->showDivider = checked;
this->tileSelector->draw();

porymapConfig.showTilesetEditorDivider = checked;
}

void TilesetEditor::countMetatileUsage() {
// do not double count
metatileSelector->usedMetatiles.fill(0);
Expand Down
15 changes: 15 additions & 0 deletions src/ui/tileseteditormetatileselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ QImage TilesetEditorMetatileSelector::buildImage(int metatileIdStart, int numMet
void TilesetEditorMetatileSelector::draw() {
this->setPixmap(QPixmap::fromImage(this->buildAllMetatilesImage()));
this->drawGrid();
this->drawDivider();
this->drawSelection();
this->drawFilters();
}
Expand Down Expand Up @@ -186,6 +187,20 @@ void TilesetEditorMetatileSelector::drawGrid() {
this->setPixmap(pixmap);
}

void TilesetEditorMetatileSelector::drawDivider() {
if (!this->showDivider)
return;

const int y = this->numRows(this->primaryTileset->numMetatiles()) * 32;

QPixmap pixmap = this->pixmap();
QPainter painter(&pixmap);
painter.setPen(Qt::white);
painter.drawLine(0, y, this->numMetatilesWide * 32, y);
painter.end();
this->setPixmap(pixmap);
}

void TilesetEditorMetatileSelector::drawFilters() {
if (selectorShowUnused) {
drawUnused();
Expand Down
11 changes: 11 additions & 0 deletions src/ui/tileseteditortileselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ void TilesetEditorTileSelector::draw() {
painter.drawImage(origin, tileImage);
}

if (this->showDivider) {
int row = this->primaryTileset->tiles.length() / this->numTilesWide;
if (this->primaryTileset->tiles.length() % this->numTilesWide != 0) {
// Round up height for incomplete last row
row++;
}
const int y = row * 16;
painter.setPen(Qt::white);
painter.drawLine(0, y, this->numTilesWide * 16, y);
}

painter.end();
this->setPixmap(QPixmap::fromImage(image));

Expand Down

0 comments on commit 64a9e2c

Please sign in to comment.