forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loading_ui.cpp
88 lines (73 loc) · 1.88 KB
/
loading_ui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "loading_ui.h"
#include <functional>
#include <memory>
#include <vector>
#include "cached_options.h"
#include "color.h"
#include "output.h"
#include "translations.h"
#include "ui.h"
#include "ui_manager.h"
#if defined(TILES)
#include "sdl_wrappers.h"
#endif // TILES
loading_ui::loading_ui( bool display )
{
if( display && !test_mode ) {
menu = std::make_unique<uilist>();
menu->settext( _( "Loading" ) );
}
}
loading_ui::~loading_ui() = default;
void loading_ui::add_entry( const std::string &description )
{
if( menu != nullptr ) {
menu->addentry( menu->entries.size(), true, 0, description );
}
}
void loading_ui::new_context( const std::string &desc )
{
if( menu != nullptr ) {
menu->reset();
menu->settext( desc );
ui = nullptr;
ui_background = nullptr;
}
}
void loading_ui::init()
{
if( menu != nullptr && ui == nullptr ) {
ui_background = std::make_unique<background_pane>();
ui = std::make_unique<ui_adaptor>();
ui->on_screen_resize( [this]( ui_adaptor & ui ) {
menu->reposition( ui );
} );
menu->reposition( *ui );
ui->on_redraw( [this]( const ui_adaptor & ) {
menu->show();
} );
}
}
void loading_ui::proceed()
{
init();
if( menu != nullptr && !menu->entries.empty() ) {
if( menu->selected >= 0 && menu->selected < static_cast<int>( menu->entries.size() ) ) {
// TODO: Color it red if it errored hard, yellow on warnings
menu->entries[menu->selected].text_color = c_green;
}
if( menu->selected + 1 < static_cast<int>( menu->entries.size() ) ) {
menu->scrollby( 1 );
}
}
show();
}
void loading_ui::show()
{
init();
if( menu != nullptr ) {
ui_manager::redraw();
refresh_display();
inp_mngr.pump_events();
}
}