Skip to content

Commit

Permalink
Add grids to tileset editor
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Dec 20, 2023
1 parent 93fb8cf commit a2d2306
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 65 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Add settings for custom images, including the collision graphics, default event icons, and pokémon icons.
- Add settings to override any symbol or macro names Porymap expects to find.
- Add a zoom slider to the Collision tab.
- Add toggleable grids to the Tileset Editor.
- Support for custom metatile ID, collision, and elevation data sizes.
- Support for 8bpp tileset tile images.

Expand Down
147 changes: 90 additions & 57 deletions forms/tileseteditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,68 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1" colspan="3">
<widget class="NoScrollComboBox" name="comboBox_layerType"/>
</item>
<item row="7" column="0" colspan="4">
<widget class="NoScrollComboBox" name="comboBox_metatileBehaviors"/>
</item>
<item row="13" column="0" colspan="3">
<widget class="QLineEdit" name="lineEdit_metatileLabel">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="12" column="0" colspan="3">
<widget class="QLabel" name="label_metatileLabel">
<property name="text">
<string>Metatile Label (Optional)</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QLabel" name="label_metatileBehavior">
<property name="text">
<string>Metatile Behavior</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGraphicsView" name="graphicsView_metatileLayers">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>66</width>
<height>34</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>66</width>
<height>34</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_BottomTop">
<property name="text">
<string>Bottom/Top</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="3">
<widget class="NoScrollComboBox" name="comboBox_metatileBehaviors"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_encounterType">
<property name="text">
Expand All @@ -228,17 +280,14 @@
<item row="11" column="0">
<widget class="NoScrollComboBox" name="comboBox_terrainType"/>
</item>
<item row="12" column="0" colspan="2">
<widget class="QLabel" name="label_metatileLabel">
<item row="0" column="2">
<widget class="QLabel" name="label_layerType">
<property name="text">
<string>Metatile Label (Optional)</string>
<string>Layer Type</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="NoScrollComboBox" name="comboBox_layerType"/>
</item>
<item row="13" column="2">
<item row="13" column="3">
<widget class="QToolButton" name="copyButton_metatileLabel">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copies the full metatile label to the clipboard.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
Expand All @@ -252,52 +301,9 @@
</property>
</widget>
</item>
<item row="13" column="0" colspan="2">
<widget class="QLineEdit" name="lineEdit_metatileLabel">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_layerType">
<property name="text">
<string>Layer Type</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_metatileBehavior">
<property name="text">
<string>Metatile Behavior</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="NoScrollComboBox" name="comboBox_encounterType"/>
</item>
<item row="1" column="0">
<widget class="QGraphicsView" name="graphicsView_metatileLayers">
<property name="minimumSize">
<size>
<width>66</width>
<height>34</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>66</width>
<height>34</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -565,10 +571,6 @@
<addaction name="actionChange_Metatiles_Count"/>
<addaction name="actionChange_Palettes"/>
<addaction name="separator"/>
<addaction name="actionShow_Unused"/>
<addaction name="actionShow_Counts"/>
<addaction name="actionShow_UnusedTiles"/>
<addaction name="separator"/>
<addaction name="actionExport_Primary_Tiles_Image"/>
<addaction name="actionExport_Secondary_Tiles_Image"/>
<addaction name="actionExport_Primary_Metatiles_Image"/>
Expand All @@ -584,8 +586,20 @@
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
<addaction name="actionLayer_Grid"/>
<addaction name="actionMetatile_Grid"/>
<addaction name="separator"/>
<addaction name="actionShow_Counts"/>
<addaction name="actionShow_Unused"/>
<addaction name="actionShow_UnusedTiles"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
<addaction name="menuTools"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
Expand Down Expand Up @@ -711,6 +725,25 @@
<string>Ctrl+V</string>
</property>
</action>
<action name="actionLayer_Grid">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Layer Grid</string>
</property>
</action>
<action name="actionMetatile_Grid">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Metatile Grid</string>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
8 changes: 8 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class PorymapConfig: public KeyValueConfigBase
this->showCursorTile = true;
this->showBorder = true;
this->showGrid = false;
this->showTilesetEditorMetatileGrid = false;
this->showTilesetEditorLayerGrid = true;
this->monitorFiles = true;
this->tilesetCheckerboardFill = true;
this->theme = "default";
Expand All @@ -88,6 +90,8 @@ class PorymapConfig: public KeyValueConfigBase
void setShowCursorTile(bool enabled);
void setShowBorder(bool enabled);
void setShowGrid(bool enabled);
void setShowTilesetEditorMetatileGrid(bool enabled);
void setShowTilesetEditorLayerGrid(bool enabled);
void setMonitorFiles(bool monitor);
void setTilesetCheckerboardFill(bool checkerboard);
void setTheme(QString theme);
Expand All @@ -113,6 +117,8 @@ class PorymapConfig: public KeyValueConfigBase
bool getShowCursorTile();
bool getShowBorder();
bool getShowGrid();
bool getShowTilesetEditorMetatileGrid();
bool getShowTilesetEditorLayerGrid();
bool getMonitorFiles();
bool getTilesetCheckerboardFill();
QString getTheme();
Expand Down Expand Up @@ -156,6 +162,8 @@ class PorymapConfig: public KeyValueConfigBase
bool showCursorTile;
bool showBorder;
bool showGrid;
bool showTilesetEditorMetatileGrid;
bool showTilesetEditorLayerGrid;
bool monitorFiles;
bool tilesetCheckerboardFill;
QString theme;
Expand Down
1 change: 1 addition & 0 deletions include/ui/metatilelayersitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MetatileLayersItem: public SelectablePixmapItem {
void setTilesets(Tileset*, Tileset*);
void setMetatile(Metatile*);
void clearLastModifiedCoords();
bool showGrid;
private:
Metatile* metatile;
Tileset *primaryTileset;
Expand Down
2 changes: 2 additions & 0 deletions include/ui/tileseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ private slots:
void on_actionShow_Unused_toggled(bool checked);
void on_actionShow_Counts_toggled(bool checked);
void on_actionShow_UnusedTiles_toggled(bool checked);
void on_actionMetatile_Grid_triggered(bool checked);
void on_actionLayer_Grid_triggered(bool checked);

void on_actionUndo_triggered();

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

protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
Expand All @@ -35,10 +36,12 @@ class TilesetEditorMetatileSelector: public SelectablePixmapItem {
Tileset *secondaryTileset = nullptr;
uint16_t selectedMetatile;
int numMetatilesWide;
int numMetatilesHigh;
uint16_t getMetatileId(int x, int y);
QPoint getMetatileIdCoords(uint16_t);
bool shouldAcceptEvent(QGraphicsSceneMouseEvent*);

int numRows(int numMetatiles);
int numRows();
void drawFilters();
void drawUnused();
void drawCounts();
Expand Down
24 changes: 24 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->showBorder = getConfigBool(key, value);
} else if (key == "show_grid") {
this->showGrid = getConfigBool(key, value);
} else if (key == "show_tileset_editor_metatile_grid") {
this->showTilesetEditorMetatileGrid = getConfigBool(key, value);
} else if (key == "show_tileset_editor_layer_grid") {
this->showTilesetEditorLayerGrid = getConfigBool(key, value);
} else if (key == "monitor_files") {
this->monitorFiles = getConfigBool(key, value);
} else if (key == "tileset_checkerboard_fill") {
Expand Down Expand Up @@ -405,6 +409,8 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0");
map.insert("show_border", this->showBorder ? "1" : "0");
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("monitor_files", this->monitorFiles ? "1" : "0");
map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0");
map.insert("theme", this->theme);
Expand Down Expand Up @@ -538,6 +544,16 @@ void PorymapConfig::setShowGrid(bool enabled) {
this->save();
}

void PorymapConfig::setShowTilesetEditorMetatileGrid(bool enabled) {
this->showTilesetEditorMetatileGrid = enabled;
this->save();
}

void PorymapConfig::setShowTilesetEditorLayerGrid(bool enabled) {
this->showTilesetEditorLayerGrid = enabled;
this->save();
}

void PorymapConfig::setTheme(QString theme) {
this->theme = theme;
}
Expand Down Expand Up @@ -662,6 +678,14 @@ bool PorymapConfig::getShowGrid() {
return this->showGrid;
}

bool PorymapConfig::getShowTilesetEditorMetatileGrid() {
return this->showTilesetEditorMetatileGrid;
}

bool PorymapConfig::getShowTilesetEditorLayerGrid() {
return this->showTilesetEditorLayerGrid;
}

bool PorymapConfig::getMonitorFiles() {
return this->monitorFiles;
}
Expand Down
15 changes: 13 additions & 2 deletions src/ui/metatilelayersitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QPainter>

void MetatileLayersItem::draw() {
const QList<QPoint> tileCoords = QList<QPoint>{
static const QList<QPoint> tileCoords = QList<QPoint>{
QPoint(0, 0),
QPoint(16, 0),
QPoint(0, 16),
Expand All @@ -19,8 +19,11 @@ void MetatileLayersItem::draw() {
QPoint(80, 16),
};

QPixmap pixmap(projectConfig.getNumLayersInMetatile() * 32, 32);
const int numLayers = projectConfig.getNumLayersInMetatile();
QPixmap pixmap(numLayers * 32, 32);
QPainter painter(&pixmap);

// Draw tile images
int numTiles = projectConfig.getNumTilesInMetatile();
for (int i = 0; i < numTiles; i++) {
Tile tile = this->metatile->tiles.at(i);
Expand All @@ -29,6 +32,14 @@ void MetatileLayersItem::draw() {
.scaled(16, 16);
painter.drawImage(tileCoords.at(i), tileImage);
}
if (this->showGrid) {
// Draw grid
painter.setPen(Qt::white);
for (int i = 1; i < numLayers; i++) {
int x = i * 32;
painter.drawLine(x, 0, x, 32);
}
}

this->setPixmap(pixmap);
}
Expand Down
Loading

0 comments on commit a2d2306

Please sign in to comment.