The Battle for Wesnoth  1.19.0-dev
game_load.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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 
21 #include "save_index.hpp"
22 #include "savegame.hpp"
23 
24 #include <SDL2/SDL_keycode.h>
25 
26 namespace gui2
27 {
28 
29 namespace dialogs
30 {
31 /**
32  * @ingroup GUIWindowDefinitionWML
33  *
34  * This shows the dialog to select and load a savegame file.
35  * Key |Type |Mandatory|Description
36  * ------------------|--------------|---------|-----------
37  * txtFilter | text |yes |The filter for the listbox items.
38  * savegame_list | @ref listbox |yes |List of savegames.
39  * filename | control |yes |Name of the savegame.
40  * date | control |no |Date the savegame was created.
41  * 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.
42  * minimap | @ref minimap |yes |Minimap of the selected savegame.
43  * imgLeader | @ref image |yes |The image of the leader in the selected savegame.
44  * lblScenario | @ref label |yes |The name of the scenario of the selected savegame.
45  * lblSummary | @ref label |yes |Summary of the selected savegame.
46  */
47 class game_load : public modal_dialog
48 {
49 public:
51 
52  static bool execute(const game_config_view& cache_config, savegame::load_game_metadata& data);
53 
54 private:
55  virtual void pre_show(window& window) override;
56 
57  virtual const std::string& window_id() const override;
58 
59  void set_save_dir_list(menu_button& dir_list);
60 
61  /** Update (both internally and visually) the list of games. */
62  void populate_game_list();
63 
64  void filter_text_changed(const std::string& text);
67  void handle_dir_select();
68 
69  /** Part of display_savegame that might throw a config::error if the savegame data is corrupt. */
71  void display_savegame();
72  void evaluate_summary_string(std::stringstream& str, const config& cfg_summary);
73 
74  void key_press_callback(const SDL_Keycode key);
75 
76  std::string& filename_;
77  std::shared_ptr<savegame::save_index_class>& save_index_manager_;
78 
82 
84 
85  std::vector<savegame::save_info> games_;
87 
88  std::vector<std::string> last_words_;
89 };
90 } // namespace dialogs
91 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A class grating read only view to a vector of config objects, viewed as one config with all children ...
This shows the dialog to select and load a savegame file.
Definition: game_load.hpp:48
std::vector< std::string > last_words_
Definition: game_load.hpp:88
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:177
field_bool * show_replay_
Definition: game_load.hpp:80
game_load(const game_config_view &cache_config, savegame::load_game_metadata &data)
Definition: game_load.cpp:77
void key_press_callback(const SDL_Keycode key)
Definition: game_load.cpp:501
void evaluate_summary_string(std::stringstream &str, const config &cfg_summary)
Definition: game_load.cpp:347
void set_save_dir_list(menu_button &dir_list)
Definition: game_load.cpp:128
field_bool * cancel_orders_
Definition: game_load.hpp:81
const game_config_view & cache_config_
Definition: game_load.hpp:86
static bool execute(const game_config_view &cache_config, savegame::load_game_metadata &data)
Definition: game_load.cpp:56
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: game_load.cpp:91
std::shared_ptr< savegame::save_index_class > & save_index_manager_
Definition: game_load.hpp:77
std::string & filename_
Definition: game_load.hpp:76
std::vector< savegame::save_info > games_
Definition: game_load.hpp:85
void populate_game_list()
Update (both internally and visually) the list of games.
Definition: game_load.cpp:151
void filter_text_changed(const std::string &text)
Definition: game_load.cpp:309
virtual const std::string & window_id() const override
The ID of the window to build.
field_bool * change_difficulty_
Definition: game_load.hpp:79
Abstract base class for all modal dialogs.
Specialized field class for boolean.
Definition: field.hpp:489
A menu_button is a styled_widget to choose an element from a list of elements.
Definition: menu_button.hpp:59
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
Filename and modification date for a file list.
Definition: save_index.hpp:26
Various uncategorised dialogs.
Generic file dialog.
std::string_view data
Definition: picture.cpp:194