commit 1a09fcd5
Replaced the help text with SagoText*.objects
Changed files
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 5fdf55c..34c8a75 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -34,6 +34,7 @@ http://www.blockattack.net
#define WITH_SDL 1
#include "sago/SagoSpriteHolder.hpp"
+#include "sago/SagoTextBox.hpp"
#include <iostream>
#include <stdlib.h>
#include <time.h> //Used for srand()
@@ -519,24 +520,49 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
infostring = _("Score as much as possible. No time limit.");
}
if (infostring.length() > 0) {
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10, gametypeName);
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160, _("Objective:"));
- globalData.standard_blue_font.drawBox(globalData.screen, { static_cast<float>(theGame2->GetTopX()+7),static_cast<float>(theGame2->GetTopY()+160+32), 280, 200}, infostring);
+ static sago::SagoTextBox infoBox;
+ static sago::SagoTextField objectiveField;
+ static sago::SagoTextField gametypeNameField;
+ infoBox.SetHolder(&globalData.spriteHolder->GetDataHolder());
+ infoBox.SetFont("freeserif");
+ infoBox.SetFontSize(30);
+ infoBox.SetMaxWidth(290);
+ infoBox.SetOutline(1, {0,0,0,255});
+ infoBox.SetText(infostring.c_str());
+ objectiveField.SetHolder(&globalData.spriteHolder->GetDataHolder());
+ objectiveField.SetFont("freeserif");
+ objectiveField.SetFontSize(30);
+ objectiveField.SetOutline(1, {0,0,0,255});
+ objectiveField.SetText(_("Objective:"));
+ gametypeNameField.SetHolder(&globalData.spriteHolder->GetDataHolder());
+ gametypeNameField.SetFont("freeserif");
+ gametypeNameField.SetFontSize(30);
+ gametypeNameField.SetOutline(1, {0,0,0,255});
+ gametypeNameField.SetText(gametypeName.c_str());
+ gametypeNameField.Draw(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10);
+ objectiveField.Draw(globalData.screen, theGame2->GetTopX()+7, theGame2->GetTopY()+160);
+ infoBox.Draw(globalData.screen, theGame2->GetTopX()+7, theGame2->GetTopY()+160+32);
}
//Write the keys that are in use
int y = theGame2->GetTopY()+400;
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,y,_("Movement keys:") );
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+120,( _("Switch: ")+getKeyName(keySettings[0].change) ).c_str() );
+ std::string controldBoxText = std::string(_("Movement keys:"))+"\n"+getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+",\n"
+ + getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)+"\n"
+ + _("Switch: ") + getKeyName(keySettings[0].change);
if (theGame->isPuzzleMode()) {
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+160,( _("Restart: ")+getKeyName(keySettings[0].push) ).c_str() );
+ controldBoxText += std::string("\n") + _("Restart: ")+getKeyName(keySettings[0].push);
}
else {
- NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+160,( _("Push line: ")+getKeyName(keySettings[0].push) ).c_str() );
+ controldBoxText += std::string("\n") + _("Push line: ")+getKeyName(keySettings[0].push);
}
-
+ static sago::SagoTextBox controldBox;
+ controldBox.SetHolder(&globalData.spriteHolder->GetDataHolder());
+ controldBox.SetFont("freeserif");
+ controldBox.SetFontSize(30);
+ controldBox.SetMaxWidth(290);
+ controldBox.SetOutline(1, {0,0,0,255});
+ controldBox.SetText(controldBoxText.c_str());
+ controldBox.Draw(globalData.screen, theGame2->GetTopX()+7,y);
}
strHolder = std::to_string(theGame2->GetScore()+theGame2->GetHandicap());
NFont_Write(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
diff --git a/source/code/sago/SagoTextBox.cpp b/source/code/sago/SagoTextBox.cpp
index d0efbfb..01694ac 100644
--- a/source/code/sago/SagoTextBox.cpp
+++ b/source/code/sago/SagoTextBox.cpp
@@ -32,7 +32,7 @@ SOFTWARE.
namespace sago {
struct SagoTextBox::SagoTextBoxData {
- sago::SagoDataHolder* tex = nullptr;
+ const sago::SagoDataHolder* tex = nullptr;
std::string fontName = "freeserif";
SDL_Color color = { 255, 255, 255, 0 };
SDL_Color outlineColor = { 255, 255, 0, 0 };
@@ -52,7 +52,7 @@ SagoTextBox::~SagoTextBox() {
delete data;
}
-void SagoTextBox::SetHolder(SagoDataHolder* holder) {
+void SagoTextBox::SetHolder(const SagoDataHolder* holder) {
data->tex = holder;
}
@@ -144,6 +144,10 @@ void SagoTextBox::SplitAndAppendLineToCache(TTF_Font* font, const std::string& t
}
std::string firstPart(text.begin(), splitLocation);
AppendLineToCache(firstPart);
+ while (splitLocation != text.end() && *splitLocation == ' ') {
+ //Trim spaces after an automatic line break.
+ ++splitLocation;
+ }
if (splitLocation == text.end()) {
return;
}
@@ -157,6 +161,7 @@ void SagoTextBox::UpdateCache() {
const std::string& s = data->text;
auto start = 0U;
auto end = s.find(delim);
+ data->lines.clear();
while (end != std::string::npos)
{
const std::string& theSubString = s.substr(start, end - start);
diff --git a/source/code/sago/SagoTextBox.hpp b/source/code/sago/SagoTextBox.hpp
index fc28c3e..6fe19d9 100644
--- a/source/code/sago/SagoTextBox.hpp
+++ b/source/code/sago/SagoTextBox.hpp
@@ -34,7 +34,7 @@ class SagoTextBox {
public:
SagoTextBox();
virtual ~SagoTextBox();
- void SetHolder(SagoDataHolder* holder);
+ void SetHolder(const SagoDataHolder* holder);
void SetText(const char* text);
void SetColor(const SDL_Color& color);
void SetFont(const char* fontName);
diff --git a/source/code/sago/SagoTextField.cpp b/source/code/sago/SagoTextField.cpp
index 2a3641c..831d3f1 100644
--- a/source/code/sago/SagoTextField.cpp
+++ b/source/code/sago/SagoTextField.cpp
@@ -59,7 +59,7 @@ namespace sago {
};
struct SagoTextField::SagoTextFieldData {
- sago::SagoDataHolder* tex = nullptr;
+ const sago::SagoDataHolder* tex = nullptr;
SDL_Surface* textSurface = nullptr;
SDL_Texture* texture = nullptr;
SDL_Surface* outlineTextSurface = nullptr;
@@ -91,7 +91,7 @@ SagoTextField::~SagoTextField() {
delete data;
}
-void SagoTextField::SetHolder(SagoDataHolder* holder) {
+void SagoTextField::SetHolder(const SagoDataHolder* holder) {
data->tex = holder;
}
diff --git a/source/code/sago/SagoTextField.hpp b/source/code/sago/SagoTextField.hpp
index 2edae17..ab05c49 100644
--- a/source/code/sago/SagoTextField.hpp
+++ b/source/code/sago/SagoTextField.hpp
@@ -48,7 +48,7 @@ public:
* Sets the data holder. This is MANDATORY
* @param holder The data holder to fetch the fonts from
*/
- void SetHolder(SagoDataHolder* holder);
+ void SetHolder(const SagoDataHolder* holder);
/**
* Set the text to display.
* @param text The actual UTF-8 encoded text