Hi there,

on Ott's request I reviewed my patches again and submitted them to
tracker as ID 4047:
https://savannah.nongnu.org/patch/index.php?func=detailitem&item_id=4047

It is still the same functionality and applies to the latest CVS
version. I checked the changes made by DarthFool and decided not to put
my preferences in the "Advanced" section, but to stick with the
Multiplayer tab, for the following reasons:

I don't think that the "Advanced" tab is needed, and it might have
negative effects. Enabling non-binary saves is in my opinion a feature
which is not neeeded by normal users and it encourages cheating since
modifying the save game is easier. I think having this configurable is a
good thing, but via console would suffice. Besides, the advanced tab is
the perfect place for developers to put all their stuff which didn't fit
elsewhere, which is a bad habit. And, as the last point, it looks
different than all other tabs, and it's user interface is not very
intuitive. But that might be a different discussion. </rant> :-)

I also checked if I could somehow use the timestamp code DarthFool uses
for his theme, but that doesn't work. I'd suggest that someone with more
experience than me checks for all usages of time() and strftime() calls
and builds a generic utils::time object (or something like that), to
counter re-coding the same stuff over and over. 
What I took from DarthFools code is the preferences::clock_format() for 
the chat timestamp, so that is configurable now as well.

Anyway, I already got lots of positive feedback for my patch, so I hope 
that it does finally make it into mainstream wesnoth; I am really 
reluctant to review the patches once a month to make them again apply.

    majestyk


Andreas Grosse <[EMAIL PROTECTED]> [28:04:05 18:16] wrote:
> Hi,
> 
> after some talking via IRC I decided to show the actual number of lines
> configured with the slider next to the slider. To make things easier for
> you to check, I created a new patch (which still applies fine to the
> latest CVS version) AND I made a screenshot how it looks like. It is
> available at http://www.rot13.de/~majestyk/wesnoth-mp-prefs.png .
> 
> Now I need a developer willing to review the code, so that the changes
> get merged into the CVS. Is there a volunteer? :-)
> 
> Cheers,
>         majestyk
> 
> Andreas Grosse <[EMAIL PROTECTED]> [22:04:05 11:16] wrote:
> > Hi,
> > 
> > I recently joined the wesnoth community, and I have a few ideas about 
> > what could be improved in some parts. Instead of buggering you with
> > implementing my features, I tried to do so myself. Since I am not a
> > seasoned C++ programmer, I'd really appreciate if someone could review
> > my attached patches. If there is a consensus about the integration, I'd
> > be happy if these changes could be merged for the next version.
> > 
> > The things I wanted to improve are focused on multiplayer chat. On my
> > first online match, things went really slow, so I wasn't always at my
> > machine. Returning to it, I would have been happy to have the messages
> > timestamped, to be able to trackback when something happened. Second,
> > when playing on a small resolution 6 lines of chat messages are just too
> > much, and I thought making it configurable would be nice.
> > 
> > Summary of changes:
> > - created a new preferences tab, called "Multiplayer"
> > - created a button called "Chat Timestamping", prepending the chat lines
> >   with a "H:m:s" timestamp (e.g.:   21:42:23 <majestyk> test line )
> > - created a slider called "Chat Lines", changing the amount of displayed
> >   lines from 1 to 20 lines.
> > 
> > To work 100%, a new image is needed for the multiplayer tab. For test
> > purposes, I used the silver mage because I like the image :-)
> > # cp images/silver-mage.png images/icons/multiplayer.png
> > 
> > I'd be grateful for almost every kind of feedback :)
> > 
> > Cheers,
> >     majestyk
Index: display.cpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/display.cpp,v
retrieving revision 1.321
diff -a -u -r1.321 display.cpp
--- display.cpp 16 May 2005 22:44:19 -0000      1.321
+++ display.cpp 26 May 2005 17:31:10 -0000
@@ -2179,6 +2179,22 @@
        grid_ = grid;
 }
 
+// timestring() returns the current date as a string.
+// Uses preferences::clock_format() for formatting.
+char *timestring ( void )
+{
+    #define TIME_SIZE 10
+       
+    time_t now = time ( NULL );
+    struct tm *lt = localtime( &now );
+
+    char *tstring;
+    tstring = new char[TIME_SIZE];
+    size_t s = 
strftime(tstring,TIME_SIZE,preferences::clock_format().c_str(),lt);
+    return tstring;
+    #undef TIME_SIZE
+}
+
 void display::debug_highlight(const gamemap::location& loc, fixed_t amount)
 {
        wassert(game_config::debug);
@@ -2291,7 +2307,6 @@
 }
 
 namespace {
-       const unsigned int max_chat_messages = 6;
        const int chat_message_border = 5;
        const int chat_message_x = 10;
        const int chat_message_y = 10;
@@ -2310,6 +2325,7 @@
                msg = message;
                action = false;
        }
+
        msg = font::word_wrap_text(msg,font::SIZE_SMALL,mapx()*3/4);
 
        int ypos = chat_message_x;
@@ -2345,9 +2361,15 @@
                }
        }
 
+    // prepend message with timestamp
+    std::stringstream message_meta;
+    if (preferences::chat_timestamp()) {
+        message_meta << timestring() << " ";
+    }
+    message_meta << str.str();
 
        const SDL_Rect rect = map_area();
-       const int speaker_handle = 
font::add_floating_label(str.str(),font::SIZE_SMALL,speaker_colour,
+       const int speaker_handle = 
font::add_floating_label(message_meta.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);
 
@@ -2368,6 +2390,8 @@
 void display::prune_chat_messages(bool remove_all)
 {
        const unsigned int message_ttl = remove_all ? 0 : 1200000;
+       const unsigned int max_chat_messages = preferences::chat_lines();
+
        if(chat_messages_.empty() == false && 
(chat_messages_.front().created_at+message_ttl < SDL_GetTicks() || 
chat_messages_.size() > max_chat_messages)) {
                const int movement = 
font::get_floating_label_rect(chat_messages_.front().handle).h;
 
Index: preferences.cpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/preferences.cpp,v
retrieving revision 1.158
diff -a -u -r1.158 preferences.cpp
--- preferences.cpp     16 May 2005 22:44:19 -0000      1.158
+++ preferences.cpp     26 May 2005 17:31:13 -0000
@@ -295,6 +295,8 @@
        return prefs["adjust_gamma"] == "yes";
 }
 
+
+
 void set_adjust_gamma(bool val)
 {
        //if we are turning gamma adjustment off, then set it to '1.0'
@@ -746,6 +748,34 @@
        prefs["flip_time"] = value ? "yes" : "no";
 }
 
+bool chat_timestamp()
+{
+       return prefs["chat_timestamp"] == "yes";
+}
+
+void set_chat_timestamp(bool value)
+{
+       prefs["chat_timestamp"] = value ? "yes" : "no";
+}
+
+int chat_lines()
+{
+       // defaults to 6 chat log lines displayed
+       static const int default_value = 6;
+       const string_map::const_iterator lines = 
prefs.values.find("chat_lines");
+       if(lines != prefs.values.end() && lines->second.empty() == false)
+               return atoi(lines->second.c_str());
+       else
+               return default_value;
+}
+
+void set_chat_lines(int lines)
+{
+       std::stringstream stream;
+       stream << lines;
+       prefs["chat_lines"] = stream.str();
+}
+
 bool show_fps()
 {
        return fps;
@@ -821,19 +851,20 @@
        const config* get_advanced_pref() const;
        void set_advanced_menu();
 
-       gui::slider music_slider_, sound_slider_, scroll_slider_, gamma_slider_;
+    gui::slider music_slider_, sound_slider_, scroll_slider_, gamma_slider_,
+                chat_lines_slider_;
        gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
                    show_grid_button_, show_floating_labels_button_, 
turn_dialog_button_,
                    turn_bell_button_, show_team_colours_button_, 
show_colour_cursors_button_,
                    show_haloing_button_, video_mode_button_, hotkeys_button_, 
gamma_button_,
-                               flip_time_button_, advanced_button_;
-       gui::label music_label_, sound_label_, scroll_label_, gamma_label_;
+                               flip_time_button_, advanced_button_, 
chat_timestamp_button_;
+       gui::label music_label_, sound_label_, scroll_label_, gamma_label_, 
chat_lines_label_;
        unsigned slider_label_width_;
 
        gui::menu advanced_;
        int advanced_selection_;
 
-       enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB, ADVANCED_TAB };
+       enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB, MULTIPLAYER_TAB, 
ADVANCED_TAB };
        TAB tab_;
        display &disp_;
        const config& game_cfg_;
@@ -843,6 +874,7 @@
        : gui::preview_pane(disp.video()),
          music_slider_(disp.video()), sound_slider_(disp.video()),
          scroll_slider_(disp.video()), gamma_slider_(disp.video()),
+         chat_lines_slider_(disp.video()),
          fullscreen_button_(disp.video(), _("Toggle Full Screen"), 
gui::button::TYPE_CHECK),
          turbo_button_(disp.video(), _("Accelerated Speed"), 
gui::button::TYPE_CHECK),
          show_ai_moves_button_(disp.video(), _("Skip AI Moves"), 
gui::button::TYPE_CHECK),
@@ -858,8 +890,10 @@
          gamma_button_(disp.video(), _("Adjust Gamma"), 
gui::button::TYPE_CHECK),
          flip_time_button_(disp.video(), _("Reverse Time Graphics"), 
gui::button::TYPE_CHECK),
          advanced_button_(disp.video(), "", gui::button::TYPE_CHECK),
+      chat_timestamp_button_(disp.video(), _("Chat Timestamping"), 
gui::button::TYPE_CHECK),
          music_label_(disp.video(), _("Music Volume:")), 
sound_label_(disp.video(), _("SFX Volume:")),
          scroll_label_(disp.video(), _("Scroll Speed:")), 
gamma_label_(disp.video(), _("Gamma:")),
+         chat_lines_label_(disp.video(), _("")),
          slider_label_width_(0), 
advanced_(disp.video(),std::vector<std::string>()), advanced_selection_(-1),
          tab_(GENERAL_TAB), disp_(disp), game_cfg_(game_cfg)
 {
@@ -872,8 +906,9 @@
 
        slider_label_width_ = maximum<unsigned>(music_label_.width(),
                              maximum<unsigned>(sound_label_.width(),
+                             maximum<unsigned>(chat_lines_label_.width(),
                              maximum<unsigned>(scroll_label_.width(),
-                                               gamma_label_.width())));
+                                               gamma_label_.width() ))));
 
        sound_slider_.set_min(1);
        sound_slider_.set_max(100);
@@ -897,6 +932,16 @@
        gamma_slider_.set_max(200);
        gamma_slider_.set_value(gamma());
        gamma_slider_.set_help_string(_("Change the brightness of the 
display"));
+       
+       chat_lines_slider_.set_min(1);
+       chat_lines_slider_.set_max(20);
+       chat_lines_slider_.set_value(chat_lines());
+       chat_lines_slider_.set_help_string(_("Set the amount of chat lines 
shown"));
+       // Have the tooltip appear over the static "Chat lines" label, too.
+       chat_lines_label_.set_help_string(_("Set the amount of chat lines 
shown"));
+
+       chat_timestamp_button_.set_check(chat_timestamp());
+       chat_timestamp_button_.set_help_string(_("Add a timestamp to chat 
messages"));
 
        fullscreen_button_.set_check(fullscreen());
        fullscreen_button_.set_help_string(_("Choose whether the game should 
run full screen or in a window"));
@@ -990,15 +1035,22 @@
                                rect.w - slider_label_width_ - border, 0 };
        sound_slider_.set_location(sound_rect);
 
+       // Multiplayer tab
+       ypos = rect.y;
+       chat_lines_label_.set_location(rect.x, ypos);
+       SDL_Rect chat_lines_rect = { rect.x + slider_label_width_, ypos,
+                                    rect.w - slider_label_width_ - border, 0 };
+       chat_lines_slider_.set_location(chat_lines_rect);
+       ypos += item_interline; chat_timestamp_button_.set_location(rect.x, 
ypos);
+
        //Advanced tab
        ypos = rect.y;
        advanced_.set_location(rect.x,ypos);
        advanced_.set_max_height(height()-100);
 
        ypos += advanced_.height() + border;
-
        advanced_button_.set_location(rect.x,ypos);
-
+       
        set_selection(tab_);
 }
 
@@ -1038,10 +1090,20 @@
        }
        if (flip_time_button_.pressed())
                set_flip_time(flip_time_button_.checked());
+    if (chat_timestamp_button_.pressed())
+        set_chat_timestamp(chat_timestamp_button_.checked());
+               
        set_sound_volume(sound_slider_.value());
        set_music_volume(music_slider_.value());
        set_scroll_speed(scroll_slider_.value());
        set_gamma(gamma_slider_.value());
+    set_chat_lines(chat_lines_slider_.value());
+
+    // display currently select amount of chat lines
+    std::stringstream buf;
+    buf << _("Chat Lines: ") << chat_lines_slider_.value();
+    chat_lines_label_.set_text(buf.str());
+    
 
        if(advanced_.selection() != advanced_selection_) {
                advanced_selection_ = advanced_.selection();
@@ -1136,6 +1198,11 @@
        sound_label_.hide(hide_sound);
        sound_slider_.hide(hide_sound);
 
+    const bool hide_multiplayer = tab_ != MULTIPLAYER_TAB;
+    chat_lines_label_.hide(hide_multiplayer);
+    chat_lines_slider_.hide(hide_multiplayer);
+    chat_timestamp_button_.hide(hide_multiplayer);
+
        const bool hide_advanced = tab_ != ADVANCED_TAB;
        advanced_.hide(hide_advanced);
        advanced_button_.hide(hide_advanced);
@@ -1152,7 +1219,10 @@
        items.push_back(pre + "general.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^General"));
        items.push_back(pre + "display.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^Display"));
        items.push_back(pre + "music.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^Sound"));
+       items.push_back(pre + "multiplayer.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^Multiplayer"));
        items.push_back(pre + "advanced.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Advanced section^Advanced"));
+
+       
        
        for(;;) {
                try {
Index: preferences.hpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/preferences.hpp,v
retrieving revision 1.55
diff -a -u -r1.55 preferences.hpp
--- preferences.hpp     14 May 2005 20:56:21 -0000      1.55
+++ preferences.hpp     26 May 2005 17:31:13 -0000
@@ -155,6 +155,13 @@
        bool flip_time();
        void set_flip_time(bool value);
 
+       // Multiplayer functions
+       bool chat_timestamp();
+       void set_chat_timestamp(bool value);
+
+       int chat_lines();
+       void set_chat_lines(int lines);
+
        bool compress_saves();
 
        std::set<std::string> &encountered_units();

Reply via email to