From 13c6fb49b38ca3710b47f46aaac3ee9cee1ba89d Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Sat, 1 Jan 2011 20:31:25 +0000 Subject: [PATCH] chat highlighting, and more features related to chat --- source/glest_game/game/chat_manager.cpp | 17 ++++--- source/glest_game/game/chat_manager.h | 1 + source/glest_game/game/console.h | 5 ++ source/glest_game/global/core_data.cpp | 1 + source/glest_game/global/core_data.h | 2 + source/glest_game/graphics/renderer.cpp | 25 ++++++++-- source/glest_game/graphics/renderer.h | 2 +- .../menu/menu_state_masterserver.cpp | 26 +++++++--- .../glest_game/menu/menu_state_masterserver.h | 3 +- source/glest_game/menu/server_line.cpp | 50 +++++++------------ source/glest_game/menu/server_line.h | 4 +- 11 files changed, 82 insertions(+), 54 deletions(-) diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index 4af0cc630..c735ebccf 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -94,13 +94,16 @@ void ChatManager::keyDown(char key) { key == configKeys.getCharKey("ChatTeamMode")) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); - if(teamMode == true) { - teamMode= false; - console->addLine(lang.get("ChatMode") + ": " + lang.get("All")); - } - else { - teamMode= true; - console->addLine(lang.get("ChatMode") + ": " + lang.get("Team")); + if (!inMenu) { + if (teamMode == true) { + teamMode = false; + console->addLine(lang.get("ChatMode") + ": " + lang.get( + "All")); + } else { + teamMode = true; + console->addLine(lang.get("ChatMode") + ": " + lang.get( + "Team")); + } } } diff --git a/source/glest_game/game/chat_manager.h b/source/glest_game/game/chat_manager.h index 1dd06ee16..b2e591263 100644 --- a/source/glest_game/game/chat_manager.h +++ b/source/glest_game/game/chat_manager.h @@ -55,6 +55,7 @@ public: bool getEditEnabled() const {return editEnabled;} bool getTeamMode() const {return teamMode;} + bool getInMenu() const {return inMenu;} string getText() const {return text;} int getXPos() const {return xPos;} void setXPos(int xPos) {this->xPos= xPos;} diff --git a/source/glest_game/game/console.h b/source/glest_game/game/console.h index 8b4a886c6..30780972f 100644 --- a/source/glest_game/game/console.h +++ b/source/glest_game/game/console.h @@ -55,6 +55,7 @@ private: float timeElapsed; Lines lines; Lines storedLines; + string stringToHighlight; //config int maxLines; @@ -78,6 +79,10 @@ public: void setLineHeight(int lineHeight) {this->lineHeight= lineHeight;} Font2D *getFont() const {return font;} void setFont(Font2D *font) {this->font= font;} + string getStringToHighlight() const { return stringToHighlight;} + void setStringToHighlight(string stringToHighlight) { this->stringToHighlight = stringToHighlight;} + + string getLine(int i) const; string getStoredLine(int i) const; diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index e4c73f1a2..6bb20cadb 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -186,6 +186,7 @@ void CoreData::load() { clickSoundB.load(dir+"/menu/sound/click_b.wav"); clickSoundC.load(dir+"/menu/sound/click_c.wav"); attentionSound.load(dir+"/menu/sound/attention.wav"); + highlightSound.load(dir+"/menu/sound/highlight.wav"); introMusic.open(dir+"/menu/music/intro_music.ogg"); introMusic.setNext(&menuMusic); menuMusic.open(dir+"/menu/music/menu_music.ogg"); diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 85f6dbe9f..c24f0b345 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -42,6 +42,7 @@ private: StaticSound clickSoundB; StaticSound clickSoundC; StaticSound attentionSound; + StaticSound highlightSound; SoundContainer waterSounds; Texture2D *logoTexture; @@ -93,6 +94,7 @@ public: StaticSound *getClickSoundB() {return &clickSoundB;} StaticSound *getClickSoundC() {return &clickSoundC;} StaticSound *getAttentionSound() {return &attentionSound;} + StaticSound *getHighlightSound() {return &highlightSound;} StaticSound *getWaterSound() {return waterSounds.getRandSound();} Font2D *getDisplayFont() const {return displayFont;} diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 5a9c630b5..889074525 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -836,7 +836,7 @@ void Renderer::renderTextureQuad(int x, int y, int w, int h, const Texture2D *te } void Renderer::renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight, - const Font2D* font, const ConsoleLineInfo *lineInfo) { + const Font2D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo) { Vec4f fontColor; const Metrics &metrics= Metrics::getInstance(); const FontMetrics *fontMetrics= font->getMetrics(); @@ -909,6 +909,9 @@ void Renderer::renderConsoleLine(int lineIndex, int xPosition, int yPosition, in fontColor = defaultFontColor; } + if(lineInfo->text.find(stringToHightlight)!=string::npos){ + fontColor=Vec4f(1.f, 0.5f, 0.5f, 0.0f); + } renderTextShadow( lineInfo->text, font, @@ -928,21 +931,21 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole,c for(int i = 0; i < console->getStoredLineCount(); ++i) { const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i); renderConsoleLine(i, console->getXPos(), console->getYPos(), - console->getLineHeight(), console->getFont(), &lineInfo); + console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo); } } else if(showMenuConsole) { for(int i = 0; i < console->getStoredLineCount() && i < maxConsoleLines; ++i) { const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i); renderConsoleLine(i, console->getXPos(), console->getYPos(), - console->getLineHeight(), console->getFont(), &lineInfo); + console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo); } } else { for(int i = 0; i < console->getLineCount(); ++i) { const ConsoleLineInfo &lineInfo = console->getLineItem(i); renderConsoleLine(i, console->getXPos(), console->getYPos(), - console->getLineHeight(), console->getFont(), &lineInfo); + console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo); } } glPopAttrib(); @@ -955,7 +958,10 @@ void Renderer::renderChatManager(const ChatManager *chatManager) { if(chatManager->getEditEnabled()) { string text=""; - if(chatManager->getTeamMode()) { + if(chatManager->getInMenu()){ + text += lang.get("Chat"); + } + else if(chatManager->getTeamMode()) { text += lang.get("Team"); } else { @@ -981,6 +987,15 @@ void Renderer::renderChatManager(const ChatManager *chatManager) { //textRenderer->render(text, 300, 150); //textRenderer->end(); } + else + { + if (chatManager->getInMenu()) { + string text = ">> "+lang.get("PressEnterToChat")+" <<"; + fontColor = Vec4f(0.5f, 0.5f, 0.5f, 0.5f); + renderTextShadow(text, chatManager->getFont(), fontColor, + chatManager->getXPos(), chatManager->getYPos()); + } + } } void Renderer::renderResourceStatus(){ diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index e920b4ed2..ff01fbb36 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -312,7 +312,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, int xPosition, int yPosition, int lineHeight, const Font2D* font,const ConsoleLineInfo *lineInfo); + void renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight, const Font2D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo); void renderChatManager(const ChatManager *chatManager); void renderResourceStatus(); void renderSelectionQuad(); diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 46b10940c..6cd213399 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -232,6 +232,8 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen string netPlayerName=Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()); string ircname=netPlayerName.substr(0,9); sprintf(szIRCNick,"MG_%s_%d",ircname.c_str(),randomNickId); + currentIrcNick=ircname; + consoleIRC.setStringToHighlight(currentIrcNick); lines[2].init(0,consoleIRC.getYPos()-10,userButtonsXBase,5); chatManager.init(&consoleIRC, -1, true, szIRCNick); @@ -283,6 +285,13 @@ void MenuStateMasterserver::IRC_CallbackEvent(IRCEventType evt, const char* orig char szBuf[4096]=""; sprintf(szBuf,"%s: %s",origin ? origin : "someone",params[1]); + string helpSTr=szBuf; + if(helpSTr.find(currentIrcNick)!=string::npos){ + CoreData &coreData= CoreData::getInstance(); + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + + soundRenderer.playFx(coreData.getHighlightSound()); + } consoleIRC.addLine(szBuf); } } @@ -522,11 +531,13 @@ void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){ buttonRefresh.mouseMove(x, y); buttonReturn.mouseMove(x, y); buttonCreateGame.mouseMove(x, y); - if(ms->get(mbLeft)){ - userScrollBar.mouseDown(x, y); - } - else - userScrollBar.mouseMove(x, y); + if (ms->get(mbLeft)) { + userScrollBar.mouseDown(x, y); + serverScrollBar.mouseDown(x, y); + } else { + userScrollBar.mouseMove(x, y); + serverScrollBar.mouseMove(x, y); + } listBoxAutoRefresh.mouseMove(x, y); if(serverScrollBar.getElementCount()!=0 ) { @@ -650,13 +661,16 @@ void MenuStateMasterserver::update() { consoleIRC.update(); MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient); - safeMutexIRCPtr.Lock(); if(ircClient != NULL) { std::vector nickList = ircClient->getNickList(); bool isNew=false; //check if there is something new if( oldNickList.size()!=nickList.size()) { isNew=true; + if(currentIrcNick!=ircClient->getNick()){ + currentIrcNick=ircClient->getNick(); + consoleIRC.setStringToHighlight(currentIrcNick); + } } else { for(int i = 0; i < nickList.size(); ++i) { diff --git a/source/glest_game/menu/menu_state_masterserver.h b/source/glest_game/menu/menu_state_masterserver.h index 1c2a05085..8783a5c8c 100644 --- a/source/glest_game/menu/menu_state_masterserver.h +++ b/source/glest_game/menu/menu_state_masterserver.h @@ -76,7 +76,7 @@ private: SimpleTaskThread *updateFromMasterserverThread; bool playServerFoundSound; ServerLines serverLines; - std::string serverInfoString; + string serverInfoString; int serverLinesToRender; int serverLinesYBase; int serverLinesLineHeight; @@ -90,6 +90,7 @@ private: int userButtonsLineHeight; int userButtonsHeight; int userButtonsWidth; + string currentIrcNick; //Console console; diff --git a/source/glest_game/menu/server_line.cpp b/source/glest_game/menu/server_line.cpp index 17665f8f8..29d74887d 100644 --- a/source/glest_game/menu/server_line.cpp +++ b/source/glest_game/menu/server_line.cpp @@ -42,14 +42,10 @@ ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY, //general info: i+=10; - glestVersionLabel.registerGraphicComponent(containerName,"glestVersionLabel" + intToStr(lineIndex)); - registeredObjNameList.push_back("glestVersionLabel" + intToStr(lineIndex)); glestVersionLabel.init(i,baseY-lineOffset); glestVersionLabel.setText(masterServerInfo.getGlestVersion()); i+=80; - registeredObjNameList.push_back("platformLabel" + intToStr(lineIndex)); - platformLabel.registerGraphicComponent(containerName,"platformLabel" + intToStr(lineIndex)); platformLabel.init(i,baseY-lineOffset); platformLabel.setText(masterServerInfo.getPlatform()); @@ -61,71 +57,55 @@ ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY, //game info: i+=80; - registeredObjNameList.push_back("serverTitleLabel" + intToStr(lineIndex)); - serverTitleLabel.registerGraphicComponent(containerName,"serverTitleLabel" + intToStr(lineIndex)); serverTitleLabel.init(i,baseY-lineOffset); serverTitleLabel.setText(masterServerInfo.getServerTitle()); i+=200; - registeredObjNameList.push_back("ipAddressLabel" + intToStr(lineIndex)); - ipAddressLabel.registerGraphicComponent(containerName,"ipAddressLabel" + intToStr(lineIndex)); ipAddressLabel.init(i,baseY-lineOffset); ipAddressLabel.setText(masterServerInfo.getIpAddress()); + + wrongVersionLabel.init(i,baseY-lineOffset); + wrongVersionLabel.setText(lang.get("IncompatibleVersion")); + //game setup info: i+=120; - registeredObjNameList.push_back("techLabel" + intToStr(lineIndex)); - techLabel.registerGraphicComponent(containerName,"techLabel" + intToStr(lineIndex)); techLabel.init(i,baseY-lineOffset); techLabel.setText(masterServerInfo.getTech()); i+=100; - registeredObjNameList.push_back("mapLabel" + intToStr(lineIndex)); - mapLabel.registerGraphicComponent(containerName,"mapLabel" + intToStr(lineIndex)); mapLabel.init(i,baseY-lineOffset); mapLabel.setText(masterServerInfo.getMap()); i+=100; - registeredObjNameList.push_back("tilesetLabel" + intToStr(lineIndex)); - tilesetLabel.registerGraphicComponent(containerName,"tilesetLabel" + intToStr(lineIndex)); tilesetLabel.init(i,baseY-lineOffset); tilesetLabel.setText(masterServerInfo.getTileset()); i+=100; - registeredObjNameList.push_back("activeSlotsLabel" + intToStr(lineIndex)); - activeSlotsLabel.registerGraphicComponent(containerName,"activeSlotsLabel" + intToStr(lineIndex)); activeSlotsLabel.init(i,baseY-lineOffset); activeSlotsLabel.setText(intToStr(masterServerInfo.getActiveSlots())+"/"+intToStr(masterServerInfo.getNetworkSlots())+"/"+intToStr(masterServerInfo.getConnectedClients())); i+=50; - registeredObjNameList.push_back("externalConnectPort" + intToStr(lineIndex)); - externalConnectPort.registerGraphicComponent(containerName,"externalConnectPort" + intToStr(lineIndex)); externalConnectPort.init(i,baseY-lineOffset); externalConnectPort.setText(intToStr(masterServerInfo.getExternalConnectPort())); i+=50; - registeredObjNameList.push_back("selectButton" + intToStr(lineIndex)); - selectButton.registerGraphicComponent(containerName,"selectButton" + intToStr(lineIndex)); selectButton.init(i, baseY-lineOffset, 30); selectButton.setText(">"); //printf("glestVersionString [%s] masterServerInfo->getGlestVersion() [%s]\n",glestVersionString.c_str(),masterServerInfo->getGlestVersion().c_str()); - bool compatible = checkVersionComptability(glestVersionString, masterServerInfo.getGlestVersion()); + compatible = checkVersionComptability(glestVersionString, masterServerInfo.getGlestVersion()); selectButton.setEnabled(compatible); selectButton.setEditable(compatible); - registeredObjNameList.push_back("gameFull" + intToStr(lineIndex)); - gameFull.registerGraphicComponent(containerName,"gameFull" + intToStr(lineIndex)); gameFull.init(i, baseY-lineOffset); gameFull.setText(lang.get("MGGameSlotsFull")); gameFull.setEnabled(!compatible); gameFull.setEditable(!compatible); - GraphicComponent::applyAllCustomProperties(containerName); } ServerLine::~ServerLine() { - GraphicComponent::clearRegisterGraphicComponent(containerName, registeredObjNameList); //delete masterServerInfo; } @@ -168,14 +148,20 @@ void ServerLine::render() { //game info: renderer.renderLabel(&serverTitleLabel); if(!gameFull.getEnabled()){ - renderer.renderLabel(&ipAddressLabel); + if (compatible) { + renderer.renderLabel(&ipAddressLabel); + + //game setup info: + renderer.renderLabel(&techLabel); + renderer.renderLabel(&mapLabel); + renderer.renderLabel(&tilesetLabel); + renderer.renderLabel(&activeSlotsLabel); + renderer.renderLabel(&externalConnectPort); + } + else { + renderer.renderLabel(&wrongVersionLabel); + } - //game setup info: - renderer.renderLabel(&techLabel); - renderer.renderLabel(&mapLabel); - renderer.renderLabel(&tilesetLabel); - renderer.renderLabel(&activeSlotsLabel); - renderer.renderLabel(&externalConnectPort); } } diff --git a/source/glest_game/menu/server_line.h b/source/glest_game/menu/server_line.h index 04a80d661..60b66adf6 100644 --- a/source/glest_game/menu/server_line.h +++ b/source/glest_game/menu/server_line.h @@ -31,8 +31,10 @@ private: MasterServerInfo masterServerInfo; int lineHeight; int baseY; + bool compatible; GraphicButton selectButton; GraphicLabel gameFull; + GraphicLabel wrongVersionLabel; //general info: GraphicLabel glestVersionLabel; @@ -52,7 +54,6 @@ private: GraphicLabel externalConnectPort; const char * containerName; - std::vector registeredObjNameList; public: ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY, int lineHeight, const char *containerName); @@ -64,7 +65,6 @@ public: void setY(int y); //void setIndex(int value); void render(); - }; }}//end namespace