Minimize talk messages spam on screen

This commit is contained in:
Eduardo Bart 2012-07-26 19:56:46 -03:00
parent 964c73a6ad
commit 564463fa01
2 changed files with 10 additions and 7 deletions

View File

@ -66,7 +66,11 @@ bool StaticText::addMessage(const std::string& name, Otc::MessageMode mode, cons
m_updateEvent = nullptr; m_updateEvent = nullptr;
} }
m_messages.push_back(text); int delay = std::max<int>(Otc::STATIC_DURATION_PER_CHARACTER * text.length(), Otc::MIN_STATIC_TEXT_DURATION);
if(isYell())
delay *= 2;
m_messages.push_back(std::make_pair(text, g_clock.millis() + delay));
compose(); compose();
if(!m_updateEvent) if(!m_updateEvent)
@ -90,8 +94,7 @@ void StaticText::update()
void StaticText::scheduleUpdate() void StaticText::scheduleUpdate()
{ {
int len = m_messages.front().length(); int delay = std::max<int>(m_messages.front().second - g_clock.millis(), 0);
int delay = std::max(Otc::STATIC_DURATION_PER_CHARACTER * len, (int)Otc::MIN_STATIC_TEXT_DURATION);
auto self = asStaticText(); auto self = asStaticText();
m_updateEvent = g_dispatcher.scheduleEvent([self]() { m_updateEvent = g_dispatcher.scheduleEvent([self]() {
@ -117,7 +120,7 @@ void StaticText::compose()
text += m_name; text += m_name;
text += " yells:\n"; text += " yells:\n";
m_color = Color(239, 239, 0); m_color = Color(239, 239, 0);
} else if(m_mode == Otc::MessageMonsterSay || m_mode == Otc::MessageMonsterYell) { } else if(m_mode == Otc::MessageMonsterSay || m_mode == Otc::MessageMonsterYell || m_mode == Otc::MessageSpell) {
m_color = Color(254, 101, 0); m_color = Color(254, 101, 0);
} else if(m_mode == Otc::MessageNpcFrom) { } else if(m_mode == Otc::MessageNpcFrom) {
text += m_name; text += m_name;
@ -128,7 +131,7 @@ void StaticText::compose()
} }
for(uint i = 0; i < m_messages.size(); ++i) { for(uint i = 0; i < m_messages.size(); ++i) {
text += m_messages[i]; text += m_messages[i].first;
if(i < m_messages.size() - 1) if(i < m_messages.size() - 1)
text += "\n"; text += "\n";

View File

@ -37,7 +37,7 @@ public:
std::string getName() { return m_name; } std::string getName() { return m_name; }
Otc::MessageMode getMessageMode() { return m_mode; } Otc::MessageMode getMessageMode() { return m_mode; }
std::string getFirstMessage() { return m_messages[0]; } std::string getFirstMessage() { return m_messages[0].first; }
bool isYell() { return m_mode == Otc::MessageYell || m_mode == Otc::MessageMonsterYell; } bool isYell() { return m_mode == Otc::MessageYell || m_mode == Otc::MessageMonsterYell; }
@ -52,7 +52,7 @@ private:
void compose(); void compose();
Boolean<false> m_yell; Boolean<false> m_yell;
std::deque<std::string> m_messages; std::deque<std::pair<std::string, ticks_t>> m_messages;
std::string m_name; std::string m_name;
Otc::MessageMode m_mode; Otc::MessageMode m_mode;
Color m_color; Color m_color;