tlobby_main: chat log scrolling fixes (bug #16059)
Based on patch by faabumc. Sending a message in chat will scroll to the bottom, as well as receiving a message if you've already scrolled that far. A few corner cases still need to be covered
This commit is contained in:
parent
e6495b929a
commit
5ea08ba37d
2 changed files with 29 additions and 18 deletions
|
@ -214,16 +214,16 @@ void tlobby_main::add_whisper_sent(const std::string& receiver,
|
|||
const std::string& message)
|
||||
{
|
||||
if(whisper_window_active(receiver)) {
|
||||
add_active_window_message(preferences::login(), message);
|
||||
add_active_window_message(preferences::login(), message, true);
|
||||
} else if(tlobby_chat_window* t = whisper_window_open(
|
||||
receiver, preferences::auto_open_whisper_windows())) {
|
||||
switch_to_window(t);
|
||||
add_active_window_message(preferences::login(), message);
|
||||
add_active_window_message(preferences::login(), message, true);
|
||||
} else {
|
||||
utils::string_map symbols;
|
||||
symbols["receiver"] = receiver;
|
||||
add_active_window_whisper(VGETTEXT("whisper to $receiver", symbols),
|
||||
message);
|
||||
message, true);
|
||||
}
|
||||
lobby_info_.get_whisper_log(receiver)
|
||||
.add_message(preferences::login(), message);
|
||||
|
@ -266,7 +266,7 @@ void tlobby_main::add_chat_room_message_sent(const std::string& room,
|
|||
switch_to_window(t);
|
||||
}
|
||||
ri->log().add_message(preferences::login(), message);
|
||||
add_active_window_message(preferences::login(), message);
|
||||
add_active_window_message(preferences::login(), message, true);
|
||||
} else {
|
||||
LOG_LB << "Cannot add sent message to ui for room " << room
|
||||
<< ", player not in the room\n";
|
||||
|
@ -302,19 +302,26 @@ void tlobby_main::add_chat_room_message_received(const std::string& room,
|
|||
}
|
||||
}
|
||||
|
||||
void tlobby_main::append_to_chatbox(const std::string& text)
|
||||
void tlobby_main::append_to_chatbox(const std::string& text, const bool force_scroll)
|
||||
{
|
||||
append_to_chatbox(text, active_window_);
|
||||
append_to_chatbox(text, active_window_, force_scroll);
|
||||
}
|
||||
|
||||
void tlobby_main::append_to_chatbox(const std::string& text, size_t id)
|
||||
void tlobby_main::append_to_chatbox(const std::string& text, size_t id, const bool force_scroll)
|
||||
{
|
||||
tgrid& grid = chat_log_container_->page_grid(id);
|
||||
tscroll_label& log = find_widget<tscroll_label>(&grid, "log_text", false);
|
||||
const bool chatbox_at_end = log.vertical_scrollbar_at_end();
|
||||
const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
|
||||
log.set_use_markup(true);
|
||||
log.set_label(log.label() + "\n" + preferences::get_chat_timestamp(time(0))
|
||||
+ text);
|
||||
log.scroll_vertical_scrollbar(tscrollbar_::END);
|
||||
|
||||
if(chatbox_at_end || force_scroll) {
|
||||
log.scroll_vertical_scrollbar(tscrollbar_::END);
|
||||
} else {
|
||||
log.set_vertical_scrollbar_item_position(chatbox_position);
|
||||
}
|
||||
}
|
||||
|
||||
void tlobby_main::do_notify(t_notify_mode mode, const std::string & sender, const std::string & message)
|
||||
|
@ -1171,16 +1178,17 @@ void tlobby_main::add_whisper_window_whisper(const std::string& sender,
|
|||
<< sender << "\n";
|
||||
return;
|
||||
}
|
||||
append_to_chatbox(ss.str(), t - &open_windows_[0]);
|
||||
append_to_chatbox(ss.str(), t - &open_windows_[0], false);
|
||||
}
|
||||
|
||||
void tlobby_main::add_active_window_whisper(const std::string& sender,
|
||||
const std::string& message)
|
||||
const std::string& message,
|
||||
const bool force_scroll)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "<b><"
|
||||
<< "whisper: " << sender << "></b> " << font::escape_text(message);
|
||||
append_to_chatbox(ss.str());
|
||||
append_to_chatbox(ss.str(), force_scroll);
|
||||
}
|
||||
|
||||
void tlobby_main::add_room_window_message(const std::string& room,
|
||||
|
@ -1195,15 +1203,16 @@ void tlobby_main::add_room_window_message(const std::string& room,
|
|||
<< "\n";
|
||||
return;
|
||||
}
|
||||
append_to_chatbox(ss.str(), t - &open_windows_[0]);
|
||||
append_to_chatbox(ss.str(), t - &open_windows_[0], false);
|
||||
}
|
||||
|
||||
void tlobby_main::add_active_window_message(const std::string& sender,
|
||||
const std::string& message)
|
||||
const std::string& message,
|
||||
const bool force_scroll)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "<b><" << sender << "></b> " << font::escape_text(message);
|
||||
append_to_chatbox(ss.str());
|
||||
append_to_chatbox(ss.str(), force_scroll);
|
||||
}
|
||||
|
||||
void tlobby_main::switch_to_window(tlobby_chat_window* t)
|
||||
|
|
|
@ -177,12 +177,12 @@ private:
|
|||
/**
|
||||
* Append some text to the active chat log
|
||||
*/
|
||||
void append_to_chatbox(const std::string& text);
|
||||
void append_to_chatbox(const std::string& text, const bool force_scroll = false);
|
||||
|
||||
/**
|
||||
* Append some text to the chat log for window "id"
|
||||
*/
|
||||
void append_to_chatbox(const std::string& text, size_t id);
|
||||
void append_to_chatbox(const std::string& text, size_t id, const bool force_scroll = false);
|
||||
|
||||
/**
|
||||
* Result flag for interfacing with other MP dialogs
|
||||
|
@ -249,7 +249,8 @@ private:
|
|||
* for "name".
|
||||
*/
|
||||
void add_active_window_whisper(const std::string& sender,
|
||||
const std::string& message);
|
||||
const std::string& message,
|
||||
const bool force_scroll = false);
|
||||
|
||||
/**
|
||||
* Add a message to the window for room "room"
|
||||
|
@ -262,7 +263,8 @@ private:
|
|||
* Add a message to the window for room "room"
|
||||
*/
|
||||
void add_active_window_message(const std::string& sender,
|
||||
const std::string& message);
|
||||
const std::string& message,
|
||||
const bool force_scroll = false);
|
||||
|
||||
/**
|
||||
* Switch to the window given by a valid pointer (e.g. received from a call
|
||||
|
|
Loading…
Add table
Reference in a new issue