MP Lobby / Create: Yield to plugins

This commit is contained in:
Celtic Minstrel 2016-08-24 16:24:30 -04:00
parent 7084eee8a7
commit a0350198c3
7 changed files with 56 additions and 9 deletions

View file

@ -1527,6 +1527,7 @@
911F2DAF1BA086FA00E3102E /* alpha.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alpha.hpp; sourceTree = "<group>"; };
911F2DB11BA0870E00E3102E /* compat.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = compat.hpp; sourceTree = "<group>"; };
911F471B1CAE5A7E00F47035 /* iterable_pair.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = iterable_pair.hpp; sourceTree = "<group>"; };
91222E9C1D6E2D2900001AF2 /* plugin_executor.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = plugin_executor.hpp; sourceTree = "<group>"; };
9122417A1CAAB7B7008B347F /* loadscreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = loadscreen.cpp; sourceTree = "<group>"; };
9122417B1CAAB7B7008B347F /* loadscreen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = loadscreen.hpp; sourceTree = "<group>"; };
91273E721C7BF1C0005E7F81 /* _main.cfg */ = {isa = PBXFileReference; lastKnownFileType = text; path = _main.cfg; sourceTree = "<group>"; };
@ -3759,6 +3760,7 @@
F40C04841706613100B4DA68 /* mp_login.hpp */,
B5A9BCC70ECA805A002BE442 /* mp_method_selection.cpp */,
B5A9BCC80ECA805A002BE442 /* mp_method_selection.hpp */,
91222E9C1D6E2D2900001AF2 /* plugin_executor.hpp */,
919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */,
919B37FB1BAF7A9D00E0094C /* synced_choice_wait.hpp */,
);

View file

@ -72,12 +72,5 @@ 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

@ -1007,6 +1007,7 @@ void tlobby_main::post_show(twindow& /*window*/)
window_ = nullptr;
remove_timer(lobby_update_timer_);
lobby_update_timer_ = 0;
plugins_context_.reset();
}
room_info* tlobby_main::active_window_room()

View file

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

View file

@ -861,6 +861,7 @@ void tmp_create_game::dialog_exit_hook(twindow& window) {
void tmp_create_game::post_show(twindow& window)
{
plugins_context_.reset();
// Show all tabs so that find_widget works correctly
find_widget<tstacked_widget>(&window, "pager", false).select_layer(-1);
if(get_retval() == twindow::OK) {

View file

@ -16,6 +16,7 @@
#define GUI_DIALOGS_MP_CREATE_GAME_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "gui/dialogs/multiplayer/plugin_executor.hpp"
#include "game_initialization/create_engine.hpp"
#include "game_initialization/configure_engine.hpp"
@ -32,7 +33,7 @@ class ttoggle_panel;
class ttree_view;
class twidget;
class tmp_create_game : public tdialog, private mp::gui2_mp_shared_context
class tmp_create_game : public tdialog, private plugin_executor
{
typedef std::pair<ng::level::TYPE, std::string> level_type_info;

View file

@ -0,0 +1,48 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_MP_PLUGIN_EXECUTOR_HPP_INCLUDED
#define GUI_MP_PLUGIN_EXECUTOR_HPP_INCLUDED
#include "gui/core/timer.hpp"
#include "gui/widgets/window.hpp"
#include "scripting/plugins/context.hpp"
#include "game_config.hpp"
#include <memory>
namespace gui2 {
class plugin_executor
{
size_t timer_id;
void play_slice() {
if(plugins_context_) {
plugins_context_->play_slice();
}
}
protected:
std::unique_ptr<plugins_context> plugins_context_;
protected:
plugin_executor() {
timer_id = add_timer(game_config::lobby_network_timer, std::bind(&plugin_executor::play_slice, this), true);
}
~plugin_executor() {
remove_timer(timer_id);
}
};
}
#endif