1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +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; updateScreen=false;
LOCPLINT->cingconsole->show(to); LOCPLINT->cingconsole->show(to);
} }
else if (terrain->needsAnimUpdate()) else
{ {
terrain->showAnim(to); terrain->showAnim(to);
for(int i = 0; i < 4; i++) 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) void CTerrainRect::showAnim(SDL_Surface * to)
{ {
if (fadeAnim->isFading()) if (!needsAnimUpdate())
return;
if (fadeAnim->isFading() || lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED)
show(to); 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) int3 CTerrainRect::whichTileIsIt(const int x, const int y)

View File

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

View File

@ -2135,9 +2135,10 @@ CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::share
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
items.reserve(_items.size()); items.reserve(_items.size());
for(int id : _items) 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); init(titleWidget_, _title, _descr);