Fix event sprite transparency regression

This commit is contained in:
GriffinR 2026-02-16 23:25:28 -05:00
parent bd78f8de52
commit f1e507d97e
5 changed files with 17 additions and 18 deletions

View File

@ -8,6 +8,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp
### Fixed
- Fix degraded image quality in exported timelapse gifs.
- Fix custom top-level data in the `encounters` object of `wild_encounters.json` being discarded if no `fields` data is present.
- Fix event sprites sometimes rendering with incorrect transparency temporarily after a sprite change.
## [6.3.0] - 2025-12-26
### Added

View File

@ -118,7 +118,6 @@ public:
void redrawEvents(const QList<Event*> &events);
void redrawEventPixmapItem(EventPixmapItem *item);
void updateEventPixmapItemZValue(EventPixmapItem *item);
qreal getEventOpacity(const Event *event) const;
bool isMouseInMap() const;
void setPlayerViewRect(const QRectF &rect);

View File

@ -7,6 +7,7 @@
#include <QGraphicsItemAnimation>
#include <QtWidgets>
#include <optional>
#include "events.h"
@ -28,6 +29,8 @@ public:
void moveTo(int x, int y);
void moveTo(const QPoint &pos);
void setOpacityOverride(qreal opacity) { m_opacityOverride = opacity;}
void clearOpacityOverride() { m_opacityOverride.reset(); }
private:
QPixmap m_basePixmap;
Event *const m_event = nullptr;
@ -35,6 +38,7 @@ private:
bool m_active = false;
bool m_selected = false;
bool m_releaseSelectionQueued = false;
std::optional<qreal> m_opacityOverride = {};
void updatePixelPosition();

View File

@ -1790,7 +1790,6 @@ void Editor::displayMapEvents() {
}
EventPixmapItem *Editor::addEventPixmapItem(Event *event) {
this->project->loadEventPixmap(event);
auto item = new EventPixmapItem(event);
connect(item, &EventPixmapItem::doubleClicked, this, &Editor::openEventMap);
connect(item, &EventPixmapItem::dragged, this, &Editor::onEventDragged);
@ -2048,34 +2047,22 @@ void Editor::redrawEvents(const QList<Event*> &events) {
}
}
qreal Editor::getEventOpacity(const Event *event) const {
// There are 4 possible opacities for an event's sprite:
// - Off the Events tab, and the event overlay is off (0.0)
// - Off the Events tab, and the event overlay is on (0.5)
// - On the Events tab, and the event has a default sprite (0.7)
// - On the Events tab, and the event has a custom sprite (1.0)
if (this->editMode != EditMode::Events)
return porymapConfig.eventOverlayEnabled ? 0.5 : 0.0;
return event->getUsesDefaultPixmap() ? 0.7 : 1.0;
}
void Editor::redrawEventPixmapItem(EventPixmapItem *item) {
if (!item) return;
Event *event = item->getEvent();
if (!event) return;
if (this->editMode == EditMode::Events) {
item->setAcceptedMouseButtons(Qt::AllButtons);
item->setSelected(this->selectedEvents.contains(event));
item->setSelected(item->getEvent() ? this->selectedEvents.contains(item->getEvent()) : false);
item->clearOpacityOverride();
} else {
// Can't interact with event pixmaps outside of event editing mode.
// We could do setEnabled(false), but rather than ignoring the mouse events this
// would reject them, which would prevent painting on the map behind the events.
item->setAcceptedMouseButtons(Qt::NoButton);
item->setSelected(false);
// When not on the events tab, events are only visible if certain settings are enabled.
item->setOpacityOverride(porymapConfig.eventOverlayEnabled ? 0.5 : 0.0);
}
updateEventPixmapItemZValue(item);
item->setOpacity(getEventOpacity(event));
item->setShapeMode(porymapConfig.eventSelectionShapeMode);
item->render(project);
}

View File

@ -19,6 +19,14 @@ void EventPixmapItem::render(Project *project) {
m_basePixmap = m_event->loadPixmap(project);
if (m_opacityOverride.has_value()) {
setOpacity(m_opacityOverride.value());
} else {
// This can only happen after loading the pixmap above,
// as whether we're using the default or not may have changed.
setOpacity(m_event->getUsesDefaultPixmap() ? 0.7 : 1.0);
}
// If the base pixmap changes, the event's pixel position may change.
updatePixelPosition();