From 5516c89576da2504e82737223f0ac55b9949a485 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 16 Nov 2024 04:55:56 +0100 Subject: [PATCH] fix gem scaling, attempt #2 This sort-of-reverts 4a71c5e12f5edd9bf2ed and fixes overlooked cases --- Aquaria/WorldMapRender.cpp | 56 ++++++++++++++++++-------------------- Aquaria/WorldMapRender.h | 1 - 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Aquaria/WorldMapRender.cpp b/Aquaria/WorldMapRender.cpp index d82405d..17065b7 100644 --- a/Aquaria/WorldMapRender.cpp +++ b/Aquaria/WorldMapRender.cpp @@ -262,8 +262,6 @@ public: position = tc ? tc->worldPosToTilePos(gemData->pos) : gemData->pos; text->setText(gemData->userString); textBG->setWidthHeight(text->getActualWidth() + 20, 25, 10); - - this->update(0); } void destroy() @@ -294,6 +292,29 @@ protected: { Quad::onUpdate(dt); + // Make sure ALL gems always have the same size no matter the container's scale. + // This is a bit nasty because some gems have the world map surface as parent (where gemData->global), + // while the map-local gems have their map tile as parent. + // So for scaling them properly, make sure the tile scale factor cancels out while normalizing the scale. + + float invparent = gemData->global ? 1.0f : 1.0f / parent->scale.x; // factor used to cancel out parent tile scaling, if the parent is a tile. + float sz = parent->getRealScale().x; + + sz *= invparent; + + if (sz < zoomMin) + sz = zoomMin; + if (sz > zoomMax) + sz = zoomMax; + + sz = sz < 1.0f ? 1.0f : 1.0f / sz; + + sz *= invparent; + + scale.x = sz; + scale.y = sz; + + Vector wp = getWorldPosition(); if (gemData->blink) @@ -1154,7 +1175,10 @@ void WorldMapRender::toggle(bool turnON) addHintQuads[i]->alpha.interpolateTo(1.0f, 0.2f); assert(gemMovers.empty()); - for (Continuity::Gems::iterator i = dsq->continuity.gems.begin(); i != dsq->continuity.gems.end(); i++) + + // I'm not sure why this is all backwards but i'm thinking that it's because the naija gem should always be on top, + // and since it's the very first one in the list that adds it last, ie. on top of everything else. + for (Continuity::Gems::reverse_iterator i = dsq->continuity.gems.rbegin(); i != dsq->continuity.gems.rend(); i++) addGem(&(*i)); for (Continuity::Beacons::reverse_iterator i = dsq->continuity.beacons.rbegin(); i != dsq->continuity.beacons.rend(); i++) @@ -1373,30 +1397,6 @@ GemMover* WorldMapTileContainer::getGem(const GemData* gemData) const return NULL; } -void WorldMapTileContainer::updateGems() -{ - // Make sure the gems always have the same size no matter the container's scale - // -> bypass this, go directly to parent - float sz = parent->scale.x; - - if (sz < zoomMin) - sz = zoomMin; - if (sz > zoomMax) - sz = zoomMax; - - sz = sz < 1.0f ? 1.0f : 1.0f / sz; - - for(size_t i = 0; i < gems.size(); ++i) - { - Quad *q = gems[i]; - - q->scale.x = sz; - q->scale.y = sz; - } -} - - - Vector WorldMapTileContainer::worldPosToTilePos(const Vector& position) const { // Notes: TILE_SIZE in the world is 1 pixel in the map template png. @@ -1429,7 +1429,5 @@ void WorldMapTileContainer::onUpdate(float dt) q.scale.y = tile.scale * tileScaleFactor; q.renderQuad = tile.revealed || tile.prerevealed; - updateGems(); - RenderObject::onUpdate(dt); } diff --git a/Aquaria/WorldMapRender.h b/Aquaria/WorldMapRender.h index 9da9559..c93e9f9 100644 --- a/Aquaria/WorldMapRender.h +++ b/Aquaria/WorldMapRender.h @@ -32,7 +32,6 @@ public: bool removeGem(GemMover *gem); GemMover *removeGem(const GemData *gem); GemMover *getGem(const GemData *gemData) const; - void updateGems(); Vector worldPosToTilePos(const Vector& p) const; Vector worldPosToMapPos(const Vector& p) const;