diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 8252436db..5a3d64f91 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -44,10 +44,10 @@ CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str) : CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE), - parent(Par), - town(Town), - str(Str), - stateCounter(80) + parent(Par), + town(Town), + str(Str), + stateTimeCounter(BUILD_ANIMATION_FINISHED_TIMEPOINT) { addUsedEvents(LCLICK | RCLICK | HOVER); pos.x += str->pos.x; @@ -168,16 +168,11 @@ SDL_Color multiplyColors(const SDL_Color & b, const SDL_Color & a, double f) void CBuildingRect::show(SDL_Surface * to) { - const ui32 stageDelay = 16; + uint32_t stageDelay = BUILDING_APPEAR_TIMEPOINT; - const ui32 S1_TRANSP = 16; //0.5 sec building appear 0->100 transparency - const ui32 S2_WHITE_B = 32; //0.5 sec border glows from white to yellow - const ui32 S3_YELLOW_B= 48; //0.5 sec border glows from yellow to normal - const ui32 BUILDED = 80; // 1 sec delay, nothing happens - - if(stateCounter < S1_TRANSP) + if(stateTimeCounter < BUILDING_APPEAR_TIMEPOINT) { - setAlpha(255*stateCounter/stageDelay); + setAlpha(255 * stateTimeCounter / stageDelay); CShowableAnim::show(to); } else @@ -186,9 +181,9 @@ void CBuildingRect::show(SDL_Surface * to) CShowableAnim::show(to); } - if(border && stateCounter > S1_TRANSP) + if(border && stateTimeCounter > BUILDING_APPEAR_TIMEPOINT) { - if(stateCounter == BUILDED) + if(stateTimeCounter >= BUILD_ANIMATION_FINISHED_TIMEPOINT) { if(parent->selectedBuilding == this) blitAtLoc(border,0,0,to); @@ -205,11 +200,11 @@ void CBuildingRect::show(SDL_Surface * to) SDL_Color oldColor = border->format->palette->colors[colorID]; SDL_Color newColor; - if (stateCounter < S2_WHITE_B) - newColor = multiplyColors(c1, c2, static_cast(stateCounter % stageDelay) / stageDelay); + if (stateTimeCounter < BUILDING_WHITE_BORDER_TIMEPOINT) + newColor = multiplyColors(c1, c2, static_cast(stateTimeCounter % stageDelay) / stageDelay); else - if (stateCounter < S3_YELLOW_B) - newColor = multiplyColors(c2, c3, static_cast(stateCounter % stageDelay) / stageDelay); + if (stateTimeCounter < BUILDING_YELLOW_BORDER_TIMEPOINT) + newColor = multiplyColors(c2, c3, static_cast(stateTimeCounter % stageDelay) / stageDelay); else newColor = oldColor; @@ -218,13 +213,13 @@ void CBuildingRect::show(SDL_Surface * to) SDL_SetColors(border, &oldColor, colorID, 1); } } - if(stateCounter < BUILDED) - stateCounter++; + if(stateTimeCounter < BUILD_ANIMATION_FINISHED_TIMEPOINT) + stateTimeCounter += GH.mainFPSmng->getElapsedMilliseconds(); } void CBuildingRect::showAll(SDL_Surface * to) { - if (stateCounter == 0) + if (stateTimeCounter == 0) return; CShowableAnim::showAll(to); @@ -646,9 +641,9 @@ void CCastleBuildings::addBuilding(BuildingID building) { //reset animation if(structures.size() == 1) - buildingRect->stateCounter = 0; // transparency -> fully visible stage + buildingRect->stateTimeCounter = 0; // transparency -> fully visible stage else - buildingRect->stateCounter = 16; // already in fully visible stage + buildingRect->stateTimeCounter = CBuildingRect::BUILDING_APPEAR_TIMEPOINT; // already in fully visible stage break; } } diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 915e7579d..6b9f7f7e8 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -42,6 +42,14 @@ class CBuildingRect : public CShowableAnim { std::string getSubtitle(); public: + enum EBuildingCreationAnimationPhases : uint32_t + { + BUILDING_APPEAR_TIMEPOINT = 500, //500 msec building appears: 0->100% transparency + BUILDING_WHITE_BORDER_TIMEPOINT = 1000, //500 msec border glows from white to yellow + BUILDING_YELLOW_BORDER_TIMEPOINT = 1500, //500 msec border glows from yellow to normal + BUILD_ANIMATION_FINISHED_TIMEPOINT = 2500 //1000 msec delay, nothing happens + }; + /// returns building associated with this structure const CBuilding * getBuilding(); @@ -51,7 +59,7 @@ public: SDL_Surface* border; SDL_Surface* area; - ui32 stateCounter;//For building construction - current stage in animation + ui32 stateTimeCounter;//For building construction - current stage in animation CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str); ~CBuildingRect();