]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Some changes to color-related functions
authorotta8634 <k9wolf@pm.me>
Fri, 20 Dec 2024 11:30:19 +0000 (19:30 +0800)
committerotta8634 <k9wolf@pm.me>
Fri, 20 Dec 2024 11:30:19 +0000 (19:30 +0800)
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].

qcsrc/common/colors.qh
qcsrc/lib/color.qh

index 48bf30453d5c3caf1500b5d9a73ab88d17534549..830e3a80d4f9da56a80f0a150a4e7403a81f402c 100644 (file)
@@ -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"
index 3a3a61fe33731b1ad0116acce5ba5ac2982d826c..c24369faef5e629c0f2dc6e86a0fae5e5d3e4806 100644 (file)
@@ -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))
                     );
 }