Refactor titlescreen loop so that it redraws properly behind other dialogs
This commit is contained in:
parent
da437f74ca
commit
d0906ceac5
6 changed files with 222 additions and 299 deletions
|
@ -754,7 +754,7 @@ bool game_launcher::goto_multiplayer()
|
|||
{
|
||||
if(jump_to_multiplayer_){
|
||||
jump_to_multiplayer_ = false;
|
||||
if(play_multiplayer()){
|
||||
if(play_multiplayer(MP_CONNECT)){
|
||||
;
|
||||
}else{
|
||||
return false;
|
||||
|
@ -813,45 +813,13 @@ void game_launcher::start_wesnothd()
|
|||
throw game::mp_server_error("Starting MP server failed!");
|
||||
}
|
||||
|
||||
bool game_launcher::play_multiplayer()
|
||||
bool game_launcher::play_multiplayer(mp_selection res)
|
||||
{
|
||||
int res;
|
||||
|
||||
state_ = saved_game();
|
||||
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
|
||||
//Print Gui only if the user hasn't specified any server
|
||||
if( multiplayer_server_.empty() ){
|
||||
|
||||
int start_server;
|
||||
do {
|
||||
start_server = 0;
|
||||
|
||||
gui2::tmp_method_selection dlg;
|
||||
|
||||
dlg.show(video());
|
||||
|
||||
if(dlg.get_retval() == gui2::twindow::OK) {
|
||||
res = dlg.get_choice();
|
||||
} else {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (res == 2 && preferences::mp_server_warning_disabled() < 2) {
|
||||
start_server = !gui2::tmp_host_game_prompt::execute(video());
|
||||
}
|
||||
} while (start_server);
|
||||
if (res < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}else{
|
||||
res = 4;
|
||||
}
|
||||
|
||||
try {
|
||||
if (res == 2)
|
||||
if (res == MP_HOST)
|
||||
{
|
||||
try {
|
||||
start_wesnothd();
|
||||
|
@ -875,21 +843,13 @@ bool game_launcher::play_multiplayer()
|
|||
events::discard_input(); // prevent the "keylogger" effect
|
||||
cursor::set(cursor::NORMAL);
|
||||
|
||||
if(res == 3) {
|
||||
if(res == MP_LOCAL) {
|
||||
mp::start_local_game(video(),
|
||||
game_config_manager::get()->game_config(), state_);
|
||||
} else if((res >= 0 && res <= 2) || res == 4) {
|
||||
std::string host;
|
||||
if(res == 0) {
|
||||
host = preferences::server_list().front().address;
|
||||
}else if(res == 2) {
|
||||
host = "localhost";
|
||||
}else if(res == 4){
|
||||
host = multiplayer_server_;
|
||||
multiplayer_server_ = "";
|
||||
}
|
||||
} else {
|
||||
mp::start_client(video(), game_config_manager::get()->game_config(),
|
||||
state_, host);
|
||||
state_, multiplayer_server_);
|
||||
multiplayer_server_.clear();
|
||||
}
|
||||
|
||||
} catch(game::mp_server_error& e) {
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
|
||||
CVideo& video() { return *video_; }
|
||||
|
||||
enum mp_selection {MP_CONNECT, MP_HOST, MP_LOCAL};
|
||||
|
||||
bool init_video();
|
||||
bool init_language();
|
||||
bool init_joystick();
|
||||
|
@ -80,7 +82,8 @@ public:
|
|||
|
||||
bool jump_to_editor() const { return jump_to_editor_; }
|
||||
|
||||
bool play_multiplayer();
|
||||
void select_mp_server(std::string server) { multiplayer_server_ = server; }
|
||||
bool play_multiplayer(mp_selection res);
|
||||
bool play_multiplayer_commandline();
|
||||
bool change_language();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "gui/dialogs/title_screen.hpp"
|
||||
|
||||
#include "addon/manager_ui.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "game_config_manager.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
@ -28,6 +29,11 @@
|
|||
#include "gui/dialogs/game_version.hpp"
|
||||
#include "gui/dialogs/language_selection.hpp"
|
||||
#include "gui/dialogs/lua_interpreter.hpp"
|
||||
#include "game_config_manager.hpp"
|
||||
#include "gui/dialogs/core_selection.hpp"
|
||||
#include "gui/dialogs/multiplayer/mp_method_selection.hpp"
|
||||
#include "gui/dialogs/multiplayer/mp_host_game_prompt.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
//#define DEBUG_TOOLTIP
|
||||
#ifdef DEBUG_TOOLTIP
|
||||
#include "gui/dialogs/tip.hpp"
|
||||
|
@ -38,9 +44,11 @@
|
|||
#include "gui/widgets/multi_page.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "help/help.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
#include "utils/functional.hpp"
|
||||
#include "game_launcher.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -125,14 +133,13 @@ REGISTER_DIALOG(title_screen)
|
|||
|
||||
bool show_debug_clock_button = false;
|
||||
|
||||
static bool hotkey(twindow& window, const ttitle_screen::tresult result)
|
||||
void ttitle_screen::basic_callback(twindow& window, tresult res)
|
||||
{
|
||||
window.set_retval(static_cast<twindow::tretval>(result));
|
||||
|
||||
return true;
|
||||
result_ = res;
|
||||
window.close();
|
||||
}
|
||||
|
||||
ttitle_screen::ttitle_screen() : debug_clock_(nullptr)
|
||||
ttitle_screen::ttitle_screen(game_launcher& game) : result_(REDRAW_BACKGROUND), game_(game), debug_clock_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -141,11 +148,25 @@ ttitle_screen::~ttitle_screen()
|
|||
delete debug_clock_;
|
||||
}
|
||||
|
||||
using btn_callback = std::function<void(twindow&)>;
|
||||
|
||||
static void register_button(twindow& window, const std::string& id, hotkey::HOTKEY_COMMAND hk, btn_callback callback)
|
||||
{
|
||||
if(hk != hotkey::HOTKEY_NULL) {
|
||||
window.register_hotkey(hk, [callback](event::tdispatcher& win, hotkey::HOTKEY_COMMAND) {
|
||||
callback(dynamic_cast<twindow&>(win));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
event::connect_signal_mouse_left_click(find_widget<tbutton>(&window, id, false), [callback](event::tdispatcher& win, event::tevent, bool&, bool&) {
|
||||
callback(dynamic_cast<twindow&>(win));
|
||||
});
|
||||
}
|
||||
|
||||
static bool fullscreen(CVideo& video)
|
||||
{
|
||||
video.set_fullscreen(!preferences::fullscreen());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -157,75 +178,16 @@ static bool launch_lua_console(twindow & window)
|
|||
|
||||
void ttitle_screen::post_build(twindow& window)
|
||||
{
|
||||
/** @todo Should become a title screen hotkey. */
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__RELOAD_WML,
|
||||
std::bind(&hotkey, std::ref(window), RELOAD_GAME_DATA));
|
||||
[this](event::tdispatcher& win, hotkey::HOTKEY_COMMAND) {
|
||||
basic_callback(dynamic_cast<twindow&>(win), RELOAD_GAME_DATA);
|
||||
return true;
|
||||
});
|
||||
|
||||
window.register_hotkey(hotkey::HOTKEY_FULLSCREEN,
|
||||
std::bind(fullscreen, std::ref(window.video())));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::HOTKEY_LANGUAGE,
|
||||
std::bind(&hotkey, std::ref(window), CHANGE_LANGUAGE));
|
||||
|
||||
window.register_hotkey(hotkey::HOTKEY_LOAD_GAME,
|
||||
std::bind(&hotkey, std::ref(window), LOAD_GAME));
|
||||
|
||||
window.register_hotkey(hotkey::HOTKEY_HELP,
|
||||
std::bind(&hotkey, std::ref(window), SHOW_HELP));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::HOTKEY_PREFERENCES,
|
||||
std::bind(&hotkey, std::ref(window), EDIT_PREFERENCES));
|
||||
|
||||
std::function<void()> next_tip_wrapper = std::bind(
|
||||
&ttitle_screen::update_tip, this, std::ref(window), true);
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__NEXT_TIP,
|
||||
std::bind(function_wrapper<bool, std::function<void()> >,
|
||||
true,
|
||||
next_tip_wrapper));
|
||||
|
||||
std::function<void()> previous_tip_wrapper = std::bind(
|
||||
&ttitle_screen::update_tip, this, std::ref(window), false);
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__PREVIOUS_TIP,
|
||||
std::bind(function_wrapper<bool, std::function<void()> >,
|
||||
true,
|
||||
previous_tip_wrapper));
|
||||
|
||||
window.register_hotkey(hotkey::TITLE_SCREEN__TUTORIAL,
|
||||
std::bind(&hotkey, std::ref(window), TUTORIAL));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__CAMPAIGN,
|
||||
std::bind(&hotkey, std::ref(window), NEW_CAMPAIGN));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__MULTIPLAYER,
|
||||
std::bind(&hotkey, std::ref(window), MULTIPLAYER));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__ADDONS,
|
||||
std::bind(&hotkey, std::ref(window), GET_ADDONS));
|
||||
|
||||
window.register_hotkey(hotkey::TITLE_SCREEN__CORES,
|
||||
std::bind(&hotkey, std::ref(window), CORES));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__EDITOR,
|
||||
std::bind(&hotkey, std::ref(window), START_MAP_EDITOR));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::TITLE_SCREEN__CREDITS,
|
||||
std::bind(&hotkey, std::ref(window), SHOW_ABOUT));
|
||||
|
||||
window.register_hotkey(hotkey::HOTKEY_QUIT_TO_DESKTOP,
|
||||
std::bind(&hotkey, std::ref(window), QUIT_GAME));
|
||||
|
||||
window.register_hotkey(
|
||||
hotkey::LUA_CONSOLE,
|
||||
std::bind(&launch_lua_console, std::ref(window)));
|
||||
|
@ -260,6 +222,7 @@ debug_tooltip(twindow& window, bool& handled, const tpoint& coordinate)
|
|||
void ttitle_screen::pre_show(twindow& window)
|
||||
{
|
||||
set_restore(false);
|
||||
set_allow_plugin_skip(false);
|
||||
window.set_click_dismiss(false);
|
||||
window.set_enter_disabled(true);
|
||||
window.set_escape_disabled(true);
|
||||
|
@ -307,19 +270,14 @@ void ttitle_screen::pre_show(twindow& window)
|
|||
|
||||
update_tip(window, true);
|
||||
|
||||
connect_signal_mouse_left_click(
|
||||
find_widget<tbutton>(&window, "next_tip", false),
|
||||
std::bind(&ttitle_screen::update_tip,
|
||||
this,
|
||||
std::ref(window),
|
||||
true));
|
||||
|
||||
connect_signal_mouse_left_click(
|
||||
find_widget<tbutton>(&window, "previous_tip", false),
|
||||
std::bind(&ttitle_screen::update_tip,
|
||||
this,
|
||||
std::ref(window),
|
||||
false));
|
||||
register_button(window, "next_tip", hotkey::TITLE_SCREEN__NEXT_TIP,
|
||||
std::bind(&ttitle_screen::update_tip, this, std::ref(window), true));
|
||||
register_button(window, "previous_tip", hotkey::TITLE_SCREEN__PREVIOUS_TIP,
|
||||
std::bind(&ttitle_screen::update_tip, this, std::ref(window), false));
|
||||
register_button(window, "help", hotkey::HOTKEY_HELP, [this](twindow&) {
|
||||
help::help_manager help_manager(&game_config_manager::get()->game_config());
|
||||
help::show_help(game_.video());
|
||||
});
|
||||
|
||||
if(game_config::images::game_title.empty()) {
|
||||
ERR_CF << "No title image defined" << std::endl;
|
||||
|
@ -342,22 +300,123 @@ void ttitle_screen::pre_show(twindow& window)
|
|||
find_widget<timage>(&window, "logo", false).set_image(game_config::images::game_logo);
|
||||
|
||||
/***** About dialog button *****/
|
||||
tbutton& about = find_widget<tbutton>(&window, "about", false);
|
||||
connect_signal_mouse_left_click(
|
||||
about,
|
||||
register_button(window, "about", hotkey::HOTKEY_NULL,
|
||||
std::bind(&tgame_version::display, std::ref(window.video())));
|
||||
|
||||
/***** Set the clock button. *****/
|
||||
tbutton& clock = find_widget<tbutton>(&window, "clock", false);
|
||||
clock.set_visible(show_debug_clock_button ? twidget::tvisible::visible
|
||||
: twidget::tvisible::invisible);
|
||||
|
||||
connect_signal_mouse_left_click(
|
||||
clock,
|
||||
register_button(window, "clock", hotkey::HOTKEY_NULL,
|
||||
std::bind(&ttitle_screen::show_debug_clock_window,
|
||||
this,
|
||||
std::ref(window.video())));
|
||||
|
||||
/***** Main menu buttons *****/
|
||||
register_button(window, "tutorial", hotkey::TITLE_SCREEN__TUTORIAL, [this](twindow& window) {
|
||||
game_.set_tutorial();
|
||||
result_ = LAUNCH_GAME;
|
||||
window.close();
|
||||
});
|
||||
register_button(window, "campaign", hotkey::TITLE_SCREEN__CAMPAIGN, [this](twindow& window) {
|
||||
if(game_.new_campaign()) {
|
||||
result_ = LAUNCH_GAME;
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
register_button(window, "load", hotkey::HOTKEY_LOAD_GAME, [this](twindow& window) {
|
||||
if(game_.load_game()) {
|
||||
result_ = LAUNCH_GAME;
|
||||
window.close();
|
||||
} else {
|
||||
game_.clear_loaded_game();
|
||||
}
|
||||
});
|
||||
register_button(window, "addons", hotkey::TITLE_SCREEN__ADDONS, [this](twindow& window) {
|
||||
// NOTE: we need the help_manager to get access to the Add-ons
|
||||
// section in the game help!
|
||||
help::help_manager help_manager(&game_config_manager::get()->game_config());
|
||||
if(manage_addons(game_.video())) {
|
||||
game_config_manager::get()->reload_changed_game_config();
|
||||
}
|
||||
});
|
||||
register_button(window, "multiplayer", hotkey::TITLE_SCREEN__MULTIPLAYER, [this](twindow& window) {
|
||||
while(true) {
|
||||
gui2::tmp_method_selection dlg;
|
||||
dlg.show(game_.video());
|
||||
|
||||
if(dlg.get_retval() != gui2::twindow::OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
int res = dlg.get_choice();
|
||||
|
||||
if(dlg.get_choice() == 2 && preferences::mp_server_warning_disabled() < 2) {
|
||||
if(!gui2::tmp_host_game_prompt::execute(game_.video())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch(res) {
|
||||
case 0:
|
||||
result_ = MP_CONNECT;
|
||||
game_.select_mp_server(preferences::server_list().front().address);
|
||||
break;
|
||||
case 1:
|
||||
result_ = MP_CONNECT;
|
||||
game_.select_mp_server("");
|
||||
break;
|
||||
case 2:
|
||||
result_ = MP_HOST;
|
||||
game_.select_mp_server("localhost");
|
||||
break;
|
||||
case 3:
|
||||
result_ = MP_LOCAL;
|
||||
break;
|
||||
}
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
});
|
||||
register_button(window, "editor", hotkey::TITLE_SCREEN__EDITOR,
|
||||
std::bind(&ttitle_screen::basic_callback, this, std::ref(window), MAP_EDITOR));
|
||||
register_button(window, "cores", hotkey::TITLE_SCREEN__CORES, [this](twindow&) {
|
||||
int current = 0;
|
||||
std::vector<config> cores;
|
||||
for (const config& core : game_config_manager::get()->game_config().child_range("core")) {
|
||||
cores.push_back(core);
|
||||
if (core["id"] == preferences::core_id())
|
||||
current = cores.size() - 1;
|
||||
}
|
||||
|
||||
gui2::tcore_selection core_dlg(cores, current);
|
||||
if (core_dlg.show(game_.video())) {
|
||||
int core_index = core_dlg.get_choice();
|
||||
const std::string& core_id = cores[core_index]["id"];
|
||||
preferences::set_core_id(core_id);
|
||||
game_config_manager::get()->reload_changed_game_config();
|
||||
}
|
||||
});
|
||||
register_button(window, "language", hotkey::HOTKEY_LANGUAGE, [this](twindow& window) {
|
||||
try {
|
||||
if(game_.change_language()) {
|
||||
t_string::reset_translations();
|
||||
image::flush_cache();
|
||||
result_ = REDRAW_BACKGROUND;
|
||||
window.close();
|
||||
}
|
||||
} catch(std::runtime_error& e) {
|
||||
gui2::show_error_message(game_.video(), e.what());
|
||||
}
|
||||
});
|
||||
register_button(window, "preferences", hotkey::HOTKEY_PREFERENCES, [this](twindow&) {
|
||||
game_.show_preferences();
|
||||
});
|
||||
register_button(window, "credits", hotkey::TITLE_SCREEN__CREDITS,
|
||||
std::bind(&ttitle_screen::basic_callback, this, std::ref(window), SHOW_ABOUT));
|
||||
register_button(window, "quit", hotkey::HOTKEY_QUIT_TO_DESKTOP,
|
||||
std::bind(&ttitle_screen::basic_callback, this, std::ref(window), QUIT_GAME));
|
||||
|
||||
auto cores = game_config_manager::get()->game_config().child_range("core");
|
||||
if(cores.size() <= 1) {
|
||||
find_widget<tbutton>(&window, "cores", false).set_visible(twindow::tvisible::invisible);
|
||||
|
@ -368,7 +427,7 @@ void ttitle_screen::pre_show(twindow& window)
|
|||
|
||||
void ttitle_screen::on_resize(twindow& window)
|
||||
{
|
||||
window.set_retval(NOTHING);
|
||||
result_ = REDRAW_BACKGROUND;
|
||||
window.close();
|
||||
}
|
||||
|
||||
|
@ -416,4 +475,13 @@ void ttitle_screen::show_debug_clock_window(CVideo& video)
|
|||
}
|
||||
}
|
||||
|
||||
ttitle_screen::tresult ttitle_screen::display(game_launcher& game)
|
||||
{
|
||||
ttitle_screen ts(game);
|
||||
while(ts.result_ == tresult::REDRAW_BACKGROUND) {
|
||||
ts.show(game.video());
|
||||
}
|
||||
return ts.result_;
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
#define GUI_DIALOGS_TITLE_SCREEN_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "hotkey/hotkey_command.hpp"
|
||||
|
||||
class game_launcher;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -36,52 +39,34 @@ extern bool show_debug_clock_button;
|
|||
class ttitle_screen : public tdialog
|
||||
{
|
||||
public:
|
||||
ttitle_screen();
|
||||
ttitle_screen(game_launcher& game);
|
||||
|
||||
~ttitle_screen();
|
||||
|
||||
/**
|
||||
* Values for the menu-items of the main menu.
|
||||
*
|
||||
* @todo Evaluate the best place for these items.
|
||||
* Values for actions which leave the title screen.
|
||||
* Actions that merely show a dialog are not included here.
|
||||
*/
|
||||
enum tresult {
|
||||
TUTORIAL = 1 /**< Start special campaign 'tutorial' */
|
||||
,
|
||||
NEW_CAMPAIGN /**< Let user select a campaign to play */
|
||||
,
|
||||
DOWNLOAD_CAMPAIGN,
|
||||
MULTIPLAYER /**<
|
||||
* Play single scenario against humans or AI
|
||||
*/
|
||||
,
|
||||
LOAD_GAME,
|
||||
GET_ADDONS,
|
||||
CORES,
|
||||
START_MAP_EDITOR,
|
||||
CHANGE_LANGUAGE,
|
||||
EDIT_PREFERENCES,
|
||||
SHOW_ABOUT /**< Show credits */
|
||||
,
|
||||
QUIT_GAME,
|
||||
TIP_PREVIOUS /**< Show previous tip-of-the-day */
|
||||
,
|
||||
TIP_NEXT /**< Show next tip-of-the-day */
|
||||
,
|
||||
SHOW_HELP,
|
||||
REDRAW_BACKGROUND /**<
|
||||
* Used after an action needing a redraw (ex:
|
||||
* fullscreen)
|
||||
*/
|
||||
,
|
||||
RELOAD_GAME_DATA /**< Used to reload all game data */
|
||||
,
|
||||
NOTHING /**<
|
||||
* Default, nothing done, no redraw needed
|
||||
*/
|
||||
LAUNCH_GAME, ///< Start playing a single-player game, such as the tutorial or a campaign
|
||||
MP_CONNECT, ///< Connect to an MP server
|
||||
MP_HOST, ///< Host an MP game
|
||||
MP_LOCAL, ///< Start a local MP game
|
||||
MAP_EDITOR, ///< Start the map/scenario editor
|
||||
SHOW_ABOUT, ///< Show credits
|
||||
QUIT_GAME, ///< Exit to desktop
|
||||
REDRAW_BACKGROUND, /**< Used after an action needing a redraw
|
||||
* For example, if the window was resized or fullscreen was toggled
|
||||
*/
|
||||
RELOAD_GAME_DATA, ///< Used to reload all game data
|
||||
};
|
||||
|
||||
static tresult display(game_launcher& launcher);
|
||||
|
||||
private:
|
||||
tresult result_;
|
||||
game_launcher& game_;
|
||||
|
||||
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const;
|
||||
|
||||
|
@ -93,6 +78,8 @@ private:
|
|||
|
||||
void on_resize(twindow& window);
|
||||
|
||||
void basic_callback(twindow& window, tresult result);
|
||||
|
||||
/** Holds the debug clock dialog. */
|
||||
tpopup* debug_clock_;
|
||||
|
||||
|
|
|
@ -499,47 +499,6 @@ twindow::tretval twindow::get_retval_by_id(const std::string& id)
|
|||
return OK;
|
||||
} else if(id == "cancel") {
|
||||
return CANCEL;
|
||||
|
||||
/**
|
||||
* The ones for the title screen.
|
||||
*
|
||||
* This is a kind of hack, but the values are hardcoded in the
|
||||
* titlescreen and don't want to change them at the moment. It would be
|
||||
* a good idea to
|
||||
* add some namespaces to avoid names clashing.
|
||||
*/
|
||||
} else if(id == "tutorial") {
|
||||
return static_cast<tretval>(ttitle_screen::TUTORIAL);
|
||||
} else if(id == "editor") {
|
||||
return static_cast<tretval>(ttitle_screen::START_MAP_EDITOR);
|
||||
} else if(id == "credits") {
|
||||
return static_cast<tretval>(ttitle_screen::SHOW_ABOUT);
|
||||
} else if(id == "quit") {
|
||||
return static_cast<tretval>(ttitle_screen::QUIT_GAME);
|
||||
|
||||
/**
|
||||
* The hacks which are here so the old engine can handle the event. The
|
||||
* new engine can't handle all dialogs yet, so it needs to fall back to
|
||||
* the old engine to make certain things happen.
|
||||
*/
|
||||
} else if(id == "help") {
|
||||
return static_cast<tretval>(ttitle_screen::SHOW_HELP);
|
||||
} else if(id == "campaign") {
|
||||
return static_cast<tretval>(ttitle_screen::NEW_CAMPAIGN);
|
||||
} else if(id == "multiplayer") {
|
||||
return static_cast<tretval>(ttitle_screen::MULTIPLAYER);
|
||||
} else if(id == "load") {
|
||||
return static_cast<tretval>(ttitle_screen::LOAD_GAME);
|
||||
} else if(id == "addons") {
|
||||
return static_cast<tretval>(ttitle_screen::GET_ADDONS);
|
||||
} else if(id == "cores") {
|
||||
return static_cast<tretval>(ttitle_screen::CORES);
|
||||
} else if(id == "language") {
|
||||
return static_cast<tretval>(ttitle_screen::CHANGE_LANGUAGE);
|
||||
} else if(id == "preferences") {
|
||||
return static_cast<tretval>(ttitle_screen::EDIT_PREFERENCES);
|
||||
|
||||
// default if nothing matched
|
||||
} else {
|
||||
return NONE;
|
||||
}
|
||||
|
|
114
src/wesnoth.cpp
114
src/wesnoth.cpp
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "about.hpp"
|
||||
#include "addon/manager.hpp"
|
||||
#include "addon/manager_ui.hpp"
|
||||
#include "build_info.hpp"
|
||||
#include "commandline_options.hpp" // for commandline_options, etc
|
||||
#include "config.hpp" // for config, config::error, etc
|
||||
|
@ -32,12 +31,10 @@
|
|||
#include "game_launcher.hpp" // for game_launcher, etc
|
||||
#include "gettext.hpp"
|
||||
#include "gui/core/event/handler.hpp" // for tmanager
|
||||
#include "gui/dialogs/core_selection.hpp" // for tcore_selection
|
||||
#include "gui/dialogs/loadscreen.hpp"
|
||||
#include "gui/dialogs/title_screen.hpp" // for ttitle_screen, etc
|
||||
#include "gui/dialogs/message.hpp" // for show_error_message
|
||||
#include "gui/widgets/helper.hpp" // for init
|
||||
#include "help/help.hpp" // for help_manager
|
||||
#include "image.hpp" // for flush_cache, etc
|
||||
#include "log.hpp" // for LOG_STREAM, general, logger, etc
|
||||
#include "preferences.hpp" // for core_id, etc
|
||||
|
@ -662,14 +659,12 @@ static int do_gameloop(const std::vector<std::string>& args)
|
|||
return 1;
|
||||
}
|
||||
|
||||
config tips_of_day;
|
||||
|
||||
LOG_CONFIG << "time elapsed: "<< (SDL_GetTicks() - start_ticks) << " ms\n";
|
||||
|
||||
plugins_manager plugins_man(new application_lua_kernel(&game->video()));
|
||||
|
||||
plugins_context::Reg const callbacks[] = {
|
||||
{ "play_multiplayer", std::bind(&game_launcher::play_multiplayer, game.get())},
|
||||
{ "play_multiplayer", std::bind(&game_launcher::play_multiplayer, game.get(), game_launcher::MP_CONNECT)},
|
||||
};
|
||||
plugins_context::aReg const accessors[] = {
|
||||
{ "command_line", std::bind(&commandline_options::to_config, &cmdline_opts)},
|
||||
|
@ -757,107 +752,58 @@ static int do_gameloop(const std::vector<std::string>& args)
|
|||
return 0;
|
||||
}
|
||||
|
||||
gui2::ttitle_screen::tresult res = game->is_loading()
|
||||
? gui2::ttitle_screen::LOAD_GAME
|
||||
: gui2::ttitle_screen::NOTHING;
|
||||
|
||||
preferences::load_hotkeys();
|
||||
|
||||
const font::floating_label_context label_manager;
|
||||
|
||||
cursor::set(cursor::NORMAL);
|
||||
if(res == gui2::ttitle_screen::NOTHING) {
|
||||
gui2::ttitle_screen dlg;
|
||||
dlg.show(game->video());
|
||||
|
||||
res = static_cast<gui2::ttitle_screen::tresult>(dlg.get_retval());
|
||||
}
|
||||
gui2::ttitle_screen::tresult res = gui2::ttitle_screen::display(*game);
|
||||
|
||||
game_launcher::RELOAD_GAME_DATA should_reload =
|
||||
game_launcher::RELOAD_DATA;
|
||||
|
||||
if(res == gui2::ttitle_screen::QUIT_GAME) {
|
||||
switch(res) {
|
||||
case gui2::ttitle_screen::QUIT_GAME:
|
||||
LOG_GENERAL << "quitting game...\n";
|
||||
return 0;
|
||||
} else if(res == gui2::ttitle_screen::LOAD_GAME) {
|
||||
if(game->load_game() == false) {
|
||||
game->clear_loaded_game();
|
||||
res = gui2::ttitle_screen::NOTHING;
|
||||
continue;
|
||||
}
|
||||
should_reload = game_launcher::NO_RELOAD_DATA;
|
||||
} else if(res == gui2::ttitle_screen::TUTORIAL) {
|
||||
game->set_tutorial();
|
||||
} else if(res == gui2::ttitle_screen::NEW_CAMPAIGN) {
|
||||
if(game->new_campaign() == false) {
|
||||
continue;
|
||||
}
|
||||
should_reload = game_launcher::NO_RELOAD_DATA;
|
||||
} else if(res == gui2::ttitle_screen::MULTIPLAYER) {
|
||||
case gui2::ttitle_screen::MP_CONNECT:
|
||||
game_config::debug = game_config::mp_debug;
|
||||
if(game->play_multiplayer() == false) {
|
||||
if(!game->play_multiplayer(game_launcher::MP_CONNECT)) {
|
||||
continue;
|
||||
}
|
||||
} else if(res == gui2::ttitle_screen::CHANGE_LANGUAGE) {
|
||||
try {
|
||||
if (game->change_language()) {
|
||||
tips_of_day.clear();
|
||||
t_string::reset_translations();
|
||||
image::flush_cache();
|
||||
}
|
||||
} catch ( std::runtime_error & e ) {
|
||||
gui2::show_error_message(game->video(), e.what());
|
||||
break;
|
||||
case gui2::ttitle_screen::MP_HOST:
|
||||
game_config::debug = game_config::mp_debug;
|
||||
if(!game->play_multiplayer(game_launcher::MP_HOST)) {
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::EDIT_PREFERENCES) {
|
||||
game->show_preferences();
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::SHOW_ABOUT) {
|
||||
about::show_about(game->video());
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::SHOW_HELP) {
|
||||
help::help_manager help_manager(&config_manager.game_config());
|
||||
help::show_help(game->video());
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::GET_ADDONS) {
|
||||
// NOTE: we need the help_manager to get access to the Add-ons
|
||||
// section in the game help!
|
||||
help::help_manager help_manager(&config_manager.game_config());
|
||||
if(manage_addons(game->video())) {
|
||||
config_manager.reload_changed_game_config();
|
||||
break;
|
||||
case gui2::ttitle_screen::MP_LOCAL:
|
||||
game_config::debug = game_config::mp_debug;
|
||||
if(!game->play_multiplayer(game_launcher::MP_LOCAL)) {
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::CORES) {
|
||||
|
||||
int current = 0;
|
||||
std::vector<config> cores;
|
||||
for (const config& core : config_manager.game_config().child_range("core")) {
|
||||
cores.push_back(core);
|
||||
if (core["id"] == preferences::core_id())
|
||||
current = cores.size() -1;
|
||||
}
|
||||
|
||||
gui2::tcore_selection core_dlg(cores, current);
|
||||
if (core_dlg.show(game->video())) {
|
||||
int core_index = core_dlg.get_choice();
|
||||
const std::string& core_id = cores[core_index]["id"];
|
||||
preferences::set_core_id(core_id);
|
||||
config_manager.reload_changed_game_config();
|
||||
}
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::RELOAD_GAME_DATA) {
|
||||
break;
|
||||
case gui2::ttitle_screen::RELOAD_GAME_DATA:
|
||||
gui2::tloadscreen::display(game->video(), [&config_manager]() {
|
||||
config_manager.reload_changed_game_config();
|
||||
image::flush_cache();
|
||||
});
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::START_MAP_EDITOR) {
|
||||
break;
|
||||
case gui2::ttitle_screen::MAP_EDITOR:
|
||||
game->start_editor();
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::NOTHING) {
|
||||
continue;
|
||||
break;
|
||||
case gui2::ttitle_screen::SHOW_ABOUT:
|
||||
about::show_about(game->video());
|
||||
break;
|
||||
case gui2::ttitle_screen::LAUNCH_GAME:
|
||||
game->launch_game(should_reload);
|
||||
break;
|
||||
case gui2::ttitle_screen::REDRAW_BACKGROUND:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
game->launch_game(should_reload);
|
||||
}
|
||||
}
|
||||
#ifdef _WIN32
|
||||
|
|
Loading…
Add table
Reference in a new issue