moved lobby-specific preferences...

...to a new lobby_preferences.hpp/cpp pair toreduce rebuild burden
when adding new preferences

renamed admin_authentication to parse_admin_athentication

renamed show_lobby_join to parse_should_show_lobby_join
This commit is contained in:
Tomasz Śniatowski 2009-08-03 22:48:48 +01:00
parent 3b033554f7
commit b46169639a
14 changed files with 226 additions and 144 deletions

View file

@ -469,6 +469,10 @@
RelativePath="..\..\src\lobby_data.cpp"
>
</File>
<File
RelativePath="..\..\src\lobby_preferences.cpp"
>
</File>
<File
RelativePath="..\..\src\map.cpp"
>
@ -4712,6 +4716,10 @@
RelativePath="..\..\src\lobby_data.hpp"
>
</File>
<File
RelativePath="..\..\src\lobby_preferences.hpp"
>
</File>
<File
RelativePath="..\..\src\log.hpp"
>

View file

@ -168,6 +168,7 @@ SET(libwesnoth-game_STAT_SRC
language.cpp
loadscreen.cpp
lobby_data.cpp
lobby_preferences.cpp
map_create.cpp
map_label.cpp
mapgen.cpp

View file

@ -170,6 +170,7 @@ wesnoth_source = \
help.cpp \
intro.cpp \
lobby_data.cpp \
lobby_preferences.cpp \
leader_list.cpp \
menu_events.cpp \
mouse_events.cpp \

View file

@ -199,6 +199,7 @@ wesnoth_sources = Split("""
intro.cpp
leader_list.cpp
lobby_data.cpp
lobby_preferences.cpp
menu_events.cpp
mouse_events.cpp
mouse_handler_base.cpp

View file

@ -1162,10 +1162,10 @@ void game_display::add_chat_message(const time_t& time, const std::string& speak
if (whisper) {
sender.assign(speaker, 9, speaker.size());
}
if (!preferences::show_lobby_join(sender, message)) return;
if (!preferences::parse_should_show_lobby_join(sender, message)) return;
if (preferences::is_ignored(sender)) return;
preferences::admin_authentication(sender, message);
preferences::parse_admin_authentication(sender, message);
if (bell) {
if ((type == events::chat_handler::MESSAGE_PRIVATE && (!is_observer() || whisper))

View file

@ -139,7 +139,7 @@ bool is_authenticated() {
return authenticated;
}
void admin_authentication(const std::string& sender, const std::string& message) {
void parse_admin_authentication(const std::string& sender, const std::string& message) {
if(sender != "server") return;
if(message.find("You are now recognized as an administrator.") == 0) {
authenticated = true;
@ -241,7 +241,7 @@ bool is_campaign_completed(const std::string& campaign_id) {
return std::find(completed.begin(), completed.end(), campaign_id) != completed.end();
}
bool show_lobby_join(const std::string& sender, const std::string& message) {
bool parse_should_show_lobby_join(const std::string& sender, const std::string& message) {
// If it's actually not a lobby join message return true (show it).
if (sender != "server" || message.find("has logged into the lobby") == std::string::npos) return true;
if (lobby_joins() == SHOW_NONE) return false;
@ -278,27 +278,6 @@ void _set_lobby_joins(int show)
}
}
bool sort_list()
{
return utils::string_bool(preferences::get("sort_list"), true);
}
void _set_sort_list(bool sort)
{
preferences::set("sort_list", sort ? "yes" : "no");
}
bool iconize_list()
{
return utils::string_bool(preferences::get("iconize_list"), true);
}
void _set_iconize_list(bool sort)
{
preferences::set("iconize_list", sort ? "yes" : "no");
}
const std::vector<game_config::server_info>& server_list()
{
static std::vector<game_config::server_info> pref_servers;
@ -903,54 +882,4 @@ void encounter_map_terrain(gamemap& map){
}
}
bool filter_lobby()
{
return utils::string_bool(preferences::get("filter_lobby"), false);
}
void set_filter_lobby(bool value)
{
preferences::set("filter_lobby", value ? "yes" : "no");
}
bool fi_invert()
{
return utils::string_bool(preferences::get("fi_invert"), false);
}
void set_fi_invert(bool value)
{
preferences::set("fi_invert", value ? "yes" : "no");
}
bool fi_vacant_slots()
{
return utils::string_bool(preferences::get("fi_vacant_slots"), false);
}
void set_fi_vacant_slots(bool value)
{
preferences::set("fi_vacant_slots", value ? "yes" : "no");
}
bool fi_friends_in_game()
{
return utils::string_bool(preferences::get("fi_friends_in_game"), false);
}
void set_fi_friends_in_game(bool value)
{
preferences::set("fi_friends_in_game", value ? "yes" : "no");
}
std::string fi_text()
{
return preferences::get("fi_text");
}
void set_fi_text(const std::string& search_string)
{
preferences::set("fi_text", search_string);
}
} // preferences namespace

View file

@ -38,9 +38,9 @@ namespace preferences {
};
bool is_authenticated();
void admin_authentication(const std::string& sender, const std::string& message);
void parse_admin_authentication(const std::string& sender, const std::string& message);
bool show_lobby_join(const std::string& sender, const std::string& message);
bool parse_should_show_lobby_join(const std::string& sender, const std::string& message);
int lobby_joins();
void _set_lobby_joins(int show);
enum { SHOW_NONE, SHOW_FRIENDS, SHOW_ALL };
@ -58,12 +58,6 @@ namespace preferences {
bool is_ignored(const std::string& nick);
bool is_campaign_completed(const std::string& campaign_id);
bool sort_list();
void _set_sort_list(bool show);
bool iconize_list();
void _set_iconize_list(bool show);
const std::vector<game_config::server_info>& server_list();
std::string network_host();
@ -235,21 +229,6 @@ namespace preferences {
// Add all terrains on the map as encountered terrains.
void encounter_map_terrain(gamemap& map);
bool filter_lobby();
void set_filter_lobby(bool value);
bool fi_invert();
void set_fi_invert(bool value);
bool fi_vacant_slots();
void set_fi_vacant_slots(bool value);
bool fi_friends_in_game();
void set_fi_friends_in_game(bool value);
std::string fi_text();
void set_fi_text(const std::string& search_string);
}
#endif

View file

@ -21,6 +21,7 @@
#include "foreach.hpp"
#include "gettext.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "lobby_preferences.hpp"
#include "preferences_display.hpp"
#include "wml_separators.hpp"
#include "widgets/slider.hpp"

View file

@ -34,6 +34,7 @@
#include "log.hpp"
#include "network.hpp"
#include "game_preferences.hpp"
#include "lobby_preferences.hpp"
#include "playmp_controller.hpp"
#include "formula_string_utils.hpp"
@ -60,39 +61,6 @@ static lg::log_domain log_lobby("lobby");
namespace gui2 {
namespace {
//TODO move this and other MP prefs to a MP_prefs header and possibly cpp
const char* prefkey_whisper_friends_only = "lobby_whisper_friends_only";
const char* prefkey_auto_open_whisper_windows = "lobby_auto_open_whisper_windows";
const char* prefkey_playerlist_sort_relation = "lobby_playerlist_sort_relation";
const char* prefkey_playerlist_sort_name = "lobby_playerlist_sort_name";
const char* prefkey_playerlist_single_group = "lobby_playerlist_single_group";
bool whisper_friends_only() {
return utils::string_bool(preferences::get(prefkey_whisper_friends_only));
}
bool auto_open_whisper_windows() {
return utils::string_bool(preferences::get(prefkey_auto_open_whisper_windows), true);
}
bool playerlist_sort_relation() {
return utils::string_bool(preferences::get(prefkey_playerlist_sort_relation), true);
}
void set_playerlist_sort_relation(bool v) {
return preferences::set(prefkey_playerlist_sort_relation, lexical_cast<std::string>(v));
}
bool playerlist_sort_name() {
return utils::string_bool(preferences::get(prefkey_playerlist_sort_name), true);
}
void set_playerlist_sort_name(bool v) {
return preferences::set(prefkey_playerlist_sort_name, lexical_cast<std::string>(v));
}
bool playerlist_single_group() {
return utils::string_bool(preferences::get(prefkey_playerlist_single_group), true);
}
void set_playerlist_single_group(bool v) {
return preferences::set(prefkey_playerlist_single_group, lexical_cast<std::string>(v));
}
}
void tsub_player_list::init(gui2::twindow &w, const std::string &id)
{
list = &w.get_widget<tlistbox>(id, false);
@ -186,7 +154,7 @@ void tlobby_main::add_whisper_sent(const std::string& receiver, const std::strin
{
if (whisper_window_active(receiver)) {
add_active_window_message(preferences::login(), message);
} else if (tlobby_chat_window* t = whisper_window_open(receiver, utils::string_bool(prefkey_auto_open_whisper_windows))) {
} 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);
} else {
@ -197,8 +165,8 @@ void tlobby_main::add_whisper_sent(const std::string& receiver, const std::strin
void tlobby_main::add_whisper_received(const std::string& sender, const std::string& message)
{
bool can_go_to_active = !whisper_friends_only() || preferences::is_friend(sender);
bool can_open_new = utils::string_bool(preferences::get(prefkey_auto_open_whisper_windows)) && can_go_to_active;
bool can_go_to_active = !preferences::whisper_friends_only() || preferences::is_friend(sender);
bool can_open_new = preferences::auto_open_whisper_windows() && can_go_to_active;
lobby_info_.get_whisper_log(sender).add_message(sender, message);
if (whisper_window_open(sender, can_open_new)) {
if (whisper_window_active(sender)) {
@ -501,7 +469,7 @@ void tlobby_main::update_playerlist()
icon_ss << ".png";
add_label_data(data, "player", name);
add_label_data(data, "main_icon", icon_ss.str());
if (playerlist_single_group()) {
if (preferences::playerlist_single_group()) {
target_list = &player_list_.other_rooms;
}
target_list->list->add_row(data);
@ -552,8 +520,8 @@ void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
player_list_.init(window);
player_list_.sort_by_name->set_value(playerlist_sort_name());
player_list_.sort_by_relation->set_value(playerlist_sort_relation());
player_list_.sort_by_name->set_value(preferences::playerlist_sort_name());
player_list_.sort_by_relation->set_value(preferences::playerlist_sort_relation());
player_list_.update_sort_icons();
player_list_.sort_by_name->set_callback_state_change(boost::bind(
@ -885,7 +853,7 @@ void tlobby_main::process_message(const config &data, bool whisper /*= false*/)
std::string sender = data["sender"];
if (preferences::is_ignored(sender)) return;
const std::string& message = data["message"];
preferences::admin_authentication(sender, message);
preferences::parse_admin_authentication(sender, message);
if (whisper) {
add_whisper_received(sender, message);
} else {
@ -1199,8 +1167,8 @@ void tlobby_main::gamelist_change_callback(gui2::twindow &/*window*/)
void tlobby_main::player_filter_callback(gui2::twidget* /*widget*/)
{
player_list_.update_sort_icons();
set_playerlist_sort_relation(player_list_.sort_by_relation->get_value());
set_playerlist_sort_name(player_list_.sort_by_name->get_value());
preferences::set_playerlist_sort_relation(player_list_.sort_by_relation->get_value());
preferences::set_playerlist_sort_name(player_list_.sort_by_name->get_value());
update_gamelist();
}

132
src/lobby_preferences.cpp Normal file
View file

@ -0,0 +1,132 @@
/* $Id$ */
/*
Copyright (C) 2009 by Tomasz Sniatowski <kailoran@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "lobby_preferences.hpp"
#include "game_preferences.hpp"
namespace preferences {
bool sort_list()
{
return utils::string_bool(preferences::get("sort_list"), true);
}
void _set_sort_list(bool sort)
{
preferences::set("sort_list", sort ? "yes" : "no");
}
bool iconize_list()
{
return utils::string_bool(preferences::get("iconize_list"), true);
}
void _set_iconize_list(bool sort)
{
preferences::set("iconize_list", sort ? "yes" : "no");
}
bool whisper_friends_only()
{
return utils::string_bool(preferences::get("lobby_whisper_friends_only"));
}
bool auto_open_whisper_windows()
{
return utils::string_bool(preferences::get("lobby_auto_open_whisper_windows"), true);
}
bool playerlist_sort_relation()
{
return utils::string_bool(preferences::get("lobby_playerlist_sort_relation"), true);
}
void set_playerlist_sort_relation(bool v)
{
return preferences::set("lobby_playerlist_sort_relation", lexical_cast<std::string>(v));
}
bool playerlist_sort_name()
{
return utils::string_bool(preferences::get("lobby_playerlist_sort_name"), true);
}
void set_playerlist_sort_name(bool v)
{
return preferences::set("lobby_playerlist_sort_name", lexical_cast<std::string>(v));
}
bool playerlist_single_group()
{
return utils::string_bool(preferences::get("lobby_playerlist_single_group"), true);
}
void set_playerlist_single_group(bool v)
{
return preferences::set("lobby_playerlist_single_group", lexical_cast<std::string>(v));
}
bool filter_lobby()
{
return utils::string_bool(preferences::get("filter_lobby"), false);
}
void set_filter_lobby(bool value)
{
preferences::set("filter_lobby", value ? "yes" : "no");
}
bool fi_invert()
{
return utils::string_bool(preferences::get("fi_invert"), false);
}
void set_fi_invert(bool value)
{
preferences::set("fi_invert", value ? "yes" : "no");
}
bool fi_vacant_slots()
{
return utils::string_bool(preferences::get("fi_vacant_slots"), false);
}
void set_fi_vacant_slots(bool value)
{
preferences::set("fi_vacant_slots", value ? "yes" : "no");
}
bool fi_friends_in_game()
{
return utils::string_bool(preferences::get("fi_friends_in_game"), false);
}
void set_fi_friends_in_game(bool value)
{
preferences::set("fi_friends_in_game", value ? "yes" : "no");
}
std::string fi_text()
{
return preferences::get("fi_text");
}
void set_fi_text(const std::string& search_string)
{
preferences::set("fi_text", search_string);
}
} //end namespace preferences

60
src/lobby_preferences.hpp Normal file
View file

@ -0,0 +1,60 @@
/* $Id$ */
/*
Copyright (C) 2009 by Tomasz Sniatowski <kailoran@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef LOBBY_PREFERENCES_HPP_INCLUDED
#define LOBBY_PREFERENCES_HPP_INCLUDED
#include <string>
namespace preferences {
bool sort_list();
void _set_sort_list(bool show);
bool iconize_list();
void _set_iconize_list(bool show);
bool whisper_friends_only();
void set_whisper_friends_only(bool v);
bool auto_open_whisper_windows();
void set_auto_open_whisper_windows(bool v);
bool playerlist_sort_relation();
void set_playerlist_sort_relation(bool v);
bool playerlist_sort_name();
void set_playerlist_sort_name(bool v);
bool playerlist_single_group();
void set_playerlist_single_group(bool v);
bool filter_lobby();
void set_filter_lobby(bool value);
bool fi_invert();
void set_fi_invert(bool value);
bool fi_vacant_slots();
void set_fi_vacant_slots(bool value);
bool fi_friends_in_game();
void set_fi_friends_in_game(bool value);
std::string fi_text();
void set_fi_text(const std::string& search_string);
} //end namespace preferences
#endif

View file

@ -20,6 +20,7 @@
#include "filesystem.hpp"
#include "foreach.hpp"
#include "lobby_preferences.hpp"
#include "map_exception.hpp"
#include "marked-up_text.hpp"
#include "minimap.hpp"

View file

@ -19,6 +19,7 @@
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "gui/dialogs/mp_cmd_wrapper.hpp"
#include "lobby_preferences.hpp"
#include "log.hpp"
#include "marked-up_text.hpp"
#include "multiplayer.hpp"
@ -525,10 +526,10 @@ void ui::process_message(const config& msg, const bool whisper) {
const std::string& sender = msg["sender"];
const std::string& message = msg["message"];
std::string room = msg["room"];
if (!preferences::show_lobby_join(sender, message)) return;
if (!preferences::parse_should_show_lobby_join(sender, message)) return;
if (preferences::is_ignored(sender)) return;
preferences::admin_authentication(sender, message);
preferences::parse_admin_authentication(sender, message);
if (whisper || utils::word_match(message, preferences::login())) {
sound::play_UI_sound(game_config::sounds::receive_message_highlight);

View file

@ -430,7 +430,7 @@ void replay::add_chat_log_entry(const config &cfg, std::ostream &str) const
{
if (!cfg) return;
if (!preferences::show_lobby_join(cfg["id"], cfg["message"])) return;
if (!preferences::parse_should_show_lobby_join(cfg["id"], cfg["message"])) return;
if (preferences::is_ignored(cfg["id"])) return;
const std::string& team_name = cfg["team_name"];
if(team_name == "") {
@ -830,7 +830,7 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
const std::string &team_name = child["team_name"];
const std::string &speaker_name = child["id"];
const std::string &message = child["message"];
//if (!preferences::show_lobby_join(speaker_name, message)) return;
//if (!preferences::parse_should_show_lobby_join(speaker_name, message)) return;
bool is_whisper = (speaker_name.find("whisper: ") == 0);
get_replay_source().add_chat_message_location();
if (!get_replay_source().is_skipping() || is_whisper) {