The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
loading_screen.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 - 2025
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
18
19#include "events.hpp"
20#include "tstring.hpp"
21
22#include <atomic>
23#include <future>
24#include <map>
26#include <vector>
27
28namespace cursor
29{
30 struct setter;
31}
32
33/**
34 * Loading screen stage IDs.
35 * When adding new entries here, don't forget to update the stage_names
36 * map with an appropriate description.
37 */
65
66namespace gui2
67{
68class drawing;
69class label;
70class window;
71
72namespace dialogs
73{
75{
76public:
77 loading_screen(std::function<void()> f);
78
80
81 static void display(const std::function<void()>& f);
82 static bool displaying() { return singleton_ != nullptr; }
83
84 /**
85 * Report what is being loaded to the loading screen.
86 *
87 * Also processes any pending events and draw calls.
88 *
89 * This should be called before commencing each loading stage.
90 *
91 * @param stage Which loading stage the caller is about to perform.
92 */
93 static void progress(loading_stage stage = loading_stage::none);
94
95 /**
96 * Indicate to the player that loading is progressing.
97 *
98 * Calling this function is necessary to allow loading screen animations
99 * to run, and input events to be processed. It should be placed
100 * inside any loading loops that may take significant time.
101 *
102 * There is an internal guard against acting too frequently, so there
103 * should be little need to limit calls to this function.
104 *
105 * If a loading screen is not currently being shown, this function does
106 * nothing.
107 */
108 static void spin();
109
110 /**
111 * Raise the loading screen to the top of the draw stack.
112 *
113 * This can be called if another TLD has been created during loading,
114 * such as happens with the game display.
115 */
116 static void raise();
117
118private:
119 virtual const std::string& window_id() const override;
120
121 virtual void pre_show() override;
122
123 virtual void post_show() override;
124
125 /** Inherited from events::pump_monitor. */
126 virtual void process() override;
127
128 /** Called by draw_manager to assign concrete layout. */
129 virtual void layout() override;
130
132
133 std::vector<std::function<void()>> load_funcs_;
134 std::future<void> worker_result_;
135 std::unique_ptr<cursor::setter> cursor_setter_;
136
139
140 utils::optional<decltype(std::chrono::steady_clock::now())> animation_start_;
141
142 std::atomic<loading_stage> current_stage_;
143
144 using stage_map = std::map<loading_stage, t_string>;
146 stage_map::const_iterator current_visible_stage_;
147
149};
150
151} // namespace dialogs
152} // namespace gui2
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition display.hpp:88
std::future< void > worker_result_
static void progress(loading_stage stage=loading_stage::none)
Report what is being loaded to the loading screen.
virtual void layout() override
Called by draw_manager to assign concrete layout.
std::atomic< loading_stage > current_stage_
static loading_screen * singleton_
static void raise()
Raise the loading screen to the top of the draw stack.
std::vector< std::function< void()> > load_funcs_
std::unique_ptr< cursor::setter > cursor_setter_
stage_map::const_iterator current_visible_stage_
virtual void process() override
Inherited from events::pump_monitor.
utils::optional< decltype(std::chrono::steady_clock::now())> animation_start_
std::map< loading_stage, t_string > stage_map
virtual const std::string & window_id() const override
The ID of the window to build.
static void spin()
Indicate to the player that loading is progressing.
virtual void post_show() override
Actions to be taken after the window has been shown.
virtual void pre_show() override
Actions to be taken before showing the window.
Abstract base class for all modal dialogs.
std::string label
What to show in the filter's drop-down list.
Definition manager.cpp:201
loading_stage
Loading screen stage IDs.
Various uncategorised dialogs.
Generic file dialog.
#define f