4-part-playerlist initial commit, needs a fix for a crash

This commit is contained in:
Tomasz Śniatowski 2009-07-21 00:15:37 +01:00
parent 650493a1be
commit 0792d6ec39
3 changed files with 196 additions and 50 deletions

View file

@ -177,58 +177,138 @@
[/listbox]
#enddef
#define PLAYERLISTBOX
[listbox]
id = "user_list"
definition = "default"
[header]
[row]
[column]
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "player"
definition = "default"
label = "Player"
[/label]
[/column]
[/row]
[/header]
[list_definition]
[row]
[column]
horizontal_grow = "true"
[toggle_panel]
definition = "default"
#define ONE_PLAYERLISTBOX ID LABEL
[row]
[column]
[grid]
[row]
[column]
horizontal_grow = "true"
border = "left,right"
border_size = 5
[grid]
[row]
[column]
border = "all"
border_size = 1
[image]
id = "main_icon"
definition = "default"
label = ""
[/image]
[label]
id = {ID}_label
definition = "default_tiny"
label = {LABEL}
[/label]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "top,right,bottom"
border_size = 3
[label]
id = "player"
definition = "default"
id = {ID}_count
definition = "default_small"
label = "0"
[/label]
[/column]
[column]
[toggle_button]
id = {ID}_show_toggle
definition = "icon"
[/toggle_button]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
[column]
[listbox]
id = {ID}
definition = "default"
horizontal_scrollbar_mode = "never"
vertical_scrollbar_mode = "never"
[header]
[row]
[column]
[label]
[/label]
[/column]
[/row]
[/header]
[list_definition]
[row]
[column]
horizontal_grow = "true"
[toggle_panel]
definition = "default"
[grid]
[row]
[column]
border = "all"
border_size = 1
[image]
id = "main_icon"
definition = "default"
label = ""
[/image]
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "top,right,bottom"
border_size = 3
[label]
id = "player"
definition = "default"
[/label]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
#enddef
#define PLAYERLISTBOX
[grid]
[row]
[column]
[grid]
[row]
[column]
[label]
definition = "default_small"
label = _ "Sort:"
[/label]
[/column]
[column]
[toggle_button]
id = "player_list_sort_name"
definition = "icon"
[/toggle_button]
[/column]
[column]
[toggle_button]
id = "player_list_sort_friends"
definition = "icon"
[/toggle_button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
[column]
[scrollbar_panel]
[definition]
{ONE_PLAYERLISTBOX "active_game" "Selected game"}
{ONE_PLAYERLISTBOX "active_room" "Current room"}
{ONE_PLAYERLISTBOX "other_rooms" "Lobby"}
{ONE_PLAYERLISTBOX "other_games" "Playing"}
[/definition]
[/scrollbar_panel]
[/column]
[/row]
[/grid]
#enddef
#define ROOMLISTBOX

View file

@ -61,6 +61,36 @@ namespace {
}
}
void tsub_player_list::init(gui2::twindow &w, const std::string &id)
{
list = &w.get_widget<tlistbox>(id, false);
show_toggle = &w.get_widget<ttoggle_button>(id + "_show_toggle", false);
show_toggle->set_icon_name("lobby/group-expanded.png");
show_toggle->set_callback_state_change(
boost::bind(&tsub_player_list::show_toggle_callback, this, _1));
count = &w.get_widget<tlabel>(id + "_count", false);
}
void tsub_player_list::show_toggle_callback(gui2::twidget* /*widget*/)
{
if (show_toggle->get_value()) {
list->set_visible(twidget::INVISIBLE);
show_toggle->set_icon_name("lobby/group-folded.png");
} else {
list->set_visible(twidget::VISIBLE);
show_toggle->set_icon_name("lobby/group-expanded.png");
}
}
void tplayer_list::init(gui2::twindow &w)
{
active_game.init(w, "active_game");
active_room.init(w, "active_room");
other_rooms.init(w, "other_rooms");
other_games.init(w, "other_games");
}
void tlobby_main::send_chat_message(const std::string& message, bool /*allies_only*/)
{
config data, msg;
@ -195,6 +225,7 @@ tlobby_main::tlobby_main(const config& game_config, lobby_info& info)
, chat_input_(NULL), window_(NULL)
, lobby_info_(info), preferences_callback_(NULL)
, open_windows_(), active_window_(0), selected_game_id_()
, player_list_()
{
}
@ -316,28 +347,39 @@ void tlobby_main::update_gamelist()
update_selected_game();
lobby_info_.update_user_statuses(selected_game_id_, active_window_room());
userlistbox_->clear();
player_list_.active_game.list->clear();
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())
{
tsub_player_list* target_list(NULL);
std::map<std::string, string_map> data;
std::stringstream icon_ss;
std::string name = user.name;
icon_ss << "lobby/status";
switch (user.state) {
case user_info::SEL_ROOM:
/* fall through */
icon_ss << "-lobby";
target_list = &player_list_.active_room;
break;
case user_info::LOBBY:
icon_ss << "-lobby";
target_list = &player_list_.other_rooms;
break;
case user_info::SEL_GAME:
name = colorize(name, "cyan");
icon_ss << (user.observing ? "-obs" : "-playing");
target_list = &player_list_.active_game;
break;
case user_info::GAME:
name = colorize(name, "red");
icon_ss << (user.observing ? "-obs" : "-playing"); break;
icon_ss << (user.observing ? "-obs" : "-playing");
target_list = &player_list_.other_games;
break;
default:
ERR_NG << "Bad user state in lobby: " << user.state << "\n";
ERR_NG << "Bad user state in lobby: " << user.name << ": " << user.state << "\n";
continue;
}
switch (user.relation) {
case user_info::ME:
@ -358,9 +400,9 @@ void tlobby_main::update_gamelist()
add_label_data(data, "player", name);
add_label_data(data, "main_icon", icon_ss.str());
userlistbox_->add_row(data);
target_list->list->add_row(data);
tgrid* grid = userlistbox_->get_row_grid(userlistbox_->get_item_count() - 1);
tgrid* grid = target_list->list->get_row_grid(target_list->list->get_item_count() - 1);
tlabel& name_label = grid->get_widget<tlabel>("player", false);
name_label.set_markup_mode(tcontrol::PANGO_MARKUP);
}
@ -393,8 +435,7 @@ void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
VALIDATE(gamelistbox_, missing_widget("game_list"));
gamelistbox_->set_callback_value_change(dialog_callback<tlobby_main, &tlobby_main::gamelist_change_callback>);
userlistbox_ = dynamic_cast<tlistbox*>(window.find_widget("user_list", false));
VALIDATE(userlistbox_, missing_widget("user_list"));
player_list_.init(window);
chat_log_container_ = dynamic_cast<tmulti_page*>(window.find_widget("chat_log_container", false));
VALIDATE(chat_log_container_, missing_widget("chat_log_container_"));

View file

@ -44,6 +44,29 @@ struct tlobby_chat_window
int pending_messages;
};
struct tplayer_list;
struct tsub_player_list
{
void init(twindow& w, const std::string& id);
void show_toggle_callback(twidget* widget);
tlabel* count;
ttoggle_button* show_toggle;
tlistbox* list;
};
struct tplayer_list
{
void init(twindow& w);
tsub_player_list active_game;
tsub_player_list active_room;
tsub_player_list other_rooms;
tsub_player_list other_games;
bool sort_by_name;
bool sort_by_relation;
};
class tlobby_main : public tdialog, private events::chat_handler
{
public:
@ -308,6 +331,8 @@ private:
ttext_box* filter_text_;
int selected_game_id_;
tplayer_list player_list_;
};
} // namespace gui2