From 26b1785b7a48163e3781248c2eb8da638872204b Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 16 Apr 2011 18:53:57 +0000 Subject: [PATCH] - mod description now word wraps on \n --- source/glest_game/facilities/components.cpp | 5 ++- source/glest_game/facilities/components.h | 10 ++++- source/glest_game/graphics/renderer.cpp | 42 +++++++++++++-------- source/glest_game/menu/menu_state_mods.cpp | 6 ++- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 111c0932..2750e502 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -249,10 +249,11 @@ void GraphicComponent::resetFade(){ const int GraphicLabel::defH= 20; const int GraphicLabel::defW= 70; -void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor){ +void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor, bool wordWrap) { GraphicComponent::init(x, y, w, h); this->centered= centered; this->textColor=textColor; + this->wordWrap = wordWrap; } // ===================================================== @@ -264,7 +265,7 @@ const int GraphicButton::defW= 90; GraphicButton::GraphicButton(std::string containerName, std::string objName) : GraphicComponent(containerName,objName) { lighted = false; - useCustomTexture = false;; + useCustomTexture = false; customTexture = NULL; } diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index 3a1f1b88..18ed324d 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -75,6 +75,9 @@ public: virtual void init(int x, int y, int w, int h); + string getInstanceName() const { return instanceName; } + void setInstanceName(string value) { instanceName = value; } + virtual int getX() const {return x;} virtual int getY() const {return y;} virtual int getW() const {return w;} @@ -116,14 +119,19 @@ public: private: bool centered; Vec3f textColor; + bool wordWrap; public: - void init(int x, int y, int w=defW, int h=defH, bool centered= false, Vec3f textColor=Vec3f(1.f, 1.f, 1.f)); + void init(int x, int y, int w=defW, int h=defH, bool centered= false, Vec3f textColor=Vec3f(1.f, 1.f, 1.f), bool wordWrap=false); bool getCentered() const {return centered;} void setCentered(bool centered) {this->centered= centered;} Vec3f getTextColor() const {return textColor;} void setTextColor(Vec3f color) {this->textColor= color;} + + bool getWordWrap() const { return wordWrap; } + void setWordWrap(bool value) { wordWrap = value; } + }; // =========================================================== diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index e50454b9..a90324da 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1295,26 +1295,36 @@ void Renderer::renderLabel(const GraphicLabel *label,const Vec4f *color) { glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); - Vec2i textPos; - int x= label->getX(); - int y= label->getY(); - int h= label->getH(); - int w= label->getW(); - - if(label->getCentered()){ - textPos= Vec2i(x+w/2, y+h/2); - } - else{ - textPos= Vec2i(x, y+h/4); - } - - if(color != NULL) { - renderText(label->getText(), label->getFont(), (*color), textPos.x, textPos.y, label->getCentered()); + vector lines; + if(label->getWordWrap() == true) { + Tokenize(label->getText(),lines,"\n"); } else { - renderText(label->getText(), label->getFont(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered()); + lines.push_back(label->getText()); } + for(unsigned int i = 0; i < lines.size(); ++i) { + Vec2i textPos; + int x= label->getX(); + int y= label->getY() - (i * label->getH()); + int h= label->getH(); + int w= label->getW(); + //if(label->getInstanceName() == "modDescrLabel") printf("~~~ lines.size() [%u] i = %d lines[i] [%s] y = %d\n",lines.size(),i,lines[i].c_str(),y); + + if(label->getCentered()){ + textPos= Vec2i(x+w/2, y+h/2); + } + else{ + textPos= Vec2i(x, y+h/4); + } + + if(color != NULL) { + renderText(lines[i], label->getFont(), (*color), textPos.x, textPos.y, label->getCentered()); + } + else { + renderText(lines[i], label->getFont(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered()); + } + } glPopAttrib(); } diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index 810716a8..f84b89e7 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -133,6 +133,7 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) : modDescrLabel.registerGraphicComponent(containerName,"modDescrLabel"); modDescrLabel.init(50,installButtonYPos-60 - 20,450,20); + modDescrLabel.setWordWrap(true); modDescrLabel.setText("description is empty"); buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); @@ -1649,7 +1650,10 @@ string MenuStateMods::getPreviewImageFileForMod(const ModInfo *modInfo) { void MenuStateMods::showDesription(const ModInfo *modInfo) { displayModPreviewImage = false; modInfoSelected = *modInfo; - modDescrLabel.setText(modInfo->description); + + string modText = modInfo->description; + replaceAll(modText, "\\n", "\n"); + modDescrLabel.setText(modText); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("### modInfo->imageUrl [%s]\n",modInfo->imageUrl.c_str());