summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp34
-rw-r--r--src/gui/speechbubble.cpp5
2 files changed, 33 insertions, 6 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 98aaeec2..3e621295 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -171,7 +171,39 @@ void Being::setSpeech(const std::string &text, Uint32 time)
{
mSpeech = text;
- mSpeechTime = 500;
+ // Trim whitespace
+ while (mSpeech[0] == ' ')
+ {
+ mSpeech = mSpeech.substr(1, mSpeech.size());
+ }
+ while (mSpeech[mSpeech.size()] == ' ')
+ {
+ mSpeech = mSpeech.substr(0, mSpeech.size() - 1);
+ }
+
+ // check for links
+ const std::string::size_type start = mSpeech.find('[');
+ const std::string::size_type end = mSpeech.find(']', start);
+
+ if (start != std::string::npos && end != std::string::npos)
+ {
+ mSpeech.erase(end);
+ std::string::size_type pos = mSpeech.find('@');
+
+ while (pos != std::string::npos)
+ {
+ mSpeech.erase(pos, 2);
+ pos = mSpeech.find('@');
+ }
+
+ pos = mSpeech.find('|');
+
+ if (pos != std::string::npos)
+ mSpeech = mSpeech.substr(pos + 1, mSpeech.size());
+ }
+
+ if (mSpeech != "")
+ mSpeechTime = 500;
}
void Being::takeDamage(int amount)
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 5539202e..4fa63973 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -61,11 +61,6 @@ SpeechBubble::SpeechBubble():
void SpeechBubble::setText(std::string mText)
{
- while (mText[0] == ' ')
- {
- mText = mText.substr(1, mText.size());
- }
-
mSpeechBox->setMinWidth(140);
mSpeechBox->setTextWrapped( mText );