Skip to content

Commit be97285

Browse files
Add setting to change metatile selector width
1 parent c45598f commit be97285

12 files changed

+56
-36
lines changed

forms/projectsettingseditor.ui

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@
852852
<x>0</x>
853853
<y>0</y>
854854
<width>570</width>
855-
<height>798</height>
855+
<height>837</height>
856856
</rect>
857857
</property>
858858
<layout class="QVBoxLayout" name="verticalLayout_12">
@@ -973,6 +973,27 @@
973973
</layout>
974974
</widget>
975975
</item>
976+
<item>
977+
<layout class="QFormLayout" name="formLayout_MetatileSelectorWidth">
978+
<item row="0" column="0">
979+
<widget class="QLabel" name="label_MetatileSelectorWidth">
980+
<property name="text">
981+
<string>Metatile Selector Width</string>
982+
</property>
983+
</widget>
984+
</item>
985+
<item row="0" column="1">
986+
<widget class="NoScrollSpinBox" name="spinBox_MetatileSelectorWidth">
987+
<property name="toolTip">
988+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The width (in metatiles) of the metatile selectors on the Map tab and in the Tileset Editor.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
989+
</property>
990+
<property name="minimum">
991+
<number>1</number>
992+
</property>
993+
</widget>
994+
</item>
995+
</layout>
996+
</item>
976997
<item>
977998
<widget class="QFrame" name="frame_WarningTilesetsTab">
978999
<property name="styleSheet">
@@ -1873,16 +1894,6 @@
18731894
<extends>QComboBox</extends>
18741895
<header>noscrollcombobox.h</header>
18751896
</customwidget>
1876-
<customwidget>
1877-
<class>NoScrollSpinBox</class>
1878-
<extends>QSpinBox</extends>
1879-
<header>noscrollspinbox.h</header>
1880-
</customwidget>
1881-
<customwidget>
1882-
<class>NoScrollTextEdit</class>
1883-
<extends>QTextEdit</extends>
1884-
<header>noscrolltextedit.h</header>
1885-
</customwidget>
18861897
<customwidget>
18871898
<class>UIntSpinBox</class>
18881899
<extends>QAbstractSpinBox</extends>
@@ -1893,6 +1904,16 @@
18931904
<extends>UIntSpinBox</extends>
18941905
<header location="global">uintspinbox.h</header>
18951906
</customwidget>
1907+
<customwidget>
1908+
<class>NoScrollSpinBox</class>
1909+
<extends>QSpinBox</extends>
1910+
<header>noscrollspinbox.h</header>
1911+
</customwidget>
1912+
<customwidget>
1913+
<class>NoScrollTextEdit</class>
1914+
<extends>QTextEdit</extends>
1915+
<header>noscrolltextedit.h</header>
1916+
</customwidget>
18961917
</customwidgets>
18971918
<resources>
18981919
<include location="../resources/images.qrc"/>

include/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class ProjectConfig: public KeyValueConfigBase
325325
this->unusedTileSplit = 0x0000;
326326
this->maxEventsPerGroup = 255;
327327
this->forcedMajorVersion = 0;
328+
this->metatileSelectorWidth = 8;
328329
this->globalConstantsFilepaths.clear();
329330
this->globalConstants.clear();
330331
this->identifiers.clear();
@@ -404,6 +405,7 @@ class ProjectConfig: public KeyValueConfigBase
404405
QList<uint32_t> warpBehaviors;
405406
int maxEventsPerGroup;
406407
int forcedMajorVersion;
408+
int metatileSelectorWidth;
407409
QStringList globalConstantsFilepaths;
408410
QMap<QString,QString> globalConstants;
409411

include/ui/metatileimageexporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class MetatileImageExporter : public QDialog
5252
};
5353
uint16_t metatileStart = 0;
5454
uint16_t metatileEnd = 0xFFFF;
55-
uint16_t numMetatilesWide = 8;
55+
uint16_t numMetatilesWide = projectConfig.metatileSelectorWidth;
5656
bool usePrimaryTileset = true;
5757
bool useSecondaryTileset = false;
5858
bool renderPlaceholders = false;

include/ui/metatileselector.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ struct MetatileSelection
3131
class MetatileSelector: public SelectablePixmapItem {
3232
Q_OBJECT
3333
public:
34-
MetatileSelector(int numMetatilesWide, Layout *layout): SelectablePixmapItem(Metatile::pixelSize()) {
34+
MetatileSelector(int numMetatilesWide, Layout *layout)
35+
: SelectablePixmapItem(Metatile::pixelSize()),
36+
numMetatilesWide(qMax(numMetatilesWide, 1))
37+
{
3538
this->externalSelection = false;
3639
this->prefabSelection = false;
37-
this->numMetatilesWide = numMetatilesWide;
3840
this->layout = layout;
3941
this->selection = MetatileSelection{};
4042
this->cellPos = QPoint(-1, -1);
@@ -65,10 +67,10 @@ class MetatileSelector: public SelectablePixmapItem {
6567
void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
6668
void drawSelection() override;
6769
private:
70+
const int numMetatilesWide;
6871
QPixmap basePixmap;
6972
bool externalSelection;
7073
bool prefabSelection;
71-
int numMetatilesWide;
7274
Layout *layout;
7375
int externalSelectionWidth;
7476
int externalSelectionHeight;

include/ui/tileseteditormetatileselector.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Layout;
99
class TilesetEditorMetatileSelector: public SelectablePixmapItem {
1010
Q_OBJECT
1111
public:
12-
TilesetEditorMetatileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, Layout *layout);
12+
TilesetEditorMetatileSelector(int numMetatilesWide, Tileset *primaryTileset, Tileset *secondaryTileset, Layout *layout);
1313
Layout *layout = nullptr;
1414

1515
void draw() override;
@@ -36,13 +36,12 @@ class TilesetEditorMetatileSelector: public SelectablePixmapItem {
3636
void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
3737

3838
private:
39+
const int numMetatilesWide;
3940
QImage baseImage;
4041
QPixmap basePixmap;
4142
Tileset *primaryTileset = nullptr;
4243
Tileset *secondaryTileset = nullptr;
4344
uint16_t selectedMetatileId;
44-
int numMetatilesWide;
45-
int numMetatilesHigh;
4645
void updateBasePixmap();
4746
uint16_t posToMetatileId(int x, int y, bool *ok = nullptr) const;
4847
uint16_t posToMetatileId(const QPoint &pos, bool *ok = nullptr) const;

src/config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,8 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
10071007
this->maxEventsPerGroup = getConfigInteger(key, value, 1, INT_MAX, 255);
10081008
} else if (key == "forced_major_version") {
10091009
this->forcedMajorVersion = getConfigInteger(key, value);
1010+
} else if (key == "metatile_selector_width") {
1011+
this->metatileSelectorWidth = getConfigInteger(key, value, 1, INT_MAX, 8);
10101012
} else {
10111013
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->filepath()).arg(key));
10121014
}
@@ -1116,6 +1118,7 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
11161118
map.insert("warp_behaviors", warpBehaviorStrs.join(","));
11171119
map.insert("max_events_per_group", QString::number(this->maxEventsPerGroup));
11181120
map.insert("forced_major_version", QString::number(this->forcedMajorVersion));
1121+
map.insert("metatile_selector_width", QString::number(this->metatileSelectorWidth));
11191122

11201123
return map;
11211124
}

src/editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ void Editor::displayMetatileSelector() {
16461646

16471647
scene_metatiles = new QGraphicsScene;
16481648
if (!metatile_selector_item) {
1649-
metatile_selector_item = new MetatileSelector(8, this->layout);
1649+
metatile_selector_item = new MetatileSelector(projectConfig.metatileSelectorWidth, this->layout);
16501650
connect(metatile_selector_item, &MetatileSelector::hoveredMetatileSelectionChanged,
16511651
this, &Editor::onHoveredMetatileSelectionChanged);
16521652
connect(metatile_selector_item, &MetatileSelector::hoveredMetatileSelectionCleared,

src/ui/imageproviders.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ QImage getMetatileSheetImage(Tileset *primaryTileset,
191191
const QSize &metatileSize,
192192
bool useTruePalettes)
193193
{
194-
if (metatileIdEnd < metatileIdStart || numMetatilesWide == 0)
194+
if (metatileIdEnd < metatileIdStart || numMetatilesWide <= 0)
195195
return QImage();
196196

197197
int numMetatilesToDraw = metatileIdEnd - metatileIdStart + 1;

src/ui/metatileselector.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ uint16_t MetatileSelector::posToMetatileId(int x, int y, bool *ok) const {
213213
// then the metatiles we used to round the primary tileset would have the index of valid secondary metatiles.
214214
// These need to be ignored, or they'll appear to be duplicates of the subseqeunt secondary metatiles.
215215
int numPrimaryRounded = numPrimaryMetatilesRounded();
216-
int firstSecondaryRow = numPrimaryRounded / qMax(this->numMetatilesWide, 1);
216+
int firstSecondaryRow = numPrimaryRounded / this->numMetatilesWide;
217217
metatileId = static_cast<uint16_t>(Project::getNumMetatilesPrimary() + index - numPrimaryRounded);
218218
if (secondaryTileset() && secondaryTileset()->contains(metatileId) && y >= firstSecondaryRow) {
219219
return metatileId;
@@ -224,11 +224,6 @@ uint16_t MetatileSelector::posToMetatileId(int x, int y, bool *ok) const {
224224
}
225225

226226
QPoint MetatileSelector::metatileIdToPos(uint16_t metatileId, bool *ok) const {
227-
if (this->numMetatilesWide == 0) {
228-
if (ok) *ok = false;
229-
return QPoint(0,0);
230-
}
231-
232227
if (primaryTileset() && primaryTileset()->contains(metatileId)) {
233228
if (ok) *ok = true;
234229
int index = metatileId;

src/ui/projectsettingseditor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ void ProjectSettingsEditor::initUi() {
161161
ui->spinBox_PlayerViewDistance_North->setMaximum(INT_MAX);
162162
ui->spinBox_PlayerViewDistance_East->setMaximum(INT_MAX);
163163
ui->spinBox_PlayerViewDistance_South->setMaximum(INT_MAX);
164+
ui->spinBox_MetatileSelectorWidth->setMaximum(maxMetatileId + 1);
164165

165166
// The values for some of the settings we provide in this window can be determined using constants in the user's projects.
166167
// If the user has these constants we disable these settings in the UI -- they can modify them using their constants.
@@ -503,6 +504,7 @@ void ProjectSettingsEditor::refresh() {
503504
ui->spinBox_PlayerViewDistance_North->setValue(projectConfig.playerViewDistance.top());
504505
ui->spinBox_PlayerViewDistance_East->setValue(projectConfig.playerViewDistance.right());
505506
ui->spinBox_PlayerViewDistance_South->setValue(projectConfig.playerViewDistance.bottom());
507+
ui->spinBox_MetatileSelectorWidth->setValue(projectConfig.metatileSelectorWidth);
506508

507509
// Set (and sync) border metatile IDs
508510
this->setBorderMetatileIds(false, projectConfig.newMapBorderMetatileIds);
@@ -598,6 +600,7 @@ void ProjectSettingsEditor::save() {
598600
ui->spinBox_PlayerViewDistance_North->value(),
599601
ui->spinBox_PlayerViewDistance_East->value(),
600602
ui->spinBox_PlayerViewDistance_South->value());
603+
projectConfig.metatileSelectorWidth = ui->spinBox_MetatileSelectorWidth->value();
601604

602605
// Save line edit settings
603606
projectConfig.prefabFilepath = ui->lineEdit_PrefabsPath->text();

0 commit comments

Comments
 (0)