1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Attempt at better encapsulation of CTerrainRect

This commit is contained in:
Ivan Savenko 2023-02-10 17:26:31 +02:00
parent 89c29206f1
commit e15c7dcd33
4 changed files with 20 additions and 11 deletions

View File

@ -606,7 +606,7 @@ void CAdvMapInt::show(SDL_Surface * to)
updateScreen=false;
LOCPLINT->cingconsole->show(to);
}
else if (terrain->needsAnimUpdate())
else
{
terrain->showAnim(to);
for(int i = 0; i < 4; i++)

View File

@ -360,10 +360,11 @@ void CTerrainRect::showAll(SDL_Surface * to)
void CTerrainRect::showAnim(SDL_Surface * to)
{
if (fadeAnim->isFading())
if (!needsAnimUpdate())
return;
if (fadeAnim->isFading() || lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED)
show(to);
else if (lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED)
show(to); // currently the same; maybe we should pass some flag to map handler so it redraws ONLY tiles that need redraw instead of full
}
int3 CTerrainRect::whichTileIsIt(const int x, const int y)

View File

@ -35,14 +35,22 @@ class CTerrainRect : public CIntObject
void handleSwipeMove(const Point & cursorPosition);
/// handles start/finish of swipe (press/release of corresponding button); returns true if state change was handled
bool handleSwipeStateChange(bool btnPressed);
int3 curHoveredTile;
int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
int3 whichTileIsIt(); //uses current cursor pos
void showPath(const Rect &extRect, SDL_Surface * to);
bool needsAnimUpdate();
public:
int tilesw, tilesh; //width and height of terrain to blit in tiles
int3 curHoveredTile;
int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
CGPath * currentPath;
CTerrainRect();
virtual ~CTerrainRect();
~CTerrainRect();
// CIntObject interface implementation
void deactivate() override;
void clickLeft(tribool down, bool previousState) override;
void clickRight(tribool down, bool previousState) override;
@ -51,14 +59,13 @@ public:
void mouseMoved (const Point & cursorPosition) override;
void show(SDL_Surface * to) override;
void showAll(SDL_Surface * to) override;
void showAnim(SDL_Surface * to);
void showPath(const Rect &extRect, SDL_Surface * to);
int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
int3 whichTileIsIt(); //uses current cursor pos
/// @returns number of visible tiles on screen respecting current map scaling
int3 tileCountOnScreen();
/// animates view by caching current surface and crossfading it with normal screen
void fadeFromCurrentView();
bool needsAnimUpdate();
};

View File

@ -2135,9 +2135,10 @@ CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::share
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
items.reserve(_items.size());
for(int id : _items)
{
items.push_back(std::make_pair(id, CGI->mh->map->objects[id]->getObjectName()));
items.push_back(std::make_pair(id, LOCPLINT->cb->getObjInstance(ObjectInstanceID(id))->getObjectName()));
}
init(titleWidget_, _title, _descr);