From 1eb28a32e097dfc08beda94745a225047402571d Mon Sep 17 00:00:00 2001 From: andrei Date: Tue, 2 Nov 2021 08:02:04 +0200 Subject: [PATCH] trade_ui: show held and worn items last --- src/trade_ui.cpp | 12 ++++++++++++ src/trade_ui.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/trade_ui.cpp b/src/trade_ui.cpp index 79a685abee2f9..b60eeee333af0 100644 --- a/src/trade_ui.cpp +++ b/src/trade_ui.cpp @@ -19,6 +19,8 @@ #include "type_id.h" static const flag_id json_flag_NO_UNWIELD( "NO_UNWIELD" ); +static const item_category_id item_category_WEAPON_HELD( "WEAPON_HELD" ); +static const item_category_id item_category_ITEMS_WORN( "ITEMS_WORN" ); namespace { point _pane_orig( int side ) @@ -70,6 +72,16 @@ std::string trade_preset::get_denial( const item_location &loc ) const return inventory_selector_preset::get_denial( loc ); } +bool trade_preset::cat_sort_compare( const inventory_entry &lhs, const inventory_entry &rhs ) const +{ + item_category const *const rcat = rhs.get_category_ptr(); + if( rcat->get_id() == item_category_ITEMS_WORN or rcat->get_id() == item_category_WEAPON_HELD ) { + return true; + } + + return inventory_selector_preset::cat_sort_compare( lhs, rhs ); +} + trade_ui::trade_ui( party_t &you, npc &trader, currency_t cost, std::string title ) : _upreset{ you, trader }, _tpreset{ trader, you }, _panes{ std::make_unique( this, trader, _tpreset, std::string(), _pane_size(), diff --git a/src/trade_ui.h b/src/trade_ui.h index 97df95a2985b5..04d6932a1ac51 100644 --- a/src/trade_ui.h +++ b/src/trade_ui.h @@ -52,6 +52,7 @@ class trade_preset : public inventory_selector_preset bool is_shown( item_location const &loc ) const override; std::string get_denial( const item_location &loc ) const override; + bool cat_sort_compare( const inventory_entry &lhs, const inventory_entry &rhs ) const override; private: Character const &_u, &_trader;