Chatbox: allow new rooms to specify if they can be closed or not

This removes the hardcoded "room name is 'lobby" predicate.
This commit is contained in:
Charles Dang 2016-10-18 02:14:09 +11:00
parent 7edad9669a
commit 497dcac47a
5 changed files with 14 additions and 12 deletions

View File

@ -759,7 +759,7 @@ void tlobby_main::pre_show(twindow& window)
*filter_text_,
std::bind(&tlobby_main::game_filter_keypress_callback, this, _5));
chatbox_->room_window_open("lobby", true);
chatbox_->room_window_open("lobby", true, false);
chatbox_->active_window_changed();
game_filter_reload();

View File

@ -274,7 +274,7 @@ void tmp_join_game::pre_show(twindow& window)
chat.set_lobby_info(lobby_info_);
chat.set_wesnothd_connection(wesnothd_connection_);
chat.room_window_open("this game", true); // TODO: better title?
chat.room_window_open("this game", true, false); // TODO: better title?
chat.active_window_changed();
//

View File

@ -122,7 +122,7 @@ void tmp_staging::pre_show(twindow& window)
chat.set_wesnothd_connection(*wesnothd_connection_);
}
chat.room_window_open("this game", true); // TODO: better title?
chat.room_window_open("this game", true, false); // TODO: better title?
chat.active_window_changed();
//

View File

@ -360,19 +360,20 @@ bool tchatbox::room_window_active(const std::string& room)
return t.name == room && t.whisper == false;
}
tlobby_chat_window* tchatbox::room_window_open(const std::string& room, bool open_new)
tlobby_chat_window* tchatbox::room_window_open(const std::string& room, const bool open_new, const bool allow_close)
{
return search_create_window(room, false, open_new);
return search_create_window(room, false, open_new, allow_close);
}
tlobby_chat_window* tchatbox::whisper_window_open(const std::string& name, bool open_new)
{
return search_create_window(name, true, open_new);
return search_create_window(name, true, open_new, true);
}
tlobby_chat_window* tchatbox::search_create_window(const std::string& name,
bool whisper,
bool open_new)
const bool whisper,
const bool open_new,
const bool allow_close)
{
for(auto& t : open_windows_) {
if(t.name == name && t.whisper == whisper) {
@ -415,7 +416,7 @@ tlobby_chat_window* tchatbox::search_create_window(const std::string& name,
connect_signal_mouse_left_click(close_button,
std::bind(&tchatbox::close_window_button_callback, this, open_windows_.back(), _3, _4));
if(name == "lobby") {
if(!allow_close) {
close_button.set_visible(tcontrol::tvisible::hidden);
}

View File

@ -219,11 +219,12 @@ public:
/**
* Check if a room window for "room" is open, if open_new is true
* then it will be created if not found.
* then it will be created if not found. If allow_close is false, the
* 'close' button will be disabled.
* @return valid ptr if the window was found or added, null otherwise
*/
tlobby_chat_window* room_window_open(const std::string& room,
bool open_new);
const bool open_new, const bool allow_close = true);
/**
* Check if a whisper window for user "name" is open, if open_new is true
@ -236,7 +237,7 @@ public:
/**
* Helper function to find and open a new window, used by *_window_open
*/
tlobby_chat_window* search_create_window(const std::string& name, bool whisper, bool open_new);
tlobby_chat_window* search_create_window(const std::string& name, const bool whisper, const bool open_new, const bool allow_close);
void do_notify(t_notify_mode mode) { do_notify(mode, "", ""); }
void do_notify(t_notify_mode mode, const std::string & sender, const std::string & message) { do_mp_notify(mode, sender, message); }