2022-07-22 22:52:54 +03:00
|
|
|
#include "Chat.h"
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
void ChatManager::addNewMessage(std::string author, std::string message) {
|
2022-07-23 00:47:19 +03:00
|
|
|
hide = 7.0;
|
2022-07-22 22:52:54 +03:00
|
|
|
messages.push_back(message);
|
|
|
|
authors.push_back(author);
|
|
|
|
isChatUpdate = true;
|
2022-07-23 00:47:19 +03:00
|
|
|
if (messages.size() > 6) {
|
|
|
|
messages.erase(messages.begin());
|
|
|
|
}
|
2022-07-22 22:52:54 +03:00
|
|
|
}
|
|
|
|
int ChatManager::update(double delta) {
|
|
|
|
hide = std::max(hide-delta, 0.0);
|
2022-07-23 00:47:19 +03:00
|
|
|
if (hide < 0.0000001) {
|
|
|
|
messages.clear();
|
|
|
|
authors.clear();
|
|
|
|
}
|
2022-07-22 22:52:54 +03:00
|
|
|
return std::min((int)(hide * 255.0), 255);
|
|
|
|
|
|
|
|
}
|
|
|
|
std::string ChatManager::getChat() {
|
|
|
|
if (isChatUpdate) {
|
|
|
|
isChatUpdate = false;
|
|
|
|
int size = messages.size();
|
|
|
|
chatStr = "";
|
2022-07-23 00:47:19 +03:00
|
|
|
for (int messageIndex = messages.size()-1; messageIndex >= 0; messageIndex--)
|
2022-07-22 22:52:54 +03:00
|
|
|
{
|
|
|
|
chatStr += authors[messageIndex] + ": " + messages[messageIndex] + ";\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chatStr;
|
|
|
|
}
|