Skip to content

Commit

Permalink
Use ui_adaptor in new character menu, debug message popup, and loadin…
Browse files Browse the repository at this point in the history
…g ui (#38916)
  • Loading branch information
Qrox authored and ZhilkinSerg committed Apr 1, 2020
1 parent 3e68103 commit a681253
Show file tree
Hide file tree
Showing 13 changed files with 577 additions and 441 deletions.
53 changes: 33 additions & 20 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "worldfactory.h"
#include "mod_manager.h"
#include "type_id.h"
#include "ui_manager.h"

#if !defined(_MSC_VER)
#include <sys/time.h>
Expand Down Expand Up @@ -144,31 +145,45 @@ void realDebugmsg( const char *filename, const char *line, const char *funcname,
);
#endif

fold_and_print( catacurses::stdscr, point_zero, getmaxx( catacurses::stdscr ), c_light_red,
"\n\n" // Looks nicer with some space
" %s\n" // translated user string: error notification
" -----------------------------------------------------------\n"
"%s"
" -----------------------------------------------------------\n"
// temporarily disable redrawing and resizing of previous uis since they
// could be in an unknown state.
ui_adaptor ui( ui_adaptor::disable_uis_below {} );
const auto init_window = []( ui_adaptor & ui ) {
ui.position_from_window( catacurses::stdscr );
};
init_window( ui );
ui.on_screen_resize( init_window );
const std::string message = string_format(
"\n\n" // Looks nicer with some space
" %s\n" // translated user string: error notification
" -----------------------------------------------------------\n"
"%s"
" -----------------------------------------------------------\n"
#if defined(BACKTRACE)
" %s\n" // translated user string: where to find backtrace
" %s\n" // translated user string: where to find backtrace
#endif
" %s\n" // translated user string: space to continue
" %s\n" // translated user string: ignore key
" %s\n" // translated user string: space to continue
" %s\n" // translated user string: ignore key
#if defined(TILES)
" %s\n" // translated user string: copy
" %s\n" // translated user string: copy
#endif // TILES
, _( "An error has occurred! Written below is the error report:" ),
formatted_report,
, _( "An error has occurred! Written below is the error report:" ),
formatted_report,
#if defined(BACKTRACE)
backtrace_instructions,
backtrace_instructions,
#endif
_( "Press <color_white>space bar</color> to continue the game." ),
_( "Press <color_white>I</color> (or <color_white>i</color>) to also ignore this particular message in the future." )
_( "Press <color_white>space bar</color> to continue the game." ),
_( "Press <color_white>I</color> (or <color_white>i</color>) to also ignore this particular message in the future." )
#if defined(TILES)
, _( "Press <color_white>C</color> (or <color_white>c</color>) to copy this message to the clipboard." )
, _( "Press <color_white>C</color> (or <color_white>c</color>) to copy this message to the clipboard." )
#endif // TILES
);
);
ui.on_redraw( [&]( const ui_adaptor & ) {
catacurses::erase();
fold_and_print( catacurses::stdscr, point_zero, getmaxx( catacurses::stdscr ), c_light_red,
"%s", message );
catacurses::refresh();
} );

#if defined(__ANDROID__)
input_context ctxt( "DEBUG_MSG" );
Expand All @@ -177,6 +192,7 @@ void realDebugmsg( const char *filename, const char *line, const char *funcname,
ctxt.register_manual_key( ' ' );
#endif
for( bool stop = false; !stop; ) {
ui_manager::redraw();
switch( inp_mngr.get_input_event().get_first_input() ) {
#if defined(TILES)
case 'c':
Expand All @@ -193,9 +209,6 @@ void realDebugmsg( const char *filename, const char *line, const char *funcname,
break;
}
}

werase( catacurses::stdscr );
catacurses::refresh();
}

// Normal functions {{{1
Expand Down
6 changes: 0 additions & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2774,9 +2774,6 @@ void game::load( const save_t &name )

void game::load_world_modfiles( loading_ui &ui )
{
catacurses::erase();
catacurses::refresh();

auto &mods = world_generator->active_world->active_mod_order;

// remove any duplicates whilst preserving order (fixes #19385)
Expand Down Expand Up @@ -2808,9 +2805,6 @@ void game::load_world_modfiles( loading_ui &ui )
// Load additional mods from that world-specific folder
load_data_from_dir( get_world_base_save_path() + "/mods", "custom", ui );

catacurses::erase();
catacurses::refresh();

DynamicDataLoader::get_instance().finalize_loaded_data( ui );
}

Expand Down
34 changes: 32 additions & 2 deletions src/loading_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ui.h"
#include "cursesdef.h"
#include "translations.h"
#include "ui_manager.h"

#if defined(TILES)
# if defined(_MSC_VER) && defined(USE_VCPKG)
Expand Down Expand Up @@ -40,11 +41,39 @@ 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<ui_adaptor>();
ui_background->on_screen_resize( []( ui_adaptor & ui_background ) {
ui_background.position_from_window( catacurses::stdscr );
} );
ui_background->position_from_window( catacurses::stdscr );
ui_background->on_redraw( []( const ui_adaptor & ) {
catacurses::erase();
catacurses::refresh();
} );

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
Expand All @@ -61,9 +90,10 @@ void loading_ui::proceed()

void loading_ui::show()
{
init();

if( menu != nullptr ) {
menu->show();
catacurses::refresh();
ui_manager::redraw();
refresh_display();
#if defined(TILES)
SDL_PumpEvents();
Expand Down
10 changes: 8 additions & 2 deletions src/loading_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
#include <vector>
#include <string>

class ui_adaptor;
class uilist;

class loading_ui
{
private:
std::unique_ptr<uilist> menu;
std::unique_ptr<ui_adaptor> ui;
std::unique_ptr<ui_adaptor> ui_background;

void init();
public:
loading_ui( bool display );
~loading_ui();
Expand All @@ -25,11 +30,12 @@ class loading_ui
*/
void add_entry( const std::string &description );
/**
* Marks current entry as processed and scrolls down.
* Place the UI onto UI stack, mark current entry as processed, scroll down,
* and redraw. (if display is enabled)
*/
void proceed();
/**
* Shows the UI on the screen (if display is enabled).
* Place the UI onto UI stack and redraw it on the screen (if display is enabled).
*/
void show();
};
Expand Down
Loading

0 comments on commit a681253

Please sign in to comment.