Skip to content

Commit

Permalink
Add checkboxes for special properties of Extra Prop Byte 2
Browse files Browse the repository at this point in the history
Also now you can use PgUp and PgDown to change palette in the floating 8x8 view
  • Loading branch information
Atari2 committed Mar 16, 2024
1 parent 9cd68b1 commit ec6e555
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 27 deletions.
46 changes: 42 additions & 4 deletions cfgeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CFGEditor::CFGEditor(const QStringList& argv, QWidget *parent)
setSizePolicy(QSizePolicy());
statusBar()->setSizeGripEnabled(false);
setUpImages();
view8x8Container = new EightByEightViewContainer(new EightByEightView(new QGraphicsScene));
view8x8Container = new EightByEightViewContainer(new EightByEightView(new QGraphicsScene), this->ui->paletteComboBox);
paletteContainer = new PaletteContainer(new PaletteView(new QGraphicsScene));
ui->labelDisplayTilesGrid->attachMap16View(ui->map16GraphicsView);
loadFullbitmap();
Expand Down Expand Up @@ -72,7 +72,7 @@ void CFGEditor::initCompleter() {
hexCompleter->setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
}

void CFGEditor::loadFullbitmap(int index) {
void CFGEditor::loadFullbitmap(int index, bool justPalette) {
if (index == -1)
index = ui->paletteComboBox->currentIndex();
QVector<QString> gfxFiles{ui->lineEditGFXSp0->text(), ui->lineEditGFXSp1->text(), ui->lineEditGFXSp2->text(), ui->lineEditGFXSp3->text()};
Expand All @@ -93,9 +93,13 @@ void CFGEditor::loadFullbitmap(int index) {
p.drawImage(QRect{0, i, 128, 64}, img, QRect{0, 0, img.width(), img.height()});
i += 64;
}
ui->map16GraphicsView->readInternalMap16File();
if (!justPalette) {
ui->map16GraphicsView->readInternalMap16File();
}
view8x8Container->updateForChange(full8x8Bitmap, true);
ui->labelDisplayTilesGrid->redraw();
if (!justPalette) {
ui->labelDisplayTilesGrid->redraw();
}
}

void CFGEditor::setUpMenuBar(QMenuBar* mb) {
Expand Down Expand Up @@ -950,6 +954,9 @@ void CFGEditor::setupForNormal() {
ui->lineEditExtraProp2->setEnabled(false);
ui->spinBoxextraBitClear->setEnabled(false);
ui->spinBoxextraBitSet->setEnabled(false);

ui->extraPropByte2Bit6CheckBox->setEnabled(false);
ui->extraPropByte2Bit7CheckBox->setEnabled(false);
}

void CFGEditor::setupForCustom() {
Expand All @@ -961,6 +968,9 @@ void CFGEditor::setupForCustom() {
ui->spinBoxextraBitClear->setEnabled(true);
ui->spinBoxextraBitSet->setEnabled(true);

ui->extraPropByte2Bit6CheckBox->setEnabled(true);
ui->extraPropByte2Bit7CheckBox->setEnabled(true);

}

void CFGEditor::setupForGenShootOther() {
Expand All @@ -971,6 +981,9 @@ void CFGEditor::setupForGenShootOther() {
ui->lineEditExtraProp2->setEnabled(true);
ui->spinBoxextraBitClear->setEnabled(true);
ui->spinBoxextraBitSet->setEnabled(true);

ui->extraPropByte2Bit6CheckBox->setEnabled(false);
ui->extraPropByte2Bit7CheckBox->setEnabled(false);
}

void CFGEditor::changeAllCheckBoxState(bool state) {
Expand Down Expand Up @@ -1038,6 +1051,12 @@ void CFGEditor::bindSpriteProp() {
});
QObject::connect(ui->lineEditExtraProp2, &QLineEdit::editingFinished, this, [&]() {
sprite->extraProp2 = (uint8_t)ui->lineEditExtraProp2->text().toUInt(nullptr, 16);
{
QSignalBlocker blocker1{ui->extraPropByte2Bit6CheckBox};
QSignalBlocker blocker2{ui->extraPropByte2Bit7CheckBox};
ui->extraPropByte2Bit6CheckBox->setCheckState(sprite->extraProp2 & 0x40 ? Qt::Checked : Qt::Unchecked);
ui->extraPropByte2Bit7CheckBox->setCheckState(sprite->extraProp2 & 0x80 ? Qt::Checked : Qt::Unchecked);
}
});
// Type
QObject::connect(ui->comboBoxType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [&](int index) {
Expand Down Expand Up @@ -1091,6 +1110,24 @@ void CFGEditor::bindSpriteProp() {
bindTweak1686();
// 190F
bindTweak190F();

QObject::connect(ui->extraPropByte2Bit6CheckBox, &QCheckBox::stateChanged, this, [&](int state) {
if (state == Qt::Checked) {
sprite->extraProp2 |= 0x40;
} else {
sprite->extraProp2 &= ~0x40;
}
ui->lineEditExtraProp2->setText(QString::asprintf("%02X", sprite->extraProp2));
});

QObject::connect(ui->extraPropByte2Bit7CheckBox, &QCheckBox::stateChanged, this, [&](int state) {
if (state == Qt::Checked) {
sprite->extraProp2 |= 0x80;
} else {
sprite->extraProp2 &= ~0x80;
}
ui->lineEditExtraProp2->setText(QString::asprintf("%02X", sprite->extraProp2));
});
}

void CFGEditor::bindTweak1656() {
Expand Down Expand Up @@ -1167,6 +1204,7 @@ void CFGEditor::bindTweak166E() {
ui->label->setPixmap(paletteImages[index].scaled(ui->label->size(), Qt::AspectRatioMode::KeepAspectRatio));
sprite->t166e.palette = index;
ui->lineEdit166E->setText(QString::asprintf("%02X", sprite->t166e.to_byte()));
loadFullbitmap(-1, true);
});
}
void CFGEditor::bindTweak167A() {
Expand Down
2 changes: 1 addition & 1 deletion cfgeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CFGEditor : public QMainWindow
void bindDisplayButtons();
void bindGFXSelector();
void initCompleter();
void loadFullbitmap(int index = -1);
void loadFullbitmap(int index = -1, bool justPalette = false);
void addLunarMagicIcons();
void closeEvent(QCloseEvent *event);
void advanceDisplayIndex();
Expand Down
44 changes: 35 additions & 9 deletions cfgeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@
<rect>
<x>10</x>
<y>10</y>
<width>161</width>
<width>141</width>
<height>21</height>
</rect>
</property>
Expand All @@ -1790,20 +1790,20 @@
<widget class="QLabel" name="asmFileLabel_3">
<property name="geometry">
<rect>
<x>340</x>
<x>210</x>
<y>10</y>
<width>61</width>
<width>20</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Byte 2:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;2:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEditExtraProp1">
<property name="geometry">
<rect>
<x>270</x>
<x>170</x>
<y>10</y>
<width>41</width>
<height>21</height>
Expand All @@ -1822,7 +1822,7 @@
<widget class="QLineEdit" name="lineEditExtraProp2">
<property name="geometry">
<rect>
<x>410</x>
<x>240</x>
<y>10</y>
<width>41</width>
<height>21</height>
Expand All @@ -1841,14 +1841,40 @@
<widget class="QLabel" name="asmFileLabel_4">
<property name="geometry">
<rect>
<x>200</x>
<x>140</x>
<y>10</y>
<width>61</width>
<width>20</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Byte 1:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;1:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QCheckBox" name="extraPropByte2Bit7CheckBox">
<property name="geometry">
<rect>
<x>290</x>
<y>0</y>
<width>181</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Run MAIN code in any state</string>
</property>
</widget>
<widget class="QCheckBox" name="extraPropByte2Bit6CheckBox">
<property name="geometry">
<rect>
<x>290</x>
<y>20</y>
<width>221</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Run both MAIN + vanilla code always</string>
</property>
</widget>
</widget>
Expand Down
1 change: 1 addition & 0 deletions clipboardtile.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "clipboardtile.h"
#include <QFileSystemWatcher>


TileInfo::TileInfo(quint16 info) {
Expand Down
38 changes: 38 additions & 0 deletions eightbyeightview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
#include "eightbyeightview.h"
#include "eightbyeightviewcontainer.h"

PgUpDownEventFilter::PgUpDownEventFilter(QObject* parent) : QObject{parent} {

}

bool PgUpDownEventFilter::eventFilter(QObject* obj, QEvent* event) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_PageDown || keyEvent->key() == Qt::Key_PageUp) {
return true;
}
return false;
} else {
return QObject::eventFilter(obj, event);
}
}

void EightByEightView::keyPressEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_PageDown) {
auto new_index = m_paletteComboBox->currentIndex() + 1;
if (new_index < m_paletteComboBox->count()) {
m_paletteComboBox->setCurrentIndex(new_index);
}
event->accept();
} else if (event->key() == Qt::Key_PageUp) {
auto new_index = m_paletteComboBox->currentIndex() - 1;
if (new_index > 0) {
m_paletteComboBox->setCurrentIndex(new_index);
}
event->accept();
}
}

EightByEightView::EightByEightView(QGraphicsScene* ogscene) : QGraphicsView(ogscene) {
setMouseTracking(true);
viewport()->setMouseTracking(true);
Expand All @@ -12,6 +44,7 @@ EightByEightView::EightByEightView(QGraphicsScene* ogscene) : QGraphicsView(ogsc
if (offset != 0)
verticalScrollBar()->setValue(value - offset);
});
verticalScrollBar()->installEventFilter(new PgUpDownEventFilter(this));
setFixedSize(275, 256);
}

Expand All @@ -24,6 +57,10 @@ int EightByEightView::convertPointToTile(const QPointF& point) {
return (((inty / 16) * 16) + ((scrollbary / 16) * 16)) + (intx / 16);
}

void EightByEightView::setComboBox(QComboBox* comboBox) {
m_paletteComboBox = comboBox;
}

void EightByEightView::mouseMoveEvent(QMouseEvent *event) {
if (!m_open || !hasFocus()) {
event->ignore();
Expand All @@ -36,6 +73,7 @@ void EightByEightView::open() {
m_open = true;
show();
raise();
verticalScrollBar()->setFocusPolicy(Qt::NoFocus);
}

void EightByEightView::close(QCloseEvent *event) {
Expand Down
14 changes: 14 additions & 0 deletions eightbyeightview.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,32 @@
#include <QTimer>
#include <QScrollBar>
#include <QToolTip>
#include <QComboBox>

class PgUpDownEventFilter : public QObject {
Q_OBJECT

public:
PgUpDownEventFilter(QObject* parent = nullptr);

protected:
bool eventFilter(QObject* obj, QEvent* event) override;
};

class EightByEightView : public QGraphicsView
{
public:
EightByEightView(QGraphicsScene* scene);
void updateForChange(QImage* image);
void setComboBox(QComboBox* comboBox);
void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent* event) override;
~EightByEightView();
void open();
void close(QCloseEvent* event);
private:
QGraphicsPixmapItem* currentItem = nullptr;
QComboBox* m_paletteComboBox = nullptr;
bool m_open = false;
void closeEvent(QCloseEvent* event);
int convertPointToTile(const QPointF& point);
Expand Down
17 changes: 9 additions & 8 deletions eightbyeightviewcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#include <QLabel>
#include <QIcon>

EightByEightViewContainer::EightByEightViewContainer(EightByEightView* view, QWidget *parent) : QWidget(parent), m_view(view)
EightByEightViewContainer::EightByEightViewContainer(EightByEightView* view, QComboBox* paletteComboBox, QWidget *parent) : QWidget(parent), m_view(view)
{
setWindowIcon(QIcon{":/Resources/ButtonIcons/8x8.png"});
setWindowTitle("8x8 Tile Viewer");
setWindowTitle("8x8 Tile Viewer");
auto layout = new QVBoxLayout(this);
setLayout(layout);
m_view->setComboBox(paletteComboBox);
layout->addWidget(m_view);
label = new QLabel(this);
label->setText("Tile 000");
Expand All @@ -19,12 +20,12 @@ EightByEightViewContainer::EightByEightViewContainer(EightByEightView* view, QWi
}

void EightByEightViewContainer::updateForChange(QImage* image, bool firstTime) {
m_view->updateForChange(image);
if (!firstTime) {
m_view->open();
show();
raise();
}
m_view->updateForChange(image);
if (!firstTime) {
m_view->open();
show();
raise();
}
}

void EightByEightViewContainer::closeEvent(QCloseEvent *event) {
Expand Down
9 changes: 5 additions & 4 deletions eightbyeightviewcontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@

#include <QWidget>
#include <QLabel>
#include <QComboBox>

class EightByEightView;

class EightByEightViewContainer : public QWidget
{
Q_OBJECT
public:
explicit EightByEightViewContainer(EightByEightView* view, QWidget *parent = nullptr);
explicit EightByEightViewContainer(EightByEightView* view, QComboBox* paletteComboBox, QWidget *parent = nullptr);
void updateForChange(QImage* image, bool firstTime = false);
void closeEvent(QCloseEvent* event);
void updateTileLabel(const QString& tile);
void closeEvent(QCloseEvent* event) override;
void updateTileLabel(const QString& tile);
signals:

private:
EightByEightView* m_view = nullptr;
QLabel* label = nullptr;
QLabel* label = nullptr;
};

#endif // EIGHTBYEIGHTVIEWCONTAINER_H
2 changes: 1 addition & 1 deletion palettecontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PaletteContainer : public QWidget
Q_OBJECT
public:
explicit PaletteContainer(PaletteView* view, QWidget *parent = nullptr);
void updateContainer(const QPixmap& image);
void updateContainer(const QPixmap& image);
signals:
void paletteChanged();
private:
Expand Down

0 comments on commit ec6e555

Please sign in to comment.