mail[Wesnoth-commits] r40308 - in /trunk: data/gui/default/window/game_load.cfg src/gui/dialogs/game_load.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by koraq on December 20, 2009 - 20:35:
Author: mordante
Date: Sun Dec 20 20:35:13 2009
New Revision: 40308

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40308&view=rev
Log:
Protect against no savegame selected in the list.

The filter can filter out all savegames, then the preview pane shouldn't
try to access an invalid index.

Modified:
    trunk/data/gui/default/window/game_load.cfg
    trunk/src/gui/dialogs/game_load.cpp

Modified: trunk/data/gui/default/window/game_load.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/game_load.cfg?rev=40308&r1=40307&r2=40308&view=diff
==============================================================================
--- trunk/data/gui/default/window/game_load.cfg (original)
+++ trunk/data/gui/default/window/game_load.cfg Sun Dec 20 20:35:13 2009
@@ -67,6 +67,8 @@
                                                                
vertical_alignment = "top"
 
                                                                [grid]
+
+                                                                       id = 
"preview_pane"
                                                                
                                                                        [row]
                                                                              
  grow_factor = 1

Modified: trunk/src/gui/dialogs/game_load.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/game_load.cpp?rev=40308&r1=40307&r2=40308&view=diff
==============================================================================
--- trunk/src/gui/dialogs/game_load.cpp (original)
+++ trunk/src/gui/dialogs/game_load.cpp Sun Dec 20 20:35:13 2009
@@ -54,12 +54,16 @@
  *     -(filename)                The name of the savegame.
  *     -[date]                    The date the savegame was created.
  *
- *     (minimap) (minimap) ()     Minimap of the selected savegame.
- *     (imgLeader) (image) ()     The image of the leader in the selected
+ *     (preview_pane) (widget) () Container widget or grid that contains the
+ *                                items for a preview. The visible status of
+ *                                this container depends on whether or not
+ *                                something is selected.
+ *     -(minimap) (minimap) ()    Minimap of the selected savegame.
+ *     -(imgLeader) (image) ()    The image of the leader in the selected
  *                                savegame.
- *     (lblScenario) (label) ()   The name of the scenario of the selected
+ *     -(lblScenario) (label) ()  The name of the scenario of the selected
  *                                savegame.
- *     (lblSummary) (label) ()    Summary of the selected savegame.
+ *     -(lblSummary) (label) ()   Summary of the selected savegame.
  * @end_table
  */
 
@@ -188,35 +192,47 @@
 
 void tgame_load::display_savegame(twindow& window)
 {
-       tlistbox& list = find_widget<tlistbox>(&window, "savegame_list", 
false);
-       savegame::save_info& game = games_[list.get_selected_row()];
-       filename_ = game.name;
-
-       config cfg_summary;
-       std::string dummy;
-
-       try {
-               savegame::manager::load_summary(game.name, cfg_summary, 
&dummy);
-       } catch(game::load_game_failed&) {
-               cfg_summary["corrupt"] = "yes";
-       }
-
-       find_widget<timage>(&window, "imgLeader", false).
-                       set_label(cfg_summary["leader_image"]);
-
-       find_widget<tminimap>(&window, "minimap", false).
-                       set_map_data(cfg_summary["map_data"]);
-
-       find_widget<tlabel>(&window, "lblScenario", 
false).set_label(game.name);
-
-       std::stringstream str;
-       str << game.format_time_local();
-       evaluate_summary_string(str, cfg_summary);
-
-       find_widget<tlabel>(&window, "lblSummary", 
false).set_label(str.str());
-
-       // FIXME: Find a better way to change the label width
-       window.invalidate_layout();
+       const int selected_row =
+                       find_widget<tlistbox>(&window, "savegame_list", false)
+                               .get_selected_row();
+
+       twidget& preview_pane =
+                       find_widget<twidget>(&window, "preview_pane", false);
+
+       if(selected_row == -1) {
+               preview_pane.set_visible(twidget::HIDDEN);
+       } else {
+               preview_pane.set_visible(twidget::VISIBLE);
+
+               savegame::save_info& game = games_[selected_row];
+               filename_ = game.name;
+
+               config cfg_summary;
+               std::string dummy;
+
+               try {
+                       savegame::manager::load_summary(game.name, 
cfg_summary, &dummy);
+               } catch(game::load_game_failed&) {
+                       cfg_summary["corrupt"] = "yes";
+               }
+
+               find_widget<timage>(&window, "imgLeader", false).
+                               set_label(cfg_summary["leader_image"]);
+
+               find_widget<tminimap>(&window, "minimap", false).
+                               set_map_data(cfg_summary["map_data"]);
+
+               find_widget<tlabel>(&window, "lblScenario", 
false).set_label(game.name);
+
+               std::stringstream str;
+               str << game.format_time_local();
+               evaluate_summary_string(str, cfg_summary);
+
+               find_widget<tlabel>(&window, "lblSummary", 
false).set_label(str.str());
+
+               // FIXME: Find a better way to change the label width
+               window.invalidate_layout();
+       }
 }
 
 void tgame_load::evaluate_summary_string(std::stringstream& str




Related Messages


Powered by MHonArc, Updated Sun Dec 20 20:40:21 2009