@ -338,7 +338,7 @@ public:
std : : string getFocusString ( ) { return " unitlabors " ; }
std : : string getFocusString ( ) { return " unitlabors " ; }
viewscreen_unitlaborsst ( vector < df : : unit * > & src );
viewscreen_unitlaborsst ( vector < df : : unit * > & src , int cursor_pos );
~ viewscreen_unitlaborsst ( ) { } ;
~ viewscreen_unitlaborsst ( ) { } ;
protected :
protected :
@ -354,7 +354,7 @@ protected:
void calcSize ( ) ;
void calcSize ( ) ;
} ;
} ;
viewscreen_unitlaborsst : : viewscreen_unitlaborsst ( vector < df : : unit * > & src )
viewscreen_unitlaborsst : : viewscreen_unitlaborsst ( vector < df : : unit * > & src , int cursor_pos )
{
{
for ( size_t i = 0 ; i < src . size ( ) ; i + + )
for ( size_t i = 0 ; i < src . size ( ) ; i + + )
{
{
@ -382,12 +382,23 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src)
units . push_back ( cur ) ;
units . push_back ( cur ) ;
}
}
std : : sort ( units . begin ( ) , units . end ( ) , sortByName ) ;
altsort = ALTSORT_NAME ;
altsort = ALTSORT_NAME ;
first_row = sel_row = 0 ;
first_column = sel_column = 0 ;
first_column = sel_column = 0 ;
first_row = 0 ;
sel_row = cursor_pos ;
calcSize ( ) ;
calcSize ( ) ;
// recalculate first_row to roughly match the original layout
first_row = 0 ;
while ( first_row < sel_row - num_rows + 1 )
first_row + = num_rows + 2 ;
// make sure the selection stays visible
if ( first_row > sel_row )
first_row = sel_row - num_rows + 1 ;
// don't scroll beyond the end
if ( first_row > units . size ( ) - num_rows )
first_row = units . size ( ) - num_rows ;
}
}
void viewscreen_unitlaborsst : : calcSize ( )
void viewscreen_unitlaborsst : : calcSize ( )
@ -528,7 +539,11 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
if ( first_column < sel_column - col_widths [ DISP_COLUMN_LABORS ] + 1 )
if ( first_column < sel_column - col_widths [ DISP_COLUMN_LABORS ] + 1 )
first_column = sel_column - col_widths [ DISP_COLUMN_LABORS ] + 1 ;
first_column = sel_column - col_widths [ DISP_COLUMN_LABORS ] + 1 ;
// handle mouse input
int input_row = sel_row ;
int input_column = sel_column ;
int input_sort = altsort ;
// Translate mouse input to appropriate keyboard input
if ( enabler - > tracking_on & & gps - > mouse_x ! = - 1 & & gps - > mouse_y ! = - 1 )
if ( enabler - > tracking_on & & gps - > mouse_x ! = - 1 & & gps - > mouse_y ! = - 1 )
{
{
int click_header = DISP_COLUMN_MAX ; // group ID of the column header clicked
int click_header = DISP_COLUMN_MAX ; // group ID of the column header clicked
@ -560,34 +575,44 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
case DISP_COLUMN_HAPPINESS :
case DISP_COLUMN_HAPPINESS :
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
{
{
descending = enabler - > mouse_lbut ;
input_sort = ALTSORT_HAPPINESS ;
std : : sort ( units . begin ( ) , units . end ( ) , sortByHappiness ) ;
if ( enabler - > mouse_lbut )
events - > insert ( interface_key : : SECONDSCROLL_PAGEUP ) ;
if ( enabler - > mouse_rbut )
events - > insert ( interface_key : : SECONDSCROLL_PAGEDOWN ) ;
}
}
break ;
break ;
case DISP_COLUMN_NAME :
case DISP_COLUMN_NAME :
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
{
{
descending = enabler - > mouse_rbut ;
input_sort = ALTSORT_NAME ;
std : : sort ( units . begin ( ) , units . end ( ) , sortByName ) ;
if ( enabler - > mouse_lbut )
events - > insert ( interface_key : : SECONDSCROLL_PAGEDOWN ) ;
if ( enabler - > mouse_rbut )
events - > insert ( interface_key : : SECONDSCROLL_PAGEUP ) ;
}
}
break ;
break ;
case DISP_COLUMN_PROFESSION :
case DISP_COLUMN_PROFESSION :
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
{
{
descending = enabler - > mouse_rbut ;
input_sort = ALTSORT_PROFESSION ;
std : : sort ( units . begin ( ) , units . end ( ) , sortByProfession ) ;
if ( enabler - > mouse_lbut )
events - > insert ( interface_key : : SECONDSCROLL_PAGEDOWN ) ;
if ( enabler - > mouse_rbut )
events - > insert ( interface_key : : SECONDSCROLL_PAGEUP ) ;
}
}
break ;
break ;
case DISP_COLUMN_LABORS :
case DISP_COLUMN_LABORS :
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
{
{
descending = enabler - > mouse_lbut ;
input_column = click_labor ;
sort_skill = columns [ click_labor ] . skill ;
if ( enabler - > mouse_lbut )
sort_labor = columns [ click_labor ] . labor ;
events - > insert ( interface_key : : SECONDSCROLL_UP ) ;
std : : sort ( units . begin ( ) , units . end ( ) , sortBySkill ) ;
if ( enabler - > mouse_rbut )
events - > insert ( interface_key : : SECONDSCROLL_DOWN ) ;
}
}
break ;
break ;
}
}
@ -603,12 +628,12 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
// left-click to view, right-click to zoom
// left-click to view, right-click to zoom
if ( enabler - > mouse_lbut )
if ( enabler - > mouse_lbut )
{
{
sel _row = click_unit ;
input _row = click_unit ;
events - > insert ( interface_key : : UNITJOB_VIEW ) ;
events - > insert ( interface_key : : UNITJOB_VIEW ) ;
}
}
if ( enabler - > mouse_rbut )
if ( enabler - > mouse_rbut )
{
{
sel _row = click_unit ;
input _row = click_unit ;
events - > insert ( interface_key : : UNITJOB_ZOOM_CRE ) ;
events - > insert ( interface_key : : UNITJOB_ZOOM_CRE ) ;
}
}
break ;
break ;
@ -617,21 +642,28 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
// left-click to toggle, right-click to just highlight
// left-click to toggle, right-click to just highlight
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
if ( enabler - > mouse_lbut | | enabler - > mouse_rbut )
{
{
sel_row = click_unit ;
sel_column = click_labor ;
if ( enabler - > mouse_lbut )
if ( enabler - > mouse_lbut )
{
input_row = click_unit ;
input_column = click_labor ;
events - > insert ( interface_key : : SELECT ) ;
events - > insert ( interface_key : : SELECT ) ;
}
if ( enabler - > mouse_rbut )
{
sel_row = click_unit ;
sel_column = click_labor ;
}
}
}
break ;
break ;
}
}
enabler - > mouse_lbut = enabler - > mouse_rbut = 0 ;
enabler - > mouse_lbut = enabler - > mouse_rbut = 0 ;
}
}
UnitInfo * cur = units [ sel _row] ;
UnitInfo * cur = units [ input _row] ;
if ( events - > count ( interface_key : : SELECT ) & & ( cur - > allowEdit ) & & ( columns [ sel _column] . labor ! = unit_labor : : NONE ) )
if ( events - > count ( interface_key : : SELECT ) & & ( cur - > allowEdit ) & & ( columns [ input _column] . labor ! = unit_labor : : NONE ) )
{
{
df : : unit * unit = cur - > unit ;
df : : unit * unit = cur - > unit ;
const SkillColumn & col = columns [ sel _column] ;
const SkillColumn & col = columns [ input _column] ;
bool newstatus = ! unit - > status . labors [ col . labor ] ;
bool newstatus = ! unit - > status . labors [ col . labor ] ;
if ( col . special )
if ( col . special )
{
{
@ -650,7 +682,7 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
if ( events - > count ( interface_key : : SELECT_ALL ) & & ( cur - > allowEdit ) )
if ( events - > count ( interface_key : : SELECT_ALL ) & & ( cur - > allowEdit ) )
{
{
df : : unit * unit = cur - > unit ;
df : : unit * unit = cur - > unit ;
const SkillColumn & col = columns [ sel _column] ;
const SkillColumn & col = columns [ input _column] ;
bool newstatus = ! unit - > status . labors [ col . labor ] ;
bool newstatus = ! unit - > status . labors [ col . labor ] ;
for ( int i = 0 ; i < NUM_COLUMNS ; i + + )
for ( int i = 0 ; i < NUM_COLUMNS ; i + + )
{
{
@ -675,15 +707,15 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
if ( events - > count ( interface_key : : SECONDSCROLL_UP ) | | events - > count ( interface_key : : SECONDSCROLL_DOWN ) )
if ( events - > count ( interface_key : : SECONDSCROLL_UP ) | | events - > count ( interface_key : : SECONDSCROLL_DOWN ) )
{
{
descending = events - > count ( interface_key : : SECONDSCROLL_UP ) ;
descending = events - > count ( interface_key : : SECONDSCROLL_UP ) ;
sort_skill = columns [ sel _column] . skill ;
sort_skill = columns [ input _column] . skill ;
sort_labor = columns [ sel _column] . labor ;
sort_labor = columns [ input _column] . labor ;
std : : sort ( units . begin ( ) , units . end ( ) , sortBySkill ) ;
std : : sort ( units . begin ( ) , units . end ( ) , sortBySkill ) ;
}
}
if ( events - > count ( interface_key : : SECONDSCROLL_PAGEUP ) | | events - > count ( interface_key : : SECONDSCROLL_PAGEDOWN ) )
if ( events - > count ( interface_key : : SECONDSCROLL_PAGEUP ) | | events - > count ( interface_key : : SECONDSCROLL_PAGEDOWN ) )
{
{
descending = events - > count ( interface_key : : SECONDSCROLL_PAGEUP ) ;
descending = events - > count ( interface_key : : SECONDSCROLL_PAGEUP ) ;
switch ( alt sort)
switch ( input_ sort)
{
{
case ALTSORT_NAME :
case ALTSORT_NAME :
std : : sort ( units . begin ( ) , units . end ( ) , sortByName ) ;
std : : sort ( units . begin ( ) , units . end ( ) , sortByName ) ;
@ -718,7 +750,7 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
{
{
for ( int i = 0 ; i < unitlist - > units [ unitlist - > page ] . size ( ) ; i + + )
for ( int i = 0 ; i < unitlist - > units [ unitlist - > page ] . size ( ) ; i + + )
{
{
if ( unitlist - > units [ unitlist - > page ] [ i ] = = units [ sel _row] - > unit )
if ( unitlist - > units [ unitlist - > page ] [ i ] = = units [ input _row] - > unit )
{
{
unitlist - > cursor_pos [ unitlist - > page ] = i ;
unitlist - > cursor_pos [ unitlist - > page ] = i ;
unitlist - > feed ( events ) ;
unitlist - > feed ( events ) ;
@ -964,7 +996,7 @@ struct unitlist_hook : df::viewscreen_unitlistst
{
{
if ( units [ page ] . size ( ) )
if ( units [ page ] . size ( ) )
{
{
Screen : : show ( new viewscreen_unitlaborsst ( units [ page ] )) ;
Screen : : show ( new viewscreen_unitlaborsst ( units [ page ] , cursor_pos [ page ] )) ;
return ;
return ;
}
}
}
}