Add raw metatile attributes editor

This commit is contained in:
GriffinR
2025-03-26 22:46:24 -04:00
parent 5cd53be057
commit c6a389b9cb
6 changed files with 252 additions and 159 deletions

View File

@@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>727</width>
<height>700</height>
<width>733</width>
<height>784</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
<enum>Qt::FocusPolicy::ClickFocus</enum>
</property>
<property name="windowTitle">
<string>Tileset Editor</string>
@@ -21,7 +21,7 @@
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
@@ -34,10 +34,10 @@
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<enum>QFrame::Shadow::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
@@ -58,15 +58,15 @@
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
<set>Qt::AlignmentFlag::AlignHCenter|Qt::AlignmentFlag::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_Metatiles">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>223</width>
<height>593</height>
<width>239</width>
<height>659</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@@ -88,17 +88,17 @@
<item row="0" column="0">
<widget class="NoScrollGraphicsView" name="graphicsView_Metatiles">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -121,7 +121,7 @@
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -129,10 +129,10 @@
</widget>
<widget class="QFrame" name="frame_Editing">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
@@ -162,14 +162,14 @@
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
<enum>QLayout::SizeConstraint::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
@@ -195,6 +195,70 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<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">
<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 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">
<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 row="1" column="0">
<widget class="QGraphicsView" name="graphicsView_metatileLayers">
<property name="sizePolicy">
@@ -216,10 +280,10 @@
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
@@ -236,15 +300,18 @@
</property>
</widget>
</item>
<item row="14" column="0">
<spacer name="verticalSpacer_7">
<item row="1" column="1">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
@@ -262,14 +329,28 @@
</property>
</widget>
</item>
<item row="12" column="0" colspan="5">
<widget class="QLabel" name="label_metatileLabel">
<item row="2" column="0" colspan="5">
<widget class="QLabel" name="label_metatileBehavior">
<property name="text">
<string>Metatile Label (Optional)</string>
<string>Metatile Behavior</string>
</property>
</widget>
</item>
<item row="13" column="4">
<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>
@@ -283,92 +364,21 @@
</property>
</widget>
</item>
<item row="1" column="2" colspan="3">
<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 row="7" column="0" colspan="5">
<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 row="0" column="2" colspan="3">
<widget class="QLabel" name="label_layerType">
<property name="text">
<string>Layer Type</string>
</property>
</widget>
</item>
<item row="13" column="0" colspan="4">
<widget class="QLineEdit" name="lineEdit_metatileLabel">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</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="1" column="1">
<spacer name="horizontalSpacer_5">
<item row="16" column="0">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</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="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="0">
<widget class="QLabel" name="label_BottomTop">
<property name="text">
<string>Bottom/Top</string>
</property>
</widget>
<item row="13" column="0" colspan="5">
<widget class="UIntHexSpinBox" name="spinBox_rawAttributesValue"/>
</item>
</layout>
</widget>
@@ -408,7 +418,7 @@
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_xFlip">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
<enum>Qt::LayoutDirection::LeftToRight</enum>
</property>
<property name="text">
<string/>
@@ -432,10 +442,10 @@
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -460,10 +470,10 @@
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<enum>QFrame::Shadow::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
@@ -506,13 +516,13 @@
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
@@ -522,7 +532,7 @@
<item row="6" column="0" colspan="2">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -544,15 +554,15 @@
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
<set>Qt::AlignmentFlag::AlignHCenter|Qt::AlignmentFlag::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_Tiles">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>455</width>
<height>232</height>
<width>445</width>
<height>237</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
@@ -571,17 +581,17 @@
<item row="0" column="0">
<widget class="NoScrollGraphicsView" name="graphicsView_Tiles">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -598,7 +608,7 @@
<item>
<widget class="QSlider" name="horizontalSlider_TilesZoom">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -613,8 +623,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>727</width>
<height>22</height>
<width>733</width>
<height>37</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -657,6 +667,7 @@
<addaction name="actionLayer_Grid"/>
<addaction name="actionMetatile_Grid"/>
<addaction name="actionShow_Tileset_Divider"/>
<addaction name="actionShow_Raw_Metatile_Attributes"/>
<addaction name="separator"/>
<addaction name="actionShow_Counts"/>
<addaction name="actionShow_Unused"/>
@@ -817,6 +828,14 @@
<string>Show Tileset Divider</string>
</property>
</action>
<action name="actionShow_Raw_Metatile_Attributes">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Raw Metatile Attributes</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
@@ -829,6 +848,16 @@
<extends>QGraphicsView</extends>
<header>mapview.h</header>
</customwidget>
<customwidget>
<class>UIntSpinBox</class>
<extends>QAbstractSpinBox</extends>
<header>uintspinbox.h</header>
</customwidget>
<customwidget>
<class>UIntHexSpinBox</class>
<extends>UIntSpinBox</extends>
<header location="global">uintspinbox.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/images.qrc"/>

View File

@@ -72,6 +72,7 @@ public:
this->showTilesetEditorMetatileGrid = false;
this->showTilesetEditorLayerGrid = true;
this->showTilesetEditorDivider = false;
this->showTilesetEditorRawAttributes = false;
this->monitorFiles = true;
this->tilesetCheckerboardFill = true;
this->newMapHeaderSectionExpanded = false;
@@ -132,6 +133,7 @@ public:
bool showTilesetEditorMetatileGrid;
bool showTilesetEditorLayerGrid;
bool showTilesetEditorDivider;
bool showTilesetEditorRawAttributes;
bool monitorFiles;
bool tilesetCheckerboardFill;
bool newMapHeaderSectionExpanded;

View File

@@ -97,8 +97,6 @@ private slots:
void on_lineEdit_metatileLabel_editingFinished();
void on_comboBox_layerType_activated(int arg1);
void on_actionExport_Primary_Tiles_Image_triggered();
void on_actionExport_Secondary_Tiles_Image_triggered();
void on_actionExport_Primary_Metatiles_Image_triggered();
@@ -116,7 +114,7 @@ private slots:
void on_horizontalSlider_TilesZoom_valueChanged(int value);
private:
void setAttributesUi();
void initAttributesUi();
void initMetatileSelector();
void initTileSelector();
void initSelectedTileItem();
@@ -143,7 +141,14 @@ private:
void commitMetatileChange(Metatile * prevMetatile);
void commitMetatileAndLabelChange(Metatile * prevMetatile, QString prevLabel);
uint32_t attributeNameToValue(Metatile::Attr attribute, const QString &text, bool *ok);
void setAttributeFromComboBox(Metatile::Attr attribute, NoScrollComboBox *combo);
void commitAttributeFromComboBox(Metatile::Attr attribute, NoScrollComboBox *combo);
void onRawAttributesEdited();
void refreshMetatileAttributes();
void commitMetatileBehavior();
void commitEncounterType();
void commitTerrainType();
void commitLayerType();
void setRawAttributesVisible(bool visible);
Ui::TilesetEditor *ui;
History<MetatileHistoryItem*> metatileHistory;

View File

@@ -388,6 +388,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->showTilesetEditorLayerGrid = getConfigBool(key, value);
} else if (key == "show_tileset_editor_divider") {
this->showTilesetEditorDivider = getConfigBool(key, value);
} else if (key == "show_tileset_editor_raw_attributes") {
this->showTilesetEditorRawAttributes = getConfigBool(key, value);
} else if (key == "monitor_files") {
this->monitorFiles = getConfigBool(key, value);
} else if (key == "tileset_checkerboard_fill") {
@@ -497,6 +499,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
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("show_tileset_editor_raw_attributes", this->showTilesetEditorRawAttributes ? "1" : "0");
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0");
map.insert("new_map_header_section_expanded", this->newMapHeaderSectionExpanded ? "1" : "0");

View File

@@ -10,11 +10,11 @@ static const QMap<Metatile::Attr, BitPacker> attributePackersFRLG = {
{Metatile::Attr::TerrainType, BitPacker(0x00003E00) },
{Metatile::Attr::EncounterType, BitPacker(0x07000000) },
{Metatile::Attr::LayerType, BitPacker(0x60000000) },
//{Metatile::Attr::Unused, BitPacker(0x98FFC000) },
{Metatile::Attr::Unused, BitPacker(0x98FFC000) },
};
static const QMap<Metatile::Attr, BitPacker> attributePackersRSE = {
{Metatile::Attr::Behavior, BitPacker(0x00FF) },
//{Metatile::Attr::Unused, BitPacker(0x0F00) },
{Metatile::Attr::Unused, BitPacker(0x0F00) },
{Metatile::Attr::LayerType, BitPacker(0xF000) },
};

View File

@@ -32,6 +32,8 @@ TilesetEditor::TilesetEditor(Project *project, Layout *layout, QWidget *parent)
this->paletteId = ui->spinBox_paletteSelector->value();
ui->actionShow_Tileset_Divider->setChecked(porymapConfig.showTilesetEditorDivider);
ui->actionShow_Raw_Metatile_Attributes->setChecked(porymapConfig.showTilesetEditorRawAttributes);
ui->spinBox_paletteSelector->setMinimum(0);
ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1);
@@ -43,18 +45,7 @@ TilesetEditor::TilesetEditor(Project *project, Layout *layout, QWidget *parent)
connect(filter, &ActiveWindowFilter::activated, this, &TilesetEditor::onWindowActivated);
this->installEventFilter(filter);
// Update the metatile's attributes values when the attribute combo boxes are edited.
connect(ui->comboBox_metatileBehaviors->lineEdit(), &QLineEdit::editingFinished, [this] {
setAttributeFromComboBox(Metatile::Attr::Behavior, ui->comboBox_metatileBehaviors);
});
connect(ui->comboBox_encounterType->lineEdit(), &QLineEdit::editingFinished, [this] {
setAttributeFromComboBox(Metatile::Attr::EncounterType, ui->comboBox_encounterType);
});
connect(ui->comboBox_terrainType->lineEdit(), &QLineEdit::editingFinished, [this] {
setAttributeFromComboBox(Metatile::Attr::TerrainType, ui->comboBox_terrainType);
});
setAttributesUi();
initAttributesUi();
initMetatileSelector();
initMetatileLayersItem();
initTileSelector();
@@ -131,7 +122,18 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi
this->initMetatileHistory();
}
void TilesetEditor::setAttributesUi() {
void TilesetEditor::initAttributesUi() {
// Update the metatile's attributes values when the attribute combo boxes are edited.
// We avoid using the 'currentTextChanged' signal here, we want to know when we can clean up the input field and commit changes.
connect(ui->comboBox_metatileBehaviors->lineEdit(), &QLineEdit::editingFinished, this, &TilesetEditor::commitMetatileBehavior);
connect(ui->comboBox_encounterType->lineEdit(), &QLineEdit::editingFinished, this, &TilesetEditor::commitEncounterType);
connect(ui->comboBox_terrainType->lineEdit(), &QLineEdit::editingFinished, this, &TilesetEditor::commitTerrainType);
connect(ui->comboBox_layerType->lineEdit(), &QLineEdit::editingFinished, this, &TilesetEditor::commitLayerType);
connect(ui->comboBox_metatileBehaviors, &QComboBox::activated, this, &TilesetEditor::commitMetatileBehavior);
connect(ui->comboBox_encounterType, &QComboBox::activated, this, &TilesetEditor::commitEncounterType);
connect(ui->comboBox_terrainType, &QComboBox::activated, this, &TilesetEditor::commitTerrainType);
connect(ui->comboBox_layerType, &QComboBox::activated, this, &TilesetEditor::commitLayerType);
// Behavior
if (projectConfig.metatileBehaviorMask) {
for (auto i = project->metatileBehaviorMapInverse.constBegin(); i != project->metatileBehaviorMapInverse.constEnd(); i++) {
@@ -184,9 +186,22 @@ void TilesetEditor::setAttributesUi() {
this->ui->label_layerType->setVisible(false);
this->ui->label_BottomTop->setText("Bottom/Middle/Top");
}
// Raw attributes value
ui->spinBox_rawAttributesValue->setMaximum(Metatile::getMaxAttributesMask());
setRawAttributesVisible(ui->actionShow_Raw_Metatile_Attributes->isChecked());
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);
}
void TilesetEditor::initMetatileSelector()
{
this->metatileSelector = new TilesetEditorMetatileSelector(this->primaryTileset, this->secondaryTileset, this->layout);
@@ -421,10 +436,7 @@ void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
this->ui->lineEdit_metatileLabel->setText(labels.owned);
this->ui->lineEdit_metatileLabel->setPlaceholderText(labels.shared);
this->ui->comboBox_metatileBehaviors->setHexItem(this->metatile->behavior());
this->ui->comboBox_layerType->setHexItem(this->metatile->layerType());
this->ui->comboBox_encounterType->setHexItem(this->metatile->encounterType());
this->ui->comboBox_terrainType->setHexItem(this->metatile->terrainType());
refreshMetatileAttributes();
}
void TilesetEditor::queueMetatileReload(uint16_t metatileId) {
@@ -581,16 +593,6 @@ void TilesetEditor::commitMetatileChange(Metatile * prevMetatile)
this->commitMetatileAndLabelChange(prevMetatile, this->ui->lineEdit_metatileLabel->text());
}
void TilesetEditor::on_comboBox_layerType_activated(int layerType)
{
if (this->metatile) {
Metatile *prevMetatile = new Metatile(*this->metatile);
this->metatile->setLayerType(layerType);
this->commitMetatileChange(prevMetatile);
this->metatileSelector->drawSelectedMetatile(); // Changing the layer type can affect how fully transparent metatiles appear
}
}
uint32_t TilesetEditor::attributeNameToValue(Metatile::Attr attribute, const QString &text, bool *ok) {
if (ok) *ok = true;
if (attribute == Metatile::Attr::Behavior) {
@@ -605,11 +607,15 @@ uint32_t TilesetEditor::attributeNameToValue(Metatile::Attr attribute, const QSt
for (auto i = project->terrainTypeToName.constBegin(); i != project->terrainTypeToName.constEnd(); i++) {
if (i.value() == text) return i.key();
}
} 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);
if (i >= 0) return i;
}
return text.toUInt(ok, 0);
}
void TilesetEditor::setAttributeFromComboBox(Metatile::Attr attribute, NoScrollComboBox *combo) {
void TilesetEditor::commitAttributeFromComboBox(Metatile::Attr attribute, NoScrollComboBox *combo) {
if (!this->metatile)
return;
@@ -619,6 +625,10 @@ void TilesetEditor::setAttributeFromComboBox(Metatile::Attr attribute, NoScrollC
Metatile *prevMetatile = new Metatile(*this->metatile);
this->metatile->setAttribute(attribute, newValue);
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());
}
// Update the text in the combo box to reflect the final value.
@@ -627,6 +637,50 @@ void TilesetEditor::setAttributeFromComboBox(Metatile::Attr attribute, NoScrollC
combo->setHexItem(this->metatile->getAttribute(attribute));
}
void TilesetEditor::onRawAttributesEdited() {
uint32_t newAttributes = ui->spinBox_rawAttributesValue->value();
if (newAttributes != this->metatile->getAttributes()) {
Metatile *prevMetatile = new Metatile(*this->metatile);
this->metatile->setAttributes(newAttributes);
this->commitMetatileChange(prevMetatile);
}
refreshMetatileAttributes();
}
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());
this->metatileSelector->drawSelectedMetatile();
}
void TilesetEditor::commitMetatileBehavior() {
commitAttributeFromComboBox(Metatile::Attr::Behavior, ui->comboBox_metatileBehaviors);
}
void TilesetEditor::commitEncounterType() {
commitAttributeFromComboBox(Metatile::Attr::EncounterType, ui->comboBox_encounterType);
}
void TilesetEditor::commitTerrainType() {
commitAttributeFromComboBox(Metatile::Attr::TerrainType, ui->comboBox_terrainType);
};
void TilesetEditor::commitLayerType() {
commitAttributeFromComboBox(Metatile::Attr::LayerType, ui->comboBox_layerType);
this->metatileSelector->drawSelectedMetatile(); // Changing the layer type can affect how fully transparent metatiles appear
}
void TilesetEditor::on_actionSave_Tileset_triggered()
{
// Need this temporary flag to stop selection resetting after saving.