Yet another new lobby WIP, this time with crude but working create/join game.
This commit is contained in:
parent
c538e687c3
commit
a44ebce1e9
4 changed files with 163 additions and 30 deletions
|
@ -77,10 +77,10 @@
|
|||
definition = "default"
|
||||
[header]
|
||||
[row]
|
||||
{GAMELISTBOX_HEADER_LABEL "map" "Map"}
|
||||
[column]
|
||||
[grid]
|
||||
[row]
|
||||
{GAMELISTBOX_HEADER_LABEL "map" "Map"}
|
||||
{GAMELISTBOX_EMPTY "minimap"}
|
||||
{GAMELISTBOX_EMPTY "name"}
|
||||
{GAMELISTBOX_EMPTY "era"}
|
||||
|
@ -88,10 +88,10 @@
|
|||
{GAMELISTBOX_EMPTY "slots"}
|
||||
{GAMELISTBOX_EMPTY "options"}
|
||||
{GAMELISTBOX_EMPTY "observe"}
|
||||
{GAMELISTBOX_HEADER_LABEL "join" "Join"}
|
||||
[/row]
|
||||
[/grid]
|
||||
[/column]
|
||||
{GAMELISTBOX_HEADER_LABEL "join" "Join"}
|
||||
[/row]
|
||||
[/header]
|
||||
[list_definition]
|
||||
|
@ -113,14 +113,14 @@
|
|||
[row]
|
||||
{GAMELISTBOX_BODY_LABEL "name" "Name"}
|
||||
{GAMELISTBOX_BODY_LABEL "map" "Map"}
|
||||
{GAMELISTBOX_BODY_LABEL "era" "Era"}
|
||||
{GAMELISTBOX_BODY_LABEL "slots" "Slots"}
|
||||
[/row]
|
||||
[/grid]
|
||||
{VERTICAL_SEP}
|
||||
[grid]
|
||||
[row]
|
||||
{GAMELISTBOX_BODY_LABEL "map_info" "Map info"}
|
||||
{GAMELISTBOX_BODY_LABEL "slots" "Slots"}
|
||||
{GAMELISTBOX_BODY_LABEL "era" "Era"}
|
||||
{GAMELISTBOX_BODY_LABEL "options" "Options"}
|
||||
[/row]
|
||||
[/grid]
|
||||
|
@ -265,6 +265,18 @@
|
|||
definition = "default"
|
||||
label = _ "Refresh"
|
||||
[/button]
|
||||
{VERTICAL_SEP}
|
||||
[button]
|
||||
id = "join_global"
|
||||
definition = "default"
|
||||
label = _ "Join"
|
||||
[/button]
|
||||
{VERTICAL_SEP}
|
||||
[button]
|
||||
id = "observe_global"
|
||||
definition = "default"
|
||||
label = _ "Observe"
|
||||
[/button]
|
||||
{VERTICAL_SEP}
|
||||
[button]
|
||||
id = "create"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "log.hpp"
|
||||
#include "network.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
||||
#include "playmp_controller.hpp"
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
static lg::log_domain log_network("network");
|
||||
|
@ -69,11 +69,12 @@ void tlobby_main::add_chat_message(const time_t& /*time*/, const std::string& sp
|
|||
window_->invalidate_layout();
|
||||
}
|
||||
|
||||
tlobby_main::tlobby_main(const config& game_config)
|
||||
: game_config_(game_config)
|
||||
tlobby_main::tlobby_main(const config& game_config, lobby_info& info)
|
||||
: legacy_result_(QUIT)
|
||||
, game_config_(game_config)
|
||||
, gamelistbox_(NULL), chat_log_(NULL)
|
||||
, chat_input_(NULL), window_(NULL)
|
||||
, lobby_info_(new lobby_info(game_config))
|
||||
, lobby_info_(info)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -100,7 +101,7 @@ void add_label_data(std::map<std::string, string_map>& map,
|
|||
|
||||
void tlobby_main::update_gamelist()
|
||||
{
|
||||
foreach (const game_info &game, lobby_info_->games())
|
||||
foreach (const game_info &game, lobby_info_.games())
|
||||
{
|
||||
std::map<std::string, string_map> data;
|
||||
|
||||
|
@ -128,7 +129,7 @@ void tlobby_main::update_gamelist()
|
|||
observe_button->set_callback_mouse_left_click(
|
||||
dialog_callback<tlobby_main, &tlobby_main::observe_button_callback>);
|
||||
}
|
||||
foreach (const user_info& user, lobby_info_->users())
|
||||
foreach (const user_info& user, lobby_info_.users())
|
||||
{
|
||||
std::map<std::string, string_map> data;
|
||||
add_label_data(data, "player", user.name);
|
||||
|
@ -151,13 +152,16 @@ void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
|
|||
window.set_event_loop_pre_callback(boost::bind(&tlobby_main::network_handler, this));
|
||||
window_ = &window;
|
||||
|
||||
tbutton* send_message = dynamic_cast<tbutton*>(window.find_widget("send_message", false));
|
||||
VALIDATE(send_message, missing_widget("send_message"));
|
||||
send_message->set_callback_mouse_left_click(dialog_callback<tlobby_main,
|
||||
&tlobby_main::send_message_button_callback>);
|
||||
|
||||
chat_input_ = dynamic_cast<ttext_box*>(window.find_widget("chat_input", false));
|
||||
VALIDATE(chat_input_, missing_widget("chat_input"));
|
||||
|
||||
GUI2_EASY_BUTTON_CALLBACK(send_message, tlobby_main);
|
||||
GUI2_EASY_BUTTON_CALLBACK(create, tlobby_main);
|
||||
GUI2_EASY_BUTTON_CALLBACK(show_help, tlobby_main);
|
||||
GUI2_EASY_BUTTON_CALLBACK(refresh, tlobby_main);
|
||||
GUI2_EASY_BUTTON_CALLBACK(settings, tlobby_main);
|
||||
GUI2_EASY_BUTTON_CALLBACK(join_global, tlobby_main);
|
||||
GUI2_EASY_BUTTON_CALLBACK(observe_global, tlobby_main);
|
||||
}
|
||||
|
||||
void tlobby_main::post_show(twindow& /*window*/)
|
||||
|
@ -213,13 +217,13 @@ void tlobby_main::process_message(const config &data, bool /*whisper / *= false*
|
|||
|
||||
void tlobby_main::process_gamelist(const config &data)
|
||||
{
|
||||
lobby_info_->process_gamelist(data);
|
||||
lobby_info_.process_gamelist(data);
|
||||
update_gamelist();
|
||||
}
|
||||
|
||||
void tlobby_main::process_gamelist_diff(const config &data)
|
||||
{
|
||||
if (lobby_info_->process_gamelist_diff(data)) {
|
||||
if (lobby_info_.process_gamelist_diff(data)) {
|
||||
update_gamelist();
|
||||
}
|
||||
}
|
||||
|
@ -236,14 +240,66 @@ void tlobby_main::process_room_query_response(const config &/*data*/)
|
|||
{
|
||||
}
|
||||
|
||||
void tlobby_main::join_button_callback(gui2::twindow &/*window*/)
|
||||
void tlobby_main::join_button_callback(gui2::twindow &window)
|
||||
{
|
||||
LOG_NW << "join_button_callback\n";
|
||||
join_global_button_callback(window);
|
||||
}
|
||||
|
||||
void tlobby_main::observe_button_callback(gui2::twindow &/*window*/)
|
||||
void tlobby_main::observe_button_callback(gui2::twindow &window)
|
||||
{
|
||||
LOG_NW << "observe_button_callback\n";
|
||||
observe_global_button_callback(window);
|
||||
}
|
||||
|
||||
void tlobby_main::observe_global_button_callback(gui2::twindow &window)
|
||||
{
|
||||
LOG_NW << "observe_global_button_callback\n";
|
||||
do_game_join(gamelistbox_->get_selected_row(), true);
|
||||
legacy_result_ = OBSERVE;
|
||||
window.close();
|
||||
}
|
||||
|
||||
void tlobby_main::join_global_button_callback(gui2::twindow &window)
|
||||
{
|
||||
LOG_NW << "join_global_button_callback\n";
|
||||
do_game_join(gamelistbox_->get_selected_row(), false);
|
||||
legacy_result_ = JOIN;
|
||||
window.close();
|
||||
}
|
||||
|
||||
bool tlobby_main::do_game_join(int idx, bool observe)
|
||||
{
|
||||
if (idx < 0 || idx > static_cast<int>(lobby_info_.games().size())) {
|
||||
ERR_NG << "Requested join/observe of a game with index out of range: "
|
||||
<< idx << ", games size is " << lobby_info_.games().size() << "\n";
|
||||
return false;
|
||||
}
|
||||
const game_info& game = lobby_info_.games()[idx];
|
||||
|
||||
config response;
|
||||
config& join = response.add_child("join");
|
||||
join["id"] = game.id;
|
||||
join["observe"] = observe ? "yes" : "no";
|
||||
if (join && game.password_required) {
|
||||
std::string password;
|
||||
/*
|
||||
const int res = gui::show_dialog(disp_, NULL, _("Password Required"),
|
||||
_("Joining this game requires a password."),
|
||||
gui::OK_CANCEL, NULL, NULL, _("Password: "), &password);
|
||||
if (res != 0) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
if(!password.empty()) {
|
||||
join["password"] = password;
|
||||
}
|
||||
}
|
||||
network::send_data(response, 0, true);
|
||||
if (observe && game.started) {
|
||||
playmp_controller::set_replay_last_turn(game.current_turn);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void tlobby_main::send_message_button_callback(gui2::twindow &/*window*/)
|
||||
|
@ -254,4 +310,26 @@ void tlobby_main::send_message_button_callback(gui2::twindow &/*window*/)
|
|||
chat_input_->set_value("");
|
||||
}
|
||||
|
||||
void tlobby_main::create_button_callback(gui2::twindow& window)
|
||||
{
|
||||
legacy_result_ = CREATE;
|
||||
window.close();
|
||||
}
|
||||
|
||||
void tlobby_main::refresh_button_callback(gui2::twindow& /*window*/)
|
||||
{
|
||||
network::send_data(config("refresh_lobby"), 0, true);
|
||||
}
|
||||
|
||||
|
||||
void tlobby_main::settings_button_callback(gui2::twindow& window)
|
||||
{
|
||||
legacy_result_ = PREFERENCES;
|
||||
window.close();
|
||||
}
|
||||
|
||||
void tlobby_main::show_help_button_callback(gui2::twindow& /*window*/)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "config.hpp"
|
||||
#include "chat_events.hpp"
|
||||
#include "lobby_data.hpp"
|
||||
|
||||
#include "boost/scoped_ptr.hpp"
|
||||
|
||||
class lobby_info;
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
|
@ -33,17 +33,23 @@ class twindow;
|
|||
class tlobby_main : public tdialog, private events::chat_handler
|
||||
{
|
||||
public:
|
||||
tlobby_main(const config& game_config);
|
||||
tlobby_main(const config& game_config, lobby_info& info);
|
||||
|
||||
~tlobby_main();
|
||||
|
||||
void update_gamelist();
|
||||
|
||||
enum legacy_result { QUIT, JOIN, OBSERVE, CREATE, PREFERENCES };
|
||||
|
||||
legacy_result get_legacy_result() const { return legacy_result_; }
|
||||
protected:
|
||||
void send_chat_message(const std::string& message, bool /*allies_only*/);
|
||||
void add_chat_message(const time_t& time, const std::string& speaker,
|
||||
int side, const std::string& message,
|
||||
events::chat_handler::MESSAGE_TYPE type = events::chat_handler::MESSAGE_PRIVATE);
|
||||
private:
|
||||
legacy_result legacy_result_;
|
||||
|
||||
/**
|
||||
* Network polling callback
|
||||
*/
|
||||
|
@ -67,8 +73,29 @@ private:
|
|||
|
||||
void observe_button_callback(twindow& window);
|
||||
|
||||
void join_global_button_callback(twindow& window);
|
||||
|
||||
void observe_global_button_callback(twindow& window);
|
||||
|
||||
/**
|
||||
* Assemble and send a game join request. Ask for password if the game
|
||||
* requires one.
|
||||
* @return true iif the request was actually sent, false if not for some
|
||||
* reason like user canceled the password dialog or idx was invalid.
|
||||
*/
|
||||
bool do_game_join(int idx, bool observe);
|
||||
|
||||
void send_message_button_callback(twindow& window);
|
||||
|
||||
void create_button_callback(twindow& window);
|
||||
|
||||
void settings_button_callback(twindow& window);
|
||||
|
||||
void show_help_button_callback(twindow& window);
|
||||
|
||||
void refresh_button_callback(twindow& window);
|
||||
|
||||
void quit_button_callback(twindow& window);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
twindow* build_window(CVideo& video);
|
||||
|
@ -91,7 +118,7 @@ private:
|
|||
|
||||
twindow* window_;
|
||||
|
||||
boost::scoped_ptr<lobby_info> lobby_info_;
|
||||
lobby_info& lobby_info_;
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -458,7 +458,7 @@ static void enter_connect_mode(game_display& disp, const config& game_config,
|
|||
|
||||
static void enter_create_mode(game_display& disp, const config& game_config, mp::chat& chat, config& gamelist, mp::controller default_controller, bool local_players_only)
|
||||
{
|
||||
if(gui2::new_widgets) {
|
||||
if (0 && gui2::new_widgets) {
|
||||
|
||||
gui2::tmp_create_game dlg(game_config);
|
||||
|
||||
|
@ -493,9 +493,30 @@ static void enter_create_mode(game_display& disp, const config& game_config, mp:
|
|||
static void enter_lobby_mode(game_display& disp, const config& game_config, mp::chat& chat, config& gamelist)
|
||||
{
|
||||
mp::ui::result res;
|
||||
lobby_info li(game_config);
|
||||
|
||||
while (true) {
|
||||
{
|
||||
if(gui2::new_widgets) {
|
||||
gui2::tlobby_main dlg(game_config, li);
|
||||
dlg.show(disp.video());
|
||||
//ugly kludge for launching other dialogs like the old lobby
|
||||
switch (dlg.get_legacy_result()) {
|
||||
case gui2::tlobby_main::CREATE:
|
||||
res = mp::ui::CREATE;
|
||||
break;
|
||||
case gui2::tlobby_main::PREFERENCES:
|
||||
res = mp::ui::PREFERENCES;
|
||||
break;
|
||||
case gui2::tlobby_main::JOIN:
|
||||
res = mp::ui::JOIN;
|
||||
break;
|
||||
case gui2::tlobby_main::OBSERVE:
|
||||
res = mp::ui::OBSERVE;
|
||||
break;
|
||||
default:
|
||||
res = mp::ui::QUIT;
|
||||
}
|
||||
} else {
|
||||
mp::lobby ui(disp, game_config, chat, gamelist);
|
||||
run_lobby_loop(disp, ui);
|
||||
res = ui.get_result();
|
||||
|
@ -576,12 +597,7 @@ void start_client(game_display& disp, const config& game_config,
|
|||
|
||||
switch(type) {
|
||||
case WESNOTHD_SERVER:
|
||||
if(gui2::new_widgets) {
|
||||
gui2::tlobby_main dlg(game_config);
|
||||
dlg.show(disp.video());
|
||||
} else {
|
||||
enter_lobby_mode(disp, game_config, chat, gamelist);
|
||||
}
|
||||
enter_lobby_mode(disp, game_config, chat, gamelist);
|
||||
break;
|
||||
case SIMPLE_SERVER:
|
||||
playmp_controller::set_replay_last_turn(0);
|
||||
|
|
Loading…
Add table
Reference in a new issue