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

Enable mouse input - rework #41605

Merged
merged 58 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
70e6421
edit
martinrhan Jun 13, 2020
c992213
edit
martinrhan Jun 13, 2020
cb1274c
Update inventory_ui.cpp
martinrhan Jun 13, 2020
6ccdd8a
Update inventory_ui.cpp
martinrhan Jun 13, 2020
b912bd4
Update inventory_ui.cpp
martinrhan Jun 13, 2020
8078efb
Update ui.cpp
martinrhan Jun 13, 2020
100e60b
Update inventory_ui.cpp
martinrhan Jun 13, 2020
3206b68
Update ui.cpp
martinrhan Jun 14, 2020
3faa3eb
edit
martinrhan Jun 14, 2020
3815ec1
Update src/ui.h
martinrhan Jun 19, 2020
04e8f80
edit
martinrhan Jun 19, 2020
7dfb153
Merge branch 'branch_mouse_uilist' into branch_mouse_pickup
martinrhan Jun 19, 2020
19a9fa5
Update pickup.h
martinrhan Jun 19, 2020
ac5e177
Update pickup.h
martinrhan Jun 19, 2020
e70471a
Update inventory_ui.h
martinrhan Jun 19, 2020
204e1c2
edit
martinrhan Jun 26, 2020
9315ac9
Merge branch 'master' into branch_mouse_pickup
martinrhan Jun 26, 2020
40cf710
Update src/inventory_ui.cpp
martinrhan Jun 27, 2020
046f864
Update src/pickup.cpp
martinrhan Jun 27, 2020
4e95d88
Update src/pickup.h
martinrhan Jun 27, 2020
a183e50
Update src/input.h
martinrhan Jun 27, 2020
b1b76d9
seperate checking is in window from get coordinate method
martinrhan Jun 27, 2020
4b0614c
added some const
martinrhan Jun 27, 2020
e77ac21
add missing brackets
martinrhan Jun 27, 2020
1f15635
fix comment
martinrhan Jun 27, 2020
42d762b
fix window_contains_point
martinrhan Jun 27, 2020
88b9259
Update sdltiles.h
martinrhan Jun 27, 2020
697a53e
fix drawn_rect max x issue
martinrhan Jun 27, 2020
dab79ec
Update sdltiles.cpp
martinrhan Jun 27, 2020
30ab7e9
Update sdltiles.cpp
martinrhan Jun 27, 2020
3b30934
Update input.cpp
martinrhan Jun 27, 2020
a23f04e
fix get window_includes_point
martinrhan Jun 27, 2020
11c9726
Update inventory_ui.cpp
martinrhan Jun 27, 2020
b358fec
Apply suggestions from code review
ZhilkinSerg Jul 6, 2020
7279394
Update src/inventory_ui.h
martinrhan Jul 8, 2020
b2a898e
Update sdltiles.h
martinrhan Jul 11, 2020
7e8ffb2
move some methods out of if defined(TILES)
martinrhan Jul 11, 2020
02b3c31
Update sdltiles.cpp
martinrhan Jul 11, 2020
04ff66a
Update sdltiles.h
martinrhan Jul 11, 2020
5dee434
Update sdltiles.cpp
martinrhan Jul 11, 2020
28da032
Update sdltiles.cpp
martinrhan Jul 11, 2020
9d36050
Apply suggestions from code review
ZhilkinSerg Jul 11, 2020
87e9249
Update sdltiles.h
ZhilkinSerg Jul 11, 2020
8128993
Update sdltiles.cpp
ZhilkinSerg Jul 11, 2020
b5cd32e
redo drawn rect record
martinrhan Jul 17, 2020
cb5075c
Merge branch 'master' into branch_mouse_pickup
ZhilkinSerg Jul 28, 2020
18c6940
Update ui.h
ZhilkinSerg Jul 28, 2020
d6e527d
Apply suggestions from code review
ZhilkinSerg Jul 28, 2020
4462ffd
Update input.cpp
ZhilkinSerg Jul 28, 2020
cfebf17
Update inventory_ui.cpp
ZhilkinSerg Jul 28, 2020
60ae6d1
Merge branch 'master' into branch_mouse_pickup
ZhilkinSerg Jul 28, 2020
7c79818
Apply suggestions from code review
ZhilkinSerg Jul 28, 2020
3bfb5a6
Update sdltiles.cpp
ZhilkinSerg Jul 28, 2020
a7723cf
Update pickup.cpp
ZhilkinSerg Jul 28, 2020
583f49f
Apply suggestions from code review
ZhilkinSerg Jul 28, 2020
14bbe4d
Update sdltiles.cpp
ZhilkinSerg Jul 28, 2020
f352e8f
Apply suggestions from code review
ZhilkinSerg Jul 28, 2020
33d75f8
Apply suggestions from code review
ZhilkinSerg Jul 28, 2020
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
4 changes: 4 additions & 0 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ class input_context
*/
input_event get_raw_input();

/**
* Get coordinate of text level from mouse input, difference between this and get_coordinates is that one is getting pixel level coordinate.
* Return false if the result is not in the window.
martinrhan marked this conversation as resolved.
Show resolved Hide resolved
*/
std::pair<point, bool> get_coordinates_text( const catacurses::window &capture_win ) const;
martinrhan marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down
12 changes: 6 additions & 6 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,10 +971,9 @@ void inventory_column::draw( const catacurses::window &win, const point &p )

const bool selected = active && is_selected( entry );

entry.drawn_info.text_x_start = x1;
martinrhan marked this conversation as resolved.
Show resolved Hide resolved
entry.drawn_rect.p_min = point( x1, yy );
const int hx_max = p.x + get_width() + contained_offset;
entry.drawn_info.text_x_end = hx_max;
entry.drawn_info.y = yy;
entry.drawn_rect.p_max = point( hx_max, yy );

if( selected && visible_cells() > 1 ) {
for( int hx = x1; hx < hx_max; ++hx ) {
Expand Down Expand Up @@ -1424,11 +1423,12 @@ inventory_entry *inventory_selector::find_entry_by_coordinate( point coordinate
return entry.is_selectable();
};
for( inventory_column *column : columns ) {
if( column->visible() == false ) {
martinrhan marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
std::vector<inventory_entry *> 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_rect.contains( coordinate ) ) {
return entry;
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "pimpl.h"
#include "units.h"
#include "item_category.h"
#include "ui.h"

class Character;
class item;
Expand All @@ -48,12 +49,6 @@ struct inventory_input;
using drop_location = std::pair<item_location, int>;
using drop_locations = std::list<drop_location>;

struct inventory_entry_drawn_info {
int text_x_start;
int text_x_end;
int y;
};

class inventory_entry
{
public:
Expand Down Expand Up @@ -129,7 +124,7 @@ class inventory_entry
nc_color get_invlet_color() const;
void update_cache();

inventory_entry_drawn_info drawn_info;
inclusive_rectangle drawn_rect;
martinrhan marked this conversation as resolved.
Show resolved Hide resolved

private:
const item_category *custom_category = nullptr;
Expand Down
29 changes: 28 additions & 1 deletion src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )
ctxt.register_action( "ANY_INPUT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "FILTER" );
ctxt.register_action( "SELECT" );
#if defined(__ANDROID__)
ctxt.allow_text_entry = true; // allow user to specify pickup amount
#endif
Expand Down Expand Up @@ -669,6 +670,7 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )
const std::string pickup_chars = ctxt.get_available_single_char_hotkeys( all_pickup_chars );

werase( w_pickup );
pickup_rect::list.clear();
for( int cur_it = start; cur_it < start + maxitems; cur_it++ ) {
if( cur_it < static_cast<int>( matches.size() ) ) {
int true_it = matches[cur_it];
Expand Down Expand Up @@ -739,8 +741,12 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )
item_name = string_format( "<color_light_red>!</color> %s", item_name );
}

trim_and_print( w_pickup, point( 6, 1 + ( cur_it % maxitems ) ), pickupW - 4, icolor,
int y = 1 + ( cur_it % maxitems );
trim_and_print( w_pickup, point( 6, y ), pickupW - 4, icolor,
item_name );
pickup_rect rect = pickup_rect( point( 6, y ), point( 6 + pickupW - 4, y ) );
rect.cur_it = cur_it;
pickup_rect::list.push_back( rect );
}
}

Expand Down Expand Up @@ -794,6 +800,15 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )
if( itemcount < 0 ) {
itemcount = 0;
}
} else if( action == "SELECT" ) {
std::pair<point, bool> p = ctxt.get_coordinates_text( w_pickup );
if( p.second ) {
pickup_rect *rect = pickup_rect::find_by_coordinate( p.first );
selected = rect->cur_it;
iScrollPos = 0;
idx = selected;
}

} else if( action == "SCROLL_UP" ) {
iScrollPos--;
} else if( action == "SCROLL_DOWN" ) {
Expand Down Expand Up @@ -1082,3 +1097,15 @@ int Pickup::cost_to_move_item( const Character &who, const item &it )
// Keep it sane - it's not a long activity
return std::min( 400, ret );
}

std::vector<Pickup::pickup_rect> Pickup::pickup_rect::list;

Pickup::pickup_rect *Pickup::pickup_rect::find_by_coordinate( point p )
{
for( pickup_rect rect : pickup_rect::list ) {
martinrhan marked this conversation as resolved.
Show resolved Hide resolved
if( rect.contains( p ) ) {
return &rect;
}
}
return nullptr;
}
12 changes: 11 additions & 1 deletion src/pickup.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define CATA_SRC_PICKUP_H

#include <vector>
#include "point.h"
#include "ui.h"

class item;
class item_location;
Expand Down Expand Up @@ -42,6 +44,14 @@ int cost_to_move_item( const Character &who, const item &it );
* @param m map they are on
*/
bool handle_spillable_contents( Character &c, item &it, map &m );
} // namespace Pickup

struct pickup_rect : inclusive_rectangle {
ZhilkinSerg marked this conversation as resolved.
Show resolved Hide resolved
pickup_rect() : inclusive_rectangle() {}
martinrhan marked this conversation as resolved.
Show resolved Hide resolved
pickup_rect( const point &P_MIN, const point &P_MAX ) : inclusive_rectangle( P_MIN, P_MAX ) {}
int cur_it;
static std::vector<pickup_rect> list;
static pickup_rect *find_by_coordinate( point p );
};

} // namespace Pickup
#endif // CATA_SRC_PICKUP_H
28 changes: 27 additions & 1 deletion src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,11 @@ 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_rect.p_min = point( x, y );
entries[ei].drawn_rect.p_max = point( x + max_entry_len, y );
trim_and_print( window, point( x, y ),
max_entry_len, co, "%s", entry.c_str() );

if( max_column_len && !entries[ ei ].ctxt.empty() ) {
Expand Down Expand Up @@ -790,6 +794,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" );
Expand Down Expand Up @@ -831,6 +836,16 @@ void uilist::query( bool loop, int timeout )
if( callback != nullptr ) {
callback->select( this );
}
} else if( !fentries.empty() && ret_act == "SELECT" ) {
std::pair<point, bool> 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
Expand Down Expand Up @@ -861,6 +876,17 @@ void uilist::query( bool loop, int timeout )
} while( loop && ret == UILIST_WAIT_INPUT );
}

uilist_entry *uilist::find_entry_by_coordinate( point p )
{
for( int i : fentries ) {
uilist_entry &entry = entries[i];
if( entry.drawn_rect.contains( p ) ) {
return &entry;
}
}
return nullptr;
}

///@}
/**
* cleanup
Expand Down
6 changes: 5 additions & 1 deletion src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "pimpl.h"
#include "point.h"
#include "string_formatter.h"
#include "input.h"

class translation;

Expand Down Expand Up @@ -96,6 +97,8 @@ struct uilist_entry {
uilist_entry( Enum e, Args && ... args ) :
uilist_entry( static_cast<int>( e ), std::forward<Args>( args )... )
{}

inclusive_rectangle drawn_rect;
};

/**
Expand Down Expand Up @@ -338,13 +341,14 @@ class uilist // NOLINT(cata-xy)

bool started = false;

uilist_entry *find_entry_by_coordinate( point p );

public:
// Results
// TODO change to getters
std::string ret_act;
int ret = 0;
int keypress = 0;

int selected = 0;
};

Expand Down