game_preferences_display.cpp

Go to the documentation of this file.
00001 /* $Id: game_preferences_display.cpp 53610 2012-03-22 00:14:03Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 #include "global.hpp"
00016 
00017 #define GETTEXT_DOMAIN "wesnoth-lib"
00018 
00019 #include "display.hpp"
00020 #include "filesystem.hpp"
00021 #include "filechooser.hpp"
00022 #include "foreach.hpp"
00023 #include "game_preferences.hpp"
00024 #include "gettext.hpp"
00025 #include "gui/dialogs/simple_item_selector.hpp"
00026 #include "gui/dialogs/transient_message.hpp"
00027 #include "lobby_preferences.hpp"
00028 #include "preferences_display.hpp"
00029 #include "wml_separators.hpp"
00030 #include "widgets/slider.hpp"
00031 #include "formula_string_utils.hpp"
00032 
00033 
00034 namespace preferences {
00035 
00036 static void set_lobby_joins(int ison)
00037 {
00038     _set_lobby_joins(ison);
00039 }
00040 
00041 static void set_sort_list(bool ison)
00042 {
00043     _set_sort_list(ison);
00044 }
00045 
00046 static void set_iconize_list(bool ison)
00047 {
00048     _set_iconize_list(ison);
00049 }
00050 
00051 namespace {
00052 
00053 struct advanced_preferences_sorter
00054 {
00055     bool operator()(const config& lhs, const config& rhs) const
00056     {
00057         return lhs["name"].t_str().str() < rhs["name"].t_str().str();
00058     }
00059 };
00060 
00061 class preferences_parent_dialog : public gui::dialog
00062 {
00063 public:
00064     preferences_parent_dialog(display &disp) : dialog(disp, _("Preferences"),"",gui::CLOSE_ONLY),
00065         clear_buttons_(false) {}
00066     ~preferences_parent_dialog() {write_preferences();}
00067     void action(gui::dialog_process_info &info)
00068     {
00069         if(clear_buttons_) {
00070             info.clear_buttons();
00071             clear_buttons_ = false;
00072         }
00073     }
00074     void clear_buttons() { clear_buttons_ = true; }
00075 private:
00076     bool clear_buttons_;
00077 };
00078 
00079 class preferences_dialog : public gui::preview_pane
00080 {
00081 public:
00082     preferences_dialog(display& disp, const config& game_cfg);
00083 
00084     struct video_mode_change_exception
00085     {
00086         enum TYPE { CHANGE_RESOLUTION, MAKE_FULLSCREEN, MAKE_WINDOWED };
00087 
00088         video_mode_change_exception(TYPE type) : type(type)
00089         {}
00090 
00091         TYPE type;
00092     };
00093 
00094     virtual handler_vector handler_members();
00095 private:
00096 
00097     void process_event();
00098     bool left_side() const { return false; }
00099     void set_selection(int index);
00100     void update_location(SDL_Rect const &rect);
00101     const config* get_advanced_pref() const;
00102     void set_advanced_menu();
00103     void sort_advanced_preferences();
00104     void set_friends_menu();
00105     std::vector<std::string> friends_names_;
00106 
00107 //
00108     // change
00109     gui::slider music_slider_, sound_slider_, UI_sound_slider_, bell_slider_,
00110                 scroll_slider_, chat_lines_slider_,
00111       buffer_size_slider_, idle_anim_slider_, autosavemax_slider_, advanced_slider_;
00112     gui::list_slider<double> turbo_slider_;
00113     gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
00114             interrupt_when_ally_sighted_button_,
00115             show_grid_button_, save_replays_button_, delete_saves_button_,
00116             show_lobby_joins_button1_,
00117             show_lobby_joins_button2_,
00118             show_lobby_joins_button3_,
00119             new_lobby_button_,
00120             sort_list_by_group_button_, iconize_list_button_,
00121             remember_pw_button_, mp_server_search_button_,
00122             friends_list_button_, friends_back_button_,
00123             friends_add_friend_button_, friends_add_ignore_button_,
00124             friends_remove_button_, show_floating_labels_button_,
00125             turn_dialog_button_, whiteboard_on_start_button_,
00126             hide_whiteboard_button_, turn_bell_button_, show_team_colors_button_,
00127             show_color_cursors_button_, show_haloing_button_, video_mode_button_,
00128             theme_button_, hotkeys_button_,
00129             advanced_button_, sound_button_,
00130             music_button_, chat_timestamp_button_,
00131             advanced_sound_button_, normal_sound_button_,
00132             UI_sound_button_, sample_rate_button1_,
00133             sample_rate_button2_, sample_rate_button3_,
00134             confirm_sound_button_, idle_anim_button_,
00135             standing_anim_button_,
00136             animate_map_button_;
00137     gui::label music_label_, sound_label_, UI_sound_label_, bell_label_,
00138                scroll_label_, chat_lines_label_,
00139                turbo_slider_label_, sample_rate_label_, buffer_size_label_,
00140                idle_anim_slider_label_, autosavemax_slider_label_,
00141                advanced_slider_label_;
00142     gui::textbox sample_rate_input_, friends_input_;
00143 
00144     unsigned slider_label_width_;
00145 
00146     gui::menu advanced_, friends_;
00147     int advanced_selection_, friends_selection_;
00148 
00149     enum TAB {  GENERAL_TAB, DISPLAY_TAB, SOUND_TAB, MULTIPLAYER_TAB, ADVANCED_TAB,
00150                 /*extra tab*/
00151                 ADVANCED_SOUND_TAB, FRIENDS_TAB};
00152     TAB tab_;
00153     display &disp_;
00154     const config& game_cfg_;
00155     std::vector<config> adv_preferences_cfg_;
00156 public:
00157     util::scoped_ptr<preferences_parent_dialog> parent;
00158 };
00159 
00160 //change
00161 preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
00162     : gui::preview_pane(disp.video()),
00163       friends_names_(),
00164       music_slider_(disp.video()), sound_slider_(disp.video()),
00165       UI_sound_slider_(disp.video()), bell_slider_(disp.video()),
00166       scroll_slider_(disp.video()),
00167       chat_lines_slider_(disp.video()), buffer_size_slider_(disp.video()),
00168       idle_anim_slider_(disp.video()), autosavemax_slider_(disp.video()),
00169       advanced_slider_(disp.video()),
00170       turbo_slider_(disp.video()),
00171 
00172 
00173       fullscreen_button_(disp.video(), _("Full screen"), gui::button::TYPE_CHECK),
00174       turbo_button_(disp.video(), _("Accelerated speed"), gui::button::TYPE_CHECK),
00175       show_ai_moves_button_(disp.video(), _("Skip AI moves"), gui::button::TYPE_CHECK),
00176       interrupt_when_ally_sighted_button_(disp.video(), _("Interrupt move when an ally is sighted"), gui::button::TYPE_CHECK),
00177       show_grid_button_(disp.video(), _("Show grid"), gui::button::TYPE_CHECK),
00178       save_replays_button_(disp.video(), _("Save replays at the end of scenarios"), gui::button::TYPE_CHECK),
00179       delete_saves_button_(disp.video(), _("Delete auto-saves at the end of scenarios"), gui::button::TYPE_CHECK),
00180       show_lobby_joins_button1_(disp.video(), _("Do not show lobby joins"), gui::button::TYPE_CHECK),
00181       show_lobby_joins_button2_(disp.video(), _("Show lobby joins of friends only"), gui::button::TYPE_CHECK),
00182       show_lobby_joins_button3_(disp.video(), _("Show all lobby joins"), gui::button::TYPE_CHECK),
00183       new_lobby_button_(disp.video(), _("Use new lobby interface"), gui::button::TYPE_CHECK),
00184       sort_list_by_group_button_(disp.video(), _("Sort lobby list"), gui::button::TYPE_CHECK),
00185       iconize_list_button_(disp.video(), _("Iconize lobby list"), gui::button::TYPE_CHECK),
00186       remember_pw_button_(disp.video(), _("Save password to preferences (plain text)"), gui::button::TYPE_CHECK),
00187       mp_server_search_button_(disp.video(), _("Set Path to wesnothd")),
00188       friends_list_button_(disp.video(), _("Friends List")),
00189       friends_back_button_(disp.video(), _("Multiplayer Options")),
00190       friends_add_friend_button_(disp.video(), _("Add As Friend")),
00191       friends_add_ignore_button_(disp.video(), _("Add As Ignore")),
00192       friends_remove_button_(disp.video(), _("Remove")),
00193       show_floating_labels_button_(disp.video(), _("Show floating labels"), gui::button::TYPE_CHECK),
00194       turn_dialog_button_(disp.video(), _("Turn dialog"), gui::button::TYPE_CHECK),
00195       whiteboard_on_start_button_(disp.video(), _("Enable planning mode on start"), gui::button::TYPE_CHECK),
00196       hide_whiteboard_button_(disp.video(), _("Hide allies’ plans by default"), gui::button::TYPE_CHECK),
00197       turn_bell_button_(disp.video(), _("Turn bell"), gui::button::TYPE_CHECK),
00198       show_team_colors_button_(disp.video(), _("Show team colors"), gui::button::TYPE_CHECK),
00199       show_color_cursors_button_(disp.video(), _("Show color cursors"), gui::button::TYPE_CHECK),
00200       show_haloing_button_(disp.video(), _("Show haloing effects"), gui::button::TYPE_CHECK),
00201       video_mode_button_(disp.video(), _("Change Resolution")),
00202       theme_button_(disp.video(), _("Theme")),
00203       hotkeys_button_(disp.video(), _("Hotkeys")),
00204       advanced_button_(disp.video(), "", gui::button::TYPE_CHECK),
00205       sound_button_(disp.video(), _("Sound effects"), gui::button::TYPE_CHECK),
00206       music_button_(disp.video(), _("Music"), gui::button::TYPE_CHECK),
00207       chat_timestamp_button_(disp.video(), _("Chat timestamping"), gui::button::TYPE_CHECK),
00208       advanced_sound_button_(disp.video(), _("sound^Advanced Options")),
00209       normal_sound_button_(disp.video(), _("sound^Standard Options")),
00210       UI_sound_button_(disp.video(), _("User interface sounds"), gui::button::TYPE_CHECK),
00211       sample_rate_button1_(disp.video(), "22050", gui::button::TYPE_CHECK),
00212       sample_rate_button2_(disp.video(), "44100", gui::button::TYPE_CHECK),
00213       sample_rate_button3_(disp.video(), _("Custom"), gui::button::TYPE_CHECK),
00214       confirm_sound_button_(disp.video(), _("Apply")),
00215       idle_anim_button_(disp.video(), _("Show unit idle animations"), gui::button::TYPE_CHECK),
00216       standing_anim_button_(disp.video(), _("Show unit standing animations"), gui::button::TYPE_CHECK),
00217       animate_map_button_(disp.video(), _("Animate map"), gui::button::TYPE_CHECK),
00218 
00219       music_label_(disp.video(), _("Volume:"), font::SIZE_SMALL),
00220       sound_label_(disp.video(), _("Volume:"), font::SIZE_SMALL),
00221       UI_sound_label_(disp.video(), _("Volume:"), font::SIZE_SMALL),
00222       bell_label_(disp.video(), _("Volume:"), font::SIZE_SMALL),
00223 
00224       scroll_label_(disp.video(), _("Scroll speed:")),
00225       chat_lines_label_(disp.video(), ""),
00226       turbo_slider_label_(disp.video(), "", font::SIZE_SMALL ),
00227       sample_rate_label_(disp.video(), _("Sample rate (Hz):")), buffer_size_label_(disp.video(), ""),
00228       idle_anim_slider_label_(disp.video(), _("Frequency:"), font::SIZE_SMALL ),
00229       autosavemax_slider_label_(disp.video(), "", font::SIZE_SMALL),
00230       advanced_slider_label_(disp.video(), "", font::SIZE_SMALL),
00231 
00232       sample_rate_input_(disp.video(), 70),
00233       friends_input_(disp.video(), 170),
00234 
00235       slider_label_width_(0),
00236       advanced_(disp.video(),std::vector<std::string>(),false,-1,-1,NULL,&gui::menu::bluebg_style),
00237       friends_(disp.video(),std::vector<std::string>(),false,-1,-1,NULL,&gui::menu::bluebg_style),
00238 
00239       advanced_selection_(-1),
00240       friends_selection_(-1),
00241 
00242       tab_(GENERAL_TAB), disp_(disp), game_cfg_(game_cfg), adv_preferences_cfg_(), parent(NULL)
00243 {
00244     sort_advanced_preferences();
00245 
00246     // FIXME: this box should be vertically centered on the screen, but is not
00247     set_measurements(465, 400);
00248 
00249 
00250     sound_button_.set_check(sound_on());
00251     sound_button_.set_help_string(_("Sound effects on/off"));
00252     sound_slider_.set_min(0);
00253     sound_slider_.set_max(128);
00254     sound_slider_.set_value(sound_volume());
00255     sound_slider_.set_help_string(_("Change the sound effects volume"));
00256 
00257     music_button_.set_check(music_on());
00258     music_button_.set_help_string(_("Music on/off"));
00259     music_slider_.set_min(0);
00260     music_slider_.set_max(128);
00261     music_slider_.set_value(music_volume());
00262     music_slider_.set_help_string(_("Change the music volume"));
00263 
00264     // bell volume slider
00265     bell_slider_.set_min(0);
00266     bell_slider_.set_max(128);
00267     bell_slider_.set_value(bell_volume());
00268     bell_slider_.set_help_string(_("Change the bell volume"));
00269 
00270     UI_sound_button_.set_check(UI_sound_on());
00271     UI_sound_button_.set_help_string(_("Turn menu and button sounds on/off"));
00272     UI_sound_slider_.set_min(0);
00273     UI_sound_slider_.set_max(128);
00274     UI_sound_slider_.set_value(UI_volume());
00275     UI_sound_slider_.set_help_string(_("Change the sound volume for button clicks, etc."));
00276 
00277     sample_rate_label_.set_help_string(_("Change the sample rate"));
00278     std::string rate = lexical_cast<std::string>(sample_rate());
00279     if (rate == "22050")
00280         sample_rate_button1_.set_check(true);
00281     else if (rate == "44100")
00282         sample_rate_button2_.set_check(true);
00283     else
00284         sample_rate_button3_.set_check(true);
00285     sample_rate_input_.set_text(rate);
00286     sample_rate_input_.set_help_string(_("User defined sample rate"));
00287     confirm_sound_button_.enable(sample_rate_button3_.checked());
00288 
00289     buffer_size_slider_.set_min(0);
00290     buffer_size_slider_.set_max(3);
00291     int v = sound_buffer_size()/512 - 1;
00292     buffer_size_slider_.set_value(v);
00293     //avoid sound reset the first time we load advanced sound
00294     buffer_size_slider_.value_change();
00295     buffer_size_slider_.set_help_string(_("Change the buffer size"));
00296     std::stringstream buf;
00297     buf << _("Buffer size: ") << sound_buffer_size();
00298     buffer_size_label_.set_text(buf.str());
00299     buffer_size_label_.set_help_string(_("Change the buffer size"));
00300 
00301     scroll_slider_.set_min(1);
00302     scroll_slider_.set_max(100);
00303     scroll_slider_.set_value(scroll_speed());
00304     scroll_slider_.set_help_string(_("Change the speed of scrolling around the map"));
00305 
00306     chat_lines_slider_.set_min(1);
00307     chat_lines_slider_.set_max(20);
00308     chat_lines_slider_.set_value(chat_lines());
00309     chat_lines_slider_.set_help_string(_("Set the amount of chat lines shown"));
00310     // Have the tooltip appear over the static "Chat lines" label, too.
00311     chat_lines_label_.set_help_string(_("Set the amount of chat lines shown"));
00312 
00313     chat_timestamp_button_.set_check(chat_timestamping());
00314     chat_timestamp_button_.set_help_string(_("Add a timestamp to chat messages"));
00315 
00316     fullscreen_button_.set_check(fullscreen());
00317     fullscreen_button_.set_help_string(_("Choose whether the game should run full screen or in a window"));
00318 
00319     turbo_button_.set_check(turbo());
00320     turbo_button_.set_help_string(_("Make units move and fight faster"));
00321 
00322     std::vector< double > turbo_items;
00323     turbo_items.push_back(0.25);
00324     turbo_items.push_back(0.5);
00325     turbo_items.push_back(0.75);
00326     turbo_items.push_back(1);
00327     turbo_items.push_back(1.25);
00328     turbo_items.push_back(1.5);
00329     turbo_items.push_back(1.75);
00330     turbo_items.push_back(2);
00331     turbo_items.push_back(3);
00332     turbo_items.push_back(4);
00333     turbo_items.push_back(8);
00334     turbo_items.push_back(16);
00335     turbo_slider_.set_items(turbo_items);
00336     if(!turbo_slider_.select_item(turbo_speed())) {
00337         turbo_slider_.select_item(1);
00338     }
00339     turbo_slider_.set_help_string(_("Units move and fight speed"));
00340 
00341     idle_anim_button_.set_check(idle_anim());
00342     idle_anim_button_.set_help_string(_("Play short random animations for idle units"));
00343 
00344     standing_anim_button_.set_check(show_standing_animations());
00345     standing_anim_button_.set_help_string(_("Continuously animate standing units in the battlefield"));
00346 
00347     animate_map_button_.set_check(animate_map());
00348     animate_map_button_.set_help_string(_("Display animated terrain graphics"));
00349 
00350     // exponential scale (2^(n/10))
00351     idle_anim_slider_.set_min(-40);
00352     idle_anim_slider_.set_max(30);
00353     idle_anim_slider_.set_value(idle_anim_rate());
00354     idle_anim_slider_.set_help_string(_("Set the frequency of unit idle animations"));
00355 
00356     autosavemax_slider_.set_min(1); //at least one autosave is stored
00357     autosavemax_slider_.set_max(preferences::INFINITE_AUTO_SAVES);
00358     autosavemax_slider_.set_value(autosavemax());
00359     autosavemax_slider_.set_help_string(_("Set maximum number of automatic saves to be retained"));
00360 
00361 
00362     show_ai_moves_button_.set_check(!show_ai_moves());
00363     show_ai_moves_button_.set_help_string(_("Do not animate AI units moving"));
00364 
00365     interrupt_when_ally_sighted_button_.set_check(interrupt_when_ally_sighted());
00366     interrupt_when_ally_sighted_button_.set_help_string(_("Sighting an allied unit interrupts your unit’s movement"));
00367 
00368     save_replays_button_.set_check(save_replays());
00369     save_replays_button_.set_help_string(_("Saves replays of games on victory in all modes and defeat in multiplayer"));
00370 
00371     delete_saves_button_.set_check(delete_saves());
00372     delete_saves_button_.set_help_string(_("Deletes previous auto-saves on victory in all modes and defeat in multiplayer"));
00373     show_grid_button_.set_check(grid());
00374     show_grid_button_.set_help_string(_("Overlay a grid onto the map"));
00375 
00376     sort_list_by_group_button_.set_check(sort_list());
00377     sort_list_by_group_button_.set_help_string(_("Sort the player list in the lobby by player groups"));
00378 
00379     iconize_list_button_.set_check(iconize_list());
00380     iconize_list_button_.set_help_string(_("Show icons in front of the player names in the lobby"));
00381 
00382     remember_pw_button_.set_check(remember_password());
00383     remember_pw_button_.set_help_string(_("Uncheck to delete the saved password (on exit)"));
00384 
00385     int lj = lobby_joins();
00386     show_lobby_joins_button1_.set_check(lj == SHOW_NONE);
00387     show_lobby_joins_button1_.set_help_string(_("Do not show messages about players joining the multiplayer lobby"));
00388     show_lobby_joins_button2_.set_check(lj == SHOW_FRIENDS);
00389     show_lobby_joins_button2_.set_help_string(_("Show messages about your friends joining the multiplayer lobby"));
00390     show_lobby_joins_button3_.set_check(lj == SHOW_ALL);
00391     show_lobby_joins_button3_.set_help_string(_("Show messages about all players joining the multiplayer lobby"));
00392 
00393     new_lobby_button_.set_check(new_lobby());
00394     new_lobby_button_.set_help_string(_("Use New Lobby Interface"));
00395 
00396     mp_server_search_button_.set_help_string(_("Find and set path to MP server to host LAN games"));
00397     friends_list_button_.set_help_string(_("View and edit your friends and ignores list"));
00398     friends_back_button_.set_help_string(_("Back to the multiplayer options"));
00399     friends_add_friend_button_.set_help_string(_("Add this username to your friends list"));
00400     friends_add_ignore_button_.set_help_string(_("Add this username to your ignores list"));
00401     friends_remove_button_.set_help_string(_("Remove this username from your list"));
00402 
00403     friends_input_.set_text("");
00404     friends_input_.set_help_string(_("Insert a username"));
00405 
00406     show_floating_labels_button_.set_check(show_floating_labels());
00407     show_floating_labels_button_.set_help_string(_("Show text above a unit when it is hit to display damage inflicted"));
00408 
00409     video_mode_button_.set_help_string(_("Change the resolution the game runs at"));
00410     theme_button_.set_help_string(_("Change the theme the game runs with"));
00411 
00412     turn_dialog_button_.set_check(turn_dialog());
00413     turn_dialog_button_.set_help_string(_("Display a dialog at the beginning of your turn"));
00414 
00415     whiteboard_on_start_button_.set_check(enable_whiteboard_mode_on_start());
00416     whiteboard_on_start_button_.set_help_string(_("Activates Planning Mode on game start"));
00417 
00418     hide_whiteboard_button_.set_check(hide_whiteboard());
00419     hide_whiteboard_button_.set_help_string(_("Hides allies’ Planning Mode plans in multiplayer games"));
00420 
00421     turn_bell_button_.set_check(turn_bell());
00422     turn_bell_button_.set_help_string(_("Play a bell sound at the beginning of your turn"));
00423 
00424     show_team_colors_button_.set_check(show_side_colors());
00425     show_team_colors_button_.set_help_string(_("Show a colored circle around the base of each unit to show which side it is on"));
00426 
00427     show_color_cursors_button_.set_check(use_color_cursors());
00428     show_color_cursors_button_.set_help_string(_("Use colored mouse cursors (may be slower)"));
00429 
00430     show_haloing_button_.set_check(show_haloes());
00431     show_haloing_button_.set_help_string(_("Use graphical special effects (may be slower)"));
00432 
00433     hotkeys_button_.set_help_string(_("View and configure keyboard shortcuts"));
00434 
00435     set_advanced_menu();
00436     set_friends_menu();
00437 }
00438 
00439 handler_vector preferences_dialog::handler_members()
00440 {
00441     handler_vector h;
00442     h.push_back(&music_slider_);
00443     h.push_back(&sound_slider_);
00444     h.push_back(&bell_slider_);
00445     h.push_back(&UI_sound_slider_);
00446     h.push_back(&scroll_slider_);
00447     h.push_back(&chat_lines_slider_);
00448     h.push_back(&turbo_slider_);
00449     h.push_back(&idle_anim_slider_);
00450     h.push_back(&autosavemax_slider_);
00451     h.push_back(&buffer_size_slider_);
00452     h.push_back(&advanced_slider_);
00453     h.push_back(&fullscreen_button_);
00454     h.push_back(&turbo_button_);
00455     h.push_back(&idle_anim_button_);
00456     h.push_back(&standing_anim_button_);
00457     h.push_back(&animate_map_button_);
00458     h.push_back(&show_ai_moves_button_);
00459     h.push_back(&interrupt_when_ally_sighted_button_);
00460     h.push_back(&save_replays_button_);
00461     h.push_back(&delete_saves_button_);
00462     h.push_back(&show_grid_button_);
00463     h.push_back(&sort_list_by_group_button_);
00464     h.push_back(&iconize_list_button_);
00465     h.push_back(&remember_pw_button_);
00466     h.push_back(&show_lobby_joins_button1_);
00467     h.push_back(&show_lobby_joins_button2_);
00468     h.push_back(&show_lobby_joins_button3_);
00469     h.push_back(&new_lobby_button_);
00470     h.push_back(&mp_server_search_button_);
00471     h.push_back(&friends_list_button_);
00472     h.push_back(&friends_back_button_);
00473     h.push_back(&friends_add_friend_button_);
00474     h.push_back(&friends_add_ignore_button_);
00475     h.push_back(&friends_remove_button_);
00476     h.push_back(&friends_input_);
00477     h.push_back(&show_floating_labels_button_);
00478     h.push_back(&turn_dialog_button_);
00479     h.push_back(&whiteboard_on_start_button_);
00480     h.push_back(&hide_whiteboard_button_);
00481     h.push_back(&turn_bell_button_);
00482     h.push_back(&UI_sound_button_);
00483     h.push_back(&show_team_colors_button_);
00484     h.push_back(&show_color_cursors_button_);
00485     h.push_back(&show_haloing_button_);
00486     h.push_back(&video_mode_button_);
00487     h.push_back(&theme_button_);
00488     h.push_back(&hotkeys_button_);
00489     h.push_back(&advanced_button_);
00490     h.push_back(&sound_button_);
00491     h.push_back(&music_button_);
00492     h.push_back(&chat_timestamp_button_);
00493     h.push_back(&advanced_sound_button_);
00494     h.push_back(&normal_sound_button_);
00495     h.push_back(&sample_rate_button1_);
00496     h.push_back(&sample_rate_button2_);
00497     h.push_back(&sample_rate_button3_);
00498     h.push_back(&confirm_sound_button_);
00499     h.push_back(&music_label_);
00500     h.push_back(&sound_label_);
00501     h.push_back(&bell_label_);
00502     h.push_back(&UI_sound_label_);
00503     h.push_back(&scroll_label_);
00504     h.push_back(&turbo_slider_label_);
00505     h.push_back(&idle_anim_slider_label_);
00506     h.push_back(&autosavemax_slider_label_);
00507     h.push_back(&advanced_slider_label_);
00508     h.push_back(&chat_lines_label_);
00509     h.push_back(&sample_rate_label_);
00510     h.push_back(&buffer_size_label_);
00511     h.push_back(&sample_rate_input_);
00512     h.push_back(&advanced_);
00513     h.push_back(&friends_);
00514     return h;
00515 }
00516 
00517 void preferences_dialog::update_location(SDL_Rect const &rect)
00518 {
00519     bg_register(rect);
00520 
00521 
00522     const int right_border = font::relative_size(10);
00523     const int horizontal_padding = 25;
00524     // please also check 800x480 resolution if you change these spacings
00525     const int top_border = 10;
00526     const int bottom_border = 10;
00527     const int short_interline = 21;
00528     const int item_interline = 40;
00529     const int bottom_row_y = rect.y + rect.h - bottom_border;
00530 
00531     // General tab
00532     int ypos = rect.y + top_border;
00533     scroll_label_.set_location(rect.x, ypos);
00534     SDL_Rect scroll_rect = create_rect(rect.x + scroll_label_.width()
00535             , ypos
00536             , rect.w - scroll_label_.width() - right_border
00537             , 0);
00538 
00539     scroll_slider_.set_location(scroll_rect);
00540     ypos += item_interline; turbo_button_.set_location(rect.x, ypos);
00541     ypos += short_interline; turbo_slider_label_.set_location(rect.x + horizontal_padding, ypos);
00542     ypos += short_interline;
00543     SDL_Rect turbo_rect = create_rect(rect.x + horizontal_padding
00544             , ypos
00545             , rect.w - horizontal_padding - right_border
00546             , 0);
00547 
00548     turbo_slider_.set_location(turbo_rect);
00549     ypos += item_interline; show_ai_moves_button_.set_location(rect.x, ypos);
00550     ypos += short_interline; turn_dialog_button_.set_location(rect.x, ypos);
00551     ypos += short_interline; whiteboard_on_start_button_.set_location(rect.x, ypos);
00552     ypos += short_interline; hide_whiteboard_button_.set_location(rect.x, ypos);
00553     ypos += short_interline; interrupt_when_ally_sighted_button_.set_location(rect.x, ypos);
00554     ypos += item_interline; save_replays_button_.set_location(rect.x, ypos);
00555     ypos += short_interline; delete_saves_button_.set_location(rect.x, ypos);
00556     ypos += short_interline; autosavemax_slider_label_.set_location(rect.x + horizontal_padding, ypos);
00557     SDL_Rect autosavemax_rect = create_rect(rect.x + horizontal_padding
00558             , ypos + short_interline
00559             , rect.w - horizontal_padding - right_border
00560             , 0);
00561 
00562     autosavemax_slider_.set_location(autosavemax_rect);
00563     hotkeys_button_.set_location(rect.x, bottom_row_y - hotkeys_button_.height());
00564 
00565     // Display tab
00566     ypos = rect.y + top_border;
00567     fullscreen_button_.set_location(rect.x, ypos);
00568 
00569     ypos += item_interline; show_color_cursors_button_.set_location(rect.x, ypos);
00570     ypos += item_interline; show_floating_labels_button_.set_location(rect.x, ypos);
00571     ypos += item_interline; show_haloing_button_.set_location(rect.x, ypos);
00572     ypos += item_interline; show_team_colors_button_.set_location(rect.x, ypos);
00573     ypos += item_interline; show_grid_button_.set_location(rect.x, ypos);
00574 
00575     ypos += item_interline; animate_map_button_.set_location(rect.x, ypos);
00576     ypos += short_interline; standing_anim_button_.set_location(rect.x, ypos);
00577     ypos += short_interline; idle_anim_button_.set_location(rect.x, ypos);
00578     ypos += short_interline;
00579     idle_anim_slider_label_.set_location(rect.x + horizontal_padding, ypos);
00580     SDL_Rect idle_anim_rect = create_rect(rect.x + horizontal_padding + idle_anim_slider_label_.width()
00581             , ypos
00582             , rect.w - horizontal_padding - idle_anim_slider_label_.width() - right_border
00583             , 0);
00584     idle_anim_slider_.set_location(idle_anim_rect);
00585 
00586     video_mode_button_.set_location(rect.x, bottom_row_y - video_mode_button_.height());
00587     theme_button_.set_location(rect.x + video_mode_button_.width() + 10,
00588                                bottom_row_y - theme_button_.height());
00589 
00590     // Sound tab
00591     slider_label_width_ = std::max<unsigned>(music_label_.width(), sound_label_.width());
00592     slider_label_width_ = std::max<unsigned>(slider_label_width_, bell_label_.width());
00593     slider_label_width_ = std::max<unsigned>(slider_label_width_, UI_sound_label_.width());
00594     ypos = rect.y + top_border;
00595     sound_button_.set_location(rect.x, ypos);
00596 
00597     ypos += short_interline;
00598     sound_label_.set_location(rect.x + horizontal_padding, ypos);
00599     const SDL_Rect sound_rect = create_rect(rect.x + horizontal_padding + slider_label_width_
00600             , ypos
00601             , rect.w - slider_label_width_ - horizontal_padding - right_border
00602             , 0);
00603     sound_slider_.set_location(sound_rect);
00604 
00605     ypos += item_interline;
00606     music_button_.set_location(rect.x, ypos);
00607 
00608     ypos += short_interline;
00609     music_label_.set_location(rect.x + horizontal_padding, ypos);
00610     const SDL_Rect music_rect = create_rect(rect.x + horizontal_padding + slider_label_width_
00611             , ypos
00612             , rect.w - slider_label_width_ - horizontal_padding - right_border
00613             , 0);
00614     music_slider_.set_location(music_rect);
00615 
00616     ypos += item_interline; //Bell slider
00617     turn_bell_button_.set_location(rect.x, ypos);
00618     ypos += short_interline;
00619     bell_label_.set_location(rect.x + horizontal_padding, ypos);
00620     const SDL_Rect bell_rect = create_rect(rect.x + horizontal_padding + slider_label_width_
00621             , ypos
00622             , rect.w - slider_label_width_ - horizontal_padding - right_border
00623             , 0);
00624     bell_slider_.set_location(bell_rect);
00625 
00626     ypos += item_interline; //UI sound slider
00627     UI_sound_button_.set_location(rect.x, ypos);
00628     ypos += short_interline;
00629     UI_sound_label_.set_location(rect.x + horizontal_padding, ypos);
00630     const SDL_Rect UI_sound_rect = create_rect(rect.x + horizontal_padding + slider_label_width_
00631             , ypos
00632             , rect.w - slider_label_width_ - horizontal_padding - right_border
00633             , 0);
00634     UI_sound_slider_.set_location(UI_sound_rect);
00635     advanced_sound_button_.set_location(rect.x, bottom_row_y - advanced_sound_button_.height());
00636 
00637 
00638     //Advanced Sound tab
00639     ypos = rect.y + top_border;
00640     sample_rate_label_.set_location(rect.x, ypos);
00641     ypos += short_interline;
00642     int h_offset = rect.x + horizontal_padding;
00643     sample_rate_button1_.set_location(h_offset, ypos);
00644     ypos += short_interline;
00645     sample_rate_button2_.set_location(h_offset, ypos);
00646     ypos += short_interline;
00647     sample_rate_button3_.set_location(h_offset, ypos);
00648     h_offset += sample_rate_button3_.width() + 5;
00649     sample_rate_input_.set_location(h_offset, ypos);
00650     h_offset += sample_rate_input_.width() + 5;
00651     confirm_sound_button_.set_location(h_offset, ypos);
00652 
00653     ypos += item_interline;
00654     buffer_size_label_.set_location(rect.x, ypos);
00655     ypos += short_interline;
00656     SDL_Rect buffer_rect = create_rect(rect.x + horizontal_padding
00657             , ypos
00658             , rect.w - horizontal_padding - right_border
00659             , 0);
00660     buffer_size_slider_.set_location(buffer_rect);
00661     ypos += item_interline;
00662     normal_sound_button_.set_location(rect.x, bottom_row_y - normal_sound_button_.height());
00663 
00664 
00665     // Multiplayer tab
00666     ypos = rect.y + top_border;
00667     chat_lines_label_.set_location(rect.x, ypos);
00668     ypos += short_interline;
00669     SDL_Rect chat_lines_rect = create_rect(rect.x + horizontal_padding
00670             , ypos
00671             , rect.w - horizontal_padding - right_border
00672             , 0);
00673     chat_lines_slider_.set_location(chat_lines_rect);
00674     ypos += item_interline; chat_timestamp_button_.set_location(rect.x, ypos);
00675     ypos += item_interline; remember_pw_button_.set_location(rect.x, ypos);
00676     ypos += item_interline; sort_list_by_group_button_.set_location(rect.x, ypos);
00677     ypos += item_interline; iconize_list_button_.set_location(rect.x, ypos);
00678 
00679     ypos += item_interline; show_lobby_joins_button1_.set_location(rect.x, ypos);
00680     ypos += short_interline; show_lobby_joins_button2_.set_location(rect.x, ypos);
00681     ypos += short_interline; show_lobby_joins_button3_.set_location(rect.x, ypos);
00682 
00683     ypos += item_interline; new_lobby_button_.set_location(rect.x, ypos);
00684 
00685     friends_list_button_.set_location(rect.x, bottom_row_y - friends_list_button_.height());
00686 
00687     mp_server_search_button_.set_location(rect.x + 10 + friends_list_button_.width(), bottom_row_y - mp_server_search_button_.height());
00688 
00689     //Friends tab
00690     ypos = rect.y + top_border;
00691     friends_input_.set_location(rect.x,ypos);
00692 
00693     friends_.set_location(rect.x,ypos + item_interline);
00694     friends_.set_max_height(height() - 100 - friends_back_button_.height());
00695 
00696     int friends_xpos;
00697 
00698     if (friends_.width() > friends_input_.width()) {
00699         friends_xpos = rect.x+  friends_.width() + 20;
00700     } else {
00701         friends_xpos = rect.x+  friends_input_.width() + 20;
00702     }
00703     friends_.set_max_width(friends_xpos - rect.x - 1);
00704 
00705     friends_add_friend_button_.set_location(friends_xpos,ypos);
00706     ypos += short_interline+3; friends_add_ignore_button_.set_location(friends_xpos,ypos);
00707     ypos += short_interline+3; friends_remove_button_.set_location(friends_xpos,ypos);
00708     friends_back_button_.set_location(rect.x, bottom_row_y - friends_back_button_.height());
00709 
00710     //Advanced tab
00711     ypos = rect.y + top_border;
00712     advanced_.set_location(rect.x,ypos);
00713     advanced_.set_max_height(height()-100);
00714 
00715     ypos += advanced_.height() + font::relative_size(14);
00716 
00717     advanced_button_.set_location(rect.x,ypos);
00718     advanced_slider_label_.set_location(rect.x,ypos);
00719     const SDL_Rect advanced_slider_rect = create_rect(rect.x
00720             , ypos + short_interline
00721             , rect.w - right_border
00722             , 0);
00723     advanced_slider_.set_location(advanced_slider_rect);
00724 
00725     set_selection(tab_);
00726 }
00727 
00728 void preferences_dialog::process_event()
00729 {
00730     if (tab_ == GENERAL_TAB) {
00731         if (turbo_button_.pressed()) {
00732             set_turbo(turbo_button_.checked());
00733             turbo_slider_.enable(turbo());
00734             turbo_slider_label_.enable(turbo());
00735         }
00736         if (show_ai_moves_button_.pressed())
00737             set_show_ai_moves(!show_ai_moves_button_.checked());
00738         if (interrupt_when_ally_sighted_button_.pressed())
00739             set_interrupt_when_ally_sighted(interrupt_when_ally_sighted_button_.checked());
00740         if (save_replays_button_.pressed())
00741             set_save_replays(save_replays_button_.checked());
00742         if (delete_saves_button_.pressed())
00743             set_delete_saves(delete_saves_button_.checked());
00744         if (turn_dialog_button_.pressed())
00745             set_turn_dialog(turn_dialog_button_.checked());
00746         if (whiteboard_on_start_button_.pressed())
00747             set_enable_whiteboard_mode_on_start(whiteboard_on_start_button_.checked());
00748         if (hide_whiteboard_button_.pressed())
00749             set_hide_whiteboard(hide_whiteboard_button_.checked());
00750         if (hotkeys_button_.pressed()) {
00751             show_hotkeys_dialog(disp_);
00752             parent->clear_buttons();
00753         }
00754 
00755         set_scroll_speed(scroll_slider_.value());
00756         set_autosavemax(autosavemax_slider_.value());
00757         set_turbo_speed(turbo_slider_.item_selected());
00758 
00759         std::stringstream buf;
00760         buf << _("Speed: ") << turbo_slider_.item_selected();
00761         turbo_slider_label_.set_text(buf.str());
00762 
00763         std::stringstream buf2;
00764         if (autosavemax_slider_.value() == preferences::INFINITE_AUTO_SAVES)
00765             buf2 << _("Maximum auto-saves: ") << _("infinite");
00766         else
00767             buf2 << _("Maximum auto-saves: ") << autosavemax_slider_.value();
00768         autosavemax_slider_label_.set_text(buf2.str());
00769 
00770         return;
00771     }
00772 
00773     if (tab_ == DISPLAY_TAB) {
00774         if (show_floating_labels_button_.pressed())
00775             set_show_floating_labels(show_floating_labels_button_.checked());
00776         if (video_mode_button_.pressed())
00777             throw video_mode_change_exception(video_mode_change_exception::CHANGE_RESOLUTION);
00778         if (theme_button_.pressed())
00779             show_theme_dialog(disp_);
00780             parent->clear_buttons();
00781         if (fullscreen_button_.pressed())
00782             throw video_mode_change_exception(fullscreen_button_.checked()
00783                                             ? video_mode_change_exception::MAKE_FULLSCREEN
00784                                             : video_mode_change_exception::MAKE_WINDOWED);
00785         if (show_color_cursors_button_.pressed())
00786             set_color_cursors(show_color_cursors_button_.checked());
00787         if (show_haloing_button_.pressed())
00788             set_show_haloes(show_haloing_button_.checked());
00789         if (show_team_colors_button_.pressed())
00790             set_show_side_colors(show_team_colors_button_.checked());
00791         if (show_grid_button_.pressed())
00792             set_grid(show_grid_button_.checked());
00793         if (animate_map_button_.pressed())
00794             set_animate_map(animate_map_button_.checked());
00795         if (idle_anim_button_.pressed()) {
00796             const bool enable_idle_anim = idle_anim_button_.checked();
00797             idle_anim_slider_label_.enable(enable_idle_anim);
00798             idle_anim_slider_.enable(enable_idle_anim);
00799             set_idle_anim(enable_idle_anim);
00800             if (!enable_idle_anim)
00801                 idle_anim_slider_.set_value(0);
00802         }
00803         if (standing_anim_button_.pressed())
00804             set_show_standing_animations(standing_anim_button_.checked());
00805 
00806         set_idle_anim_rate(idle_anim_slider_.value());
00807 
00808         return;
00809     }
00810 
00811 
00812     if (tab_ == SOUND_TAB) {
00813         if (turn_bell_button_.pressed()) {
00814             if(!set_turn_bell(turn_bell_button_.checked()))
00815                 turn_bell_button_.set_check(false);
00816             bell_slider_.enable(turn_bell());
00817             bell_label_.enable(turn_bell());
00818         }
00819         if (sound_button_.pressed()) {
00820             if(!set_sound(sound_button_.checked()))
00821                 sound_button_.set_check(false);
00822             sound_slider_.enable(sound_on());
00823             sound_label_.enable(sound_on());
00824         }
00825         if (UI_sound_button_.pressed()) {
00826             if(!set_UI_sound(UI_sound_button_.checked()))
00827                 UI_sound_button_.set_check(false);
00828             UI_sound_slider_.enable(UI_sound_on());
00829             UI_sound_label_.enable(UI_sound_on());
00830         }
00831         set_sound_volume(sound_slider_.value());
00832         set_UI_volume(UI_sound_slider_.value());
00833         set_bell_volume(bell_slider_.value());
00834 
00835         if (music_button_.pressed()) {
00836             if(!set_music(music_button_.checked()))
00837                 music_button_.set_check(false);
00838             music_slider_.enable(music_on());
00839             music_label_.enable(music_on());
00840         }
00841         set_music_volume(music_slider_.value());
00842 
00843         if (advanced_sound_button_.pressed())
00844             set_selection(ADVANCED_SOUND_TAB);
00845 
00846         return;
00847     }
00848 
00849     if (tab_ == ADVANCED_SOUND_TAB) {
00850         bool apply = false;
00851         std::string rate;
00852 
00853         if (sample_rate_button1_.pressed()) {
00854             if (sample_rate_button1_.checked()) {
00855                 sample_rate_button2_.set_check(false);
00856                 sample_rate_button3_.set_check(false);
00857                 confirm_sound_button_.enable(false);
00858                 apply = true;
00859                 rate = "22050";
00860             } else
00861                 sample_rate_button1_.set_check(true);
00862         }
00863         if (sample_rate_button2_.pressed()) {
00864             if (sample_rate_button2_.checked()) {
00865                 sample_rate_button1_.set_check(false);
00866                 sample_rate_button3_.set_check(false);
00867                 confirm_sound_button_.enable(false);
00868                 apply = true;
00869                 rate = "44100";
00870             } else
00871                 sample_rate_button2_.set_check(true);
00872         }
00873         if (sample_rate_button3_.pressed()) {
00874             if (sample_rate_button3_.checked()) {
00875                 sample_rate_button1_.set_check(false);
00876                 sample_rate_button2_.set_check(false);
00877                 confirm_sound_button_.enable(true);
00878             } else
00879                 sample_rate_button3_.set_check(true);
00880         }
00881         if (confirm_sound_button_.pressed()) {
00882             apply = true;
00883             rate = sample_rate_input_.text();
00884         }
00885 
00886         if (apply)
00887             try {
00888             save_sample_rate(lexical_cast<unsigned int>(rate));
00889             } catch (bad_lexical_cast&) {
00890             }
00891 
00892         if (buffer_size_slider_.value_change()) {
00893             const size_t buffer_size = 512 << buffer_size_slider_.value();
00894             save_sound_buffer_size(buffer_size);
00895             std::stringstream buf;
00896             buf << _("Buffer size: ") << buffer_size;
00897             buffer_size_label_.set_text(buf.str());
00898         }
00899 
00900         if (normal_sound_button_.pressed())
00901             set_selection(SOUND_TAB);
00902 
00903         return;
00904     }
00905 
00906     if (tab_ == MULTIPLAYER_TAB) {
00907         if (show_lobby_joins_button1_.pressed()) {
00908             set_lobby_joins(SHOW_NONE);
00909             show_lobby_joins_button1_.set_check(true);
00910             show_lobby_joins_button2_.set_check(false);
00911             show_lobby_joins_button3_.set_check(false);
00912         } else if (show_lobby_joins_button2_.pressed()) {
00913             set_lobby_joins(SHOW_FRIENDS);
00914             show_lobby_joins_button1_.set_check(false);
00915             show_lobby_joins_button2_.set_check(true);
00916             show_lobby_joins_button3_.set_check(false);
00917         } else if (show_lobby_joins_button3_.pressed()) {
00918             set_lobby_joins(SHOW_ALL);
00919             show_lobby_joins_button1_.set_check(false);
00920             show_lobby_joins_button2_.set_check(false);
00921             show_lobby_joins_button3_.set_check(true);
00922         }
00923         if (new_lobby_button_.pressed())
00924             set_new_lobby(new_lobby_button_.checked());
00925         if (sort_list_by_group_button_.pressed())
00926             set_sort_list(sort_list_by_group_button_.checked());
00927         if (iconize_list_button_.pressed())
00928             set_iconize_list(iconize_list_button_.checked());
00929         if (remember_pw_button_.pressed())
00930             set_remember_password(remember_pw_button_.checked());
00931         if (chat_timestamp_button_.pressed())
00932             set_chat_timestamping(chat_timestamp_button_.checked());
00933         if (friends_list_button_.pressed())
00934             set_selection(FRIENDS_TAB);
00935 
00936         if (mp_server_search_button_.pressed())
00937         {
00938             std::string path = show_wesnothd_server_search(disp_);
00939             if (!path.empty())
00940             {
00941                 preferences::set_mp_server_program_name(path);
00942             }
00943             parent->clear_buttons();
00944         }
00945 
00946         set_chat_lines(chat_lines_slider_.value());
00947 
00948         //display currently select amount of chat lines
00949         std::stringstream buf;
00950         buf << _("Chat lines: ") << chat_lines_slider_.value();
00951         chat_lines_label_.set_text(buf.str());
00952 
00953         return;
00954     }
00955 
00956     if (tab_ == FRIENDS_TAB) {
00957         if(friends_.double_clicked() || friends_.selection() != friends_selection_) {
00958             friends_selection_ = friends_.selection();
00959             std::stringstream ss;
00960             ss << friends_names_[friends_.selection()];
00961             if (ss.str() != "(empty list)") friends_input_.set_text(ss.str());
00962             else friends_input_.set_text("");
00963         }
00964         if (friends_back_button_.pressed())
00965             set_selection(MULTIPLAYER_TAB);
00966 
00967         if (friends_add_friend_button_.pressed()) {
00968             if (preferences::add_friend(friends_input_.text())) {
00969                 friends_input_.clear();
00970                 set_friends_menu();
00971             } else {
00972                 gui2::show_transient_error_message(disp_.video(), _("Invalid username"));
00973             }
00974         }
00975         if (friends_add_ignore_button_.pressed()) {
00976             if (preferences::add_ignore(friends_input_.text())) {
00977                 friends_input_.clear();
00978                 set_friends_menu();
00979             } else {
00980                 gui2::show_transient_error_message(disp_.video(), _("Invalid username"));
00981             }
00982         }
00983         if (friends_remove_button_.pressed()) {
00984             std::string to_remove = friends_input_.text();
00985             if(to_remove.empty() && friends_.selection() >= 0 && friends_names_[friends_.selection()] != "(empty list)") {
00986                 to_remove = friends_names_[friends_.selection()];
00987             }
00988             if(!to_remove.empty()) {
00989                 /** @todo Better to remove from a specific relation. */
00990                 preferences::remove_friend(to_remove);
00991                 preferences::remove_ignore(to_remove);
00992                 friends_input_.clear();
00993                 set_friends_menu();
00994             }
00995         }
00996         return;
00997     }
00998 
00999     if (tab_ == ADVANCED_TAB) {
01000         if(advanced_.selection() != advanced_selection_) {
01001             advanced_selection_ = advanced_.selection();
01002             const config* const adv = get_advanced_pref();
01003             if(adv != NULL) {
01004                 const config& pref = *adv;
01005                 const std::string description = pref["description"];
01006                 std::string value = preferences::get(pref["field"]);
01007                 advanced_button_.hide(pref["type"] != "boolean");
01008                 const bool hide_int = pref["type"] != "int";
01009                 advanced_slider_.hide(hide_int);
01010                 advanced_slider_label_.hide(hide_int);
01011                 if(value.empty()) {
01012                     value = pref["default"].str();
01013                 }
01014                 if (pref["type"] == "boolean") {
01015                     advanced_button_.set_width(0);
01016                     advanced_button_.set_label(pref["name"]);
01017                     advanced_button_.set_check(value == "yes");
01018                     advanced_button_.set_help_string(description);
01019                 } else if (pref["type"] == "int") {
01020                     std::stringstream ss;
01021                     ss << pref["name"] << ": " << value;
01022                     advanced_slider_label_.set_text(ss.str());
01023                     advanced_slider_label_.set_help_string(description);
01024                     advanced_slider_.set_min(lexical_cast<int>(pref["min"]));
01025                     advanced_slider_.set_max(lexical_cast<int>(pref["max"]));
01026                     advanced_slider_.set_increment(pref["step"].to_int(1));
01027                     advanced_slider_.set_value(lexical_cast<int>(value));
01028                     advanced_slider_.set_help_string(description);
01029                 }
01030             }
01031         }
01032 
01033         const config* const adv = get_advanced_pref();
01034         if(advanced_button_.pressed()) {
01035             if(adv != NULL) {
01036                 const config& pref = *adv;
01037                 preferences::set(pref["field"],
01038                         advanced_button_.checked());
01039                 set_advanced_menu();
01040             }
01041         }
01042 
01043         if(advanced_slider_.value_change()) {
01044             if(adv != NULL) {
01045                 const config& pref = *adv;
01046                 preferences::set(pref["field"],
01047                         str_cast(advanced_slider_.value()));
01048                 set_advanced_menu();
01049                 std::stringstream ss;
01050                 ss << pref["name"] << ": " << advanced_slider_.value();
01051                 advanced_slider_label_.set_text(ss.str());
01052             }
01053         }
01054 
01055         return;
01056     }
01057 }
01058 
01059 const config* preferences_dialog::get_advanced_pref() const
01060 {
01061     if(advanced_selection_ >= 0) {
01062         const size_t n = static_cast<size_t>(advanced_selection_);
01063         if (n < adv_preferences_cfg_.size()) {
01064             return &adv_preferences_cfg_[n];
01065         }
01066     }
01067 
01068     return NULL;
01069 }
01070 
01071 void preferences_dialog::set_advanced_menu()
01072 {
01073     std::vector<std::string> advanced_items;
01074     foreach (const config &adv, adv_preferences_cfg_)
01075     {
01076         std::ostringstream str;
01077         std::string field = preferences::get(adv["field"]);
01078         if(field.empty()) {
01079             field = adv["default"].str();
01080         }
01081 
01082         if(field == "yes") {
01083             field = _("yes");
01084         } else if(field == "no") {
01085             field = _("no");
01086         }
01087 
01088         str << adv["name"] << COLUMN_SEPARATOR << field;
01089         advanced_items.push_back(str.str());
01090     }
01091 
01092     advanced_.set_items(advanced_items,true,true);
01093 }
01094 
01095 void preferences_dialog::sort_advanced_preferences()
01096 {
01097     adv_preferences_cfg_.clear();
01098 
01099     foreach(const config& adv, game_cfg_.child_range("advanced_preference")) {
01100         adv_preferences_cfg_.push_back(adv);
01101     }
01102 
01103     std::sort(adv_preferences_cfg_.begin(), adv_preferences_cfg_.end(), advanced_preferences_sorter());
01104 }
01105 
01106 void preferences_dialog::set_friends_menu()
01107 {
01108     const std::set<std::string>& friends = preferences::get_friends();
01109     const std::set<std::string>& ignores = preferences::get_ignores();
01110 
01111     std::vector<std::string> friends_items;
01112     std::vector<std::string> friends_names;
01113     std::string const imgpre = IMAGE_PREFIX + std::string("misc/status-");
01114 
01115     std::set<std::string>::const_iterator i;
01116     for (i = friends.begin(); i != friends.end(); ++i)
01117     {
01118         friends_items.push_back(imgpre + "friend.png" + COLUMN_SEPARATOR
01119                 + *i + COLUMN_SEPARATOR + _("friend"));
01120         friends_names.push_back(*i);
01121     }
01122     for (i = ignores.begin(); i != ignores.end(); ++i)
01123     {
01124         friends_items.push_back(imgpre + "ignore.png" + COLUMN_SEPARATOR
01125                 + *i + COLUMN_SEPARATOR + _("ignored"));
01126         friends_names.push_back(*i);
01127     }
01128     if (friends_items.empty()) {
01129         friends_items.push_back(_("(empty list)"));
01130         friends_names.push_back("(empty list)");
01131     }
01132     friends_names_ = friends_names;
01133     friends_.set_items(friends_items,true,true);
01134 }
01135 
01136 void preferences_dialog::set_selection(int index)
01137 {
01138     tab_ = TAB(index);
01139     set_dirty();
01140     bg_restore();
01141 
01142     const bool hide_general = tab_ != GENERAL_TAB;
01143     scroll_label_.hide(hide_general);
01144     scroll_slider_.hide(hide_general);
01145     turbo_button_.hide(hide_general);
01146     turbo_slider_label_.hide(hide_general);
01147     turbo_slider_.hide(hide_general);
01148     turbo_slider_label_.enable(turbo());
01149     turbo_slider_.enable(turbo());
01150     show_ai_moves_button_.hide(hide_general);
01151     turn_dialog_button_.hide(hide_general);
01152     whiteboard_on_start_button_.hide(hide_general);
01153     hide_whiteboard_button_.hide(hide_general);
01154     interrupt_when_ally_sighted_button_.hide(hide_general);
01155     hotkeys_button_.hide(hide_general);
01156     save_replays_button_.hide(hide_general);
01157     delete_saves_button_.hide(hide_general);
01158     autosavemax_slider_label_.hide(hide_general);
01159     autosavemax_slider_label_.enable(!hide_general);
01160     autosavemax_slider_.hide(hide_general);
01161     autosavemax_slider_.enable(!hide_general);
01162 
01163     const bool hide_display = tab_ != DISPLAY_TAB;
01164     show_floating_labels_button_.hide(hide_display);
01165     show_color_cursors_button_.hide(hide_display);
01166     show_haloing_button_.hide(hide_display);
01167     fullscreen_button_.hide(hide_display);
01168     idle_anim_button_.hide(hide_display);
01169     idle_anim_slider_label_.hide(hide_display);
01170     idle_anim_slider_label_.enable(idle_anim());
01171     idle_anim_slider_.hide(hide_display);
01172     idle_anim_slider_.enable(idle_anim());
01173     standing_anim_button_.hide(hide_display);
01174     animate_map_button_.hide(hide_display);
01175     video_mode_button_.hide(hide_display);
01176     theme_button_.hide(hide_display);
01177     show_team_colors_button_.hide(hide_display);
01178     show_grid_button_.hide(hide_display);
01179 
01180     const bool hide_sound = tab_ != SOUND_TAB;
01181     music_button_.hide(hide_sound);
01182     music_label_.hide(hide_sound);
01183     music_slider_.hide(hide_sound);
01184     sound_button_.hide(hide_sound);
01185     sound_label_.hide(hide_sound);
01186     sound_slider_.hide(hide_sound);
01187     UI_sound_button_.hide(hide_sound);
01188     UI_sound_label_.hide(hide_sound);
01189     UI_sound_slider_.hide(hide_sound);
01190     turn_bell_button_.hide(hide_sound);
01191     bell_label_.hide(hide_sound);
01192     bell_slider_.hide(hide_sound);
01193     music_slider_.enable(music_on());
01194     bell_slider_.enable(turn_bell());
01195     sound_slider_.enable(sound_on());
01196     UI_sound_slider_.enable(UI_sound_on());
01197     music_label_.enable(music_on());
01198     bell_label_.enable(turn_bell());
01199     sound_label_.enable(sound_on());
01200     UI_sound_label_.enable(UI_sound_on());
01201     advanced_sound_button_.hide(hide_sound);
01202 
01203     const bool hide_advanced_sound = tab_ != ADVANCED_SOUND_TAB;
01204     sample_rate_label_.hide(hide_advanced_sound);
01205     sample_rate_button1_.hide(hide_advanced_sound);
01206     sample_rate_button2_.hide(hide_advanced_sound);
01207     sample_rate_button3_.hide(hide_advanced_sound);
01208     sample_rate_input_.hide(hide_advanced_sound);
01209     confirm_sound_button_.hide(hide_advanced_sound);
01210     buffer_size_label_.hide(hide_advanced_sound);
01211     buffer_size_slider_.hide(hide_advanced_sound);
01212     normal_sound_button_.hide(hide_advanced_sound);
01213 
01214     const bool hide_multiplayer = tab_ != MULTIPLAYER_TAB;
01215     chat_lines_label_.hide(hide_multiplayer);
01216     chat_lines_slider_.hide(hide_multiplayer);
01217     chat_timestamp_button_.hide(hide_multiplayer);
01218     sort_list_by_group_button_.hide(hide_multiplayer);
01219     iconize_list_button_.hide(hide_multiplayer);
01220     remember_pw_button_.hide(hide_multiplayer);
01221     show_lobby_joins_button1_.hide(hide_multiplayer);
01222     show_lobby_joins_button2_.hide(hide_multiplayer);
01223     show_lobby_joins_button3_.hide(hide_multiplayer);
01224     new_lobby_button_.hide(hide_multiplayer);
01225     friends_list_button_.hide(hide_multiplayer);
01226     mp_server_search_button_.hide(hide_multiplayer);
01227 
01228     const bool hide_friends = tab_ != FRIENDS_TAB;
01229     friends_.hide(hide_friends);
01230     friends_back_button_.hide(hide_friends);
01231     friends_add_friend_button_.hide(hide_friends);
01232     friends_add_ignore_button_.hide(hide_friends);
01233     friends_remove_button_.hide(hide_friends);
01234     friends_input_.hide(hide_friends);
01235 
01236     const bool hide_advanced = tab_ != ADVANCED_TAB;
01237     advanced_.hide(hide_advanced);
01238     std::string adv_type = get_advanced_pref() != NULL ? (*get_advanced_pref())["type"].str() : "";
01239     const bool hide_advanced_bool = hide_advanced || adv_type != "boolean";
01240     const bool hide_advanced_int = hide_advanced || adv_type != "int";
01241     advanced_button_.hide(hide_advanced_bool);
01242     advanced_slider_label_.hide(hide_advanced_int);
01243     advanced_slider_.hide(hide_advanced_int);
01244 }
01245 
01246 }
01247 
01248 void show_preferences_dialog(display& disp, const config& game_cfg)
01249 {
01250     std::vector<std::string> items;
01251 
01252     std::string const pre = IMAGE_PREFIX + std::string("icons/icon-");
01253     char const sep = COLUMN_SEPARATOR;
01254     items.push_back(pre + "general.png" + sep + sgettext("Prefs section^General"));
01255     items.push_back(pre + "display.png" + sep + sgettext("Prefs section^Display"));
01256     items.push_back(pre + "music.png" + sep + sgettext("Prefs section^Sound"));
01257     items.push_back(pre + "multiplayer.png" + sep + sgettext("Prefs section^Multiplayer"));
01258     items.push_back(pre + "advanced.png" + sep + sgettext("Advanced section^Advanced"));
01259 
01260     for(;;) {
01261         try {
01262             preferences_dialog dialog(disp,game_cfg);
01263             dialog.parent.assign(new preferences_parent_dialog(disp));
01264             dialog.parent->set_menu(items);
01265             dialog.parent->add_pane(&dialog);
01266             dialog.parent->show();
01267             return;
01268         } catch(preferences_dialog::video_mode_change_exception& e) {
01269             switch(e.type) {
01270             case preferences_dialog::video_mode_change_exception::CHANGE_RESOLUTION:
01271                 show_video_mode_dialog(disp);
01272                 break;
01273             case preferences_dialog::video_mode_change_exception::MAKE_FULLSCREEN:
01274                 set_fullscreen(true);
01275                 break;
01276             case preferences_dialog::video_mode_change_exception::MAKE_WINDOWED:
01277                 set_fullscreen(false);
01278                 break;
01279             }
01280 
01281             if(items[1].empty() || items[1][0] != '*') {
01282                 items[1] = "*" + items[1];
01283             }
01284         }
01285     }
01286 }
01287 
01288 bool show_theme_dialog(display& disp)
01289 {
01290     std::vector<std::string> options = disp.get_theme().get_known_themes();
01291     if(!options.empty()){
01292         gui2::tsimple_item_selector dlg(_("Choose Theme"), "", options);
01293 
01294         for(size_t k = 0; k < options.size(); ++k) {
01295             if(options[k] == preferences::theme()) {
01296                 dlg.set_selected_index(static_cast<int>(k));
01297             }
01298         }
01299 
01300         dlg.show(disp.video());
01301         const int action = dlg.selected_index();
01302 
01303         if(action >= 0){
01304         preferences::set_theme(options[action]);
01305         //it would be preferable for the new theme to take effect
01306         //immediately, however, this will have to do for now.
01307         gui2::show_transient_message(disp.video(),"",_("New theme will take effect on next new or loaded game."));
01308         return(1);
01309         }
01310     }else{
01311         gui2::show_transient_message(disp.video(),"",_("No known themes. Try changing from within an existing game."));
01312     }
01313     return(0);
01314 }
01315 
01316 std::string show_wesnothd_server_search(display& disp)
01317 {
01318     // Showing file_chooser so user can search the wesnothd
01319     std::string old_path = preferences::get_mp_server_program_name();
01320     size_t offset = old_path.rfind("/");
01321     if (offset != std::string::npos)
01322     {
01323         old_path = old_path.substr(0, offset);
01324     }
01325     else
01326     {
01327         old_path = "";
01328     }
01329 #ifndef _WIN32
01330 
01331 #ifndef WESNOTH_PREFIX
01332 #define WESNOTH_PREFIX "/usr"
01333 #endif
01334     const std::string filename = "wesnothd";
01335     std::string path = WESNOTH_PREFIX + std::string("/bin");
01336     if (!is_directory(path))
01337         path = get_cwd();
01338 
01339 #else
01340     const std::string filename = "wesnothd.exe";
01341     std::string path = get_cwd();
01342 #endif
01343     if (!old_path.empty()
01344             && is_directory(old_path))
01345     {
01346         path = old_path;
01347     }
01348 
01349     utils::string_map symbols;
01350 
01351     symbols["filename"] = filename;
01352 
01353     const std::string title = utils::interpolate_variables_into_string(
01354               _("Find $filename server binary to host networked games")
01355             , &symbols);
01356 
01357     int res = dialogs::show_file_chooser_dialog(disp, path, title, false, filename);
01358     if (res == 0)
01359         return path;
01360     else
01361         return "";
01362 }
01363 
01364 
01365 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:53 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs