forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loading_ui.cpp
85 lines (71 loc) · 1.84 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
#include "loading_ui.h"
#include <memory>
#include <vector>
#include "cached_options.h"
#include "color.h"
#include "input.h"
#include "output.h"
#include "sdl_wrappers.h"
#include "translations.h"
#include "ui.h"
#include "ui_manager.h"
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();
}
}