game_preferences_display.cpp

Go to the documentation of this file.
00001 /* $Id: game_preferences_display.cpp 24144 2008-02-28 17:36:51Z soliton $ */
00002 /*
00003    Copyright (C) 2003 - 2008 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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 #include "global.hpp"
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "cursor.hpp"
00019 #include "display.hpp"
00020 #include "game_preferences.hpp"
00021 #include "gettext.hpp"
00022 #include "hotkeys.hpp"
00023 #include "marked-up_text.hpp"
00024 #include "preferences_display.hpp"
00025 #include "construct_dialog.hpp"
00026 #include "video.hpp"
00027 #include "wml_separators.hpp"
00028 #include "widgets/button.hpp"
00029 #include "widgets/label.hpp"
00030 #include "widgets/menu.hpp"
00031 #include "widgets/slider.hpp"
00032 #include "widgets/textbox.hpp"
00033 #include "scoped_resource.hpp"
00034 #include "theme.hpp"
00035 
00036 #include <vector>
00037 #include <string>
00038 
00039 namespace preferences {
00040 
00041 static void set_lobby_joins(int ison)
00042 {
00043     _set_lobby_joins(ison);
00044 }
00045 
00046 static void set_sort_list(bool ison)
00047 {
00048     _set_sort_list(ison);
00049 }
00050 
00051 static void set_iconize_list(bool ison)
00052 {
00053     _set_iconize_list(ison);
00054 }
00055 
00056 namespace {
00057 
00058 class preferences_parent_dialog : public gui::dialog
00059 {
00060 public:
00061     preferences_parent_dialog(display &disp) : dialog(disp, _("Preferences"),"",gui::CLOSE_ONLY),
00062         clear_buttons_(false) {}
00063     ~preferences_parent_dialog() {write_preferences();}
00064     void action(gui::dialog_process_info &info)
00065     {
00066         if(clear_buttons_) {
00067             info.clear_buttons();
00068             clear_buttons_ = false;
00069         }
00070     }
00071     void clear_buttons() { clear_buttons_ = true; }
00072 private:
00073     bool clear_buttons_;
00074 };
00075 
00076 class preferences_dialog : public gui::preview_pane
00077 {
00078 public:
00079     preferences_dialog(display& disp, const config& game_cfg);
00080 
00081     struct video_mode_change_exception
00082     {
00083         enum TYPE { CHANGE_RESOLUTION, MAKE_FULLSCREEN, MAKE_WINDOWED };
00084 
00085         video_mode_change_exception(TYPE type) : type(type)
00086         {}
00087 
00088         TYPE type;
00089     };
00090 
00091     virtual handler_vector handler_members();
00092 private:
00093 
00094     void process_event();
00095     bool left_side() const { return false; }
00096     void set_selection(int index);
00097     void update_location(SDL_Rect const &rect);
00098     const config* get_advanced_pref() const;
00099     void set_advanced_menu();
00100     void set_friends_menu();
00101     std::vector<std::string> friends_names_;
00102 
00103 //
00104     // change
00105     gui::slider music_slider_, sound_slider_, UI_sound_slider_, bell_slider_,
00106                 scroll_slider_, gamma_slider_, chat_lines_slider_,
00107       buffer_size_slider_, idle_anim_slider_, autosavemax_slider_;
00108     gui::list_slider<double> turbo_slider_;
00109     gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
00110             show_grid_button_, save_replays_button_, delete_saves_button_,
00111             show_lobby_joins_button1_,
00112             show_lobby_joins_button2_,
00113             show_lobby_joins_button3_,
00114             sort_list_by_group_button_, iconize_list_button_,
00115             friends_list_button_, friends_back_button_,
00116             friends_add_friend_button_, friends_add_ignore_button_,
00117             friends_remove_button_, show_floating_labels_button_,
00118             turn_dialog_button_, turn_bell_button_,
00119             show_team_colours_button_, show_colour_cursors_button_,
00120             show_haloing_button_, video_mode_button_,
00121             theme_button_, hotkeys_button_, gamma_button_,
00122             flip_time_button_, advanced_button_, sound_button_,
00123             music_button_, chat_timestamp_button_,
00124             advanced_sound_button_, normal_sound_button_,
00125             UI_sound_button_, sample_rate_button1_,
00126             sample_rate_button2_, sample_rate_button3_,
00127             confirm_sound_button_, idle_anim_button_;
00128     gui::label music_label_, sound_label_, UI_sound_label_, bell_label_,
00129                scroll_label_, gamma_label_, chat_lines_label_,
00130                turbo_slider_label_, sample_rate_label_, buffer_size_label_,
00131       idle_anim_slider_label_, autosavemax_slider_label_;
00132     gui::textbox sample_rate_input_, friends_input_;
00133 
00134     unsigned slider_label_width_;
00135 
00136     gui::menu advanced_, friends_;
00137     int advanced_selection_, friends_selection_;
00138 
00139     enum TAB {  GENERAL_TAB, DISPLAY_TAB, SOUND_TAB, MULTIPLAYER_TAB, ADVANCED_TAB,
00140                 /*extra tab*/
00141                 ADVANCED_SOUND_TAB, FRIENDS_TAB};
00142     TAB tab_;
00143     display &disp_;
00144     const config& game_cfg_;
00145 public:
00146     util::scoped_ptr<preferences_parent_dialog> parent;
00147 };
00148 
00149 //change
00150 preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
00151     : gui::preview_pane(disp.video()),
00152       music_slider_(disp.video()), sound_slider_(disp.video()),
00153       UI_sound_slider_(disp.video()), bell_slider_(disp.video()),
00154       scroll_slider_(disp.video()), gamma_slider_(disp.video()),
00155       chat_lines_slider_(disp.video()), buffer_size_slider_(disp.video()),
00156       idle_anim_slider_(disp.video()), autosavemax_slider_(disp.video()), 
00157       turbo_slider_(disp.video()),
00158 
00159 
00160       fullscreen_button_(disp.video(), _("Toggle Full Screen"), gui::button::TYPE_CHECK),
00161       turbo_button_(disp.video(), _("Accelerated Speed"), gui::button::TYPE_CHECK),
00162       show_ai_moves_button_(disp.video(), _("Skip AI Moves"), gui::button::TYPE_CHECK),
00163       show_grid_button_(disp.video(), _("Show Grid"), gui::button::TYPE_CHECK),
00164       save_replays_button_(disp.video(), _("Save Replay on SP/MP Victory or MP Defeat"), gui::button::TYPE_CHECK),
00165       delete_saves_button_(disp.video(), _("Delete Auto-Saves on SP/MP Victory or MP Defeat"), gui::button::TYPE_CHECK),
00166       show_lobby_joins_button1_(disp.video(), _("Do Not Show Lobby Joins"), gui::button::TYPE_CHECK),
00167       show_lobby_joins_button2_(disp.video(), _("Show Lobby Joins Of Friends Only"), gui::button::TYPE_CHECK),
00168       show_lobby_joins_button3_(disp.video(), _("Show All Lobby Joins"), gui::button::TYPE_CHECK),
00169       sort_list_by_group_button_(disp.video(), _("Sort Lobby List"), gui::button::TYPE_CHECK),
00170       iconize_list_button_(disp.video(), _("Iconize Lobby List"), gui::button::TYPE_CHECK),
00171       friends_list_button_(disp.video(), _("Friends List")),
00172       friends_back_button_(disp.video(), _("Multiplayer Options")),
00173       friends_add_friend_button_(disp.video(), _("Add As Friend")),
00174       friends_add_ignore_button_(disp.video(), _("Add As Ignore")),
00175       friends_remove_button_(disp.video(), _("Remove")),
00176       show_floating_labels_button_(disp.video(), _("Show Floating Labels"), gui::button::TYPE_CHECK),
00177       turn_dialog_button_(disp.video(), _("Turn Dialog"), gui::button::TYPE_CHECK),
00178       turn_bell_button_(disp.video(), _("Turn Bell"), gui::button::TYPE_CHECK),
00179       show_team_colours_button_(disp.video(), _("Show Team Colors"), gui::button::TYPE_CHECK),
00180       show_colour_cursors_button_(disp.video(), _("Show Color Cursors"), gui::button::TYPE_CHECK),
00181       show_haloing_button_(disp.video(), _("Show Haloing Effects"), gui::button::TYPE_CHECK),
00182       video_mode_button_(disp.video(), _("Change Resolution")),
00183       theme_button_(disp.video(), _("Theme")),
00184       hotkeys_button_(disp.video(), _("Hotkeys")),
00185       gamma_button_(disp.video(), _("Adjust Gamma"), gui::button::TYPE_CHECK),
00186       flip_time_button_(disp.video(), _("Reverse Time Graphics"), gui::button::TYPE_CHECK),
00187       advanced_button_(disp.video(), "", gui::button::TYPE_CHECK),
00188       sound_button_(disp.video(), _("Sound effects"), gui::button::TYPE_CHECK),
00189       music_button_(disp.video(), _("Music"), gui::button::TYPE_CHECK),
00190       chat_timestamp_button_(disp.video(), _("Chat Timestamping"), gui::button::TYPE_CHECK),
00191       advanced_sound_button_(disp.video(), _("sound^Advanced Options")),
00192       normal_sound_button_(disp.video(), _("sound^Standard Options")),
00193       UI_sound_button_(disp.video(), _("User Interface Sounds"), gui::button::TYPE_CHECK),
00194       sample_rate_button1_(disp.video(), "22050", gui::button::TYPE_CHECK),
00195       sample_rate_button2_(disp.video(), "44100", gui::button::TYPE_CHECK),
00196       sample_rate_button3_(disp.video(), _("Custom"), gui::button::TYPE_CHECK),
00197       confirm_sound_button_(disp.video(), _("Apply")),
00198       idle_anim_button_(disp.video(), _("Show Unit Idle Animations"), gui::button::TYPE_CHECK),
00199 
00200       music_label_(disp.video(), _("Music Volume:")), sound_label_(disp.video(), _("SFX Volume:")),
00201       UI_sound_label_(disp.video(), _("UI Sound Volume:")),
00202       bell_label_(disp.video(), _("Bell Volume:")), scroll_label_(disp.video(), _("Scroll Speed:")),
00203       gamma_label_(disp.video(), _("Gamma:")), chat_lines_label_(disp.video(), ""),
00204       turbo_slider_label_(disp.video(), "", font::SIZE_SMALL ),
00205       sample_rate_label_(disp.video(), _("Sample Rate (Hz):")), buffer_size_label_(disp.video(), ""),
00206       idle_anim_slider_label_(disp.video(), _("Frequency:")),
00207       autosavemax_slider_label_(disp.video(), "", font::SIZE_SMALL),
00208 
00209       sample_rate_input_(disp.video(), 70),
00210       friends_input_(disp.video(), 170),
00211 
00212       slider_label_width_(0),
00213       advanced_(disp.video(),std::vector<std::string>(),false,-1,-1,NULL,&gui::menu::bluebg_style),
00214       friends_(disp.video(),std::vector<std::string>(),false,-1,-1,NULL,&gui::menu::bluebg_style),
00215 
00216       advanced_selection_(-1),
00217       friends_selection_(-1),
00218 
00219       tab_(GENERAL_TAB), disp_(disp), game_cfg_(game_cfg), parent(NULL)
00220 {
00221     // FIXME: this box should be vertically centered on the screen, but is not
00222 #ifdef USE_TINY_GUI
00223     set_measurements(180, 180);       // FIXME: should compute this, but using what data ?
00224 #else
00225     set_measurements(440, 405);
00226 #endif
00227 
00228 
00229     sound_button_.set_check(sound_on());
00230     sound_button_.set_help_string(_("Sound effects on/off"));
00231     sound_slider_.set_min(0);
00232     sound_slider_.set_max(128);
00233     sound_slider_.set_value(sound_volume());
00234     sound_slider_.set_help_string(_("Change the sound effects volume"));
00235 
00236     music_button_.set_check(music_on());
00237     music_button_.set_help_string(_("Music on/off"));
00238     music_slider_.set_min(0);
00239     music_slider_.set_max(128);
00240     music_slider_.set_value(music_volume());
00241     music_slider_.set_help_string(_("Change the music volume"));
00242 
00243     // bell volume slider
00244     bell_slider_.set_min(0);
00245     bell_slider_.set_max(128);
00246     bell_slider_.set_value(bell_volume());
00247     bell_slider_.set_help_string(_("Change the bell volume"));
00248 
00249     UI_sound_button_.set_check(UI_sound_on());
00250     UI_sound_button_.set_help_string(_("Turn menu and button sounds on/off"));
00251     UI_sound_slider_.set_min(0);
00252     UI_sound_slider_.set_max(128);
00253     UI_sound_slider_.set_value(UI_volume());
00254     UI_sound_slider_.set_help_string(_("Change the sound volume for button clicks, etc."));
00255 
00256     sample_rate_label_.set_help_string(_("Change the sample rate"));
00257     std::string rate = lexical_cast<std::string>(sample_rate());
00258     if (rate == "22050")
00259         sample_rate_button1_.set_check(true);
00260     else if (rate == "44100")
00261         sample_rate_button2_.set_check(true);
00262     else
00263         sample_rate_button3_.set_check(true);
00264     sample_rate_input_.set_text(rate);
00265     sample_rate_input_.set_help_string(_("User defined sample rate"));
00266     confirm_sound_button_.enable(sample_rate_button3_.checked());
00267 
00268     buffer_size_slider_.set_min(0);
00269     buffer_size_slider_.set_max(3);
00270     int v = sound_buffer_size()/512 - 1;
00271     buffer_size_slider_.set_value(v);
00272     //avoid sound reset the first time we load advanced sound
00273     buffer_size_slider_.value_change();
00274     buffer_size_slider_.set_help_string(_("Change the buffer size"));
00275     std::stringstream buf;
00276     buf << _("Buffer Size: ") << sound_buffer_size();
00277     buffer_size_label_.set_text(buf.str());
00278     buffer_size_label_.set_help_string(_("Change the buffer size"));
00279 
00280     scroll_slider_.set_min(1);
00281     scroll_slider_.set_max(100);
00282     scroll_slider_.set_value(scroll_speed());
00283     scroll_slider_.set_help_string(_("Change the speed of scrolling around the map"));
00284 
00285     chat_lines_slider_.set_min(1);
00286     chat_lines_slider_.set_max(20);
00287     chat_lines_slider_.set_value(chat_lines());
00288     chat_lines_slider_.set_help_string(_("Set the amount of chat lines shown"));
00289     // Have the tooltip appear over the static "Chat lines" label, too.
00290     chat_lines_label_.set_help_string(_("Set the amount of chat lines shown"));
00291 
00292     chat_timestamp_button_.set_check(chat_timestamping());
00293     chat_timestamp_button_.set_help_string(_("Add a timestamp to chat messages"));
00294 
00295     gamma_button_.set_check(adjust_gamma());
00296     gamma_button_.set_help_string(_("Change the brightness of the display"));
00297 
00298     gamma_slider_.set_min(50);
00299     gamma_slider_.set_max(200);
00300     gamma_slider_.set_value(gamma());
00301     gamma_slider_.set_help_string(_("Change the brightness of the display"));
00302 
00303     fullscreen_button_.set_check(fullscreen());
00304     fullscreen_button_.set_help_string(_("Choose whether the game should run full screen or in a window"));
00305 
00306     turbo_button_.set_check(turbo());
00307     turbo_button_.set_help_string(_("Make units move and fight faster"));
00308 
00309     //0.25 0.5 1 2 4 8 16
00310     std::vector< double > turbo_items;
00311     turbo_items.push_back(0.25);
00312     turbo_items.push_back(0.5);
00313     turbo_items.push_back(0.75);
00314     turbo_items.push_back(1);
00315     turbo_items.push_back(1.5);
00316     turbo_items.push_back(2);
00317     turbo_items.push_back(4);
00318     turbo_items.push_back(8);
00319     turbo_items.push_back(16);
00320     turbo_slider_.set_items(turbo_items);
00321     if(!turbo_slider_.select_item(turbo_speed())) {
00322         turbo_slider_.select_item(1);
00323     }
00324     turbo_slider_.set_help_string(_("Units move and fight speed"));
00325 
00326     idle_anim_button_.set_check(idle_anim());
00327     idle_anim_button_.set_help_string(_("Show unit idle animations"));
00328 
00329     // exponential scale (2^(n/10))
00330     idle_anim_slider_.set_min(-40);
00331     idle_anim_slider_.set_max(30);
00332     idle_anim_slider_.set_value(idle_anim_rate());
00333     idle_anim_slider_.set_help_string(_("Set the frequency of unit idle animations"));
00334 
00335     autosavemax_slider_.set_min(1); //at least one autosave is stored
00336     autosavemax_slider_.set_max(preferences::INFINITE_AUTO_SAVES);
00337     autosavemax_slider_.set_value(autosavemax());
00338     autosavemax_slider_.set_help_string(_("Set maximum number of automatic saves to be retained"));
00339 
00340 
00341     show_ai_moves_button_.set_check(!show_ai_moves());
00342     show_ai_moves_button_.set_help_string(_("Do not animate AI units moving"));
00343 
00344     save_replays_button_.set_check(save_replays());
00345     save_replays_button_.set_help_string(_("Save Replay on SP/MP Victory or MP Defeat"));
00346 
00347     delete_saves_button_.set_check(delete_saves());
00348     delete_saves_button_.set_help_string(_("Delete Auto-Saves on SP/MP Victory or MP Defeat"));
00349     show_grid_button_.set_check(grid());
00350     show_grid_button_.set_help_string(_("Overlay a grid onto the map"));
00351 
00352     sort_list_by_group_button_.set_check(sort_list());
00353     sort_list_by_group_button_.set_help_string(_("Sort the player list in the lobby by player groups"));
00354 
00355     iconize_list_button_.set_check(iconize_list());
00356     iconize_list_button_.set_help_string(_("Show icons in front of the player names in the lobby."));
00357 
00358     show_lobby_joins_button1_.set_check(lobby_joins() == SHOW_NONE);
00359     show_lobby_joins_button1_.set_help_string(_("Do not show messages about players joining the multiplayer lobby"));
00360     show_lobby_joins_button2_.set_check(lobby_joins() == SHOW_FRIENDS);
00361     show_lobby_joins_button2_.set_help_string(_("Show messages about your friends joining the multiplayer lobby"));
00362     show_lobby_joins_button3_.set_check(lobby_joins() == SHOW_ALL);
00363     show_lobby_joins_button3_.set_help_string(_("Show messages about all players joining the multiplayer lobby"));
00364 
00365     friends_list_button_.set_help_string(_("View and edit your friends and ignores list"));
00366     friends_back_button_.set_help_string(_("Back to the multiplayer options"));
00367     friends_add_friend_button_.set_help_string(_("Add this username to your friends list"));
00368     friends_add_ignore_button_.set_help_string(_("Add this username to your ignores list"));
00369     friends_remove_button_.set_help_string(_("Remove this username from your list"));
00370 
00371     friends_input_.set_text("");
00372     friends_input_.set_help_string(_("Insert a username"));
00373 
00374     show_floating_labels_button_.set_check(show_floating_labels());
00375     show_floating_labels_button_.set_help_string(_("Show text above a unit when it is hit to display damage inflicted"));
00376 
00377     video_mode_button_.set_help_string(_("Change the resolution the game runs at"));
00378     theme_button_.set_help_string(_("Change the theme the game runs with"));
00379 
00380     turn_dialog_button_.set_check(turn_dialog());
00381     turn_dialog_button_.set_help_string(_("Display a dialog at the beginning of your turn"));
00382 
00383     turn_bell_button_.set_check(turn_bell());
00384     turn_bell_button_.set_help_string(_("Play a bell sound at the beginning of your turn"));
00385 
00386     show_team_colours_button_.set_check(show_side_colours());
00387     show_team_colours_button_.set_help_string(_("Show a colored circle around the base of each unit to show which side it is on"));
00388 
00389     flip_time_button_.set_check(flip_time());
00390     flip_time_button_.set_help_string(_("Choose whether the sun moves left-to-right or right-to-left"));
00391 
00392     show_colour_cursors_button_.set_check(use_colour_cursors());
00393     show_colour_cursors_button_.set_help_string(_("Use colored mouse cursors (may be slower)"));
00394 
00395     show_haloing_button_.set_check(show_haloes());
00396     show_haloing_button_.set_help_string(_("Use graphical special effects (may be slower)"));
00397 
00398     hotkeys_button_.set_help_string(_("View and configure keyboard shortcuts"));
00399 
00400     set_advanced_menu();
00401     set_friends_menu();
00402 }
00403 
00404 handler_vector preferences_dialog::handler_members()
00405 {
00406     handler_vector h;
00407     h.push_back(&music_slider_);
00408     h.push_back(&sound_slider_);
00409     h.push_back(&bell_slider_);
00410     h.push_back(&UI_sound_slider_);
00411     h.push_back(&scroll_slider_);
00412     h.push_back(&gamma_slider_);
00413     h.push_back(&chat_lines_slider_);
00414     h.push_back(&turbo_slider_);
00415     h.push_back(&idle_anim_slider_);
00416     h.push_back(&autosavemax_slider_);
00417     h.push_back(&buffer_size_slider_);
00418     h.push_back(&fullscreen_button_);
00419     h.push_back(&turbo_button_);
00420     h.push_back(&idle_anim_button_);
00421     h.push_back(&show_ai_moves_button_);
00422     h.push_back(&save_replays_button_);
00423     h.push_back(&delete_saves_button_);
00424     h.push_back(&show_grid_button_);
00425     h.push_back(&sort_list_by_group_button_);
00426     h.push_back(&iconize_list_button_);
00427     h.push_back(&show_lobby_joins_button1_);
00428     h.push_back(&show_lobby_joins_button2_);
00429     h.push_back(&show_lobby_joins_button3_);
00430     h.push_back(&friends_list_button_);
00431     h.push_back(&friends_back_button_);
00432     h.push_back(&friends_add_friend_button_);
00433     h.push_back(&friends_add_ignore_button_);
00434     h.push_back(&friends_remove_button_);
00435     h.push_back(&friends_input_);
00436     h.push_back(&show_floating_labels_button_);
00437     h.push_back(&turn_dialog_button_);
00438     h.push_back(&turn_bell_button_);
00439     h.push_back(&UI_sound_button_);
00440     h.push_back(&show_team_colours_button_);
00441     h.push_back(&show_colour_cursors_button_);
00442     h.push_back(&show_haloing_button_);
00443     h.push_back(&video_mode_button_);
00444     h.push_back(&theme_button_);
00445     h.push_back(&hotkeys_button_);
00446     h.push_back(&gamma_button_);
00447     h.push_back(&flip_time_button_);
00448     h.push_back(&advanced_button_);
00449     h.push_back(&sound_button_);
00450     h.push_back(&music_button_);
00451     h.push_back(&chat_timestamp_button_);
00452     h.push_back(&advanced_sound_button_);
00453     h.push_back(&normal_sound_button_);
00454     h.push_back(&sample_rate_button1_);
00455     h.push_back(&sample_rate_button2_);
00456     h.push_back(&sample_rate_button3_);
00457     h.push_back(&confirm_sound_button_);
00458     h.push_back(&music_label_);
00459     h.push_back(&sound_label_);
00460     h.push_back(&bell_label_);
00461     h.push_back(&UI_sound_label_);
00462     h.push_back(&scroll_label_);
00463     h.push_back(&gamma_label_);
00464     h.push_back(&turbo_slider_label_);
00465     h.push_back(&idle_anim_slider_label_);
00466     h.push_back(&autosavemax_slider_label_);
00467     h.push_back(&chat_lines_label_);
00468     h.push_back(&sample_rate_label_);
00469     h.push_back(&buffer_size_label_);
00470     h.push_back(&sample_rate_input_);
00471     h.push_back(&advanced_);
00472     h.push_back(&friends_);
00473     return h;
00474 }
00475 
00476 void preferences_dialog::update_location(SDL_Rect const &rect)
00477 {
00478     bg_register(rect);
00479 
00480 
00481     const int right_border = font::relative_size(10);
00482     const int horizontal_padding = 25;
00483 #if USE_TINY_GUI
00484     const int top_border = 14;
00485     const int bottom_border = 0;
00486     const int short_interline = 20;
00487     const int item_interline = 20;
00488 #else
00489     // please also check 800x600 resolution if you change these spacings
00490     const int top_border = 28;
00491     const int bottom_border = 10;
00492     const int short_interline = 21;
00493     const int item_interline = 40;
00494 #endif
00495     const int bottom_row_y = rect.y + rect.h - bottom_border;
00496 
00497     // General tab
00498     int ypos = rect.y + top_border;
00499     scroll_label_.set_location(rect.x, ypos);
00500     SDL_Rect scroll_rect = { rect.x + scroll_label_.width(), ypos,
00501                             rect.w - scroll_label_.width() - right_border, 0 };
00502     scroll_slider_.set_location(scroll_rect);
00503     ypos += item_interline; turbo_button_.set_location(rect.x, ypos);
00504     ypos += short_interline; turbo_slider_label_.set_location(rect.x + horizontal_padding, ypos);
00505     ypos += short_interline;
00506     SDL_Rect turbo_rect = { rect.x + horizontal_padding, ypos,
00507                             rect.w - horizontal_padding - right_border, 0 };
00508     turbo_slider_.set_location(turbo_rect);
00509     ypos += item_interline; show_ai_moves_button_.set_location(rect.x, ypos);
00510     ypos += short_interline; turn_dialog_button_.set_location(rect.x, ypos);
00511     ypos += item_interline; show_team_colours_button_.set_location(rect.x, ypos);
00512     ypos += short_interline; show_grid_button_.set_location(rect.x, ypos);
00513     ypos += item_interline; save_replays_button_.set_location(rect.x, ypos);
00514     ypos += short_interline; delete_saves_button_.set_location(rect.x, ypos);
00515     ypos += short_interline; autosavemax_slider_label_.set_location(rect.x, ypos);
00516     SDL_Rect autosavemax_rect = { rect.x, ypos+short_interline,
00517                   rect.w - right_border, 0};
00518     autosavemax_slider_.set_location(autosavemax_rect);
00519     hotkeys_button_.set_location(rect.x, bottom_row_y - hotkeys_button_.height());
00520 
00521     // Display tab
00522     ypos = rect.y + top_border;
00523     gamma_button_.set_location(rect.x, ypos);
00524     ypos += short_interline;
00525     gamma_label_.set_location(rect.x, ypos);
00526     SDL_Rect gamma_rect = { rect.x + gamma_label_.width(), ypos,
00527                             rect.w - gamma_label_.width() - right_border, 0 };
00528     gamma_slider_.set_location(gamma_rect);
00529     ypos += item_interline; fullscreen_button_.set_location(rect.x, ypos);
00530     ypos += item_interline; show_colour_cursors_button_.set_location(rect.x, ypos);
00531     ypos += item_interline; flip_time_button_.set_location(rect.x,ypos);
00532     ypos += item_interline; show_floating_labels_button_.set_location(rect.x, ypos);
00533     ypos += item_interline; show_haloing_button_.set_location(rect.x, ypos);
00534     ypos += item_interline; idle_anim_button_.set_location(rect.x, ypos);
00535     ypos += short_interline;
00536     idle_anim_slider_label_.set_location(rect.x, ypos);
00537     SDL_Rect idle_anim_rect = { rect.x + idle_anim_slider_label_.width(), ypos,
00538                                 rect.w - idle_anim_slider_label_.width() - right_border, 0 };
00539     idle_anim_slider_.set_location(idle_anim_rect);
00540     video_mode_button_.set_location(rect.x, bottom_row_y - video_mode_button_.height());
00541     theme_button_.set_location(rect.x + video_mode_button_.width() + 10,
00542                                bottom_row_y - theme_button_.height());
00543 
00544     // Sound tab
00545     slider_label_width_ = maximum<unsigned>(music_label_.width(), sound_label_.width());
00546     slider_label_width_ = maximum<unsigned>(slider_label_width_, bell_label_.width());
00547     slider_label_width_ = maximum<unsigned>(slider_label_width_, UI_sound_label_.width());
00548     ypos = rect.y + top_border;
00549     sound_button_.set_location(rect.x, ypos);
00550 
00551     ypos += short_interline;
00552     sound_label_.set_location(rect.x, ypos);
00553     const SDL_Rect sound_rect = { rect.x + slider_label_width_, ypos,
00554                                 rect.w - slider_label_width_ - right_border, 0 };
00555     sound_slider_.set_location(sound_rect);
00556 
00557     ypos += item_interline;
00558     music_button_.set_location(rect.x, ypos);
00559 
00560     ypos += short_interline;
00561     music_label_.set_location(rect.x, ypos);
00562     const SDL_Rect music_rect = { rect.x + slider_label_width_, ypos,
00563                                 rect.w - slider_label_width_ - right_border, 0 };
00564     music_slider_.set_location(music_rect);
00565 
00566     ypos += item_interline; //Bell slider
00567     turn_bell_button_.set_location(rect.x, ypos);
00568     ypos += short_interline;
00569     bell_label_.set_location(rect.x, ypos);
00570     const SDL_Rect bell_rect = {rect.x + slider_label_width_, ypos,
00571                                 rect.w - slider_label_width_ - right_border, 0 };
00572     bell_slider_.set_location(bell_rect);
00573 
00574     ypos += item_interline; //UI sound slider
00575     UI_sound_button_.set_location(rect.x, ypos);
00576     ypos += short_interline;
00577     UI_sound_label_.set_location(rect.x, ypos);
00578     const SDL_Rect UI_sound_rect = {rect.x + slider_label_width_, ypos,
00579                                 rect.w - slider_label_width_ - right_border, 0 };
00580     UI_sound_slider_.set_location(UI_sound_rect);
00581     advanced_sound_button_.set_location(rect.x, bottom_row_y - advanced_sound_button_.height());
00582 
00583 
00584     //Advanced Sound tab
00585     ypos = rect.y + top_border;
00586     sample_rate_label_.set_location(rect.x, ypos);
00587     ypos += short_interline;
00588     int h_offset = rect.x + horizontal_padding;
00589     sample_rate_button1_.set_location(h_offset, ypos);
00590     ypos += short_interline;
00591     sample_rate_button2_.set_location(h_offset, ypos);
00592     ypos += short_interline;
00593     sample_rate_button3_.set_location(h_offset, ypos);
00594     h_offset += sample_rate_button3_.width() + 5;
00595     sample_rate_input_.set_location(h_offset, ypos);
00596     h_offset += sample_rate_input_.width() + 5;
00597     confirm_sound_button_.set_location(h_offset, ypos);
00598 
00599     ypos += item_interline;
00600     buffer_size_label_.set_location(rect.x, ypos);
00601     ypos += short_interline;
00602     SDL_Rect buffer_rect = {rect.x + horizontal_padding, ypos,
00603                             rect.w - horizontal_padding - right_border, 0 };
00604     buffer_size_slider_.set_location(buffer_rect);
00605     ypos += item_interline;
00606     normal_sound_button_.set_location(rect.x, bottom_row_y - normal_sound_button_.height());
00607 
00608 
00609     // Multiplayer tab
00610     ypos = rect.y + top_border;
00611     chat_lines_label_.set_location(rect.x, ypos);
00612     ypos += short_interline;
00613     SDL_Rect chat_lines_rect = { rect.x + horizontal_padding, ypos,
00614                                 rect.w - horizontal_padding - right_border, 0 };
00615     chat_lines_slider_.set_location(chat_lines_rect);
00616     ypos += item_interline; chat_timestamp_button_.set_location(rect.x, ypos);
00617     ypos += item_interline; sort_list_by_group_button_.set_location(rect.x, ypos);
00618     ypos += item_interline; iconize_list_button_.set_location(rect.x, ypos);
00619 
00620     ypos += item_interline; show_lobby_joins_button1_.set_location(rect.x, ypos);
00621     ypos += short_interline; show_lobby_joins_button2_.set_location(rect.x, ypos);
00622     ypos += short_interline; show_lobby_joins_button3_.set_location(rect.x, ypos);
00623 
00624     friends_list_button_.set_location(rect.x, bottom_row_y - friends_list_button_.height());
00625 
00626     //Friends tab
00627     ypos = rect.y + top_border;
00628     friends_input_.set_location(rect.x,ypos);
00629 
00630     friends_.set_location(rect.x,ypos + item_interline);
00631     friends_.set_max_height(height() - 100 - friends_back_button_.height());
00632 
00633     int friends_xpos;
00634 
00635     if (friends_.width() > friends_input_.width()) {
00636         friends_xpos = rect.x+  friends_.width() + 20;
00637     } else {
00638         friends_xpos = rect.x+  friends_input_.width() + 20;
00639     }
00640     friends_.set_max_width(friends_xpos - rect.x - 1);
00641 
00642     friends_add_friend_button_.set_location(friends_xpos,ypos);
00643     ypos += short_interline+3; friends_add_ignore_button_.set_location(friends_xpos,ypos);
00644     ypos += short_interline+3; friends_remove_button_.set_location(friends_xpos,ypos);
00645     friends_back_button_.set_location(rect.x, bottom_row_y - friends_back_button_.height());
00646 
00647     //Advanced tab
00648     ypos = rect.y + top_border;
00649     advanced_.set_location(rect.x,ypos);
00650     advanced_.set_max_height(height()-100);
00651 
00652     ypos += advanced_.height() + font::relative_size(14);
00653 
00654     advanced_button_.set_location(rect.x,ypos);
00655 
00656     set_selection(tab_);
00657 }
00658 
00659 void preferences_dialog::process_event()
00660 {
00661     if (tab_ == GENERAL_TAB) {
00662         if (turbo_button_.pressed()) {
00663             set_turbo(turbo_button_.checked());
00664             turbo_slider_.enable(turbo());
00665             turbo_slider_label_.enable(turbo());
00666         }
00667         if (show_ai_moves_button_.pressed())
00668             set_show_ai_moves(!show_ai_moves_button_.checked());
00669         if (show_grid_button_.pressed())
00670             set_grid(show_grid_button_.checked());
00671         if (save_replays_button_.pressed())
00672             set_save_replays(save_replays_button_.checked());
00673         if (delete_saves_button_.pressed())
00674             set_delete_saves(delete_saves_button_.checked());
00675         if (turn_dialog_button_.pressed())
00676             set_turn_dialog(turn_dialog_button_.checked());
00677         if (show_team_colours_button_.pressed())
00678             set_show_side_colours(show_team_colours_button_.checked());
00679         if (hotkeys_button_.pressed()) {
00680             show_hotkeys_dialog(disp_);
00681             parent->clear_buttons();
00682         }
00683 
00684         set_scroll_speed(scroll_slider_.value());
00685         set_autosavemax(autosavemax_slider_.value());
00686         set_turbo_speed(turbo_slider_.item_selected());
00687 
00688         std::stringstream buf;
00689         buf << _("Speed: ") << turbo_slider_.item_selected();
00690         turbo_slider_label_.set_text(buf.str());
00691 
00692         std::stringstream buf2;
00693         if (autosavemax_slider_.value() == preferences::INFINITE_AUTO_SAVES)
00694             buf2 << _("Maximum Auto-Saves: ") << _("infinite");
00695         else
00696             buf2 << _("Maximum Auto-Saves: ") << autosavemax_slider_.value();
00697         autosavemax_slider_label_.set_text(buf2.str());
00698 
00699         return;
00700     }
00701 
00702     if (tab_ == DISPLAY_TAB) {
00703         if (show_floating_labels_button_.pressed())
00704             set_show_floating_labels(show_floating_labels_button_.checked());
00705         if (video_mode_button_.pressed())
00706             throw video_mode_change_exception(video_mode_change_exception::CHANGE_RESOLUTION);
00707         if (theme_button_.pressed())
00708             show_theme_dialog(disp_);
00709             parent->clear_buttons();
00710         if (fullscreen_button_.pressed())
00711             throw video_mode_change_exception(fullscreen_button_.checked()
00712                                             ? video_mode_change_exception::MAKE_FULLSCREEN
00713                                             : video_mode_change_exception::MAKE_WINDOWED);
00714         if (show_colour_cursors_button_.pressed())
00715             set_colour_cursors(show_colour_cursors_button_.checked());
00716         if (show_haloing_button_.pressed())
00717             set_show_haloes(show_haloing_button_.checked());
00718         if (gamma_button_.pressed()) {
00719             set_adjust_gamma(gamma_button_.checked());
00720             const bool enable_gamma = adjust_gamma();
00721             gamma_slider_.enable(enable_gamma);
00722             gamma_label_.enable(enable_gamma);
00723         }
00724         if (flip_time_button_.pressed())
00725             set_flip_time(flip_time_button_.checked());
00726         if (idle_anim_button_.pressed()) {
00727             const bool enable_idle_anim = idle_anim_button_.checked();
00728             idle_anim_slider_label_.enable(enable_idle_anim);
00729             idle_anim_slider_.enable(enable_idle_anim);
00730             set_idle_anim(enable_idle_anim);
00731             if (!enable_idle_anim)
00732                 idle_anim_slider_.set_value(0);
00733         }
00734 
00735         set_gamma(gamma_slider_.value());
00736         set_idle_anim_rate(idle_anim_slider_.value());
00737 
00738         return;
00739     }
00740 
00741 
00742     if (tab_ == SOUND_TAB) {
00743         if (turn_bell_button_.pressed()) {
00744             if(!set_turn_bell(turn_bell_button_.checked()))
00745                 turn_bell_button_.set_check(false);
00746             bell_slider_.enable(turn_bell());
00747             bell_label_.enable(turn_bell());
00748         }
00749         if (sound_button_.pressed()) {
00750             if(!set_sound(sound_button_.checked()))
00751                 sound_button_.set_check(false);
00752             sound_slider_.enable(sound_on());
00753             sound_label_.enable(sound_on());
00754         }
00755         if (UI_sound_button_.pressed()) {
00756             if(!set_UI_sound(UI_sound_button_.checked()))
00757                 UI_sound_button_.set_check(false);
00758             UI_sound_slider_.enable(UI_sound_on());
00759             UI_sound_label_.enable(UI_sound_on());
00760         }
00761         set_sound_volume(sound_slider_.value());
00762         set_UI_volume(UI_sound_slider_.value());
00763         set_bell_volume(bell_slider_.value());
00764 
00765         if (music_button_.pressed()) {
00766             if(!set_music(music_button_.checked()))
00767                 music_button_.set_check(false);
00768             music_slider_.enable(music_on());
00769             music_label_.enable(music_on());
00770         }
00771         set_music_volume(music_slider_.value());
00772 
00773         if (advanced_sound_button_.pressed())
00774             set_selection(ADVANCED_SOUND_TAB);
00775 
00776         return;
00777     }
00778 
00779     if (tab_ == ADVANCED_SOUND_TAB) {
00780         bool apply = false;
00781         std::string rate;
00782 
00783         if (sample_rate_button1_.pressed()) {
00784             if (sample_rate_button1_.checked()) {
00785                 sample_rate_button2_.set_check(false);
00786                 sample_rate_button3_.set_check(false);
00787                 confirm_sound_button_.enable(false);
00788                 apply = true;
00789                 rate = "22050";
00790             } else
00791                 sample_rate_button1_.set_check(true);
00792         }
00793         if (sample_rate_button2_.pressed()) {
00794             if (sample_rate_button2_.checked()) {
00795                 sample_rate_button1_.set_check(false);
00796                 sample_rate_button3_.set_check(false);
00797                 confirm_sound_button_.enable(false);
00798                 apply = true;
00799                 rate = "44100";
00800             } else
00801                 sample_rate_button2_.set_check(true);
00802         }
00803         if (sample_rate_button3_.pressed()) {
00804             if (sample_rate_button3_.checked()) {
00805                 sample_rate_button1_.set_check(false);
00806                 sample_rate_button2_.set_check(false);
00807                 confirm_sound_button_.enable(true);
00808             } else
00809                 sample_rate_button3_.set_check(true);
00810         }
00811         if (confirm_sound_button_.pressed()) {
00812             apply = true;
00813             rate = sample_rate_input_.text();
00814         }
00815 
00816         if (apply)
00817             try {
00818             save_sample_rate(lexical_cast<unsigned int>(rate));
00819             } catch (bad_lexical_cast&) {
00820             }
00821 
00822         if (buffer_size_slider_.value_change()) {
00823             const size_t buffer_size = 512 << buffer_size_slider_.value();
00824             save_sound_buffer_size(buffer_size);
00825             std::stringstream buf;
00826             buf << _("Buffer Size: ") << buffer_size;
00827             buffer_size_label_.set_text(buf.str());
00828         }
00829 
00830         if (normal_sound_button_.pressed())
00831             set_selection(SOUND_TAB);
00832 
00833         return;
00834     }
00835 
00836     if (tab_ == MULTIPLAYER_TAB) {
00837         if (show_lobby_joins_button1_.pressed()) {
00838             set_lobby_joins(SHOW_NONE);
00839             show_lobby_joins_button1_.set_check(true);
00840             show_lobby_joins_button2_.set_check(false);
00841             show_lobby_joins_button3_.set_check(false);
00842         } else if (show_lobby_joins_button2_.pressed()) {
00843             set_lobby_joins(SHOW_FRIENDS);
00844             show_lobby_joins_button1_.set_check(false);
00845             show_lobby_joins_button2_.set_check(true);
00846             show_lobby_joins_button3_.set_check(false);
00847         } else if (show_lobby_joins_button3_.pressed()) {
00848             set_lobby_joins(SHOW_ALL);
00849             show_lobby_joins_button1_.set_check(false);
00850             show_lobby_joins_button2_.set_check(false);
00851             show_lobby_joins_button3_.set_check(true);
00852         }
00853         if (sort_list_by_group_button_.pressed())
00854             set_sort_list(sort_list_by_group_button_.checked());
00855         if (iconize_list_button_.pressed())
00856             set_iconize_list(iconize_list_button_.checked());
00857         if (chat_timestamp_button_.pressed())
00858             set_chat_timestamping(chat_timestamp_button_.checked());
00859         if (friends_list_button_.pressed())
00860             set_selection(FRIENDS_TAB);
00861 
00862         set_chat_lines(chat_lines_slider_.value());
00863 
00864         //display currently select amount of chat lines
00865         std::stringstream buf;
00866         buf << _("Chat Lines: ") << chat_lines_slider_.value();
00867         chat_lines_label_.set_text(buf.str());
00868 
00869         return;
00870     }
00871 
00872     if (tab_ == FRIENDS_TAB) {
00873         if(friends_.double_clicked() || friends_.selection() != friends_selection_) {
00874             friends_selection_ = friends_.selection();
00875             std::stringstream ss;
00876             ss << friends_names_[friends_.selection()];
00877             if (ss.str() != "(empty list)") friends_input_.set_text(ss.str());
00878             else friends_input_.set_text("");
00879         }
00880         if (friends_back_button_.pressed())
00881             set_selection(MULTIPLAYER_TAB);
00882 
00883         if (friends_add_friend_button_.pressed()) {
00884             if (preferences::add_friend(friends_input_.text())) {
00885                 friends_input_.clear();
00886                 set_friends_menu();
00887             } else {
00888                 gui::dialog(disp_, "", _("Invalid username")).show();;
00889             }
00890         }
00891         if (friends_add_ignore_button_.pressed()) {
00892             if (preferences::add_ignore(friends_input_.text())) {
00893                 friends_input_.clear();
00894                 set_friends_menu();
00895             } else {
00896                 gui::dialog(disp_, "", _("Invalid username")).show();;
00897             }
00898         }
00899         if (friends_remove_button_.pressed()) {
00900             std::string to_remove = friends_input_.text();
00901             if(to_remove.empty() && friends_.selection() >= 0 && friends_names_[friends_.selection()] != "(empty list)") {
00902                 to_remove = friends_names_[friends_.selection()];
00903             }
00904             if(!to_remove.empty()) {
00905                 //! @todo Better to remove from a specific relation.
00906                 preferences::remove_friend(to_remove);
00907                 preferences::remove_ignore(to_remove);
00908                 friends_input_.clear();
00909                 set_friends_menu();
00910             }
00911         }
00912         return;
00913     }
00914 
00915     if (tab_ == ADVANCED_TAB) {
00916         if(advanced_.selection() != advanced_selection_) {
00917             advanced_selection_ = advanced_.selection();
00918             const config* const adv = get_advanced_pref();
00919             if(adv != NULL) {
00920                 const config& pref = *adv;
00921                 advanced_button_.set_width(0);
00922                 advanced_button_.set_label(pref["name"]);
00923                 std::string value = preferences::get(pref["field"]);
00924                 if(value.empty()) {
00925                     value = pref["default"];
00926                 }
00927 
00928                 advanced_button_.set_check(value == "yes");
00929             }
00930         }
00931 
00932         if(advanced_button_.pressed()) {
00933             const config* const adv = get_advanced_pref();
00934             if(adv != NULL) {
00935                 const config& pref = *adv;
00936                 preferences::set(pref["field"],
00937                         advanced_button_.checked() ? "yes" : "no");
00938                 set_advanced_menu();
00939             }
00940         }
00941 
00942         return;
00943     }
00944 }
00945 
00946 const config* preferences_dialog::get_advanced_pref() const
00947 {
00948     const config::child_list& adv = game_cfg_.get_children("advanced_preference");
00949     if(advanced_selection_ >= 0 && advanced_selection_ < int(adv.size())) {
00950         return adv[advanced_selection_];
00951     } else {
00952         return NULL;
00953     }
00954 }
00955 
00956 void preferences_dialog::set_advanced_menu()
00957 {
00958     std::vector<std::string> advanced_items;
00959     const config::child_list& adv = game_cfg_.get_children("advanced_preference");
00960     for(config::child_list::const_iterator i = adv.begin(); i != adv.end(); ++i) {
00961         std::ostringstream str;
00962         std::string field = preferences::get((**i)["field"]);
00963         if(field.empty()) {
00964             field = (**i)["default"];
00965         }
00966 
00967         if(field == "yes") {
00968             field = _("yes");
00969         } else if(field == "no") {
00970             field = _("no");
00971         }
00972 
00973         str << (**i)["name"] << COLUMN_SEPARATOR << field;
00974         advanced_items.push_back(str.str());
00975     }
00976 
00977     advanced_.set_items(advanced_items,true,true);
00978 }
00979 
00980 void preferences_dialog::set_friends_menu()
00981 {
00982     const std::vector<std::string>& friends = utils::split(preferences::get_friends());
00983     const std::vector<std::string>& ignores = utils::split(preferences::get_ignores());
00984     std::vector<std::string> friends_items;
00985     std::vector<std::string> friends_names;
00986     std::string const imgpre = IMAGE_PREFIX + std::string("misc/status-");
00987     std::vector<std::string>::const_iterator i;
00988     for (i = friends.begin(); i != friends.end(); ++i)
00989     {
00990         friends_items.push_back(imgpre + "friend.png" + COLUMN_SEPARATOR
00991                 + *i + COLUMN_SEPARATOR + "friend");
00992         friends_names.push_back(*i);
00993     }
00994     for (i = ignores.begin(); i != ignores.end(); ++i)
00995     {
00996         friends_items.push_back(imgpre + "ignore.png" + COLUMN_SEPARATOR
00997                 + *i + COLUMN_SEPARATOR + "ignored");
00998         friends_names.push_back(*i);
00999     }
01000     if (friends_items.empty()) {
01001         friends_items.push_back(_("(empty list)"));
01002         friends_names.push_back("(empty list)");
01003     }
01004     friends_names_ = friends_names;
01005     friends_.set_items(friends_items,true,true);
01006 }
01007 
01008 void preferences_dialog::set_selection(int index)
01009 {
01010     tab_ = TAB(index);
01011     set_dirty();
01012     bg_restore();
01013 
01014     const bool hide_general = tab_ != GENERAL_TAB;
01015     scroll_label_.hide(hide_general);
01016     scroll_slider_.hide(hide_general);
01017     turbo_button_.hide(hide_general);
01018     turbo_slider_label_.hide(hide_general);
01019     turbo_slider_.hide(hide_general);
01020     turbo_slider_label_.enable(turbo());
01021     turbo_slider_.enable(turbo());
01022     show_ai_moves_button_.hide(hide_general);
01023     turn_dialog_button_.hide(hide_general);
01024     hotkeys_button_.hide(hide_general);
01025     show_team_colours_button_.hide(hide_general);
01026     show_grid_button_.hide(hide_general);
01027     save_replays_button_.hide(hide_general);
01028     delete_saves_button_.hide(hide_general);
01029     autosavemax_slider_label_.hide(hide_general);
01030     autosavemax_slider_label_.enable(!hide_general);
01031     autosavemax_slider_.hide(hide_general);
01032     autosavemax_slider_.enable(!hide_general);
01033 
01034     const bool hide_display = tab_ != DISPLAY_TAB;
01035     gamma_label_.hide(hide_display);
01036     gamma_slider_.hide(hide_display);
01037     gamma_label_.enable(adjust_gamma());
01038     gamma_slider_.enable(adjust_gamma());
01039     gamma_button_.hide(hide_display);
01040     show_floating_labels_button_.hide(hide_display);
01041     show_colour_cursors_button_.hide(hide_display);
01042     show_haloing_button_.hide(hide_display);
01043     fullscreen_button_.hide(hide_display);
01044     idle_anim_button_.hide(hide_display);
01045     idle_anim_slider_label_.hide(hide_display);
01046     idle_anim_slider_label_.enable(idle_anim());
01047     idle_anim_slider_.hide(hide_display);
01048     idle_anim_slider_.enable(idle_anim());
01049     video_mode_button_.hide(hide_display);
01050     theme_button_.hide(hide_display);
01051     flip_time_button_.hide(hide_display);
01052 
01053     const bool hide_sound = tab_ != SOUND_TAB;
01054     music_button_.hide(hide_sound);
01055     music_label_.hide(hide_sound);
01056     music_slider_.hide(hide_sound);
01057     sound_button_.hide(hide_sound);
01058     sound_label_.hide(hide_sound);
01059     sound_slider_.hide(hide_sound);
01060     UI_sound_button_.hide(hide_sound);
01061     UI_sound_label_.hide(hide_sound);
01062     UI_sound_slider_.hide(hide_sound);
01063     turn_bell_button_.hide(hide_sound);
01064     bell_label_.hide(hide_sound);
01065     bell_slider_.hide(hide_sound);
01066     music_slider_.enable(music_on());
01067     bell_slider_.enable(turn_bell());
01068     sound_slider_.enable(sound_on());
01069     UI_sound_slider_.enable(UI_sound_on());
01070     music_label_.enable(music_on());
01071     bell_label_.enable(turn_bell());
01072     sound_label_.enable(sound_on());
01073     UI_sound_label_.enable(UI_sound_on());
01074     advanced_sound_button_.hide(hide_sound);
01075 
01076     const bool hide_advanced_sound = tab_ != ADVANCED_SOUND_TAB;
01077     sample_rate_label_.hide(hide_advanced_sound);
01078     sample_rate_button1_.hide(hide_advanced_sound);
01079     sample_rate_button2_.hide(hide_advanced_sound);
01080     sample_rate_button3_.hide(hide_advanced_sound);
01081     sample_rate_input_.hide(hide_advanced_sound);
01082     confirm_sound_button_.hide(hide_advanced_sound);
01083     buffer_size_label_.hide(hide_advanced_sound);
01084     buffer_size_slider_.hide(hide_advanced_sound);
01085     normal_sound_button_.hide(hide_advanced_sound);
01086 
01087     const bool hide_multiplayer = tab_ != MULTIPLAYER_TAB;
01088     chat_lines_label_.hide(hide_multiplayer);
01089     chat_lines_slider_.hide(hide_multiplayer);
01090     chat_timestamp_button_.hide(hide_multiplayer);
01091     sort_list_by_group_button_.hide(hide_multiplayer);
01092     iconize_list_button_.hide(hide_multiplayer);
01093     show_lobby_joins_button1_.hide(hide_multiplayer);
01094     show_lobby_joins_button2_.hide(hide_multiplayer);
01095     show_lobby_joins_button3_.hide(hide_multiplayer);
01096     friends_list_button_.hide(hide_multiplayer);
01097 
01098     const bool hide_friends = tab_ != FRIENDS_TAB;
01099     friends_.hide(hide_friends);
01100     friends_back_button_.hide(hide_friends);
01101     friends_add_friend_button_.hide(hide_friends);
01102     friends_add_ignore_button_.hide(hide_friends);
01103     friends_remove_button_.hide(hide_friends);
01104     friends_input_.hide(hide_friends);
01105 
01106     const bool hide_advanced = tab_ != ADVANCED_TAB;
01107     advanced_.hide(hide_advanced);
01108     advanced_button_.hide(hide_advanced);
01109 }
01110 
01111 }
01112 
01113 void show_preferences_dialog(display& disp, const config& game_cfg)
01114 {
01115     std::vector<std::string> items;
01116 
01117     std::string const pre = IMAGE_PREFIX + std::string("icons/icon-");
01118     char const sep = COLUMN_SEPARATOR;
01119     items.push_back(pre + "general.png" + sep + sgettext("Prefs section^General"));
01120     items.push_back(pre + "display.png" + sep + sgettext("Prefs section^Display"));
01121     items.push_back(pre + "music.png" + sep + sgettext("Prefs section^Sound"));
01122     items.push_back(pre + "multiplayer.png" + sep + sgettext("Prefs section^Multiplayer"));
01123     items.push_back(pre + "advanced.png" + sep + sgettext("Advanced section^Advanced"));
01124 
01125     for(;;) {
01126         try {
01127             preferences_dialog dialog(disp,game_cfg);
01128             dialog.parent.assign(new preferences_parent_dialog(disp));
01129             dialog.parent->set_menu(items);
01130             dialog.parent->add_pane(&dialog);
01131             dialog.parent->show();
01132             return;
01133         } catch(preferences_dialog::video_mode_change_exception& e) {
01134             switch(e.type) {
01135             case preferences_dialog::video_mode_change_exception::CHANGE_RESOLUTION:
01136                 show_video_mode_dialog(disp);
01137                 break;
01138             case preferences_dialog::video_mode_change_exception::MAKE_FULLSCREEN:
01139                 set_fullscreen(true);
01140                 break;
01141             case preferences_dialog::video_mode_change_exception::MAKE_WINDOWED:
01142                 set_fullscreen(false);
01143                 break;
01144             }
01145 
01146             if(items[1].empty() || items[1][0] != '*') {
01147                 items[1] = "*" + items[1];
01148             }
01149         }
01150     }
01151 }
01152 
01153 bool show_theme_dialog(display& disp)
01154 {
01155     int action = 0;
01156     std::vector<std::string> options = disp.get_theme().get_known_themes();
01157     if(options.size()){
01158         std::string current_theme=_("Saved Theme Preference: ")+preferences::theme();
01159         action = gui::show_dialog(disp,NULL,"",current_theme,gui::OK_CANCEL,&options);
01160         if(action >= 0){
01161         preferences::set_theme(options[action]);
01162         //it would be preferable for the new theme to take effect
01163         //immediately, however, this will have to do for now.
01164         gui::message_dialog(disp,"",_("New theme will take effect on next new or loaded game.")).show();
01165         return(1);
01166         }
01167     }else{
01168         gui::message_dialog(disp,"",_("No known themes. Try changing from within an existing game.")).show();
01169     }
01170     return(0);
01171 }
01172 
01173 }

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs