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
--- preferences.cpp 2005-04-16 21:35:32.000000000 +0200
+++ preferences.cpp.maj 2005-04-22 00:35:21.691770848 +0200
@@ -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'
@@ -737,6 +739,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;
@@ -810,16 +840,17 @@
void set_selection(int index);
void update_location(SDL_Rect const &rect);
- 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_;
- gui::label music_label_, sound_label_, scroll_label_, gamma_label_;
+ flip_time_button_, chat_timestamp_button_;
+ gui::label music_label_, sound_label_, scroll_label_, gamma_label_,
chat_lines_label_;
unsigned slider_label_width_;
- enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB };
+ enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB, MULTIPLAYER_TAB };
TAB tab_;
display &disp_;
};
@@ -828,6 +859,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),
@@ -842,8 +874,10 @@
hotkeys_button_(disp.video(), _("Hotkeys")),
gamma_button_(disp.video(), _("Adjust Gamma"),
gui::button::TYPE_CHECK),
flip_time_button_(disp.video(), _("Reverse Time Graphics"),
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(), _("Chat Lines:")),
slider_label_width_(0), tab_(GENERAL_TAB), disp_(disp)
{
// FIXME: this box should be vertically centered on the screen, but is
not
@@ -855,8 +889,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);
@@ -880,6 +915,14 @@
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"));
+
+ 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"));
@@ -971,6 +1014,14 @@
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);
+
set_selection(tab_);
}
@@ -1010,10 +1061,14 @@
}
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());
}
void preferences_dialog::set_selection(int index)
@@ -1049,6 +1104,11 @@
music_slider_.hide(hide_sound);
sound_label_.hide(hide_sound);
sound_slider_.hide(hide_sound);
+
+ bool hide_multiplayer = tab_ != MULTIPLAYER_TAB;
+ chat_lines_label_.hide(hide_multiplayer);
+ chat_lines_slider_.hide(hide_multiplayer);
+ chat_timestamp_button_.hide(hide_multiplayer);
}
}
@@ -1062,6 +1122,7 @@
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"));
for(;;) {
try {
--- preferences.hpp 2005-04-02 23:33:21.000000000 +0200
+++ preferences.hpp.maj 2005-04-22 00:35:31.291311496 +0200
@@ -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();
--- display.cpp 2005-04-17 22:59:32.000000000 +0200
+++ display.cpp.maj 2005-04-22 00:35:09.619606096 +0200
@@ -2149,6 +2149,30 @@
grid_ = grid;
}
+// timestring() returns the current date as a string.
+// Example: 20:42:18
+char *timestring ( void )
+{
+# define TIME_SIZE 40
+
+ const struct tm *tm;
+ size_t len;
+ time_t now;
+ char *s;
+
+ now = time ( NULL );
+ tm = localtime ( &now );
+
+ s = new char[TIME_SIZE];
+
+ // alternative mode, including the day ...
+ // len = strftime ( s, TIME_SIZE, "%Y-%m-%d %H:%M:%S", tm );
+ len = strftime ( s, TIME_SIZE, "%H:%M:%S", tm );
+
+ return s;
+# undef TIME_SIZE
+}
+
void display::debug_highlight(const gamemap::location& loc, fixed_t amount)
{
wassert(game_config::debug);
@@ -2261,7 +2285,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;
@@ -2280,6 +2303,7 @@
msg = message;
action = false;
}
+
msg = font::word_wrap_text(msg,font::SIZE_SMALL,mapx()*3/4);
int ypos = chat_message_x;
@@ -2314,9 +2338,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);
@@ -2337,6 +2367,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;