Improve metatile properties layout

This commit is contained in:
GriffinR
2025-08-01 21:51:01 -04:00
parent d0337a7ae3
commit db9ecd744f
5 changed files with 465 additions and 223 deletions

View File

@@ -65,7 +65,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>253</width>
<width>241</width>
<height>659</height>
</rect>
</property>
@@ -195,170 +195,290 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_MetatileProperties">
<item row="15" column="0" colspan="4">
<widget class="QLineEdit" name="lineEdit_metatileLabel">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2" colspan="3">
<widget class="NoScrollComboBox" name="comboBox_layerType">
<item row="5" column="0" colspan="2">
<widget class="QFrame" name="frame_RawAttributesValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>185</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label_RawAttributesValue">
<property name="text">
<string>Raw Attributes Value</string>
</property>
</widget>
</item>
<item>
<widget class="UIntHexSpinBox" name="spinBox_RawAttributesValue"/>
</item>
<item>
<spacer name="verticalSpacer_10">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="14" column="0" colspan="5">
<widget class="QLabel" name="label_metatileLabel">
<property name="text">
<string>Metatile Label (Optional)</string>
</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="10" column="0" colspan="5">
<widget class="QLabel" name="label_terrainType">
<property name="text">
<string>Terrain Type</string>
</property>
</widget>
</item>
<item row="0" column="2" colspan="3">
<widget class="QLabel" name="label_layerType">
<property name="text">
<string>Layer Type</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="5">
<widget class="NoScrollComboBox" name="comboBox_metatileBehaviors">
<item row="0" column="1" rowspan="2">
<widget class="QFrame" name="frame_LayerType">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertPolicy::NoInsert</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_LayerType">
<property name="text">
<string>Layer Type</string>
</property>
</widget>
</item>
<item>
<widget class="NoScrollComboBox" name="comboBox_LayerType">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>185</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGraphicsView" name="graphicsView_metatileLayers">
<item row="6" column="0" colspan="2">
<widget class="QFrame" name="frame_MetatileLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>1</width>
<height>1</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item row="1" column="1">
<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>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/clipboard.ico</normaloff>:/icons/clipboard.ico</iconset>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="lineEdit_MetatileLabel">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_MetatileLabel">
<property name="text">
<string>Metatile Label (Optional)</string>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer_11">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="11" column="0" colspan="5">
<widget class="NoScrollComboBox" name="comboBox_terrainType">
<item row="4" column="0" colspan="2">
<widget class="QFrame" name="frame_TerrainType">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertPolicy::NoInsert</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label_TerrainType">
<property name="text">
<string>Terrain Type</string>
</property>
</widget>
</item>
<item>
<widget class="NoScrollComboBox" name="comboBox_TerrainType">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertPolicy::NoInsert</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="0" colspan="5">
<widget class="NoScrollComboBox" name="comboBox_encounterType">
<item row="3" column="0" colspan="2">
<widget class="QFrame" name="frame_EncounterType">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertPolicy::NoInsert</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label_EncounterType">
<property name="text">
<string>Encounter Type</string>
</property>
</widget>
</item>
<item>
<widget class="NoScrollComboBox" name="comboBox_EncounterType">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertPolicy::NoInsert</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="5">
<widget class="QLabel" name="label_metatileBehavior">
<property name="text">
<string>Metatile Behavior</string>
</property>
</widget>
</item>
<item row="12" column="0" colspan="5">
<widget class="QLabel" name="label_rawAttributesValue">
<property name="text">
<string>Raw Attributes Value</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="5">
<widget class="QLabel" name="label_encounterType">
<property name="text">
<string>Encounter Type</string>
</property>
</widget>
</item>
<item row="15" column="4">
<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>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/clipboard.ico</normaloff>:/icons/clipboard.ico</iconset>
</property>
</widget>
</item>
<item row="16" column="0">
<item row="10" column="0">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
@@ -371,8 +491,119 @@
</property>
</spacer>
</item>
<item row="13" column="0" colspan="5">
<widget class="UIntHexSpinBox" name="spinBox_rawAttributesValue"/>
<item row="2" column="0" colspan="2">
<widget class="QFrame" name="frame_MetatileBehavior">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label_MetatileBehavior">
<property name="text">
<string>Metatile Behavior</string>
</property>
</widget>
</item>
<item>
<widget class="NoScrollComboBox" name="comboBox_MetatileBehaviors">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertPolicy::NoInsert</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QFrame" name="frame_Layers">
<layout class="QVBoxLayout" name="verticalLayout_Layers">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_BottomTop">
<property name="text">
<string>Bottom/Top</string>
</property>
</widget>
</item>
<item>
<widget class="QGraphicsView" name="graphicsView_MetatileLayers">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>1</width>
<height>1</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_12">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@@ -512,12 +743,6 @@
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item>
@@ -555,8 +780,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>446</width>
<height>241</height>
<width>458</width>
<height>203</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">

View File

@@ -96,9 +96,7 @@ private slots:
void on_actionUndo_triggered();
void on_actionRedo_triggered();
void on_lineEdit_metatileLabel_editingFinished();
void on_copyButton_metatileLabel_clicked();
void on_copyButton_MetatileLabel_clicked();
void on_actionCut_triggered();
void on_actionCopy_triggered();
@@ -155,6 +153,8 @@ private:
bool swapMetatiles(uint16_t metatileIdA, uint16_t metatileIdB);
void applyMetatileSwapToLayouts(uint16_t metatileIdA, uint16_t metatileIdB);
void applyMetatileSwapsToLayouts();
void rebuildMetatilePropertiesFrame();
void addWidgetToMetatileProperties(QWidget *w, int *row, int rowSpan);
Ui::TilesetEditor *ui;
History<MetatileHistoryItem*> metatileHistory;
@@ -179,6 +179,7 @@ private:
QSet<uint16_t> metatileReloadQueue;
MetatileImageExporter::Settings *metatileImageExportSettings = nullptr;
QList<QPair<uint16_t,uint16_t>> metatileIdSwaps;
int numLayerViewRows;
bool save();

View File

@@ -32,7 +32,6 @@ public:
QImage buildPrimaryTilesIndexedImage();
QImage buildSecondaryTilesIndexedImage();
QVector<uint16_t> usedTiles;
bool showUnused = false;
bool showDivider = false;

View File

@@ -338,7 +338,7 @@ void PorymapConfig::reset() {
this->metatilesZoom = 30;
this->tilesetEditorMetatilesZoom = 30;
this->tilesetEditorTilesZoom = 30;
this->tilesetEditorLayerOrientation = Qt::Horizontal;
this->tilesetEditorLayerOrientation = Qt::Vertical;
this->showPlayerView = false;
this->showCursorTile = true;
this->showBorder = true;

View File

@@ -30,7 +30,7 @@ TilesetEditor::TilesetEditor(Project *project, Layout *layout, QWidget *parent)
auto validator = new IdentifierValidator(this);
validator->setAllowEmpty(true);
ui->lineEdit_metatileLabel->setValidator(validator);
ui->lineEdit_MetatileLabel->setValidator(validator);
ui->actionShow_Tileset_Divider->setChecked(porymapConfig.showTilesetEditorDivider);
ui->actionShow_Raw_Metatile_Attributes->setChecked(porymapConfig.showTilesetEditorRawAttributes);
@@ -65,6 +65,8 @@ TilesetEditor::TilesetEditor(Project *project, Layout *layout, QWidget *parent)
connect(ui->actionLayer_Arrangement_Horizontal, &QAction::triggered, [this] { setMetatileLayerOrientation(Qt::Horizontal); });
connect(ui->actionLayer_Arrangement_Vertical, &QAction::triggered, [this] { setMetatileLayerOrientation(Qt::Vertical); });
connect(ui->lineEdit_MetatileLabel, &QLineEdit::editingFinished, this, &TilesetEditor::commitMetatileLabel);
initAttributesUi();
initMetatileSelector();
initMetatileLayersItem();
@@ -141,77 +143,71 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi
}
void TilesetEditor::initAttributesUi() {
connect(ui->comboBox_metatileBehaviors, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitMetatileBehavior);
connect(ui->comboBox_encounterType, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitEncounterType);
connect(ui->comboBox_terrainType, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitTerrainType);
connect(ui->comboBox_layerType, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitLayerType);
connect(ui->comboBox_MetatileBehaviors, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitMetatileBehavior);
connect(ui->comboBox_EncounterType, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitEncounterType);
connect(ui->comboBox_TerrainType, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitTerrainType);
connect(ui->comboBox_LayerType, &NoScrollComboBox::editingFinished, this, &TilesetEditor::commitLayerType);
// Behavior
if (projectConfig.metatileBehaviorMask) {
for (auto i = project->metatileBehaviorMapInverse.constBegin(); i != project->metatileBehaviorMapInverse.constEnd(); i++) {
this->ui->comboBox_metatileBehaviors->addItem(i.value(), i.key());
this->ui->comboBox_MetatileBehaviors->addItem(i.value(), i.key());
}
this->ui->comboBox_metatileBehaviors->setMinimumContentsLength(0);
this->ui->comboBox_MetatileBehaviors->setMinimumContentsLength(0);
} else {
this->ui->comboBox_metatileBehaviors->setVisible(false);
this->ui->label_metatileBehavior->setVisible(false);
this->ui->frame_MetatileBehavior->setVisible(false);
}
// Terrain Type
if (projectConfig.metatileTerrainTypeMask) {
for (auto i = project->terrainTypeToName.constBegin(); i != project->terrainTypeToName.constEnd(); i++) {
this->ui->comboBox_terrainType->addItem(i.value(), i.key());
this->ui->comboBox_TerrainType->addItem(i.value(), i.key());
}
this->ui->comboBox_terrainType->setMinimumContentsLength(0);
this->ui->comboBox_TerrainType->setMinimumContentsLength(0);
} else {
this->ui->comboBox_terrainType->setVisible(false);
this->ui->label_terrainType->setVisible(false);
this->ui->frame_TerrainType->setVisible(false);
}
// Encounter Type
if (projectConfig.metatileEncounterTypeMask) {
for (auto i = project->encounterTypeToName.constBegin(); i != project->encounterTypeToName.constEnd(); i++) {
this->ui->comboBox_encounterType->addItem(i.value(), i.key());
this->ui->comboBox_EncounterType->addItem(i.value(), i.key());
}
this->ui->comboBox_encounterType->setMinimumContentsLength(0);
this->ui->comboBox_EncounterType->setMinimumContentsLength(0);
} else {
this->ui->comboBox_encounterType->setVisible(false);
this->ui->label_encounterType->setVisible(false);
this->ui->frame_EncounterType->setVisible(false);
}
// Layer Type
if (!projectConfig.tripleLayerMetatilesEnabled) {
this->ui->comboBox_layerType->addItem("Normal - Middle/Top", Metatile::LayerType::Normal);
this->ui->comboBox_layerType->addItem("Covered - Bottom/Middle", Metatile::LayerType::Covered);
this->ui->comboBox_layerType->addItem("Split - Bottom/Top", Metatile::LayerType::Split);
this->ui->comboBox_layerType->setEditable(false);
this->ui->comboBox_layerType->setMinimumContentsLength(0);
this->ui->comboBox_LayerType->addItem("Normal - Middle/Top", Metatile::LayerType::Normal);
this->ui->comboBox_LayerType->addItem("Covered - Bottom/Middle", Metatile::LayerType::Covered);
this->ui->comboBox_LayerType->addItem("Split - Bottom/Top", Metatile::LayerType::Split);
this->ui->comboBox_LayerType->setEditable(false);
this->ui->comboBox_LayerType->setMinimumContentsLength(0);
if (!projectConfig.metatileLayerTypeMask) {
// User doesn't have triple layer metatiles, but has no layer type attribute.
// Porymap is still using the layer type value to render metatiles, and with
// no mask set every metatile will be "Middle/Top", so just display the combo
// box but prevent the user from changing the value.
this->ui->comboBox_layerType->setEnabled(false);
this->ui->comboBox_LayerType->setEnabled(false);
}
} else {
this->ui->comboBox_layerType->setVisible(false);
this->ui->label_layerType->setVisible(false);
this->ui->frame_LayerType->setVisible(false);
this->ui->label_BottomTop->setText("Bottom/Middle/Top");
}
// Raw attributes value
ui->spinBox_rawAttributesValue->setMaximum(Metatile::getMaxAttributesMask());
ui->spinBox_RawAttributesValue->setMaximum(Metatile::getMaxAttributesMask());
setRawAttributesVisible(ui->actionShow_Raw_Metatile_Attributes->isChecked());
connect(ui->spinBox_rawAttributesValue, &UIntHexSpinBox::editingFinished, this, &TilesetEditor::onRawAttributesEdited);
connect(ui->spinBox_RawAttributesValue, &UIntHexSpinBox::editingFinished, this, &TilesetEditor::onRawAttributesEdited);
connect(ui->actionShow_Raw_Metatile_Attributes, &QAction::toggled, this, &TilesetEditor::setRawAttributesVisible);
this->ui->frame_Properties->adjustSize();
}
void TilesetEditor::setRawAttributesVisible(bool visible) {
porymapConfig.showTilesetEditorRawAttributes = visible;
ui->label_rawAttributesValue->setVisible(visible);
ui->spinBox_rawAttributesValue->setVisible(visible);
ui->frame_RawAttributesValue->setVisible(visible);
rebuildMetatilePropertiesFrame();
}
void TilesetEditor::initMetatileSelector()
@@ -262,25 +258,51 @@ void TilesetEditor::setMetatileLayerOrientation(Qt::Orientation orientation) {
int w = Tile::pixelWidth() * numTilesWide * scale + 2;
int h = Tile::pixelHeight() * numTilesTall * scale + 2;
ui->graphicsView_selectedTile->setFixedSize(w, h);
ui->graphicsView_metatileLayers->setFixedSize(w, h);
ui->graphicsView_MetatileLayers->setFixedSize(w, h);
// If the layers are laid out vertically then the orientation is obvious, no need to label them.
// This also lets us give the vertical space of the label over to the layer view.
ui->label_BottomTop->setVisible(horizontal);
// Let the graphics view take over the label's vertical space (or conversely, give the space back).
// (This is a bit of a process, apparently there's no quick way to set a widget's row / row span once they're added to the layout
int row, col, rowSpan, colSpan;
int index = ui->gridLayout_MetatileProperties->indexOf(ui->label_BottomTop);
ui->gridLayout_MetatileProperties->getItemPosition(index, &row, &col, &rowSpan, &colSpan);
rebuildMetatilePropertiesFrame();
}
// TODO: Rearrange the rest of the metatile properties panel. The vertical triple-layer metatiles layout esp. looks terrible.
ui->gridLayout_MetatileProperties->removeWidget(ui->graphicsView_metatileLayers);
if (horizontal) {
// Give space from graphics view back to label
ui->gridLayout_MetatileProperties->addWidget(ui->graphicsView_metatileLayers, row + 1, col, rowSpan, colSpan);
// We rearrange the metatile properties panel depending on the orientation and size of the metatile layer view.
// If triple layer metatiles are in-use then layer type field is hidden, so there's an awkward amount of space
// next to the layer view, especially in the vertical orientation.
// We shift 1-2 widgets up to fill this space next to the layer view. This gets a little complicated because which
// widgets are available to move changes depending on the user's settings.
void TilesetEditor::rebuildMetatilePropertiesFrame() {
if (porymapConfig.tilesetEditorLayerOrientation == Qt::Horizontal) {
this->numLayerViewRows = 1;
} else {
// Take space from label and give it to graphics view
ui->gridLayout_MetatileProperties->addWidget(ui->graphicsView_metatileLayers, row, col, rowSpan + 1, colSpan);
this->numLayerViewRows = projectConfig.tripleLayerMetatilesEnabled ? 4 : 2;
}
for (const auto &frame : ui->gridLayout_MetatileProperties->findChildren<QFrame*>()) {
ui->gridLayout_MetatileProperties->removeWidget(frame);
}
ui->gridLayout_MetatileProperties->addWidget(ui->frame_Layers, 0, 0, this->numLayerViewRows, 1);
int row = 0;
addWidgetToMetatileProperties(ui->frame_LayerType, &row, 2);
if (porymapConfig.tilesetEditorLayerOrientation == Qt::Horizontal) {
// When the layer view's orientation is horizontal we only allow the
// layer type selector to share the row with the layer view.
row = this->numLayerViewRows;
}
addWidgetToMetatileProperties(ui->frame_MetatileBehavior, &row, 2);
addWidgetToMetatileProperties(ui->frame_EncounterType, &row, 2);
addWidgetToMetatileProperties(ui->frame_TerrainType, &row, 2);
addWidgetToMetatileProperties(ui->frame_RawAttributesValue, &row, 2);
addWidgetToMetatileProperties(ui->frame_MetatileLabel, &row, 2);
}
void TilesetEditor::addWidgetToMetatileProperties(QWidget *w, int *row, int rowSpan) {
if (w->isVisibleTo(ui->frame_Properties)) {
int col = (*row < this->numLayerViewRows) ? 1 : 0; // Shift widget over if it shares the row with the layer view
ui->gridLayout_MetatileProperties->addWidget(w, *row, col, rowSpan, -1);
*row += rowSpan;
}
}
@@ -299,7 +321,7 @@ void TilesetEditor::initMetatileLayersItem() {
this->metatileLayersScene = new QGraphicsScene;
this->metatileLayersScene->addItem(this->metatileLayersItem);
this->ui->graphicsView_metatileLayers->setScene(this->metatileLayersScene);
this->ui->graphicsView_MetatileLayers->setScene(this->metatileLayersScene);
}
void TilesetEditor::initTileSelector() {
@@ -478,8 +500,8 @@ void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
this->metatileLayersItem->draw();
MetatileLabelPair labels = Tileset::getMetatileLabelPair(metatileId, this->primaryTileset, this->secondaryTileset);
this->ui->lineEdit_metatileLabel->setText(labels.owned);
this->ui->lineEdit_metatileLabel->setPlaceholderText(labels.shared);
this->ui->lineEdit_MetatileLabel->setText(labels.owned);
this->ui->lineEdit_MetatileLabel->setPlaceholderText(labels.shared);
refreshMetatileAttributes();
}
@@ -598,12 +620,7 @@ void TilesetEditor::refreshTileFlips() {
void TilesetEditor::setMetatileLabel(QString label)
{
this->ui->lineEdit_metatileLabel->setText(label);
commitMetatileLabel();
}
void TilesetEditor::on_lineEdit_metatileLabel_editingFinished()
{
this->ui->lineEdit_MetatileLabel->setText(label);
commitMetatileLabel();
}
@@ -613,7 +630,7 @@ void TilesetEditor::commitMetatileLabel() {
// Only commit if the field has changed.
uint16_t metatileId = this->getSelectedMetatileId();
QString oldLabel = Tileset::getOwnedMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset);
QString newLabel = this->ui->lineEdit_metatileLabel->text();
QString newLabel = this->ui->lineEdit_MetatileLabel->text();
if (oldLabel != newLabel) {
Metatile *prevMetatile = new Metatile(*this->metatile);
Tileset::setMetatileLabel(metatileId, newLabel, this->primaryTileset, this->secondaryTileset);
@@ -626,12 +643,12 @@ void TilesetEditor::commitMetatileAndLabelChange(Metatile * prevMetatile, QStrin
commit(new MetatileHistoryItem(this->getSelectedMetatileId(),
prevMetatile, new Metatile(*this->metatile),
prevLabel, this->ui->lineEdit_metatileLabel->text()));
prevLabel, this->ui->lineEdit_MetatileLabel->text()));
}
void TilesetEditor::commitMetatileChange(Metatile * prevMetatile)
{
this->commitMetatileAndLabelChange(prevMetatile, this->ui->lineEdit_metatileLabel->text());
this->commitMetatileAndLabelChange(prevMetatile, this->ui->lineEdit_MetatileLabel->text());
}
uint32_t TilesetEditor::attributeNameToValue(Metatile::Attr attribute, const QString &text, bool *ok) {
@@ -650,7 +667,7 @@ uint32_t TilesetEditor::attributeNameToValue(Metatile::Attr attribute, const QSt
}
} else if (attribute == Metatile::Attr::LayerType) {
// The layer type text is not editable, it uses special display names. Just get the index of the display name.
int i = ui->comboBox_layerType->findText(text);
int i = ui->comboBox_LayerType->findText(text);
if (i >= 0) return i;
}
return text.toUInt(ok, 0);
@@ -667,8 +684,8 @@ void TilesetEditor::commitAttributeFromComboBox(Metatile::Attr attribute, NoScro
this->commitMetatileChange(prevMetatile);
// When an attribute changes we also need to update the raw value display.
const QSignalBlocker b_RawAttributesValue(ui->spinBox_rawAttributesValue);
ui->spinBox_rawAttributesValue->setValue(this->metatile->getAttributes());
const QSignalBlocker b_RawAttributesValue(ui->spinBox_RawAttributesValue);
ui->spinBox_RawAttributesValue->setValue(this->metatile->getAttributes());
}
// Update the text in the combo box to reflect the final value.
@@ -680,7 +697,7 @@ void TilesetEditor::commitAttributeFromComboBox(Metatile::Attr attribute, NoScro
void TilesetEditor::onRawAttributesEdited() {
if (!this->metatile) return;
uint32_t newAttributes = ui->spinBox_rawAttributesValue->value();
uint32_t newAttributes = ui->spinBox_RawAttributesValue->value();
if (newAttributes != this->metatile->getAttributes()) {
Metatile *prevMetatile = new Metatile(*this->metatile);
this->metatile->setAttributes(newAttributes);
@@ -692,34 +709,34 @@ void TilesetEditor::onRawAttributesEdited() {
void TilesetEditor::refreshMetatileAttributes() {
if (!this->metatile) return;
const QSignalBlocker b_MetatileBehaviors(ui->comboBox_metatileBehaviors);
const QSignalBlocker b_EncounterType(ui->comboBox_encounterType);
const QSignalBlocker b_TerrainType(ui->comboBox_terrainType);
const QSignalBlocker b_LayerType(ui->comboBox_layerType);
const QSignalBlocker b_RawAttributesValue(ui->spinBox_rawAttributesValue);
ui->comboBox_metatileBehaviors->setHexItem(this->metatile->behavior());
ui->comboBox_encounterType->setHexItem(this->metatile->encounterType());
ui->comboBox_terrainType->setHexItem(this->metatile->terrainType());
ui->comboBox_layerType->setHexItem(this->metatile->layerType());
ui->spinBox_rawAttributesValue->setValue(this->metatile->getAttributes());
const QSignalBlocker b_MetatileBehaviors(ui->comboBox_MetatileBehaviors);
const QSignalBlocker b_EncounterType(ui->comboBox_EncounterType);
const QSignalBlocker b_TerrainType(ui->comboBox_TerrainType);
const QSignalBlocker b_LayerType(ui->comboBox_LayerType);
const QSignalBlocker b_RawAttributesValue(ui->spinBox_RawAttributesValue);
ui->comboBox_MetatileBehaviors->setHexItem(this->metatile->behavior());
ui->comboBox_EncounterType->setHexItem(this->metatile->encounterType());
ui->comboBox_TerrainType->setHexItem(this->metatile->terrainType());
ui->comboBox_LayerType->setHexItem(this->metatile->layerType());
ui->spinBox_RawAttributesValue->setValue(this->metatile->getAttributes());
this->metatileSelector->drawSelectedMetatile();
}
void TilesetEditor::commitMetatileBehavior() {
commitAttributeFromComboBox(Metatile::Attr::Behavior, ui->comboBox_metatileBehaviors);
commitAttributeFromComboBox(Metatile::Attr::Behavior, ui->comboBox_MetatileBehaviors);
}
void TilesetEditor::commitEncounterType() {
commitAttributeFromComboBox(Metatile::Attr::EncounterType, ui->comboBox_encounterType);
commitAttributeFromComboBox(Metatile::Attr::EncounterType, ui->comboBox_EncounterType);
}
void TilesetEditor::commitTerrainType() {
commitAttributeFromComboBox(Metatile::Attr::TerrainType, ui->comboBox_terrainType);
commitAttributeFromComboBox(Metatile::Attr::TerrainType, ui->comboBox_TerrainType);
};
void TilesetEditor::commitLayerType() {
commitAttributeFromComboBox(Metatile::Attr::LayerType, ui->comboBox_layerType);
commitAttributeFromComboBox(Metatile::Attr::LayerType, ui->comboBox_LayerType);
this->metatileSelector->drawSelectedMetatile(); // Changing the layer type can affect how fully transparent metatiles appear
}
@@ -919,7 +936,7 @@ bool TilesetEditor::replaceMetatile(uint16_t metatileId, const Metatile &src, QS
Tileset::setMetatileLabel(metatileId, newLabel, this->primaryTileset, this->secondaryTileset);
if (metatileId == this->getSelectedMetatileId())
this->ui->lineEdit_metatileLabel->setText(newLabel);
this->ui->lineEdit_MetatileLabel->setText(newLabel);
// Update tile usage if any tiles changed
if (this->tileSelector && this->tileSelector->showUnused) {
@@ -1023,7 +1040,7 @@ void TilesetEditor::pasteMetatile(const Metatile &toPaste, QString newLabel) {
if (!this->metatile) return;
Metatile *prevMetatile = new Metatile(*this->metatile);
QString prevLabel = this->ui->lineEdit_metatileLabel->text();
QString prevLabel = this->ui->lineEdit_MetatileLabel->text();
if (newLabel.isNull()) newLabel = prevLabel; // Don't change the label if one wasn't copied
uint16_t metatileId = this->getSelectedMetatileId();
if (!this->replaceMetatile(metatileId, toPaste, newLabel)) {
@@ -1246,7 +1263,7 @@ void TilesetEditor::countTileUsage() {
}
}
void TilesetEditor::on_copyButton_metatileLabel_clicked() {
void TilesetEditor::on_copyButton_MetatileLabel_clicked() {
uint16_t metatileId = this->getSelectedMetatileId();
QString label = Tileset::getMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset);
if (label.isEmpty()) return;
@@ -1254,7 +1271,7 @@ void TilesetEditor::on_copyButton_metatileLabel_clicked() {
if (tileset)
label.prepend(tileset->getMetatileLabelPrefix());
QGuiApplication::clipboard()->setText(label);
QToolTip::showText(this->ui->copyButton_metatileLabel->mapToGlobal(QPoint(0, 0)), "Copied!");
QToolTip::showText(this->ui->copyButton_MetatileLabel->mapToGlobal(QPoint(0, 0)), "Copied!");
}
void TilesetEditor::on_horizontalSlider_MetatilesZoom_valueChanged(int value) {