mail[Wesnoth-commits] r10287 - in /trunk: changelog src/display.cpp src/multiplayer_ui.cpp src/playturn.cpp src/preferences.cpp src/preferences.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by jeremy . rosen on February 25, 2006 - 12:49:
Author: boucman
Date: Sat Feb 25 12:48:37 2006
New Revision: 10287

URL: http://svn.gna.org/viewcvs/wesnoth?rev=10287&view=rev
Log:
add MP chat ignore list, commands are /ignore add <nick> /ignore remove 
<nick> /ignore list and /ignore clear

Modified:
    trunk/changelog
    trunk/src/display.cpp
    trunk/src/multiplayer_ui.cpp
    trunk/src/playturn.cpp
    trunk/src/preferences.cpp
    trunk/src/preferences.hpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=10287&r1=10286&r2=10287&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sat Feb 25 12:48:37 2006
@@ -60,6 +60,7 @@
    * 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

Modified: trunk/src/display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=10287&r1=10286&r2=10287&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Sat Feb 25 12:48:37 2006
@@ -2465,70 +2465,85 @@
 
 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 << " ";
+       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;
+
+               if(message.find("/me ") == 0) {
+                       msg.assign(message,4,message.size());
+                       action = true;
                } else {
-                       str << "<" << speaker << ">";
-                       message_str << msg;
-               }
-       } else {
-               if(action) {
-                       str << "*" << speaker << " " << msg << "*";
-                       message_colour = speaker_colour;
-                       message_str << " ";
+                       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 {
-                       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();
+                       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();
+       }
 }
 
 void display::clear_chat_messages()

Modified: trunk/src/multiplayer_ui.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_ui.cpp?rev=10287&r1=10286&r2=10287&view=diff
==============================================================================
--- trunk/src/multiplayer_ui.cpp (original)
+++ trunk/src/multiplayer_ui.cpp Sat Feb 25 12:48:37 2006
@@ -268,6 +268,7 @@
                //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 @@
                        
(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 @@
                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")){

Modified: trunk/src/playturn.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playturn.cpp?rev=10287&r1=10286&r2=10287&view=diff
==============================================================================
--- trunk/src/playturn.cpp (original)
+++ trunk/src/playturn.cpp Sat Feb 25 12:48:37 2006
@@ -2200,6 +2200,7 @@
        }
 
        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 @@
                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;

Modified: trunk/src/preferences.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences.cpp?rev=10287&r1=10286&r2=10287&view=diff
==============================================================================
--- trunk/src/preferences.cpp (original)
+++ trunk/src/preferences.cpp Sat Feb 25 12:48:37 2006
@@ -100,6 +100,11 @@
 
 std::string get(const std::string key) {
        return prefs[key];
+}
+
+config* get_prefs(){
+       config* pointer = &prefs;
+       return pointer;
 }
 
 namespace {

Modified: trunk/src/preferences.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences.hpp?rev=10287&r1=10286&r2=10287&view=diff
==============================================================================
--- trunk/src/preferences.hpp (original)
+++ trunk/src/preferences.hpp Sat Feb 25 12:48:37 2006
@@ -44,6 +44,8 @@
        // 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);




Related Messages


Powered by MHonArc, Updated Sat Feb 25 13:40:26 2006