Mp Lobby: set up plugins context

This commit is contained in:
Charles Dang 2016-08-24 14:59:25 +11:00
parent 8699ad0a05
commit fbfabfba50
5 changed files with 27 additions and 6 deletions

View file

@ -18,6 +18,7 @@
#include "mp_game_settings.hpp"
#include "connect_engine.hpp"
#include "multiplayer_ui.hpp"
#include "scripting/plugins/context.hpp"
class config;
class CVideo;
@ -71,5 +72,12 @@ mp::ui::result goto_mp_connect(CVideo& video, ng::connect_engine& engine,
*/
mp::ui::result goto_mp_wait(CVideo& video, saved_game& state, const config& game_config, twesnothd_connection* wesnothd_connection, bool observe);
// TODO: move to own file?
class gui2_mp_shared_context
{
public:
std::unique_ptr<plugins_context> plugins_context_;
};
}
#endif

View file

@ -976,6 +976,21 @@ void tlobby_main::pre_show(twindow& window)
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, &window](const config&) { join_global_button_callback(window); }, true);
plugins_context_->set_callback("observe", [this, &window](const config&) { observe_global_button_callback(window); }, true);
plugins_context_->set_callback("create", [this, &window](const config&) { create_button_callback(window); }, true);
plugins_context_->set_callback("quit", [&window](const config&) { window.set_retval(twindow::CANCEL); }, false);
plugins_context_->set_callback("chat", [this](const config& cfg) { send_chat_message(cfg["message"], false); }, true);
// TODO: gui1 version allowed specifying by id, should we support this?
plugins_context_->set_callback("select_game", [this](const config& cfg) { gamelistbox_->select_row(cfg["index"].to_int()); }, 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_; });
}
void tlobby_main::post_show(twindow& /*window*/)

View file

@ -19,6 +19,7 @@
#include "gui/widgets/tree_view.hpp"
#include "chat_events.hpp"
#include "gui/dialogs/lobby/info.hpp"
#include "game_initialization/multiplayer.hpp"
class display;
@ -74,7 +75,7 @@ struct tplayer_list
ttree_view* tree;
};
class tlobby_main : public tdialog, private events::chat_handler
class tlobby_main : public tdialog, private events::chat_handler, private mp::gui2_mp_shared_context
{
public:
tlobby_main(const config& game_config, lobby_info& info, twesnothd_connection &wesnothd_connection);

View file

@ -82,7 +82,6 @@ tmp_create_game::tmp_create_game(const config& cfg, ng::create_engine& create_en
, turn_bonus_(register_integer("turn_bonus", true, prefs::countdown_turn_bonus, prefs::set_countdown_turn_bonus))
, reservior_(register_integer("reservior", true, prefs::countdown_reservoir_time, prefs::set_countdown_reservoir_time))
, action_bonus_(register_integer("action_bonus", true, prefs::countdown_action_bonus, prefs::set_countdown_action_bonus))
, plugins_context_()
{
level_types_ = {
{ng::level::TYPE::SCENARIO, _("Scenarios")},

View file

@ -19,8 +19,8 @@
#include "game_initialization/create_engine.hpp"
#include "game_initialization/configure_engine.hpp"
#include "game_initialization/multiplayer.hpp"
#include "mp_game_settings.hpp"
#include "scripting/plugins/context.hpp"
class config;
@ -32,7 +32,7 @@ class ttoggle_panel;
class ttree_view;
class twidget;
class tmp_create_game : public tdialog
class tmp_create_game : public tdialog, private mp::gui2_mp_shared_context
{
typedef std::pair<ng::level::TYPE, std::string> level_type_info;
@ -125,8 +125,6 @@ private:
tfield_integer* reservior_;
tfield_integer* action_bonus_;
std::unique_ptr<plugins_context> plugins_context_;
template<typename widget>
void on_filter_change(twindow& window, const std::string& id);