new lobby player list sorting:
...by name, relation(friends/neutral/ignores) or both (first by relation then by name)
This commit is contained in:
parent
1584ae7f74
commit
17be99971f
9 changed files with 96 additions and 9 deletions
BIN
data/core/images/lobby/sort-az-off.png
Normal file
BIN
data/core/images/lobby/sort-az-off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
BIN
data/core/images/lobby/sort-az.png
Normal file
BIN
data/core/images/lobby/sort-az.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
BIN
data/core/images/lobby/sort-friend-off.png
Normal file
BIN
data/core/images/lobby/sort-friend-off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 371 B |
BIN
data/core/images/lobby/sort-friend.png
Normal file
BIN
data/core/images/lobby/sort-friend.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 378 B |
|
@ -208,7 +208,7 @@
|
|||
[column]
|
||||
[toggle_button]
|
||||
id = {ID}_show_toggle
|
||||
definition = "icon_small"
|
||||
definition = "icon_tiny"
|
||||
[/toggle_button]
|
||||
[/column]
|
||||
[/row]
|
||||
|
@ -273,19 +273,21 @@
|
|||
[column]
|
||||
[label]
|
||||
definition = "default_small"
|
||||
label = _ "Sort:"
|
||||
label = _ "Sort players:"
|
||||
[/label]
|
||||
[/column]
|
||||
[column]
|
||||
[toggle_button]
|
||||
id = "player_list_sort_name"
|
||||
definition = "icon"
|
||||
definition = "icon_small"
|
||||
icon = "lobby/sort-az-off.png"
|
||||
[/toggle_button]
|
||||
[/column]
|
||||
[column]
|
||||
[toggle_button]
|
||||
id = "player_list_sort_friends"
|
||||
definition = "icon"
|
||||
id = "player_list_sort_relation"
|
||||
definition = "icon_small"
|
||||
icon = "lobby/sort-friend-off.png"
|
||||
[/toggle_button]
|
||||
[/column]
|
||||
[/row]
|
||||
|
|
|
@ -108,6 +108,8 @@ void tplayer_list::init(gui2::twindow &w)
|
|||
active_room.init(w, "active_room");
|
||||
other_rooms.init(w, "other_rooms");
|
||||
other_games.init(w, "other_games");
|
||||
sort_by_name = &w.get_widget<ttoggle_button>("player_list_sort_name", false);
|
||||
sort_by_relation = &w.get_widget<ttoggle_button>("player_list_sort_relation", false);
|
||||
}
|
||||
|
||||
void tlobby_main::send_chat_message(const std::string& message, bool /*allies_only*/)
|
||||
|
@ -368,6 +370,7 @@ void tlobby_main::update_gamelist()
|
|||
update_selected_game();
|
||||
|
||||
lobby_info_.update_user_statuses(selected_game_id_, active_window_room());
|
||||
lobby_info_.sort_users(player_list_.sort_by_name->get_value(), player_list_.sort_by_relation->get_value());
|
||||
|
||||
bool lobby = false;
|
||||
if (room_info* ri = active_window_room()) {
|
||||
|
@ -379,8 +382,9 @@ void tlobby_main::update_gamelist()
|
|||
player_list_.active_room.list->clear();
|
||||
player_list_.other_rooms.list->clear();
|
||||
player_list_.other_games.list->clear();
|
||||
foreach (const user_info& user, lobby_info_.users())
|
||||
foreach (const user_info* userptr, lobby_info_.users_sorted())
|
||||
{
|
||||
const user_info& user = *userptr;
|
||||
tsub_player_list* target_list(NULL);
|
||||
std::map<std::string, string_map> data;
|
||||
std::stringstream icon_ss;
|
||||
|
@ -473,6 +477,11 @@ void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
|
|||
|
||||
player_list_.init(window);
|
||||
|
||||
player_list_.sort_by_name->set_callback_state_change(boost::bind(
|
||||
&tlobby_main::player_filter_callback, this, _1));
|
||||
player_list_.sort_by_relation->set_callback_state_change(boost::bind(
|
||||
&tlobby_main::player_filter_callback, this, _1));
|
||||
|
||||
chat_log_container_ = dynamic_cast<tmulti_page*>(window.find_widget("chat_log_container", false));
|
||||
VALIDATE(chat_log_container_, missing_widget("chat_log_container_"));
|
||||
|
||||
|
@ -1023,4 +1032,19 @@ void tlobby_main::gamelist_change_callback(gui2::twindow &/*window*/)
|
|||
update_selected_game();
|
||||
}
|
||||
|
||||
void tlobby_main::player_filter_callback(gui2::twidget* /*widget*/)
|
||||
{
|
||||
if (player_list_.sort_by_name->get_value()) {
|
||||
player_list_.sort_by_name->set_icon_name("lobby/sort-az.png");
|
||||
} else {
|
||||
player_list_.sort_by_name->set_icon_name("lobby/sort-az-off.png");
|
||||
}
|
||||
if (player_list_.sort_by_relation->get_value()) {
|
||||
player_list_.sort_by_relation->set_icon_name("lobby/sort-friend.png");
|
||||
} else {
|
||||
player_list_.sort_by_relation->set_icon_name("lobby/sort-friend-off.png");
|
||||
}
|
||||
update_gamelist();
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -65,8 +65,8 @@ struct tplayer_list
|
|||
tsub_player_list other_rooms;
|
||||
tsub_player_list other_games;
|
||||
|
||||
bool sort_by_name;
|
||||
bool sort_by_relation;
|
||||
ttoggle_button* sort_by_name;
|
||||
ttoggle_button* sort_by_relation;
|
||||
};
|
||||
|
||||
class tlobby_main : public tdialog, private events::chat_handler
|
||||
|
@ -293,6 +293,8 @@ private:
|
|||
|
||||
void gamelist_change_callback(twindow& window);
|
||||
|
||||
void player_filter_callback(twidget* widget);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
twindow* build_window(CVideo& video);
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ void user_info::update_state(int selected_game_id, const room_info* current_room
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
game_info::game_info() :
|
||||
mini_map(),
|
||||
id(),
|
||||
|
@ -568,3 +569,57 @@ void lobby_info::update_user_statuses(int game_id, const room_info *room)
|
|||
user.update_state(game_id, room);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct user_sorter_name
|
||||
{
|
||||
bool operator()(const user_info& u1, const user_info& u2) {
|
||||
return u1.name < u2.name;
|
||||
}
|
||||
bool operator()(const user_info* u1, const user_info* u2) {
|
||||
return operator()(*u1, *u2);
|
||||
}
|
||||
};
|
||||
|
||||
struct user_sorter_relation
|
||||
{
|
||||
bool operator()(const user_info& u1, const user_info& u2) {
|
||||
return static_cast<int>(u1.relation) < static_cast<int>(u2.relation);
|
||||
}
|
||||
bool operator()(const user_info* u1, const user_info* u2) {
|
||||
return operator()(*u1, *u2);
|
||||
}
|
||||
};
|
||||
|
||||
struct user_sorter_relation_name
|
||||
{
|
||||
bool operator()(const user_info& u1, const user_info& u2) {
|
||||
return static_cast<int>(u1.relation) < static_cast<int>(u2.relation)
|
||||
|| (u1.relation == u2.relation && u1.name < u2.name);
|
||||
}
|
||||
bool operator()(const user_info* u1, const user_info* u2) {
|
||||
return operator()(*u1, *u2);
|
||||
}
|
||||
};
|
||||
|
||||
void lobby_info::sort_users(bool by_name, bool by_relation)
|
||||
{
|
||||
users_sorted_.clear();
|
||||
foreach (user_info& u, users_) {
|
||||
users_sorted_.push_back(&u);
|
||||
}
|
||||
if (by_name) {
|
||||
if (by_relation) {
|
||||
std::sort(users_sorted_.begin(), users_sorted_.end(), user_sorter_relation_name());
|
||||
} else {
|
||||
std::sort(users_sorted_.begin(), users_sorted_.end(), user_sorter_name());
|
||||
}
|
||||
} else if (by_relation) {
|
||||
std::sort(users_sorted_.begin(), users_sorted_.end(), user_sorter_relation());
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<user_info*>& lobby_info::users_sorted()
|
||||
{
|
||||
return users_sorted_;
|
||||
}
|
|
@ -90,7 +90,7 @@ struct user_info
|
|||
|
||||
void update_state(int selected_game_id, const room_info* current_room = NULL);
|
||||
|
||||
enum user_relation { ME, FRIEND, NEUTRAL, IGNORED };
|
||||
enum user_relation { FRIEND, ME, NEUTRAL, IGNORED };
|
||||
enum user_state { LOBBY, SEL_ROOM, GAME, SEL_GAME };
|
||||
|
||||
bool operator> (const user_info& b) const;
|
||||
|
@ -260,6 +260,8 @@ public:
|
|||
void set_game_filter_invert(bool value);
|
||||
void apply_game_filter();
|
||||
|
||||
void sort_users(bool by_name, bool by_relation);
|
||||
|
||||
void open_room(const std::string& name);
|
||||
void close_room(const std::string& name);
|
||||
bool has_room(const std::string& name) const;
|
||||
|
@ -276,6 +278,7 @@ public:
|
|||
const std::vector<game_info>& games() const { return games_; }
|
||||
const std::vector<game_info*>& games_filtered();
|
||||
const std::vector<user_info>& users() const { return users_; }
|
||||
const std::vector<user_info*>& users_sorted();
|
||||
private:
|
||||
void parse_gamelist();
|
||||
|
||||
|
@ -287,6 +290,7 @@ private:
|
|||
std::map<int, game_info*> games_by_id_;
|
||||
std::vector<game_info*> games_filtered_;
|
||||
std::vector<user_info> users_;
|
||||
std::vector<user_info*> users_sorted_;
|
||||
std::map<std::string, chat_log> whispers_;
|
||||
game_filter_and_stack game_filter_;
|
||||
bool game_filter_invert_;
|
||||
|
|
Loading…
Add table
Reference in a new issue