The Battle for Wesnoth  1.17.0-dev
game_load.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Jörg Hinrichs <joerg.hinrichs@alice-dsl.de>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "gettext.hpp"
21 #include "save_index.hpp"
22 #include "savegame.hpp"
23 
24 #include <SDL2/SDL_keycode.h>
25 
26 namespace gui2
27 {
28 class text_box_base;
29 
30 namespace dialogs
31 {
32 /**
33  * @ingroup GUIWindowDefinitionWML
34  *
35  * This shows the dialog to select and load a savegame file.
36  * Key |Type |Mandatory|Description
37  * ------------------|--------------|---------|-----------
38  * txtFilter | text |yes |The filter for the listbox items.
39  * savegame_list | @ref listbox |yes |List of savegames.
40  * filename | control |yes |Name of the savegame.
41  * date | control |no |Date the savegame was created.
42  * preview_pane | widget |yes |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.
43  * minimap | @ref minimap |yes |Minimap of the selected savegame.
44  * imgLeader | @ref image |yes |The image of the leader in the selected savegame.
45  * lblScenario | @ref label |yes |The name of the scenario of the selected savegame.
46  * lblSummary | @ref label |yes |Summary of the selected savegame.
47  */
48 class game_load : public modal_dialog
49 {
50 public:
51  game_load(const game_config_view& cache_config, savegame::load_game_metadata& data);
52 
53  static bool execute(const game_config_view& cache_config, savegame::load_game_metadata& data);
54 
55 private:
56  virtual void pre_show(window& window) override;
57 
58  virtual const std::string& window_id() const override;
59 
60  void set_save_dir_list(menu_button& dir_list);
61 
62  /** Update (both internally and visually) the list of games. */
63  void populate_game_list();
64 
65  void filter_text_changed(const std::string& text);
68  void handle_dir_select();
69 
70  /** Part of display_savegame that might throw a config::error if the savegame data is corrupt. */
72  void display_savegame();
73  void evaluate_summary_string(std::stringstream& str, const config& cfg_summary);
74 
75  void key_press_callback(const SDL_Keycode key);
76 
77  std::string& filename_;
78  std::shared_ptr<savegame::save_index_class>& save_index_manager_;
79 
83 
85 
86  std::vector<savegame::save_info> games_;
88 
89  std::vector<std::string> last_words_;
90 };
91 } // namespace dialogs
92 } // namespace gui2
A menu_button is a styled_widget to choose an element from a list of elements.
Definition: menu_button.hpp:60
field_bool * change_difficulty_
Definition: game_load.hpp:80
This shows the dialog to select and load a savegame file.
Definition: game_load.hpp:48
Specialized field class for boolean.
Definition: field.hpp:544
std::shared_ptr< savegame::save_index_class > & save_index_manager_
Definition: game_load.hpp:78
void populate_game_list()
Update (both internally and visually) the list of games.
Definition: game_load.cpp:155
const game_config_view & cache_config_
Definition: game_load.hpp:87
void key_press_callback(const SDL_Keycode key)
Definition: game_load.cpp:483
void set_save_dir_list(menu_button &dir_list)
Definition: game_load.cpp:132
static bool execute(const game_config_view &cache_config, savegame::load_game_metadata &data)
Definition: game_load.cpp:61
std::vector< std::string > last_words_
Definition: game_load.hpp:89
game_load(const game_config_view &cache_config, savegame::load_game_metadata &data)
Definition: game_load.cpp:82
Generic file dialog.
Definition: field-fwd.hpp:22
std::vector< savegame::save_info > games_
Definition: game_load.hpp:86
virtual const std::string & window_id() const override
The id of the window to build.
Various uncategorised dialogs.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: game_load.cpp:95
void filter_text_changed(const std::string &text)
Definition: game_load.cpp:315
field_bool * show_replay_
Definition: game_load.hpp:81
void display_savegame_internal(const savegame::save_info &game)
Part of display_savegame that might throw a config::error if the savegame data is corrupt...
Definition: game_load.cpp:181
field_bool * cancel_orders_
Definition: game_load.hpp:82
std::string & filename_
Definition: game_load.hpp:77
Filename and modification date for a file list.
Definition: save_index.hpp:26
Abstract base class for all modal dialogs.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
void evaluate_summary_string(std::stringstream &str, const config &cfg_summary)
Definition: game_load.cpp:353