diff --git a/SConstruct b/SConstruct index 46c4bb337a6..979a69cbda3 100644 --- a/SConstruct +++ b/SConstruct @@ -95,6 +95,7 @@ else: if env.get('cxxtool',""): env['CXX'] = env['cxxtool'] + env['ENV']['HOME'] = os.environ['HOME'] Help("""Arguments may be a mixture of switches and targets an any order. Switches apply to the entire build regrdless of where they are in the order. diff --git a/src/SConscript b/src/SConscript index 889d08f7053..44cf86caf71 100644 --- a/src/SConscript +++ b/src/SConscript @@ -179,7 +179,6 @@ wesnoth_sources = Split(""" game_display.cpp game_events.cpp game_preferences.cpp - game_preferences_display.cpp gamestatus.cpp generate_report.cpp halo.cpp @@ -221,6 +220,7 @@ wesnoth_sources = Split(""" widgets/combo.cpp widgets/scrollpane.cpp """) +wesnoth_sources.extend(env.Object("game_preferences_display.cpp", EXTRA_DEFINE = "WESNOTH_PREFIX='\"%s\"'" % env['prefix'])) python_env = env.Clone() if env['python']: diff --git a/src/game.cpp b/src/game.cpp index 92a6fe878dc..328feb6c30a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -22,6 +22,7 @@ #include "construct_dialog.hpp" #include "cursor.hpp" #include "dialogs.hpp" +#include "file_chooser.hpp" #include "game_display.hpp" #include "filesystem.hpp" #include "font.hpp" @@ -1662,11 +1663,39 @@ void game_controller::remove_addon(const std::string& addon) remove_local_addon(addon); } + class file_preview_pane : public gui::preview_pane { + + }; + + + class filebrowser : public gui::dialog { + std::string directory_; + std::string regex_match_; + bool show_dirs_; + public: + filebrowser(display &disp, const std::string& title="", const std::string& message=""); + int show(); + }; + + filebrowser::filebrowser(display &disp, const std::string& title, const std::string& message) : + gui::dialog(disp, title, message,gui::OK_CANCEL), + directory_(), regex_match_(), show_dirs_(false) + { + + } + + int filebrowser::show() + { + return gui::dialog::show(); + } + void game_controller::start_wesnothd() { + // Make sure that we have laoded name from preferences + preferences::check_mp_server_program_name(); if(game_config::wesnothd_name.empty()) { - throw game::mp_server_error("Couldn't locate the server binary."); + throw game::mp_server_error("No server name given the server binary."); } @@ -1687,7 +1716,6 @@ void game_controller::start_wesnothd() if (std::system(("cmd /C start \"wesnoth server\" /B \"" + game_config::wesnothd_name + "\" -c " + config + " -t 2 -T 5 ").c_str()) != 0) #endif { -#ifndef _WIN32 // try to locate wesnothd std::string old_name = game_config::wesnothd_name; std::string needle = "wesnothd"; @@ -1696,21 +1724,24 @@ void game_controller::start_wesnothd() && found + needle.size() < game_config::wesnothd_name.size()) { game_config::wesnothd_name = game_config::wesnothd_name.substr(0, found + needle.size()); - - try { - start_wesnothd(); - return; - } catch(...) +#ifdef _WIN32 + game_config::Wesnothd_name += ".exe"; +#endif + if (old_name != game_config::wesnothd_name) { - game_config::wesnothd_name = old_name; - throw; + + try { + start_wesnothd(); + return; + } catch(...) + { + game_config::wesnothd_name = old_name; + throw; + } } } - else -#endif - { - // We should show gui to set wesnothd_name - } + + LOG_GENERAL << "Failed to run server start script\n"; throw game::mp_server_error("Starting MP server failed!"); } @@ -1805,7 +1836,32 @@ bool game_controller::play_multiplayer() try { if (res == 2) { - start_wesnothd(); + try { + start_wesnothd(); + } catch(game::mp_server_error) + { + std::string path = preferences::show_wesnothd_server_search(disp()); + + if (!path.empty()) + { + std::string old_name = game_config::wesnothd_name; + game_config::wesnothd_name = path; + try { + start_wesnothd(); + } catch(...) + { + game_config::wesnothd_name = old_name; + throw; + } + preferences::set_mp_server_program_name(); + } + else + { + throw game::mp_server_error("No path given for mp server prgoram."); + } + } + + } /* do */ { diff --git a/src/game_config.cpp b/src/game_config.cpp index aaa471e6f83..3de1ac9c97a 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -216,8 +216,6 @@ namespace game_config sinf.address = (**server)["address"]; server_list.push_back(sinf); } - if (!v["wesnothd_name"].empty()) - wesnothd_name = v["wesnothd_name"]; } void add_color_info(const config& v){ diff --git a/src/game_preferences.cpp b/src/game_preferences.cpp index 6571a8347e5..15d4103a58f 100644 --- a/src/game_preferences.cpp +++ b/src/game_preferences.cpp @@ -367,6 +367,24 @@ void set_mp_server_warning_disabled(int value) preferences::set("mp_server_warning_disabled", lexical_cast(value)); } +void set_mp_server_program_name() +{ + if (game_config::wesnothd_name.empty()) + { + preferences::clear("mp_server_program_name"); + } + else + { + preferences::set("mp_server_program_name", game_config::wesnothd_name); + } +} + +void check_mp_server_program_name() +{ + if (preferences::get("mp_server_program_name").empty()) + return; + game_config::wesnothd_name = preferences::get("mp_server_program_name"); +} bool random_start_time() { diff --git a/src/game_preferences.hpp b/src/game_preferences.hpp index d4bf4d8ace9..b67bd9bdc65 100644 --- a/src/game_preferences.hpp +++ b/src/game_preferences.hpp @@ -87,6 +87,9 @@ namespace preferences { int mp_server_warning_disabled(); void set_mp_server_warning_disabled(int value); + void set_mp_server_program_name(); + void check_mp_server_program_name(); + bool random_start_time(); void set_random_start_time(bool value); diff --git a/src/game_preferences_display.cpp b/src/game_preferences_display.cpp index b54f69d7b20..5c74c30f0dd 100644 --- a/src/game_preferences_display.cpp +++ b/src/game_preferences_display.cpp @@ -17,6 +17,8 @@ #include "cursor.hpp" #include "display.hpp" +#include "filesystem.hpp" +#include "file_chooser.hpp" #include "game_preferences.hpp" #include "gettext.hpp" #include "hotkeys.hpp" @@ -112,6 +114,7 @@ private: show_lobby_joins_button2_, show_lobby_joins_button3_, sort_list_by_group_button_, iconize_list_button_, + mp_server_search_button_, friends_list_button_, friends_back_button_, friends_add_friend_button_, friends_add_ignore_button_, friends_remove_button_, show_floating_labels_button_, @@ -168,6 +171,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg) show_lobby_joins_button3_(disp.video(), _("Show All Lobby Joins"), gui::button::TYPE_CHECK), sort_list_by_group_button_(disp.video(), _("Sort Lobby List"), gui::button::TYPE_CHECK), iconize_list_button_(disp.video(), _("Iconize Lobby List"), gui::button::TYPE_CHECK), + mp_server_search_button_(disp.video(), _("set path to server")), friends_list_button_(disp.video(), _("Friends List")), friends_back_button_(disp.video(), _("Multiplayer Options")), friends_add_friend_button_(disp.video(), _("Add As Friend")), @@ -362,6 +366,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg) show_lobby_joins_button3_.set_check(lobby_joins() == SHOW_ALL); show_lobby_joins_button3_.set_help_string(_("Show messages about all players joining the multiplayer lobby")); + mp_server_search_button_.set_help_string(_("Find and set path to MP server to host lan games.")); friends_list_button_.set_help_string(_("View and edit your friends and ignores list")); friends_back_button_.set_help_string(_("Back to the multiplayer options")); friends_add_friend_button_.set_help_string(_("Add this username to your friends list")); @@ -427,6 +432,7 @@ handler_vector preferences_dialog::handler_members() h.push_back(&show_lobby_joins_button1_); h.push_back(&show_lobby_joins_button2_); h.push_back(&show_lobby_joins_button3_); + h.push_back(&mp_server_search_button_); h.push_back(&friends_list_button_); h.push_back(&friends_back_button_); h.push_back(&friends_add_friend_button_); @@ -623,6 +629,8 @@ void preferences_dialog::update_location(SDL_Rect const &rect) friends_list_button_.set_location(rect.x, bottom_row_y - friends_list_button_.height()); + mp_server_search_button_.set_location(rect.x + 10 + friends_list_button_.width(), bottom_row_y - mp_server_search_button_.height()); + //Friends tab ypos = rect.y + top_border; friends_input_.set_location(rect.x,ypos); @@ -859,6 +867,9 @@ void preferences_dialog::process_event() if (friends_list_button_.pressed()) set_selection(FRIENDS_TAB); + if (mp_server_search_button_.pressed()) + show_wesnothd_server_search(disp_); + set_chat_lines(chat_lines_slider_.value()); //display currently select amount of chat lines @@ -1094,6 +1105,7 @@ void preferences_dialog::set_selection(int index) show_lobby_joins_button2_.hide(hide_multiplayer); show_lobby_joins_button3_.hide(hide_multiplayer); friends_list_button_.hide(hide_multiplayer); + mp_server_search_button_.hide(hide_multiplayer); const bool hide_friends = tab_ != FRIENDS_TAB; friends_.hide(hide_friends); @@ -1110,6 +1122,24 @@ void preferences_dialog::set_selection(int index) } +std::string show_wesnothd_server_search(display& disp) +{ + // Showing file_chooser so user can search the wesnothd +#ifndef _WIN32 + std::string title = _("Find wesnothd server binary"); + std::string path = WESNOTH_PREFIX + std::string("/bin"); + if (!is_directory(path)) + path = get_cwd(); + +#else + std::string title = _("Find wesnothd.exe server binary"); + std::string path = get_cwd(); +#endif + + int res = dialogs::show_file_chooser_dialog(disp, path, title); + return path; +} + void show_preferences_dialog(display& disp, const config& game_cfg) { std::vector items; diff --git a/src/preferences.cpp b/src/preferences.cpp index 73c55fd995e..6ab3f7db1b8 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -76,10 +76,15 @@ void write_preferences() } -void set(const std::string key, std::string value) { +void set(const std::string& key, std::string value) { prefs[key] = value; } +void clear(const std::string& key) +{ + prefs.recursive_clear_value(key); +} + void set_child(const std::string& key, const config& val) { prefs.clear_children(key); prefs.add_child(key, val); diff --git a/src/preferences.hpp b/src/preferences.hpp index 11eb093ec58..a56866d363e 100644 --- a/src/preferences.hpp +++ b/src/preferences.hpp @@ -39,7 +39,8 @@ namespace preferences { void write_preferences(); // Low-level, should be seen only by preferences_display ? - void set(const std::string key, std::string value); + void set(const std::string& key, std::string value); + void clear(const std::string& key); void set_child(const std::string& key, const config& val); config* get_child(const std::string& key); const std::string get(const std::string key); diff --git a/src/preferences_display.hpp b/src/preferences_display.hpp index 8eaf7e7f841..54509a7dc18 100644 --- a/src/preferences_display.hpp +++ b/src/preferences_display.hpp @@ -40,6 +40,7 @@ namespace preferences { void set_idle_anim(bool ison); void set_idle_anim_rate(int rate); + std::string show_wesnothd_server_search(display&); void show_preferences_dialog(display& disp, const config& game_cfg); bool show_video_mode_dialog(display& disp); bool show_theme_dialog(display& disp);