1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Minor refactoring from code review

This commit is contained in:
Dydzio 2023-01-16 00:33:53 +01:00
parent 7dd7f4af54
commit 54e499f5e7
2 changed files with 16 additions and 13 deletions

View File

@ -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<double>(stateTimeCounter % stageDelay) / stageDelay);
else
if (stateTimeCounter < S3_YELLOW_B)
if (stateTimeCounter < BUILDING_YELLOW_BORDER_TIMEPOINT)
newColor = multiplyColors(c2, c3, static_cast<double>(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;
}
}

View File

@ -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();