1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Partial implementation of world view mode

This commit is contained in:
Ivan Savenko 2023-02-15 23:13:25 +02:00
parent beb7ce5beb
commit d46687a9c8
9 changed files with 35 additions and 43 deletions

View File

@ -1975,7 +1975,7 @@ void CPlayerInterface::showPuzzleMap()
void CPlayerInterface::viewWorldMap()
{
adventureInt->changeMode(EAdvMapMode::WORLD_VIEW, 0.36F);
adventureInt->changeMode(EAdvMapMode::WORLD_VIEW);
}
void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellID)

View File

@ -81,7 +81,6 @@ void CAdvMapInt::setScrollingCursor(ui8 direction) const
CAdvMapInt::CAdvMapInt():
mode(EAdvMapMode::NORMAL),
worldViewScale(0.0f), //actual init later in changeMode
minimap(new CMinimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH))),
statusbar(CGStatusBar::create(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG)),
heroList(new CHeroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD)),
@ -238,7 +237,7 @@ CAdvMapInt::CAdvMapInt():
activeMapPanel = panelMain;
changeMode(EAdvMapMode::NORMAL, 0.36F);
changeMode(EAdvMapMode::NORMAL);
underground->block(!CGI->mh->map->twoLevel);
questlog->block(!CGI->mh->map->quests.size());
@ -254,7 +253,7 @@ void CAdvMapInt::fshowOverview()
void CAdvMapInt::fworldViewBack()
{
changeMode(EAdvMapMode::NORMAL, 0.36F);
changeMode(EAdvMapMode::NORMAL);
CGI->mh->discardWorldViewCache();
auto hero = curHero();
@ -265,17 +264,17 @@ void CAdvMapInt::fworldViewBack()
void CAdvMapInt::fworldViewScale1x()
{
// TODO set corresponding scale button to "selected" mode
changeMode(EAdvMapMode::WORLD_VIEW, 0.22f); // 7 pixels per tile
changeMode(EAdvMapMode::WORLD_VIEW, 7); // 7 pixels per tile
}
void CAdvMapInt::fworldViewScale2x()
{
changeMode(EAdvMapMode::WORLD_VIEW, 0.36f); // 11 pixels per tile
changeMode(EAdvMapMode::WORLD_VIEW, 11); // 11 pixels per tile
}
void CAdvMapInt::fworldViewScale4x()
{
changeMode(EAdvMapMode::WORLD_VIEW, 0.5f); // 16 pixels per tile
changeMode(EAdvMapMode::WORLD_VIEW, 16); // 16 pixels per tile
}
void CAdvMapInt::fswitchLevel()
@ -295,14 +294,13 @@ void CAdvMapInt::fswitchLevel()
redrawOnNextFrame = true;
minimap->setLevel(terrain->getLevel());
if (mode == EAdvMapMode::WORLD_VIEW)
terrain->redraw();
}
void CAdvMapInt::fshowQuestlog()
{
LOCPLINT->showQuestLog();
}
void CAdvMapInt::fsleepWake()
{
const CGHeroInstance *h = curHero();
@ -683,9 +681,6 @@ void CAdvMapInt::centerOn(int3 on, bool fade)
if (switchedLevels)
minimap->setLevel(terrain->getLevel());
minimap->redraw();
if (mode == EAdvMapMode::WORLD_VIEW)
terrain->redraw();
}
void CAdvMapInt::centerOn(const CGObjectInstance * obj, bool fade)
@ -1506,7 +1501,12 @@ void CAdvMapInt::quickCombatUnlock()
activate();
}
void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale)
void CAdvMapInt::changeMode(EAdvMapMode newMode)
{
changeMode(newMode, 11);
}
void CAdvMapInt::changeMode(EAdvMapMode newMode, int tileSize)
{
if (mode != newMode)
{
@ -1524,6 +1524,7 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale)
infoBar->activate();
worldViewOptions.clear();
terrain->setTileSize(32);
break;
case EAdvMapMode::WORLD_VIEW:
@ -1536,15 +1537,10 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale)
heroList->deactivate();
infoBar->showSelection(); // to prevent new day animation interfering world view mode
infoBar->deactivate();
terrain->setTileSize(tileSize);
break;
}
worldViewScale = newScale;
redraw();
}
else if (worldViewScale != newScale) // still in world view mode, but the scale changed
{
worldViewScale = newScale;
redraw();
}
}

View File

@ -83,7 +83,6 @@ private:
//int3 position;
EAdvMapMode mode;
float worldViewScale;
WorldViewOptions worldViewOptions;
@ -226,7 +225,8 @@ public:
Rect terrainAreaTiles() const;
/// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
void changeMode(EAdvMapMode newMode, float newScale);
void changeMode(EAdvMapMode newMode);
void changeMode(EAdvMapMode newMode, int tileSize);
};
extern std::shared_ptr<CAdvMapInt> adventureInt;

View File

@ -81,7 +81,7 @@ CMinimapInstance::CMinimapInstance(CMinimap *Parent, int Level):
void CMinimapInstance::showAll(SDL_Surface * to)
{
Canvas target(to);
target.draw(*minimap, pos.topLeft(), pos.dimensions());
target.drawScaled(*minimap, pos.topLeft(), pos.dimensions());
}
CMinimap::CMinimap(const Rect & position)

View File

@ -306,3 +306,8 @@ int CTerrainRect::getLevel()
{
return renderer->getModel()->getLevel();
}
void CTerrainRect::setTileSize(int sizePixels)
{
renderer->setTileSize(Point(sizePixels, sizePixels));
}

View File

@ -58,6 +58,7 @@ public:
void setViewCenter(const int3 & coordinates);
void setViewCenter(const Point & position, int level);
void setLevel(int level);
void setTileSize(int sizePixels);
int3 getTileCenter();
Point getViewCenter();

View File

@ -611,7 +611,7 @@ void MapRendererPath::renderTile(const IMapRendererContext & context, Canvas & t
auto next = iter + 1;
auto prev = iter - 1;
// start of path - currentl hero location
// start of path - current hero location
if(next == path->nodes.end())
return;

View File

@ -33,11 +33,7 @@ Canvas::Canvas(const Canvas & other):
Canvas::Canvas(const Canvas & other, const Rect & newClipRect):
Canvas(other)
{
//clipRect.emplace();
//CSDL_Ext::getClipRect(surface, clipRect.get());
renderArea = other.renderArea.intersect(newClipRect + other.renderArea.topLeft());
//CSDL_Ext::setClipRect(surface, currClipRect);
}
Canvas::Canvas(const Point & size):
@ -48,32 +44,29 @@ Canvas::Canvas(const Point & size):
Canvas::~Canvas()
{
//if (clipRect)
// CSDL_Ext::setClipRect(surface, clipRect.get());
SDL_FreeSurface(surface);
}
void Canvas::draw(std::shared_ptr<IImage> image, const Point & pos)
void Canvas::draw(const std::shared_ptr<IImage>& image, const Point & pos)
{
assert(image);
if (image)
image->draw(surface, renderArea.x + pos.x, renderArea.y + pos.y);
}
void Canvas::draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect)
void Canvas::draw(const std::shared_ptr<IImage>& image, const Point & pos, const Rect & sourceRect)
{
assert(image);
if (image)
image->draw(surface, renderArea.x + pos.x, renderArea.y + pos.y, &sourceRect);
}
void Canvas::draw(Canvas & image, const Point & pos)
void Canvas::draw(const Canvas & image, const Point & pos)
{
CSDL_Ext::blitSurface(image.surface, image.renderArea, surface, renderArea.topLeft() + pos);
}
void Canvas::draw(Canvas & image, const Point & pos, const Point & targetSize)
void Canvas::drawScaled(const Canvas & image, const Point & pos, const Point & targetSize)
{
SDL_Rect targetRect = CSDL_Ext::toSDL(Rect(pos, targetSize));
SDL_BlitScaled(image.surface, nullptr, surface, &targetRect );

View File

@ -24,13 +24,10 @@ class Canvas
/// Target surface
SDL_Surface * surface;
/// Clip rect that was in use on surface originally and needs to be restored on destruction
boost::optional<Rect> clipRect;
/// Current rendering area, all rendering operations will be moved into selected area
Rect renderArea;
Canvas & operator = (Canvas & other) = delete;
Canvas & operator = (const Canvas & other) = delete;
public:
/// constructs canvas using existing surface. Caller maintains ownership on the surface
@ -48,16 +45,16 @@ public:
~Canvas();
/// renders image onto this canvas at specified position
void draw(std::shared_ptr<IImage> image, const Point & pos);
void draw(const std::shared_ptr<IImage>& image, const Point & pos);
/// renders section of image bounded by sourceRect at specified position
void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect);
void draw(const std::shared_ptr<IImage>& image, const Point & pos, const Rect & sourceRect);
/// renders another canvas onto this canvas
void draw(Canvas & image, const Point & pos);
void draw(const Canvas &image, const Point & pos);
/// renders another canvas onto this canvas with scaling
void draw(Canvas & image, const Point & pos, const Point & targetSize);
void drawScaled(const Canvas &image, const Point & pos, const Point & targetSize);
/// renders single pixels with specified color
void drawPoint(const Point & dest, const ColorRGBA & color);