add friendlist

This commit is contained in:
Jérémy Rosen 2006-12-28 13:30:38 +00:00
parent a85fb382b5
commit 9fc9763969
12 changed files with 236 additions and 50 deletions

View file

@ -79,6 +79,9 @@ Version 1.3-svn:
(patch #605)A
* changed the zoom hotkeys from 'z', 'x' and 'c' to '+', '-' and '0'
* fix the completion when controlling multiple sides (bug #8101, patch #653)
* add a friend list in MP lobby, they will display a special icon in lobby,
and you can be warned when they join the lobby even when not receiving
lobby joins
* WML engine
* added prerecruit event that takes place after the unit is created but
before it is displayed.

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

View file

@ -2388,11 +2388,11 @@ void display::add_chat_message(const std::string& speaker, int side, const std::
{
config* cignore;
bool ignored = false;
if ((cignore = preferences::get_prefs()->child("ignore"))){
if ((cignore = preferences::get_prefs()->child("relationship"))){
for(std::map<std::string,t_string>::const_iterator i = cignore->values.begin();
i != cignore->values.end(); ++i){
if(speaker == i->first || speaker == "whisper: " + i->first){
if (i->second == "yes"){
if (i->second == "ignored"){
ignored = true;
}
}

View file

@ -1731,7 +1731,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
}
}
}
else if(cmd == "unstore_unit") {
wassert(state_of_game != NULL);
const config& var = state_of_game->get_variable_cfg(

View file

@ -1441,17 +1441,18 @@ namespace events{
static const std::string query = "/query";
static const std::string whisper = "/whisper";
static const std::string whisper2 = "/msg";
static const std::string ignore = "/ignore";
static const std::string list = "/list";
static const std::string help = "/help";
static const std::string emote = "/emote";
static const std::string emote2 = "/me";
static const std::string add = "add";
static const std::string addignore = "addignore";
static const std::string addfriend = "addfriend";
static const std::string remove = "remove";
static const std::string list = "list";
static const std::string display = "display";
static const std::string clear = "clear";
static const std::string help_chat_help = _("Commands: whisper ignore emote. Type /help [command] for more help.");
static const std::string help_chat_help = _("Commands: whisper list emote. Type /help [command] for more help.");
bool is_command = (message.at(0) == '/');
unsigned int argc = 0;
@ -1503,21 +1504,23 @@ namespace events{
if (have_command) {
if (command == "whisper" || command == "msg") {
add_chat_message("help",0,_("Sends private message. You can't send messages to players that control any side in game. Usage: /whisper [nick] [message]"));
} else if (command == "ignore") {
} else if (command == "list") {
if (have_subcommand) {
if (subcommand == "add"){
add_chat_message("help",0,_("Add player to your ignore list. Usage: /ignore add [argument]"));
if (subcommand == "addfriend"){
add_chat_message("help",0,_("Add player to your friends list. Usage: /list addfriend [argument]"));
} else if (subcommand == "addignore"){
add_chat_message("help",0,_("Add player to your ignore list. Usage: /list ignore [argument]"));
} else if (subcommand == "remove") {
add_chat_message("help",0,_("Remove player from your ignore list. Usage: /ignore remove [argument]"));
add_chat_message("help",0,_("Remove player from your ignore or friends list. Usage: /list remove [argument]"));
} else if (subcommand == "clear") {
add_chat_message("help",0,_("Clear your ignore list. Usage: /ignore clear"));
} else if (subcommand == "list") {
add_chat_message("help",0,_("Show your ignore list. Usage: /ignore list"));
add_chat_message("help",0,_("Clear your ignore and friends list. Usage: /list clear"));
} else if (subcommand == "display") {
add_chat_message("help",0,_("Show your ignore and friends list. Usage: /list display"));
} else {
add_chat_message("help",0,_("Unknown subcommand"));
}
} else {
add_chat_message("help",0,_("Ignore messages from players on this list. Usage: /ignore [subcommand] [argument](optional) Subcommands: add remove list clear. Type /help ignore [subcommand] for more info."));
add_chat_message("help",0,_("Ignore messages from players on the ignore list and highlight players on the friends list. Usage: /list [subcommand] [argument](optional) Subcommands: addfriend addignore remove display clear. Type /help list [subcommand] for more info."));
}
} else if (command == "emote" || command == "me") {
add_chat_message("help",0,_("Send an emotion or personal action in chat. Usage: /emote [message]"));
@ -1527,60 +1530,89 @@ namespace events{
} else {
add_chat_message("help",0,help_chat_help);
}
} else if (message.size() > ignore.size() && std::equal(ignore.begin(),ignore.end(), message.begin())) {
} else if (message.size() > list.size() && std::equal(list.begin(),list.end(), message.begin())) {
config* cignore;
if (arg1 == add){
if (!preferences::get_prefs()->child("ignore")){
preferences::get_prefs()->add_child("ignore");
if (arg1 == addignore){
if (!preferences::get_prefs()->child("relationship")){
preferences::get_prefs()->add_child("relationship");
}
cignore = preferences::get_prefs()->child("ignore");
cignore = preferences::get_prefs()->child("relationship");
if(utils::isvalid_username(arg2))
{
(*cignore)[arg2] = "yes";
(*cignore)[arg2] = "ignored";
add_chat_message("ignores list",0, _("Added to ignore list: ")+arg2,display::MESSAGE_PRIVATE);
} else {
add_chat_message("ignores list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
}
} else if (arg1 == addfriend){
if (!preferences::get_prefs()->child("relationship")){
preferences::get_prefs()->add_child("relationship");
}
cignore = preferences::get_prefs()->child("relationship");
if(utils::isvalid_username(arg2))
{
(*cignore)[arg2] = "friend";
add_chat_message("friends list",0, _("Added to friends list: ")+arg2,display::MESSAGE_PRIVATE);
} else {
add_chat_message("friends list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
}
} else if (arg1 == remove){
if ((cignore = preferences::get_prefs()->child("ignore"))){
if ((cignore = preferences::get_prefs()->child("relationship"))){
if(utils::isvalid_username(arg2))
{
(*cignore)[arg2] = "no";
add_chat_message("ignores list",0, _("Removed from ignore list: ")+arg2,display::MESSAGE_PRIVATE);
add_chat_message("list",0, _("Removed from list: ")+arg2,display::MESSAGE_PRIVATE);
} else {
add_chat_message("ignores list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
add_chat_message("list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
}
}
} else if (arg1 == list){
std::string text;
if ((cignore = preferences::get_prefs()->child("ignore"))){
} else if (arg1 == display){
std::string text_ignore;
std::string text_friend;
if ((cignore = preferences::get_prefs()->child("relationship"))){
for(std::map<std::string,t_string>::const_iterator i = cignore->values.begin();
i != cignore->values.end(); ++i){
if (i->second == "yes"){
text+=i->first+",";
if (i->second == "ignored"){
text_ignore+=i->first+",";
}
if (i->second == "friend"){
text_friend+=i->first+",";
}
}
if(!text.empty()){
text.erase(text.length()-1,1);
if(!text_ignore.empty()){
text_ignore.erase(text_ignore.length()-1,1);
add_chat_message("ignores list",0, text_ignore,display::MESSAGE_PRIVATE);
}
if(!text_friend.empty()){
text_friend.erase(text_friend.length()-1,1);
add_chat_message("friends list",0, text_friend,display::MESSAGE_PRIVATE);
}
if (text_friend.empty() && text_ignore.empty()) {
add_chat_message("list",0, _("There are no players on your friends or ignore list."));
}
}
add_chat_message("ignores list",0, text,display::MESSAGE_PRIVATE);
} else if (arg1 == clear){
if ((cignore = preferences::get_prefs()->child("ignore"))){
if ((cignore = preferences::get_prefs()->child("relationship"))){
string_map::iterator nick;
for(nick= cignore->values.begin() ; nick!= cignore->values.end(); nick++) {
if((*cignore)[nick->first] != "no") {
if((*cignore)[nick->first] == "ignored") {
add_chat_message("ignore list",0, _("Removed from ignore list: ")+nick->first,display::MESSAGE_PRIVATE);
}
if((*cignore)[nick->first] == "friend") {
add_chat_message("friend list",0, _("Removed from friends list: ")+nick->first,display::MESSAGE_PRIVATE);
}
(*cignore)[nick->first] = "no";
add_chat_message("ignores list",0, _("Removed from ignore list: ")+nick->first,display::MESSAGE_PRIVATE);
}
}
}
} else {
add_chat_message("ignores list",0,_("Unknown command: ")+arg1,display::MESSAGE_PRIVATE);
add_chat_message("list",0,_("Unknown command: ")+arg1,display::MESSAGE_PRIVATE);
}
} else if ((cmd == emote || cmd == emote2) && argc > 0) {
//emote message

View file

@ -371,11 +371,11 @@ void ui::process_network_data(const config& data, const network::connection /*so
const config& msg = *data.child("message");
config* cignore;
bool ignored = false;
if ((cignore = preferences::get_prefs()->child("ignore"))){
if ((cignore = preferences::get_prefs()->child("relationship"))){
for(std::map<std::string,t_string>::const_iterator i = cignore->values.begin();
i != cignore->values.end(); ++i){
if(msg["sender"] == i->first){
if (i->second == "yes"){
if (i->second == "ignored"){
ignored = true;
}
}
@ -395,11 +395,11 @@ void ui::process_network_data(const config& data, const network::connection /*so
config* cignore;
bool ignored = false;
if ((cignore = preferences::get_prefs()->child("ignore"))){
if ((cignore = preferences::get_prefs()->child("relationship"))){
for(std::map<std::string,t_string>::const_iterator i = cignore->values.begin();
i != cignore->values.end(); ++i){
if(cwhisper["sender"] == i->first){
if (i->second == "yes"){
if (i->second == "ignored"){
ignored = true;
}
}
@ -471,18 +471,95 @@ void ui::layout_children(const SDL_Rect& /*rect*/)
}
void ui::gamelist_updated(bool silent)
{
std::vector<std::string> user_strings;
{
std::vector<std::string> user_strings;
config::child_list users = gamelist_.get_children("user");
config::child_iterator user;
//if we have not already got the relationship child it will
//cause the game to crash if we don't create it.
if (!preferences::get_prefs()->child("relationship")){
preferences::get_prefs()->add_child("relationship");
}
config* cignore;
cignore = preferences::get_prefs()->child("relationship");
char const COLUMN_SEPARATOR = '=', IMAGE_PREFIX = '&';
std::string const imgpre = IMAGE_PREFIX + std::string("misc/status-");
char const sep1 = COLUMN_SEPARATOR;
if(preferences::sort_list()) {
for (user = users.begin(); user != users.end(); ++user) {
std::string ig = std::string((**user)["name"]);
if((*cignore)[ig] == "friend") {
std::string prefix = (**user)["available"] == "no" ? "#" : "";
std::string suffix = "";
if(!(**user)["location"].empty()) {
suffix = std::string(" (") + (**user)["location"] + std::string(")");
}
if(preferences::iconize_list()) {
user_strings.push_back(imgpre + "friend.png" + sep1 + prefix + (**user)["name"].str() + suffix);
} else {
user_strings.push_back(prefix + (**user)["name"].str() + suffix);
}
}
}
for (user = users.begin(); user != users.end(); ++user) {
std::string ig = std::string((**user)["name"]);
if((*cignore)[ig] != "ignored" && (*cignore)[ig] != "friend") {
std::string prefix = (**user)["available"] == "no" ? "#" : "";
std::string suffix = "";
if(!(**user)["location"].empty()) {
suffix = std::string(" (") + (**user)["location"] + std::string(")");
}
if(preferences::iconize_list()) {
user_strings.push_back(imgpre + "neutral.png" + sep1 + prefix + (**user)["name"].str() + suffix);
} else {
user_strings.push_back(prefix + (**user)["name"].str() + suffix);
}
}
}
for (user = users.begin(); user != users.end(); ++user) {
std::string ig = std::string((**user)["name"]);
if((*cignore)[ig] == "ignored") {
std::string prefix = (**user)["available"] == "no" ? "#" : "";
std::string suffix = "";
if(!(**user)["location"].empty()) {
suffix = std::string(" (") + (**user)["location"] + std::string(")");
}
if(preferences::iconize_list()) {
user_strings.push_back(imgpre + "ignore.png" + sep1 + prefix + (**user)["name"].str() + suffix);
} else {
user_strings.push_back(prefix + (**user)["name"].str() + suffix);
}
}
}
} else {
for (user = users.begin(); user != users.end(); ++user) {
const std::string prefix = (**user)["available"] == "no" ? "#" : "";
std::string suffix = "";
if(!(**user)["location"].empty()) {
suffix = std::string(" (") + (**user)["location"] + std::string(")");
}
user_strings.push_back(prefix + (**user)["name"].str() + suffix);
}
if(preferences::iconize_list()) {
std::string ig = std::string((**user)["name"]);
if((*cignore)[ig] == "ignored") {
user_strings.push_back(imgpre + "ignore.png" + sep1 + prefix + (**user)["name"].str() + suffix);
} else if ((*cignore)[ig] == "friend") {
user_strings.push_back(imgpre + "friend.png" + sep1 + prefix + (**user)["name"].str() + suffix);
} else {
user_strings.push_back(imgpre + "neutral.png" + sep1 + prefix + (**user)["name"].str() + suffix);
}
} else {
user_strings.push_back(prefix + (**user)["name"].str() + suffix);
}
}
}
set_user_list(user_strings, silent);
}

View file

@ -309,6 +309,34 @@ void _set_lobby_joins(bool show)
prefs["lobby_joins"] = "no";
}
bool sort_list()
{
return prefs["sort_list"] != "no";
}
void _set_sort_list(bool sort)
{
if(sort)
prefs["sort_list"] = "yes";
else
prefs["sort_list"] = "no";
}
bool iconize_list()
{
return prefs["iconize_list"] != "no";
}
void _set_iconize_list(bool sort)
{
if(sort)
prefs["iconize_list"] = "yes";
else
prefs["iconize_list"] = "no";
}
const std::string& official_network_host()
{
static const std::string host = WESNOTH_DEFAULT_SERVER;

View file

@ -96,6 +96,12 @@ namespace preferences {
bool lobby_joins();
void _set_lobby_joins(bool show);
bool sort_list();
void _set_sort_list(bool show);
bool iconize_list();
void _set_iconize_list(bool show);
const std::string& official_network_host();

View file

@ -168,6 +168,16 @@ void set_lobby_joins(bool ison)
_set_lobby_joins(ison);
}
void set_sort_list(bool ison)
{
_set_sort_list(ison);
}
void set_iconize_list(bool ison)
{
_set_iconize_list(ison);
}
void set_colour_cursors(bool value)
{
_set_colour_cursors(value);
@ -206,7 +216,7 @@ private:
gui::slider music_slider_, sound_slider_, bell_slider_, scroll_slider_,
gamma_slider_, chat_lines_slider_, turbo_slider_;
gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_, show_grid_button_,
lobby_minimaps_button_, show_lobby_joins_button_, show_floating_labels_button_, turn_dialog_button_,
lobby_minimaps_button_, show_lobby_joins_button_, sort_list_by_group_button_, iconize_list_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_, theme_button_, hotkeys_button_, gamma_button_,
flip_time_button_, advanced_button_, sound_button_, music_button_, chat_timestamp_button_;
@ -234,7 +244,9 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
show_ai_moves_button_(disp.video(), _("Skip AI Moves"), gui::button::TYPE_CHECK),
show_grid_button_(disp.video(), _("Show Grid"), gui::button::TYPE_CHECK),
lobby_minimaps_button_(disp.video(), _("Show Lobby Minimaps"), gui::button::TYPE_CHECK),
show_lobby_joins_button_(disp.video(), _("Show Lobby Joins"), gui::button::TYPE_CHECK),
show_lobby_joins_button_(disp.video(), _("Show Lobby Joins Of Friends"), gui::button::TYPE_CHECK),
sort_list_by_group_button_(disp.video(), _("Sort Lobby List"), gui::button::TYPE_CHECK),
iconize_list_button_(disp.video(), _("Iconize Lobby List"), gui::button::TYPE_CHECK),
show_floating_labels_button_(disp.video(), _("Show Floating Labels"), gui::button::TYPE_CHECK),
turn_dialog_button_(disp.video(), _("Turn Dialog"), gui::button::TYPE_CHECK),
turn_bell_button_(disp.video(), _("Turn Bell"), gui::button::TYPE_CHECK),
@ -328,9 +340,15 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
lobby_minimaps_button_.set_check(show_lobby_minimaps());
lobby_minimaps_button_.set_help_string(_("Show minimaps in the multiplayer lobby"));
sort_list_by_group_button_.set_check(sort_list());
sort_list_by_group_button_.set_help_string(_("Sort the player list in the lobby by player groups"));
iconize_list_button_.set_check(iconize_list());
iconize_list_button_.set_help_string(_("Show icons in front of the player names in the lobby."));
show_lobby_joins_button_.set_check(lobby_joins());
show_lobby_joins_button_.set_help_string(_("Show messages about players joining the multiplayer lobby"));
show_lobby_joins_button_.set_help_string(_("Show messages about your friends joining the multiplayer lobby"));
show_floating_labels_button_.set_check(show_floating_labels());
show_floating_labels_button_.set_help_string(_("Show text above a unit when it is hit to display damage inflicted"));
@ -376,6 +394,8 @@ handler_vector preferences_dialog::handler_members()
h.push_back(&show_ai_moves_button_);
h.push_back(&show_grid_button_);
h.push_back(&lobby_minimaps_button_);
h.push_back(&sort_list_by_group_button_);
h.push_back(&iconize_list_button_);
h.push_back(&show_lobby_joins_button_);
h.push_back(&show_floating_labels_button_);
h.push_back(&turn_dialog_button_);
@ -495,6 +515,8 @@ void preferences_dialog::update_location(SDL_Rect const &rect)
ypos += item_interline; chat_timestamp_button_.set_location(rect.x, ypos);
ypos += item_interline; lobby_minimaps_button_.set_location(rect.x, ypos);
ypos += item_interline; show_lobby_joins_button_.set_location(rect.x, ypos);
ypos += item_interline; sort_list_by_group_button_.set_location(rect.x, ypos);
ypos += item_interline; iconize_list_button_.set_location(rect.x, ypos);
//Advanced tab
ypos = rect.y + top_border;
@ -520,6 +542,10 @@ void preferences_dialog::process_event()
save_show_lobby_minimaps(lobby_minimaps_button_.checked());
if (show_lobby_joins_button_.pressed())
set_lobby_joins(show_lobby_joins_button_.checked());
if (sort_list_by_group_button_.pressed())
set_sort_list(sort_list_by_group_button_.checked());
if (iconize_list_button_.pressed())
set_iconize_list(iconize_list_button_.checked());
if (show_floating_labels_button_.pressed())
set_show_floating_labels(show_floating_labels_button_.checked());
if (video_mode_button_.pressed())
@ -691,6 +717,8 @@ void preferences_dialog::set_selection(int index)
chat_lines_slider_.hide(hide_multiplayer);
chat_timestamp_button_.hide(hide_multiplayer);
lobby_minimaps_button_.hide(hide_multiplayer);
sort_list_by_group_button_.hide(hide_multiplayer);
iconize_list_button_.hide(hide_multiplayer);
show_lobby_joins_button_.hide(hide_multiplayer);
const bool hide_advanced = tab_ != ADVANCED_TAB;

View file

@ -710,10 +710,22 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
if(preferences::message_bell()) {
sound::play_sound(game_config::sounds::receive_message);
}
const int side = lexical_cast_default<int>((*child)["side"].c_str(),0);
disp.add_chat_message(speaker_name,side,(*child)["message"],
team_name == "" ? display::MESSAGE_PUBLIC : display::MESSAGE_PRIVATE);
std::string str = (*child)["message"];
std::string buf;
std::stringstream ss(str);
ss >> buf;
if (!preferences::get_prefs()->child("relationship")){
preferences::get_prefs()->add_child("relationship");
}
config* cignore;
cignore = preferences::get_prefs()->child("relationship");
if ((*cignore)[buf] == "friend") {
const int side = lexical_cast_default<int>((*child)["side"].c_str(),0);
disp.add_chat_message(speaker_name,side,(*child)["message"],
team_name == "" ? display::MESSAGE_PUBLIC : display::MESSAGE_PRIVATE);
}
}
}
} else if((child = cfg->child("label")) != NULL) {