From f5e21ae8963aef6f6036eac376a66f88922d4e39 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Thu, 8 Apr 2010 20:19:25 +0000 Subject: [PATCH] ingame fontcolor change with key 'C' is back --- source/glest_game/game/game.cpp | 6 +- source/glest_game/graphics/renderer.cpp | 22 +++-- source/glest_game/graphics/renderer.h | 2 +- source/glest_game/gui/display.cpp | 98 +++++++++++++++++++++++ source/glest_game/gui/display.h | 102 ++++++++++++++++++++++++ source/glest_game/gui/gui.cpp | 4 + source/glest_game/gui/gui.h | 3 +- 7 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 source/glest_game/gui/display.cpp create mode 100644 source/glest_game/gui/display.h diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index a2deb6f7..f98b097d 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -656,7 +656,11 @@ void Game::keyDown(char key){ } } } - + //switch display color + else if(key=='C'){ + gui.switchToNextDisplayColor(); + } + //increment speed else if(key==vkAdd){ if(speedChangesAllowed){ diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index df9da383..ae60cc25 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -689,6 +689,7 @@ void Renderer::renderTextureQuad(int x, int y, int w, int h, const Texture2D *te } void Renderer::renderConsole(const Console *console){ + const Gui *gui= game->getGui(); glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); @@ -696,6 +697,7 @@ void Renderer::renderConsole(const Console *console){ renderTextShadow( console->getLine(i), CoreData::getInstance().getConsoleFont(), + gui->getDisplay()->getColor(), 20, i*20+20); } @@ -726,6 +728,7 @@ void Renderer::renderChatManager(const ChatManager *chatManager){ void Renderer::renderResourceStatus(){ const Metrics &metrics= Metrics::getInstance(); + const Gui *gui= game->getGui(); const World *world= game->getWorld(); const Faction *thisFaction= world->getFaction(world->getThisFactionIndex()); @@ -774,6 +777,7 @@ void Renderer::renderResourceStatus(){ renderTextShadow( str, CoreData::getInstance().getDisplayFontSmall(), + gui->getDisplay()->getColor(), j*100+220, metrics.getVirtualH()-30, false); ++j; } @@ -846,15 +850,18 @@ void Renderer::renderText(const string &text, const Font2D *font, const Vec3f &c glPopAttrib(); } -void Renderer::renderTextShadow(const string &text, const Font2D *font, int x, int y, bool centered){ +void Renderer::renderTextShadow(const string &text, const Font2D *font,const Vec4f &color, int x, int y, bool centered){ glPushAttrib(GL_CURRENT_BIT); Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y); - textRenderer->begin(font); - glColor3f(0.0f, 0.0f, 0.0f); - textRenderer->render(text, pos.x-1.0f, pos.y-1.0f); - glColor3f(1.0f, 1.0f, 1.0f); + if(color.w<0.5) + { + textRenderer->begin(font); + glColor3f(0.0f, 0.0f, 0.0f); + textRenderer->render(text, pos.x-1.0f, pos.y-1.0f); + } + glColor3f(color.x,color.y,color.z); textRenderer->render(text, pos.x, pos.y); textRenderer->end(); @@ -1717,11 +1724,12 @@ void Renderer::renderDisplay(){ const Display *display= game->getGui()->getDisplay(); glPushAttrib(GL_ENABLE_BIT); - + //infoString renderTextShadow( display->getInfoText().c_str(), coreData.getDisplayFont(), + display->getColor(), metrics.getDisplayX(), metrics.getDisplayY()+Display::infoStringY); @@ -1729,6 +1737,7 @@ void Renderer::renderDisplay(){ renderTextShadow( display->getTitle().c_str(), coreData.getDisplayFont(), + display->getColor(), metrics.getDisplayX()+40, metrics.getDisplayY() + metrics.getDisplayH() - 20); @@ -1738,6 +1747,7 @@ void Renderer::renderDisplay(){ renderTextShadow( display->getText().c_str(), coreData.getDisplayFont(), + display->getColor(), metrics.getDisplayX() -1, metrics.getDisplayY() + metrics.getDisplayH() - 56); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 063a7b43..d8a2404e 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -231,7 +231,7 @@ public: void renderSelectionQuad(); void renderText(const string &text, const Font2D *font, float alpha, int x, int y, bool centered= false); void renderText(const string &text, const Font2D *font, const Vec3f &color, int x, int y, bool centered= false); - void renderTextShadow(const string &text, const Font2D *font, int x, int y, bool centered= false); + void renderTextShadow(const string &text, const Font2D *font,const Vec4f &color, int x, int y, bool centered= false); //components void renderLabel(const GraphicLabel *label); diff --git a/source/glest_game/gui/display.cpp b/source/glest_game/gui/display.cpp new file mode 100644 index 00000000..3d2c8a0f --- /dev/null +++ b/source/glest_game/gui/display.cpp @@ -0,0 +1,98 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Marti�o Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "display.h" + +#include "metrics.h" +#include "command_type.h" +#include "leak_dumper.h" + +using namespace Shared::Graphics; + +namespace Glest{ namespace Game{ + +// ===================================================== +// class Display +// ===================================================== + +Display::Display(){ + colors[0]= Vec4f(1.f, 1.f, 1.f, 0.0f); + colors[1]= Vec4f(1.f, 0.5f, 0.5f, 0.0f); + colors[2]= Vec4f(0.5f, 0.5f, 1.0f, 0.0f); + colors[3]= Vec4f(0.5f, 1.0f, 0.5f, 0.0f); + colors[4]= Vec4f(0.0f, 0.0f, 0.0f, 1.0f); + colors[5]= Vec4f(0.0f, 0.0f, 1.0f, 1.0f); + colors[6]= Vec4f(1.0f, 0.0f, 0.0f, 1.0f); + colors[7]= Vec4f(0.0f, 1.0f, 0.0f, 1.0f); + colors[8]= Vec4f(1.0f, 1.0f, 1.0f, 1.0f); + + currentColor= 0; + + clear(); +} + +//misc +void Display::clear(){ + for(int i=0; iimageSize*cellSideCount){ + return invalidPos; + } + + int cellX= x/imageSize; + int cellY= (y/imageSize) % cellSideCount; + int index= (cellSideCount-cellY-1)*cellSideCount+cellX;; + + if(index<0 || index>=downCellCount || downImages[index]==NULL){ + index= invalidPos; + } + + return index; +} + +int Display::computeDownX(int index) const{ + return (index % cellSideCount) * imageSize; +} + +int Display::computeDownY(int index) const{ + return Display::downY - (index/cellSideCount)*imageSize - imageSize; +} + +int Display::computeUpX(int index) const{ + return (index % cellSideCount) * imageSize; +} + +int Display::computeUpY(int index) const{ + return Metrics::getInstance().getDisplayH() - (index/cellSideCount)*imageSize - imageSize; +} + +}}//end namespace diff --git a/source/glest_game/gui/display.h b/source/glest_game/gui/display.h new file mode 100644 index 00000000..857e3877 --- /dev/null +++ b/source/glest_game/gui/display.h @@ -0,0 +1,102 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Marti�o Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _GLEST_GAME_DISPLAY_H_ +#define _GLEST_GAME_DISPLAY_H_ + +#include + +#include "texture.h" +#include "util.h" +#include "command_type.h" +#include "game_util.h" + +using std::string; + +using Shared::Graphics::Texture2D; +using Shared::Graphics::Vec4f; +using Shared::Util::replaceBy; + +namespace Glest{ namespace Game{ + +// ===================================================== +// class Display +// +/// Display for unit commands, and unit selection +// ===================================================== + +class Display{ +public: + static const int cellSideCount= 4; + static const int upCellCount= cellSideCount*cellSideCount; + static const int downCellCount= cellSideCount*cellSideCount; + static const int colorCount= 9; + static const int imageSize= 32; + static const int invalidPos= -1; + static const int downY = imageSize*9; + static const int infoStringY= imageSize*4; + +private: + string title; + string text; + string infoText; + const Texture2D *upImages[upCellCount]; + const Texture2D *downImages[downCellCount]; + bool downLighted[downCellCount]; + const CommandType *commandTypes[downCellCount]; + CommandClass commandClasses[downCellCount]; + int progressBar; + int downSelectedPos; + Vec4f colors[colorCount]; + int currentColor; + + +public: + Display(); + + //get + string getTitle() const {return title;} + string getText() const {return text;} + string getInfoText() const {return infoText;} + const Texture2D *getUpImage(int index) const {return upImages[index];} + const Texture2D *getDownImage(int index) const {return downImages[index];} + bool getDownLighted(int index) const {return downLighted[index];} + const CommandType *getCommandType(int i) {return commandTypes[i];} + CommandClass getCommandClass(int i) {return commandClasses[i];} + Vec4f getColor() const {return colors[currentColor];} + int getProgressBar() const {return progressBar;} + int getDownSelectedPos() const {return downSelectedPos;} + + //set + void setTitle(const string title) {this->title= formatString(title);} + void setText(const string &text) {this->text= formatString(text);} + void setInfoText(const string infoText) {this->infoText= formatString(infoText);} + void setUpImage(int i, const Texture2D *image) {upImages[i]= image;} + void setDownImage(int i, const Texture2D *image) {downImages[i]= image;} + void setCommandType(int i, const CommandType *ct) {commandTypes[i]= ct;} + void setCommandClass(int i, const CommandClass cc) {commandClasses[i]= cc;} + void setDownLighted(int i, bool lighted) {downLighted[i]= lighted;} + void setProgressBar(int i) {progressBar= i;} + void setDownSelectedPos(int i) {downSelectedPos= i;} + + //misc + void clear(); + void switchColor(); + int computeDownIndex(int x, int y); + int computeDownX(int index) const; + int computeDownY(int index) const; + int computeUpX(int index) const; + int computeUpY(int index) const; +}; + +}}//end namespace + +#endif diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 0dfcffb4..b90b587a 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -361,6 +361,10 @@ void Gui::hotKey(char key){ } } +void Gui::switchToNextDisplayColor(){ + display.switchColor(); +} + void Gui::onSelectionChanged(){ resetState(); computeDisplay(); diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 373b8d87..235bdb9f 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -174,6 +174,7 @@ public: void hotKey(char key); //misc + void switchToNextDisplayColor(); void onSelectionChanged(); private: