Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,9 @@ void editmap::edit_feature()

blink = true;
bool quit = false;

// Hold list till end
shared_ptr_fast<uilist_impl> ui_impl;
do {
const T_id override( emenu.selected );
if( override ) {
Expand All @@ -1152,7 +1155,7 @@ void editmap::edit_feature()
info_title_curr = info_title<T_t>();
do_ui_invalidation();

emenu.query( false, get_option<int>( "BLINK_SPEED" ) );
ui_impl = emenu.query( false, get_option<int>( "BLINK_SPEED" ) );
if( emenu.ret == UILIST_CANCEL ) {
quit = true;
} else if( ( emenu.ret >= 0 && static_cast<size_t>( emenu.ret ) < T_t::count() ) ||
Expand Down Expand Up @@ -1252,6 +1255,7 @@ void editmap::edit_fld()
restore_on_out_of_scope info_title_prev( info_title_curr );
map &here = get_map();

shared_ptr_fast<uilist_impl> ui_impl;
blink = true;
do {
const field_type_id override( fmenu.selected );
Expand All @@ -1278,7 +1282,7 @@ void editmap::edit_fld()
info_title_curr = pgettext( "Map editor: Editing field effects", "Field effects" );
do_ui_invalidation();

fmenu.query( false, get_option<int>( "BLINK_SPEED" ) );
ui_impl = fmenu.query( false, get_option<int>( "BLINK_SPEED" ) );
if( ( fmenu.ret > 0 && static_cast<size_t>( fmenu.ret ) < field_type::count() ) ||
( fmenu.ret == UILIST_ADDITIONAL && ( fmenu.ret_act == "LEFT" || fmenu.ret_act == "RIGHT" ) ) ) {

Expand Down
3 changes: 2 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,7 @@ int game::inventory_item_menu( item_location locThisItem,
bool first_execution = true;
static int lang_version = detail::get_current_language_version();
catacurses::window w_info;
shared_ptr_fast<uilist_impl> ui_impl;
do {
//lang check here is needed to redraw the menu when using "Toggle language to English" option
if( first_execution || lang_version != detail::get_current_language_version() ) {
Expand Down Expand Up @@ -2222,7 +2223,7 @@ int game::inventory_item_menu( item_location locThisItem,
}

const int prev_selected = action_menu.selected;
action_menu.query( false );
ui_impl = action_menu.query( false );
if( action_menu.ret >= 0 ) {
cMenu = action_menu.ret; /* Remember: hotkey == retval, see addentry above. */
} else if( action_menu.ret == UILIST_UNBOUND && action_menu.ret_act == "RIGHT" ) {
Expand Down
23 changes: 10 additions & 13 deletions src/uilist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,6 @@ void uilist::init()

input_category = "UILIST";
additional_actions.clear();

if( ui ) {
ui.reset();
}
}

input_context uilist::create_main_input_context() const
Expand Down Expand Up @@ -873,21 +869,22 @@ bool uilist::scrollby( const uilist::scroll_amount scrollby )

shared_ptr_fast<uilist_impl> uilist::create_or_get_ui()
{
if( !ui ) {
shared_ptr_fast<uilist_impl> current_ui = ui.lock();
if( !current_ui ) {
if( title.empty() ) {
ui = make_shared_fast<uilist_impl>( *this );
ui = current_ui = make_shared_fast<uilist_impl>( *this );
} else {
ui = make_shared_fast<uilist_impl>( *this, title );
ui = current_ui = make_shared_fast<uilist_impl>( *this, title );
}
}
return ui;
return current_ui;
}

/**
* Handle input and update display
*
*/
void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )
shared_ptr_fast<uilist_impl> uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )
{
#if defined(__ANDROID__)
if( get_option<bool>( "ANDROID_NATIVE_UI" ) && !entries.empty() && !desired_bounds ) {
Expand Down Expand Up @@ -950,20 +947,18 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )
} else {
ret = UILIST_ERROR;
}
return;
return nullptr;
}
#endif
ret_evt = input_event();
if( entries.empty() ) {
ret = UILIST_ERROR;
return;
return nullptr;
}
ret = UILIST_WAIT_INPUT;

input_context ctxt = create_main_input_context();

// Ensure we have a uilist to work on
// TODO: We don't even use the return value here, find a better solution
shared_ptr_fast<uilist_impl> ui = create_or_get_ui();

#if defined(__ANDROID__)
Expand Down Expand Up @@ -1041,6 +1036,8 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )
}
}
} while( loop && ret == UILIST_WAIT_INPUT );

return ui;
}

///@}
Expand Down
5 changes: 3 additions & 2 deletions src/uilist.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ class uilist // NOLINT(cata-xy)
};
};
bool scrollby( uilist::scroll_amount scrollby );
void query( bool loop = true, int timeout = 50, bool allow_unfiltered_hotkeys = false );
shared_ptr_fast<uilist_impl> query( bool loop = true, int timeout = 50,
bool allow_unfiltered_hotkeys = false );
void filterlist();
// In add_entry/add_entry_desc/add_entry_col, int k only support letters
// (a-z, A-Z) and digits (0-9), MENU_AUTOASSIGN, and 0 or ' ' (disable
Expand Down Expand Up @@ -488,7 +489,7 @@ class uilist // NOLINT(cata-xy)
std::map<input_event, int, std::function<bool( const input_event &, const input_event & )>>
keymap { input_event::compare_type_mod_code };

shared_ptr_fast<uilist_impl> ui;
weak_ptr_fast<uilist_impl> ui;

std::unique_ptr<string_input_popup_imgui> filter_popup;

Expand Down
Loading