From 70e64211e74a10d5b7ad7924456749f1bc091e9b Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sat, 13 Jun 2020 12:47:38 +0800 Subject: [PATCH 01/12] edit --- src/inventory_ui.cpp | 9 ++++----- src/inventory_ui.h | 8 ++++++++ src/ui.cpp | 35 +++++++++++++++++++++++++++++++++-- src/ui.h | 20 ++++++++++++++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index 7076234789759..114c17727ca83 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -1426,14 +1426,12 @@ inventory_entry *inventory_selector::find_entry_by_coordinate( point coordinate for( inventory_column *column : columns ) { std::vector entries = column->get_entries( filter_to_selected ); for( inventory_entry *entry : entries ) { - if( entry->drawn_info.text_x_start <= coordinate.x && - coordinate.x <= entry->drawn_info.text_x_end && - entry->drawn_info.y == coordinate.y ) { + if( entry->drawn_info.include_point( coordinate ) ) { return entry; } } + return nullptr; } - return nullptr; } @@ -1957,7 +1955,8 @@ void inventory_selector::set_active_column( size_t index ) } } -size_t inventory_selector::get_columns_width( const std::vector &columns ) const +size_t inventory_selector::get_columns_width( const std::vector &columns ) +const { return std::accumulate( columns.begin(), columns.end(), static_cast< size_t >( 0 ), []( const size_t &lhs, const inventory_column * column ) { diff --git a/src/inventory_ui.h b/src/inventory_ui.h index c7ca68d1c1712..52b1380418819 100644 --- a/src/inventory_ui.h +++ b/src/inventory_ui.h @@ -52,6 +52,14 @@ struct inventory_entry_drawn_info { int text_x_start; int text_x_end; int y; + bool include_point( point p )const { + if( text_x_start <= p.x && + p.x <= text_x_end && + y == p.y ) { + return true; + } + return false; + } }; class inventory_entry diff --git a/src/ui.cpp b/src/ui.cpp index 41eed88461d57..a63df4e5094b9 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -613,7 +613,12 @@ void uilist::show() // to be used. const auto entry = utf8_wrapper( ei == selected ? remove_color_tags( entries[ ei ].txt ) : entries[ ei ].txt ); - trim_and_print( window, point( pad_left + 4, estart + si ), + int x = pad_left + 4; + int y = estart + si; + entries[ei].drawn_info.text_x_start = x; + entries[ei].drawn_info.text_x_end = x + max_entry_len; + entries[ei].drawn_info.y = y; + trim_and_print( window, point( x, y ), max_entry_len, co, "%s", entry.c_str() ); if( max_column_len && !entries[ ei ].ctxt.empty() ) { @@ -790,6 +795,7 @@ void uilist::query( bool loop, int timeout ) if( allow_cancel ) { ctxt.register_action( "QUIT" ); } + ctxt.register_action( "SELECT" ); ctxt.register_action( "CONFIRM" ); ctxt.register_action( "FILTER" ); ctxt.register_action( "ANY_INPUT" ); @@ -831,6 +837,16 @@ void uilist::query( bool loop, int timeout ) if( callback != nullptr ) { callback->select( this ); } + } else if( !fentries.empty() && ret_act == "SELECT" ) { + std::pair p = ctxt.get_coordinates_text( window ); + if( p.second ) { + uilist_entry *entry = find_entry_by_coordinate( p.first ); + if( entry != nullptr ) { + if( entry->enabled ) { + ret = entry->retval; + } + } + } } else if( !fentries.empty() && ret_act == "CONFIRM" ) { if( entries[ selected ].enabled ) { ret = entries[ selected ].retval; // valid @@ -861,6 +877,22 @@ void uilist::query( bool loop, int timeout ) } while( loop && ret == UILIST_WAIT_INPUT ); } +uilist_entry *uilist::find_entry_by_coordinate( point p ) +{ + for( uilist_entry &entry : entries ) { + if( entry.drawn_info.include_point( p ) ) { + return &entry; + } + } + /*for( int i = 0; i < entries.size(); i++ ) { + uilist_entry *entry = &entries[i]; + if( entry->drawn_info.include_point( p ) ) { + return entry; + } + }*/ + return nullptr; +} + ///@} /** * cleanup @@ -958,4 +990,3 @@ void pointmenu_cb::select( uilist *const menu ) { impl->select( menu ); } - diff --git a/src/ui.h b/src/ui.h index 6af4ab1b7c1a5..3e47c53e1f1c0 100644 --- a/src/ui.h +++ b/src/ui.h @@ -16,6 +16,7 @@ #include "pimpl.h" #include "point.h" #include "string_formatter.h" +#include "input.h" class translation; @@ -49,6 +50,20 @@ struct mvwzstr { int sym = 0; }; +struct uilist_entry_drawn_info { + int text_x_start; + int text_x_end; + int y; + bool include_point( point p )const { + if( text_x_start <= p.x && + p.x <= text_x_end && + y == p.y ) { + return true; + } + return false; + } +}; + /** * uilist_entry: entry line for uilist */ @@ -96,6 +111,8 @@ struct uilist_entry { uilist_entry( Enum e, Args && ... args ) : uilist_entry( static_cast( e ), std::forward( args )... ) {} + + uilist_entry_drawn_info drawn_info; }; /** @@ -338,6 +355,8 @@ class uilist // NOLINT(cata-xy) bool started = false; + uilist_entry *find_entry_by_coordinate( point p ); + public: // Results // TODO change to getters @@ -346,6 +365,7 @@ class uilist // NOLINT(cata-xy) int keypress; int selected; + }; /** From c992213e8a5aa6e821c1ab683cf5109f5c84508c Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sat, 13 Jun 2020 18:35:36 +0800 Subject: [PATCH 02/12] edit --- src/inventory_ui.cpp | 3 +++ src/ui.cpp | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index 114c17727ca83..bf96051cebfeb 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -1424,6 +1424,9 @@ inventory_entry *inventory_selector::find_entry_by_coordinate( point coordinate return entry.is_selectable(); }; for( inventory_column *column : columns ) { + if( !column->visible ) { + continue; + } std::vector entries = column->get_entries( filter_to_selected ); for( inventory_entry *entry : entries ) { if( entry->drawn_info.include_point( coordinate ) ) { diff --git a/src/ui.cpp b/src/ui.cpp index a63df4e5094b9..a0c9554decac9 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -884,12 +884,6 @@ uilist_entry *uilist::find_entry_by_coordinate( point p ) return &entry; } } - /*for( int i = 0; i < entries.size(); i++ ) { - uilist_entry *entry = &entries[i]; - if( entry->drawn_info.include_point( p ) ) { - return entry; - } - }*/ return nullptr; } From cb1274c77e9ce24aa79216147614a324be55cb1e Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sat, 13 Jun 2020 18:51:29 +0800 Subject: [PATCH 03/12] Update inventory_ui.cpp --- src/inventory_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index bf96051cebfeb..e5e4adc7c0b2f 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -1424,7 +1424,7 @@ inventory_entry *inventory_selector::find_entry_by_coordinate( point coordinate return entry.is_selectable(); }; for( inventory_column *column : columns ) { - if( !column->visible ) { + if( column->visible() == false ) { continue; } std::vector entries = column->get_entries( filter_to_selected ); From 6ccdd8ad985fe358b9525adcaefb876bf268d6af Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sat, 13 Jun 2020 20:06:49 +0800 Subject: [PATCH 04/12] Update inventory_ui.cpp --- src/inventory_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index e5e4adc7c0b2f..b32def83a583b 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -1433,8 +1433,8 @@ inventory_entry *inventory_selector::find_entry_by_coordinate( point coordinate return entry; } } - return nullptr; } + return nullptr; } From b912bd479c9f6b606b2952162b1bb8f05d304976 Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sat, 13 Jun 2020 20:07:23 +0800 Subject: [PATCH 05/12] Update inventory_ui.cpp --- src/inventory_ui.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index b32def83a583b..32e411a57eaca 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -1958,8 +1958,7 @@ void inventory_selector::set_active_column( size_t index ) } } -size_t inventory_selector::get_columns_width( const std::vector &columns ) -const +size_t inventory_selector::get_columns_width( const std::vector &columns )const { return std::accumulate( columns.begin(), columns.end(), static_cast< size_t >( 0 ), []( const size_t &lhs, const inventory_column * column ) { From 8078efbe89ac8be1cced7bf39cf783c04174206e Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sat, 13 Jun 2020 20:10:04 +0800 Subject: [PATCH 06/12] Update ui.cpp --- src/ui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui.cpp b/src/ui.cpp index a0c9554decac9..0b42ec481b10e 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -984,3 +984,4 @@ void pointmenu_cb::select( uilist *const menu ) { impl->select( menu ); } + From 100e60b2f3d75cede42d77ad77a1f1f8cbc2d606 Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sat, 13 Jun 2020 20:10:16 +0800 Subject: [PATCH 07/12] Update inventory_ui.cpp --- src/inventory_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index 32e411a57eaca..e5858175feb65 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -1958,7 +1958,7 @@ void inventory_selector::set_active_column( size_t index ) } } -size_t inventory_selector::get_columns_width( const std::vector &columns )const +size_t inventory_selector::get_columns_width( const std::vector &columns ) const { return std::accumulate( columns.begin(), columns.end(), static_cast< size_t >( 0 ), []( const size_t &lhs, const inventory_column * column ) { From 3206b688611aab4150be46e14082bc4ba7565ab6 Mon Sep 17 00:00:00 2001 From: martinrhan Date: Sun, 14 Jun 2020 12:33:33 +0800 Subject: [PATCH 08/12] Update ui.cpp --- src/ui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui.cpp b/src/ui.cpp index 0b42ec481b10e..094ccff74e743 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -879,7 +879,8 @@ void uilist::query( bool loop, int timeout ) uilist_entry *uilist::find_entry_by_coordinate( point p ) { - for( uilist_entry &entry : entries ) { + for( int i : fentries ) { + uilist_entry &entry = entries[i]; if( entry.drawn_info.include_point( p ) ) { return &entry; } From 3815ec1d10182629e32844a144cbdd0d3f97a283 Mon Sep 17 00:00:00 2001 From: martinrhan <53336429+martinrhan@users.noreply.github.com> Date: Fri, 19 Jun 2020 19:55:10 +0800 Subject: [PATCH 09/12] Update src/ui.h Co-authored-by: Mark Langsdorf --- src/ui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui.h b/src/ui.h index 3e47c53e1f1c0..b1da717a7c5f5 100644 --- a/src/ui.h +++ b/src/ui.h @@ -54,7 +54,7 @@ struct uilist_entry_drawn_info { int text_x_start; int text_x_end; int y; - bool include_point( point p )const { + bool include_point( point p ) const { if( text_x_start <= p.x && p.x <= text_x_end && y == p.y ) { From 04e8f805f39e13e89c4f93b34bf64c54378bdc6a Mon Sep 17 00:00:00 2001 From: martinrhan Date: Fri, 19 Jun 2020 20:07:35 +0800 Subject: [PATCH 10/12] edit --- src/inventory_ui.h | 13 +------------ src/ui.h | 5 ++++- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/inventory_ui.h b/src/inventory_ui.h index 52b1380418819..1811a75262e76 100644 --- a/src/inventory_ui.h +++ b/src/inventory_ui.h @@ -48,18 +48,7 @@ struct inventory_input; using drop_location = std::pair; using drop_locations = std::list; -struct inventory_entry_drawn_info { - int text_x_start; - int text_x_end; - int y; - bool include_point( point p )const { - if( text_x_start <= p.x && - p.x <= text_x_end && - y == p.y ) { - return true; - } - return false; - } +struct inventory_entry_drawn_info : entry_drawn_info { }; class inventory_entry diff --git a/src/ui.h b/src/ui.h index b1da717a7c5f5..f41b259f98fee 100644 --- a/src/ui.h +++ b/src/ui.h @@ -50,7 +50,7 @@ struct mvwzstr { int sym = 0; }; -struct uilist_entry_drawn_info { +struct entry_drawn_info { int text_x_start; int text_x_end; int y; @@ -64,6 +64,9 @@ struct uilist_entry_drawn_info { } }; +struct uilist_entry_drawn_info : entry_drawn_info { +}; + /** * uilist_entry: entry line for uilist */ From 16b5e56e3afff72bb747df507f66d6e96701bab5 Mon Sep 17 00:00:00 2001 From: martinrhan Date: Fri, 19 Jun 2020 21:11:08 +0800 Subject: [PATCH 11/12] Update inventory_ui.h --- src/inventory_ui.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/inventory_ui.h b/src/inventory_ui.h index 1811a75262e76..98c69f070929a 100644 --- a/src/inventory_ui.h +++ b/src/inventory_ui.h @@ -24,6 +24,7 @@ #include "pimpl.h" #include "units.h" #include "item_category.h" +#include "ui.h" class Character; class item; From e0533c2b016b910321c10c551809412d30cae692 Mon Sep 17 00:00:00 2001 From: martinrhan <53336429+martinrhan@users.noreply.github.com> Date: Sat, 20 Jun 2020 18:29:53 +0800 Subject: [PATCH 12/12] Update src/inventory_ui.cpp Co-authored-by: BevapDin --- src/inventory_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index b21b10add40b5..e5cf8d99474d7 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -1424,7 +1424,7 @@ inventory_entry *inventory_selector::find_entry_by_coordinate( point coordinate return entry.is_selectable(); }; for( inventory_column *column : columns ) { - if( column->visible() == false ) { + if( !column->visible() ) { continue; } std::vector entries = column->get_entries( filter_to_selected );