Added wesnothd search dialog to preferences and after failed mp server launch

Code still needs some testing and cleaning. I will look at it tomorrow
This commit is contained in:
Pauli Nieminen 2008-06-24 14:35:44 +00:00
parent b1a9e085e5
commit 40df21d79a
10 changed files with 133 additions and 20 deletions

View file

@ -95,6 +95,7 @@ else:
if env.get('cxxtool',""): if env.get('cxxtool',""):
env['CXX'] = env['cxxtool'] env['CXX'] = env['cxxtool']
env['ENV']['HOME'] = os.environ['HOME']
Help("""Arguments may be a mixture of switches and targets an any order. 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. Switches apply to the entire build regrdless of where they are in the order.

View file

@ -179,7 +179,6 @@ wesnoth_sources = Split("""
game_display.cpp game_display.cpp
game_events.cpp game_events.cpp
game_preferences.cpp game_preferences.cpp
game_preferences_display.cpp
gamestatus.cpp gamestatus.cpp
generate_report.cpp generate_report.cpp
halo.cpp halo.cpp
@ -221,6 +220,7 @@ wesnoth_sources = Split("""
widgets/combo.cpp widgets/combo.cpp
widgets/scrollpane.cpp widgets/scrollpane.cpp
""") """)
wesnoth_sources.extend(env.Object("game_preferences_display.cpp", EXTRA_DEFINE = "WESNOTH_PREFIX='\"%s\"'" % env['prefix']))
python_env = env.Clone() python_env = env.Clone()
if env['python']: if env['python']:

View file

@ -22,6 +22,7 @@
#include "construct_dialog.hpp" #include "construct_dialog.hpp"
#include "cursor.hpp" #include "cursor.hpp"
#include "dialogs.hpp" #include "dialogs.hpp"
#include "file_chooser.hpp"
#include "game_display.hpp" #include "game_display.hpp"
#include "filesystem.hpp" #include "filesystem.hpp"
#include "font.hpp" #include "font.hpp"
@ -1662,11 +1663,39 @@ void game_controller::remove_addon(const std::string& addon)
remove_local_addon(addon); remove_local_addon(addon);
} }
void game_controller::start_wesnothd() 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()) { 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) if (std::system(("cmd /C start \"wesnoth server\" /B \"" + game_config::wesnothd_name + "\" -c " + config + " -t 2 -T 5 ").c_str()) != 0)
#endif #endif
{ {
#ifndef _WIN32
// try to locate wesnothd // try to locate wesnothd
std::string old_name = game_config::wesnothd_name; std::string old_name = game_config::wesnothd_name;
std::string needle = "wesnothd"; std::string needle = "wesnothd";
@ -1696,6 +1724,11 @@ void game_controller::start_wesnothd()
&& found + needle.size() < game_config::wesnothd_name.size()) && found + needle.size() < game_config::wesnothd_name.size())
{ {
game_config::wesnothd_name = game_config::wesnothd_name.substr(0, found + needle.size()); game_config::wesnothd_name = game_config::wesnothd_name.substr(0, found + needle.size());
#ifdef _WIN32
game_config::Wesnothd_name += ".exe";
#endif
if (old_name != game_config::wesnothd_name)
{
try { try {
start_wesnothd(); start_wesnothd();
@ -1706,11 +1739,9 @@ void game_controller::start_wesnothd()
throw; throw;
} }
} }
else
#endif
{
// We should show gui to set wesnothd_name
} }
LOG_GENERAL << "Failed to run server start script\n"; LOG_GENERAL << "Failed to run server start script\n";
throw game::mp_server_error("Starting MP server failed!"); throw game::mp_server_error("Starting MP server failed!");
} }
@ -1805,7 +1836,32 @@ bool game_controller::play_multiplayer()
try { try {
if (res == 2) if (res == 2)
{ {
try {
start_wesnothd(); 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 */ { /* do */ {

View file

@ -216,8 +216,6 @@ namespace game_config
sinf.address = (**server)["address"]; sinf.address = (**server)["address"];
server_list.push_back(sinf); server_list.push_back(sinf);
} }
if (!v["wesnothd_name"].empty())
wesnothd_name = v["wesnothd_name"];
} }
void add_color_info(const config& v){ void add_color_info(const config& v){

View file

@ -367,6 +367,24 @@ void set_mp_server_warning_disabled(int value)
preferences::set("mp_server_warning_disabled", lexical_cast<std::string>(value)); preferences::set("mp_server_warning_disabled", lexical_cast<std::string>(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() bool random_start_time()
{ {

View file

@ -87,6 +87,9 @@ namespace preferences {
int mp_server_warning_disabled(); int mp_server_warning_disabled();
void set_mp_server_warning_disabled(int value); void set_mp_server_warning_disabled(int value);
void set_mp_server_program_name();
void check_mp_server_program_name();
bool random_start_time(); bool random_start_time();
void set_random_start_time(bool value); void set_random_start_time(bool value);

View file

@ -17,6 +17,8 @@
#include "cursor.hpp" #include "cursor.hpp"
#include "display.hpp" #include "display.hpp"
#include "filesystem.hpp"
#include "file_chooser.hpp"
#include "game_preferences.hpp" #include "game_preferences.hpp"
#include "gettext.hpp" #include "gettext.hpp"
#include "hotkeys.hpp" #include "hotkeys.hpp"
@ -112,6 +114,7 @@ private:
show_lobby_joins_button2_, show_lobby_joins_button2_,
show_lobby_joins_button3_, show_lobby_joins_button3_,
sort_list_by_group_button_, iconize_list_button_, sort_list_by_group_button_, iconize_list_button_,
mp_server_search_button_,
friends_list_button_, friends_back_button_, friends_list_button_, friends_back_button_,
friends_add_friend_button_, friends_add_ignore_button_, friends_add_friend_button_, friends_add_ignore_button_,
friends_remove_button_, show_floating_labels_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), 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), 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), 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_list_button_(disp.video(), _("Friends List")),
friends_back_button_(disp.video(), _("Multiplayer Options")), friends_back_button_(disp.video(), _("Multiplayer Options")),
friends_add_friend_button_(disp.video(), _("Add As Friend")), 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_check(lobby_joins() == SHOW_ALL);
show_lobby_joins_button3_.set_help_string(_("Show messages about all players joining the multiplayer lobby")); 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_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_back_button_.set_help_string(_("Back to the multiplayer options"));
friends_add_friend_button_.set_help_string(_("Add this username to your friends list")); 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_button1_);
h.push_back(&show_lobby_joins_button2_); h.push_back(&show_lobby_joins_button2_);
h.push_back(&show_lobby_joins_button3_); h.push_back(&show_lobby_joins_button3_);
h.push_back(&mp_server_search_button_);
h.push_back(&friends_list_button_); h.push_back(&friends_list_button_);
h.push_back(&friends_back_button_); h.push_back(&friends_back_button_);
h.push_back(&friends_add_friend_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()); 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 //Friends tab
ypos = rect.y + top_border; ypos = rect.y + top_border;
friends_input_.set_location(rect.x,ypos); friends_input_.set_location(rect.x,ypos);
@ -859,6 +867,9 @@ void preferences_dialog::process_event()
if (friends_list_button_.pressed()) if (friends_list_button_.pressed())
set_selection(FRIENDS_TAB); set_selection(FRIENDS_TAB);
if (mp_server_search_button_.pressed())
show_wesnothd_server_search(disp_);
set_chat_lines(chat_lines_slider_.value()); set_chat_lines(chat_lines_slider_.value());
//display currently select amount of chat lines //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_button2_.hide(hide_multiplayer);
show_lobby_joins_button3_.hide(hide_multiplayer); show_lobby_joins_button3_.hide(hide_multiplayer);
friends_list_button_.hide(hide_multiplayer); friends_list_button_.hide(hide_multiplayer);
mp_server_search_button_.hide(hide_multiplayer);
const bool hide_friends = tab_ != FRIENDS_TAB; const bool hide_friends = tab_ != FRIENDS_TAB;
friends_.hide(hide_friends); 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) void show_preferences_dialog(display& disp, const config& game_cfg)
{ {
std::vector<std::string> items; std::vector<std::string> items;

View file

@ -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; prefs[key] = value;
} }
void clear(const std::string& key)
{
prefs.recursive_clear_value(key);
}
void set_child(const std::string& key, const config& val) { void set_child(const std::string& key, const config& val) {
prefs.clear_children(key); prefs.clear_children(key);
prefs.add_child(key, val); prefs.add_child(key, val);

View file

@ -39,7 +39,8 @@ namespace preferences {
void write_preferences(); void write_preferences();
// Low-level, should be seen only by preferences_display ? // 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); void set_child(const std::string& key, const config& val);
config* get_child(const std::string& key); config* get_child(const std::string& key);
const std::string get(const std::string key); const std::string get(const std::string key);

View file

@ -40,6 +40,7 @@ namespace preferences {
void set_idle_anim(bool ison); void set_idle_anim(bool ison);
void set_idle_anim_rate(int rate); void set_idle_anim_rate(int rate);
std::string show_wesnothd_server_search(display&);
void show_preferences_dialog(display& disp, const config& game_cfg); void show_preferences_dialog(display& disp, const config& game_cfg);
bool show_video_mode_dialog(display& disp); bool show_video_mode_dialog(display& disp);
bool show_theme_dialog(display& disp); bool show_theme_dialog(display& disp);