Exemplo n.º 1
0
void tlobby_main::join_global_button_callback(twindow& window)
{
	if(do_game_join(gamelistbox_->get_selected_row(), false)) {
		legacy_result_ = JOIN;
		window.close();
	}
}
Exemplo n.º 2
0
void tlobby_main::observe_global_button_callback(twindow& window)
{
	if(do_game_join(gamelistbox_->get_selected_row(), true)) {
		legacy_result_ = OBSERVE;
		window.close();
	}
}
Exemplo n.º 3
0
void tlobby_main::join_or_observe(int idx)
{
	const game_info& game = *lobby_info_.games()[idx];
	if(do_game_join(idx, !game.can_join())) {
		window_->set_retval(game.can_join() ? JOIN : OBSERVE);
	}
}
Exemplo n.º 4
0
void tlobby_main::join_or_observe(int idx)
{
	const game_info& game = *lobby_info_.games()[idx];
	if(do_game_join(idx, !game.can_join())) {
		legacy_result_ = game.can_join() ? JOIN : OBSERVE;
		window_->close();
	}
}
Exemplo n.º 5
0
void tlobby_main::join_global_button_callback(twindow& window)
{
	if(do_game_join(gamelistbox_->get_selected_row(), false)) {
		window.set_retval(JOIN);
	}
}
Exemplo n.º 6
0
void tlobby_main::observe_global_button_callback(twindow& window)
{
	if(do_game_join(gamelistbox_->get_selected_row(), true)) {
		window.set_retval(OBSERVE);
	}
}
Exemplo n.º 7
0
void tlobby_main::pre_show(twindow& window)
{
	SCOPE_LB;

	gamelistbox_ = find_widget<tlistbox>(&window, "game_list", false, true);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(
			*gamelistbox_,
			std::bind(&tlobby_main::gamelist_change_callback, *this, std::ref(window)));
#else
	gamelistbox_->set_callback_value_change(
			dialog_callback<tlobby_main, &tlobby_main::gamelist_change_callback>);
#endif

	window.keyboard_capture(gamelistbox_);

	player_list_.init(window);

	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(
			std::bind(&tlobby_main::player_filter_callback, this, _1));
	player_list_.sort_by_relation->set_callback_state_change(
			std::bind(&tlobby_main::player_filter_callback, this, _1));

	window.set_enter_disabled(true);
	window.set_escape_disabled(true);

	// A new key handler to deal with escape in a different manner.
	window.connect_signal<event::SDL_KEY_DOWN>(
		std::bind(&tlobby_main::signal_handler_key_down, this, _5, _3, _4),
		event::tdispatcher::front_pre_child);

	window_ = &window;

	chatbox_ = find_widget<tchatbox>(&window, "chat", false, true);
	chatbox_->set_lobby_info(lobby_info_);
	chatbox_->set_wesnothd_connection(wesnothd_connection_);
	chatbox_->set_active_window_changed_callback([this]() { player_list_dirty_ = true; });

	find_widget<tbutton>(&window, "create", false).set_retval(CREATE);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "refresh", false),
		std::bind(&tlobby_main::refresh_button_callback, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "show_preferences", false),
		std::bind(&tlobby_main::show_preferences_button_callback, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "join_global", false),
		std::bind(&tlobby_main::join_global_button_callback, this, std::ref(window)));

	find_widget<tbutton>(&window, "join_global", false).set_active(false);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "observe_global", false),
		std::bind(&tlobby_main::observe_global_button_callback, this, std::ref(window)));

	find_widget<tbutton>(&window, "observe_global", false).set_active(false);

	tmenu_button& replay_options = find_widget<tmenu_button>(&window, "replay_options", false);

	if(preferences::skip_mp_replay()) {
		replay_options.set_selected(1);
	}

	if(preferences::blindfold_replay()) {
		replay_options.set_selected(2);
	}

	replay_options.connect_click_handler(
			std::bind(&tlobby_main::skip_replay_changed_callback, this, std::ref(window)));

	filter_friends_ = find_widget<ttoggle_button>(&window, "filter_with_friends", false, true);
	filter_ignored_ = find_widget<ttoggle_button>(&window, "filter_without_ignored", false, true);
	filter_slots_   = find_widget<ttoggle_button>(&window, "filter_vacant_slots", false, true);
	filter_invert_  = find_widget<ttoggle_button>(&window, "filter_invert", false, true);
	filter_text_    = find_widget<ttext_box>(&window, "filter_text", false, true);

	filter_friends_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_ignored_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_slots_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	filter_invert_->set_callback_state_change(
			std::bind(&tlobby_main::game_filter_change_callback, this, _1));
	connect_signal_pre_key_press(
			*filter_text_,
			std::bind(&tlobby_main::game_filter_keypress_callback, this, _5));

	chatbox_->room_window_open("lobby", true);
	chatbox_->active_window_changed();
	game_filter_reload();

	// Force first update to be directly.
	tlobby_main::network_handler();
	lobby_update_timer_ = add_timer(
		game_config::lobby_network_timer, std::bind(&tlobby_main::network_handler, this), true);

	// Set up Lua plugin context
	plugins_context_.reset(new plugins_context("Multiplayer Lobby"));

	plugins_context_->set_callback("join",    [&, this](const config&) {
		if(do_game_join(get_game_index_from_id(selected_game_id_), false)) {
			window.set_retval(JOIN);
		}
	}, true);

	plugins_context_->set_callback("observe", [&, this](const config&) {
		if(do_game_join(get_game_index_from_id(selected_game_id_), true)) {
			window.set_retval(OBSERVE);
		}
	}, true);

	plugins_context_->set_callback("create", [this, &window](const config&) { window.set_retval(CREATE); }, true);
	plugins_context_->set_callback("quit", [&window](const config&) { window.set_retval(twindow::CANCEL); }, false);

	plugins_context_->set_callback("chat", [this](const config& cfg) { chatbox_->send_chat_message(cfg["message"], false); }, true);
	plugins_context_->set_callback("select_game", [this](const config& cfg) {
		selected_game_id_ = cfg.has_attribute("id") ? cfg["id"].to_int() : lobby_info_.games()[cfg["index"].to_int()]->id;
	}, true);

	plugins_context_->set_accessor("game_list",   [this](const config&) { return lobby_info_.gamelist(); });
	plugins_context_->set_accessor("game_config", [this](const config&) { return game_config_; });
}