forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadvanced_inv_pagination.cpp
45 lines (38 loc) · 1006 Bytes
/
advanced_inv_pagination.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "advanced_inv_pagination.h"
#include <vector>
#include "advanced_inv_pane.h"
class item_category;
void advanced_inventory_pagination::reset_page()
{
line = 0;
page = 0;
last_category = nullptr;
}
bool advanced_inventory_pagination::new_category( const item_category *cat ) const
{
return last_category != cat;
}
int advanced_inventory_pagination::lines_needed( int index )
{
if( pane.sortby == SORTBY_CATEGORY && new_category( pane.items[index].cat ) ) {
return 2;
}
return 1;
}
bool advanced_inventory_pagination::step( int index )
{
// item would overflow page
if( line + lines_needed( index ) > linesPerPage ) {
page++;
line = 0;
// always reprint category header on next page
last_category = nullptr;
// print item on next page
step( index );
return true;
}
// print on this page
line += lines_needed( index );
last_category = pane.items[index].cat;
return false;
}