add MP chat ignore list,
...commands are /ignore add <nick> /ignore remove <nick> /ignore list and /ignore clear
This commit is contained in:
parent
f0474fbe44
commit
8e4701ff14
6 changed files with 214 additions and 64 deletions
|
@ -60,6 +60,7 @@ SVN trunk (1.1.1+svn):
|
|||
* tab completion now completes to smallest substring, and show possible
|
||||
completions
|
||||
* added whisper support for lobby and observers in game
|
||||
* Added ignore list on MP
|
||||
|
||||
Version 1.1.1:
|
||||
* campaigns
|
||||
|
|
135
src/display.cpp
135
src/display.cpp
|
@ -2465,70 +2465,85 @@ namespace {
|
|||
|
||||
void display::add_chat_message(const std::string& speaker, int side, const std::string& message, display::MESSAGE_TYPE type)
|
||||
{
|
||||
bool action;
|
||||
std::string msg;
|
||||
|
||||
if(message.find("/me ") == 0) {
|
||||
msg.assign(message,4,message.size());
|
||||
action = true;
|
||||
} else {
|
||||
msg = message;
|
||||
action = false;
|
||||
}
|
||||
msg = font::word_wrap_text(msg,font::SIZE_SMALL,mapx()*3/4);
|
||||
|
||||
int ypos = chat_message_x;
|
||||
for(std::vector<chat_message>::const_iterator m = chat_messages_.begin(); m != chat_messages_.end(); ++m) {
|
||||
ypos += font::get_floating_label_rect(m->handle).h;
|
||||
}
|
||||
|
||||
SDL_Color speaker_colour = {255,255,255,255};
|
||||
if(side >= 1) {
|
||||
speaker_colour = team::get_side_colour(side);
|
||||
}
|
||||
|
||||
SDL_Color message_colour = chat_message_colour;
|
||||
std::stringstream str;
|
||||
std::stringstream message_str;
|
||||
if(type == MESSAGE_PUBLIC) {
|
||||
if(action) {
|
||||
str << "<" << speaker << " " << msg << ">";
|
||||
message_colour = speaker_colour;
|
||||
message_str << " ";
|
||||
} else {
|
||||
str << "<" << speaker << ">";
|
||||
message_str << msg;
|
||||
}
|
||||
} else {
|
||||
if(action) {
|
||||
str << "*" << speaker << " " << msg << "*";
|
||||
message_colour = speaker_colour;
|
||||
message_str << " ";
|
||||
} else {
|
||||
str << "*" << speaker << "*";
|
||||
message_str << msg;
|
||||
config* cignore;
|
||||
bool ignored = false;
|
||||
if (cignore = preferences::get_prefs()->child("ignore")){
|
||||
for(std::map<std::string,t_string>::const_iterator i = cignore->values.begin();
|
||||
i != cignore->values.end(); ++i){
|
||||
if(speaker == i->first){
|
||||
if (i->second == "yes"){
|
||||
ignored = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignored){
|
||||
bool action;
|
||||
std::string msg;
|
||||
|
||||
// prepend message with timestamp
|
||||
std::stringstream message_complete;
|
||||
if (preferences::chat_timestamp()) {
|
||||
message_complete << timestring() << " ";
|
||||
if(message.find("/me ") == 0) {
|
||||
msg.assign(message,4,message.size());
|
||||
action = true;
|
||||
} else {
|
||||
msg = message;
|
||||
action = false;
|
||||
}
|
||||
msg = font::word_wrap_text(msg,font::SIZE_SMALL,mapx()*3/4);
|
||||
|
||||
int ypos = chat_message_x;
|
||||
for(std::vector<chat_message>::const_iterator m = chat_messages_.begin(); m != chat_messages_.end(); ++m) {
|
||||
ypos += font::get_floating_label_rect(m->handle).h;
|
||||
}
|
||||
|
||||
SDL_Color speaker_colour = {255,255,255,255};
|
||||
if(side >= 1) {
|
||||
speaker_colour = team::get_side_colour(side);
|
||||
}
|
||||
|
||||
SDL_Color message_colour = chat_message_colour;
|
||||
std::stringstream str;
|
||||
std::stringstream message_str;
|
||||
if(type == MESSAGE_PUBLIC) {
|
||||
if(action) {
|
||||
str << "<" << speaker << " " << msg << ">";
|
||||
message_colour = speaker_colour;
|
||||
message_str << " ";
|
||||
} else {
|
||||
str << "<" << speaker << ">";
|
||||
message_str << msg;
|
||||
}
|
||||
} else {
|
||||
if(action) {
|
||||
str << "*" << speaker << " " << msg << "*";
|
||||
message_colour = speaker_colour;
|
||||
message_str << " ";
|
||||
} else {
|
||||
str << "*" << speaker << "*";
|
||||
message_str << msg;
|
||||
}
|
||||
}
|
||||
|
||||
// prepend message with timestamp
|
||||
std::stringstream message_complete;
|
||||
if (preferences::chat_timestamp()) {
|
||||
message_complete << timestring() << " ";
|
||||
}
|
||||
message_complete << str.str();
|
||||
|
||||
const SDL_Rect rect = map_area();
|
||||
const int speaker_handle = font::add_floating_label(message_complete.str(),font::SIZE_SMALL,speaker_colour,
|
||||
rect.x+chat_message_x,rect.y+ypos,
|
||||
0,0,-1,rect,font::LEFT_ALIGN,&chat_message_bg,chat_message_border);
|
||||
|
||||
const int message_handle = font::add_floating_label(message_str.str(),font::SIZE_SMALL,message_colour,
|
||||
rect.x + chat_message_x + font::get_floating_label_rect(speaker_handle).w,rect.y+ypos,
|
||||
0,0,-1,rect,font::LEFT_ALIGN,&chat_message_bg,chat_message_border);
|
||||
|
||||
chat_messages_.push_back(chat_message(speaker_handle,message_handle));
|
||||
|
||||
prune_chat_messages();
|
||||
}
|
||||
message_complete << str.str();
|
||||
|
||||
const SDL_Rect rect = map_area();
|
||||
const int speaker_handle = font::add_floating_label(message_complete.str(),font::SIZE_SMALL,speaker_colour,
|
||||
rect.x+chat_message_x,rect.y+ypos,
|
||||
0,0,-1,rect,font::LEFT_ALIGN,&chat_message_bg,chat_message_border);
|
||||
|
||||
const int message_handle = font::add_floating_label(message_str.str(),font::SIZE_SMALL,message_colour,
|
||||
rect.x + chat_message_x + font::get_floating_label_rect(speaker_handle).w,rect.y+ypos,
|
||||
0,0,-1,rect,font::LEFT_ALIGN,&chat_message_bg,chat_message_border);
|
||||
|
||||
chat_messages_.push_back(chat_message(speaker_handle,message_handle));
|
||||
|
||||
prune_chat_messages();
|
||||
}
|
||||
|
||||
void display::clear_chat_messages()
|
||||
|
|
|
@ -268,6 +268,7 @@ void ui::handle_key_event(const SDL_KeyboardEvent& event)
|
|||
//otherwise it's just a chat message
|
||||
static const std::string query = "/query ";
|
||||
static const std::string whisper = "/msg ";
|
||||
static const std::string ignore = "/ignore ";
|
||||
|
||||
config data;
|
||||
|
||||
|
@ -296,7 +297,62 @@ void ui::handle_key_event(const SDL_KeyboardEvent& event)
|
|||
(entry_textbox_.text().substr(whisper.size()+receiver.size()+1)));
|
||||
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
|
||||
} else if (text.size() >= ignore.size() && std::equal(ignore.begin(),ignore.end(),text.begin())) {
|
||||
|
||||
static const std::string add = "add";
|
||||
static const std::string remove = "remove";
|
||||
static const std::string list = "list";
|
||||
static const std::string clear = "clear";
|
||||
|
||||
int pos;
|
||||
pos = text.find(" ",ignore.size());
|
||||
|
||||
const std::string arg = text.substr((pos+1),text.find_first_of(' '));
|
||||
|
||||
const std::string command = text.substr(ignore.size(),
|
||||
(text.size()-arg.size()-ignore.size()-1));
|
||||
|
||||
config* cignore;
|
||||
|
||||
if (std::equal(add.begin(),add.end(),command.begin())){
|
||||
if (!preferences::get_prefs()->child("ignore")){
|
||||
preferences::get_prefs()->add_child("ignore");
|
||||
}
|
||||
cignore = preferences::get_prefs()->child("ignore");
|
||||
(*cignore)[arg] = "yes";
|
||||
chat_.add_message("ignores list", "Added "+arg+" to ignore list.");
|
||||
|
||||
} else if (std::equal(remove.begin(),remove.end(),command.begin())){
|
||||
if ((cignore = preferences::get_prefs()->child("ignore"))){
|
||||
(*cignore)[arg] = "no";
|
||||
chat_.add_message("ignores list", "Removed "+arg+" from ignore list.");
|
||||
}
|
||||
} else if (std::equal(list.begin(),list.end(),command.begin())){
|
||||
std::string message = " ";
|
||||
if ((cignore = preferences::get_prefs()->child("ignore"))){
|
||||
std::map<std::string,t_string>::const_iterator i ;
|
||||
for( i = cignore->values.begin(); i != cignore->values.end(); ++i){
|
||||
if (i->second == "yes"){
|
||||
message+=i->first+",";
|
||||
}
|
||||
}
|
||||
message.erase(message.length()-1,1);
|
||||
}
|
||||
chat_.add_message("ignores list", message);
|
||||
} else if (std::equal(clear.begin(),clear.end(),command.begin())){
|
||||
|
||||
if ((cignore = preferences::get_prefs()->child("ignore"))){
|
||||
string_map::iterator nick;
|
||||
for(nick= cignore->values.begin() ; nick!= cignore->values.end(); nick++) {
|
||||
(*cignore)[nick->first] = "no";
|
||||
chat_.add_message("ignores list", "Removed "+nick->first+" from ignore list.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
chat_.add_message("ignores list", "unknown command "+command+".");
|
||||
}
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
} else {
|
||||
|
||||
// Sends the message to the network
|
||||
|
@ -358,11 +414,26 @@ void ui::process_network_data(const config& data, const network::connection /*so
|
|||
throw network::error((*data.child("error"))["message"]);
|
||||
} else {
|
||||
if(data.child("message")) {
|
||||
sound::play_sound(game_config::sounds::receive_message);
|
||||
|
||||
const config& msg = *data.child("message");
|
||||
chat_.add_message(msg["sender"], msg["message"]);
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
config* cignore;
|
||||
bool ignored = false;
|
||||
if ((cignore = preferences::get_prefs()->child("ignore"))){
|
||||
for(std::map<std::string,t_string>::const_iterator i = cignore->values.begin();
|
||||
i != cignore->values.end(); ++i){
|
||||
if(msg["sender"] == i->first){
|
||||
if (i->second == "yes"){
|
||||
ignored = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignored){
|
||||
sound::play_sound(game_config::sounds::receive_message);
|
||||
|
||||
chat_.add_message(msg["sender"], msg["message"]);
|
||||
chat_.update_textbox(chat_textbox_);
|
||||
}
|
||||
}
|
||||
|
||||
if(data.child("whisper")){
|
||||
|
|
|
@ -2200,6 +2200,7 @@ void turn_info::do_speak(const std::string& message, bool allies_only)
|
|||
}
|
||||
|
||||
static const std::string whisper = "/msg ";
|
||||
static const std::string ignore = "/ignore ";
|
||||
if (is_observer() && message.size() >= whisper.size() &&
|
||||
std::equal(whisper.begin(),whisper.end(),message.begin())) {
|
||||
|
||||
|
@ -2218,6 +2219,61 @@ void turn_info::do_speak(const std::string& message, bool allies_only)
|
|||
data.add_child("whisper", cwhisper);
|
||||
gui_.add_chat_message("whisper to "+cwhisper["receiver"],0,cwhisper["message"], display::MESSAGE_PRIVATE);
|
||||
network::send_data(data);
|
||||
|
||||
} else if (message.size() >= ignore.size() && std::equal(ignore.begin(),ignore.end(), message.begin())) {
|
||||
|
||||
static const std::string add = "add";
|
||||
static const std::string remove = "remove";
|
||||
static const std::string list = "list";
|
||||
static const std::string clear = "clear";
|
||||
|
||||
int pos;
|
||||
pos = message.find(" ",ignore.size());
|
||||
|
||||
const std::string arg = message.substr((pos+1), message.size());
|
||||
|
||||
const std::string command = message.substr(ignore.size(),
|
||||
(message.size()-arg.size()-ignore.size()-1));
|
||||
|
||||
config* cignore;
|
||||
|
||||
if (std::equal(add.begin(),add.end(),command.begin())){
|
||||
if (!preferences::get_prefs()->child("ignore")){
|
||||
preferences::get_prefs()->add_child("ignore");
|
||||
}
|
||||
cignore = preferences::get_prefs()->child("ignore");
|
||||
(*cignore)[arg] = "yes";
|
||||
gui_.add_chat_message("ignores list",0, "Added "+arg+" to ignore list.",display::MESSAGE_PRIVATE);
|
||||
|
||||
} else if (std::equal(remove.begin(),remove.end(),command.begin())){
|
||||
if ((cignore = preferences::get_prefs()->child("ignore"))){
|
||||
(*cignore)[arg] = "no";
|
||||
gui_.add_chat_message("ignores list",0, "Removed "+arg+" from ignore list.",display::MESSAGE_PRIVATE);
|
||||
}
|
||||
} else if (std::equal(list.begin(),list.end(),command.begin())){
|
||||
std::string text = " ";
|
||||
if ((cignore = preferences::get_prefs()->child("ignore"))){
|
||||
for(std::map<std::string,t_string>::const_iterator i = cignore->values.begin();
|
||||
i != cignore->values.end(); ++i){
|
||||
if (i->second == "yes"){
|
||||
text+=i->first+",";
|
||||
}
|
||||
}
|
||||
text.erase(text.length()-1,1);
|
||||
}
|
||||
gui_.add_chat_message("ignores list",0, text,display::MESSAGE_PRIVATE);
|
||||
} else if (std::equal(clear.begin(),clear.end(),command.begin())){
|
||||
|
||||
if ((cignore = preferences::get_prefs()->child("ignore"))){
|
||||
string_map::iterator nick;
|
||||
for(nick= cignore->values.begin() ; nick!= cignore->values.end(); nick++) {
|
||||
(*cignore)[nick->first] = "no";
|
||||
gui_.add_chat_message("ignores list",0, "Removed "+nick->first+" from ignore list.",display::MESSAGE_PRIVATE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gui_.add_chat_message("ignores list",0,"unknown command "+command+".",display::MESSAGE_PRIVATE);
|
||||
}
|
||||
} else {
|
||||
|
||||
config cfg;
|
||||
|
|
|
@ -102,6 +102,11 @@ std::string get(const std::string key) {
|
|||
return prefs[key];
|
||||
}
|
||||
|
||||
config* get_prefs(){
|
||||
config* pointer = &prefs;
|
||||
return pointer;
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool is_fullscreen = false;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ namespace preferences {
|
|||
// low-level, should be seen only by preferences_display ?
|
||||
void set(std::string key, std::string value);
|
||||
std::string get(const std::string key);
|
||||
|
||||
config* get_prefs();
|
||||
|
||||
bool fullscreen();
|
||||
void _set_fullscreen(bool ison);
|
||||
|
|
Loading…
Add table
Reference in a new issue