Move some dialogs to a more appropriate namespace and module.
This commit is contained in:
parent
e5df2e4b3c
commit
b5a82e4ac8
8 changed files with 149 additions and 145 deletions
134
src/dialogs.cpp
134
src/dialogs.cpp
|
@ -30,6 +30,7 @@
|
|||
#include "minimap.hpp"
|
||||
#include "replay.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "thread.hpp"
|
||||
#include "util.hpp"
|
||||
#include "video.hpp"
|
||||
#include "wassert.hpp"
|
||||
|
@ -893,4 +894,137 @@ void campaign_preview_pane::draw_contents()
|
|||
}
|
||||
}
|
||||
|
||||
network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))
|
||||
{
|
||||
#ifdef USE_TINY_GUI
|
||||
const size_t width = 200;
|
||||
const size_t height = 40;
|
||||
const size_t border = 10;
|
||||
#else
|
||||
const size_t width = 300;
|
||||
const size_t height = 80;
|
||||
const size_t border = 20;
|
||||
#endif
|
||||
const int left = disp.w()/2 - width/2;
|
||||
const int top = disp.h()/2 - height/2;
|
||||
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
gui::button cancel_button(disp.video(),_("Cancel"));
|
||||
std::vector<gui::button*> buttons_ptr(1,&cancel_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
|
||||
frame.layout(left,top,width,height);
|
||||
frame.draw();
|
||||
|
||||
const SDL_Rect progress_rect = {left+border,top+border,width-border*2,height-border*2};
|
||||
gui::progress_bar progress(disp.video());
|
||||
progress.set_location(progress_rect);
|
||||
|
||||
events::raise_draw_event();
|
||||
disp.flip();
|
||||
|
||||
network::statistics old_stats = get_stats(connection_num);
|
||||
|
||||
cfg.clear();
|
||||
for(;;) {
|
||||
const network::connection res = network::receive_data(cfg,connection_num,100);
|
||||
const network::statistics stats = get_stats(connection_num);
|
||||
if(stats.current_max != 0 && stats != old_stats) {
|
||||
old_stats = stats;
|
||||
progress.set_progress_percent((stats.current*100)/stats.current_max);
|
||||
std::ostringstream stream;
|
||||
stream << stats.current/1024 << "/" << stats.current_max/1024 << _("KB");
|
||||
progress.set_text(stream.str());
|
||||
}
|
||||
|
||||
events::raise_draw_event();
|
||||
disp.flip();
|
||||
|
||||
if(res != 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
events::pump();
|
||||
if(cancel_button.pressed()) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
network::get_send_stats);
|
||||
}
|
||||
|
||||
network::connection network_receive_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num)
|
||||
{
|
||||
return network_data_dialog(disp, msg, cfg, connection_num,
|
||||
network::get_receive_stats);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class connect_waiter : public threading::waiter
|
||||
{
|
||||
public:
|
||||
connect_waiter(display& disp, gui::button& button) : disp_(disp), button_(button)
|
||||
{}
|
||||
ACTION process();
|
||||
|
||||
private:
|
||||
display& disp_;
|
||||
gui::button& button_;
|
||||
};
|
||||
|
||||
connect_waiter::ACTION connect_waiter::process()
|
||||
{
|
||||
events::raise_draw_event();
|
||||
disp_.flip();
|
||||
events::pump();
|
||||
if(button_.pressed()) {
|
||||
return ABORT;
|
||||
} else {
|
||||
return WAIT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace dialogs
|
||||
{
|
||||
|
||||
network::connection network_connect_dialog(display& disp, const std::string& msg, const std::string& hostname, int port)
|
||||
{
|
||||
#ifdef USE_TINY_GUI
|
||||
const size_t width = 200;
|
||||
const size_t height = 20;
|
||||
#else
|
||||
const size_t width = 250;
|
||||
const size_t height = 20;
|
||||
#endif
|
||||
const int left = disp.w()/2 - width/2;
|
||||
const int top = disp.h()/2 - height/2;
|
||||
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
gui::button cancel_button(disp.video(),_("Cancel"));
|
||||
std::vector<gui::button*> buttons_ptr(1,&cancel_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
|
||||
frame.layout(left,top,width,height);
|
||||
frame.draw();
|
||||
|
||||
events::raise_draw_event();
|
||||
disp.flip();
|
||||
|
||||
connect_waiter waiter(disp,cancel_button);
|
||||
return network::connect(hostname,port,waiter);
|
||||
}
|
||||
|
||||
} //end namespace dialogs
|
||||
|
|
|
@ -101,6 +101,10 @@ private:
|
|||
int index_;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
} //end namespace dialogs
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1022,7 +1022,7 @@ void game_controller::download_campaigns(std::string host)
|
|||
|
||||
try {
|
||||
const network::manager net_manager;
|
||||
const network::connection sock = gui::network_connect_dialog(disp(), _("Connecting to Server..."),
|
||||
const network::connection sock = dialogs::network_connect_dialog(disp(), _("Connecting to Server..."),
|
||||
items.front(), lexical_cast_default<int>(items.back(),15003) );
|
||||
if(!sock) {
|
||||
gui::show_error_message(disp(), _("Could not connect to host."));
|
||||
|
@ -1034,7 +1034,7 @@ void game_controller::download_campaigns(std::string host)
|
|||
cfg.add_child("request_campaign_list");
|
||||
network::send_data(cfg,sock);
|
||||
|
||||
network::connection res = gui::network_receive_dialog(disp(),_("Asking for list of add-ons"),cfg,sock);
|
||||
network::connection res = dialogs::network_receive_dialog(disp(),_("Asking for list of add-ons"),cfg,sock);
|
||||
if(!res) {
|
||||
return;
|
||||
}
|
||||
|
@ -1187,7 +1187,7 @@ void game_controller::download_campaigns(std::string host)
|
|||
request.add_child("request_campaign")["name"] = campaigns[index];
|
||||
network::send_data(request,sock);
|
||||
|
||||
res = gui::network_receive_dialog(disp(),_("Downloading add-on..."),cfg,sock);
|
||||
res = dialogs::network_receive_dialog(disp(),_("Downloading add-on..."),cfg,sock);
|
||||
if(!res) {
|
||||
return;
|
||||
}
|
||||
|
@ -1301,7 +1301,7 @@ void game_controller::upload_campaign(const std::string& campaign, network::conn
|
|||
std::cerr << "uploading campaign...\n";
|
||||
network::send_data(data,sock);
|
||||
|
||||
sock = gui::network_send_dialog(disp(),_("Sending add-on"),data,sock);
|
||||
sock = dialogs::network_send_dialog(disp(),_("Sending add-on"),data,sock);
|
||||
if(!sock) {
|
||||
gui::show_error_message(disp(), _("Connection timed out"));
|
||||
} else if(data.child("error")) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include "construct_dialog.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -163,7 +164,7 @@ static server_type open_connection(game_display& disp, const std::string& origin
|
|||
|
||||
config::child_list redirects;
|
||||
config data;
|
||||
sock = gui::network_connect_dialog(disp,_("Connecting to Server..."),host,port);
|
||||
sock = dialogs::network_connect_dialog(disp,_("Connecting to Server..."),host,port);
|
||||
|
||||
do {
|
||||
|
||||
|
@ -172,7 +173,7 @@ static server_type open_connection(game_display& disp, const std::string& origin
|
|||
}
|
||||
|
||||
data.clear();
|
||||
network::connection data_res = gui::network_receive_dialog(
|
||||
network::connection data_res = dialogs::network_receive_dialog(
|
||||
disp,_("Reading from Server..."),data);
|
||||
mp::check_response(data_res, data);
|
||||
|
||||
|
@ -200,7 +201,7 @@ static server_type open_connection(game_display& disp, const std::string& origin
|
|||
|
||||
if(network::nconnections() > 0)
|
||||
network::disconnect();
|
||||
sock = gui::network_connect_dialog(disp,_("Connecting to Server..."),host,port);
|
||||
sock = dialogs::network_connect_dialog(disp,_("Connecting to Server..."),host,port);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include "basic_dialog.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_events.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
@ -181,7 +182,7 @@ void wait::process_event()
|
|||
void wait::join_game(bool observe)
|
||||
{
|
||||
for(;;) {
|
||||
network::connection data_res = gui::network_receive_dialog(disp(),
|
||||
network::connection data_res = dialogs::network_receive_dialog(disp(),
|
||||
_("Getting game data..."), level_);
|
||||
check_response(data_res, level_);
|
||||
|
||||
|
|
|
@ -366,7 +366,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
|
|||
|
||||
do {
|
||||
cfg.clear();
|
||||
network::connection data_res = gui::network_receive_dialog(disp,
|
||||
network::connection data_res = dialogs::network_receive_dialog(disp,
|
||||
msg, cfg);
|
||||
if(!data_res)
|
||||
throw network::error(_("Connection timed out"));
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "key.hpp"
|
||||
#include "log.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "thread.hpp"
|
||||
#include "language.hpp"
|
||||
#include "sdl_utils.hpp"
|
||||
#include "tooltips.hpp"
|
||||
|
@ -421,134 +420,3 @@ int show_dialog(display& screen, surface image,
|
|||
|
||||
}
|
||||
|
||||
namespace gui {
|
||||
|
||||
network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))
|
||||
{
|
||||
#ifdef USE_TINY_GUI
|
||||
const size_t width = 200;
|
||||
const size_t height = 40;
|
||||
const size_t border = 10;
|
||||
#else
|
||||
const size_t width = 300;
|
||||
const size_t height = 80;
|
||||
const size_t border = 20;
|
||||
#endif
|
||||
const int left = disp.w()/2 - width/2;
|
||||
const int top = disp.h()/2 - height/2;
|
||||
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
gui::button cancel_button(disp.video(),_("Cancel"));
|
||||
std::vector<gui::button*> buttons_ptr(1,&cancel_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
|
||||
frame.layout(left,top,width,height);
|
||||
frame.draw();
|
||||
|
||||
const SDL_Rect progress_rect = {left+border,top+border,width-border*2,height-border*2};
|
||||
gui::progress_bar progress(disp.video());
|
||||
progress.set_location(progress_rect);
|
||||
|
||||
events::raise_draw_event();
|
||||
disp.flip();
|
||||
|
||||
network::statistics old_stats = get_stats(connection_num);
|
||||
|
||||
cfg.clear();
|
||||
for(;;) {
|
||||
const network::connection res = network::receive_data(cfg,connection_num,100);
|
||||
const network::statistics stats = get_stats(connection_num);
|
||||
if(stats.current_max != 0 && stats != old_stats) {
|
||||
old_stats = stats;
|
||||
progress.set_progress_percent((stats.current*100)/stats.current_max);
|
||||
std::ostringstream stream;
|
||||
stream << stats.current/1024 << "/" << stats.current_max/1024 << _("KB");
|
||||
progress.set_text(stream.str());
|
||||
}
|
||||
|
||||
events::raise_draw_event();
|
||||
disp.flip();
|
||||
|
||||
if(res != 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
events::pump();
|
||||
if(cancel_button.pressed()) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
network::get_send_stats);
|
||||
}
|
||||
|
||||
network::connection network_receive_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num)
|
||||
{
|
||||
return network_data_dialog(disp, msg, cfg, connection_num,
|
||||
network::get_receive_stats);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class connect_waiter : public threading::waiter
|
||||
{
|
||||
public:
|
||||
connect_waiter(display& disp, gui::button& button) : disp_(disp), button_(button)
|
||||
{}
|
||||
ACTION process();
|
||||
|
||||
private:
|
||||
display& disp_;
|
||||
gui::button& button_;
|
||||
};
|
||||
|
||||
connect_waiter::ACTION connect_waiter::process()
|
||||
{
|
||||
events::raise_draw_event();
|
||||
disp_.flip();
|
||||
events::pump();
|
||||
if(button_.pressed()) {
|
||||
return ABORT;
|
||||
} else {
|
||||
return WAIT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
network::connection network_connect_dialog(display& disp, const std::string& msg, const std::string& hostname, int port)
|
||||
{
|
||||
#ifdef USE_TINY_GUI
|
||||
const size_t width = 200;
|
||||
const size_t height = 20;
|
||||
#else
|
||||
const size_t width = 250;
|
||||
const size_t height = 20;
|
||||
#endif
|
||||
const int left = disp.w()/2 - width/2;
|
||||
const int top = disp.h()/2 - height/2;
|
||||
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
gui::button cancel_button(disp.video(),_("Cancel"));
|
||||
std::vector<gui::button*> buttons_ptr(1,&cancel_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
|
||||
frame.layout(left,top,width,height);
|
||||
frame.draw();
|
||||
|
||||
events::raise_draw_event();
|
||||
disp.flip();
|
||||
|
||||
connect_waiter waiter(disp,cancel_button);
|
||||
return network::connect(hostname,port,waiter);
|
||||
}
|
||||
|
||||
} //end namespace gui
|
||||
|
|
|
@ -183,10 +183,6 @@ int show_dialog(display &screen, surface image,
|
|||
|
||||
void show_error_message(display &disp, std::string const &message);
|
||||
|
||||
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);
|
||||
|
||||
void check_quit(CVideo &video);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue