wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth ./changelog src/game.cpp src/playturn.c...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth ./changelog src/game.cpp src/playturn.c...
Date: Tue, 03 May 2005 23:16:39 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    05/05/04 03:16:39

Modified files:
        .              : changelog 
        src            : game.cpp playturn.cpp preferences.cpp 
                         preferences.hpp 
        src/widgets    : button.cpp button.hpp menu.cpp 
Added files:
        images/icons   : icon-advanced.png 

Log message:
        added 'Advanced' preferences section

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/images/icons/icon-advanced.png?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/changelog.diff?tr1=1.645&tr2=1.646&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.240&tr2=1.241&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.366&tr2=1.367&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/preferences.cpp.diff?tr1=1.152&tr2=1.153&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/preferences.hpp.diff?tr1=1.53&tr2=1.54&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/button.cpp.diff?tr1=1.62&tr2=1.63&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/button.hpp.diff?tr1=1.30&tr2=1.31&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/menu.cpp.diff?tr1=1.87&tr2=1.88&r1=text&r2=text

Patches:
Index: wesnoth/changelog
diff -u wesnoth/changelog:1.645 wesnoth/changelog:1.646
--- wesnoth/changelog:1.645     Tue May  3 22:24:52 2005
+++ wesnoth/changelog   Wed May  4 03:16:39 2005
@@ -1,5 +1,6 @@
 CVS HEAD:
  * user interface improvements:
+   * added 'Advanced' preferences section with 'binary save files' and 'show 
combat' as initial options
    * fix editor file chooser when starting directory has many files (#11698)
    * made it so network dialogs show progress of data transfers again
    * starting position in editor now starts at player 1 (#10625)
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.240 wesnoth/src/game.cpp:1.241
--- wesnoth/src/game.cpp:1.240  Wed Apr 27 22:17:37 2005
+++ wesnoth/src/game.cpp        Wed May  4 03:16:39 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.240 2005/04/27 22:17:37 silene Exp $ */
+/* $Id: game.cpp,v 1.241 2005/05/04 03:16:39 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -100,7 +100,9 @@
 
        bool new_campaign();
        bool play_multiplayer();
-       bool change_language();
+       bool change_language();
+
+       void show_preferences();
 
        enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
        void play_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
@@ -1171,6 +1173,14 @@
        hotkey::load_descriptions();
 
        return false;
+}
+
+void game_controller::show_preferences()
+{
+       const preferences::display_manager disp_manager(&disp());
+       preferences::show_preferences_dialog(disp(),game_config_);
+
+       disp().redraw_everything();
 }
 
 //this function reads the game configuration, searching for valid cached 
copies first
@@ -1563,11 +1573,8 @@
                        if(game.change_language() == false) {
                                continue;
                        }
-               } else if(res == gui::EDIT_PREFERENCES) {
-                       const preferences::display_manager 
disp_manager(&game.disp());
-                       preferences::show_preferences_dialog(game.disp());
-
-                       game.disp().redraw_everything();
+               } else if(res == gui::EDIT_PREFERENCES) {
+                       game.show_preferences();
                        continue;
                } else if(res == gui::SHOW_ABOUT) {
                        about::show_about(game.disp());
Index: wesnoth/src/playturn.cpp
diff -u wesnoth/src/playturn.cpp:1.366 wesnoth/src/playturn.cpp:1.367
--- wesnoth/src/playturn.cpp:1.366      Mon May  2 19:42:04 2005
+++ wesnoth/src/playturn.cpp    Wed May  4 03:16:39 2005
@@ -1,4 +1,4 @@
-/* $Id: playturn.cpp,v 1.366 2005/05/02 19:42:04 silene Exp $ */
+/* $Id: playturn.cpp,v 1.367 2005/05/04 03:16:39 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -2123,7 +2123,7 @@
 
 void turn_info::preferences()
 {
-       preferences::show_preferences_dialog(gui_);
+       preferences::show_preferences_dialog(gui_,terrain_config_);
        gui_.redraw_everything();
 }
 
Index: wesnoth/src/preferences.cpp
diff -u wesnoth/src/preferences.cpp:1.152 wesnoth/src/preferences.cpp:1.153
--- wesnoth/src/preferences.cpp:1.152   Sat Apr 16 19:35:32 2005
+++ wesnoth/src/preferences.cpp Wed May  4 03:16:39 2005
@@ -1,4 +1,4 @@
-/* $Id: preferences.cpp,v 1.152 2005/04/16 19:35:32 ott Exp $ */
+/* $Id: preferences.cpp,v 1.153 2005/05/04 03:16:39 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -791,7 +791,7 @@
 class preferences_dialog : public gui::preview_pane
 {
 public:
-       preferences_dialog(display& disp);
+       preferences_dialog(display& disp, const config& game_cfg);
 
        struct video_mode_change_exception
        {
@@ -808,23 +808,29 @@
        void process_event();
        bool left_side() const { return false; }
        void set_selection(int index);
-       void update_location(SDL_Rect const &rect);
+       void update_location(SDL_Rect const &rect);
+       const config* get_advanced_pref() const;
+       void set_advanced_menu();
 
        gui::slider music_slider_, sound_slider_, scroll_slider_, gamma_slider_;
        gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
                    show_grid_button_, show_floating_labels_button_, 
turn_dialog_button_,
                    turn_bell_button_, show_team_colours_button_, 
show_colour_cursors_button_,
                    show_haloing_button_, video_mode_button_, hotkeys_button_, 
gamma_button_,
-                               flip_time_button_;
+                               flip_time_button_, advanced_button_;
        gui::label music_label_, sound_label_, scroll_label_, gamma_label_;
        unsigned slider_label_width_;
+
+       gui::menu advanced_;
+       int advanced_selection_;
 
-       enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB };
+       enum TAB { GENERAL_TAB, DISPLAY_TAB, SOUND_TAB, ADVANCED_TAB };
        TAB tab_;
-       display &disp_;
+       display &disp_;
+       const config& game_cfg_;
 };
 
-preferences_dialog::preferences_dialog(display& disp)
+preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
        : gui::preview_pane(disp.video()),
          music_slider_(disp.video()), sound_slider_(disp.video()),
          scroll_slider_(disp.video()), gamma_slider_(disp.video()),
@@ -841,10 +847,12 @@
          video_mode_button_(disp.video(), _("Video Mode")),
          hotkeys_button_(disp.video(), _("Hotkeys")),
          gamma_button_(disp.video(), _("Adjust Gamma"), 
gui::button::TYPE_CHECK),
-         flip_time_button_(disp.video(), _("Reverse Time Graphics"), 
gui::button::TYPE_CHECK),
+         flip_time_button_(disp.video(), _("Reverse Time Graphics"), 
gui::button::TYPE_CHECK),
+         advanced_button_(disp.video(), "", gui::button::TYPE_CHECK),
          music_label_(disp.video(), _("Music Volume:")), 
sound_label_(disp.video(), _("SFX Volume:")),
          scroll_label_(disp.video(), _("Scroll Speed:")), 
gamma_label_(disp.video(), _("Gamma:")),
-         slider_label_width_(0), tab_(GENERAL_TAB), disp_(disp)
+         slider_label_width_(0), 
advanced_(disp.video(),std::vector<std::string>()), advanced_selection_(-1),
+         tab_(GENERAL_TAB), disp_(disp), game_cfg_(game_cfg)
 {
        // FIXME: this box should be vertically centered on the screen, but is 
not
 #if USE_TINY_GUI
@@ -916,7 +924,9 @@
        show_haloing_button_.set_check(show_haloes());
        show_haloing_button_.set_help_string(_("Use graphical special effects 
(may be slower)"));
 
-       hotkeys_button_.set_help_string(_("View and configure keyboard 
shortcuts"));
+       hotkeys_button_.set_help_string(_("View and configure keyboard 
shortcuts"));
+
+       set_advanced_menu();
 }
 
 void preferences_dialog::update_location(SDL_Rect const &rect)
@@ -969,7 +979,16 @@
        sound_label_.set_location(rect.x, ypos);
        SDL_Rect sound_rect = { rect.x + slider_label_width_, ypos,
                                rect.w - slider_label_width_ - border, 0 };
-       sound_slider_.set_location(sound_rect);
+       sound_slider_.set_location(sound_rect);
+
+       //Advanced tab
+       ypos = rect.y;
+       advanced_.set_location(rect.x,ypos);
+       advanced_.set_max_height(height()-100);
+
+       ypos += advanced_.height() + border;
+
+       advanced_button_.set_location(rect.x,ypos);
 
        set_selection(tab_);
 }
@@ -1013,8 +1032,66 @@
        set_sound_volume(sound_slider_.value());
        set_music_volume(music_slider_.value());
        set_scroll_speed(scroll_slider_.value());
-       set_gamma(gamma_slider_.value());
-}
+       set_gamma(gamma_slider_.value());
+
+       if(advanced_.selection() != advanced_selection_) {
+               advanced_selection_ = advanced_.selection();
+               const config* const adv = get_advanced_pref();
+               if(adv != NULL) {
+                       const config& pref = *adv;
+                       advanced_button_.set_label(pref["name"]);
+                       std::string value = prefs[pref["field"]];
+                       if(value.empty()) {
+                               value = pref["default"];
+                       }
+
+                       advanced_button_.set_check(value == "yes");
+               }
+       }
+
+       if(advanced_button_.pressed()) {
+               const config* const adv = get_advanced_pref();
+               if(adv != NULL) {
+                       const config& pref = *adv;
+                       prefs[pref["field"]] = advanced_button_.checked() ? 
"yes" : "no";
+                       set_advanced_menu();
+               }
+       }
+}
+
+const config* preferences_dialog::get_advanced_pref() const
+{
+       const config::child_list& adv = 
game_cfg_.get_children("advanced_preference");
+       if(advanced_selection_ >= 0 && advanced_selection_ < int(adv.size())) {
+               return adv[advanced_selection_];
+       } else {
+               return NULL;
+       }
+}
+
+void preferences_dialog::set_advanced_menu()
+{
+       std::vector<std::string> advanced_items;
+       const config::child_list& adv = 
game_cfg_.get_children("advanced_preference");
+       for(config::child_list::const_iterator i = adv.begin(); i != adv.end(); 
++i) {
+               std::ostringstream str;
+               std::string field = prefs[(**i)["field"]];
+               if(field.empty()) {
+                       field = (**i)["default"];
+               }
+
+               if(field == "yes") {
+                       field = _("yes");
+               } else if(field == "no") {
+                       field = _("no");
+               }
+
+               str << (**i)["name"] << COLUMN_SEPARATOR << field;
+               advanced_items.push_back(str.str());
+       }
+
+       advanced_.set_items(advanced_items,true,true);
+}
 
 void preferences_dialog::set_selection(int index)
 {
@@ -1022,7 +1099,7 @@
        set_dirty();
        bg_restore();
 
-       bool hide_general = tab_ != GENERAL_TAB;
+       const bool hide_general = tab_ != GENERAL_TAB;
        scroll_label_.hide(hide_general);
        scroll_slider_.hide(hide_general);
        turbo_button_.hide(hide_general);
@@ -1033,7 +1110,7 @@
        show_team_colours_button_.hide(hide_general);
        show_grid_button_.hide(hide_general);
 
-       bool hide_display = tab_ != DISPLAY_TAB, hide_gamma = hide_display || 
!adjust_gamma();
+       const bool hide_display = tab_ != DISPLAY_TAB, hide_gamma = 
hide_display || !adjust_gamma();
        gamma_label_.hide(hide_gamma);
        gamma_slider_.hide(hide_gamma);
        gamma_button_.hide(hide_display);
@@ -1044,16 +1121,20 @@
        video_mode_button_.hide(hide_display);
        flip_time_button_.hide(hide_display);
 
-       bool hide_sound = tab_ != SOUND_TAB;
+       const bool hide_sound = tab_ != SOUND_TAB;
        music_label_.hide(hide_sound);
        music_slider_.hide(hide_sound);
        sound_label_.hide(hide_sound);
-       sound_slider_.hide(hide_sound);
+       sound_slider_.hide(hide_sound);
+
+       const bool hide_advanced = tab_ != ADVANCED_TAB;
+       advanced_.hide(hide_advanced);
+       advanced_button_.hide(hide_advanced);
 }
 
 }
 
-void show_preferences_dialog(display& disp)
+void show_preferences_dialog(display& disp, const config& game_cfg)
 {
        std::vector<std::string> items;
 
@@ -1061,13 +1142,14 @@
        char const sep = COLUMN_SEPARATOR;
        items.push_back(pre + "general.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^General"));
        items.push_back(pre + "display.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^Display"));
-       items.push_back(pre + "music.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^Sound"));
+       items.push_back(pre + "music.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Prefs section^Sound"));
+       items.push_back(pre + "advanced.png" + sep + 
dsgettext(GETTEXT_DOMAIN,"Advanced section^Advanced"));
        
        for(;;) {
                try {
                        const events::event_context dialog_events_context;
 
-                       preferences_dialog dialog(disp);
+                       preferences_dialog dialog(disp,game_cfg);
                        std::vector<gui::preview_pane*> panes;
                        panes.push_back(&dialog);
 
Index: wesnoth/src/preferences.hpp
diff -u wesnoth/src/preferences.hpp:1.53 wesnoth/src/preferences.hpp:1.54
--- wesnoth/src/preferences.hpp:1.53    Sat Apr  2 21:33:21 2005
+++ wesnoth/src/preferences.hpp Wed May  4 03:16:39 2005
@@ -1,4 +1,4 @@
-/* $Id: preferences.hpp,v 1.53 2005/04/02 21:33:21 gruikya Exp $ */
+/* $Id: preferences.hpp,v 1.54 2005/05/04 03:16:39 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -169,7 +169,7 @@
        void set_theme(const std::string& theme);
        const std::string& theme();
 
-       void show_preferences_dialog(display& disp);
+       void show_preferences_dialog(display& disp, const config& game_cfg);
        bool show_video_mode_dialog(display& disp);
        // If prefs is non-null, save the hotkeys in that config instead of
        // the default.
Index: wesnoth/src/widgets/button.cpp
diff -u wesnoth/src/widgets/button.cpp:1.62 wesnoth/src/widgets/button.cpp:1.63
--- wesnoth/src/widgets/button.cpp:1.62 Mon Mar 28 08:27:01 2005
+++ wesnoth/src/widgets/button.cpp      Wed May  4 03:16:39 2005
@@ -1,4 +1,4 @@
-/* $Id: button.cpp,v 1.62 2005/03/28 08:27:01 silene Exp $ */
+/* $Id: button.cpp,v 1.63 2005/05/04 03:16:39 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -33,7 +33,8 @@
                std::string button_image_name, SPACE_CONSUMPTION spacing)
        : widget(video), label_(label),
          image_(NULL), pressedImage_(NULL), activeImage_(NULL), 
pressedActiveImage_(NULL),
-         button_(true), state_(NORMAL), type_(type), enabled_(true), 
pressed_(false)
+         button_(true), state_(NORMAL), type_(type), enabled_(true), 
pressed_(false),
+         spacing_(spacing), base_height_(0), base_width_(0)
 {
        set_label(label);
 
@@ -63,42 +64,51 @@
        }
 
        if (button_image.null())
-               throw error();
+               throw error();
+
+       base_height_ = button_image->h;
+       base_width_ = button_image->w;
+
+       calculate_size();
 
-       textRect_.x = 0;
-       textRect_.y = 0;
-       textRect_.w = video.getx();
-       textRect_.h = video.gety();
-
-       textRect_ = font::draw_text(NULL,textRect_,font_size,
-                                   font::BUTTON_COLOUR,label_,0,0);
-
-#ifdef USE_TINY_GUI
-       set_height(textRect_.h+vertical_padding);
-#else
-       set_height(maximum(textRect_.h+vertical_padding,button_image->h));
-#endif
        if(type == TYPE_PRESS) {
-#ifdef USE_TINY_GUI
-               set_width(textRect_.w + horizontal_padding);
-#else
-               if(spacing == MINIMUM_SPACE) {
-                       set_width(textRect_.w + horizontal_padding);
-               } else {
-                       
set_width(maximum(textRect_.w+horizontal_padding,button_image->w));
-               }
-#endif
                
image_.assign(scale_surface(button_image,location().w,location().h));
                
pressedImage_.assign(scale_surface(pressed_image,location().w,location().h));
                
activeImage_.assign(scale_surface(active_image,location().w,location().h));
        } else {
-               set_width(checkbox_horizontal_padding + textRect_.w + 
button_image->w);
                
image_.assign(scale_surface(button_image,button_image->w,button_image->h));
                
pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h));
                
activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h));
                if (type == TYPE_CHECK)
                        
pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, 
button_image->h));
        }
+}
+
+void button::calculate_size()
+{
+       textRect_ = screen_area();
+
+       textRect_ = font::draw_text(NULL,textRect_,font_size,
+                                   font::BUTTON_COLOUR,label_,0,0);
+
+#ifdef USE_TINY_GUI
+       set_height(textRect_.h+vertical_padding);
+#else
+       set_height(maximum(textRect_.h+vertical_padding,base_height_));
+#endif
+       if(type_ == TYPE_PRESS) {
+#ifdef USE_TINY_GUI
+               set_width(textRect_.w + horizontal_padding);
+#else
+               if(spacing_ == MINIMUM_SPACE) {
+                       set_width(textRect_.w + horizontal_padding);
+               } else {
+                       
set_width(maximum(textRect_.w+horizontal_padding,base_width_));
+               }
+#endif
+       } else {
+               set_width(checkbox_horizontal_padding + textRect_.w + 
base_width_);
+       }
 }
 
 void button::set_check(bool check)
@@ -184,7 +194,8 @@
 }
 
 void button::set_label(const std::string& val)
-{
+{
+       bg_restore();
        label_ = val;
 
        //if we have a list of items, use the first one that isn't an image
@@ -195,11 +206,8 @@
                        label_ = *i;
                }
        }
-
-       textRect_ = screen_area();
-       const std::string etext = font::make_text_ellipsis(label_, font_size, 
width());
-       textRect_ = font::draw_text(NULL,textRect_,font_size,
-                                   font::BUTTON_COLOUR,etext,0,0);
+
+       calculate_size();
 
        set_dirty(true);
 }
Index: wesnoth/src/widgets/button.hpp
diff -u wesnoth/src/widgets/button.hpp:1.30 wesnoth/src/widgets/button.hpp:1.31
--- wesnoth/src/widgets/button.hpp:1.30 Fri Mar 18 21:21:48 2005
+++ wesnoth/src/widgets/button.hpp      Wed May  4 03:16:39 2005
@@ -1,4 +1,4 @@
-/* $Id: button.hpp,v 1.30 2005/03/18 21:21:48 ydirson Exp $ */
+/* $Id: button.hpp,v 1.31 2005/05/04 03:16:39 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -55,7 +55,9 @@
        virtual void mouse_up(const SDL_MouseButtonEvent& event);
        virtual void draw_contents();
 
-private:
+private:
+
+       void calculate_size();
 
        std::string label_;
        surface image_, pressedImage_, activeImage_, pressedActiveImage_;
@@ -70,7 +72,11 @@
 
        bool enabled_;
 
-       bool pressed_;
+       bool pressed_;
+
+       SPACE_CONSUMPTION spacing_;
+
+       int base_height_, base_width_;
 
        bool hit(int x, int y) const;
 }; //end class button
Index: wesnoth/src/widgets/menu.cpp
diff -u wesnoth/src/widgets/menu.cpp:1.87 wesnoth/src/widgets/menu.cpp:1.88
--- wesnoth/src/widgets/menu.cpp:1.87   Wed Apr 20 17:27:39 2005
+++ wesnoth/src/widgets/menu.cpp        Wed May  4 03:16:39 2005
@@ -147,7 +147,11 @@
        //undrawn_items_.clear();
        max_items_ = -1; // Force recalculation of the max items.
        item_height_ = -1; // Force recalculation of the item height.
-       selected_ = 0;
+
+       if(keep_viewport == false || selected_ >= int(items.size())) {
+               selected_ = 0;
+       }
+
        fill_items(items, strip_spaces);
        if (!keep_viewport)
                set_position(0);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]