The Battle for Wesnoth  1.15.1+dev
loading_screen.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
17 
18 #include "events.hpp"
19 #include "tstring.hpp"
20 
21 #include <atomic>
22 #include <future>
23 #include <map>
24 #include <vector>
25 
26 namespace cursor
27 {
28  struct setter;
29 }
30 
31 /**
32  * Loading screen stage IDs.
33  * When adding new entries here, don't forget to update the stage_names
34  * map with an appropriate description.
35  */
36 enum class loading_stage
37 {
41  init_fonts,
42  init_teams,
43  init_theme,
44  load_config,
45  load_data,
46  load_level,
47  init_lua,
50  load_units,
52  start_game,
56  waiting,
57  redirect,
61  none,
62 };
63 
64 namespace gui2
65 {
66 class label;
67 class window;
68 
69 namespace dialogs
70 {
72 {
73 public:
74  loading_screen(std::function<void()> f);
75 
76  ~loading_screen();
77 
78  static void display(std::function<void()> f);
79  static bool displaying() { return singleton_ != nullptr; }
80 
81  static void progress(loading_stage stage = loading_stage::none);
82 
83 private:
84  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
85  virtual const std::string& window_id() const override;
86 
87  /** Inherited from modal_dialog. */
88  virtual void pre_show(window& window) override;
89 
90  /** Inherited from modal_dialog. */
91  virtual void post_show(window& window) override;
92 
93  /** Inherited from events::pump_monitor. */
94  virtual void process(events::pump_info&) override;
95 
96  /** Checks whether the worker thread has returned and loading is complete. */
97  bool loading_complete() const;
98 
99  /** Callback to handle drawing the progress animation. */
100  void draw_callback();
101 
103 
105  std::function<void()> load_func_;
106  std::future<void> worker_result_;
107  std::unique_ptr<cursor::setter> cursor_setter_;
108 
109  std::exception_ptr exception_;
110 
113 
114  std::atomic<loading_stage> current_stage_;
115 
116  using stage_map = std::map<loading_stage, t_string>;
118 
119  std::vector<t_string> animation_stages_;
120  stage_map::const_iterator current_visible_stage_;
121 };
122 
123 } // namespace dialogs
124 } // namespace gui2
stage_map::const_iterator current_visible_stage_
std::atomic< loading_stage > current_stage_
Label showing a text.
Definition: label.hpp:32
Generic file dialog.
Definition: field-fwd.hpp:22
loading_stage
Loading screen stage IDs.
std::vector< t_string > animation_stages_
void process(int mousex, int mousey)
Definition: tooltips.cpp:193
std::future< void > worker_result_
Various uncategorised dialogs.
std::map< loading_stage, t_string > stage_map
std::unique_ptr< cursor::setter > cursor_setter_
static loading_screen * singleton_
#define f
std::function< void()> load_func_
Abstract base class for all modal dialogs.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63