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