Skip to content

Commit

Permalink
remove display dependency from mp connect code.
Browse files Browse the repository at this point in the history
and from codes that are used by it, specially the loadgame and the
networkrecieve dialog.
  • Loading branch information
gfgtdf committed Jan 12, 2016
1 parent a96ca1e commit 93c53df
Show file tree
Hide file tree
Showing 32 changed files with 252 additions and 252 deletions.
46 changes: 23 additions & 23 deletions src/dialogs.cpp
Expand Up @@ -1150,23 +1150,23 @@ void unit_types_preview_pane::process_event()
}
}

static network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))
static network::connection network_data_dialog(CVideo& video, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))
{
const size_t width = 300;
const size_t height = 80;
const size_t border = 20;
const int left = disp.w()/2 - width/2;
const int top = disp.h()/2 - height/2;
const int left = video.getx()/2 - width/2;
const int top = video.gety()/2 - height/2;

const events::event_context dialog_events_context;

gui::button cancel_button(disp.video(),_("Cancel"));
gui::button cancel_button(video, _("Cancel"));
std::vector<gui::button*> buttons_ptr(1,&cancel_button);

gui::dialog_frame frame(disp.video(), msg, gui::dialog_frame::default_style, true, &buttons_ptr);
gui::dialog_frame frame(video, msg, gui::dialog_frame::default_style, true, &buttons_ptr);
SDL_Rect centered_layout = frame.layout(left,top,width,height).interior;
centered_layout.x = disp.w() / 2 - centered_layout.w / 2;
centered_layout.y = disp.h() / 2 - centered_layout.h / 2;
centered_layout.x = video.getx() / 2 - centered_layout.w / 2;
centered_layout.y = video.gety() / 2 - centered_layout.h / 2;
// HACK: otherwise we get an empty useless space in the dialog below the progressbar
centered_layout.h = height;
frame.layout(centered_layout);
Expand All @@ -1177,11 +1177,11 @@ static network::connection network_data_dialog(display& disp, const std::string&
, centered_layout.w - border * 2
, centered_layout.h - border * 2);

gui::progress_bar progress(disp.video());
gui::progress_bar progress(video);
progress.set_location(progress_rect);

events::raise_draw_event();
disp.video().flip();
video.flip();

network::statistics old_stats = get_stats(connection_num);

Expand All @@ -1198,7 +1198,7 @@ static network::connection network_data_dialog(display& disp, const std::string&
}

events::raise_draw_event();
disp.video().flip();
video.flip();
events::pump();

if(res != 0) {
Expand All @@ -1214,13 +1214,13 @@ static network::connection network_data_dialog(display& disp, const std::string&

network::connection network_send_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num)
{
return network_data_dialog(disp, msg, cfg, connection_num,
return network_data_dialog(disp.video(), msg, cfg, connection_num,
network::get_send_stats);
}

network::connection network_receive_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num)
network::connection network_receive_dialog(CVideo& v, const std::string& msg, config& cfg, network::connection connection_num)
{
return network_data_dialog(disp, msg, cfg, connection_num,
return network_data_dialog(v, msg, cfg, connection_num,
network::get_receive_stats);
}

Expand All @@ -1231,19 +1231,19 @@ namespace {
class connect_waiter : public threading::waiter
{
public:
connect_waiter(display& disp, gui::button& button) : disp_(disp), button_(button)
connect_waiter(CVideo& v, gui::button& button) : v_(v), button_(button)
{}
ACTION process();

private:
display& disp_;
CVideo& v_;
gui::button& button_;
};

connect_waiter::ACTION connect_waiter::process()
{
events::raise_draw_event();
disp_.video().flip();
v_.flip();
events::pump();
if(button_.pressed()) {
return ABORT;
Expand All @@ -1257,26 +1257,26 @@ connect_waiter::ACTION connect_waiter::process()
namespace dialogs
{

network::connection network_connect_dialog(display& disp, const std::string& msg, const std::string& hostname, int port)
network::connection network_connect_dialog(CVideo& v, const std::string& msg, const std::string& hostname, int port)
{
const size_t width = 250;
const size_t height = 20;
const int left = disp.w()/2 - width/2;
const int top = disp.h()/2 - height/2;
const int left = v.getx()/2 - width/2;
const int top = v.gety()/2 - height/2;

const events::event_context dialog_events_context;

gui::button cancel_button(disp.video(),_("Cancel"));
gui::button cancel_button(v,_("Cancel"));
std::vector<gui::button*> buttons_ptr(1,&cancel_button);

gui::dialog_frame frame(disp.video(), msg, gui::dialog_frame::default_style, true, &buttons_ptr);
gui::dialog_frame frame(v, msg, gui::dialog_frame::default_style, true, &buttons_ptr);
frame.layout(left,top,width,height);
frame.draw();

events::raise_draw_event();
disp.video().flip();
v.flip();

connect_waiter waiter(disp,cancel_button);
connect_waiter waiter(v,cancel_button);
return network::connect(hostname,port,waiter);
}

Expand Down
4 changes: 2 additions & 2 deletions src/dialogs.hpp
Expand Up @@ -138,8 +138,8 @@ class unit_types_preview_pane : public dialogs::unit_preview_pane
};

network::connection network_send_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num=0);
network::connection network_receive_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num=0);
network::connection network_connect_dialog(display& disp, const std::string& msg, const std::string& hostname, int port);
network::connection network_receive_dialog(CVideo& video, const std::string& msg, config& cfg, network::connection connection_num=0);
network::connection network_connect_dialog(CVideo& video, const std::string& msg, const std::string& hostname, int port);

} //end namespace dialogs

Expand Down
10 changes: 5 additions & 5 deletions src/game_initialization/create_engine.cpp
Expand Up @@ -17,7 +17,7 @@
#include "config_assign.hpp"
#include "game_config_manager.hpp"
#include "game_launcher.hpp"
#include "game_display.hpp"
#include "video.hpp"
#include "game_preferences.hpp"
#include "generators/map_generator.hpp"
#include "gui/dialogs/campaign_difficulty.hpp"
Expand Down Expand Up @@ -389,7 +389,7 @@ int campaign::max_players() const
return max_players_;
}

create_engine::create_engine(game_display& disp, saved_game& state) :
create_engine::create_engine(CVideo& v, saved_game& state) :
current_level_type_(),
current_level_index_(0),
current_era_index_(0),
Expand All @@ -407,7 +407,7 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
eras_(),
mods_(),
state_(state),
disp_(disp),
video_(v),
dependency_manager_(NULL),
generator_(NULL)
{
Expand All @@ -421,7 +421,7 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
state_.mp_settings().show_connect = connect;
game_config_manager::get()->load_game_config_for_create(type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
//Initilialize dependency_manager_ after refreshing game config.
dependency_manager_.reset(new depcheck::manager(game_config_manager::get()->game_config(), type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER, disp.video()));
dependency_manager_.reset(new depcheck::manager(game_config_manager::get()->game_config(), type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER, video_));
//TODO the editor dir is already configurable, is the preferences value
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/maps", &user_map_names_,
NULL, filesystem::FILE_NAME_ONLY);
Expand Down Expand Up @@ -619,7 +619,7 @@ std::string create_engine::select_campaign_difficulty(int set_value)
// We don't pass the difficulties vector here because additional data is required
// to constrict the dialog
gui2::tcampaign_difficulty dlg(current_level().data());
dlg.show(disp_.video());
dlg.show(video_);

return dlg.selected_difficulty();
}
Expand Down
8 changes: 4 additions & 4 deletions src/game_initialization/create_engine.hpp
Expand Up @@ -18,12 +18,12 @@
#include "make_enum.hpp"
#include "map.hpp"
#include "mp_game_settings.hpp"
#include "game_display.hpp"

#include "video.hpp"
#include <boost/scoped_ptr.hpp>
#include <string>
#include <utility>

class CVideo;
class saved_game;
class map_generator;
namespace ng {
Expand Down Expand Up @@ -178,7 +178,7 @@ class campaign : public level
class create_engine
{
public:
create_engine(game_display& disp, saved_game& state);
create_engine(CVideo& v, saved_game& state);
~create_engine();

enum MP_EXTRA { ERA, MOD };
Expand Down Expand Up @@ -302,7 +302,7 @@ class create_engine

saved_game& state_;

game_display& disp_;
CVideo& video_;
//Never NULL
boost::scoped_ptr<depcheck::manager> dependency_manager_;

Expand Down
22 changes: 11 additions & 11 deletions src/game_initialization/mp_options.cpp
Expand Up @@ -72,22 +72,22 @@ void manager::init_widgets()
continue;
}

widgets_ordered_.push_back(new title_display(display_.video(), comp.cfg["name"]));
widgets_ordered_.push_back(new title_display(video_, comp.cfg["name"]));
BOOST_FOREACH (const config::any_child& c, comp.cfg.all_children_range()) {
const std::string id = c.cfg["id"];
if (c.key == "slider") {
widgets_ordered_.push_back(new slider_display(display_.video(), c.cfg));
widgets_ordered_.push_back(new slider_display(video_, c.cfg));
} else if (c.key == "entry") {
widgets_ordered_.push_back(new entry_display(display_.video(), c.cfg));
widgets_ordered_.push_back(new entry_display(video_, c.cfg));
} else if (c.key == "checkbox") {
widgets_ordered_.push_back(new checkbox_display(display_.video(), c.cfg));
widgets_ordered_.push_back(new checkbox_display(video_, c.cfg));
} else if (c.key == "combo") {
widgets_ordered_.push_back(new combo_display(display_, c.cfg));
widgets_ordered_.push_back(new combo_display(video_, c.cfg));
}
widgets_ordered_.back()->set_value(get_stored_value(id));
widgets_[id] = widgets_ordered_.back();
}
widgets_ordered_.push_back(new reset_display(display_.video(), comp.cfg["id"], *this));
widgets_ordered_.push_back(new reset_display(video_, comp.cfg["id"], *this));
}
}

Expand All @@ -109,10 +109,10 @@ bool manager::has_options() const
return !widgets_.empty();
}

manager::manager(const config &gamecfg, game_display &display, gui::scrollpane *pane, const config &values)
manager::manager(const config &gamecfg, CVideo &video, gui::scrollpane *pane, const config &values)
: options_info_()
, values_(values)
, display_(display)
, video_(video)
, pane_(pane)
, era_()
, scenario_()
Expand Down Expand Up @@ -523,9 +523,9 @@ void title_display::hide_children(bool hide)
title_->hide(hide);
}

combo_display::combo_display(game_display &display, const config &cfg) :
label_(new gui::label(display.video(), cfg["name"])),
combo_(new gui::combo(display, std::vector<std::string>())),
combo_display::combo_display(CVideo &video, const config &cfg) :
label_(new gui::label(video, cfg["name"])),
combo_(new gui::combo(video, std::vector<std::string>())),
values_()
{
std::vector<std::string> items;
Expand Down
8 changes: 4 additions & 4 deletions src/game_initialization/mp_options.hpp
Expand Up @@ -18,7 +18,7 @@
#include <string>
#include "config.hpp"
#include "video.hpp"
#include "game_display.hpp"
#include "video.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window.hpp"
#include "widgets/scrollpane.hpp"
Expand Down Expand Up @@ -99,7 +99,7 @@ class checkbox_display : public option_display
class combo_display : public option_display
{
public:
combo_display(game_display& display, const config& cfg);
combo_display(CVideo& video, const config& cfg);
~combo_display();

void layout(int &xpos, int &ypos, int w, int border_size, gui::scrollpane *pane);
Expand Down Expand Up @@ -163,7 +163,7 @@ class manager
*
* @param initial_value The initial values for each option.
*/
manager(const config& gamecfg, game_display& display, gui::scrollpane* pane, const config& initial_value);
manager(const config& gamecfg, CVideo& video, gui::scrollpane* pane, const config& initial_value);

~manager();

Expand Down Expand Up @@ -232,7 +232,7 @@ class manager
config values_;

/** The screen to display the dialog on */
game_display &display_;
CVideo& video_;

/** The scrollarea to put the widgets on */
gui::scrollpane* pane_;
Expand Down

0 comments on commit 93c53df

Please sign in to comment.