Skip to content

Commit

Permalink
Add 'All' settings, avoid unnecessary work in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Oct 4, 2024
1 parent 354680d commit 6e79c6c
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 69 deletions.
64 changes: 39 additions & 25 deletions forms/mapimageexporter.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>817</width>
<height>518</height>
<height>535</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -52,38 +52,45 @@
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Event_Options">
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_Warps">
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_Triggers">
<property name="text">
<string>Warps</string>
<string>Triggers</string>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_Objects">
<property name="text">
<string>Objects</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="checkBox_HealLocations">
<property name="text">
<string>Heal Locations</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_BGs">
<widget class="QCheckBox" name="checkBox_Warps">
<property name="text">
<string>BGs</string>
<string>Warps</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_Triggers">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_AllEvents">
<property name="text">
<string>Triggers</string>
<string>All</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_HealSpots">
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_BGs">
<property name="text">
<string>Heal Spots</string>
<string>BGs</string>
</property>
</widget>
</item>
Expand All @@ -100,31 +107,38 @@
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Connection_Options">
<item row="0" column="0">
<item row="1" column="2">
<widget class="QCheckBox" name="checkBox_ConnectionLeft">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_ConnectionUp">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_ConnectionDown">
<item row="1" column="3">
<widget class="QCheckBox" name="checkBox_ConnectionRight">
<property name="text">
<string>Down</string>
<string>Right</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_ConnectionLeft">
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_ConnectionDown">
<property name="text">
<string>Left</string>
<string>Down</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="checkBox_ConnectionRight">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_AllConnections">
<property name="text">
<string>Right</string>
<string>All</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -317,8 +331,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>439</height>
<width>469</width>
<height>464</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down
8 changes: 4 additions & 4 deletions include/ui/mapimageexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MapImageExporter : public QDialog
bool showWarps = false;
bool showBGs = false;
bool showTriggers = false;
bool showHealSpots = false;
bool showHealLocations = false;
bool showUpConnections = false;
bool showDownConnections = false;
bool showLeftConnections = false;
Expand Down Expand Up @@ -67,20 +67,20 @@ private slots:
void on_checkBox_Warps_stateChanged(int state);
void on_checkBox_BGs_stateChanged(int state);
void on_checkBox_Triggers_stateChanged(int state);
void on_checkBox_HealSpots_stateChanged(int state);
void on_checkBox_HealLocations_stateChanged(int state);
void on_checkBox_AllEvents_stateChanged(int state);

void on_checkBox_ConnectionUp_stateChanged(int state);
void on_checkBox_ConnectionDown_stateChanged(int state);
void on_checkBox_ConnectionLeft_stateChanged(int state);
void on_checkBox_ConnectionRight_stateChanged(int state);
void on_checkBox_AllConnections_stateChanged(int state);

void on_checkBox_Elevation_stateChanged(int state);
void on_checkBox_Grid_stateChanged(int state);
void on_checkBox_Border_stateChanged(int state);

void on_pushButton_Save_pressed();
void on_pushButton_Reset_pressed();
void on_pushButton_Cancel_pressed();
void on_spinBox_TimelapseDelay_valueChanged(int delayMs);
void on_spinBox_FrameSkip_valueChanged(int skip);

Expand Down
145 changes: 105 additions & 40 deletions src/ui/mapimageexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_, ImageExpor
this->ui->comboBox_MapSelection->addItems(editor->project->mapNames);
this->ui->comboBox_MapSelection->setCurrentText(map->name);
this->ui->comboBox_MapSelection->setEnabled(false);// TODO: allow selecting map from drop-down

connect(ui->pushButton_Save, &QPushButton::pressed, this, &MapImageExporter::saveImage);
connect(ui->pushButton_Cancel, &QPushButton::pressed, this, &MapImageExporter::close);
}

MapImageExporter::~MapImageExporter() {
Expand All @@ -73,6 +76,12 @@ void MapImageExporter::resizeEvent(QResizeEvent *event) {
}

void MapImageExporter::saveImage() {
// Make sure preview is up-to-date before we save.
if (this->preview.isNull())
updatePreview();
if (this->preview.isNull())
return;

QString title = getTitle(this->mode);
QString defaultFilename;
switch (this->mode)
Expand Down Expand Up @@ -219,11 +228,11 @@ bool MapImageExporter::historyItemAppliesToFrame(const QUndoCommand *command) {
case CommandId::ID_EventDelete:
case CommandId::ID_EventDuplicate: {
bool eventTypeIsApplicable =
(this->showObjects && (command->id() & IDMask_EventType_Object) != 0)
|| (this->showWarps && (command->id() & IDMask_EventType_Warp) != 0)
|| (this->showBGs && (command->id() & IDMask_EventType_BG) != 0)
|| (this->showTriggers && (command->id() & IDMask_EventType_Trigger) != 0)
|| (this->showHealSpots && (command->id() & IDMask_EventType_Heal) != 0);
(this->showObjects && (command->id() & IDMask_EventType_Object) != 0)
|| (this->showWarps && (command->id() & IDMask_EventType_Warp) != 0)
|| (this->showBGs && (command->id() & IDMask_EventType_BG) != 0)
|| (this->showTriggers && (command->id() & IDMask_EventType_Trigger) != 0)
|| (this->showHealLocations && (command->id() & IDMask_EventType_Heal) != 0);
return eventTypeIsApplicable;
}
default:
Expand Down Expand Up @@ -435,6 +444,7 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
if (!ignoreBorder && (this->showUpConnections || this->showDownConnections || this->showLeftConnections || this->showRightConnections)) {
// if showing connections, draw on outside of image
QPainter connectionPainter(&pixmap);
// TODO: Reading the connections from the editor and not 'map' is incorrect.
for (auto connectionItem : editor->connection_items) {
const QString direction = connectionItem->connection->direction();
if ((showUpConnections && direction == "up")
Expand All @@ -448,27 +458,30 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
}

// draw events
QPainter eventPainter(&pixmap);
QList<Event *> events = map->getAllEvents();
int pixelOffset = 0;
if (!ignoreBorder && this->showBorder) {
pixelOffset = this->mode == ImageExporterMode::Normal ? BORDER_DISTANCE * 16 : STITCH_MODE_BORDER_DISTANCE * 16;
}
for (Event *event : events) {
editor->project->setEventPixmap(event);
Event::Group group = event->getEventGroup();
if ((showObjects && group == Event::Group::Object)
|| (showWarps && group == Event::Group::Warp)
|| (showBGs && group == Event::Group::Bg)
|| (showTriggers && group == Event::Group::Coord)
|| (showHealSpots && group == Event::Group::Heal))
eventPainter.drawImage(QPoint(event->getPixelX() + pixelOffset, event->getPixelY() + pixelOffset), event->getPixmap().toImage());
if (this->showObjects || this->showWarps || this->showBGs || this->showTriggers || this->showHealLocations) {
QPainter eventPainter(&pixmap);
int pixelOffset = 0;
if (!ignoreBorder && this->showBorder) {
pixelOffset = this->mode == ImageExporterMode::Normal ? BORDER_DISTANCE * 16 : STITCH_MODE_BORDER_DISTANCE * 16;
}
const QList<Event *> events = map->getAllEvents();
for (const auto &event : events) {
Event::Group group = event->getEventGroup();
if ((this->showObjects && group == Event::Group::Object)
|| (this->showWarps && group == Event::Group::Warp)
|| (this->showBGs && group == Event::Group::Bg)
|| (this->showTriggers && group == Event::Group::Coord)
|| (this->showHealLocations && group == Event::Group::Heal)) {
editor->project->setEventPixmap(event);
eventPainter.drawImage(QPoint(event->getPixelX() + pixelOffset, event->getPixelY() + pixelOffset), event->getPixmap().toImage());
}
}
eventPainter.end();
}
eventPainter.end();

// draw grid directly onto the pixmap
// since the last grid lines are outside of the pixmap, add a pixel to the bottom and right
if (showGrid) {
if (this->showGrid) {
int addX = 1, addY = 1;
if (borderHeight) addY = 0;
if (borderWidth) addX = 0;
Expand All @@ -491,14 +504,11 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {

void MapImageExporter::updateShowBorderState() {
// If any of the Connections settings are enabled then this setting is locked (it's implicitly enabled)
bool on = (showUpConnections || showDownConnections || showLeftConnections || showRightConnections);
const QSignalBlocker blocker(ui->checkBox_Border);
if (showUpConnections || showDownConnections || showLeftConnections || showRightConnections) {
ui->checkBox_Border->setChecked(true);
ui->checkBox_Border->setDisabled(true);
showBorder = true;
} else {
ui->checkBox_Border->setDisabled(false);
}
ui->checkBox_Border->setChecked(on);
ui->checkBox_Border->setDisabled(on);
showBorder = on;
}

void MapImageExporter::on_checkBox_Elevation_stateChanged(int state) {
Expand Down Expand Up @@ -536,8 +546,40 @@ void MapImageExporter::on_checkBox_Triggers_stateChanged(int state) {
updatePreview();
}

void MapImageExporter::on_checkBox_HealSpots_stateChanged(int state) {
showHealSpots = (state == Qt::Checked);
void MapImageExporter::on_checkBox_HealLocations_stateChanged(int state) {
showHealLocations = (state == Qt::Checked);
updatePreview();
}

// Shortcut setting for enabling all events
void MapImageExporter::on_checkBox_AllEvents_stateChanged(int state) {
bool on = (state == Qt::Checked);

const QSignalBlocker b_Objects(ui->checkBox_Objects);
ui->checkBox_Objects->setChecked(on);
ui->checkBox_Objects->setDisabled(on);
showObjects = on;

const QSignalBlocker b_Warps(ui->checkBox_Warps);
ui->checkBox_Warps->setChecked(on);
ui->checkBox_Warps->setDisabled(on);
showWarps = on;

const QSignalBlocker b_BGs(ui->checkBox_BGs);
ui->checkBox_BGs->setChecked(on);
ui->checkBox_BGs->setDisabled(on);
showBGs = on;

const QSignalBlocker b_Triggers(ui->checkBox_Triggers);
ui->checkBox_Triggers->setChecked(on);
ui->checkBox_Triggers->setDisabled(on);
showTriggers = on;

const QSignalBlocker b_HealLocations(ui->checkBox_HealLocations);
ui->checkBox_HealLocations->setChecked(on);
ui->checkBox_HealLocations->setDisabled(on);
showHealLocations = on;

updatePreview();
}

Expand Down Expand Up @@ -565,6 +607,34 @@ void MapImageExporter::on_checkBox_ConnectionRight_stateChanged(int state) {
updatePreview();
}

// Shortcut setting for enabling all connection directions
void MapImageExporter::on_checkBox_AllConnections_stateChanged(int state) {
bool on = (state == Qt::Checked);

const QSignalBlocker b_Up(ui->checkBox_ConnectionUp);
ui->checkBox_ConnectionUp->setChecked(on);
ui->checkBox_ConnectionUp->setDisabled(on);
showUpConnections = on;

const QSignalBlocker b_Down(ui->checkBox_ConnectionDown);
ui->checkBox_ConnectionDown->setChecked(on);
ui->checkBox_ConnectionDown->setDisabled(on);
showDownConnections = on;

const QSignalBlocker b_Left(ui->checkBox_ConnectionLeft);
ui->checkBox_ConnectionLeft->setChecked(on);
ui->checkBox_ConnectionLeft->setDisabled(on);
showLeftConnections = on;

const QSignalBlocker b_Right(ui->checkBox_ConnectionRight);
ui->checkBox_ConnectionRight->setChecked(on);
ui->checkBox_ConnectionRight->setDisabled(on);
showRightConnections = on;

updateShowBorderState();
updatePreview();
}

void MapImageExporter::on_checkBox_ActualSize_stateChanged(int state) {
previewActualSize = (state == Qt::Checked);
if (previewActualSize) {
Expand All @@ -574,17 +644,12 @@ void MapImageExporter::on_checkBox_ActualSize_stateChanged(int state) {
}
}

void MapImageExporter::on_pushButton_Save_pressed() {
saveImage();
}

void MapImageExporter::on_pushButton_Reset_pressed() {
for (auto widget : this->findChildren<QCheckBox *>())
for (auto widget : this->findChildren<QCheckBox *>()) {
const QSignalBlocker b(widget);
widget->setChecked(false);
}

void MapImageExporter::on_pushButton_Cancel_pressed() {
this->close();
}
updatePreview();
}

void MapImageExporter::on_spinBox_TimelapseDelay_valueChanged(int delayMs) {
Expand Down

0 comments on commit 6e79c6c

Please sign in to comment.