From 0602c8e7629d02757c984ac7485dfb45896c64fa Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 7 Feb 2016 14:19:55 +0100 Subject: [PATCH] Fading color. --- src/Components/Modules/Colors.cpp | 68 ++++++++++++++++++----- src/Components/Modules/Colors.hpp | 9 +++ src/Components/Modules/StructuredData.cpp | 1 + 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/src/Components/Modules/Colors.cpp b/src/Components/Modules/Colors.cpp index 69c9bd74..c3f01f9f 100644 --- a/src/Components/Modules/Colors.cpp +++ b/src/Components/Modules/Colors.cpp @@ -1,21 +1,59 @@ #include "STDInclude.hpp" -// -- Additional colors -- -// -// Colors are resolved using ColorIndex(). -// It resolves the colorTable entry using the ASCII value. -// If we want to add colors, we have to use correct ASCII chars. -// As the last value is 0x39 (9), we have to go on with 0x3A (:) -// So the next chars would be: -// 0x3A (:), 0x3B (;), 0x3C (<), 0x3D (=), ... -// -// The problem though is that I_CleanString doesn't know we added colors, so we have to adapt that as well! - namespace Components { Dvar::Var Colors::NewColors; std::vector Colors::ColorTable; + DWORD Colors::HsvToRgb(Colors::HsvColor hsv) + { + DWORD rgb; + unsigned char region, p, q, t; + unsigned int h, s, v, remainder; + + if (hsv.s == 0) + { + rgb = RGB(hsv.v, hsv.v, hsv.v); + return rgb; + } + + // converting to 16 bit to prevent overflow + h = hsv.h; + s = hsv.s; + v = hsv.v; + + region = static_cast(h / 43); + remainder = (h - (region * 43)) * 6; + + p = static_cast((v * (255 - s)) >> 8); + q = static_cast((v * (255 - ((s * remainder) >> 8))) >> 8); + t = static_cast((v * (255 - ((s * (255 - remainder)) >> 8))) >> 8); + + switch (region) + { + case 0: + rgb = RGB(v, t, p); + break; + case 1: + rgb = RGB(q, v, p); + break; + case 2: + rgb = RGB(p, v, t); + break; + case 3: + rgb = RGB(p, q, v); + break; + case 4: + rgb = RGB(t, p, v); + break; + default: + rgb = RGB(v, p, q); + break; + } + + return rgb; + } + void Colors::Strip(const char* in, char* out, int max) { if (!in || !out) return; @@ -117,6 +155,10 @@ namespace Components { *color = *reinterpret_cast(0x66E5F74); } + else if (index == ':') + { + *color = Colors::HsvToRgb({ static_cast((Game::Com_Milliseconds() / 200) % 256), 255,255 }); + } else { int clrIndex = Colors::ColorIndex(index); @@ -188,8 +230,8 @@ namespace Components Colors::Add(0, 0, 0); // 9 - Team color (allies?) // Custom colors - Colors::Add(211, 84, 0); // 10 - Orange (:) - Colors::Add(0, 255, 200); // 11 - Turqoise (;) - using that color in infostrings (e.g. your name) fails, ';' is an illegal character! + Colors::Add(0, 0, 0); // 10 - Rainbow (:) + //Colors::Add(0, 255, 200); // 11 - Turqoise (;) - using that color in infostrings (e.g. your name) fails, ';' is an illegal character! } Colors::~Colors() diff --git a/src/Components/Modules/Colors.hpp b/src/Components/Modules/Colors.hpp index 64baa0a9..cf445c29 100644 --- a/src/Components/Modules/Colors.hpp +++ b/src/Components/Modules/Colors.hpp @@ -13,6 +13,15 @@ namespace Components static char Add(uint8_t r, uint8_t g, uint8_t b); private: + struct HsvColor + { + unsigned char h; + unsigned char s; + unsigned char v; + }; + + static DWORD HsvToRgb(HsvColor hsv); + static Dvar::Var NewColors; static void ClientUserinfoChanged(); diff --git a/src/Components/Modules/StructuredData.cpp b/src/Components/Modules/StructuredData.cpp index 04f334ca..65f6548b 100644 --- a/src/Components/Modules/StructuredData.cpp +++ b/src/Components/Modules/StructuredData.cpp @@ -117,6 +117,7 @@ namespace Components StructuredData::Singleton = this; ZeroMemory(StructuredData::IndexCount, sizeof(StructuredData)); + // TODO: Write these into fastfiles and only hotpatch them when building fastfiles! AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF, [] (Game::XAssetType type, std::string filename) { Game::XAssetHeader header = { 0 };