From 8ed2ba3055b3ed95b830e6e4cd97a9d26ae3ed08 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 16 Feb 2026 23:25:28 -0500 Subject: [PATCH] Fix event sprite transparency regression --- CHANGELOG.md | 1 + include/editor.h | 1 - include/ui/eventpixmapitem.h | 3 +++ src/editor.cpp | 21 ++++----------------- src/ui/eventpixmapitem.cpp | 8 ++++++++ 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03176ea8..0e200bba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp - Fix actions triggered with the use of `utility.registerAction` calling all functions across plug-ins with the registered name, rather than just the function in the script that registered it. - Fix the tool tips for the tileset selectors always listing the same tileset size. - Fix event sprite names that appear in `symbol_obj_event_gfx_pointers` by value and not by name not rendering with the correct sprite. +- Fix event sprites sometimes rendering with incorrect transparency temporarily after a sprite change. ## [6.3.0] - 2025-12-26 ### Added diff --git a/include/editor.h b/include/editor.h index d356aef3..83ef2e7c 100644 --- a/include/editor.h +++ b/include/editor.h @@ -118,7 +118,6 @@ public: void redrawEvents(const QList &events); void redrawEventPixmapItem(EventPixmapItem *item); void updateEventPixmapItemZValue(EventPixmapItem *item); - qreal getEventOpacity(const Event *event) const; bool isMouseInMap() const; void setPlayerViewRect(const QRectF &rect); diff --git a/include/ui/eventpixmapitem.h b/include/ui/eventpixmapitem.h index a28232ba..2f231a95 100644 --- a/include/ui/eventpixmapitem.h +++ b/include/ui/eventpixmapitem.h @@ -28,6 +28,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 +37,7 @@ private: bool m_active = false; bool m_selected = false; bool m_releaseSelectionQueued = false; + std::optional m_opacityOverride = {}; void updatePixelPosition(); diff --git a/src/editor.cpp b/src/editor.cpp index be0e9827..f85f427b 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1788,7 +1788,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); @@ -2046,34 +2045,22 @@ void Editor::redrawEvents(const QList &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); } diff --git a/src/ui/eventpixmapitem.cpp b/src/ui/eventpixmapitem.cpp index bc7bb964..c85e5f59 100644 --- a/src/ui/eventpixmapitem.cpp +++ b/src/ui/eventpixmapitem.cpp @@ -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();