Skip to content

Commit

Permalink
Merge pull request #77987 from db48x/fix-drop-direction
Browse files Browse the repository at this point in the history
reorder the cardinal direction indicators in the AIM drop window
  • Loading branch information
Anton Burmistrov authored Nov 20, 2024
2 parents d65bfa1 + 528f232 commit 0d10948
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
66 changes: 40 additions & 26 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,10 @@ class query_destination_callback : public uilist_callback
draw_squares( menu );
}
float desired_extra_space_left( ) override {
return ImGui::CalcTextSize( "[1] [2] [3]" ).x;
cataimgui::PushMonoFont();
float rv = ImGui::CalcTextSize( "[1][2][3]" ).x + ( 3.0 * ImGui::GetStyle().ItemSpacing.x );
ImGui::PopFont();
return rv;
}
};

Expand All @@ -2087,30 +2090,33 @@ void query_destination_callback::draw_squares( const uilist *menu )
sel = _adv_inv.screen_relative_location(
static_cast <aim_location>( menu->previewing + 1 ) );
}
for( int i = 1; i < 10; i++ ) {
aim_location loc = _adv_inv.screen_relative_location( static_cast <aim_location>( i ) );
std::string key = _adv_inv.get_location_key( loc );
advanced_inv_area &square = _adv_inv.get_one_square( loc );
bool in_vehicle = square.can_store_in_vehicle();
const char *bracket = in_vehicle ? "<>" : "[]";
// always show storage option for vehicle storage, if applicable
bool canputitems = menu->entries[i - 1].enabled && square.canputitems();
nc_color bcolor = canputitems ? sel == loc ? h_white : c_light_gray : c_red;
nc_color kcolor = canputitems ? sel == loc ? h_white : c_dark_gray : c_red;
// TODO(db48x): maybe make these clickable buttons or something
ImGui::PushID( i );
ImGui::BeginGroup();
ImGui::TextColored( bcolor, "%c", bracket[0] );
ImGui::SameLine( 0.0, 0.0 );
ImGui::TextColored( kcolor, "%s", key.c_str() );
ImGui::SameLine( 0.0, 0.0 );
ImGui::TextColored( bcolor, "%c", bracket[1] );
ImGui::EndGroup();
ImGui::PopID();
if( i % 3 != 0 ) {
cataimgui::PushMonoFont();
for( int i = 7; i >= 1; i -= 3 ) { // 7,4,1
for( int ii = 0; ii <= 2; ii++ ) { // +0,1,2
aim_location loc = _adv_inv.screen_relative_location( static_cast <aim_location>( i + ii ) );
std::string key = _adv_inv.get_location_key( loc );
advanced_inv_area &square = _adv_inv.get_one_square( loc );
bool in_vehicle = square.can_store_in_vehicle();
const char *bracket = in_vehicle ? "<>" : "[]";
// always show storage option for vehicle storage, if applicable
bool canputitems = menu->entries[i + ii - 1].enabled && square.canputitems();
nc_color bcolor = canputitems ? ( sel == loc ? h_white : c_light_gray ) : c_red;
nc_color kcolor = canputitems ? ( sel == loc ? h_white : c_dark_gray ) : c_red;
// TODO(db48x): maybe make these clickable buttons or something
ImGui::PushID( i + ii );
ImGui::BeginGroup();
ImGui::TextColored( bcolor, "%c", bracket[0] );
ImGui::SameLine( 0.0, 0.0 );
ImGui::TextColored( kcolor, "%s", key.c_str() );
ImGui::SameLine( 0.0, 0.0 );
ImGui::TextColored( bcolor, "%c", bracket[1] );
ImGui::EndGroup();
ImGui::PopID();
ImGui::SameLine();
}
ImGui::NewLine();
}
ImGui::PopFont();
}

bool advanced_inventory::query_destination( aim_location &def )
Expand Down Expand Up @@ -2142,10 +2148,18 @@ bool advanced_inventory::query_destination( aim_location &def )
if( size >= MAX_ITEM_IN_SQUARE ) {
prefix += _( " (FULL)" );
}
menu.addentry( ordered_loc,
s.canputitems() && s.id != panes[src].get_area(),
get_location_key( ordered_loc )[0],
prefix + " " + s.name + " " + ( s.veh != nullptr ? s.veh->name : "" ) );
if( s.veh != nullptr ) {
menu.addentry_col( ordered_loc,
s.canputitems() && s.id != panes[src].get_area(),
get_location_key( ordered_loc )[0],
prefix + " " + s.name,
s.veh->name );
} else {
menu.addentry( ordered_loc,
s.canputitems() && s.id != panes[src].get_area(),
get_location_key( ordered_loc )[0],
prefix + " " + s.name );
}
}
}
// Selected keyed to uilist.entries, which starts at 0.
Expand Down
7 changes: 0 additions & 7 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,8 @@ class uilist_impl : cataimgui::window
return parent.desired_bounds.value_or( parent.calculated_bounds );
}
void draw_controls() override;
void on_resized() override;
};

void uilist_impl::on_resized()
{
parent.setup();
}

void uilist_impl::draw_controls()
{
if( !parent.text.empty() ) {
Expand Down Expand Up @@ -897,7 +891,6 @@ shared_ptr_fast<uilist_impl> uilist::create_or_get_ui()
} else {
ui = current_ui = make_shared_fast<uilist_impl>( *this, title );
}
current_ui->on_resized();
}
return current_ui;
}
Expand Down

0 comments on commit 0d10948

Please sign in to comment.