Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIM: keep ui_adaptor running during move activities #62400

Merged
merged 1 commit into from
Nov 29, 2022
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
78 changes: 47 additions & 31 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,27 @@ std::string enum_to_string<aim_entry>( const aim_entry v )

} // namespace io

namespace
{
std::unique_ptr<advanced_inventory> advinv;
} // namespace

void create_advanced_inv()
{
advanced_inventory advinv;
advinv.display();
if( !advinv ) {
advinv = std::make_unique<advanced_inventory>();
}
advinv->display();
// keep the UI and its ui_adaptor running if we're returning
if( uistate.transfer_save.exit_code != aim_exit::re_entry ) {
kill_advanced_inv();
}
}

void kill_advanced_inv()
{
advinv.reset();
cancel_aim_processing();
}

// *INDENT-OFF*
Expand Down Expand Up @@ -703,10 +720,6 @@ void advanced_inventory::redraw_pane( side p )
{
input_context ctxt( "ADVANCED_INVENTORY" );

// don't update ui if processing demands
if( is_processing() ) {
return;
}
advanced_inventory_pane &pane = panes[p];
if( recalc || pane.recalc ) {
recalc_pane( p );
Expand Down Expand Up @@ -1237,23 +1250,21 @@ void advanced_inventory::redraw_sidebar()
input_context ctxt( "ADVANCED_INVENTORY" );
ctxt.register_action( "HELP_KEYBINDINGS" );

if( !is_processing() ) {
werase( head );
werase( minimap );
werase( mm_border );
draw_border( head );
Messages::display_messages( head, 2, 1, w_width - 1, head_height - 2 );
draw_minimap();
right_print( head, 0, +3, c_white, string_format(
_( "< [<color_yellow>%s</color>] keybindings >" ),
ctxt.get_desc( "HELP_KEYBINDINGS" ) ) );
if( get_player_character().has_watch() ) {
const std::string time = to_string_time_of_day( calendar::turn );
mvwprintz( head, point( 2, 0 ), c_white, time );
}
wnoutrefresh( head );
refresh_minimap();
}
werase( head );
werase( minimap );
werase( mm_border );
draw_border( head );
Messages::display_messages( head, 2, 1, w_width - 1, head_height - 2 );
draw_minimap();
right_print( head, 0, +3, c_white, string_format(
_( "< [<color_yellow>%s</color>] keybindings >" ),
ctxt.get_desc( "HELP_KEYBINDINGS" ) ) );
if( get_player_character().has_watch() ) {
const std::string time = to_string_time_of_day( calendar::turn );
mvwprintz( head, point( 2, 0 ), c_white, time );
}
wnoutrefresh( head );
refresh_minimap();
}

void advanced_inventory::change_square( const aim_location changeSquare,
Expand Down Expand Up @@ -1510,6 +1521,7 @@ void advanced_inventory::action_examine( advanced_inv_listitem *sitem,
exit = true;
} else {
player_character.cancel_activity();
uistate.transfer_save.exit_code = aim_exit::none;
}
// Might have changed a stack (activated an item, repaired an item, etc.)
if( spane.get_area() == AIM_INVENTORY ) {
Expand Down Expand Up @@ -1538,19 +1550,20 @@ void advanced_inventory::action_examine( advanced_inv_listitem *sitem,

void advanced_inventory::display()
{
init();

avatar &player_character = get_avatar();
player_character.inv->restack( player_character );

input_context ctxt{ register_ctxt() };

exit = false;
recalc = true;
if( !is_processing() ) {
init();

player_character.inv->restack( player_character );

recalc = true;
}

std::unique_ptr<string_input_popup> spopup;
std::unique_ptr<ui_adaptor> ui;
if( !is_processing() ) {
if( !ui ) {
ui = std::make_unique<ui_adaptor>();
ui->on_screen_resize( [&]( ui_adaptor & ui ) {
constexpr int min_w_height = 10;
Expand Down Expand Up @@ -1616,7 +1629,8 @@ void advanced_inventory::display()
advanced_inventory::side::left;

if( ui ) {
ui_manager::redraw();
ui->invalidate_ui();
ui_manager::redraw_invalidated();
}

recalc = false;
Expand Down Expand Up @@ -2131,4 +2145,6 @@ bool advanced_inventory::is_processing() const
void cancel_aim_processing()
{
uistate.transfer_save.re_enter_move_all = aim_entry::START;
uistate.transfer_save.aim_all_location = AIM_AROUND_BEGIN;
uistate.transfer_save.exit_code = aim_exit::none;
}
3 changes: 3 additions & 0 deletions src/advanced_inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "advanced_inv_area.h"
#include "advanced_inv_pane.h"
#include "cursesdef.h"
#include "ui_manager.h"

class advanced_inv_listitem;
class input_context;
Expand Down Expand Up @@ -51,6 +52,8 @@ class advanced_inventory
};
static constexpr int head_height = 5;

std::unique_ptr<ui_adaptor> ui;

// swap the panes and windows via std::swap()
void swap_panes();

Expand Down
9 changes: 8 additions & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@

struct dealt_projectile_attack;

static const activity_id ACT_ADV_INVENTORY( "ACT_ADV_INVENTORY" );
static const activity_id ACT_AUTODRIVE( "ACT_AUTODRIVE" );
static const activity_id ACT_CONSUME_DRINK_MENU( "ACT_CONSUME_DRINK_MENU" );
static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
Expand Down Expand Up @@ -8210,13 +8211,19 @@ void Character::cancel_activity()
stop_hauling();
}
// Clear any backlog items that aren't auto-resume.
// but keep only one instance of ACT_ADV_INVENTORY
// FIXME: this is required by the legacy code in advanced_inventory::move_all_items()
bool has_adv_inv = has_activity( ACT_ADV_INVENTORY );
for( auto backlog_item = backlog.begin(); backlog_item != backlog.end(); ) {
if( backlog_item->auto_resume ) {
if( backlog_item->auto_resume &&
( !has_adv_inv || backlog_item->id() != ACT_ADV_INVENTORY ) ) {
backlog_item++;
has_adv_inv |= backlog_item->id() == ACT_ADV_INVENTORY;
} else {
backlog_item = backlog.erase( backlog_item );
}
}

// act wait stamina interrupts an ongoing activity.
// and automatically puts auto_resume = true on it
// we don't want that to persist if there is another interruption.
Expand Down
4 changes: 4 additions & 0 deletions src/do_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,10 @@ bool do_turn()
while( u.moves > 0 && u.activity ) {
u.activity.do_turn( u );
}
// FIXME: hack needed due to the legacy code in advanced_inventory::move_all_items()
if( !u.activity ) {
kill_advanced_inv();
}

// Process NPC sound events before they move or they hear themselves talking
for( npc &guy : g->all_npcs() ) {
Expand Down
2 changes: 2 additions & 0 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,6 @@ class pointmenu_cb : public uilist_callback
void select( uilist *menu ) override;
};

void kill_advanced_inv();

#endif // CATA_SRC_UI_H