- mod description now word wraps on \n
This commit is contained in:
parent
29bb7800f6
commit
26b1785b7a
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
};
|
||||
|
||||
// ===========================================================
|
||||
|
|
|
@ -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<string> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue