From 6dbcfc204fce857f40bc1d4ab10177840e174082 Mon Sep 17 00:00:00 2001 From: Nikolay Borodin Date: Wed, 14 Feb 2024 13:07:30 +0200 Subject: [PATCH] Let's use enums for groupnumber --- src/display3d.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/display3d.cpp b/src/display3d.cpp index be58557668d..69a7434f0eb 100644 --- a/src/display3d.cpp +++ b/src/display3d.cpp @@ -3622,6 +3622,12 @@ static void drawDroidAndStructureSelections() /// X/Y offset to display the group number at #define GN_X_OFFSET (8) #define GN_Y_OFFSET (3) +enum GROUPNUMBER_TYPE +{ + GN_NORMAL, + GN_DAMAGED, + GN_FACTORY +}; /// rendering of the unit's group next to the unit itself, /// or the group that will be assigned to the unit after production in the factory static void drawGroupNumber(BASE_OBJECT *psObject) @@ -3629,8 +3635,7 @@ static void drawGroupNumber(BASE_OBJECT *psObject) UWORD id = UWORD_MAX; UBYTE groupNumber = UBYTE_MAX; int32_t x = 0, y = 0; - bool isFactory = false; - bool wentToRepair = false; + GROUPNUMBER_TYPE groupNumberType = GN_NORMAL; if (auto *psDroid = dynamic_cast(psObject)) { @@ -3642,7 +3647,7 @@ static void drawGroupNumber(BASE_OBJECT *psObject) if (psDroid->repairGroup != UBYTE_MAX) { groupNumber = psDroid->repairGroup; - wentToRepair = true; + groupNumberType = GN_DAMAGED; } else { groupNumber = psDroid->group; } @@ -3660,7 +3665,7 @@ static void drawGroupNumber(BASE_OBJECT *psObject) y = scrY - GN_Y_OFFSET; groupNumber = psStruct->productToGroup; - isFactory = true; + groupNumberType = GN_FACTORY; } switch (groupNumber) @@ -3701,17 +3706,19 @@ static void drawGroupNumber(BASE_OBJECT *psObject) if (id != UWORD_MAX) { - if (wentToRepair) + switch (groupNumberType) { + case GN_NORMAL: + iV_DrawImage(IntImages, id, x, y); + break; + case GN_DAMAGED: iV_DrawImageTint(IntImages, id, x, y, pal_RGBA(255, 0, 0, 255) /* red */); - } - else if (isFactory) - { + break; + case GN_FACTORY: iV_DrawImageTint(IntImages, id, x, y, pal_RGBA(255, 220, 115, 255) /* gold */); - } - else - { - iV_DrawImage(IntImages, id, x, y); + break; + default: + break; } } }