From cbddf2d8fbae9ec7fef7c7016f9a12cb9c213ec4 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 15 Jan 2023 17:22:53 +0100 Subject: [PATCH 1/4] Adjust newly built building appearance and outline blinking speed --- client/windows/CCastleInterface.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 31ba43873..f178c2ea5 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -47,7 +47,7 @@ CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town parent(Par), town(Town), str(Str), - stateCounter(80) + stateCounter(150) { addUsedEvents(LCLICK | RCLICK | HOVER); pos.x += str->pos.x; @@ -154,12 +154,12 @@ SDL_Color multiplyColors(const SDL_Color & b, const SDL_Color & a, double f) void CBuildingRect::show(SDL_Surface * to) { - const ui32 stageDelay = 16; + const ui32 stageDelay = 30; - 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 + const ui32 S1_TRANSP = 30; //0.5 sec building appear 0->100 transparency + const ui32 S2_WHITE_B = 60; //0.5 sec border glows from white to yellow + const ui32 S3_YELLOW_B= 90; //0.5 sec border glows from yellow to normal + const ui32 BUILDED = 150; // 1 sec delay, nothing happens if(stateCounter < S1_TRANSP) { From 7dd7f4af548b7ae525d2dc3676f73f92441494d5 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 15 Jan 2023 19:56:55 +0100 Subject: [PATCH 2/4] Change to time-based frame counting, easier than I though --- client/windows/CCastleInterface.cpp | 44 ++++++++++++++--------------- client/windows/CCastleInterface.h | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index f178c2ea5..0d5ba23ef 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(150) + parent(Par), + town(Town), + str(Str), + stateTimeCounter(2500) { addUsedEvents(LCLICK | RCLICK | HOVER); pos.x += str->pos.x; @@ -154,16 +154,16 @@ SDL_Color multiplyColors(const SDL_Color & b, const SDL_Color & a, double f) void CBuildingRect::show(SDL_Surface * to) { - const ui32 stageDelay = 30; + const ui32 stageDelay = 500; - const ui32 S1_TRANSP = 30; //0.5 sec building appear 0->100 transparency - const ui32 S2_WHITE_B = 60; //0.5 sec border glows from white to yellow - const ui32 S3_YELLOW_B= 90; //0.5 sec border glows from yellow to normal - const ui32 BUILDED = 150; // 1 sec delay, nothing happens + const ui32 S1_TRANSP = 500; //500 msec building appear 0->100 transparency + const ui32 S2_WHITE_B = 1000; //500 msec border glows from white to yellow + const ui32 S3_YELLOW_B= 1500; //500 msec border glows from yellow to normal + const ui32 BUILDED = 2500; //1000 msec delay, nothing happens - if(stateCounter < S1_TRANSP) + if(stateTimeCounter < S1_TRANSP) { - setAlpha(255*stateCounter/stageDelay); + setAlpha(255 * stateTimeCounter / stageDelay); CShowableAnim::show(to); } else @@ -172,9 +172,9 @@ void CBuildingRect::show(SDL_Surface * to) CShowableAnim::show(to); } - if(border && stateCounter > S1_TRANSP) + if(border && stateTimeCounter > S1_TRANSP) { - if(stateCounter == BUILDED) + if(stateTimeCounter >= BUILDED) { if(parent->selectedBuilding == this) blitAtLoc(border,0,0,to); @@ -191,11 +191,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 < S2_WHITE_B) + 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 < S3_YELLOW_B) + newColor = multiplyColors(c2, c3, static_cast(stateTimeCounter % stageDelay) / stageDelay); else newColor = oldColor; @@ -204,13 +204,13 @@ void CBuildingRect::show(SDL_Surface * to) SDL_SetColors(border, &oldColor, colorID, 1); } } - if(stateCounter < BUILDED) - stateCounter++; + if(stateTimeCounter < BUILDED) + stateTimeCounter += GH.mainFPSmng->getElapsedMilliseconds(); } void CBuildingRect::showAll(SDL_Surface * to) { - if (stateCounter == 0) + if (stateTimeCounter == 0) return; CShowableAnim::showAll(to); @@ -632,9 +632,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 = 500; // already in fully visible stage break; } } diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 915e7579d..55bdc31d0 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -51,7 +51,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(); From 54e499f5e750df8973b951f13a278946c26fcd36 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Mon, 16 Jan 2023 00:33:53 +0100 Subject: [PATCH 3/4] Minor refactoring from code review --- client/windows/CCastleInterface.cpp | 21 ++++++++------------- client/windows/CCastleInterface.h | 8 ++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 0d5ba23ef..8c8852be9 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -154,14 +154,9 @@ SDL_Color multiplyColors(const SDL_Color & b, const SDL_Color & a, double f) void CBuildingRect::show(SDL_Surface * to) { - const ui32 stageDelay = 500; + uint32_t stageDelay = BUILDING_APPEAR_TIMEPOINT; - const ui32 S1_TRANSP = 500; //500 msec building appear 0->100 transparency - const ui32 S2_WHITE_B = 1000; //500 msec border glows from white to yellow - const ui32 S3_YELLOW_B= 1500; //500 msec border glows from yellow to normal - const ui32 BUILDED = 2500; //1000 msec delay, nothing happens - - if(stateTimeCounter < S1_TRANSP) + if(stateTimeCounter < BUILDING_APPEAR_TIMEPOINT) { setAlpha(255 * stateTimeCounter / stageDelay); CShowableAnim::show(to); @@ -172,9 +167,9 @@ void CBuildingRect::show(SDL_Surface * to) CShowableAnim::show(to); } - if(border && stateTimeCounter > S1_TRANSP) + if(border && stateTimeCounter > BUILDING_APPEAR_TIMEPOINT) { - if(stateTimeCounter >= BUILDED) + if(stateTimeCounter >= BUILD_ANIMATION_FINISHED_TIMEPOINT) { if(parent->selectedBuilding == this) blitAtLoc(border,0,0,to); @@ -191,10 +186,10 @@ void CBuildingRect::show(SDL_Surface * to) SDL_Color oldColor = border->format->palette->colors[colorID]; SDL_Color newColor; - if (stateTimeCounter < S2_WHITE_B) + if (stateTimeCounter < BUILDING_WHITE_BORDER_TIMEPOINT) newColor = multiplyColors(c1, c2, static_cast(stateTimeCounter % stageDelay) / stageDelay); else - if (stateTimeCounter < S3_YELLOW_B) + if (stateTimeCounter < BUILDING_YELLOW_BORDER_TIMEPOINT) newColor = multiplyColors(c2, c3, static_cast(stateTimeCounter % stageDelay) / stageDelay); else newColor = oldColor; @@ -204,7 +199,7 @@ void CBuildingRect::show(SDL_Surface * to) SDL_SetColors(border, &oldColor, colorID, 1); } } - if(stateTimeCounter < BUILDED) + if(stateTimeCounter < BUILD_ANIMATION_FINISHED_TIMEPOINT) stateTimeCounter += GH.mainFPSmng->getElapsedMilliseconds(); } @@ -634,7 +629,7 @@ void CCastleBuildings::addBuilding(BuildingID building) if(structures.size() == 1) buildingRect->stateTimeCounter = 0; // transparency -> fully visible stage else - buildingRect->stateTimeCounter = 500; // 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 55bdc31d0..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(); From c3b254a815982c64a99530004c8915751f6d6364 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Mon, 16 Jan 2023 18:26:31 +0100 Subject: [PATCH 4/4] Enum value can be used here as well --- client/windows/CCastleInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 8c8852be9..f55c1869b 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -47,7 +47,7 @@ CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town parent(Par), town(Town), str(Str), - stateTimeCounter(2500) + stateTimeCounter(BUILD_ANIMATION_FINISHED_TIMEPOINT) { addUsedEvents(LCLICK | RCLICK | HOVER); pos.x += str->pos.x;