From c4c812dd1569575dfa08e837c74d238dc766ae28 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 22 Oct 2010 21:54:47 +0000 Subject: [PATCH] - updated chat player colors in console so ONLY playername is colored the players color (by request from titi) --- source/glest_game/graphics/renderer.cpp | 124 ++++++++++++------------ source/glest_game/graphics/renderer.h | 1 + 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index ffb57521..d5af3b44 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -26,6 +26,7 @@ #include #include #include "cache_manager.h" +#include "network_manager.h" #include "leak_dumper.h" using namespace Shared::Graphics; @@ -786,16 +787,8 @@ void Renderer::renderTextureQuad(int x, int y, int w, int h, const Texture2D *te assertGl(); } -void Renderer::renderConsole(const Console *console,const bool showFullConsole,const bool showMenuConsole){ - - if(console == NULL) { - throw runtime_error("console == NULL"); - } - - glPushAttrib(GL_ENABLE_BIT); - glEnable(GL_BLEND); +void Renderer::RenderConsoleLine(int lineIndex, string line,int playerIndex,int xPosition) { Vec4f fontColor; - if(game != NULL) { fontColor = game->getGui()->getDisplay()->getColor(); } @@ -806,70 +799,77 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole,c Vec4f defaultFontColor = fontColor; - if(showFullConsole) { + if(playerIndex >= 0) { std::map &crcPlayerTextureCache = CacheManager::getCachedItem< std::map >(GameConstants::playerTextureCacheLookupKey); + Vec3f playerColor = crcPlayerTextureCache[playerIndex]->getPixmap()->getPixel3f(0, 0); + fontColor.x = playerColor.x; + fontColor.y = playerColor.y; + fontColor.z = playerColor.z; + + GameNetworkInterface *gameNetInterface = NetworkManager::getInstance().getGameNetworkInterface(); + if(gameNetInterface != NULL && gameNetInterface->getGameSettings() != NULL) { + const GameSettings *gameSettings = gameNetInterface->getGameSettings(); + string playerName = gameSettings->getNetworkPlayerName(playerIndex); + if(StartsWith(line, playerName + ":") == true) { + line = line.erase(0,playerName.length()+1); + string headerLine = "*" + playerName + ":"; + + renderTextShadow( + headerLine, + CoreData::getInstance().getConsoleFont(), + fontColor, + xPosition, lineIndex * 20 + 20); - for(int i = 0; i < console->getStoredLineCount(); ++i) { - int playerIndex = console->getStoredLinePlayerIndex(i); - if(playerIndex >= 0) { - Vec3f playerColor = crcPlayerTextureCache[playerIndex]->getPixmap()->getPixel3f(0, 0); - fontColor.x = playerColor.x; - fontColor.y = playerColor.y; - fontColor.z = playerColor.z; - } - else { fontColor = defaultFontColor; + xPosition += (7 * (playerName.length() + 2)); } - - renderTextShadow( - console->getStoredLine(i), - CoreData::getInstance().getConsoleFont(), - fontColor, - 20, i*20+20); - } - } - else if(showMenuConsole) { - std::map &crcPlayerTextureCache = CacheManager::getCachedItem< std::map >(GameConstants::playerTextureCacheLookupKey); - - for(int i = 0; i < console->getStoredLineCount() && i < maxConsoleLines; ++i) { - int playerIndex = console->getStoredLinePlayerIndex(i); - if(playerIndex >= 0) { - Vec3f playerColor = crcPlayerTextureCache[playerIndex]->getPixmap()->getPixel3f(0, 0); - fontColor.x = playerColor.x; - fontColor.y = playerColor.y; - fontColor.z = playerColor.z; - } - else { - fontColor = defaultFontColor; - } - - renderTextShadow( - console->getStoredLine(i), - CoreData::getInstance().getConsoleFont(), - fontColor, - 20, i*20+20); } } else { - std::map &crcPlayerTextureCache = CacheManager::getCachedItem< std::map >(GameConstants::playerTextureCacheLookupKey); + fontColor = defaultFontColor; + } + renderTextShadow( + line, + CoreData::getInstance().getConsoleFont(), + fontColor, + xPosition, lineIndex * 20 + 20); +} + +void Renderer::renderConsole(const Console *console,const bool showFullConsole,const bool showMenuConsole){ + + if(console == NULL) { + throw runtime_error("console == NULL"); + } + + glPushAttrib(GL_ENABLE_BIT); + glEnable(GL_BLEND); + + if(showFullConsole) { + for(int i = 0; i < console->getStoredLineCount(); ++i) { + string line = console->getStoredLine(i); + int playerIndex = console->getStoredLinePlayerIndex(i); + int xPosition = 20; + + RenderConsoleLine(i, line,playerIndex,xPosition); + } + } + else if(showMenuConsole) { + for(int i = 0; i < console->getStoredLineCount() && i < maxConsoleLines; ++i) { + string line = console->getStoredLine(i); + int playerIndex = console->getStoredLinePlayerIndex(i); + int xPosition = 20; + + RenderConsoleLine(i, line,playerIndex,xPosition); + } + } + else { for(int i = 0; i < console->getLineCount(); ++i) { + string line = console->getLine(i); int playerIndex = console->getLinePlayerIndex(i); - if(playerIndex >= 0) { - Vec3f playerColor = crcPlayerTextureCache[playerIndex]->getPixmap()->getPixel3f(0, 0); - fontColor.x = playerColor.x; - fontColor.y = playerColor.y; - fontColor.z = playerColor.z; - } - else { - fontColor = defaultFontColor; - } + int xPosition = 20; - renderTextShadow( - console->getLine(i), - CoreData::getInstance().getConsoleFont(), - fontColor, - 20, i*20+20); + RenderConsoleLine(i, line,playerIndex,xPosition); } } glPopAttrib(); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index ee081bea..387da588 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -306,6 +306,7 @@ public: void renderBackground(const Texture2D *texture); void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha=1.f,const Vec3f *color=NULL); void renderConsole(const Console *console, const bool showAll=false, const bool showMenuConsole=false); + void RenderConsoleLine(int lineIndex, string line,int playerIndex,int xPosition); void renderChatManager(const ChatManager *chatManager); void renderResourceStatus(); void renderSelectionQuad();