From: otta8634 Date: Fri, 20 Dec 2024 11:30:19 +0000 (+0800) Subject: Some changes to color-related functions X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9c18f3405ee4a803aada4d54b26f0d937b385378;p=xonotic%2Fxonotic-data.pk3dir.git Some changes to color-related functions Added a new macro to color extra words after the m_name, in the guide. Bounded RGB parameters in rgb_to_hexcolor to [0,1]. --- diff --git a/qcsrc/common/colors.qh b/qcsrc/common/colors.qh index 48bf30453..830e3a80d 100644 --- a/qcsrc/common/colors.qh +++ b/qcsrc/common/colors.qh @@ -80,5 +80,7 @@ const vector COLOR_STATUSEFFECT_SPAWNSHIELD = '0.36 1 0.07'; const vector COLOR_STATUSEFFECT_STUNNED = '0.67 0.84 1'; const vector COLOR_STATUSEFFECT_WEBBED = '0.94 0.3 1'; -// Useful macro for the guide +// Useful macros for the guide #define COLORED_NAME(class) strcat(rgb_to_hexcolor(NEW(class).m_color), NEW(class).m_name, "^7") +#define COLORED_NAME_WITH_CONCAT(class, concat) strcat(rgb_to_hexcolor(NEW(class).m_color), NEW(class).m_name, " ", concat, "^7") +// These can't be used everywhere, or else it would cause circular includes by including "class" diff --git a/qcsrc/lib/color.qh b/qcsrc/lib/color.qh index 3a3a61fe3..c24369fae 100644 --- a/qcsrc/lib/color.qh +++ b/qcsrc/lib/color.qh @@ -184,8 +184,8 @@ string rgb_to_hexcolor(vector rgb) { return strcat( "^x", - DEC_TO_HEXDIGIT(floor(rgb.x * 15 + 0.5)), - DEC_TO_HEXDIGIT(floor(rgb.y * 15 + 0.5)), - DEC_TO_HEXDIGIT(floor(rgb.z * 15 + 0.5)) + DEC_TO_HEXDIGIT(floor(bound(0, rgb.x, 1) * 15 + 0.5)), + DEC_TO_HEXDIGIT(floor(bound(0, rgb.y, 1) * 15 + 0.5)), + DEC_TO_HEXDIGIT(floor(bound(0, rgb.z, 1) * 15 + 0.5)) ); }